tinygo
tinygo copied to clipboard
tinygo should support passing other arguments to the emulator
A number of tests require more filesystem access that simply the current directory. Being able to pass additional --dir= flags to wasmtime would allow tinygo test -target=wasi to pass more package tests.
A specific example of this is compress/flate which needs --dir=. --dir=.. --dir=../.. in order to read the files it needs for testing.
I think this was addressed by https://github.com/tinygo-org/tinygo/pull/2780
~/go/src/go.googlesource.com/go/src/compress/flate $ tinygo test compress/flate --dir=. --dir=.. --dir=../..
malformed import path "--dir=.": leading dash
malformed import path "--dir=..": leading dash
cannot resolve packages: exit status 1
I think that's what I'd like to make possible somehow.
How would TinyGo know the difference between flags that must be passed to the emulator and flags that must be passed to the test binary? Normally, flags to tinygo test are passed to the test binary (see for example go test ./compiler -update in the TinyGo source code).
--extra-emu-flags=...
I saw this while porting wazero to work with things like this. FYI the wasi calls look like the below. Nevermind the NOENT as that's a thing I'm working on.. the important thing are the inputs
$ ./build/tinygo test -target wasi -c -o flate.wasm compress/flate
$ wazero run -hostlogging=filesystem -mount=.:/ flate.wasm -test.v
==> wasi_snapshot_preview1.fd_prestat_get(fd=3)
<== (prestat={pr_name_len=1},errno=ESUCCESS)
==> wasi_snapshot_preview1.fd_prestat_dir_name(fd=3)
<== (path=/,errno=ESUCCESS)
==> wasi_snapshot_preview1.fd_prestat_get(fd=4)
<== (prestat=,errno=EBADF)
==> wasi_snapshot_preview1.fd_fdstat_get(fd=3)
<== (stat={filetype=DIRECTORY,fdflags=,fs_rights_base=,fs_rights_inheriting=},errno=ESUCCESS)
==> wasi_snapshot_preview1.path_open(fd=3,dirflags=SYMLINK_FOLLOW,path=../testdata/e.txt,oflags=,fs_rights_base=,fs_rights_inheriting=,fdflags=)
<== (opened_fd=,errno=ENOENT)
==> wasi_snapshot_preview1.fd_fdstat_get(fd=3)
<== (stat={filetype=DIRECTORY,fdflags=,fs_rights_base=,fs_rights_inheriting=},errno=ESUCCESS)
==> wasi_snapshot_preview1.path_open(fd=3,dirflags=SYMLINK_FOLLOW,path=../../testdata/Isaac.Newton-Opticks.txt,oflags=,fs_rights_base=,fs_rights_inheriting=,fdflags=)
<== (opened_fd=,errno=ENOENT)
==> wasi_snapshot_preview1.fd_fdstat_get(fd=3)
<== (stat={filetype=DIRECTORY,fdflags=,fs_rights_base=,fs_rights_inheriting=},errno=ESUCCESS)
==> wasi_snapshot_preview1.path_open(fd=3,dirflags=SYMLINK_FOLLOW,path=../../testdata/Isaac.Newton-Opticks.txt,oflags=,fs_rights_base=,fs_rights_inheriting=,fdflags=)
<== (opened_fd=,errno=ENOENT)
Yeah, there was some tricks involved to get all the proper directories added for testing compress/flate: https://github.com/tinygo-org/tinygo/blob/release/main.go#L254