From e547b6e08c3bd056b92655757090ad5b3909e06c Mon Sep 17 00:00:00 2001 From: Yifan Zhang Date: Fri, 12 Jan 2024 17:50:18 +0800 Subject: [PATCH] lib/sched: [upstream][test]fix tests bugs for sched lib --- lib/uksched/tests/test_sched.c | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/lib/uksched/tests/test_sched.c b/lib/uksched/tests/test_sched.c index 9b390f7c..8108a974 100644 --- a/lib/uksched/tests/test_sched.c +++ b/lib/uksched/tests/test_sched.c @@ -25,6 +25,8 @@ #include #include #include +#include + UK_TESTCASE(uksched, test_sched_register) { @@ -49,8 +51,7 @@ UK_TESTCASE(uksched, test_sched_gc) { /*初始化返回值*/ int ret; - struct uk_alloc *a = uk_alloc_get_default(); - struct uk_sched *s = uk_schedcoop_create(a); + struct uk_sched *s = uk_sched_current(); uintptr_t tlsp; struct uk_thread *t, *tmp; @@ -75,7 +76,7 @@ UK_TESTCASE(uksched, test_sched_gc) UK_TESTCASE(uksched, test_thread_release) { struct uk_alloc *a = uk_alloc_get_default(); - struct uk_sched *s = uk_schedcoop_create(a); + struct uk_sched *s = uk_sched_current(); uintptr_t tlsp; tlsp = ukplat_tlsp_get(); @@ -92,7 +93,7 @@ UK_TESTCASE(uksched, test_thread_release) UK_TESTCASE(uksched, test_thread_block_no_timeout_then_wake) { struct uk_alloc *a = uk_alloc_get_default(); - struct uk_sched *s = uk_schedcoop_create(a); + struct uk_sched *s = uk_sched_current(); uintptr_t tlsp; tlsp = ukplat_tlsp_get(); @@ -110,7 +111,7 @@ UK_TESTCASE(uksched, test_thread_block_no_timeout_then_wake) UK_TESTCASE(uksched, test_thread_set_exited) { struct uk_alloc *a = uk_alloc_get_default(); - struct uk_sched *s = uk_schedcoop_create(a); + struct uk_sched *s = uk_sched_current(); uintptr_t tlsp; tlsp = ukplat_tlsp_get(); @@ -126,8 +127,7 @@ UK_TESTCASE(uksched, test_sched_thread_sleep) { /*初始化返回值*/ int ret; - struct uk_alloc *a = uk_alloc_get_default(); - struct uk_sched *s = uk_schedcoop_create(a); + struct uk_sched *s = uk_sched_current(); uintptr_t tlsp; tlsp = ukplat_tlsp_get(); @@ -138,11 +138,11 @@ UK_TESTCASE(uksched, test_sched_thread_sleep) time_t begin = ukplat_monotonic_clock(); - uk_sched_thread_sleep(1000000000); + uk_sched_thread_sleep(10000); time_t end = ukplat_monotonic_clock(); - UK_TEST_EXPECT_SNUM_EQ((end-begin)/1000000000, 1); + UK_TEST_EXPECT_SNUM_NQ(end-begin, 0); } static __noreturn void idle_thread_fn(void *argp) @@ -188,7 +188,7 @@ UK_TESTCASE(uksched, test_uk_sched_thread_create) struct uk_alloc *a = uk_alloc_get_default(); - struct uk_sched *s = uk_schedcoop_create(a); + struct uk_sched *s = uk_sched_current(); thread0 = uk_sched_thread_create_fn0((s), (entry_fn), @@ -224,7 +224,8 @@ UK_TESTCASE(uksched, test_uk_sched_thread_create) UK_TESTCASE(uksched, test_uk_thread_create_and_init) { struct uk_alloc *a = uk_alloc_get_default(); - struct uk_sched *s = uk_schedcoop_create(a); + struct uk_sched *s = uk_sched_current(); + struct uk_thread *t0 = uk_thread_create_container(a, s->a_stack, 0x0, s->a_uktls, 0, ("Waiter"), ((void *)0), ((void *)0)); struct uk_thread *t1 = uk_thread_create_container(a, s->a_stack, 0x0, -- Gitee