Skip to content

Commit 01be840

Browse files
authored
ClusterFuzz: Add a --no_retry option for local debugging (#7187)
When we run ClusterFuzz's run.py locally, we need to investigate any errors in creating fuzz testcases (as those are real bugs in wasm-opt). Previously we just checked for a "retry" message in the output of run.py (as the script retries automatically - we don't want a wasm-opt bug to stop ClusterFuzz), but that makes it impossible to debug the problem, since the retry tramples the data. The new option, used only locally, stops at the error so it can be investigated.
1 parent fcea593 commit 01be840

2 files changed

Lines changed: 22 additions & 10 deletions

File tree

scripts/clusterfuzz/run.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,12 @@ def get_file_name(prefix, index):
9292
# (We also use urandom below, which uses this under the hood.)
9393
system_random = random.SystemRandom()
9494

95+
# In production ClusterFuzz we retry whenever we see a wasm-opt error. We are
96+
# not looking for wasm-opt issues there, and just use it to generate testcases
97+
# for VMs. For local testing, however, we may want to disable retrying, which
98+
# allows us to debug any such failures that we run into.
99+
retry = True
100+
95101

96102
# Generate a random wasm file, and return a string that creates a typed array of
97103
# those bytes, suitable for use in a JS file, in the form
@@ -117,6 +123,11 @@ def get_wasm_contents(i, output_dir):
117123
try:
118124
subprocess.check_call(cmd)
119125
except subprocess.CalledProcessError:
126+
if not retry:
127+
print('error in running wasm-opt')
128+
print(' '.join(cmd))
129+
raise
130+
120131
# Try again.
121132
print('(oops, retrying wasm-opt)')
122133
attempt += 1
@@ -217,13 +228,16 @@ def main(argv):
217228
# https://google.github.io/clusterfuzz/setting-up-fuzzing/blackbox-fuzzing/#uploading-a-fuzzer
218229
output_dir = '.'
219230
num = 100
220-
expected_flags = ['input_dir=', 'output_dir=', 'no_of_files=']
231+
expected_flags = ['input_dir=', 'output_dir=', 'no_of_files=', 'no_retry']
221232
optlist, _ = getopt.getopt(argv[1:], '', expected_flags)
222233
for option, value in optlist:
223234
if option == '--output_dir':
224235
output_dir = value
225236
elif option == '--no_of_files':
226237
num = int(value)
238+
elif option == '--no_retry':
239+
global retry
240+
retry = False
227241

228242
for i in range(1, num + 1):
229243
testcase_file_path = os.path.join(output_dir,

scripts/fuzz_opt.py

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1580,15 +1580,13 @@ def handle(self, wasm):
15801580
os.unlink(f)
15811581

15821582
# Call run.py(), similarly to how ClusterFuzz does.
1583-
out = run([sys.executable,
1584-
os.path.join(self.clusterfuzz_dir, 'run.py'),
1585-
'--output_dir=' + os.getcwd(),
1586-
'--no_of_files=1'])
1587-
1588-
# We should not see any mention of a wasm-opt error that caused a
1589-
# retry. On production ClusterFuzz this is not an error, but we do want
1590-
# to know about such issues, as they may be real bugs in wasm-opt.
1591-
assert 'retry' not in out, out
1583+
run([sys.executable,
1584+
os.path.join(self.clusterfuzz_dir, 'run.py'),
1585+
'--output_dir=' + os.getcwd(),
1586+
'--no_of_files=1',
1587+
# Do not retry on wasm-opt errors: we want to investigate
1588+
# them.
1589+
'--no_retry'])
15921590

15931591
# We should see the two files.
15941592
assert os.path.exists(fuzz_file)

0 commit comments

Comments
 (0)