From 7dda111306309d72ed8234d41767cbaca1abe42b Mon Sep 17 00:00:00 2001 From: Ben Noordhuis Date: Sat, 6 Aug 2011 23:55:35 +0200 Subject: [PATCH] test, bench: add --list option to runners, prints available tests --- test/run-benchmarks.c | 26 +++++++++++++++------- test/run-tests.c | 8 +++++-- test/runner.c | 51 +++++++++++++++++++++++++++++++++++++++++++ test/runner.h | 8 +++++++ 4 files changed, 83 insertions(+), 10 deletions(-) diff --git a/test/run-benchmarks.c b/test/run-benchmarks.c index d04c78d5e..af11beb9b 100644 --- a/test/run-benchmarks.c +++ b/test/run-benchmarks.c @@ -32,23 +32,33 @@ /* The time in milliseconds after which a single benchmark times out. */ #define BENCHMARK_TIMEOUT 60000 +static int maybe_run_test(int argc, char **argv); + int main(int argc, char **argv) { platform_init(argc, argv); switch (argc) { case 1: return run_tests(BENCHMARK_TIMEOUT, 1); - case 2: { - if (strcmp(argv[1], "spawn_helper") == 0) { - printf("hello world\n"); - return 42; - } - - return run_test(argv[1], BENCHMARK_TIMEOUT, 1); - } + case 2: return maybe_run_test(argc, argv); case 3: return run_test_part(argv[1], argv[2]); default: LOGF("Too many arguments.\n"); return 1; } } + + +static int maybe_run_test(int argc, char **argv) { + if (strcmp(argv[1], "--list") == 0) { + print_tests(stdout); + return 0; + } + + if (strcmp(argv[1], "spawn_helper") == 0) { + printf("hello world\n"); + return 42; + } + + return run_test(argv[1], BENCHMARK_TIMEOUT, 1); +} diff --git a/test/run-tests.c b/test/run-tests.c index fca3a6cb9..283ff2bcc 100644 --- a/test/run-tests.c +++ b/test/run-tests.c @@ -33,11 +33,10 @@ #define TEST_TIMEOUT 5000 static int maybe_run_test(int argc, char **argv); +static void list_all_tests(void); int main(int argc, char **argv) { - int i; - platform_init(argc, argv); switch (argc) { @@ -52,6 +51,11 @@ int main(int argc, char **argv) { static int maybe_run_test(int argc, char **argv) { + if (strcmp(argv[1], "--list") == 0) { + print_tests(stdout); + return 0; + } + if (strcmp(argv[1], "spawn_helper1") == 0) { return 1; } diff --git a/test/runner.c b/test/runner.c index 483800466..73a3864ee 100644 --- a/test/runner.c +++ b/test/runner.c @@ -258,3 +258,54 @@ int run_test_part(const char* test, const char* part) { LOGF("No test part with that name: %s:%s\n", test, part); return 255; } + + +static int compare_task(const void* va, const void* vb) { + const task_entry_t* a = va; + const task_entry_t* b = vb; + return strcmp(a->task_name, b->task_name); +} + + +static int find_helpers(const task_entry_t* task, const task_entry_t** helpers) { + const task_entry_t* helper; + int n_helpers; + + for (n_helpers = 0, helper = TASKS; helper->main; helper++) { + if (helper->is_helper && strcmp(helper->task_name, task->task_name) == 0) { + *helpers++ = helper; + n_helpers++; + } + } + + return n_helpers; +} + + +void print_tests(FILE* stream) { + const task_entry_t* helpers[1024]; + const task_entry_t* task; + int n_helpers; + int n_tasks; + int i; + + for (n_tasks = 0, task = TASKS; task->main; n_tasks++, task++); + qsort(TASKS, n_tasks, sizeof(TASKS[0]), compare_task); + + for (task = TASKS; task->main; task++) { + if (task->is_helper) { + continue; + } + + n_helpers = find_helpers(task, helpers); + if (n_helpers) { + printf("%-25s (helpers:", task->task_name); + for (i = 0; i < n_helpers; i++) { + printf(" %s", helpers[i]->process_name); + } + printf(")\n"); + } else { + printf("%s\n", task->task_name); + } + } +} diff --git a/test/runner.h b/test/runner.h index 59eff1ed3..3b93ffe99 100644 --- a/test/runner.h +++ b/test/runner.h @@ -22,6 +22,8 @@ #ifndef RUNNER_H_ #define RUNNER_H_ +#include /* FILE */ + /* * The maximum number of processes (main + helpers) that a test / benchmark @@ -104,6 +106,12 @@ int run_test(const char* test, int timeout, int benchmark_output); int run_test_part(const char* test, const char* part); +/* + * Print tests in sorted order to `stream`. Used by `./run-tests --list`. + */ +void print_tests(FILE* stream); + + /* * Stuff that should be implemented by test-runner-.h * All functions return 0 on success, -1 on failure, unless specified