Skip to content

Commit c744bd1

Browse files
authored
[NFC] Improve ClusterFuzz testing (#7157)
1. Error on retrying due to a wasm-opt issue, locally (in production, we don't want to error on ClusterFuzz). 2. Move some asserts from test_run_py to the helper generate_testcases (so that the asserts happen in all callers).
1 parent d444abd commit c744bd1

File tree

2 files changed

+23
-15
lines changed

2 files changed

+23
-15
lines changed

scripts/fuzz_opt.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1654,10 +1654,15 @@ def handle(self, wasm):
16541654
os.unlink(f)
16551655

16561656
# Call run.py(), similarly to how ClusterFuzz does.
1657-
run([sys.executable,
1658-
os.path.join(self.clusterfuzz_dir, 'run.py'),
1659-
'--output_dir=' + os.getcwd(),
1660-
'--no_of_files=1'])
1657+
out = run([sys.executable,
1658+
os.path.join(self.clusterfuzz_dir, 'run.py'),
1659+
'--output_dir=' + os.getcwd(),
1660+
'--no_of_files=1'])
1661+
1662+
# We should not see any mention of a wasm-opt error that caused a
1663+
# retry. On production ClusterFuzz this is not an error, but we do want
1664+
# to know about such issues, as they may be real bugs in wasm-opt.
1665+
assert 'retry' not in out, out
16611666

16621667
# We should see the two files.
16631668
assert os.path.exists(fuzz_file)

test/unit/test_cluster_fuzz.py

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -74,22 +74,14 @@ def generate_testcases(self, N, testcase_dir):
7474
stdout=subprocess.PIPE,
7575
stderr=subprocess.PIPE)
7676
self.assertEqual(proc.returncode, 0)
77-
return proc
78-
79-
# Test the bundled run.py script.
80-
def test_run_py(self):
81-
temp_dir = tempfile.TemporaryDirectory()
82-
83-
N = 10
84-
proc = self.generate_testcases(N, temp_dir.name)
8577

8678
# We should have logged the creation of N testcases.
8779
self.assertEqual(proc.stdout.count('Created testcase:'), N)
8880

8981
# We should have actually created them.
9082
for i in range(0, N + 2):
91-
fuzz_file = os.path.join(temp_dir.name, f'fuzz-binaryen-{i}.js')
92-
flags_file = os.path.join(temp_dir.name, f'flags-binaryen-{i}.js')
83+
fuzz_file = os.path.join(testcase_dir, f'fuzz-binaryen-{i}.js')
84+
flags_file = os.path.join(testcase_dir, f'flags-binaryen-{i}.js')
9385
# We actually emit the range [1, N], so 0 or N+1 should not exist.
9486
if i >= 1 and i <= N:
9587
self.assertTrue(os.path.exists(fuzz_file))
@@ -98,8 +90,19 @@ def test_run_py(self):
9890
self.assertTrue(not os.path.exists(fuzz_file))
9991
self.assertTrue(not os.path.exists(flags_file))
10092

93+
return proc
94+
95+
# Test the bundled run.py script.
96+
def test_run_py(self):
97+
temp_dir = tempfile.TemporaryDirectory()
98+
99+
N = 10
100+
proc = self.generate_testcases(N, temp_dir.name)
101+
101102
# Run.py should report no errors or warnings to stderr, except from
102-
# those we know are safe.
103+
# those we know are safe (we cannot test this in generate_testcases,
104+
# because the caller could do something like set BINARYEN_PASS_DEBUG,
105+
# which generates intentional stderr warnings).
103106
SAFE_WARNINGS = [
104107
# When we randomly pick no passes to run, this is shown.
105108
'warning: no passes specified, not doing any work',

0 commit comments

Comments
 (0)