Skip to content

Commit 1e6435a

Browse files
authored
Emcc fuzzing followups (#2812)
Avoid pass-debug when fuzzing emcc, as it can be slow and isn't what we care about. Clean up a loop.
1 parent f53f88f commit 1e6435a

File tree

2 files changed

+20
-5
lines changed

2 files changed

+20
-5
lines changed

scripts/fuzz_opt.py

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
script covers different options being passed)
1616
'''
1717

18+
import contextlib
1819
import os
1920
import difflib
2021
import math
@@ -87,6 +88,17 @@ def randomize_pass_debug():
8788
print('randomized pass debug:', os.environ.get('BINARYEN_PASS_DEBUG', ''))
8889

8990

91+
@contextlib.contextmanager
92+
def no_pass_debug():
93+
old_env = os.environ.copy()
94+
if os.environ.get('BINARYEN_PASS_DEBUG'):
95+
del os.environ['BINARYEN_PASS_DEBUG']
96+
try:
97+
yield
98+
finally:
99+
os.environ.update(old_env)
100+
101+
90102
def randomize_feature_opts():
91103
global FEATURE_OPTS
92104
FEATURE_OPTS = CONSTANT_FEATURE_OPTS[:]
@@ -380,7 +392,11 @@ def run(self, wasm):
380392
compile_cmd += ['-Os']
381393
else:
382394
compile_cmd += ['-Oz']
383-
run(compile_cmd)
395+
# avoid pass-debug on the emcc invocation itself (which runs
396+
# binaryen to optimize the wasm), as the wasm here can be very
397+
# large and it isn't what we are focused on testing here
398+
with no_pass_debug():
399+
run(compile_cmd)
384400
return run_vm(['d8', 'a.out.js'])
385401

386402
def can_run(self):

src/tools/wasm2c-wrapper.h

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -98,14 +98,13 @@ int main(int argc, char** argv) {
9898

9999
// For each export in the wasm, emit code to call it and log its result,
100100
// similar to the other wrappers.
101-
size_t exportIndex = 0;
102-
103-
for (auto& exp : wasm.exports) {
101+
for (size_t i = 0; i < wasm.exports.size(); i++) {
102+
auto& exp = wasm.exports[i];
104103
if (exp->kind != ExternalKind::Function) {
105104
continue;
106105
}
107106

108-
ret += " case " + std::to_string(exportIndex++) + ":\n";
107+
ret += " case " + std::to_string(i) + ":\n";
109108

110109
auto* func = wasm.getFunction(exp->value);
111110

0 commit comments

Comments
 (0)