Commit 20495e89 authored by Anas Nashif's avatar Anas Nashif Committed by Anas Nashif
Browse files

ztest: support skipping tests



Some tests cant run everywhere, instead of completely dropping them, we
should report them as being skipped.

Signed-off-by: default avatarAnas Nashif <anas.nashif@intel.com>
parent 910a569e
Loading
Loading
Loading
Loading
+9 −2
Original line number Diff line number Diff line
@@ -59,10 +59,12 @@

#define FAIL "FAIL"
#define PASS "PASS"
#define SKIP "SKIP"
#define FMT_ERROR "%s - %s@%d. "

#define TC_PASS 0
#define TC_FAIL 1
#define TC_SKIP 2

#define TC_ERROR(fmt, ...)                               \
	do {                                                 \
@@ -77,8 +79,13 @@
/* prints result and the function name */
#define _TC_END_RESULT(result, func)					\
	do {								\
		TC_END(result, "%s - %s.\n",				\
		       (result) == TC_PASS ? PASS : FAIL, func);	\
		if ((result) == TC_PASS) {				\
			TC_END(result, "%s - %s.\n", PASS, func);	\
		} else if ((result) == TC_FAIL) {			\
			TC_END(result, "%s - %s.\n", FAIL, func);	\
		} else {						\
			TC_END(result, "%s - %s.\n", SKIP, func);	\
		}							\
		PRINT_LINE;						\
	} while (0)
#define TC_END_RESULT(result)                           \
+6 −0
Original line number Diff line number Diff line
@@ -51,6 +51,12 @@ void ztest_test_fail(void);
 */
void ztest_test_pass(void);

/**
 * @brief Skip the current test.
 *
 */
void ztest_test_skip(void);

/**
 * @brief Do nothing, successfully.
 *
+13 −4
Original line number Diff line number Diff line
@@ -172,6 +172,13 @@ void ztest_test_pass(void)
	k_thread_abort(k_current_get());
}

void ztest_test_skip(void)
{
	test_result = 2;
	k_sem_give(&test_end_signal);
	k_thread_abort(k_current_get());
}

static void init_testing(void)
{
	k_sem_init(&test_end_signal, 0, 1);
@@ -216,15 +223,17 @@ static int run_test(struct unit_test *test)
	 * phase": this will corrupt the kernel ready queue.
	 */
	k_sem_take(&test_end_signal, K_FOREVER);
	if (test_result) {
	if (test_result == 1) {
		ret = TC_FAIL;
		_TC_END_RESULT(ret, test->name);
	}

	if (!test_result || !FAIL_FAST) {
	if (test_result == 2) {
		_TC_END_RESULT(TC_SKIP, test->name);
	} else if (!test_result || !FAIL_FAST) {
		ret |= cleanup_test(test);
	}

		_TC_END_RESULT(ret, test->name);
	}

	return ret;
}