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