Skip to content
This repository has been archived by the owner on May 4, 2018. It is now read-only.

Commit

Permalink
test, bench: add --list option to runners, prints available tests
Browse files Browse the repository at this point in the history
  • Loading branch information
bnoordhuis committed Aug 6, 2011
1 parent 6c32055 commit 7dda111
Show file tree
Hide file tree
Showing 4 changed files with 83 additions and 10 deletions.
26 changes: 18 additions & 8 deletions test/run-benchmarks.c
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -32,23 +32,33 @@
/* The time in milliseconds after which a single benchmark times out. */ /* The time in milliseconds after which a single benchmark times out. */
#define BENCHMARK_TIMEOUT 60000 #define BENCHMARK_TIMEOUT 60000


static int maybe_run_test(int argc, char **argv);



int main(int argc, char **argv) { int main(int argc, char **argv) {
platform_init(argc, argv); platform_init(argc, argv);


switch (argc) { switch (argc) {
case 1: return run_tests(BENCHMARK_TIMEOUT, 1); case 1: return run_tests(BENCHMARK_TIMEOUT, 1);
case 2: { case 2: return maybe_run_test(argc, argv);
if (strcmp(argv[1], "spawn_helper") == 0) {
printf("hello world\n");
return 42;
}

return run_test(argv[1], BENCHMARK_TIMEOUT, 1);
}
case 3: return run_test_part(argv[1], argv[2]); case 3: return run_test_part(argv[1], argv[2]);
default: default:
LOGF("Too many arguments.\n"); LOGF("Too many arguments.\n");
return 1; 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);
}
8 changes: 6 additions & 2 deletions test/run-tests.c
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -33,11 +33,10 @@
#define TEST_TIMEOUT 5000 #define TEST_TIMEOUT 5000


static int maybe_run_test(int argc, char **argv); static int maybe_run_test(int argc, char **argv);
static void list_all_tests(void);




int main(int argc, char **argv) { int main(int argc, char **argv) {
int i;

platform_init(argc, argv); platform_init(argc, argv);


switch (argc) { switch (argc) {
Expand All @@ -52,6 +51,11 @@ int main(int argc, char **argv) {




static int maybe_run_test(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) { if (strcmp(argv[1], "spawn_helper1") == 0) {
return 1; return 1;
} }
Expand Down
51 changes: 51 additions & 0 deletions test/runner.c
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -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); LOGF("No test part with that name: %s:%s\n", test, part);
return 255; 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);
}
}
}
8 changes: 8 additions & 0 deletions test/runner.h
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
#ifndef RUNNER_H_ #ifndef RUNNER_H_
#define RUNNER_H_ #define RUNNER_H_


#include <stdio.h> /* FILE */



/* /*
* The maximum number of processes (main + helpers) that a test / benchmark * The maximum number of processes (main + helpers) that a test / benchmark
Expand Down Expand Up @@ -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); 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 * Stuff that should be implemented by test-runner-<platform>.h
* All functions return 0 on success, -1 on failure, unless specified * All functions return 0 on success, -1 on failure, unless specified
Expand Down

0 comments on commit 7dda111

Please sign in to comment.