test, bench: add --list option to runners, prints available tests
This commit is contained in:
parent
6c3205557b
commit
7dda111306
@ -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);
|
||||
}
|
||||
|
||||
@ -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;
|
||||
}
|
||||
|
||||
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -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
|
||||
@ -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-<platform>.h
|
||||
* All functions return 0 on success, -1 on failure, unless specified
|
||||
|
||||
Loading…
Reference in New Issue
Block a user