Add file read test

extensions
Volodymyr Shymanskyy 5 years ago
parent e36cd6b666
commit 377af5a15b

@ -4,7 +4,7 @@
# Usage:
# ./run-wasi-test.py
# ./run-wasi-test.py --exec ../custom_build/wasm3 --timeout 120
# ./run-wasi-test.py --exec "wasmer run"
# ./run-wasi-test.py --exec "wasmer run --dir=."
#
import argparse
@ -63,13 +63,13 @@ commands = [
{
"name": "Simple WASI test",
"wasm": "./wasi/test.wasm",
"args": ["args", "test"],
"expect_pattern": "Hello world*Constructor OK*Args: *; args; test;*fib(20) = 6765*[* ms]*=== done ===*"
"args": ["cat", "./wasi/0.txt"],
"expect_pattern": "Hello world*Constructor OK*Args: *; cat; ./wasi/0.txt;*fib(20) = 6765*[* ms]*48 65 6c 6c 6f 20 77 6f 72 6c 64*=== done ===*"
}, {
"name": "Simple WASI test (wasm-opt -O3)",
"wasm": "./wasi/test-opt.wasm",
"args": ["args", "test"],
"expect_pattern": "Hello world*Constructor OK*Args: *; args; test;*fib(20) = 6765*[* ms]*=== done ===*"
"args": ["cat", "./wasi/0.txt"],
"expect_pattern": "Hello world*Constructor OK*Args: *; cat; ./wasi/0.txt;*fib(20) = 6765*[* ms]*48 65 6c 6c 6f 20 77 6f 72 6c 64*=== done ===*"
}, {
"name": "mandelbrot",
"wasm": "./benchmark/mandelbrot/mandel.wasm",
@ -97,6 +97,7 @@ commands = [
"wasm": "./benchmark/stream/stream.wasm",
"expect_pattern": "----*Solution Validates:*on all three arrays*----*"
}, {
# TODO "if": { "file_exists": "./self-hosting/wasm3-fib.wasm" },
"name": "Self-hosting",
"wasm": "./self-hosting/wasm3-fib.wasm",
"expect_pattern": "wasm3 on WASM*Result: 832040*Elapsed: * ms*"

Binary file not shown.

@ -3,6 +3,9 @@
#include <string.h>
#include <time.h>
#include <sys/stat.h>
#include <fcntl.h>
/*
* Helpers
*/
@ -105,6 +108,20 @@ void test_perf_fib(uint32_t n) {
printf("%d [%.3f ms]\n", result, fms);
}
void test_cat(char* fn) {
int file = open(fn, O_RDONLY);
if (file >= 0) {
char c = 0;
while (read(file, &c, sizeof(c)) > 0) {
printf("%02x ", c);
}
close(file);
puts("");
} else {
printf("Cannot open %s\n", fn);
}
}
/*
* Main
*/
@ -116,9 +133,13 @@ int main(int argc, char **argv)
test_printf();
test_args(argc, argv);
test_gettime();
test_random();
//test_random();
test_perf_fib(20);
if (0 == strcmp(argv[1], "cat")) {
test_cat(argv[2]);
}
puts("=== done ===");
return 0;
}

Binary file not shown.
Loading…
Cancel
Save