Skip to content
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

Merged
merged 11 commits into from
Feb 16, 2023
Merged

Add some low level tests #19

merged 11 commits into from
Feb 16, 2023

Conversation

yamt
Copy link
Contributor

@yamt yamt commented Dec 22, 2022

(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%

@abrown
Copy link
Collaborator

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

@yamt
Copy link
Contributor Author

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 will take a look.

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.

i agree.

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.

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 eshost, but its purpose looks similar, sure.

call $proc_exit
unreachable
)
(memory 1 1 shared)
Copy link
Contributor Author

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.

Copy link
Contributor Author

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.

@loganek
Copy link
Collaborator

loganek commented Dec 23, 2022

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.

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

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.

i feel the current adapter api is too simple though

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)
Copy link
Collaborator

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.

Copy link
Contributor Author

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.

Copy link
Member

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.

Copy link
Contributor Author

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.

Copy link
Contributor Author

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.

Copy link
Contributor Author

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)

Copy link
Contributor Author

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

Copy link
Contributor Author

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.

@@ -0,0 +1,6 @@
#! /bin/sh
Copy link
Member

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

Copy link
Contributor Author

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.

Copy link
Member

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.

Copy link
Contributor Author

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 .

Copy link
Collaborator

@loganek loganek Jan 11, 2023

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

Copy link
Contributor Author

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

@yamt
Copy link
Contributor Author

yamt commented Jan 18, 2023

is there any blocker on this?

Copy link
Collaborator

@abrown abrown left a 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!

@loganek
Copy link
Collaborator

loganek commented Jan 20, 2023

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

@yamt
Copy link
Contributor Author

yamt commented Jan 20, 2023

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?
  1. run build-wat.sh to build tests.
  2. follow the instructions in wasi-testsuite.

depending on the way how the feature is enabled in wasmtime, (i don't know)
you might need to modify the wasmtime adapter script, which is currently in wasi-testsuite repo.

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

for me, the "infix" notation is more difficult to read/write than the current style.
other points make sense.

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!

why don't you approve then? :-)

@loganek
Copy link
Collaborator

loganek commented Jan 20, 2023

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 .sh files into one, I'm not that concerned about potential conflicts).

Other than that, the PR looks good. Many thanks for doing that!

@abrown
Copy link
Collaborator

abrown commented Jan 20, 2023

why don't you approve then? :-)

Because I was too lazy to actually decipher the WAT!

@yamt
Copy link
Contributor Author

yamt commented Jan 23, 2023

I think having a brief description at the beginning of each test file would really help.

done.

I'd also prefer to have single command for building all tests (we can merge both .sh files into one, I'm not that concerned about potential conflicts).

done.
this conflicts with #25 .

@@ -0,0 +1,45 @@
;; When the main thread calls proc_exit, it should terminate
;; a thread blocking in `memory.atomic.wait32` opecode.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
;; a thread blocking in `memory.atomic.wait32` opecode.
;; a thread blocking in `memory.atomic.wait32` opcode.

Copy link
Contributor Author

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.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
;; the main thread blocking in `memory.atomic.wait32` opecode.
;; the main thread blocking in `memory.atomic.wait32` opcode.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@yamt
Copy link
Contributor Author

yamt commented Jan 23, 2023

I think having a brief description at the beginning of each test file would really help.

done.

I'd also prefer to have single command for building all tests (we can merge both .sh files into one, I'm not that concerned about potential conflicts).

done. this conflicts with #25 .

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
@yamt
Copy link
Contributor Author

yamt commented Feb 6, 2023

@abrown any blockers?

@abrown
Copy link
Collaborator

abrown commented Feb 16, 2023

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.

@abrown abrown merged commit b278cc6 into WebAssembly:main Feb 16, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants