diff --git a/common/kernel.c b/common/kernel.c index 043842b8..3c0b258a 100644 --- a/common/kernel.c +++ b/common/kernel.c @@ -31,6 +31,7 @@ #include #include #include +#include #ifdef KTF_PMU #include #endif @@ -51,6 +52,8 @@ static void __noreturn echo_loop(void) { } void kernel_main(void) { + task_t *tests_task; + printk("\nKTF - Kernel Test Framework!\n"); zap_boot_mappings(); @@ -59,7 +62,12 @@ void kernel_main(void) { display_multiboot_mmap(); } - test_main(); + tests_task = new_task("tests", test_main, NULL); + schedule_task(tests_task, smp_processor_id()); + + run_tasks(smp_processor_id()); + + wait_for_all_tasks(); printk("All tasks done.\n"); diff --git a/common/sched.c b/common/sched.c index 69772f8d..5bbc0bcc 100644 --- a/common/sched.c +++ b/common/sched.c @@ -41,8 +41,6 @@ static tid_t next_tid; static spinlock_t lock = SPINLOCK_INIT; -static bool terminate; - void init_tasks(void) { printk("Initializing tasks\n"); @@ -226,12 +224,24 @@ void wait_for_task_group(task_group_t group) { } } cpu_relax(); - } while (busy && !terminate); + } while (busy); } void run_tasks(unsigned int cpu) { - do { - run_task(get_task_for_cpu(cpu)); + task_t *task; + + while ((task = get_task_for_cpu(cpu))) { + switch (task->state) { + case TASK_STATE_DONE: + printk("Task '%s' finished with result %lu\n", task->name, task->result); + destroy_task(task); + break; + case TASK_STATE_SCHEDULED: + run_task(task); + break; + default: + break; + } cpu_relax(); - } while (!terminate); + } } diff --git a/include/ktf.h b/include/ktf.h index 24d613bf..44f84188 100644 --- a/include/ktf.h +++ b/include/ktf.h @@ -45,7 +45,7 @@ extern bool opt_debug; extern int usermode_call(user_func_t fn, void *fn_arg); extern void kernel_main(void) __noreturn; -extern void test_main(void); +extern void test_main(void *unused); #endif /* __ASSEMBLY__ */ diff --git a/tests/test.c b/tests/test.c index 0e969242..0ec088d6 100644 --- a/tests/test.c +++ b/tests/test.c @@ -59,7 +59,7 @@ static get_next_test_result_t get_next_test(test_fn **out_test_fn, char **out_na return TESTS_DONE; } -void test_main(void) { +void test_main(void *unused) { char *name; test_fn *fn = NULL; unsigned n = 0; @@ -75,7 +75,5 @@ void test_main(void) { n++; } - wait_for_all_tasks(); - printk("Tests completed: %u\n", n); }