X-Git-Url: http://git.barrelfish.org/?p=barrelfish;a=blobdiff_plain;f=usr%2Ftests%2Fproc_mgmt_test%2Fmain.c;h=09e1ccc19578c17d47c526efe2f87ad70ba78a1d;hp=82e69040ddff8fd50b761970004059016b1d1880;hb=23d2c2bec84d178791f3c252112a31e35abf0c15;hpb=626764cf36dd89a98ee4a2f45cc613c48b010dfd diff --git a/usr/tests/proc_mgmt_test/main.c b/usr/tests/proc_mgmt_test/main.c index 82e6904..09e1ccc 100644 --- a/usr/tests/proc_mgmt_test/main.c +++ b/usr/tests/proc_mgmt_test/main.c @@ -15,61 +15,51 @@ #include #include -#include +#include +#include #include #define PROC_MGMT_BENCH 1 -#define PROC_MGMT_BENCH_MIN_RUNS 120 +#define PROC_MGMT_BENCH_MIN_RUNS 20 -int my_id; -// int total_ids; - -static void test_spawn(coreid_t core_id, char *argv[], - struct capref *ret_domain_cap) +static errval_t test_spawn(coreid_t core_id, char *argv[], + struct capref *ret_domain_cap) { assert(ret_domain_cap != NULL); - errval_t err = proc_mgmt_spawn_program(core_id, - "/x86_64/sbin/proc_mgmt_test", - argv, NULL, 0, ret_domain_cap); - if (err_is_ok(err)) { - // printf("OK: my_id=%i, spawn(%u, proc_mgmt_test)\n", my_id, core_id); - } else { - // printf("FAIL: spawn(%u, proc_mgmt_test), err=%s\n", core_id, - // err_getstring(err)); + errval_t err = spawn_program(core_id, "/x86_64/sbin/proc_mgmt_test", + argv, NULL, 0, ret_domain_cap); + if (err_is_fail(err)) { + return err; } + return SYS_ERR_OK; +} + +/* +static void test_span(coreid_t core_id) +{ + errval_t err = proc_mgmt_span(core_id); + if (err_is_fail(err)) { + } +} + +static void test_kill(struct capref domain_cap) +{ + errval_t err = proc_mgmt_kill(domain_cap); + if (err_is_ok(err)) { + USER_PANIC("Failed killing domain") + } } -// static void test_span(coreid_t core_id) -// { -// errval_t err = proc_mgmt_span(core_id); -// if (err_is_ok(err)) { -// printf("OK: span(%u)\n", core_id); -// } else { -// printf("FAIL: span(%u), err=%s\n", core_id, err_getstring(err)); -// } -// } - -// static void test_kill(struct capref domain_cap) -// { -// errval_t err = proc_mgmt_kill(domain_cap); -// if (err_is_ok(err)) { -// printf("OK: kill\n"); -// } else { -// printf("FAIL: kill, err=%s\n", err_getstring(err)); -// } -// } - -// static void test_wait(struct capref domain_cap) -// { -// uint8_t code; -// errval_t err = proc_mgmt_wait(domain_cap, &code); -// if (err_is_ok(err)) { -// printf("OK: wait, code=%u\n", code); -// } else { -// printf("FAIL: wait, err=%s\n", err_getstring(err)); -// } -// } +static void test_wait(struct capref domain_cap) +{ + uint8_t code; + errval_t err = proc_mgmt_wait(domain_cap, &code); + if (err_is_fail(err)) { + USER_PANIC("Failed waiting for domain"); + } +} +*/ static inline cycles_t calculate_time(cycles_t tsc_start, cycles_t tsc_end) { @@ -82,126 +72,179 @@ static inline cycles_t calculate_time(cycles_t tsc_start, cycles_t tsc_end) return result; } -int main(int argc, char **argv) +static void run_benchmark_spawn(coreid_t target_core) { + bench_init(); + + cycles_t tsc_start, tsc_end; + cycles_t result; + uint64_t tscperus; + + bench_ctl_t *ctl = calloc(1, sizeof(*ctl)); + ctl->mode = BENCH_MODE_FIXEDRUNS; + ctl->result_dimensions = 1; + ctl->min_runs = PROC_MGMT_BENCH_MIN_RUNS; + ctl->data = calloc(ctl->min_runs * ctl->result_dimensions, + sizeof(*ctl->data)); + + errval_t err = sys_debug_get_tsc_per_ms(&tscperus); + assert(err_is_ok(err)); + tscperus /= 1000; + + struct capref domain_cap; + + char *spawn_argv[] = { "proc_mgmt_test", "0", "norun", NULL}; + do { + tsc_start = bench_tsc(); + + test_spawn(target_core, spawn_argv, &domain_cap); + + tsc_end = bench_tsc(); + result = calculate_time(tsc_start, tsc_end); + } while (!bench_ctl_add_run(ctl, &result)); + + cap_destroy(domain_cap); + bench_ctl_dump_analysis(ctl, 0, "client", tscperus); + + bench_ctl_destroy(ctl); +} + +int main(int argc, char **argv) +{ + errval_t err; if (argc == 3) { - bench_init(); - - cycles_t tsc_start, tsc_end; - cycles_t result; - uint64_t tscperus; - - bench_ctl_t *ctl = calloc(1, sizeof(*ctl)); - ctl->mode = BENCH_MODE_FIXEDRUNS; - ctl->result_dimensions = 1; - ctl->min_runs = PROC_MGMT_BENCH_MIN_RUNS; - ctl->data = calloc(ctl->min_runs * ctl->result_dimensions, - sizeof(*ctl->data)); - - errval_t err = sys_debug_get_tsc_per_ms(&tscperus); - assert(err_is_ok(err)); - tscperus /= 1000; - - coreid_t target_core = 0;//strcmp(argv[1], "1") == 0 ? 1 : 2; - char *spawn_argv[] = { "proc_mgmt_test", "noop", NULL }; - my_id = atoi(argv[1]); - struct capref domain_cap; - // total_ids = atoi(argv[2]); - - barrelfish_usleep((0 - 10 * my_id) * 1000 * 1000); - - // ctl = bench_ctl_init(BENCH_MODE_FIXEDRUNS, 1, 100); - do { - // debug_printf("BEFORE test_spawn\n"); - tsc_start = bench_tsc(); - - test_spawn(target_core, spawn_argv, &domain_cap); - // test_wait(domain_cap); - - tsc_end = bench_tsc(); - result = calculate_time(tsc_start, tsc_end); - - barrelfish_usleep(2 * 1000 * 1000); - }while (!bench_ctl_add_run(ctl, &result)); - // } while (true); - - bench_ctl_dump_analysis(ctl, 0, "client", tscperus); - - bench_ctl_destroy(ctl); - - barrelfish_usleep(5 * 1000 * 1000); - while (true); - - printf("TEST DONE\n"); + if (strcmp("starter", argv[2]) == 0) { + // just continue; + } else if (strcmp("norun", argv[2]) == 0) { + // directly return + return 0; + } else if (strcmp("run", argv[2]) == 0) { + // Run infinite loop + printf("Running infinite Loop"); + while(true) { + printf("Running infinite Loop"); + barrelfish_usleep(1000*1000); + event_dispatch_non_block(get_default_waitset()); + } + } else if (strcmp("sleeper", argv[2]) == 0) { + // Process that we wait for to finish + printf("Running for a few seconds \n"); + barrelfish_usleep(10*1000*1000); + printf("Sleeper exit\n"); + return 0; + } else if (strcmp("span", argv[2]) == 0) { + // Process that spans domains + if (disp_get_core_id() == 0) { + spawn_span(1); + } else { + spawn_span(0); + } + while(true) { + event_dispatch(get_default_waitset()); + } + } else { + USER_PANIC("Unknown Role \n "); + } + } else { - // for(;;) { - // errval_t err = event_dispatch(get_default_waitset()); - // if(err_is_fail(err)) { - // USER_PANIC_ERR(err, "event_dispatch"); - // } - // } - } + USER_PANIC("Not enough arguments to run test \n "); + } - // printf("HELLO from proc_mgmt_test, argc=%u\n", argc); - // // errval_t err; - // if (argc == 1) { - // struct capref domain_cap_0; - // char *argv_0[] = { "proc_mgmt_test", "1", NULL }; - // test_spawn(0, argv_0, &domain_cap_0); - // barrelfish_usleep(5*1000*1000); - // // while (true); - // test_kill(domain_cap_0); - // test_wait(domain_cap_0); - // // barrelfish_usleep(0 * 1*1*1); - - // struct capref domain_cap_1; - // char *argv_1[] = { "proc_mgmt_test", "1", "2", NULL }; - // test_spawn(1, argv_1, &domain_cap_1); - // test_wait(domain_cap_1); - - // printf("TEST DONE\n"); - // // barrelfish_usleep(5*1000*1000); - - // // err = proc_mgmt_kill(domain_cap); - // // if (err_is_fail(err)) { - // // USER_PANIC_ERR(err, "failed to kill proc_mgmt_test"); - // // } - - // // uint8_t status; - // // err = proc_mgmt_wait(domain_cap, &status); - // // printf("2nd proc_mgmt_test finished with status %u\n", status); - // } else if (argc == 2) { - // // test_span(disp_get_core_id() == 0 ? 1 : 0); - - // // // struct capability ret; - // // // err = debug_cap_identify(cap_domainid, &ret); - // // // if (err_is_fail(err)) { - // // // USER_PANIC_ERR(err, "failed to identify cap_domainid"); - // // // } - // // // assert(ret.type == ObjType_Domain); - // // // printf("proc_mgmt_test: cap_domainid = { .coreid=%u, .core_local_id=%u " - // // // "}\n", ret.u.domain.coreid, ret.u.domain.core_local_id); - - // // // coreid_t other_core = disp_get_core_id() == 0 ? 1 : 0; - // // // err = proc_mgmt_span(other_core);//domain_new_dispatcher(other_core, span_cb, NULL); - // // // if (err_is_fail(err)) { - // // // USER_PANIC_ERR(err, "failed to span proc_mgmt_test on core %u\n", - // // // other_core); - // // // } - - // // // barrelfish_usleep(5*1000*1000); - // // // printf("Main dispatcher exiting...\n"); - - // for(;;) { - // errval_t err = event_dispatch(get_default_waitset()); - // if(err_is_fail(err)) { - // USER_PANIC_ERR(err, "event_dispatch"); - // } - // } - // } else { - // // barrelfish_usleep(5 * 1000 * 1000); - // // We'll just exit normally here, spawner should be waiting for us. - // } + struct capref domain_cap; + printf("Testing kill on same core\n"); + char *spawn_argv[] = { "proc_mgmt_test", "0", "run", NULL}; + err = test_spawn(2, spawn_argv, &domain_cap); + if (err_is_fail(err)) { + USER_PANIC("Failed spawning program proc_mgmt_test \n"); + } + + //starting a process takes some time ... + barrelfish_usleep(5*1000*1000); + + printf("Killing process \n"); + err = spawn_kill(domain_cap); + if (err_is_fail(err)) { + USER_PANIC("Failed waiting for domain \n"); + } + + // Killing a process takes some time ... + barrelfish_usleep(5*1000*1000); + + printf("Testing kill on other core\n"); + err = test_spawn(1, spawn_argv, &domain_cap); + if (err_is_fail(err)) { + USER_PANIC("Failed spawning program proc_mgmt_test \n"); + } + + barrelfish_usleep(5*1000*1000); + + printf("Killing process \n"); + err = spawn_kill(domain_cap); + if (err_is_fail(err)) { + USER_PANIC("Failed waiting for domain \n"); + } + + // TODO check if process was killed + printf("Testing spaning on different core\n"); + char *spawn_argv3[] = { "proc_mgmt_test", "0", "span", NULL}; + err = test_spawn(0, spawn_argv3, &domain_cap); + if (err_is_fail(err)) { + USER_PANIC("Failed spawning program proc_mgmt_test \n"); + } + printf("Testing spaning on same core\n"); + err = test_spawn(2, spawn_argv3, &domain_cap); + if (err_is_fail(err)) { + USER_PANIC("Failed spawning program proc_mgmt_test \n"); + } + + printf("Testing wait on different core process\n"); + char *spawn_argv2[] = { "proc_mgmt_test", "0", "sleeper"}; + err = test_spawn(0, spawn_argv2, &domain_cap); + if (err_is_fail(err)) { + USER_PANIC("Failed spawning program proc_mgmt_test \n"); + } + + barrelfish_usleep(5*1000*1000); + + uint8_t code; + printf("Waiting for process on different core to finish \n"); + err = spawn_wait(domain_cap, &code, false); + if (err_is_fail(err)) { + USER_PANIC("Failed waiting for domain \n"); + } + printf("Unblocked \n"); + + printf("Testing wait on same core process\n"); + err = test_spawn(2, spawn_argv2, &domain_cap); + if (err_is_fail(err)) { + USER_PANIC("Failed spawning program proc_mgmt_test \n"); + } + + barrelfish_usleep(5*1000*1000); + + printf("Waiting for process on same core to finish \n"); + err = spawn_wait(domain_cap, &code, true); + if (err_is_fail(err)) { + USER_PANIC("Failed waiting for domain \n"); + } + printf("Nowait hang return code %d \n", code); + err = spawn_wait(domain_cap, &code, false); + if (err_is_fail(err)) { + USER_PANIC("Failed waiting for domain \n"); + } + printf("Unblocked \n"); + + err = spawn_wait(domain_cap, &code, true); + if (err_is_fail(err)) { + USER_PANIC("Failed waiting for domain \n"); + } + printf("Nowait hang return code %d \n", code); + printf("Running benchmarks core 0 \n"); + run_benchmark_spawn(0); + printf("Running benchmarks core 3 \n"); + run_benchmark_spawn(3); + + printf("TEST DONE\n"); return 0; }