-
Notifications
You must be signed in to change notification settings - Fork 853
[Fuzzing] Use initial contents in ClusterFuzz #7192
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
1e2baa2
07606f6
7d3980c
6a85f2e
89bdcac
a69d7f8
374f5b1
88e12a4
170f7dd
5669479
0611b9c
bd0f0e9
3d9af45
28cb857
cd9f117
71d8a73
7b6171c
c21354c
c65cc27
32c30ab
e8e1e24
62f71c9
029fae6
3d03fa8
c8cc9b6
da419e8
f85cb36
1dc68d8
07ca22c
b9e0002
168cb5f
64be86c
9fbfba1
896f3dc
5cdf404
bded873
f91d80c
13572f9
0fe503b
e5cbaf5
77cf4fc
dfd9a96
a9c6f69
9b5ab79
23c84ec
01403c6
714572e
c41d01d
22628d7
fdfa966
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -71,6 +71,7 @@ | |
| ''' | ||
|
|
||
| import os | ||
| import subprocess | ||
| import sys | ||
| import tarfile | ||
|
|
||
|
|
@@ -87,7 +88,9 @@ | |
| # Delete the argument, as importing |shared| scans it. | ||
| sys.argv.pop() | ||
|
|
||
| from test import fuzzing # noqa | ||
| from test import shared # noqa | ||
| from test import support # noqa | ||
|
|
||
| # Pick where to get the builds | ||
| if build_dir: | ||
|
|
@@ -97,6 +100,14 @@ | |
| binaryen_bin = shared.options.binaryen_bin | ||
| binaryen_lib = shared.options.binaryen_lib | ||
|
|
||
| # ClusterFuzz's run.py uses these features. Keep this in sync with that, so that | ||
| # we only bundle initial content that makes sense for it. | ||
| features = [ | ||
| '-all', | ||
| '--disable-shared-everything', | ||
| '--disable-fp16', | ||
| ] | ||
|
Comment on lines
+105
to
+109
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would it be feasible to deduplicate these into a shared location?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not trivially, since |
||
|
|
||
| with tarfile.open(output_file, "w:gz") as tar: | ||
| # run.py | ||
| run = os.path.join(shared.options.binaryen_root, 'scripts', 'clusterfuzz', 'run.py') | ||
|
|
@@ -128,6 +139,40 @@ | |
| print(f' ......... : {path}') | ||
| tar.add(path, arcname=f'lib/{name}') | ||
|
|
||
| # Add tests we will use as initial content under initial/. We put all the | ||
| # tests from the test suite there. | ||
| print(' .. initial content: ') | ||
| temp_wasm = 'temp.wasm' | ||
| index = 0 | ||
| all_tests = shared.get_all_tests() | ||
| for i, test in enumerate(all_tests): | ||
| if not fuzzing.is_fuzzable(test): | ||
| continue | ||
| for wast, asserts in support.split_wast(test): | ||
| if not wast: | ||
| continue | ||
| support.write_wast(temp_wasm, wast) | ||
| # If the file is not valid for our features, skip it. In the same | ||
| # operation, also convert to binary if this was text (binary is more | ||
| # compact). | ||
| cmd = shared.WASM_OPT + ['-q', temp_wasm, '-o', temp_wasm] + features | ||
| if subprocess.run(cmd, stderr=subprocess.PIPE).returncode: | ||
| continue | ||
|
|
||
| # Looks good. | ||
| tar.add(temp_wasm, arcname=f'initial/{index}.wasm') | ||
| index += 1 | ||
| print(f'\r {100 * i / len(all_tests):.2f}%', end='', flush=True) | ||
| print(f' (num: {index})') | ||
|
|
||
| # Write initial/num.txt which contains the number of testcases in that | ||
| # directory (saves run.py from needing to listdir each time). | ||
|
Comment on lines
+168
to
+169
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does this make a measurable performance difference?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I can't measure this on ClusterFuzz itself, which is where it really matters. But imagine that ClusterFuzz might start to move to calling |
||
| num_txt = 'num.txt' | ||
| with open(num_txt, 'w') as f: | ||
| f.write(f'{index}') | ||
| tar.add(num_txt, arcname='initial/num.txt') | ||
|
|
||
|
|
||
| print('Done.') | ||
| print('To run the tests on this bundle, do:') | ||
| print() | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -67,7 +67,7 @@ def repl(text): | |
|
|
||
|
|
||
| # Replace the wasm files and write them out. | ||
| js = re.sub(r'var \w+ = new Uint8Array\(\[([\d,]+)\]\);', repl, js) | ||
| js = re.sub(r'var \w+ = new Uint8Array\(\[([\d,]+)\]\)', repl, js) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why no more semicolon?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Because now we can have one of the new comments between this and the semicolon. Detecting that would make this complicated for no useful reason (and adding the comment after the semicolon would be a little annoying in (Sorry if this wasn't clear enough in the description.) |
||
|
|
||
| # Write out the new JS. | ||
| with open(f'{out}.js', 'w') as f: | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What lints are we skipping here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The one that imports must be on top (which we can't do because of lines 83-89, which I can't think of a nice alternative to).