tinygo icon indicating copy to clipboard operation
tinygo copied to clipboard

tinygo should support passing other arguments to the emulator

Open dgryski opened this issue 3 years ago • 4 comments
trafficstars

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.

dgryski avatar Dec 18 '21 01:12 dgryski

I think this was addressed by https://github.com/tinygo-org/tinygo/pull/2780

deadprogram avatar Apr 28 '22 07:04 deadprogram

~/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.

dgryski avatar Sep 12 '22 16:09 dgryski

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).

aykevl avatar Sep 14 '22 13:09 aykevl

--extra-emu-flags=...

dgryski avatar Sep 14 '22 13:09 dgryski

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)

codefromthecrypt avatar Jan 12 '23 06:01 codefromthecrypt

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

dgryski avatar Jan 12 '23 06:01 dgryski