1 /*
2  * Copyright (c) 2020 Intel Corporation
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  */
6 
7 #ifndef ZEPHYR_INCLUDE_ZTEST_FATAL_HOOK_H_
8 #define ZEPHYR_INCLUDE_ZTEST_FATAL_HOOK_H_
9 
10 #include <zephyr.h>
11 
12 
13 #if defined(CONFIG_ZTEST_FATAL_HOOK)
14 /**
15  * @brief Set the flag that treat fatal error happened as expected
16  *
17  * @details This is used for negative test cases which triggers a fatal
18  * error. Set the param true will still pass the test case when expected
19  * fatal error happened. For normal test case, set it false makes it back
20  * to normal behavior.
21  *
22  * @param valid flag indicate fault is expected
23  */
24 __syscall void ztest_set_fault_valid(bool valid);
25 
26 /* @brief A hook after fatal error handler
27  *
28  * @details This is a test case hook that can run code from test case, in
29  * order to deal with some special case when catching the expected fatal
30  * error.
31  *
32  * Usage: Define your own hook function in your test case code, and do what
33  * you want to do after fatal error handler.
34  *
35  * By default, it will do nothing before leaving error handler.
36  */
37 void ztest_post_fatal_error_hook(unsigned int reason,
38 		const z_arch_esf_t *pEsf);
39 
40 #endif
41 
42 
43 #if defined(CONFIG_ZTEST_ASSERT_HOOK)
44 /**
45  * @brief Set the flag that treat assert fail happened as expected
46  *
47  * @details This is used for negative test cases which triggers a assert
48  * fail. Set the param true will still pass the test case when expected
49  * assert fail happened. For normal test case, set it false make it back
50  * to normal behavior.
51  *
52  * @param valid flag indicate assert is expected
53  */
54 __syscall void ztest_set_assert_valid(bool valid);
55 
56 /* @brief A hook after assert fault handler
57  *
58  * @details This is a test case hook that can run code from test case, in
59  * order to deal with some special case when catching the expected assert
60  * failed.
61  *
62  * Usage: Define your own hook function in your test case code, and do what
63  * you want to do after assert handler.
64  *
65  * By default, it will abort the thread which assert failed.
66  */
67 void ztest_post_assert_fail_hook(void);
68 
69 #endif
70 
71 #if defined(CONFIG_ZTEST_FATAL_HOOK) || defined(CONFIG_ZTEST_ASSERT_HOOK)
72 #include <syscalls/ztest_error_hook.h>
73 #endif
74 
75 #endif /* ZEPHYR_INCLUDE_ZTEST_FATAL_HOOK_H_ */
76