Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 34 additions & 34 deletions scripts/fuzz_opt.py
Original file line number Diff line number Diff line change
Expand Up @@ -423,8 +423,8 @@ def pick_initial_contents():
# Host limits are reported as [host limit REASON]
HOST_LIMIT_PREFIX = '[host limit '

# --fuzz-exec reports calls as [fuzz-exec] calling foo
FUZZ_EXEC_CALL_PREFIX = '[fuzz-exec] calling'
# --fuzz-exec reports calls as [fuzz-exec] export foo
FUZZ_EXEC_EXPORT_PREFIX = '[fuzz-exec] export'

# --fuzz-exec reports a stack limit using this notation
STACK_LIMIT = '[trap stack limit]'
Expand All @@ -440,11 +440,11 @@ def pick_initial_contents():
EXCEPTION_PREFIX = 'exception thrown: '


# given a call line that includes FUZZ_EXEC_CALL_PREFIX, return the export that
# is called
def get_export_from_call_line(call_line):
assert FUZZ_EXEC_CALL_PREFIX in call_line
return call_line.split(FUZZ_EXEC_CALL_PREFIX)[1].strip()
# given an export line that includes FUZZ_EXEC_EXPORT_PREFIX, return the export
# that is called
def get_export_from_export_line(export_line):
assert FUZZ_EXEC_EXPORT_PREFIX in export_line
return export_line.split(FUZZ_EXEC_EXPORT_PREFIX)[1].strip()


# compare two strings, strictly
Expand Down Expand Up @@ -786,7 +786,7 @@ class BinaryenInterpreter:
def run(self, wasm):
output = run_bynterp(wasm, ['--fuzz-exec-before'])
if output != IGNORE:
calls = output.count(FUZZ_EXEC_CALL_PREFIX)
calls = output.count(FUZZ_EXEC_EXPORT_PREFIX)
errors = output.count(TRAP_PREFIX) + output.count(HOST_LIMIT_PREFIX)
if errors > calls / 2:
# A significant amount of execution on this testcase
Expand Down Expand Up @@ -1131,14 +1131,14 @@ def fix_number(x):
# we can't test this function, which the trap is in the middle of.
# erase everything from this function's output and onward, so we
# only compare the previous trap-free code
call_start = interpreter.rindex(FUZZ_EXEC_CALL_PREFIX, 0, trap_index)
call_start = interpreter.rindex(FUZZ_EXEC_EXPORT_PREFIX, 0, trap_index)
call_end = interpreter.index('\n', call_start)
call_line = interpreter[call_start:call_end]
export_line = interpreter[call_start:call_end]
# fix up the call line so it matches the JS
fixed_call_line = fix_output_for_js(call_line)
before = before[:before.index(fixed_call_line)]
after = after[:after.index(fixed_call_line)]
interpreter = interpreter[:interpreter.index(call_line)]
fixed_export_line = fix_output_for_js(export_line)
before = before[:before.index(fixed_export_line)]
after = after[:after.index(fixed_export_line)]
interpreter = interpreter[:interpreter.index(export_line)]

if compare_before_to_after:
compare_between_vms(before, after, 'Wasm2JS (before/after)')
Expand Down Expand Up @@ -1293,14 +1293,14 @@ def handle_pair(self, input, before_wasm, after_wasm, opts):
# finding the call line right before us. that is, the output looks
# like this:
#
# [fuzz-exec] calling foo
# [fuzz-exec] export foo
# .. stuff happening during foo ..
# [fuzz-exec] calling bar
# [fuzz-exec] export bar
# .. stuff happening during bar ..
#
# if the trap happened during bar, the relevant call line is
# "[fuzz-exec] calling bar".
call_start = before.rfind(FUZZ_EXEC_CALL_PREFIX, 0, trap_index)
# "[fuzz-exec] export bar".
call_start = before.rfind(FUZZ_EXEC_EXPORT_PREFIX, 0, trap_index)
if call_start < 0:
# the trap happened before we called an export, so it occured
# during startup (the start function, or memory segment
Expand All @@ -1311,17 +1311,17 @@ def handle_pair(self, input, before_wasm, after_wasm, opts):
# be prefixes of each other
call_end = before.index(os.linesep, call_start) + 1
# we now know the contents of the call line after which the trap
# happens, which is something like "[fuzz-exec] calling bar", and
# happens, which is something like "[fuzz-exec] export bar", and
# it is unique since it contains the function being called.
call_line = before[call_start:call_end]
trapping_export = get_export_from_call_line(call_line)
export_line = before[call_start:call_end]
trapping_export = get_export_from_export_line(export_line)

# now that we know the trapping export, we can leave only the safe
# ones that are before it
safe_exports = []
for line in before.splitlines():
if FUZZ_EXEC_CALL_PREFIX in line:
export = get_export_from_call_line(line)
if FUZZ_EXEC_EXPORT_PREFIX in line:
export = get_export_from_export_line(line)
if export == trapping_export:
break
safe_exports.append(export)
Expand Down Expand Up @@ -1437,10 +1437,10 @@ def traps_in_instantiation(output):
trap_index = output.find('*exception*')
if trap_index == -1:
return False
call_index = output.find(FUZZ_EXEC_CALL_PREFIX)
if call_index == -1:
export_index = output.find(FUZZ_EXEC_EXPORT_PREFIX)
if export_index == -1:
return True
return trap_index < call_index
return trap_index < export_index


# Tests wasm-merge
Expand Down Expand Up @@ -1575,8 +1575,8 @@ def handle(self, wasm):
# primary module, but only the original ones.
exports = []
for line in output.splitlines():
if FUZZ_EXEC_CALL_PREFIX in line:
exports.append(get_export_from_call_line(line))
if FUZZ_EXEC_EXPORT_PREFIX in line:
exports.append(get_export_from_export_line(line))

# pick which to split out, with a random rate of picking (biased towards
# 0.5).
Expand Down Expand Up @@ -1770,7 +1770,7 @@ def handle_pair(self, input, before_wasm, after_wasm, opts):
fuzz_file,
'extracted'])
if get_exports('extracted.0.wasm', ['func']):
assert FUZZ_EXEC_CALL_PREFIX in output
assert FUZZ_EXEC_EXPORT_PREFIX in output

def ensure(self):
# The first time we actually run, set things up: make a bundle like the
Expand Down Expand Up @@ -1883,7 +1883,7 @@ def handle(self, wasm):
# wasm files.
exports = get_exports(wasm, ['func', 'global'])
exports += get_exports(second_wasm, ['func', 'global'])
calls_in_output = output.count(FUZZ_EXEC_CALL_PREFIX)
calls_in_output = output.count(FUZZ_EXEC_EXPORT_PREFIX)
if calls_in_output == 0:
print(f'warning: no calls in output. output:\n{output}')
assert calls_in_output == len(exports), exports
Expand Down Expand Up @@ -2000,11 +2000,11 @@ def compare_to_merged_output(self, output, merged_output):
b = merged_output_lines[i]
if a == b:
continue
if a.startswith(FUZZ_EXEC_CALL_PREFIX):
if a.startswith(FUZZ_EXEC_EXPORT_PREFIX):
# Fix up
# [fuzz-exec] calling foo/bar
# [fuzz-exec] export foo/bar
# for different foo/bar. Just copy the original.
assert b.startswith(FUZZ_EXEC_CALL_PREFIX)
assert b.startswith(FUZZ_EXEC_EXPORT_PREFIX)
merged_output_lines[i] = output_lines[i]
elif a.startswith(FUZZ_EXEC_NOTE_RESULT):
# Fix up
Expand Down Expand Up @@ -2263,7 +2263,7 @@ def handle(self, wasm):
# any logging before the first call.)
line_groups = [['before calls']]
for line in out.splitlines():
if line.startswith(FUZZ_EXEC_CALL_PREFIX):
if line.startswith(FUZZ_EXEC_EXPORT_PREFIX):
line_groups.append([line])
else:
line_groups[-1].append(line)
Expand Down
2 changes: 1 addition & 1 deletion scripts/fuzz_shell.js
Original file line number Diff line number Diff line change
Expand Up @@ -630,7 +630,7 @@ function build(binary, isSecond) {
}

// Execute the task.
console.log(`[fuzz-exec] calling ${task.name}${task.deferred ? ' (after defer)' : ''}`);
console.log(`[fuzz-exec] export ${task.name}${task.deferred ? ' (after defer)' : ''}`);
let result;
try {
result = task.func();
Expand Down
2 changes: 1 addition & 1 deletion scripts/update_lit_checks.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
ITEM_RE = re.compile(r'(?:^\s*\(rec\s*)?(^\s*)\((' + ALL_ITEMS + r')\s+(' + ITEM_NAME + ').*$',
re.MULTILINE)

FUZZ_EXEC_FUNC = re.compile(r'^\[fuzz-exec\] calling (?P<name>\S*)$')
FUZZ_EXEC_FUNC = re.compile(r'^\[fuzz-exec\] export (?P<name>\S*)$')

ANNOTATION_RE = re.compile(r'^\s*\(\@.*')

Expand Down
7 changes: 3 additions & 4 deletions src/tools/execution-results.h
Original file line number Diff line number Diff line change
Expand Up @@ -488,7 +488,7 @@ struct ExecutionResults {
// opts)
for (auto& exp : wasm.exports) {
if (exp->kind == ExternalKind::Function) {
std::cout << "[fuzz-exec] calling " << exp->name << "\n";
std::cout << "[fuzz-exec] export " << exp->name << "\n";
auto* func = wasm.getFunction(*exp->getInternalName());
FunctionResult ret = run(func, wasm, instance);
results[exp->name] = ret;
Expand All @@ -503,9 +503,8 @@ struct ExecutionResults {
}
}
} else if (exp->kind == ExternalKind::Global) {
// Log the global's value. (We use "calling" here to match the output
// for calls, which simplifies the fuzzer.)
std::cout << "[fuzz-exec] calling " << exp->name << "\n";
// Log the global's value.
std::cout << "[fuzz-exec] export " << exp->name << "\n";
Literals* value = instance.getExportedGlobalOrNull(exp->name);
assert(value);
assert(value->size() == 1);
Expand Down
2 changes: 1 addition & 1 deletion src/tools/wasm2c-wrapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ int main(int argc, char** argv) {

auto* func = wasm.getFunction(*exp->getInternalName());

ret += std::string(" puts(\"[fuzz-exec] calling ") +
ret += std::string(" puts(\"[fuzz-exec] export ") +
exp->name.toString() + "\");\n";
auto result = func->getResults();

Expand Down
2 changes: 1 addition & 1 deletion test/lit/d8/fuzz_shell.wast
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@
;;
;; RUN: v8 %S/../../../scripts/fuzz_shell.js -- %t.wasm | filecheck %s
;;
;; CHECK: [fuzz-exec] calling test
;; CHECK: [fuzz-exec] export test
;; CHECK: [fuzz-exec] note result: test => 42

6 changes: 3 additions & 3 deletions test/lit/d8/fuzz_shell_exceptions.wast
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,11 @@
;;
;; RUN: v8 %S/../../../scripts/fuzz_shell.js -- %t.wasm | filecheck %s
;;
;; CHECK: [fuzz-exec] calling throwing-js
;; CHECK: [fuzz-exec] export throwing-js
;; CHECK: exception thrown: Error: js exception
;; CHECK: [fuzz-exec] calling throwing-tag
;; CHECK: [fuzz-exec] export throwing-tag
;; CHECK: exception thrown: [object WebAssembly.Exception]
;; CHECK: [fuzz-exec] calling throwing-jstag-null
;; CHECK: [fuzz-exec] export throwing-jstag-null
;; CHECK: exception thrown: null


Expand Down
26 changes: 13 additions & 13 deletions test/lit/d8/fuzz_shell_jspi.wast
Original file line number Diff line number Diff line change
Expand Up @@ -49,32 +49,32 @@
;; we get a random-like ordering, which includes some defers (each of which has
;; a later finish), showing that we interleave stacks.
;;
;; CHECK: [fuzz-exec] calling a
;; CHECK: [fuzz-exec] calling b
;; CHECK: [fuzz-exec] export a
;; CHECK: [fuzz-exec] export b
;; CHECK: [fuzz-exec] note result: a => 10
;; CHECK: [fuzz-exec] calling b
;; CHECK: [fuzz-exec] export b
;; CHECK: [fuzz-exec] note result: b => 20
;; CHECK: [fuzz-exec] calling a
;; CHECK: [fuzz-exec] export a
;; CHECK: (jspi: defer a)
;; CHECK: [fuzz-exec] calling d
;; CHECK: [fuzz-exec] export d
;; CHECK: (jspi: defer d)
;; CHECK: [fuzz-exec] calling e
;; CHECK: [fuzz-exec] export e
;; CHECK: [fuzz-exec] note result: b => 20
;; CHECK: [fuzz-exec] calling c
;; CHECK: [fuzz-exec] export c
;; CHECK: [fuzz-exec] note result: e => 50
;; CHECK: [fuzz-exec] calling c
;; CHECK: [fuzz-exec] export c
;; CHECK: (jspi: defer c)
;; CHECK: [fuzz-exec] calling c
;; CHECK: [fuzz-exec] export c
;; CHECK: (jspi: finish c)
;; CHECK: [fuzz-exec] note result: c => 30
;; CHECK: [fuzz-exec] calling d
;; CHECK: [fuzz-exec] export d
;; CHECK: [fuzz-exec] note result: c => 30
;; CHECK: [fuzz-exec] calling d
;; CHECK: [fuzz-exec] export d
;; CHECK: (jspi: finish d)
;; CHECK: [fuzz-exec] note result: d => 40
;; CHECK: [fuzz-exec] calling e
;; CHECK: [fuzz-exec] export e
;; CHECK: [fuzz-exec] note result: d => 40
;; CHECK: [fuzz-exec] calling a
;; CHECK: [fuzz-exec] export a
;; CHECK: (jspi: finish a)
;; CHECK: [fuzz-exec] note result: a => 10
;; CHECK: [fuzz-exec] note result: e => 50
Expand Down
14 changes: 7 additions & 7 deletions test/lit/d8/fuzz_shell_sleep.wast
Original file line number Diff line number Diff line change
Expand Up @@ -53,20 +53,20 @@
;; func2 is more because we do not have a toplevel await, see comment in
;; fuzz_shell_jspi.wast.)
;;
;; CHECK: [fuzz-exec] calling func2
;; CHECK: [fuzz-exec] export func2
;; CHECK: [fuzz-exec] note result: func2 => 2
;; CHECK: [fuzz-exec] calling func1
;; CHECK: [fuzz-exec] export func1
;; CHECK: (jspi: defer func1)
;; CHECK: [fuzz-exec] calling func3
;; CHECK: [fuzz-exec] export func3
;; CHECK: [fuzz-exec] note result: func3 => 3
;; CHECK: [fuzz-exec] calling func1 (after defer)
;; CHECK: [fuzz-exec] export func1 (after defer)
;; CHECK: (jspi: finish func1)
;; CHECK: [fuzz-exec] note result: func1 => 1
;; CHECK: [fuzz-exec] calling func5
;; CHECK: [fuzz-exec] export func5
;; CHECK: (jspi: defer func5)
;; CHECK: [fuzz-exec] calling func4
;; CHECK: [fuzz-exec] export func4
;; CHECK: [fuzz-exec] note result: func4 => 4
;; CHECK: [fuzz-exec] calling func5 (after defer)
;; CHECK: [fuzz-exec] export func5 (after defer)
;; CHECK: (jspi: finish func5)
;; CHECK: [fuzz-exec] note result: func5 => 5

Loading
Loading