diff options
| author | Bjoern Brandenburg <bbb@mpi-sws.org> | 2012-08-01 03:13:56 -0400 |
|---|---|---|
| committer | Bjoern Brandenburg <bbb@mpi-sws.org> | 2012-08-01 03:13:56 -0400 |
| commit | 92403908792f38bf4f420ea2a552bf73702ee681 (patch) | |
| tree | d4f3a48a2def23393698837e2f508e4c0cee87e0 | |
| parent | 41884912179240ae4d22cf67984522d5225a7d26 (diff) | |
Run test suite for currently active plugin by default
Try to infer current plugin if no plugin is specified.
| -rw-r--r-- | tests/runner.c | 40 |
1 files changed, 37 insertions, 3 deletions
diff --git a/tests/runner.c b/tests/runner.c index 11470bc..0fd3aa7 100644 --- a/tests/runner.c +++ b/tests/runner.c | |||
| @@ -6,6 +6,7 @@ | |||
| 6 | #include <string.h> | 6 | #include <string.h> |
| 7 | #include <stdio.h> | 7 | #include <stdio.h> |
| 8 | 8 | ||
| 9 | #define PROC_ACTIVE_PLUGIN "/proc/litmus/active_plugin" | ||
| 9 | 10 | ||
| 10 | /* auto generated by Makefile */ | 11 | /* auto generated by Makefile */ |
| 11 | #include "../test_catalog.inc" | 12 | #include "../test_catalog.inc" |
| @@ -49,17 +50,50 @@ int run_tests(int* testidx, int num_tests, const char* plugin) | |||
| 49 | return ok; | 50 | return ok; |
| 50 | } | 51 | } |
| 51 | 52 | ||
| 53 | static int get_active_plugin(char *buf, size_t buf_size) | ||
| 54 | { | ||
| 55 | FILE *f; | ||
| 56 | size_t nread; | ||
| 57 | |||
| 58 | f = fopen(PROC_ACTIVE_PLUGIN, "r"); | ||
| 59 | if (f) { | ||
| 60 | /* proc files read in one go */ | ||
| 61 | nread = fread(buf, sizeof(char), buf_size - 1, f); | ||
| 62 | fclose(f); | ||
| 63 | |||
| 64 | /* remove trailing newline */ | ||
| 65 | if (nread > 0 && buf[nread - 1] == '\n') | ||
| 66 | nread--; | ||
| 67 | |||
| 68 | /* null terminate buffer */ | ||
| 69 | if (nread > 0) { | ||
| 70 | buf[nread] = '\0'; | ||
| 71 | return 1; | ||
| 72 | } | ||
| 73 | } | ||
| 74 | return 0; | ||
| 75 | } | ||
| 76 | |||
| 52 | #define streq(s1, s2) (!strcmp(s1, s2)) | 77 | #define streq(s1, s2) (!strcmp(s1, s2)) |
| 53 | 78 | ||
| 54 | int main(int argc, char** argv) | 79 | int main(int argc, char** argv) |
| 55 | { | 80 | { |
| 56 | int ok, i; | 81 | int ok, i; |
| 82 | char active_plugin[256]; | ||
| 83 | char *plugin_name = NULL; | ||
| 57 | 84 | ||
| 58 | printf("** LITMUS^RT test suite.\n"); | 85 | printf("** LITMUS^RT test suite.\n"); |
| 59 | 86 | ||
| 60 | if (argc == 2) { | 87 | if (argc == 2) |
| 88 | plugin_name = argv[1]; | ||
| 89 | else if (get_active_plugin(active_plugin, sizeof(active_plugin))) { | ||
| 90 | /* run tests for currently active plugin */ | ||
| 91 | plugin_name = active_plugin; | ||
| 92 | } | ||
| 93 | |||
| 94 | if (plugin_name) { | ||
| 61 | for (i = 0; i < NUM_PLUGINS; i++) | 95 | for (i = 0; i < NUM_PLUGINS; i++) |
| 62 | if (streq(testsuite[i].plugin, argv[1])) { | 96 | if (streq(testsuite[i].plugin, plugin_name)) { |
| 63 | ok = run_tests(testsuite[i].testcases, | 97 | ok = run_tests(testsuite[i].testcases, |
| 64 | testsuite[i].num_cases, | 98 | testsuite[i].num_cases, |
| 65 | testsuite[i].plugin); | 99 | testsuite[i].plugin); |
| @@ -67,7 +101,7 @@ int main(int argc, char** argv) | |||
| 67 | ok, testsuite[i].num_cases - ok); | 101 | ok, testsuite[i].num_cases - ok); |
| 68 | return ok == testsuite[i].num_cases ? 0 : 3; | 102 | return ok == testsuite[i].num_cases ? 0 : 3; |
| 69 | } | 103 | } |
| 70 | fprintf(stderr, "** Unknown plugin: '%s'\n", argv[1]); | 104 | fprintf(stderr, "** Unknown plugin: '%s'\n", plugin_name); |
| 71 | return 1; | 105 | return 1; |
| 72 | } else { | 106 | } else { |
| 73 | fprintf(stderr, "Usage: %s <plugin name>\n", argv[0]); | 107 | fprintf(stderr, "Usage: %s <plugin name>\n", argv[0]); |
