1 /* 2 * Copyright (c) 2022 Nordic Semiconductor ASA 3 * 4 * SPDX-License-Identifier: Apache-2.0 5 */ 6 7 #include <zephyr/kernel.h> 8 #include <zephyr/ztest.h> 9 #include "assert.h" 10 11 DEFINE_FAKE_VALUE_FUNC(bool, mock_check_if_assert_expected); 12 assert_print(const char * fmt,...)13void assert_print(const char *fmt, ...) 14 { 15 va_list ap; 16 17 va_start(ap, fmt); 18 vprintk(fmt, ap); 19 va_end(ap); 20 } 21 assert_post_action(const char * file,unsigned int line)22void assert_post_action(const char *file, unsigned int line) 23 { 24 /* ztest_test_pass()/ztest_test_fail() are used to stop the execution 25 * If this is an unexpected assert (i.e. not following expect_assert()) 26 * calling mock_check_if_assert_expected() will return 'false' as 27 * a default return value 28 */ 29 if (mock_check_if_assert_expected() == true) { 30 printk("Assertion expected as part of a test case.\n"); 31 /* Mark the test as passed and stop execution: 32 * Needed in the passing scenario to prevent undefined behavior after hitting the 33 * assert. In real builds (non-UT), the system will be halted by the assert. 34 */ 35 ztest_test_pass(); 36 } else { 37 /* Mark the test as failed and stop execution */ 38 ztest_test_fail(); 39 } 40 } 41