Skip to content

Commit 20495e8

Browse files
nashifAnas Nashif
authored andcommitted
ztest: support skipping tests
Some tests cant run everywhere, instead of completely dropping them, we should report them as being skipped. Signed-off-by: Anas Nashif <[email protected]>
1 parent 910a569 commit 20495e8

File tree

3 files changed

+28
-6
lines changed

3 files changed

+28
-6
lines changed

tests/include/tc_util.h

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,12 @@
5959

6060
#define FAIL "FAIL"
6161
#define PASS "PASS"
62+
#define SKIP "SKIP"
6263
#define FMT_ERROR "%s - %s@%d. "
6364

6465
#define TC_PASS 0
6566
#define TC_FAIL 1
67+
#define TC_SKIP 2
6668

6769
#define TC_ERROR(fmt, ...) \
6870
do { \
@@ -77,8 +79,13 @@
7779
/* prints result and the function name */
7880
#define _TC_END_RESULT(result, func) \
7981
do { \
80-
TC_END(result, "%s - %s.\n", \
81-
(result) == TC_PASS ? PASS : FAIL, func); \
82+
if ((result) == TC_PASS) { \
83+
TC_END(result, "%s - %s.\n", PASS, func); \
84+
} else if ((result) == TC_FAIL) { \
85+
TC_END(result, "%s - %s.\n", FAIL, func); \
86+
} else { \
87+
TC_END(result, "%s - %s.\n", SKIP, func); \
88+
} \
8289
PRINT_LINE; \
8390
} while (0)
8491
#define TC_END_RESULT(result) \

tests/ztest/include/ztest_test.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,12 @@ void ztest_test_fail(void);
5151
*/
5252
void ztest_test_pass(void);
5353

54+
/**
55+
* @brief Skip the current test.
56+
*
57+
*/
58+
void ztest_test_skip(void);
59+
5460
/**
5561
* @brief Do nothing, successfully.
5662
*

tests/ztest/src/ztest.c

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,13 @@ void ztest_test_pass(void)
172172
k_thread_abort(k_current_get());
173173
}
174174

175+
void ztest_test_skip(void)
176+
{
177+
test_result = 2;
178+
k_sem_give(&test_end_signal);
179+
k_thread_abort(k_current_get());
180+
}
181+
175182
static void init_testing(void)
176183
{
177184
k_sem_init(&test_end_signal, 0, 1);
@@ -216,16 +223,18 @@ static int run_test(struct unit_test *test)
216223
* phase": this will corrupt the kernel ready queue.
217224
*/
218225
k_sem_take(&test_end_signal, K_FOREVER);
219-
if (test_result) {
226+
if (test_result == 1) {
220227
ret = TC_FAIL;
228+
_TC_END_RESULT(ret, test->name);
221229
}
222230

223-
if (!test_result || !FAIL_FAST) {
231+
if (test_result == 2) {
232+
_TC_END_RESULT(TC_SKIP, test->name);
233+
} else if (!test_result || !FAIL_FAST) {
224234
ret |= cleanup_test(test);
235+
_TC_END_RESULT(ret, test->name);
225236
}
226237

227-
_TC_END_RESULT(ret, test->name);
228-
229238
return ret;
230239
}
231240

0 commit comments

Comments
 (0)