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 <jing.j.wang@intel.com>
This commit is contained in:
jing wang 2016-11-01 14:26:20 +08:00 committed by Anas Nashif
parent 2c48278be7
commit 2c3346ae73

View file

@ -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;
}