Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tasks: run test_main() as a BSP task #264

Merged
merged 1 commit into from
Jul 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
}