同步操作将从 Gitee 极速下载/darwin-xnu 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
The tests directories osfmk/tests and bsd/tests include set of tests that run in kernel at boot-time. The primary objective for these tests is to verify functionality of various subsystems like memory allocators, scheduling, VM, IPC ports etc. Following are some tips and guidelines to creating and running tests.
kernPOST=0x1
"" to enable kernel testing on boot.usb get /patch/to/kc
"bootx
"[KTEST] <test> logs
"Kernel POST supports configuring test through boot-args. For example if you want to run your test #8 (say you are tweaking it to do more testing). Just set "kernPOST_config=8
" and only your test will be run. The configuration also takes ranges as follows
-> kernPOST_config=1_3,5_9999 # skip test#4. Will run tests 1,2,3 and 5,6 and onwards.
-> kernPOST_config=1_3,4_9999 # will not skip anything. lower_upper are both inclusive.
Adding a new kernel POST test is very simple. Here are a few steps and guidelines for adding tests.
osfmk/tests/
and bsd/tests
where you can add tests based on your area of testing.#include <xnupost.h>
to include required functions and macros for testing. Remember to add file_name.c in osfmk/conf/files
or bsd/conf/files
asosfmk/tests/my_tests.c optional config_xnupost
kern_return_t my_sample_tests(void);
struct xnupost_test kernel_post_tests[] = {
XNUPOST_TEST_CONFIG_BASIC(my_sample_tests), // simple test
XNUPOST_TEST_CONFIG_TEST_PANIC(panic_test) // test that is expected to panic
};
kern_return_t my_sample_tests() {
uint64_t test_begin_timestamp = 0;
uint64_t cur_timestamp = 0, tmp;
T_SETUPBEGIN;
test_begin_timestamp = mach_absolute_time();
T_ASSERT_NOTNULL(test_begin_timestamp, "mach_absolute_time returned 0.");
T_SETUPEND;
T_LOG("Testing mach_absolute_time for 100 iterations");
for (int i = 0; i < 100; i++) {
tmp = mach_absolute_time();
T_EXPECT_TRUE((cur_timestamp <= tmp ), "Time went backwards");
cur_timestamp = tmp;
}
T_LOG("Completed mach_absolute_time tests.");
return KERN_SUCCESS;
}
Bats has a new test type kernel_POST that runs Lean test environment tests. You can run the following command to get POST testing.
~osdev/tat/dev/bin/bats build -b <build> -t darwinLTE -p xnu:<branch> -r <radarnum>
The xnupost subsystem provides mechanism for setting up a panic widget
. This widget can check for some conditions and report test case SUCCESS/FAILURE. See xnupost.h for XT_RET*
style return values. There are convenience macros for registering for generic panic and for assertion handling. For example if you wish to check for api foo(int arg) { assert(arg > 0); ... } then a test case could be like
kern_return_t test_foo_arg_assertion(void) {
void * assert_retval = NULL;
kern_return_t kr = T_REGISTER_ASSERT_CHECK("arg > 0", &assert_retval);
T_ASSERT(kr == KERN_SUCCESS, "register assertion handler");
foo(-1); /* this will cause assert to fire */
T_ASSERT(assert_retval == (void *)XT_RET_W_SUCCESS, "verify assertion was hit");
}
On debug/development kernels, the panic()
code is modified to call out to XNUPOST system xnupost_process_panic()
. This callout can then determine if testing was enabled and has a widget registered for checking panics. If yes, then the corresponding widget function is called and the return value determines what action is taken. For example a widget could return either of the following values
XT_PANIC_UNRELATED /* not related. continue panic / XT_RET_W_FAIL / report FAILURE and return from panic / XT_RET_W_SUCCESS / report SUCCESS and return from panic / XT_PANIC_W_FAIL / report FAILURE and continue to panic / XT_PANIC_W_SUCCESS / report SUCCESS and continue to panic */
The panic widget data is saved in internal data array where each is of type: struct xnupost_panic_widget { void * xtp_context_p; /* a context pointer for callbacks to track / void ** xtp_outval_p; / an out param for function to return some value to running test / const char * xtp_func_name; / widget name for tracking in serial output */ xt_panic_widget_func xtp_func; };
There is an example use case in osfmk/tests/kernel_tests.c :check_panic_test() and panic_test()
for writing a widget.
For basic assertion check see example in osfmkt/tests/kernel_tests.c :kcdata_api_assert_tests()
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。