Added an initial version of a test case application.

This commit is contained in:
Jacek Galowicz 2012-09-16 16:48:55 +02:00
parent fb15bae2e7
commit 36477f214a
2 changed files with 116 additions and 8 deletions

View file

@ -46,7 +46,7 @@ int jacobi(void* arg);
void echo_init(void);
void netio_init(void);
#ifdef START_CONSUMER_PRODUCER
#if defined(START_CONSUMER_PRODUCER) || defined(START_CHIEFTEST)
static sem_t consuming, producing;
static mailbox_int32_t mbox;
static int val = 0;
@ -89,9 +89,28 @@ static int producer(void* arg)
return 0;
}
static int producer_consumer(void)
{
tid_t id1, id2, ret;
int result1, result2, result;
create_kernel_task(&id1, producer, NULL, NORMAL_PRIO);
create_kernel_task(&id2, consumer, NULL, NORMAL_PRIO);
ret = wait(&result);
if (ret == id1) result1 = result;
else result2 = result;
ret = wait(&result);
if (ret == id1) result1 = result;
else result2 = result;
return result1 || result2;
}
#endif
#if defined(START_FOO) || defined(START_JOIN_TEST)
#if defined(START_FOO) || defined(START_JOIN_TEST) || defined(START_CHIEFTEST)
static int foo(void* arg)
{
int i;
@ -388,7 +407,7 @@ static int svm_bench(void *arg)
}
#endif
#ifdef START_JOIN_TEST
#if defined(START_JOIN_TEST) || defined(START_CHIEFTEST)
static int join_test(void* arg)
{
tid_t id, ret;
@ -403,7 +422,7 @@ static int join_test(void* arg)
kprintf("Child %u finished: result = %d\n", id, result);
return 0;
return result != 42;
}
#endif
@ -497,6 +516,89 @@ next_try:
}
#endif
#ifdef START_CHIEFTEST
struct testcase_t {
tid_t tid;
int retval;
char* userspace_argv[10];
entry_point_t kernelspace_ep;
char* testcase_name;
};
#define USERSPACE_TC(execpath, name) {0, 0, {execpath, NULL}, NULL, name}
#define KERNELSPACE_TC(execpointer, name) {0, 0, {NULL}, execpointer, name}
struct testcase_t testcases[] = {
USERSPACE_TC("/bin/jacobi", "Jacobi serial user space app"),
USERSPACE_TC("/bin/tests", "Tests user space app"),
USERSPACE_TC("/bin/hello", "Hello userspace app"),
KERNELSPACE_TC(producer_consumer, "Producer consumer kernel space test"),
KERNELSPACE_TC(join_test, "Join kernel space test")
};
static int chiefmastertest(void)
{
int tests = sizeof(testcases) / sizeof(struct testcase_t);
int i;
int result;
tid_t id, ret;
struct testcase_t* current;
kprintf("Starting Chiefmaster test: %d test cases.\n", tests);
for (i = 0; i < tests; i++) {
current = &testcases[i];
kprintf("Starting testcase: %s\n", current->testcase_name);
if (current->kernelspace_ep == NULL &&
current->userspace_argv[0] != NULL) {
create_user_task(&current->tid, current->userspace_argv[0],
current->userspace_argv);
} else if (current->kernelspace_ep != NULL &&
current->userspace_argv[0] == NULL) {
create_kernel_task(&current->tid, current->kernelspace_ep,
NULL, NORMAL_PRIO);
} else {
kprintf("Invalid test case struct #%d!\n", i);
continue;
}
do {
ret = wait(&result);
} while(ret != current->tid);
kprintf("Testcase %s returned %d\n", current->testcase_name, result);
current->retval = result;
}
kprintf("======================================================\n");
kprintf("Master Chief test case results:\n");
for (i = 0; i < tests; i++) {
current = &testcases[i];
kprintf("%s: ", current->testcase_name);
if (current->retval) {
pushfg(COL_RED);
kprintf("Bad :(");
} else {
pushfg(COL_GREEN);
kprintf("Pass :)");
}
popfg();
popbg();
kprintf("\n");
}
kprintf("======================================================\n");
return 0;
}
#endif // START_CHIEFTEST
int test_init(void)
{
#ifdef START_HELLO
@ -513,19 +615,23 @@ int test_init(void)
char* client_argv[] = {"/bin/client", "192.168.0.1", "6789", NULL};
#endif
#ifdef START_CHIEFTEST
create_kernel_task(NULL, chiefmastertest, NULL, NORMAL_PRIO);
#endif
#ifdef START_ECHO
echo_init();
#endif
#ifdef START_NETIO
netio_init();
#endif
#ifdef START_CONSUMER_PRODUCER
#if defined(START_CONSUMER_PRODUCER) || defined(START_CHIEFTEST)
sem_init(&producing, 1);
sem_init(&consuming, 0);
mailbox_int32_init(&mbox);
create_kernel_task(NULL, producer, NULL, NORMAL_PRIO);
create_kernel_task(NULL, consumer, NULL, NORMAL_PRIO);
#endif
#ifdef START_CONSUMER_PRODUCER
create_kernel_task(NULL, producer_consumer, NULL, NORMAL_PRIO);
#endif
#ifdef START_MEASURE_CTX_SWITCH
create_kernel_task(NULL, measure_ctx_switch, (int)0, NORMAL_PRIO);

View file

@ -47,6 +47,8 @@
#define START_TESTS
//#define START_JACOBI
//#define START_CHIEFTEST
// does our demos require GFX support?
//#define CONFIG_GFX