ztest: Replace PRINT with PRINT_DATA
The testsuite subsystem provides the macro PRINT_DATA() which can be overridden using CONFIG_ZTEST_TC_UTIL_USER_OVERRIDE. Switch all calls of PRINT() to PRINT_DATA withing the testsuite subsystem. Signed-off-by: Keith Short <keithshort@google.com>
This commit is contained in:
parent
82a2a16649
commit
da4f4e8748
3 changed files with 62 additions and 57 deletions
|
@ -18,6 +18,7 @@
|
|||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <zephyr/tc_util.h>
|
||||
#include <zephyr/ztest.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
@ -34,7 +35,8 @@ void ztest_skip_failed_assumption(void);
|
|||
static inline bool z_zassert_(bool cond, const char *file, int line)
|
||||
{
|
||||
if (cond == false) {
|
||||
PRINT("\n Assertion failed at %s:%d\n", ztest_relative_filename(file), line);
|
||||
PRINT_DATA("\n Assertion failed at %s:%d\n", ztest_relative_filename(file),
|
||||
line);
|
||||
ztest_test_fail();
|
||||
return false;
|
||||
}
|
||||
|
@ -47,7 +49,8 @@ static inline bool z_zassert_(bool cond, const char *file, int line)
|
|||
static inline bool z_zassume_(bool cond, const char *file, int line)
|
||||
{
|
||||
if (cond == false) {
|
||||
PRINT("\n Assumption failed at %s:%d\n", ztest_relative_filename(file), line);
|
||||
PRINT_DATA("\n Assumption failed at %s:%d\n", ztest_relative_filename(file),
|
||||
line);
|
||||
ztest_skip_failed_assumption();
|
||||
return false;
|
||||
}
|
||||
|
@ -60,7 +63,8 @@ static inline bool z_zassume_(bool cond, const char *file, int line)
|
|||
static inline bool z_zexpect_(bool cond, const char *file, int line)
|
||||
{
|
||||
if (cond == false) {
|
||||
PRINT("\n Expectation failed at %s:%d\n", ztest_relative_filename(file), line);
|
||||
PRINT_DATA("\n Expectation failed at %s:%d\n", ztest_relative_filename(file),
|
||||
line);
|
||||
ztest_test_expect_fail();
|
||||
return false;
|
||||
}
|
||||
|
@ -79,8 +83,8 @@ static inline bool z_zassert(bool cond, const char *default_msg, const char *fil
|
|||
va_list vargs;
|
||||
|
||||
va_start(vargs, msg);
|
||||
PRINT("\n Assertion failed at %s:%d: %s: %s\n", ztest_relative_filename(file),
|
||||
line, func, default_msg);
|
||||
PRINT_DATA("\n Assertion failed at %s:%d: %s: %s\n",
|
||||
ztest_relative_filename(file), line, func, default_msg);
|
||||
vprintk(msg, vargs);
|
||||
printk("\n");
|
||||
va_end(vargs);
|
||||
|
@ -89,8 +93,8 @@ static inline bool z_zassert(bool cond, const char *default_msg, const char *fil
|
|||
}
|
||||
#if CONFIG_ZTEST_ASSERT_VERBOSE == 2
|
||||
else {
|
||||
PRINT("\n Assertion succeeded at %s:%d (%s)\n", ztest_relative_filename(file),
|
||||
line, func);
|
||||
PRINT_DATA("\n Assertion succeeded at %s:%d (%s)\n",
|
||||
ztest_relative_filename(file), line, func);
|
||||
}
|
||||
#endif
|
||||
return true;
|
||||
|
@ -103,8 +107,8 @@ static inline bool z_zassume(bool cond, const char *default_msg, const char *fil
|
|||
va_list vargs;
|
||||
|
||||
va_start(vargs, msg);
|
||||
PRINT("\n Assumption failed at %s:%d: %s: %s\n", ztest_relative_filename(file),
|
||||
line, func, default_msg);
|
||||
PRINT_DATA("\n Assumption failed at %s:%d: %s: %s\n",
|
||||
ztest_relative_filename(file), line, func, default_msg);
|
||||
vprintk(msg, vargs);
|
||||
printk("\n");
|
||||
va_end(vargs);
|
||||
|
@ -113,8 +117,8 @@ static inline bool z_zassume(bool cond, const char *default_msg, const char *fil
|
|||
}
|
||||
#if CONFIG_ZTEST_ASSERT_VERBOSE == 2
|
||||
else {
|
||||
PRINT("\n Assumption succeeded at %s:%d (%s)\n", ztest_relative_filename(file),
|
||||
line, func);
|
||||
PRINT_DATA("\n Assumption succeeded at %s:%d (%s)\n",
|
||||
ztest_relative_filename(file), line, func);
|
||||
}
|
||||
#endif
|
||||
return true;
|
||||
|
@ -127,8 +131,8 @@ static inline bool z_zexpect(bool cond, const char *default_msg, const char *fil
|
|||
va_list vargs;
|
||||
|
||||
va_start(vargs, msg);
|
||||
PRINT("\n Expectation failed at %s:%d: %s: %s\n", ztest_relative_filename(file),
|
||||
line, func, default_msg);
|
||||
PRINT_DATA("\n Expectation failed at %s:%d: %s: %s\n",
|
||||
ztest_relative_filename(file), line, func, default_msg);
|
||||
vprintk(msg, vargs);
|
||||
printk("\n");
|
||||
va_end(vargs);
|
||||
|
@ -137,8 +141,8 @@ static inline bool z_zexpect(bool cond, const char *default_msg, const char *fil
|
|||
}
|
||||
#if CONFIG_ZTEST_ASSERT_VERBOSE == 2
|
||||
else {
|
||||
PRINT("\n Expectation succeeded at %s:%d (%s)\n", ztest_relative_filename(file),
|
||||
line, func);
|
||||
PRINT_DATA("\n Expectation succeeded at %s:%d (%s)\n",
|
||||
ztest_relative_filename(file), line, func);
|
||||
}
|
||||
#endif
|
||||
return true;
|
||||
|
|
|
@ -92,10 +92,10 @@ static int cleanup_test(struct ztest_unit_test *test)
|
|||
#endif
|
||||
|
||||
if (!ret && mock_status == 1) {
|
||||
PRINT("Test %s failed: Unused mock parameter values\n", test->name);
|
||||
PRINT_DATA("Test %s failed: Unused mock parameter values\n", test->name);
|
||||
ret = TC_FAIL;
|
||||
} else if (!ret && mock_status == 2) {
|
||||
PRINT("Test %s failed: Unused mock return values\n", test->name);
|
||||
PRINT_DATA("Test %s failed: Unused mock return values\n", test->name);
|
||||
ret = TC_FAIL;
|
||||
} else {
|
||||
;
|
||||
|
@ -414,16 +414,16 @@ void ztest_test_fail(void)
|
|||
{
|
||||
switch (cur_phase) {
|
||||
case TEST_PHASE_SETUP:
|
||||
PRINT(" at %s function\n", get_friendly_phase_name(cur_phase));
|
||||
PRINT_DATA(" at %s function\n", get_friendly_phase_name(cur_phase));
|
||||
longjmp(test_suite_fail, 1);
|
||||
case TEST_PHASE_BEFORE:
|
||||
case TEST_PHASE_TEST:
|
||||
PRINT(" at %s function\n", get_friendly_phase_name(cur_phase));
|
||||
PRINT_DATA(" at %s function\n", get_friendly_phase_name(cur_phase));
|
||||
longjmp(test_fail, 1);
|
||||
case TEST_PHASE_AFTER:
|
||||
case TEST_PHASE_TEARDOWN:
|
||||
case TEST_PHASE_FRAMEWORK:
|
||||
PRINT(" ERROR: cannot fail in test phase '%s()', bailing\n",
|
||||
PRINT_DATA(" ERROR: cannot fail in test phase '%s()', bailing\n",
|
||||
get_friendly_phase_name(cur_phase));
|
||||
longjmp(stack_fail, 1);
|
||||
}
|
||||
|
@ -435,7 +435,7 @@ void ztest_test_pass(void)
|
|||
if (cur_phase == TEST_PHASE_TEST) {
|
||||
longjmp(test_pass, 1);
|
||||
}
|
||||
PRINT(" ERROR: cannot pass in test phase '%s()', bailing\n",
|
||||
PRINT_DATA(" ERROR: cannot pass in test phase '%s()', bailing\n",
|
||||
get_friendly_phase_name(cur_phase));
|
||||
longjmp(stack_fail, 1);
|
||||
}
|
||||
|
@ -449,7 +449,7 @@ void ztest_test_skip(void)
|
|||
case TEST_PHASE_TEST:
|
||||
longjmp(test_skip, 1);
|
||||
default:
|
||||
PRINT(" ERROR: cannot skip in test phase '%s()', bailing\n",
|
||||
PRINT_DATA(" ERROR: cannot skip in test phase '%s()', bailing\n",
|
||||
get_friendly_phase_name(cur_phase));
|
||||
longjmp(stack_fail, 1);
|
||||
}
|
||||
|
@ -462,16 +462,16 @@ void ztest_test_expect_fail(void)
|
|||
|
||||
switch (cur_phase) {
|
||||
case TEST_PHASE_SETUP:
|
||||
PRINT(" at %s function\n", get_friendly_phase_name(cur_phase));
|
||||
PRINT_DATA(" at %s function\n", get_friendly_phase_name(cur_phase));
|
||||
break;
|
||||
case TEST_PHASE_BEFORE:
|
||||
case TEST_PHASE_TEST:
|
||||
PRINT(" at %s function\n", get_friendly_phase_name(cur_phase));
|
||||
PRINT_DATA(" at %s function\n", get_friendly_phase_name(cur_phase));
|
||||
break;
|
||||
case TEST_PHASE_AFTER:
|
||||
case TEST_PHASE_TEARDOWN:
|
||||
case TEST_PHASE_FRAMEWORK:
|
||||
PRINT(" ERROR: cannot fail in test phase '%s()', bailing\n",
|
||||
PRINT_DATA(" ERROR: cannot fail in test phase '%s()', bailing\n",
|
||||
get_friendly_phase_name(cur_phase));
|
||||
longjmp(stack_fail, 1);
|
||||
}
|
||||
|
@ -572,7 +572,7 @@ void ztest_test_fail(void)
|
|||
test_finalize();
|
||||
break;
|
||||
default:
|
||||
PRINT(" ERROR: cannot fail in test phase '%s()', bailing\n",
|
||||
PRINT_DATA(" ERROR: cannot fail in test phase '%s()', bailing\n",
|
||||
get_friendly_phase_name(cur_phase));
|
||||
test_status = ZTEST_STATUS_CRITICAL_ERROR;
|
||||
break;
|
||||
|
@ -588,7 +588,7 @@ void ztest_test_pass(void)
|
|||
test_finalize();
|
||||
break;
|
||||
default:
|
||||
PRINT(" ERROR: cannot pass in test phase '%s()', bailing\n",
|
||||
PRINT_DATA(" ERROR: cannot pass in test phase '%s()', bailing\n",
|
||||
get_friendly_phase_name(cur_phase));
|
||||
test_status = ZTEST_STATUS_CRITICAL_ERROR;
|
||||
if (cur_phase == TEST_PHASE_BEFORE) {
|
||||
|
@ -610,7 +610,7 @@ void ztest_test_skip(void)
|
|||
test_finalize();
|
||||
break;
|
||||
default:
|
||||
PRINT(" ERROR: cannot skip in test phase '%s()', bailing\n",
|
||||
PRINT_DATA(" ERROR: cannot skip in test phase '%s()', bailing\n",
|
||||
get_friendly_phase_name(cur_phase));
|
||||
test_status = ZTEST_STATUS_CRITICAL_ERROR;
|
||||
break;
|
||||
|
@ -807,7 +807,7 @@ static int z_ztest_run_test_suite_ptr(struct ztest_suite_node *suite, bool shuff
|
|||
|
||||
#ifndef KERNEL
|
||||
if (setjmp(stack_fail)) {
|
||||
PRINT("TESTSUITE crashed.\n");
|
||||
PRINT_DATA("TESTSUITE crashed.\n");
|
||||
test_status = ZTEST_STATUS_CRITICAL_ERROR;
|
||||
end_report();
|
||||
exit(1);
|
||||
|
@ -1157,7 +1157,7 @@ void ztest_verify_all_test_suites_ran(void)
|
|||
for (suite = _ztest_suite_node_list_start; suite < _ztest_suite_node_list_end;
|
||||
++suite) {
|
||||
if (suite->stats->run_count < 1) {
|
||||
PRINT("ERROR: Test suite '%s' did not run.\n", suite->name);
|
||||
PRINT_DATA("ERROR: Test suite '%s' did not run.\n", suite->name);
|
||||
all_tests_run = false;
|
||||
}
|
||||
}
|
||||
|
@ -1165,7 +1165,8 @@ void ztest_verify_all_test_suites_ran(void)
|
|||
for (test = _ztest_unit_test_list_start; test < _ztest_unit_test_list_end; ++test) {
|
||||
suite = ztest_find_test_suite(test->test_suite_name);
|
||||
if (suite == NULL) {
|
||||
PRINT("ERROR: Test '%s' assigned to test suite '%s' which doesn't "
|
||||
PRINT_DATA("ERROR: Test '%s' assigned to test suite '%s' which "
|
||||
"doesn't "
|
||||
"exist\n",
|
||||
test->name, test->test_suite_name);
|
||||
all_tests_run = false;
|
||||
|
@ -1180,7 +1181,7 @@ void ztest_verify_all_test_suites_ran(void)
|
|||
for (test = _ztest_unit_test_list_start; test < _ztest_unit_test_list_end; ++test) {
|
||||
if (test->stats->fail_count + test->stats->pass_count + test->stats->skip_count !=
|
||||
test->stats->run_count) {
|
||||
PRINT("Bad stats for %s.%s\n", test->test_suite_name, test->name);
|
||||
PRINT_DATA("Bad stats for %s.%s\n", test->test_suite_name, test->name);
|
||||
test_status = 1;
|
||||
}
|
||||
}
|
||||
|
@ -1430,11 +1431,11 @@ int main(void)
|
|||
}
|
||||
state.boots += 1;
|
||||
if (test_status == 0) {
|
||||
PRINT("Reset board #%u to test again\n", state.boots);
|
||||
PRINT_DATA("Reset board #%u to test again\n", state.boots);
|
||||
k_msleep(10);
|
||||
sys_reboot(SYS_REBOOT_COLD);
|
||||
} else {
|
||||
PRINT("Failed after %u attempts\n", state.boots);
|
||||
PRINT_DATA("Failed after %u attempts\n", state.boots);
|
||||
state.boots = 0;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -33,7 +33,7 @@ static struct parameter *alloc_parameter(void)
|
|||
|
||||
param = calloc(1, sizeof(struct parameter));
|
||||
if (!param) {
|
||||
PRINT("Failed to allocate mock parameter\n");
|
||||
PRINT_DATA("Failed to allocate mock parameter\n");
|
||||
ztest_test_fail();
|
||||
}
|
||||
|
||||
|
@ -205,7 +205,7 @@ void z_ztest_check_expected_value(const char *fn, const char *name, uintptr_t va
|
|||
|
||||
param = find_and_delete_value(¶meter_list, fn, name);
|
||||
if (!param) {
|
||||
PRINT("Failed to find parameter %s for %s\n", name, fn);
|
||||
PRINT_DATA("Failed to find parameter %s for %s\n", name, fn);
|
||||
ztest_test_fail();
|
||||
}
|
||||
|
||||
|
@ -216,7 +216,7 @@ void z_ztest_check_expected_value(const char *fn, const char *name, uintptr_t va
|
|||
/* We need to cast these values since the toolchain doesn't
|
||||
* provide inttypes.h
|
||||
*/
|
||||
PRINT("%s:%s received wrong value: Got %lu, expected %lu\n", fn, name,
|
||||
PRINT_DATA("%s:%s received wrong value: Got %lu, expected %lu\n", fn, name,
|
||||
(unsigned long)val, (unsigned long)expected);
|
||||
ztest_test_fail();
|
||||
}
|
||||
|
@ -234,7 +234,7 @@ void z_ztest_check_expected_data(const char *fn, const char *name, void *data, u
|
|||
|
||||
param = find_and_delete_value(¶meter_list, fn, name);
|
||||
if (!param) {
|
||||
PRINT("Failed to find parameter %s for %s\n", name, fn);
|
||||
PRINT_DATA("Failed to find parameter %s for %s\n", name, fn);
|
||||
/* No return from this function but for coverity reasons
|
||||
* put a return after to avoid the warning of a null
|
||||
* dereference of param below.
|
||||
|
@ -247,14 +247,14 @@ void z_ztest_check_expected_data(const char *fn, const char *name, void *data, u
|
|||
free_parameter(param);
|
||||
|
||||
if (expected == NULL && data != NULL) {
|
||||
PRINT("%s:%s received data while expected null pointer\n", fn, name);
|
||||
PRINT_DATA("%s:%s received data while expected null pointer\n", fn, name);
|
||||
ztest_test_fail();
|
||||
} else if (data == NULL && expected != NULL) {
|
||||
PRINT("%s:%s received null pointer while expected data\n", fn, name);
|
||||
PRINT_DATA("%s:%s received null pointer while expected data\n", fn, name);
|
||||
ztest_test_fail();
|
||||
} else if (data != NULL) {
|
||||
if (memcmp(data, expected, length) != 0) {
|
||||
PRINT("%s:%s data provided don't match\n", fn, name);
|
||||
PRINT_DATA("%s:%s data provided don't match\n", fn, name);
|
||||
ztest_test_fail();
|
||||
}
|
||||
}
|
||||
|
@ -271,14 +271,14 @@ void z_ztest_copy_return_data(const char *fn, const char *name, void *data, uint
|
|||
void *return_data;
|
||||
|
||||
if (data == NULL) {
|
||||
PRINT("%s:%s received null pointer\n", fn, name);
|
||||
PRINT_DATA("%s:%s received null pointer\n", fn, name);
|
||||
ztest_test_fail();
|
||||
return;
|
||||
}
|
||||
|
||||
param = find_and_delete_value(¶meter_list, fn, name);
|
||||
if (!param) {
|
||||
PRINT("Failed to find parameter %s for %s\n", name, fn);
|
||||
PRINT_DATA("Failed to find parameter %s for %s\n", name, fn);
|
||||
memset(data, 0, length);
|
||||
ztest_test_fail();
|
||||
} else {
|
||||
|
@ -299,7 +299,7 @@ uintptr_t z_ztest_get_return_value(const char *fn)
|
|||
struct parameter *param = find_and_delete_value(&return_value_list, fn, "");
|
||||
|
||||
if (!param) {
|
||||
PRINT("Failed to find return value for function %s\n", fn);
|
||||
PRINT_DATA("Failed to find return value for function %s\n", fn);
|
||||
ztest_test_fail();
|
||||
}
|
||||
|
||||
|
@ -325,12 +325,12 @@ int z_cleanup_mock(void)
|
|||
int fail = 0;
|
||||
|
||||
if (parameter_list.next) {
|
||||
PRINT("Parameter not used by mock: %s:%s\n", parameter_list.next->fn,
|
||||
PRINT_DATA("Parameter not used by mock: %s:%s\n", parameter_list.next->fn,
|
||||
parameter_list.next->name);
|
||||
fail = 1;
|
||||
}
|
||||
if (return_value_list.next) {
|
||||
PRINT("Return value no used by mock: %s\n", return_value_list.next->fn);
|
||||
PRINT_DATA("Return value no used by mock: %s\n", return_value_list.next->fn);
|
||||
fail = 2;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue