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