proc_mgmt: adding tests
authorRoni Häcki <roni.haecki@inf.ethz.ch>
Fri, 29 Sep 2017 14:42:52 +0000 (16:42 +0200)
committerRoni Häcki <roni.haecki@inf.ethz.ch>
Fri, 29 Sep 2017 14:42:52 +0000 (16:42 +0200)
Still some more debugging required when the process exits, otherwise the test seems to
be working.

Signed-off-by: Roni Häcki <roni.haecki@inf.ethz.ch>

usr/tests/proc_mgmt_test/main.c

index b70acff..46a6953 100644 (file)
 #include <barrelfish/barrelfish.h>
 #include <barrelfish/deferred.h>
 #include <barrelfish/proc_mgmt_client.h>
+#include <barrelfish/spawn_client.h>
 #include <bench/bench.h>
 
 #define PROC_MGMT_BENCH 1
-#define PROC_MGMT_BENCH_MIN_RUNS 150
-
-int my_id;
+#define PROC_MGMT_BENCH_MIN_RUNS 20
 // 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));
+       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,125 +73,171 @@ 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)
 {
-       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));
+    bench_init();
 
-               errval_t err = sys_debug_get_tsc_per_ms(&tscperus);
-           assert(err_is_ok(err));
-           tscperus /= 1000;
+    cycles_t tsc_start, tsc_end;
+    cycles_t result;
+    uint64_t tscperus;
 
-               coreid_t target_core = 7;//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]);
+    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));
 
-        barrelfish_usleep((0 - 1 * my_id) * 100 * 1000);
+    errval_t err = sys_debug_get_tsc_per_ms(&tscperus);
+    assert(err_is_ok(err));
+    tscperus /= 1000;
 
-           // ctl = bench_ctl_init(BENCH_MODE_FIXEDRUNS, 1, 100);
-           do {
-               // debug_printf("BEFORE test_spawn\n");
-               tsc_start = bench_tsc();
+    struct capref domain_cap;
 
-                       test_spawn(target_core, spawn_argv, &domain_cap);
-                       // test_wait(domain_cap);
+    char *spawn_argv[] = { "proc_mgmt_test", "0", "norun", NULL};
+    do {
+        tsc_start = bench_tsc();
 
-               tsc_end = bench_tsc();
-               result = calculate_time(tsc_start, tsc_end);
+        test_spawn(target_core, spawn_argv, &domain_cap);
 
-                       barrelfish_usleep(0 * 1000 * 1000);
-           }while (!bench_ctl_add_run(ctl, &result));
-           // } while (true);
+        tsc_end = bench_tsc();
+        result = calculate_time(tsc_start, tsc_end);
+    } while (!bench_ctl_add_run(ctl, &result));    
 
-           bench_ctl_dump_analysis(ctl, 0, "client", tscperus);
+    cap_destroy(domain_cap);
+    bench_ctl_dump_analysis(ctl, 0, "client", tscperus);
 
-       bench_ctl_destroy(ctl);
+    bench_ctl_destroy(ctl);
+}
+*/
 
-               barrelfish_usleep(5 * 1000 * 1000);
+int main(int argc, char **argv)
+{   
+    errval_t err;
+       if (argc == 3) {
+        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) {
+                proc_mgmt_span(1);
+            } else {
+                proc_mgmt_span(0);
+            }
+            while(true) {
+                event_dispatch(get_default_waitset());
+            }
+        } else {
+            USER_PANIC("Unknown Role \n ");
+        }
 
-               printf("TEST DONE\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 = proc_mgmt_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 = proc_mgmt_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 = proc_mgmt_wait(domain_cap, &code);
+       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 = proc_mgmt_wait(domain_cap, &code);
+       if (err_is_fail(err)) {
+        USER_PANIC("Failed waiting for domain \n");
+       }
+    printf("Unblocked \n");
+
+    /*
+    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;
 }