]> git.saurik.com Git - apple/xnu.git/blame - osfmk/tests/xnupost.h
xnu-6153.11.26.tar.gz
[apple/xnu.git] / osfmk / tests / xnupost.h
CommitLineData
d9a64523 1/*
cb323159 2 * Copyright (c) 2019 Apple Inc. All rights reserved.
d9a64523
A
3 *
4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
5 *
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.
14 *
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
17 *
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.
25 *
26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
27 */
28
29#ifndef _TESTS_XNUPOST_H
30#define _TESTS_XNUPOST_H
31
32#ifndef CONFIG_XNUPOST
33#error "Testing is not enabled if CONFIG_XNUPOST is not enabled"
34#endif
35
36#include <kern/kern_types.h>
37#include <kern/assert.h>
38#include <tests/ktest.h>
39
40#define XT_CONFIG_RUN 0x0
41#define XT_CONFIG_IGNORE 0x1
42#define XT_CONFIG_EXPECT_PANIC 0x2
43
44#define XTCTL_RUN_TESTS 1
45#define XTCTL_RESET_TESTDATA 2
46
47typedef enum { XT_ACTION_NONE = 0, XT_ACTION_SKIPPED, XT_ACTION_PASSED, XT_ACTION_FAILED } xnupost_test_action_t;
48
49typedef kern_return_t (*test_function)(void);
50struct xnupost_test {
51 uint16_t xt_config;
52 uint16_t xt_test_num;
53 kern_return_t xt_retval;
54 kern_return_t xt_expected_retval;
55 uint64_t xt_begin_time;
56 uint64_t xt_end_time;
57 xnupost_test_action_t xt_test_actions;
58 test_function xt_func;
59 const char * xt_name;
60};
61
62typedef 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 */
68
69typedef xt_panic_return_t (*xt_panic_widget_func)(const char * panicstr, void * context, void ** outval);
70struct xnupost_panic_widget {
71 void * xtp_context_p;
72 void ** xtp_outval_p;
73 const char * xtp_func_name;
74 xt_panic_widget_func xtp_func;
75};
76
77/* for internal use only. Use T_REGISTER_* macros */
78extern xt_panic_return_t _xt_generic_assert_check(const char * s, void * str_to_match, void ** outval);
79kern_return_t xnupost_register_panic_widget(xt_panic_widget_func funcp, const char * funcname, void * context, void ** outval);
80
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)
84
85typedef struct xnupost_test xnupost_test_data_t;
86typedef struct xnupost_test * xnupost_test_t;
87
88extern struct xnupost_test kernel_post_tests[];
89extern uint32_t kernel_post_tests_count;
90extern uint32_t total_post_tests_count;
91
92#define XNUPOST_TEST_CONFIG_BASIC(func) \
cb323159
A
93 { \
94 .xt_config = XT_CONFIG_RUN, \
95 .xt_test_num = 0, \
96 .xt_retval = -1, \
97 .xt_expected_retval = T_STATE_PASS, \
98 .xt_begin_time = 0, \
99 .xt_end_time = 0, \
100 .xt_test_actions = 0, \
101 .xt_func = (func), \
102 .xt_name = "xnu."#func \
d9a64523
A
103 }
104
105#define XNUPOST_TEST_CONFIG_TEST_PANIC(func) \
cb323159
A
106 { \
107 .xt_config = XT_CONFIG_EXPECT_PANIC, \
108 .xt_test_num = 0, \
109 .xt_retval = -1, \
110 .xt_expected_retval = T_STATE_PASS, \
111 .xt_begin_time = 0, \
112 .xt_end_time = 0, \
113 .xt_test_actions = 0, \
114 .xt_func = (func), \
115 .xt_name = "xnu."#func \
d9a64523
A
116 }
117
118void xnupost_init(void);
119/*
120 * Parse boot-args specific to POST testing and setup enabled/disabled settings
121 * returns: KERN_SUCCESS - if testing is enabled.
122 */
123kern_return_t xnupost_parse_config(void);
124kern_return_t xnupost_run_tests(xnupost_test_t test_list, uint32_t test_count);
125kern_return_t xnupost_list_tests(xnupost_test_t test_list, uint32_t test_count);
126kern_return_t xnupost_reset_tests(xnupost_test_t test_list, uint32_t test_count);
127
128int xnupost_export_testdata(void * outp, uint32_t size, uint32_t * lenp);
129uint32_t xnupost_get_estimated_testdata_size(void);
130
131kern_return_t kernel_do_post(void);
132kern_return_t xnupost_process_kdb_stop(const char * panic_s);
133int xnupost_reset_all_tests(void);
134
135kern_return_t kernel_list_tests(void);
136int bsd_do_post(void);
137int bsd_list_tests(void);
138
139#endif /* _TESTS_XNUPOST_H */