diff options
author | sotech117 <michael_foiani@brown.edu> | 2024-02-20 19:02:36 +0000 |
---|---|---|
committer | sotech117 <michael_foiani@brown.edu> | 2024-02-20 19:02:36 +0000 |
commit | d0c413bd585e5dc1ee2fc2bc8b4af110ef5900c6 (patch) | |
tree | e22098e4ebc68f14af241afb2876186408e33d5e /kernel/test | |
parent | d2b13e08f8d6111b7f7e79a47a124fc47dd9433c (diff) |
add cancellation test, will ask about bug at meeting
Diffstat (limited to 'kernel/test')
-rw-r--r-- | kernel/test/proctest.c | 24 |
1 files changed, 24 insertions, 0 deletions
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; |