This folder contains code to compile all the sample code and execute on WAMR.
Please ensure you have built the iwasm_gc
in default directory, see this document
npm start
The script will print the pass rate, and the failed cases will be recorded into the test.log
file.
Running [xxx] get invalid return code: xxx
- This error means the
iwasm_gc
returned with non-zero code - if code is null, it means the runtime process crashed
- This error means the
Running [xxx] get unexpected output
- This means the actual output of the wasm module is not expected text
- Compile the ts source code to wasm module
- Run the wasm module on WAMR with given arguments in
validation.json
- Compare the output with the expected result
Note: The failed cases doesn't always mean there are bugs in the compiler or runtime, many known reasons may cause the cases to fail:
- Some cases require non-primitive arguments (e.g. struct, any) but currently the runtime only receives
number
type arguments through cli- Some cases require some imported functions/globals, but the runtime didn't provide them
- Some cases return complex values (e.g. struct, array, any), the runtime can't print detailed information, so the output is not accurate
validation.json
is a json file to record the cases to be tested, the format is:
[
{
"module": "any_binary_add",
"entries": [
{
"name": "addAnyAny",
"args": [],
"result": "3:f64"
},
{
"name": "addNumberAnyInBinaryExpr",
"args": [],
"result": "2:f64"
},
{
"name": "addNumberAnyInMulExpr",
"args": [],
"result": "9:f64"
}
]
},
{
// ...
}
]
module
is the name of the ts file to be testedentries
is an array of functions to be testedname
is the name of the exported functionargs
is an array of arguments, currently only support numberresult
is the expected output text
This is for develop usage, don't run this script unless you know what will happen.
It's tedious to write the validation.json
file manually, so we provide a script to generate it automatically.
npm run gen_item
- The script use ts2wasm frontend to parse the ts source code, and extract all export functions, and get the parameter count of the function
- For each function, it will randomly generate some argument and call it with
ts-node
- The generated args, and the executed result will be recorded into the
validation.json
file
Note: This script will overwrite the
validation.json
file, so please backup it before running this script.
Note: Some functions may not be able to run on
ts-node
, so the script will remain theresult
empty. Also some text may not be very accurate, you need to fill/correct it manually.