Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 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
32 changes: 16 additions & 16 deletions test/lit/exec/array.wast
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

(data $data "a")

;; CHECK: [fuzz-exec] calling func
;; CHECK: [fuzz-exec] export func
;; CHECK-NEXT: [fuzz-exec] note result: func => 1
(func $func (export "func") (result i32)
;; Verifies the order of execution is correct - we should return 1, not 2.
Expand All @@ -25,7 +25,7 @@
)
)

;; CHECK: [fuzz-exec] calling new_active
;; CHECK: [fuzz-exec] export new_active
;; CHECK-NEXT: [trap out of bounds segment access in array.new_elem]
(func $new_active (export "new_active")
;; Even though this is reading 0 items, offset 1 is out of bounds in that
Expand All @@ -38,7 +38,7 @@
)
)

;; CHECK: [fuzz-exec] calling new_active_in_bounds
;; CHECK: [fuzz-exec] export new_active_in_bounds
(func $new_active_in_bounds (export "new_active_in_bounds")
;; Even though this is dropped, we read 0 from offset 0, which is ok.
(drop
Expand All @@ -49,7 +49,7 @@
)
)

;; CHECK: [fuzz-exec] calling new_passive
;; CHECK: [fuzz-exec] export new_passive
(func $new_passive (export "new_passive")
;; Using the passive segment here works.
(drop
Expand All @@ -60,7 +60,7 @@
)
)

;; CHECK: [fuzz-exec] calling init_active
;; CHECK: [fuzz-exec] export init_active
;; CHECK-NEXT: [trap out of bounds segment access in array.init_elem]
(func $init_active (export "init_active")
;; Even though this is reading 0 items, offset 1 is out of bounds in that
Expand All @@ -75,7 +75,7 @@
)
)

;; CHECK: [fuzz-exec] calling init_active_in_bounds
;; CHECK: [fuzz-exec] export init_active_in_bounds
(func $init_active_in_bounds (export "init_active_in_bounds")
;; Even though this is dropped, we read 0 from offset 0, which is ok.
(array.init_elem $array-func $active
Expand All @@ -88,7 +88,7 @@
)
)

;; CHECK: [fuzz-exec] calling init_passive
;; CHECK: [fuzz-exec] export init_passive
(func $init_passive (export "init_passive")
;; This works ok.
(array.init_elem $array-func $passive
Expand All @@ -101,7 +101,7 @@
)
)

;; CHECK: [fuzz-exec] calling drop_array.new_data
;; CHECK: [fuzz-exec] export drop_array.new_data
;; CHECK-NEXT: [trap dropped segment access in array.new_data]
(func $drop_array.new_data (export "drop_array.new_data")
;; Dropping the data segment causes the next instruction to trap, even though
Expand All @@ -116,24 +116,24 @@
)

)
;; CHECK: [fuzz-exec] calling func
;; CHECK: [fuzz-exec] export func
;; CHECK-NEXT: [fuzz-exec] note result: func => 1

;; CHECK: [fuzz-exec] calling new_active
;; CHECK: [fuzz-exec] export new_active
;; CHECK-NEXT: [trap out of bounds segment access in array.new_elem]

;; CHECK: [fuzz-exec] calling new_active_in_bounds
;; CHECK: [fuzz-exec] export new_active_in_bounds

;; CHECK: [fuzz-exec] calling new_passive
;; CHECK: [fuzz-exec] export new_passive

;; CHECK: [fuzz-exec] calling init_active
;; CHECK: [fuzz-exec] export init_active
;; CHECK-NEXT: [trap out of bounds segment access in array.init_elem]

;; CHECK: [fuzz-exec] calling init_active_in_bounds
;; CHECK: [fuzz-exec] export init_active_in_bounds

;; CHECK: [fuzz-exec] calling init_passive
;; CHECK: [fuzz-exec] export init_passive

;; CHECK: [fuzz-exec] calling drop_array.new_data
;; CHECK: [fuzz-exec] export drop_array.new_data
;; CHECK-NEXT: [trap dropped segment access in array.new_data]
;; CHECK-NEXT: [fuzz-exec] comparing drop_array.new_data
;; CHECK-NEXT: [fuzz-exec] comparing func
Expand Down
2 changes: 1 addition & 1 deletion test/lit/exec/atomic.wast
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

(memory $0 23 256 shared)

;; CHECK: [fuzz-exec] calling wait_and_log
;; CHECK: [fuzz-exec] export wait_and_log
;; CHECK-NEXT: [LoggingExternalInterface logging 2]
(func $wait_and_log (export "wait_and_log")
(call $log
Expand Down
2 changes: 1 addition & 1 deletion test/lit/exec/cont_bindings.wast
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
)
)

;; CHECK: [fuzz-exec] calling bindings
;; CHECK: [fuzz-exec] export bindings
;; CHECK-NEXT: [LoggingExternalInterface logging 42]
;; CHECK-NEXT: [LoggingExternalInterface logging 3.14159]
(func $bindings (export "bindings")
Expand Down
6 changes: 3 additions & 3 deletions test/lit/exec/cont_export.wast
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

(tag $tag (type $none))

;; CHECK: [fuzz-exec] calling suspend
;; CHECK: [fuzz-exec] export suspend
;; CHECK-NEXT: [LoggingExternalInterface logging 10]
;; CHECK-NEXT: [exception thrown: unhandled suspend]
(func $suspend (export "suspend")
Expand All @@ -22,7 +22,7 @@
(call $log (i32.const 20))
)

;; CHECK: [fuzz-exec] calling call-call-export
;; CHECK: [fuzz-exec] export call-call-export
;; CHECK-NEXT: [LoggingExternalInterface logging 10]
;; CHECK-NEXT: [trap suspend through JS]
(func $call-call-export (export "call-call-export")
Expand All @@ -33,7 +33,7 @@
)
)

;; CHECK: [fuzz-exec] calling handled
;; CHECK: [fuzz-exec] export handled
;; CHECK-NEXT: [LoggingExternalInterface logging 10]
;; CHECK-NEXT: [trap suspend through JS]
(func $handled (export "handled")
Expand Down
6 changes: 3 additions & 3 deletions test/lit/exec/cont_export_throw.wast
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@

(tag $tag (type $none))

;; CHECK: [fuzz-exec] calling suspend
;; CHECK: [fuzz-exec] export suspend
;; CHECK-NEXT: [exception thrown: unhandled suspend]
(func $suspend (export "suspend")
(suspend $tag)
)

;; CHECK: [fuzz-exec] calling handled
;; CHECK: [fuzz-exec] export handled
;; CHECK-NEXT: [trap suspend through JS]
(func $handled (export "handled")
(drop
Expand All @@ -36,7 +36,7 @@
)
)

;; CHECK: [fuzz-exec] calling suspend2
;; CHECK: [fuzz-exec] export suspend2
;; CHECK-NEXT: [exception thrown: unhandled suspend]
(func $suspend2 (export "suspend2")
(suspend $tag)
Expand Down
Loading
Loading