@@ -128,6 +128,8 @@ def test_correct_host_repo_path(self, _, __):
128
128
os .path .basename (image_repo_path ))
129
129
130
130
131
+ @unittest .skipIf (not os .getenv ('INTEGRATION_TESTS' ),
132
+ 'INTEGRATION_TESTS=1 not set' )
131
133
class BuildFuzzersIntegrationTest (unittest .TestCase ):
132
134
"""Integration tests for build_fuzzers."""
133
135
@@ -229,75 +231,57 @@ def test_invalid_workspace(self):
229
231
))
230
232
231
233
232
- def remove_test_files (out_parent_dir , allowlist ):
233
- """Removes test files from |out_parent_dir| that are not in |allowlist|, a
234
- list of files with paths relative to the out directory."""
235
- out_dir = os .path .join (out_parent_dir , 'out' )
236
- allowlist = set (allowlist )
237
- for rel_out_path in os .listdir (out_dir ):
238
- if rel_out_path in allowlist :
239
- continue
240
- path_to_remove = os .path .join (out_dir , rel_out_path )
241
- if os .path .isdir (path_to_remove ):
242
- shutil .rmtree (path_to_remove )
243
- else :
244
- os .remove (path_to_remove )
245
-
246
-
247
234
class RunFuzzerIntegrationTestMixin : # pylint: disable=too-few-public-methods,invalid-name
248
235
"""Mixin for integration test classes that runbuild_fuzzers on builds of a
249
236
specific sanitizer."""
250
237
# These must be defined by children.
251
238
FUZZER_DIR = None
252
239
FUZZER = None
253
240
254
- def tearDown (self ):
255
- """Removes any existing crashes and test files."""
256
- remove_test_files (self .FUZZER_DIR , self .FUZZER )
257
-
258
241
def _test_run_with_sanitizer (self , fuzzer_dir , sanitizer ):
259
242
"""Calls run_fuzzers on fuzzer_dir and |sanitizer| and asserts
260
243
the run succeeded and that no bug was found."""
261
- run_success , bug_found = cifuzz .run_fuzzers (10 ,
262
- fuzzer_dir ,
263
- 'curl' ,
264
- sanitizer = sanitizer )
244
+ with test_helpers .temp_dir_copy (fuzzer_dir ) as fuzzer_dir_copy :
245
+ run_success , bug_found = cifuzz .run_fuzzers (10 ,
246
+ fuzzer_dir_copy ,
247
+ 'curl' ,
248
+ sanitizer = sanitizer )
265
249
self .assertTrue (run_success )
266
250
self .assertFalse (bug_found )
267
251
268
252
269
- class RunMemoryFuzzerIntegrationTest (unittest . TestCase ,
270
- RunFuzzerIntegrationTestMixin ):
253
+ class RunMemoryFuzzerIntegrationTest (RunFuzzerIntegrationTestMixin ,
254
+ unittest . TestCase ):
271
255
"""Integration test for build_fuzzers with an MSAN build."""
272
256
FUZZER_DIR = MEMORY_FUZZER_DIR
273
257
FUZZER = MEMORY_FUZZER
274
258
259
+ @unittest .skipIf (not os .getenv ('INTEGRATION_TESTS' ),
260
+ 'INTEGRATION_TESTS=1 not set' )
275
261
def test_run_with_memory_sanitizer (self ):
276
262
"""Tests run_fuzzers with a valid MSAN build."""
277
263
self ._test_run_with_sanitizer (self .FUZZER_DIR , 'memory' )
278
264
279
265
280
- class RunUndefinedFuzzerIntegrationTest (unittest . TestCase ,
281
- RunFuzzerIntegrationTestMixin ):
266
+ class RunUndefinedFuzzerIntegrationTest (RunFuzzerIntegrationTestMixin ,
267
+ unittest . TestCase ):
282
268
"""Integration test for build_fuzzers with an UBSAN build."""
283
269
FUZZER_DIR = UNDEFINED_FUZZER_DIR
284
270
FUZZER = UNDEFINED_FUZZER
285
271
272
+ @unittest .skipIf (not os .getenv ('INTEGRATION_TESTS' ),
273
+ 'INTEGRATION_TESTS=1 not set' )
286
274
def test_run_with_undefined_sanitizer (self ):
287
- """Tests run_fuzzers with a valid MSAN build."""
275
+ """Tests run_fuzzers with a valid UBSAN build."""
288
276
self ._test_run_with_sanitizer (self .FUZZER_DIR , 'undefined' )
289
277
290
278
291
- class RunAddressFuzzersIntegrationTest (unittest .TestCase ):
279
+ class RunAddressFuzzersIntegrationTest (RunFuzzerIntegrationTestMixin ,
280
+ unittest .TestCase ):
292
281
"""Integration tests for build_fuzzers with an ASAN build."""
293
282
294
- def tearDown (self ):
295
- """Removes any existing crashes and test files."""
296
- files_to_keep = [
297
- 'undefined' , 'memory' , EXAMPLE_CRASH_FUZZER , EXAMPLE_NOCRASH_FUZZER
298
- ]
299
- remove_test_files (TEST_FILES_PATH , files_to_keep )
300
-
283
+ @unittest .skipIf (not os .getenv ('INTEGRATION_TESTS' ),
284
+ 'INTEGRATION_TESTS=1 not set' )
301
285
def test_new_bug_found (self ):
302
286
"""Tests run_fuzzers with a valid ASAN build."""
303
287
# Set the first return value to True, then the second to False to
@@ -314,6 +298,8 @@ def test_new_bug_found(self):
314
298
self .assertTrue (run_success )
315
299
self .assertTrue (bug_found )
316
300
301
+ @unittest .skipIf (not os .getenv ('INTEGRATION_TESTS' ),
302
+ 'INTEGRATION_TESTS=1 not set' )
317
303
def test_old_bug_found (self ):
318
304
"""Tests run_fuzzers with a bug found in OSS-Fuzz before."""
319
305
with mock .patch .object (fuzz_target .FuzzTarget ,
@@ -409,6 +395,8 @@ def test_allow_broken_fuzz_targets_percentage(self, mocked_docker_run):
409
395
' ' .join (mocked_docker_run .call_args [0 ][0 ]))
410
396
411
397
398
+ @unittest .skipIf (not os .getenv ('INTEGRATION_TESTS' ),
399
+ 'INTEGRATION_TESTS=1 not set' )
412
400
class GetFilesCoveredByTargetTest (unittest .TestCase ):
413
401
"""Tests get_files_covered_by_target."""
414
402
0 commit comments