Skip to content

Instantly share code, notes, and snippets.

@piscisaureus
Created April 1, 2011 00:46
Show Gist options
  • Save piscisaureus/897555 to your computer and use it in GitHub Desktop.
Save piscisaureus/897555 to your computer and use it in GitHub Desktop.
int simple();
int ping_pong_server();
int ping_pong_client();
TEST_LIST_START
TEST_ENTRY (simple)
TEST_ENTRY2 (pingpong, ping_pong_server)
TEST_ENTRY2 (pingpong, ping_pong_client)
TEST_LIST_END
#include <string.h>
#include <stdio.h>
#ifdef _WIN32
# include <windows.h>
#endif
typedef struct {
char *group_name;
char *process_name;
int (*main)();
int ran;
} test_entry_t;
#define TEST_LIST_START \
test_entry_t TESTS[] = {
#define TEST_LIST_END \
{ 0, 0, 0, 0 } \
};
#define TEST_ENTRY(main) \
{ "" # main, "" # main, &main, 0 },
#define TEST_ENTRY2(name, main) \
{ "" # name, "" # main, &main, 0 },
#include "test-list.h"
int main(int argc, char **argv) {
int i;
test_entry_t *test, *testproc;
if (argc > 1) {
/* A specific test process was requested */
for (test = (test_entry_t*)&TESTS; test->main; test++) {
if (strcmp(argv[1], test->process_name) == 0)
return test->main();
}
fprintf(stderr, "Test process %s not found!\n", argv[1]);
return 255;
} else {
/* Run all tests */
test = (test_entry_t*)&TESTS;
for (test = (test_entry_t*)&TESTS; test->main; test++) {
if (!test->ran) {
for (testproc = test; testproc->main; testproc++) {
start_process(testproc->process_name);
testproc->ran = 1;
}
process_waitall();
}
}
return 0;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment