From 92403908792f38bf4f420ea2a552bf73702ee681 Mon Sep 17 00:00:00 2001 From: Bjoern Brandenburg Date: Wed, 1 Aug 2012 09:13:56 +0200 Subject: Run test suite for currently active plugin by default Try to infer current plugin if no plugin is specified. --- tests/runner.c | 40 +++++++++++++++++++++++++++++++++++++--- 1 file 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 @@ #include #include +#define PROC_ACTIVE_PLUGIN "/proc/litmus/active_plugin" /* auto generated by Makefile */ #include "../test_catalog.inc" @@ -49,17 +50,50 @@ int run_tests(int* testidx, int num_tests, const char* plugin) return ok; } +static int get_active_plugin(char *buf, size_t buf_size) +{ + FILE *f; + size_t nread; + + f = fopen(PROC_ACTIVE_PLUGIN, "r"); + if (f) { + /* proc files read in one go */ + nread = fread(buf, sizeof(char), buf_size - 1, f); + fclose(f); + + /* remove trailing newline */ + if (nread > 0 && buf[nread - 1] == '\n') + nread--; + + /* null terminate buffer */ + if (nread > 0) { + buf[nread] = '\0'; + return 1; + } + } + return 0; +} + #define streq(s1, s2) (!strcmp(s1, s2)) int main(int argc, char** argv) { int ok, i; + char active_plugin[256]; + char *plugin_name = NULL; printf("** LITMUS^RT test suite.\n"); - if (argc == 2) { + if (argc == 2) + plugin_name = argv[1]; + else if (get_active_plugin(active_plugin, sizeof(active_plugin))) { + /* run tests for currently active plugin */ + plugin_name = active_plugin; + } + + if (plugin_name) { for (i = 0; i < NUM_PLUGINS; i++) - if (streq(testsuite[i].plugin, argv[1])) { + if (streq(testsuite[i].plugin, plugin_name)) { ok = run_tests(testsuite[i].testcases, testsuite[i].num_cases, testsuite[i].plugin); @@ -67,7 +101,7 @@ int main(int argc, char** argv) ok, testsuite[i].num_cases - ok); return ok == testsuite[i].num_cases ? 0 : 3; } - fprintf(stderr, "** Unknown plugin: '%s'\n", argv[1]); + fprintf(stderr, "** Unknown plugin: '%s'\n", plugin_name); return 1; } else { fprintf(stderr, "Usage: %s \n", argv[0]); -- cgit v1.2.2