-
Notifications
You must be signed in to change notification settings - Fork 38
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
bench: Fix execution pre-validation #340
Changes from all commits
b58a010
83642e9
0abdf09
a109468
a0bb16b
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 |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# Fizzy: A fast WebAssembly interpreter | ||
# Copyright 2020 The Fizzy Authors. | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
add_subdirectory(benchmarks) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
# Fizzy: A fast WebAssembly interpreter | ||
# Copyright 2020 The Fizzy Authors. | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
add_test( | ||
NAME fizzy/smoketests/bench/benchmarks | ||
COMMAND fizzy-bench ${CMAKE_CURRENT_LIST_DIR} --benchmark_min_time=0.01 | ||
) | ||
|
||
add_test( | ||
NAME fizzy/smoketests/bench/cli-missing-dir-arg | ||
COMMAND fizzy-bench | ||
) | ||
set_tests_properties( | ||
fizzy/smoketests/bench/cli-missing-dir-arg | ||
PROPERTIES | ||
PASS_REGULAR_EXPRESSION "Missing DIR argument" | ||
) | ||
|
||
add_test( | ||
NAME fizzy/smoketests/bench/cli-invalid-arg | ||
COMMAND fizzy-bench ${CMAKE_CURRENT_LIST_DIR} --nonexisting_argument | ||
) | ||
set_tests_properties( | ||
fizzy/smoketests/bench/cli-invalid-arg | ||
PROPERTIES | ||
PASS_REGULAR_EXPRESSION "error: unrecognized command-line flag: --nonexisting_argument" | ||
) | ||
|
||
|
||
# Dump coverage data to distinct files (otherwise file will be overwritten). | ||
set_tests_properties( | ||
fizzy/smoketests/bench/benchmarks | ||
fizzy/smoketests/bench/cli-missing-dir-arg | ||
fizzy/smoketests/bench/cli-invalid-arg | ||
PROPERTIES | ||
ENVIRONMENT LLVM_PROFILE_FILE=${CMAKE_BINARY_DIR}/bench-%p.profraw | ||
) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
addition | ||
add | ||
ii:i | ||
1 2 | ||
|
||
3 | ||
|
||
division_by_zero | ||
div | ||
ii:i | ||
1 0 | ||
|
||
0 | ||
|
||
memory_initialization_failure | ||
add | ||
ii:i | ||
0 0 | ||
fe | ||
0 | ||
|
||
unexcepted_result | ||
div | ||
ii:i | ||
1 1 | ||
|
||
|
||
|
||
expected_memory_shorter | ||
add | ||
ii:i | ||
0 0 | ||
|
||
0 | ||
00 | ||
|
||
missing_function | ||
sub | ||
ii:i | ||
0 0 | ||
|
||
0 | ||
|
||
incorrect_result_value | ||
add | ||
ii:i | ||
2 2 | ||
|
||
5 | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
(module | ||
(func (export "add") (param i32 i32) (result i32) | ||
local.get 0 | ||
local.get 1 | ||
i32.add | ||
) | ||
(func (export "div") (param i32 i32) (result i32) | ||
local.get 0 | ||
local.get 1 | ||
i32.div_u | ||
) | ||
) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
add | ||
add | ||
ii:i | ||
1 2 | ||
|
||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
(module | ||
(func (export "add") (param i32 i32) (result i32) | ||
local.get 0 | ||
i32.add | ||
) | ||
) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
fake | ||
fake_func | ||
: | ||
|
||
|
||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
increase_value | ||
inc | ||
i: | ||
0 | ||
ff000000 | ||
|
||
00010000 | ||
|
||
|
||
wrong_expected_memory | ||
inc | ||
i: | ||
0 | ||
ff000000 | ||
|
||
ffffffff | ||
|
||
missing_result_value | ||
inc | ||
i: | ||
0 | ||
|
||
0 | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
(module | ||
(memory 1 1) | ||
(func (export "inc") (param i32) | ||
local.get 0 | ||
local.get 0 | ||
i32.load | ||
i32.const 1 | ||
i32.add | ||
i32.store | ||
) | ||
) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
main | ||
main | ||
i:i | ||
0 | ||
|
||
0 | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
(module | ||
(func $imported (import "env" "imported") (param i32) (result i32)) | ||
(func (export "main") (param i32) (result i32) | ||
local.get 0 | ||
call $imported | ||
) | ||
) |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -135,7 +135,6 @@ WasmEngine::Result FizzyEngine::execute( | |
{ | ||
const auto [trapped, result_stack] = | ||
fizzy::execute(*m_instance, static_cast<uint32_t>(func_ref), args); | ||
assert(result_stack.size() <= 1); | ||
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. This just shows fizzy's "public api" is broken right now :) Hopefully after the span things are going in, we can merge a version of #219 can go in and fix this. 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 was confused at first, but truly we dump whole stack also in the case when returning |
||
return {trapped, !result_stack.empty() ? result_stack.back() : std::optional<uint64_t>{}}; | ||
} | ||
} // namespace fizzy::test |
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.
Can you explain the changes here in this function?
It looks like when validation is not ok, you would still go and dereference
func_ref
at line 185There 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.
Ah I guess it works because
validate_benchmark_case
would calllstate.SkipWithError
and the loop below will not be executed.But why then not just early return
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.
Yes. The loop will not run, but we need to call
auto _ : state
anyway (this is a libbenchmark limitation in the version we use).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.
Perhaps it's woth to add a comment that we need to call it even when validation failed.