diff options
| author | Bjoern Brandenburg <bbb@mpi-sws.org> | 2015-07-27 11:50:14 -0400 |
|---|---|---|
| committer | Bjoern Brandenburg <bbb@mpi-sws.org> | 2015-07-27 11:50:14 -0400 |
| commit | a483e1f85dd78be6f9d6b8cdb024859983ec1f55 (patch) | |
| tree | bf5aa0ec6971a382b2d5c927c986e7e508d62b53 | |
| parent | 86468257446cf8639bc1e0d3b4cbe382321582a5 (diff) | |
Test suite: add -v (verbose) option to runtests
Logging PIDs makes finding the right message in kernel debug traces
easier...
| -rw-r--r-- | tests/runner.c | 54 |
1 files changed, 46 insertions, 8 deletions
diff --git a/tests/runner.c b/tests/runner.c index 0fd3aa7..ab6bbf6 100644 --- a/tests/runner.c +++ b/tests/runner.c | |||
| @@ -13,6 +13,8 @@ | |||
| 13 | 13 | ||
| 14 | #include "litmus.h" | 14 | #include "litmus.h" |
| 15 | 15 | ||
| 16 | int verbose = 0; | ||
| 17 | |||
| 16 | int run_test(struct testcase *tc) { | 18 | int run_test(struct testcase *tc) { |
| 17 | int status; | 19 | int status; |
| 18 | pid_t pid; | 20 | pid_t pid; |
| @@ -26,6 +28,10 @@ int run_test(struct testcase *tc) { | |||
| 26 | tc->function(); | 28 | tc->function(); |
| 27 | exit(0); | 29 | exit(0); |
| 28 | } else { | 30 | } else { |
| 31 | if (verbose) { | ||
| 32 | printf("[PID=%d] ", pid); | ||
| 33 | fflush(stdout); | ||
| 34 | } | ||
| 29 | /* parent: wait for completion of test */ | 35 | /* parent: wait for completion of test */ |
| 30 | SYSCALL( waitpid(pid, &status, 0) ); | 36 | SYSCALL( waitpid(pid, &status, 0) ); |
| 31 | if (WIFEXITED(status) && WEXITSTATUS(status) == 0) | 37 | if (WIFEXITED(status) && WEXITSTATUS(status) == 0) |
| @@ -74,18 +80,53 @@ static int get_active_plugin(char *buf, size_t buf_size) | |||
| 74 | return 0; | 80 | return 0; |
| 75 | } | 81 | } |
| 76 | 82 | ||
| 83 | const char *usage_msg = | ||
| 84 | "Usage: runtests OPTIONS [plugin name]\n" | ||
| 85 | " -v verbose (prints PIDs)\n" | ||
| 86 | "\n"; | ||
| 87 | |||
| 88 | void usage(char *error) { | ||
| 89 | int i; | ||
| 90 | fprintf(stderr, "%s\n%s", error, usage_msg); | ||
| 91 | fprintf(stderr, "Supported plugins: "); | ||
| 92 | for (i = 0; i < NUM_PLUGINS; i++) | ||
| 93 | fprintf(stderr, "%s ", testsuite[i].plugin); | ||
| 94 | fprintf(stderr, "\n"); | ||
| 95 | exit(1); | ||
| 96 | } | ||
| 97 | |||
| 77 | #define streq(s1, s2) (!strcmp(s1, s2)) | 98 | #define streq(s1, s2) (!strcmp(s1, s2)) |
| 78 | 99 | ||
| 100 | #define OPTSTR "v" | ||
| 101 | |||
| 79 | int main(int argc, char** argv) | 102 | int main(int argc, char** argv) |
| 80 | { | 103 | { |
| 81 | int ok, i; | 104 | int ok, i, opt; |
| 82 | char active_plugin[256]; | 105 | char active_plugin[256]; |
| 83 | char *plugin_name = NULL; | 106 | char *plugin_name = NULL; |
| 84 | 107 | ||
| 108 | while ((opt = getopt(argc, argv, OPTSTR)) != -1) { | ||
| 109 | switch (opt) { | ||
| 110 | case 'v': | ||
| 111 | verbose = 1; | ||
| 112 | break; | ||
| 113 | case ':': | ||
| 114 | usage("Argument missing."); | ||
| 115 | break; | ||
| 116 | case '?': | ||
| 117 | default: | ||
| 118 | usage("Bad argument."); | ||
| 119 | break; | ||
| 120 | } | ||
| 121 | } | ||
| 122 | |||
| 123 | argc -= optind; | ||
| 124 | argv += optind; | ||
| 125 | |||
| 85 | printf("** LITMUS^RT test suite.\n"); | 126 | printf("** LITMUS^RT test suite.\n"); |
| 86 | 127 | ||
| 87 | if (argc == 2) | 128 | if (argc == 1) |
| 88 | plugin_name = argv[1]; | 129 | plugin_name = argv[0]; |
| 89 | else if (get_active_plugin(active_plugin, sizeof(active_plugin))) { | 130 | else if (get_active_plugin(active_plugin, sizeof(active_plugin))) { |
| 90 | /* run tests for currently active plugin */ | 131 | /* run tests for currently active plugin */ |
| 91 | plugin_name = active_plugin; | 132 | plugin_name = active_plugin; |
| @@ -102,13 +143,10 @@ int main(int argc, char** argv) | |||
| 102 | return ok == testsuite[i].num_cases ? 0 : 3; | 143 | return ok == testsuite[i].num_cases ? 0 : 3; |
| 103 | } | 144 | } |
| 104 | fprintf(stderr, "** Unknown plugin: '%s'\n", plugin_name); | 145 | fprintf(stderr, "** Unknown plugin: '%s'\n", plugin_name); |
| 146 | usage(""); | ||
| 105 | return 1; | 147 | return 1; |
| 106 | } else { | 148 | } else { |
| 107 | fprintf(stderr, "Usage: %s <plugin name>\n", argv[0]); | 149 | usage("** Active plugin unknown"); |
| 108 | fprintf(stderr, "Supported plugins: "); | ||
| 109 | for (i = 0; i < NUM_PLUGINS; i++) | ||
| 110 | fprintf(stderr, "%s ", testsuite[i].plugin); | ||
| 111 | fprintf(stderr, "\n"); | ||
| 112 | return 2; | 150 | return 2; |
| 113 | } | 151 | } |
| 114 | } | 152 | } |
