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>
47 ktest_testbegin(const char * test_name
)
49 ktest_current_time
= mach_absolute_time();
50 ktest_test_name
= test_name
;
51 ktest_emit_testbegin(test_name
);
57 ktest_current_time
= mach_absolute_time();
63 ktest_testskip(const char * msg
, ...)
67 ktest_current_time
= mach_absolute_time();
70 ktest_emit_testskip(msg
, args
);
75 ktest_log(const char * msg
, ...)
79 ktest_current_time
= mach_absolute_time();
82 ktest_emit_log(msg
, args
);
87 ktest_perf(const char * metric
, const char * unit
, double value
, const char * desc
)
89 ktest_current_time
= mach_absolute_time();
90 ktest_emit_perfdata(metric
, unit
, value
, desc
);
94 ktest_testcase(int success
)
96 ktest_current_time
= mach_absolute_time();
98 if (success
&& !ktest_expectfail
) {
101 ktest_testcase_result
= T_RESULT_PASS
;
102 } else if (!success
&& !ktest_expectfail
) {
105 ktest_testcase_result
= T_RESULT_FAIL
;
106 } else if (success
&& ktest_expectfail
) {
109 ktest_testcase_result
= T_RESULT_UXPASS
;
110 } else if (!success
&& ktest_expectfail
) {
113 ktest_testcase_result
= T_RESULT_XFAIL
;
116 ktest_update_test_result_state();
117 if (ktest_quiet
== 0 ||
118 ktest_testcase_result
== T_RESULT_FAIL
||
119 ktest_testcase_result
== T_RESULT_UXPASS
) {
120 ktest_emit_testcase();
122 ktest_expression_index
++;
125 ktest_expectfail
= 0;
126 ktest_output_buf
[0] = '\0';
127 ktest_current_msg
[0] = '\0';
128 ktest_current_expr
[0] = '\0';
129 for (int i
= 0; i
< KTEST_MAXVARS
; i
++) {
130 ktest_current_var_names
[i
][0] = '\0';
131 ktest_current_var_values
[i
][0] = '\0';
133 ktest_current_var_index
= 0;
137 ktest_update_test_result_state(void)
139 ktest_test_result
= ktest_test_result_statetab
[ktest_test_result
]
140 [ktest_testcase_result
]
141 [ktest_testcase_mode
];
145 ktest_assertion_check(void)
147 if (ktest_testcase_result
== T_RESULT_FAIL
|| ktest_testcase_result
== T_RESULT_UXPASS
) {
149 panic("XNUPOST: Assertion failed : %s : at %s:%d", ktest_test_name
, ktest_current_file
, ktest_current_line
);