2 * Copyright (c) 2015 Apple Inc. All rights reserved.
4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. The rights granted to you under the License
10 * may not be used to create, or enable the creation or redistribution of,
11 * unlawful or unlicensed copies of an Apple operating system, or to
12 * circumvent, violate, or enable the circumvention or violation of, any
13 * terms of an Apple operating system software license agreement.
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
18 * The Original Code and all software distributed under the License are
19 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
20 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
22 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
23 * Please see the License for the specific language governing rights and
24 * limitations under the License.
26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
29 #ifndef _TESTS_XNUPOST_H
30 #define _TESTS_XNUPOST_H
32 #ifndef CONFIG_XNUPOST
33 #error "Testing is not enabled if CONFIG_XNUPOST is not enabled"
36 #include <kern/kern_types.h>
37 #include <kern/assert.h>
38 #include <tests/ktest.h>
40 #define XT_CONFIG_RUN 0x0
41 #define XT_CONFIG_IGNORE 0x1
42 #define XT_CONFIG_EXPECT_PANIC 0x2
44 #define XTCTL_RUN_TESTS 1
45 #define XTCTL_RESET_TESTDATA 2
47 typedef enum { XT_ACTION_NONE
= 0, XT_ACTION_SKIPPED
, XT_ACTION_PASSED
, XT_ACTION_FAILED
} xnupost_test_action_t
;
49 typedef kern_return_t (*test_function
)(void);
53 kern_return_t xt_retval
;
54 kern_return_t xt_expected_retval
;
55 uint64_t xt_begin_time
;
57 xnupost_test_action_t xt_test_actions
;
58 test_function xt_func
;
62 typedef kern_return_t xt_panic_return_t
;
63 #define XT_PANIC_UNRELATED 0x8 /* not related. continue panic */
64 #define XT_RET_W_FAIL 0x9 /* report FAILURE and return from panic */
65 #define XT_RET_W_SUCCESS 0xA /* report SUCCESS and return from panic */
66 #define XT_PANIC_W_FAIL 0xB /* report FAILURE and continue to panic */
67 #define XT_PANIC_W_SUCCESS 0xC /* report SUCCESS and continue to panic */
69 typedef xt_panic_return_t (*xt_panic_widget_func
)(const char * panicstr
, void * context
, void ** outval
);
70 struct xnupost_panic_widget
{
73 const char * xtp_func_name
;
74 xt_panic_widget_func xtp_func
;
77 /* for internal use only. Use T_REGISTER_* macros */
78 extern xt_panic_return_t
_xt_generic_assert_check(const char * s
, void * str_to_match
, void ** outval
);
79 kern_return_t
xnupost_register_panic_widget(xt_panic_widget_func funcp
, const char * funcname
, void * context
, void ** outval
);
81 #define T_REGISTER_PANIC_WIDGET(func, ctx, outval) xnupost_register_panic_widget((func), #func, (ctx), (outval))
82 #define T_REGISTER_ASSERT_CHECK(assert_str, retval) \
83 T_REGISTER_PANIC_WIDGET(_xt_generic_assert_check, (void *)__DECONST(char *, assert_str), retval)
85 typedef struct xnupost_test xnupost_test_data_t
;
86 typedef struct xnupost_test
* xnupost_test_t
;
88 extern struct xnupost_test kernel_post_tests
[];
89 extern uint32_t kernel_post_tests_count
;
90 extern uint32_t total_post_tests_count
;
92 #define XNUPOST_TEST_CONFIG_BASIC(func) \
94 XT_CONFIG_RUN, 0, -1, T_STATE_PASS, 0, 0, 0, (func), "xnu."#func \
97 #define XNUPOST_TEST_CONFIG_TEST_PANIC(func) \
99 XT_CONFIG_EXPECT_PANIC, 0, -1, T_STATE_PASS, 0, 0, 0, (func), "xnu."#func \
102 void xnupost_init(void);
104 * Parse boot-args specific to POST testing and setup enabled/disabled settings
105 * returns: KERN_SUCCESS - if testing is enabled.
107 kern_return_t
xnupost_parse_config(void);
108 kern_return_t
xnupost_run_tests(xnupost_test_t test_list
, uint32_t test_count
);
109 kern_return_t
xnupost_list_tests(xnupost_test_t test_list
, uint32_t test_count
);
110 kern_return_t
xnupost_reset_tests(xnupost_test_t test_list
, uint32_t test_count
);
112 int xnupost_export_testdata(void * outp
, uint32_t size
, uint32_t * lenp
);
113 uint32_t xnupost_get_estimated_testdata_size(void);
115 kern_return_t
kernel_do_post(void);
116 kern_return_t
xnupost_process_kdb_stop(const char * panic_s
);
117 int xnupost_reset_all_tests(void);
119 kern_return_t
kernel_list_tests(void);
120 int bsd_do_post(void);
121 int bsd_list_tests(void);
123 #endif /* _TESTS_XNUPOST_H */