-
Notifications
You must be signed in to change notification settings - Fork 39
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
Support floats in spectest runner #445
Changes from all commits
179d2e8
e41dd73
4106bd9
8674884
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 |
---|---|---|
|
@@ -9,7 +9,7 @@ add_test( | |
set_tests_properties( | ||
fizzy/smoketests/spectests/default | ||
PROPERTIES | ||
PASS_REGULAR_EXPRESSION "PASSED 23, FAILED 0, SKIPPED 7" | ||
PASS_REGULAR_EXPRESSION "PASSED 26, FAILED 1, SKIPPED 3" | ||
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. 1 failure is for float global, will be fixed in #446 |
||
) | ||
|
||
add_test( | ||
|
@@ -19,7 +19,7 @@ add_test( | |
set_tests_properties( | ||
fizzy/smoketests/spectests/skipvalidation | ||
PROPERTIES | ||
PASS_REGULAR_EXPRESSION "PASSED 22, FAILED 0, SKIPPED 8" | ||
PASS_REGULAR_EXPRESSION "PASSED 25, FAILED 1, SKIPPED 4" | ||
) | ||
|
||
add_test( | ||
|
@@ -39,7 +39,7 @@ add_test( | |
set_tests_properties( | ||
fizzy/smoketests/spectests/broken | ||
PROPERTIES | ||
PASS_REGULAR_EXPRESSION "PASSED 0, FAILED 2, SKIPPED 4" | ||
PASS_REGULAR_EXPRESSION "PASSED 1, FAILED 2, SKIPPED 6" | ||
) | ||
|
||
add_test( | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -50,12 +50,6 @@ const auto spectest_bin = fizzy::test::from_hex( | |
const auto spectest_module = fizzy::parse(spectest_bin); | ||
const std::string spectest_name = "spectest"; | ||
|
||
template <typename T> | ||
uint64_t json_to_value(const json& v) | ||
{ | ||
return static_cast<std::make_unsigned_t<T>>(std::stoull(v.get<std::string>())); | ||
} | ||
|
||
fizzy::bytes load_wasm_file(const fs::path& json_file_path, std::string_view filename) | ||
{ | ||
std::ifstream wasm_file{fs::path{json_file_path}.replace_filename(filename)}; | ||
|
@@ -402,6 +396,20 @@ class test_runner | |
return it_instance->second.get(); | ||
} | ||
|
||
std::optional<fizzy::Value> read_value(const json& v) | ||
{ | ||
const auto arg_type = v.at("type").get<std::string>(); | ||
if (arg_type != "i32" && arg_type != "i64" && arg_type != "f32" && arg_type != "f64") | ||
{ | ||
skip("Unsupported value type '" + arg_type + "'."); | ||
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 is not covered by unit tests. 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. Added tests. |
||
return std::nullopt; | ||
} | ||
|
||
// Values of all types are serialized to JSON as integers. | ||
// Value type will handle correct conversions. | ||
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. How? Why not keep the old 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. It's just simpler without additional Presumably |
||
return std::stoull(v.at("value").get<std::string>()); | ||
} | ||
|
||
std::optional<fizzy::ExecutionResult> invoke(const json& action) | ||
{ | ||
auto instance = find_instance_for_action(action); | ||
|
@@ -419,18 +427,11 @@ class test_runner | |
std::vector<fizzy::Value> args; | ||
for (const auto& arg : action.at("args")) | ||
{ | ||
const auto arg_type = arg.at("type").get<std::string>(); | ||
uint64_t arg_value; | ||
if (arg_type == "i32") | ||
arg_value = json_to_value<int32_t>(arg.at("value")); | ||
else if (arg_type == "i64") | ||
arg_value = json_to_value<int64_t>(arg.at("value")); | ||
else | ||
{ | ||
skip("Unsupported argument type '" + arg_type + "'."); | ||
const auto arg_value = read_value(arg); | ||
if (!arg_value.has_value()) | ||
return std::nullopt; | ||
} | ||
args.push_back(arg_value); | ||
|
||
args.push_back(*arg_value); | ||
} | ||
|
||
try | ||
|
@@ -444,25 +445,17 @@ class test_runner | |
} | ||
} | ||
|
||
bool check_result(uint64_t actual_value, const json& expected) | ||
bool check_result(fizzy::Value actual_value, const json& expected) | ||
{ | ||
const auto expected_type = expected.at("type").get<std::string>(); | ||
uint64_t expected_value; | ||
if (expected_type == "i32") | ||
expected_value = json_to_value<int32_t>(expected.at("value")); | ||
else if (expected_type == "i64") | ||
expected_value = json_to_value<int64_t>(expected.at("value")); | ||
else | ||
{ | ||
skip("Unsupported expected type '" + expected_type + "'."); | ||
const auto expected_value = read_value(expected); | ||
if (!expected_value.has_value()) | ||
return false; | ||
} | ||
|
||
if (expected_value != actual_value) | ||
if (*expected_value != actual_value) | ||
{ | ||
std::stringstream message; | ||
message << "Incorrect returned value. Expected: " << expected_value << " (0x" | ||
<< std::hex << expected_value << ") Actual: " << std::dec << actual_value | ||
message << "Incorrect returned value. Expected: " << *expected_value << " (0x" | ||
<< std::hex << *expected_value << ") Actual: " << std::dec << actual_value | ||
<< " (0x" << std::hex << actual_value << std::dec << ")"; | ||
fail(message.str()); | ||
return false; | ||
|
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.
4 new failures are all in
globals.wast
, will be fixed in #446