Skip to content

Commit

Permalink
tasks: run test_main() as a BSP task
Browse files Browse the repository at this point in the history
Signed-off-by: Pawel Wieczorkiewicz <[email protected]>
  • Loading branch information
wipawel committed Jul 7, 2022
1 parent 51d8998 commit ccbe2a2
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 11 deletions.
10 changes: 9 additions & 1 deletion common/kernel.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#include <percpu.h>
#include <sched.h>
#include <setup.h>
#include <smp/smp.h>
#ifdef KTF_PMU
#include <perfmon/pfmlib.h>
#endif
Expand All @@ -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();
Expand All @@ -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");

Expand Down
22 changes: 16 additions & 6 deletions common/sched.c
Original file line number Diff line number Diff line change
Expand Up @@ -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");

Expand Down Expand Up @@ -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);
}
}
2 changes: 1 addition & 1 deletion include/ktf.h
Original file line number Diff line number Diff line change
Expand Up @@ -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__ */

Expand Down
4 changes: 1 addition & 3 deletions tests/test.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -75,7 +75,5 @@ void test_main(void) {
n++;
}

wait_for_all_tasks();

printk("Tests completed: %u\n", n);
}

0 comments on commit ccbe2a2

Please sign in to comment.