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