]>
Commit | Line | Data |
---|---|---|
d9a64523 A |
1 | /* |
2 | * Copyright (c) 2015 Apple Inc. All rights reserved. | |
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 | #include <tests/ktest.h> | |
30 | #include <tests/ktest_internal.h> | |
31 | #include <mach/mach_time.h> | |
32 | #include <kern/misc_protos.h> | |
33 | ||
34 | void | |
0a7de745 A |
35 | ktest_start(void) |
36 | { | |
d9a64523 A |
37 | ktest_emit_start(); |
38 | } | |
39 | ||
40 | void | |
0a7de745 A |
41 | ktest_finish(void) |
42 | { | |
d9a64523 A |
43 | ktest_emit_finish(); |
44 | } | |
45 | ||
46 | void | |
0a7de745 A |
47 | ktest_testbegin(const char * test_name) |
48 | { | |
d9a64523 A |
49 | ktest_current_time = mach_absolute_time(); |
50 | ktest_test_name = test_name; | |
51 | ktest_emit_testbegin(test_name); | |
52 | } | |
53 | ||
54 | void | |
0a7de745 A |
55 | ktest_testend() |
56 | { | |
d9a64523 A |
57 | ktest_current_time = mach_absolute_time(); |
58 | ktest_emit_testend(); | |
59 | ktest_test_index++; | |
60 | } | |
61 | ||
62 | void | |
0a7de745 A |
63 | ktest_testskip(const char * msg, ...) |
64 | { | |
d9a64523 A |
65 | va_list args; |
66 | ||
67 | ktest_current_time = mach_absolute_time(); | |
68 | ||
69 | va_start(args, msg); | |
70 | ktest_emit_testskip(msg, args); | |
71 | va_end(args); | |
d9a64523 A |
72 | } |
73 | ||
74 | void | |
0a7de745 A |
75 | ktest_log(const char * msg, ...) |
76 | { | |
d9a64523 A |
77 | va_list args; |
78 | ||
79 | ktest_current_time = mach_absolute_time(); | |
80 | ||
81 | va_start(args, msg); | |
82 | ktest_emit_log(msg, args); | |
83 | va_end(args); | |
84 | } | |
85 | ||
86 | void | |
87 | ktest_perf(const char * metric, const char * unit, double value, const char * desc) | |
88 | { | |
89 | ktest_current_time = mach_absolute_time(); | |
90 | ktest_emit_perfdata(metric, unit, value, desc); | |
91 | } | |
92 | ||
93 | void | |
94 | ktest_testcase(int success) | |
95 | { | |
96 | ktest_current_time = mach_absolute_time(); | |
97 | ||
0a7de745 | 98 | if (success && !ktest_expectfail) { |
d9a64523 A |
99 | /* PASS */ |
100 | ktest_passcount++; | |
101 | ktest_testcase_result = T_RESULT_PASS; | |
0a7de745 | 102 | } else if (!success && !ktest_expectfail) { |
d9a64523 A |
103 | /* FAIL */ |
104 | ktest_failcount++; | |
105 | ktest_testcase_result = T_RESULT_FAIL; | |
0a7de745 | 106 | } else if (success && ktest_expectfail) { |
d9a64523 A |
107 | /* UXPASS */ |
108 | ktest_xpasscount++; | |
109 | ktest_testcase_result = T_RESULT_UXPASS; | |
0a7de745 | 110 | } else if (!success && ktest_expectfail) { |
d9a64523 A |
111 | /* XFAIL */ |
112 | ktest_xfailcount++; | |
113 | ktest_testcase_result = T_RESULT_XFAIL; | |
114 | } | |
115 | ||
116 | ktest_update_test_result_state(); | |
0a7de745 A |
117 | if (ktest_quiet == 0 || |
118 | ktest_testcase_result == T_RESULT_FAIL || | |
119 | ktest_testcase_result == T_RESULT_UXPASS) { | |
d9a64523 A |
120 | ktest_emit_testcase(); |
121 | } | |
122 | ktest_expression_index++; | |
123 | ||
124 | ktest_quiet = 0; | |
125 | ktest_expectfail = 0; | |
126 | ktest_output_buf[0] = '\0'; | |
127 | ktest_current_msg[0] = '\0'; | |
128 | ktest_current_expr[0] = '\0'; | |
0a7de745 | 129 | for (int i = 0; i < KTEST_MAXVARS; i++) { |
d9a64523 A |
130 | ktest_current_var_names[i][0] = '\0'; |
131 | ktest_current_var_values[i][0] = '\0'; | |
132 | } | |
133 | ktest_current_var_index = 0; | |
134 | } | |
135 | ||
136 | void | |
0a7de745 A |
137 | ktest_update_test_result_state(void) |
138 | { | |
d9a64523 | 139 | ktest_test_result = ktest_test_result_statetab[ktest_test_result] |
0a7de745 A |
140 | [ktest_testcase_result] |
141 | [ktest_testcase_mode]; | |
d9a64523 A |
142 | } |
143 | ||
144 | void | |
0a7de745 A |
145 | ktest_assertion_check(void) |
146 | { | |
d9a64523 A |
147 | if (ktest_testcase_result == T_RESULT_FAIL || ktest_testcase_result == T_RESULT_UXPASS) { |
148 | ktest_testend(); | |
149 | panic("XNUPOST: Assertion failed : %s : at %s:%d", ktest_test_name, ktest_current_file, ktest_current_line); | |
150 | } | |
151 | } |