tests: kernel/common: fix inadequate failing to thread context

The thread context test has insufficient checkings for failing
so add them:

() The variable rv for pass/fail is set but never checked. So
   add a check to fail the test if such indicated.
() Each thread's pass variable is set to TC_FAIL (== 1) and
   the check for successful thread execution simply checks
   if pass variable is not zero, which is always true. So
   change it so the check for failing condition is reasonable.

Signed-off-by: Daniel Leung <daniel.leung@intel.com>
This commit is contained in:
Daniel Leung 2022-02-23 07:54:17 -08:00 committed by Maureen Helm
commit 45940cf8cf

View file

@ -51,7 +51,7 @@ static void errno_thread(void *_n, void *_my_errno, void *_unused)
k_msleep(30 - (n * 10)); k_msleep(30 - (n * 10));
if (errno == my_errno) { if (errno == my_errno) {
result[n].pass = 1; result[n].pass = TC_PASS;
} }
zassert_equal(errno, my_errno, NULL); zassert_equal(errno, my_errno, NULL);
@ -91,7 +91,7 @@ void test_thread_context(void)
for (int ii = 0; ii < N_THREADS; ii++) { for (int ii = 0; ii < N_THREADS; ii++) {
struct result *p = k_fifo_get(&fifo, K_MSEC(100)); struct result *p = k_fifo_get(&fifo, K_MSEC(100));
if (!p || !p->pass) { if (!p || (p->pass != TC_PASS)) {
rv = TC_FAIL; rv = TC_FAIL;
} }
} }
@ -106,6 +106,10 @@ void test_thread_context(void)
for (int ii = 0; ii < N_THREADS; ii++) { for (int ii = 0; ii < N_THREADS; ii++) {
k_thread_join(&threads[ii], K_FOREVER); k_thread_join(&threads[ii], K_FOREVER);
} }
if (rv != TC_PASS) {
ztest_test_fail();
}
} }