This repo provides a set of unit tests that can be used to check a WASM Backend's conformance to the WebAssembly spec.
- The JSON file for a spec test suite is read.
- For each spec test wasm defined in the JSON:
- All the spec tests are created in a C++ file to match the function declaration as interpreted from the JSON.
- Test are categorized into
assert_trap/assert_exhaustionandassert_return. - Tests are split up into
sub_applyfunctions based on the rules defined below. - An
applyfunction is written that switches on the third parameter to decide whichsub_applyfunction to run. - A map of the function name and the index in order is created to be used for merging.
- Unit Tests are generated based on the rules below.
- The generated C++ files are compiled and linked, without optimizations to prevent the empty functions from being optimized out.
- The generated WASM is combined with the original test wasm.
- The imports and apply functions (and any helper functions) from the generated wasm are combined with the test function definitions from the spec test wasm.
- Any necessary shifting of type/import/function/call/exports numbers is done.
- This is where the generated map from above is used.
- The newly created merged wasms and unit test C++ files are copied into the appropriate directory in the Leap repo.
-
Within a spec test suite, each
assert_trapandassert_exhaustiontest case is given a uniquesub_applyfunction.- All tests in a suite are in the same WASM file, so the test that is run is based on the
test.namepassed in toapply(which calls the correctsub_apply).
- All tests in a suite are in the same WASM file, so the test that is run is based on the
-
Within a test suite,
assert_returntests are grouped into sets of 100.- This is due to the limit on 1024 locals and 1024 func defs built into nodeos. Some spec tests had too many functions to have a
sub_applyper test, and some had too many variables to be put all into onesub_apply. - 100 was found to be the number that did not exceed this maximum for all the tests.
- The tests also have some reliance on ordering (a store may need to be called before a load for example).
- 100 also works out to make sure the right ordering is achieved.
- This is due to the limit on 1024 locals and 1024 func defs built into nodeos. Some spec tests had too many functions to have a
-
The unit tests are split into 2 groups. All of the
assert_traptests are grouped into oneBOOST_DATA_TEST_CASEand all theassert_returntests are grouped into a secondBOOST_DATA_TEST_CASE -
The unit test files are grouped by test suite (all
addresstests are together, allcalltests together, etc.)
- Run the
setup_eosio_tests.pyscript with no options to see the help text.
-
memory_grow.3 -- Will fail if not deleted from generated tests.
- Unclear how to hand alter this to have memory properly zeroed where expected.
-
start.7 -- Will fail if not deleted from generated tests.
- Imports "print" from "spectest". Changing to any of the
eosio::printfunctions results in "start function must be nullary" due to their requiring a parameter.
- Imports "print" from "spectest". Changing to any of the
-
globals.2 -- Delete from generated tests or it segfaults due to missing wasm.
eosio-wasm2wasterror "mutable globals cannot be exported" when converting to wast.wasm2watprovided by WABT handles this correctly, implying an error in CDT.
-
globals.3 -- Delete from generated tests or it segfaults due to missing wasm.
eosio-wasm2wasterror "mutable globals cannot be exported" when converting to wast.wasm2watprovided by WABT handles this correctly, implying an error in CDT.
-
globals.14 -- Delete from generated tests or it segfaults due to missing wasm.
- Imports "global_i32" from "spectest".
- Unclear what an appropriate substition would be.
- Imports "global_i32" from "spectest".