Skip to content

Commit

Permalink
[test] Update wasi tests to pass on all engines
Browse files Browse the repository at this point in the history
  • Loading branch information
titzer committed Nov 7, 2024
1 parent 0b5d2ca commit 9ac0ce3
Show file tree
Hide file tree
Showing 8 changed files with 34 additions and 18 deletions.
17 changes: 17 additions & 0 deletions test/bin/run-wasm-wasi1@wizeng
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/bin/bash

SOURCE="${BASH_SOURCE[0]}"
while [ -h "$SOURCE" ]; do
DIR="$( cd -P "$( dirname "$SOURCE" )" >/dev/null 2>&1 && pwd )"
SOURCE="$(readlink "$SOURCE")"
[[ $SOURCE != /* ]] && SOURCE="$DIR/$SOURCE"
done
DIR="$( cd -P "$( dirname "$SOURCE" )" >/dev/null 2>&1 && pwd )"

OUT=$1
shift
TEST=$1
shift

BASE=${TEST/%.v3/}
exec $DIR/../config/wizeng -dir=. $OUT/${BASE}.wasm "$@"
6 changes: 2 additions & 4 deletions test/wasi/cat0.v3
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@ def iovecs = Array<int>.new(2);
def sizebuf = Array<int>.new(1);
def buffer = Array<byte>.new(1024);

def main() -> int {
def main() {
var r: int;

var ioptr = Pointer.atContents(iovecs);
var sizeptr = Pointer.atContents(sizebuf);

var path = "cat0.v3.input";
put("##+open\n");
var rights = wasi_rights.fd_read.tag;
var rights = (1 << wasi_rights.fd_read.tag) | (1 << wasi_rights.path_open.tag);
r = wasi_snapshot_preview1.path_open(3, 0, Pointer.atContents(path), path.length, 0, rights, rights, 0, Pointer.atContents(sizebuf));
check_errno(r);
var fd = sizebuf[0];
Expand All @@ -26,8 +26,6 @@ def main() -> int {
put("##+write\n");
r = wasi_snapshot_preview1.fd_write(1, ioptr, 1, sizeptr);
check_errno(r);

return 42;
}

def put_in = Array<int>.new(2);
Expand Down
1 change: 0 additions & 1 deletion test/wasi/cat0.v3.out
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,3 @@ FooBarBaz==78723487
)!@#$%^&*(
>>>>>>>>>>
##-ok
42
2 changes: 2 additions & 0 deletions test/wasi/echo.v3
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ component RiRuntime {
}
return args;
}
def exit(code: int) { // TODO: required to make entry stub return nothing
}
}

def main(args: Array<string>) -> int {
Expand Down
2 changes: 1 addition & 1 deletion test/wasi/fd_prestat1.v3
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def puti(i: int) {
def iobuf = Array<byte>.new(16);
def retbuf = Array<byte>.new(16);
def fs_write(data: Pointer, len: int) -> int {
var fd = 0;
var fd = 1;
var p = Pointer.atContents(iobuf);
(p + 0).store<int>(data - Pointer.NULL);
(p + 4).store<int>(len);
Expand Down
5 changes: 2 additions & 3 deletions test/wasi/fd_write00.v3
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
def iovecs = Array<int>.new(4);
def sizebuf = Array<int>.new(1);

def main() -> int {
def main() {
var msg = "fd_write: success\n";

iovecs[0] = Pointer.atContents(msg) - Pointer.NULL;
Expand All @@ -12,6 +12,5 @@ def main() -> int {
var ioptr = Pointer.atContents(iovecs);
var sizeptr = Pointer.atContents(sizebuf);
var r = wasi_snapshot_preview1.fd_write(1, ioptr, 1, sizeptr);
if (r != 0) return -1 - sizebuf[0];
return 43;
if (r != 0) var x = 1/0;
}
14 changes: 8 additions & 6 deletions test/wasi/fd_write01.v3
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
def iovecs = Array<int>.new(4);
def sizebuf = Array<int>.new(1);

def main() -> int {
def main() {
var msg = "fd_write: success\n";

var ioptr = Pointer.atContents(iovecs);
Expand All @@ -10,11 +10,13 @@ def main() -> int {
for (i < msg.length) {
iovecs[0] = Pointer.atElement(msg, 0) - Pointer.NULL;
iovecs[1] = i;
iovecs[2] = Pointer.atElement(msg, i) - Pointer.NULL;
iovecs[3] = msg.length - i;

var r = wasi_snapshot_preview1.fd_write(1, ioptr, 2, sizeptr);
if (r != 0) return -1 - sizebuf[0];
// TODO: wasmtime doesn't support multiple iovecs
if (wasi_snapshot_preview1.fd_write(1, ioptr, 1, sizeptr) != 0) var x = 1/0;

iovecs[0] = Pointer.atElement(msg, i) - Pointer.NULL;
iovecs[1] = msg.length - i;

if (wasi_snapshot_preview1.fd_write(1, ioptr, 1, sizeptr) != 0) var x = 1/0;
}
return 43;
}
5 changes: 2 additions & 3 deletions test/wasi/fd_write02.v3
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
def iovecs = Array<int>.new(2);
def sizebuf = Array<int>.new(1);

def main() -> int {
def main() {
var msg = "fd_write(stderr): success\n";

iovecs[0] = Pointer.atContents(msg) - Pointer.NULL;
Expand All @@ -10,6 +10,5 @@ def main() -> int {
var ioptr = Pointer.atContents(iovecs);
var sizeptr = Pointer.atContents(sizebuf);
var r = wasi_snapshot_preview1.fd_write(2, ioptr, 1, sizeptr); // stderr
if (r != 0) return -1 - sizebuf[0];
return 44;
if (r != 0) var x = 1/0;
}

0 comments on commit 9ac0ce3

Please sign in to comment.