Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix warnings #291

Merged
merged 1 commit into from
Sep 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 4 additions & 12 deletions src/margo-core.c
Original file line number Diff line number Diff line change
Expand Up @@ -388,12 +388,8 @@
margo_finalize_callback_t* cb,
void** uargs)
{
struct margo_finalize_cb* prev = NULL;
struct margo_finalize_cb* fcb = mid->prefinalize_cb;
while (fcb != NULL && fcb->owner != owner) {
prev = fcb;
fcb = fcb->next;
}
struct margo_finalize_cb* fcb = mid->prefinalize_cb;

Check warning on line 391 in src/margo-core.c

View check run for this annotation

Codecov / codecov/patch

src/margo-core.c#L391

Added line #L391 was not covered by tests
while (fcb != NULL && fcb->owner != owner) { fcb = fcb->next; }
if (fcb == NULL) return 0;
if (cb) *cb = fcb->callback;
if (uargs) *uargs = fcb->uargs;
Expand Down Expand Up @@ -480,12 +476,8 @@
margo_finalize_callback_t* cb,
void** uargs)
{
struct margo_finalize_cb* prev = NULL;
struct margo_finalize_cb* fcb = mid->finalize_cb;
while (fcb != NULL && fcb->owner != owner) {
prev = fcb;
fcb = fcb->next;
}
struct margo_finalize_cb* fcb = mid->finalize_cb;

Check warning on line 479 in src/margo-core.c

View check run for this annotation

Codecov / codecov/patch

src/margo-core.c#L479

Added line #L479 was not covered by tests
while (fcb != NULL && fcb->owner != owner) { fcb = fcb->next; }
if (fcb == NULL) return 0;
if (cb) *cb = fcb->callback;
if (uargs) *uargs = fcb->uargs;
Expand Down
210 changes: 109 additions & 101 deletions tests/unit-tests/margo-init.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,16 @@

static void* test_context_setup(const MunitParameter params[], void* user_data)
{
(void) params;
(void) user_data;
(void)params;
(void)user_data;
struct test_context* ctx = calloc(1, sizeof(*ctx));

return ctx;
}

static void test_context_tear_down(void *data)
static void test_context_tear_down(void* data)
{
struct test_context *ctx = (struct test_context*)data;
struct test_context* ctx = (struct test_context*)data;

free(ctx);
}
Expand All @@ -29,19 +29,21 @@
static MunitResult init_cycle_server(const MunitParameter params[], void* data)
{
const char* protocol = munit_parameters_get(params, "protocol");
int use_progress_thread = atoi(munit_parameters_get(params, "use_progress_thread"));
int rpc_thread_count = atoi(munit_parameters_get(params, "rpc_thread_count"));
int use_progress_thread
= atoi(munit_parameters_get(params, "use_progress_thread"));
int rpc_thread_count
= atoi(munit_parameters_get(params, "rpc_thread_count"));

struct test_context* ctx = (struct test_context*)data;

ctx->mid = margo_init(protocol, MARGO_SERVER_MODE,
use_progress_thread, rpc_thread_count);
ctx->mid = margo_init(protocol, MARGO_SERVER_MODE, use_progress_thread,
rpc_thread_count);
munit_assert_not_null(ctx->mid);

margo_finalize(ctx->mid);

ctx->mid = margo_init(protocol, MARGO_SERVER_MODE,
use_progress_thread, rpc_thread_count);
ctx->mid = margo_init(protocol, MARGO_SERVER_MODE, use_progress_thread,
rpc_thread_count);
munit_assert_not_null(ctx->mid);

margo_finalize(ctx->mid);
Expand All @@ -53,19 +55,21 @@
static MunitResult init_cycle_client(const MunitParameter params[], void* data)
{
const char* protocol = munit_parameters_get(params, "protocol");
int use_progress_thread = atoi(munit_parameters_get(params, "use_progress_thread"));
int rpc_thread_count = atoi(munit_parameters_get(params, "rpc_thread_count"));
int use_progress_thread
= atoi(munit_parameters_get(params, "use_progress_thread"));
int rpc_thread_count
= atoi(munit_parameters_get(params, "rpc_thread_count"));

struct test_context* ctx = (struct test_context*)data;

ctx->mid = margo_init(protocol, MARGO_CLIENT_MODE,
use_progress_thread, rpc_thread_count);
ctx->mid = margo_init(protocol, MARGO_CLIENT_MODE, use_progress_thread,
rpc_thread_count);
munit_assert_not_null(ctx->mid);

margo_finalize(ctx->mid);

ctx->mid = margo_init(protocol, MARGO_CLIENT_MODE,
use_progress_thread, rpc_thread_count);
ctx->mid = margo_init(protocol, MARGO_CLIENT_MODE, use_progress_thread,
rpc_thread_count);
munit_assert_not_null(ctx->mid);

margo_finalize(ctx->mid);
Expand All @@ -86,73 +90,78 @@
static MunitResult finalize_and_wait(const MunitParameter params[], void* data)
{
const char* protocol = munit_parameters_get(params, "protocol");
int use_progress_thread = atoi(munit_parameters_get(params, "use_progress_thread"));
int rpc_thread_count = atoi(munit_parameters_get(params, "rpc_thread_count"));
int use_progress_thread
= atoi(munit_parameters_get(params, "use_progress_thread"));
int rpc_thread_count
= atoi(munit_parameters_get(params, "rpc_thread_count"));

struct test_context* ctx = (struct test_context*)data;

margo_set_environment(NULL);
ABT_init(0, NULL);

/* init and finalize_and_wait */
ctx->mid = margo_init(protocol, MARGO_SERVER_MODE,
use_progress_thread, rpc_thread_count);
ctx->mid = margo_init(protocol, MARGO_SERVER_MODE, use_progress_thread,
rpc_thread_count);
munit_assert_not_null(ctx->mid);

margo_finalize_and_wait(ctx->mid);

/* init and finalize_and_wait but issue a slow RPC first */
ctx->mid = margo_init(protocol, MARGO_SERVER_MODE,
use_progress_thread, rpc_thread_count);
ctx->mid = margo_init(protocol, MARGO_SERVER_MODE, use_progress_thread,
rpc_thread_count);
munit_assert_not_null(ctx->mid);

hg_id_t rpc_id = MARGO_REGISTER(ctx->mid, "rpc", void, void, rpc_ult);
margo_registered_disable_response(ctx->mid, rpc_id, HG_TRUE);

hg_handle_t handle = HG_HANDLE_NULL;
hg_addr_t addr = HG_ADDR_NULL;
hg_addr_t addr = HG_ADDR_NULL;

margo_addr_self(ctx->mid, &addr);
margo_create(ctx->mid, addr, rpc_id, &handle);
margo_addr_free(ctx->mid, addr);
margo_forward(handle, NULL);
margo_destroy(handle);

double t1 = ABT_get_wtime();
// double t1 = ABT_get_wtime();
margo_finalize_and_wait(ctx->mid);
double t2 = ABT_get_wtime();
//munit_assert_double(t2-t1, >=, 0.5);
// double t2 = ABT_get_wtime();
// munit_assert_double(t2-t1, >=, 0.5);

ABT_finalize();

return MUNIT_OK;
}

static MunitResult ref_incr_and_release(const MunitParameter params[], void* data)
static MunitResult ref_incr_and_release(const MunitParameter params[],
void* data)
{
const char* protocol = munit_parameters_get(params, "protocol");
int use_progress_thread = atoi(munit_parameters_get(params, "use_progress_thread"));
int rpc_thread_count = atoi(munit_parameters_get(params, "rpc_thread_count"));
int use_progress_thread
= atoi(munit_parameters_get(params, "use_progress_thread"));
int rpc_thread_count
= atoi(munit_parameters_get(params, "rpc_thread_count"));

struct test_context* ctx = (struct test_context*)data;

margo_set_environment(NULL);
ABT_init(0, NULL);

/* init and finalize_and_wait */
ctx->mid = margo_init(protocol, MARGO_SERVER_MODE,
use_progress_thread, rpc_thread_count);
ctx->mid = margo_init(protocol, MARGO_SERVER_MODE, use_progress_thread,
rpc_thread_count);
munit_assert_not_null(ctx->mid);

margo_finalize_and_wait(ctx->mid);

/* init and finalize_and_wait but issue a slow RPC first */
ctx->mid = margo_init(protocol, MARGO_SERVER_MODE,
use_progress_thread, rpc_thread_count);
ctx->mid = margo_init(protocol, MARGO_SERVER_MODE, use_progress_thread,
rpc_thread_count);
munit_assert_not_null(ctx->mid);

unsigned refcount = 1234;
hg_return_t hret = margo_instance_ref_count(ctx->mid, &refcount);
unsigned refcount = 1234;
hg_return_t hret = margo_instance_ref_count(ctx->mid, &refcount);
munit_assert_int(hret, ==, HG_SUCCESS);
munit_assert_int(refcount, ==, 1);

Expand All @@ -164,7 +173,7 @@
munit_assert_int(refcount, ==, 2);

bool is_finalized = true;
hret = margo_instance_is_finalized(ctx->mid, &is_finalized);
hret = margo_instance_is_finalized(ctx->mid, &is_finalized);
munit_assert_int(hret, ==, HG_SUCCESS);
munit_assert(!is_finalized);

Expand All @@ -186,59 +195,63 @@
return MUNIT_OK;
}

static void kill_test(void* args) {
static void kill_test(void* args)
{
volatile int* x = (int*)args;
double t = ABT_get_wtime();
while(ABT_get_wtime() - t < 1.0) {
ABT_thread_yield();
}
if(*x == 1) return;
double t = ABT_get_wtime();
while (ABT_get_wtime() - t < 1.0) { ABT_thread_yield(); }
if (*x == 1)
return;
else {
x = NULL;
x = NULL;

Check warning on line 206 in tests/unit-tests/margo-init.c

View check run for this annotation

Codecov / codecov/patch

tests/unit-tests/margo-init.c#L206

Added line #L206 was not covered by tests
*x = 1; // segfault
}
}

void my_func(void*) {}

static MunitResult multiple_pools_progress_loop(const MunitParameter params[], void* data)
static MunitResult multiple_pools_progress_loop(const MunitParameter params[],
void* data)
{
const char* config = "{\n"
"\"argobots\": {"
"\"pools\": ["
"{\"name\":\"__primary__\",\"access\":\"mpmc\",\"kind\":\"fifo_wait\"},"
"{\"name\":\"p1\",\"access\":\"mpmc\",\"kind\":\"fifo_wait\"},"
"{\"name\":\"p2\",\"access\":\"mpmc\",\"kind\":\"fifo_wait\"}"
"],"
"\"xstreams\": ["
"{\"name\":\"__primary__\","
"\"scheduler\":{"
"\"pools\":[\"__primary__\",\"p1\"],"
"\"type\":\"basic_wait\""
"}"
"},"
"{\"name\":\"es1\","
"\"scheduler\":{"
"\"pools\":[\"p2\"],"
"\"type\":\"basic_wait\""
"}"
"}"
"]"
"},"
"\"progress_pool\":\"p1\","
"\"rpc_pool\":\"p1\""
"}";
const char* config
= "{\n"
"\"argobots\": {"
"\"pools\": ["
"{\"name\":\"__primary__\",\"access\":\"mpmc\",\"kind\":\"fifo_"
"wait\"},"
"{\"name\":\"p1\",\"access\":\"mpmc\",\"kind\":\"fifo_wait\"},"
"{\"name\":\"p2\",\"access\":\"mpmc\",\"kind\":\"fifo_wait\"}"
"],"
"\"xstreams\": ["
"{\"name\":\"__primary__\","
"\"scheduler\":{"
"\"pools\":[\"__primary__\",\"p1\"],"
"\"type\":\"basic_wait\""
"}"
"},"
"{\"name\":\"es1\","
"\"scheduler\":{"
"\"pools\":[\"p2\"],"
"\"type\":\"basic_wait\""
"}"
"}"
"]"
"},"
"\"progress_pool\":\"p1\","
"\"rpc_pool\":\"p1\""
"}";

struct margo_init_info info = MARGO_INIT_INFO_INITIALIZER;
info.json_config = config;
info.json_config = config;
margo_instance_id mid = margo_init_ext("na+sm", MARGO_SERVER_MODE, &info);

struct margo_pool_info p2 = {0};
margo_find_pool_by_name(mid, "p2", &p2);

ABT_thread ult, killer;
ABT_thread ult, killer;
volatile int x = 0;
ABT_thread_create(p2.pool, kill_test, (void*)&x, ABT_THREAD_ATTR_NULL, &killer);
ABT_thread_create(p2.pool, kill_test, (void*)&x, ABT_THREAD_ATTR_NULL,
&killer);
ABT_thread_create(p2.pool, my_func, NULL, ABT_THREAD_ATTR_NULL, &ult);
ABT_thread_join(ult);
x = 1;
Expand All @@ -250,40 +263,35 @@
return MUNIT_OK;
}

static char* protocol_params[] = {
"na+sm", NULL
};
static char* protocol_params[] = {"na+sm", NULL};

static char* use_progress_thread_params[] = {
"0","1", NULL
};
static char* use_progress_thread_params[] = {"0", "1", NULL};

static char* rpc_thread_count_params[] = {
"0", "1", "2", "-1", NULL
};
static char* rpc_thread_count_params[] = {"0", "1", "2", "-1", NULL};

static MunitParameterEnum test_params[] = {
{ "protocol", protocol_params },
{ "use_progress_thread", use_progress_thread_params },
{ "rpc_thread_count", rpc_thread_count_params },
{ NULL, NULL }
};
static MunitParameterEnum test_params[]
= {{"protocol", protocol_params},
{"use_progress_thread", use_progress_thread_params},
{"rpc_thread_count", rpc_thread_count_params},
{NULL, NULL}};

static MunitTest tests[] = {
{ "/init-cycle-client", init_cycle_client, test_context_setup, test_context_tear_down, MUNIT_TEST_OPTION_NONE, test_params},
{ "/init-cycle-server", init_cycle_server, test_context_setup, test_context_tear_down, MUNIT_TEST_OPTION_NONE, test_params},
{ "/finalize-and-wait", finalize_and_wait, test_context_setup, test_context_tear_down, MUNIT_TEST_OPTION_NONE, test_params},
{ "/ref-incr-and-release", ref_incr_and_release, test_context_setup, test_context_tear_down, MUNIT_TEST_OPTION_NONE, test_params},
{ "/multiple-pools-progress-loop", multiple_pools_progress_loop, test_context_setup, test_context_tear_down, MUNIT_TEST_OPTION_NONE, NULL},
{ NULL, NULL, NULL, NULL, MUNIT_TEST_OPTION_NONE, NULL }
};

static const MunitSuite test_suite = {
"/margo", tests, NULL, 1, MUNIT_SUITE_OPTION_NONE
};


int main(int argc, char **argv)
{"/init-cycle-client", init_cycle_client, test_context_setup,
test_context_tear_down, MUNIT_TEST_OPTION_NONE, test_params},
{"/init-cycle-server", init_cycle_server, test_context_setup,
test_context_tear_down, MUNIT_TEST_OPTION_NONE, test_params},
{"/finalize-and-wait", finalize_and_wait, test_context_setup,
test_context_tear_down, MUNIT_TEST_OPTION_NONE, test_params},
{"/ref-incr-and-release", ref_incr_and_release, test_context_setup,
test_context_tear_down, MUNIT_TEST_OPTION_NONE, test_params},
{"/multiple-pools-progress-loop", multiple_pools_progress_loop,
test_context_setup, test_context_tear_down, MUNIT_TEST_OPTION_NONE, NULL},
{NULL, NULL, NULL, NULL, MUNIT_TEST_OPTION_NONE, NULL}};

static const MunitSuite test_suite
= {"/margo", tests, NULL, 1, MUNIT_SUITE_OPTION_NONE};

int main(int argc, char** argv)
{
return munit_suite_main(&test_suite, NULL, argc, argv);
}
Loading