Skip to content

Commit

Permalink
test: Support floating point arguments ad expected results in spectests
Browse files Browse the repository at this point in the history
  • Loading branch information
gumb0 committed Jul 31, 2020
1 parent 76d9e9a commit 30045c2
Showing 1 changed file with 23 additions and 3 deletions.
26 changes: 23 additions & 3 deletions test/spectests/spectests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,23 @@ 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)
fizzy::Value json_to_value(const json& v)
{
return static_cast<std::make_unsigned_t<T>>(std::stoull(v.get<std::string>()));
}

template<>
fizzy::Value json_to_value<float>(const json& v)
{
return std::stoull(v.get<std::string>());
}

template<>
fizzy::Value json_to_value<double>(const json& v)
{
return 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)};
Expand Down Expand Up @@ -420,11 +432,15 @@ class test_runner
for (const auto& arg : action.at("args"))
{
const auto arg_type = arg.at("type").get<std::string>();
uint64_t arg_value;
fizzy::Value 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 if (arg_type == "f32")
arg_value = json_to_value<float>(arg.at("value"));
else if (arg_type == "f64")
arg_value = json_to_value<double>(arg.at("value"));
else
{
skip("Unsupported argument type '" + arg_type + "'.");
Expand All @@ -447,11 +463,15 @@ class test_runner
bool check_result(uint64_t actual_value, const json& expected)
{
const auto expected_type = expected.at("type").get<std::string>();
uint64_t expected_value;
fizzy::Value 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 if (expected_type == "f32")
expected_value = json_to_value<float>(expected.at("value"));
else if (expected_type == "f64")
expected_value = json_to_value<double>(expected.at("value"));
else
{
skip("Unsupported expected type '" + expected_type + "'.");
Expand Down

0 comments on commit 30045c2

Please sign in to comment.