21
21
import kunit
22
22
23
23
test_tmpdir = ''
24
+ abs_test_data_dir = ''
24
25
25
26
def setUpModule ():
26
- global test_tmpdir
27
+ global test_tmpdir , abs_test_data_dir
27
28
test_tmpdir = tempfile .mkdtemp ()
29
+ abs_test_data_dir = os .path .abspath (os .path .join (os .path .dirname (__file__ ), 'test_data' ))
28
30
29
31
def tearDownModule ():
30
32
shutil .rmtree (test_tmpdir )
31
33
32
- def get_absolute_path (path ):
33
- return os .path .join (os . path . dirname ( __file__ ) , path )
34
+ def test_data_path (path ):
35
+ return os .path .join (abs_test_data_dir , path )
34
36
35
37
class KconfigTest (unittest .TestCase ):
36
38
@@ -46,8 +48,7 @@ def test_is_subset_of(self):
46
48
47
49
def test_read_from_file (self ):
48
50
kconfig = kunit_config .Kconfig ()
49
- kconfig_path = get_absolute_path (
50
- 'test_data/test_read_from_file.kconfig' )
51
+ kconfig_path = test_data_path ('test_read_from_file.kconfig' )
51
52
52
53
kconfig .read_from_file (kconfig_path )
53
54
@@ -98,8 +99,7 @@ def assertContains(self, needle, haystack):
98
99
str (needle ) + '" not found in "' + str (haystack ) + '"!' )
99
100
100
101
def test_output_isolated_correctly (self ):
101
- log_path = get_absolute_path (
102
- 'test_data/test_output_isolated_correctly.log' )
102
+ log_path = test_data_path ('test_output_isolated_correctly.log' )
103
103
with open (log_path ) as file :
104
104
result = kunit_parser .isolate_kunit_output (file .readlines ())
105
105
self .assertContains ('TAP version 14' , result )
@@ -110,8 +110,7 @@ def test_output_isolated_correctly(self):
110
110
self .assertContains ('ok 1 - example' , result )
111
111
112
112
def test_output_with_prefix_isolated_correctly (self ):
113
- log_path = get_absolute_path (
114
- 'test_data/test_pound_sign.log' )
113
+ log_path = test_data_path ('test_pound_sign.log' )
115
114
with open (log_path ) as file :
116
115
result = kunit_parser .isolate_kunit_output (file .readlines ())
117
116
self .assertContains ('TAP version 14' , result )
@@ -140,26 +139,23 @@ def test_output_with_prefix_isolated_correctly(self):
140
139
self .assertContains ('ok 3 - string-stream-test' , result )
141
140
142
141
def test_parse_successful_test_log (self ):
143
- all_passed_log = get_absolute_path (
144
- 'test_data/test_is_test_passed-all_passed.log' )
142
+ all_passed_log = test_data_path ('test_is_test_passed-all_passed.log' )
145
143
with open (all_passed_log ) as file :
146
144
result = kunit_parser .parse_run_tests (file .readlines ())
147
145
self .assertEqual (
148
146
kunit_parser .TestStatus .SUCCESS ,
149
147
result .status )
150
148
151
149
def test_parse_failed_test_log (self ):
152
- failed_log = get_absolute_path (
153
- 'test_data/test_is_test_passed-failure.log' )
150
+ failed_log = test_data_path ('test_is_test_passed-failure.log' )
154
151
with open (failed_log ) as file :
155
152
result = kunit_parser .parse_run_tests (file .readlines ())
156
153
self .assertEqual (
157
154
kunit_parser .TestStatus .FAILURE ,
158
155
result .status )
159
156
160
157
def test_no_tests (self ):
161
- empty_log = get_absolute_path (
162
- 'test_data/test_is_test_passed-no_tests_run.log' )
158
+ empty_log = test_data_path ('test_is_test_passed-no_tests_run.log' )
163
159
with open (empty_log ) as file :
164
160
result = kunit_parser .parse_run_tests (
165
161
kunit_parser .isolate_kunit_output (file .readlines ()))
@@ -169,8 +165,7 @@ def test_no_tests(self):
169
165
result .status )
170
166
171
167
def test_no_kunit_output (self ):
172
- crash_log = get_absolute_path (
173
- 'test_data/test_insufficient_memory.log' )
168
+ crash_log = test_data_path ('test_insufficient_memory.log' )
174
169
print_mock = mock .patch ('builtins.print' ).start ()
175
170
with open (crash_log ) as file :
176
171
result = kunit_parser .parse_run_tests (
@@ -180,17 +175,15 @@ def test_no_kunit_output(self):
180
175
file .close ()
181
176
182
177
def test_crashed_test (self ):
183
- crashed_log = get_absolute_path (
184
- 'test_data/test_is_test_passed-crash.log' )
178
+ crashed_log = test_data_path ('test_is_test_passed-crash.log' )
185
179
with open (crashed_log ) as file :
186
180
result = kunit_parser .parse_run_tests (file .readlines ())
187
181
self .assertEqual (
188
182
kunit_parser .TestStatus .TEST_CRASHED ,
189
183
result .status )
190
184
191
185
def test_ignores_prefix_printk_time (self ):
192
- prefix_log = get_absolute_path (
193
- 'test_data/test_config_printk_time.log' )
186
+ prefix_log = test_data_path ('test_config_printk_time.log' )
194
187
with open (prefix_log ) as file :
195
188
result = kunit_parser .parse_run_tests (file .readlines ())
196
189
self .assertEqual (
@@ -199,8 +192,7 @@ def test_ignores_prefix_printk_time(self):
199
192
self .assertEqual ('kunit-resource-test' , result .suites [0 ].name )
200
193
201
194
def test_ignores_multiple_prefixes (self ):
202
- prefix_log = get_absolute_path (
203
- 'test_data/test_multiple_prefixes.log' )
195
+ prefix_log = test_data_path ('test_multiple_prefixes.log' )
204
196
with open (prefix_log ) as file :
205
197
result = kunit_parser .parse_run_tests (file .readlines ())
206
198
self .assertEqual (
@@ -209,8 +201,7 @@ def test_ignores_multiple_prefixes(self):
209
201
self .assertEqual ('kunit-resource-test' , result .suites [0 ].name )
210
202
211
203
def test_prefix_mixed_kernel_output (self ):
212
- mixed_prefix_log = get_absolute_path (
213
- 'test_data/test_interrupted_tap_output.log' )
204
+ mixed_prefix_log = test_data_path ('test_interrupted_tap_output.log' )
214
205
with open (mixed_prefix_log ) as file :
215
206
result = kunit_parser .parse_run_tests (file .readlines ())
216
207
self .assertEqual (
@@ -219,7 +210,7 @@ def test_prefix_mixed_kernel_output(self):
219
210
self .assertEqual ('kunit-resource-test' , result .suites [0 ].name )
220
211
221
212
def test_prefix_poundsign (self ):
222
- pound_log = get_absolute_path ( 'test_data/ test_pound_sign.log' )
213
+ pound_log = test_data_path ( ' test_pound_sign.log' )
223
214
with open (pound_log ) as file :
224
215
result = kunit_parser .parse_run_tests (file .readlines ())
225
216
self .assertEqual (
@@ -228,7 +219,7 @@ def test_prefix_poundsign(self):
228
219
self .assertEqual ('kunit-resource-test' , result .suites [0 ].name )
229
220
230
221
def test_kernel_panic_end (self ):
231
- panic_log = get_absolute_path ( 'test_data/ test_kernel_panic_interrupt.log' )
222
+ panic_log = test_data_path ( ' test_kernel_panic_interrupt.log' )
232
223
with open (panic_log ) as file :
233
224
result = kunit_parser .parse_run_tests (file .readlines ())
234
225
self .assertEqual (
@@ -237,7 +228,7 @@ def test_kernel_panic_end(self):
237
228
self .assertEqual ('kunit-resource-test' , result .suites [0 ].name )
238
229
239
230
def test_pound_no_prefix (self ):
240
- pound_log = get_absolute_path ( 'test_data/ test_pound_no_prefix.log' )
231
+ pound_log = test_data_path ( ' test_pound_no_prefix.log' )
241
232
with open (pound_log ) as file :
242
233
result = kunit_parser .parse_run_tests (file .readlines ())
243
234
self .assertEqual (
@@ -248,7 +239,7 @@ def test_pound_no_prefix(self):
248
239
class KUnitJsonTest (unittest .TestCase ):
249
240
250
241
def _json_for (self , log_file ):
251
- with ( open (get_absolute_path (log_file ) )) as file :
242
+ with open (test_data_path (log_file )) as file :
252
243
test_result = kunit_parser .parse_run_tests (file )
253
244
json_obj = kunit_json .get_json_result (
254
245
test_result = test_result ,
@@ -258,22 +249,19 @@ def _json_for(self, log_file):
258
249
return json .loads (json_obj )
259
250
260
251
def test_failed_test_json (self ):
261
- result = self ._json_for (
262
- 'test_data/test_is_test_passed-failure.log' )
252
+ result = self ._json_for ('test_is_test_passed-failure.log' )
263
253
self .assertEqual (
264
254
{'name' : 'example_simple_test' , 'status' : 'FAIL' },
265
255
result ["sub_groups" ][1 ]["test_cases" ][0 ])
266
256
267
257
def test_crashed_test_json (self ):
268
- result = self ._json_for (
269
- 'test_data/test_is_test_passed-crash.log' )
258
+ result = self ._json_for ('test_is_test_passed-crash.log' )
270
259
self .assertEqual (
271
260
{'name' : 'example_simple_test' , 'status' : 'ERROR' },
272
261
result ["sub_groups" ][1 ]["test_cases" ][0 ])
273
262
274
263
def test_no_tests_json (self ):
275
- result = self ._json_for (
276
- 'test_data/test_is_test_passed-no_tests_run.log' )
264
+ result = self ._json_for ('test_is_test_passed-no_tests_run.log' )
277
265
self .assertEqual (0 , len (result ['sub_groups' ]))
278
266
279
267
class StrContains (str ):
@@ -282,7 +270,7 @@ def __eq__(self, other):
282
270
283
271
class KUnitMainTest (unittest .TestCase ):
284
272
def setUp (self ):
285
- path = get_absolute_path ( 'test_data/ test_is_test_passed-all_passed.log' )
273
+ path = test_data_path ( ' test_is_test_passed-all_passed.log' )
286
274
with open (path ) as file :
287
275
all_passed_log = file .readlines ()
288
276
0 commit comments