Skip to content

Commit

Permalink
Make it possible to run individual tests.
Browse files Browse the repository at this point in the history
Fixes joyent#100.
  • Loading branch information
bnoordhuis committed Jul 14, 2011
1 parent f142a4b commit a29b209
Show file tree
Hide file tree
Showing 7 changed files with 192 additions and 177 deletions.
8 changes: 7 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -97,15 +97,21 @@ test/echo.o: test/echo.c test/echo.h
$(CC) $(CPPFLAGS) $(CFLAGS) -c test/echo.c -o test/echo.o


.PHONY: clean clean-platform distclean distclean-platform test benchmark
.PHONY: clean clean-platform distclean distclean-platform test bench


test: test/run-tests$(E)
test/run-tests

test-%: test/run-tests$(E)
test/run-tests $(@:test-%=%)

bench: test/run-benchmarks$(E)
test/run-benchmarks

bench-%: test/run-benchmarks$(E)
test/run-benchmarks $(@:bench-%=%)

clean: clean-platform
$(RM) -f src/*.o *.a test/run-tests$(E) test/run-benchmarks$(E)

Expand Down
26 changes: 7 additions & 19 deletions test/run-benchmarks.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,26 +34,14 @@


int main(int argc, char **argv) {
task_entry_t *task;

platform_init(argc, argv);

if (argc > 1) {
/* A specific process was requested. */
return run_process(argv[1]);

} else {
/* Run all benchmarks. */
task = (task_entry_t*)&TASKS;
for (task = (task_entry_t*)&TASKS; task->main; task++) {
if (task->is_helper) {
continue;
}

run_task(task, BENCHMARK_TIMEOUT, 1);
}
LOG("Done.\n");

return 0;
switch (argc) {
case 1: return run_tests(BENCHMARK_TIMEOUT, 1);
case 2: return run_test(argv[1], BENCHMARK_TIMEOUT, 1);
case 3: return run_test_part(argv[1], argv[2]);
default:
LOGF("Too many arguments.\n");
return 1;
}
}
53 changes: 7 additions & 46 deletions test/run-tests.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,54 +33,15 @@
#define TEST_TIMEOUT 5000


static void log_progress(int total, int passed, int failed, char* name) {
LOGF("[%% %3d|+ %3d|- %3d]: %s", (passed + failed) / total * 100,
passed, failed, name);
}


int main(int argc, char **argv) {
int total, passed, failed;
task_entry_t* task;

platform_init(argc, argv);

if (argc > 1) {
/* A specific process was requested. */
return run_process(argv[1]);

} else {
/* Count the number of tests. */
total = 0;
task = (task_entry_t*)&TASKS;
for (task = (task_entry_t*)&TASKS; task->main; task++) {
if (!task->is_helper) {
total++;
}
}

/* Run all tests. */
passed = 0;
failed = 0;
task = (task_entry_t*)&TASKS;
for (task = (task_entry_t*)&TASKS; task->main; task++) {
if (task->is_helper) {
continue;
}

rewind_cursor();
log_progress(total, passed, failed, task->task_name);

if (run_task(task, TEST_TIMEOUT, 0)) {
passed++;
} else {
failed++;
}
}

rewind_cursor();
log_progress(total, passed, failed, "Done.\n");

return 0;
switch (argc) {
case 1: return run_tests(TEST_TIMEOUT, 0);
case 2: return run_test(argv[1], TEST_TIMEOUT, 0);
case 3: return run_test_part(argv[1], argv[2]);
default:
LOGF("Too many arguments.\n");
return 1;
}
}
6 changes: 3 additions & 3 deletions test/runner-unix.c
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,9 @@ void platform_init(int argc, char **argv) {
}


/* Invoke "arv[0] test-name". Store process info in *p. */
/* Invoke "argv[0] test-name [test-part]". Store process info in *p. */
/* Make sure that all stdio output of the processes is buffered up. */
int process_start(char* name, process_info_t* p) {
int process_start(char* name, char* part, process_info_t* p) {
FILE* stdout_file = tmpfile();
if (!stdout_file) {
perror("tmpfile");
Expand All @@ -92,7 +92,7 @@ int process_start(char* name, process_info_t* p) {
dup2(fileno(stdout_file), STDOUT_FILENO);
dup2(fileno(stdout_file), STDERR_FILENO);

char* args[3] = { executable_path, name, NULL };
char* args[] = { executable_path, name, part, NULL };
execvp(executable_path, args);
perror("execvp()");
_exit(127);
Expand Down
26 changes: 19 additions & 7 deletions test/runner-win.c
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ void platform_init(int argc, char **argv) {
}


int process_start(char *name, process_info_t *p) {
int process_start(char *name, char *part, process_info_t *p) {
HANDLE file = INVALID_HANDLE_VALUE;
HANDLE nul = INVALID_HANDLE_VALUE;
WCHAR path[MAX_PATH], filename[MAX_PATH];
Expand Down Expand Up @@ -97,12 +97,24 @@ int process_start(char *name, process_info_t *p) {
if (result == 0 || result == sizeof(image))
goto error;

if (_snwprintf((wchar_t*)&args,
sizeof(args) / sizeof(wchar_t),
L"\"%s\" %S",
image,
name) < 0)
goto error;
if (part) {
if (_snwprintf((wchar_t*)args,
sizeof(args) / sizeof(wchar_t),
L"\"%s\" %S %S",
image,
name,
part) < 0) {
goto error;
}
} else {
if (_snwprintf((wchar_t*)args,
sizeof(args) / sizeof(wchar_t),
L"\"%s\" %S",
image,
name) < 0) {
goto error;
}
}

memset((void*)&si, 0, sizeof(si));
si.cb = sizeof(si);
Expand Down
Loading

0 comments on commit a29b209

Please sign in to comment.