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 #include <tests/ktest.h>
30 #include <tests/ktest_internal.h>
31 #include <mach/mach_time.h>
32 #include <kern/misc_protos.h>
45 ktest_testbegin(const char * test_name
) {
46 ktest_current_time
= mach_absolute_time();
47 ktest_test_name
= test_name
;
48 ktest_emit_testbegin(test_name
);
53 ktest_current_time
= mach_absolute_time();
59 ktest_testskip(const char * msg
, ...) {
62 ktest_current_time
= mach_absolute_time();
65 ktest_emit_testskip(msg
, args
);
71 ktest_log(const char * msg
, ...) {
74 ktest_current_time
= mach_absolute_time();
77 ktest_emit_log(msg
, args
);
82 ktest_perf(const char * metric
, const char * unit
, double value
, const char * desc
)
84 ktest_current_time
= mach_absolute_time();
85 ktest_emit_perfdata(metric
, unit
, value
, desc
);
89 ktest_testcase(int success
)
91 ktest_current_time
= mach_absolute_time();
93 if(success
&& !ktest_expectfail
) {
96 ktest_testcase_result
= T_RESULT_PASS
;
97 } else if(!success
&& !ktest_expectfail
) {
100 ktest_testcase_result
= T_RESULT_FAIL
;
101 } else if(success
&& ktest_expectfail
) {
104 ktest_testcase_result
= T_RESULT_UXPASS
;
105 } else if(!success
&& ktest_expectfail
) {
108 ktest_testcase_result
= T_RESULT_XFAIL
;
111 ktest_update_test_result_state();
112 if(ktest_quiet
== 0 ||
113 ktest_testcase_result
== T_RESULT_FAIL
||
114 ktest_testcase_result
== T_RESULT_UXPASS
) {
115 ktest_emit_testcase();
117 ktest_expression_index
++;
120 ktest_expectfail
= 0;
121 ktest_output_buf
[0] = '\0';
122 ktest_current_msg
[0] = '\0';
123 ktest_current_expr
[0] = '\0';
124 for(int i
= 0; i
< KTEST_MAXVARS
; i
++) {
125 ktest_current_var_names
[i
][0] = '\0';
126 ktest_current_var_values
[i
][0] = '\0';
128 ktest_current_var_index
= 0;
132 ktest_update_test_result_state(void) {
133 ktest_test_result
= ktest_test_result_statetab
[ktest_test_result
]
134 [ktest_testcase_result
]
135 [ktest_testcase_mode
];
139 ktest_assertion_check(void) {
140 if (ktest_testcase_result
== T_RESULT_FAIL
|| ktest_testcase_result
== T_RESULT_UXPASS
) {
142 panic("XNUPOST: Assertion failed : %s : at %s:%d", ktest_test_name
, ktest_current_file
, ktest_current_line
);