Skip to content
Browse files

test, bench: add --list option to runners, prints available tests

  • Loading branch information...
1 parent 6c32055 commit 7dda111306309d72ed8234d41767cbaca1abe42b @bnoordhuis bnoordhuis committed Aug 6, 2011
Showing with 83 additions and 10 deletions.
  1. +18 −8 test/run-benchmarks.c
  2. +6 −2 test/run-tests.c
  3. +51 −0 test/runner.c
  4. +8 −0 test/runner.h
View
26 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);
+}
View
8 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;
}
View
51 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);
+ }
+ }
+}
View
8 test/runner.h
@@ -22,6 +22,8 @@
#ifndef RUNNER_H_
#define RUNNER_H_
+#include <stdio.h> /* FILE */
+
/*
* The maximum number of processes (main + helpers) that a test / benchmark
@@ -105,6 +107,12 @@ 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-<platform>.h
* All functions return 0 on success, -1 on failure, unless specified
* otherwise.

0 comments on commit 7dda111

Please sign in to comment.
Something went wrong with that request. Please try again.