From 2c3346ae73d60453188b7f6745a5b0eb46b02b8f Mon Sep 17 00:00:00 2001 From: jing wang Date: Tue, 1 Nov 2016 14:26:20 +0800 Subject: [PATCH] ztest: fix ztest syncronization issue when execution ztest execute syncronization depends on sem take and give between TC. Current issues are *) test execution go to next one before current TC finish *) one TC failure will block whole testing. Fix this issue by move k_sem_take from init_testing to run_test and add k_sem_give in run_test_fail. Meanwhile, set init sem value range from 0 to 1 Issue: ZEP-1164 Change-Id: I7b2d38501d0965455a71863a4729ee81472a63ec Signed-off-by: jing wang --- tests/ztest/src/ztest.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tests/ztest/src/ztest.c b/tests/ztest/src/ztest.c index 3f0895131df..8bba4bbaf1d 100644 --- a/tests/ztest/src/ztest.c +++ b/tests/ztest/src/ztest.c @@ -143,13 +143,13 @@ static struct k_sem mutex; void ztest_test_fail(void) { test_result = -1; + k_sem_give(&mutex); k_thread_abort(k_current_get()); } static void init_testing(void) { - k_sem_init(&mutex, 1, UINT_MAX); - k_sem_take(&mutex, K_FOREVER); + k_sem_init(&mutex, 0, 1); } static void test_cb(void *a, void *dummy2, void *dummy) @@ -171,6 +171,7 @@ static int run_test(struct unit_test *test) k_thread_spawn(&thread_stack[0], sizeof(thread_stack), (k_thread_entry_t) test_cb, (struct unit_test *)test, NULL, NULL, -1, 0, 0); + k_sem_take(&mutex, K_FOREVER); if (test_result) { ret = TC_FAIL; }