From d0c413bd585e5dc1ee2fc2bc8b4af110ef5900c6 Mon Sep 17 00:00:00 2001 From: sotech117 Date: Tue, 20 Feb 2024 19:02:36 +0000 Subject: add cancellation test, will ask about bug at meeting --- kernel/test/proctest.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'kernel/test/proctest.c') diff --git a/kernel/test/proctest.c b/kernel/test/proctest.c index 9ab4c65..f49da72 100644 --- a/kernel/test/proctest.c +++ b/kernel/test/proctest.c @@ -274,6 +274,28 @@ void test_out_of_order_termination() } +/* + Test threads' cancellation fields. +*/ +void test_cancellation() +{ + proc_t *new_proc1 = proc_create("proc test 1"); + kthread_t *new_kthread1 = kthread_create(new_proc1, test_func, new_proc1->p_pid, new_proc1); + test_assert(new_kthread1->kt_cancelled == 0, "Thread should not be cancelled"); + sched_make_runnable(new_kthread1); + + proc_kill(new_proc1, 1); + + test_assert(new_kthread1->kt_cancelled == 1, "Thread should be cancelled"); + + // wait for the thread to finish + int status; + int ret = do_waitpid(new_proc1->p_pid, &status, 0); + test_assert(ret != -ECHILD, "Should have found the process"); + test_assert(status == 1, "Returned status not set correctly"); +} + + long proctest_main(long arg1, void *arg2) { dbg(DBG_TEST, "\nStarting Procs tests\n"); @@ -290,6 +312,8 @@ long proctest_main(long arg1, void *arg2) test_proc_kill_all(); dbg(DBG_TEST, "\nStarting test_out_of_order_termination\n"); test_out_of_order_termination(); + dbg(DBG_TEST, "\nStarting test_cancellation\n"); + test_cancellation(); test_fini(); return 0; -- cgit v1.2.3-70-g09d2