-
Notifications
You must be signed in to change notification settings - Fork 8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add some low level tests #19
Conversation
yamt
commented
Dec 22, 2022
I'm interested in reviewing this but it may have to be in the new year (I'll be out for a bit). @yamt, you might also be interested in the tests I added over in WebAssembly/wasi-libc#369. I think it is a good idea to have tests in both places: in the spec to check that and over in wasi-libc to check our pthreads implementation. What I would like to think through more clearly in January is whether there is a clean way to enable multiple engines to run both sets of tests (and wasi-testsuite too, @loganek!). I see you have a Python driver of some kind... perhaps there is a need for something like eshost but for Wasm engines that lets us easily run all these tests. |
i will take a look.
i agree.
wasi-testsuite has simple wrappers (called "runtime adapter" there) for engines. there are implementations of wasmtime, wamr, toywasm, at least. i feel the current adapter api is too simple though. cf. WebAssembly/wasi-testsuite#39 i was not aware of |
call $proc_exit | ||
unreachable | ||
) | ||
(memory 1 1 shared) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
these assume the "inherit semantics" described in WebAssembly/wasi-libc#369 (comment).
for "import semantics" described in WebAssembly/wasi-libc#369 (comment), this needs to be changed to an imported memory.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i adapted these tests to the latter.
Same here, I'm on holidays till January (in fact, I'm ooto since mid December so my responses are a bit slow right now) so I'll catch up on all the changes then.
We already have a framework for that, an the next step is to pull tests from different repos (proposals, even wasi-libc) an run them with runtimes that are onboarded to the framework. We can talk more about this next year.
Yes, the API is intentionally simple so we can quickly get something up and running. I expect some changes there in the future although leaning towards keeping it rather simple to reduce onboarding effort (rather than asking runtimes to implement complex debug/test interfaces). |
@@ -0,0 +1,39 @@ | |||
(module | |||
(memory (import "foo" "bar") 1 1 shared) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should there also be an exported memory? From the doc:
Regardless of the kind, all modules accessing WASI APIs also export a linear memory with the name memory.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should there also be an exported memory? From the doc:
Regardless of the kind, all modules accessing WASI APIs also export a linear memory with the name memory.
sure. i will update tomorrow.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure about this. Firstly, that doc marked as legacy. Secondly, if this doc were current I would recommend that it be updated as part of wasi-threads to specify that memory but either be exported or imported.
IIUC wasi-threads should require that memory be imported. The extra requirement to redundantly re-export the memory back to the runtime seems like a wasmtime specific thing that I'm not sure we want to spec.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i guess the original motivation of memory export in wasi was to explicitly allow the host to examine the linear memory for given pointers, especially for polyfilling implementations. in that regard, you are right when the memory is imported from the host, there is little point to export it back.
on the other hand, it might still make sense to have a well-known name (ie. "memory") to indicate which memory is used for wasi pointers in case of multi-memory.
i personally has no strong opinions either ways.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should there also be an exported memory? From the doc:
Regardless of the kind, all modules accessing WASI APIs also export a linear memory with the name memory.
sure. i will update tomorrow.
postponed as it seems a bit more controversial than i thought.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
an old discussion: WebAssembly/WASI#48 (comment)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i'd suggest not to block this PR for the memory export/import issue.
it isn't something to decide in this PR.
#22
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should there also be an exported memory? From the doc:
Regardless of the kind, all modules accessing WASI APIs also export a linear memory with the name memory.
sure. i will update tomorrow.
postponed as it seems a bit more controversial than i thought.
i added export as well to increase the chances for these to work on more runtimes.
test/build-wat.sh
Outdated
@@ -0,0 +1,6 @@ | |||
#! /bin/sh |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this file be just be called build.sh
or build-wasm.sh
(build-wat reads like the output of the script, would be wat, but its actually the input.. maybe campile-wat.sh
if you want to keep wat in the name?)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
there is already build.sh
, which build wasm from c.
i meant build from wat
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah I see. In that case perhaps we can replace the two different shell scripts with a single Makefile that by default converts all .c
and .wat
files?
No need to block this PR on that, but it might be nicer that creating a bunch of different "make" scripts.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, i agree it's nice to have a unformed way to build tests.
at least it would help WebAssembly/wasi-testsuite#41 .
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
or merge those two build scripts into a single build.sh
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
or merge those two build scripts into a single
build.sh
eventually, maybe.
at this moment C tests and WAT tests are worked on by different people.
merging them now just increases chances to conflict with eg. #25
is there any blocker on this? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, I've had some more time to look at this and have an opinion:
- I think it's great to expand the test coverage for this proposal, so that's a plus!
- I still don't really understand how to run these in Wasmtime, e.g., but maybe that can should is already explained somewhere else?
- I have had to write WAT tests in the past and they can be very... unpleasant to work with. It is difficult to understand "what is being tested here?" at a glance. I think two things would improve this PR: 1) a short story at the top explaining the sequence of events (e.g., "we start two threads, the main one exits with code X and we ensure that that is the code observed") and 2) making the WAT easier to read, e.g., by using names (
$foo
in locals, parameters) and "infix" notation (if (i32.le_s (i32.const 0)) ...
). I get that this is pretty subjective but if you all have had to write and debug much WAT by hand in the past you may know what I mean.
I don't want to block progress so I'm fine with merging this PR but I do think it could be improved, either here or in the future to make things easier to understand. Thanks @yamt for the PR!
I'm going to open a PR to update https://github.com/WebAssembly/wasi-threads/blob/main/test/README.md tomorrow or beginning of next week so that should be clear then. |
depending on the way how the feature is enabled in wasmtime, (i don't know)
for me, the "infix" notation is more difficult to read/write than the current style.
why don't you approve then? :-) |
I think having a brief description at the beginning of each test file would really help. I'd also prefer to have single command for building all tests (we can merge both Other than that, the PR looks good. Many thanks for doing that! |
Because I was too lazy to actually decipher the WAT! |
done.
done. |
@@ -0,0 +1,45 @@ | |||
;; When the main thread calls proc_exit, it should terminate | |||
;; a thread blocking in `memory.atomic.wait32` opecode. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
;; a thread blocking in `memory.atomic.wait32` opecode. | |
;; a thread blocking in `memory.atomic.wait32` opcode. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
@@ -0,0 +1,45 @@ | |||
;; When a non-main thread calls proc_exit, it should terminate | |||
;; the main thread blocking in `memory.atomic.wait32` opecode. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
;; the main thread blocking in `memory.atomic.wait32` opecode. | |
;; the main thread blocking in `memory.atomic.wait32` opcode. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
and as you merged #25, i now have to resolve conflicts. sigh. |
``` (venv) spacetanuki% TOYWASM=~/git/toywasm/b/toywasm python3 test-runner/wasi_test_runner.py -t ~/git/wasm/wasi-threads/test/testsuite -r ~/git/toywasm/test/wasi-testsuite-adapter.py Test wasi_threads_exit_nonmain_wasi passed Test wasi_threads_exit_main_busy passed Test wasi_threads_exit_main_wasi passed Test wasi_threads_exit_nonmain_busy passed Test wasi_threads_spawn passed Test wasi_threads_exit_main_block passed Test wasi_threads_exit_nonmain_block passed ===== Test results ===== Runtime: toywasm v0.0 Suite: WASI threads proposal Total: 7 Passed: 7 Failed: 0 Test suites: 1 passed, 0 total Tests: 7 passed, 0 total (venv) spacetanuki% ```
as suggested in WebAssembly/wasi-libc#369 the corresponding toywasm change: yamt/toywasm@4d81846 ``` spacetanuki% TOYWASM=~/git/toywasm/b/toywasm python3 ~/git/wasm/wasi-testsuite/test-runner/wasi_test_runner.py -t ./test/testsuite -r ~/git/toywasm/test/wasi-testsuite-adapter.py Test wasi_threads_exit_nonmain_wasi passed Test wasi_threads_exit_main_busy passed Test wasi_threads_exit_main_wasi passed Test wasi_threads_exit_nonmain_busy passed Test wasi_threads_spawn passed Test wasi_threads_exit_main_block passed Test wasi_threads_exit_nonmain_block passed ===== Test results ===== Runtime: toywasm v0.0 Suite: WASI threads proposal Total: 7 Passed: 7 Failed: 0 Test suites: 1 passed, 0 total Tests: 7 passed, 0 total spacetanuki% ```
While it's a bit redundant to both import and export a memory, it's what WASI implementations expect. Emscripten, toywasm: Import alone is fine. But export wouldn't hurt. wasm-micro-runtime: Export is checked. Nothing actually seems to rely on it though. wasmtime: Export is necessary? References: https://github.com/WebAssembly/WASI/blob/main/legacy/application-abi.md#current-unstable-abi WebAssembly#22
Also add some comments
While I suspect wait and notify are memory barriers for most implementations, it's safer to issue explicit fences.
@abrown any blockers? |
Ok, I'm merging this; thanks @yamt for your patience as we veeery slowly reviewed this. I think any additional nits can be worked out in future commits and this moves things forward as-is. |