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

wasi: Test the stdio streams implementation #6764

Merged
merged 18 commits into from
Jul 31, 2023
Merged

Conversation

elliottt
Copy link
Member

@elliottt elliottt commented Jul 24, 2023

Test the stdio implementations in the wasi crate, by forking a child process and controlling its stdin directly. This testing exposed a few needed changes:

  • AsyncReadStream and AsyncWriteStream both now terminate the associated tokio::task when they are dropped.
  • The stdin implementation on unix and windows now properly handles spanning tokio runtime restarts, and process termination.

After implementing these changes, the wasi implementation of stdin works on windows now and is better tested on unix.

@elliottt elliottt force-pushed the trevor/stdio-stream-testing branch from 4885463 to 6b99913 Compare July 24, 2023 23:52
@pchickey pchickey force-pushed the trevor/stdio-stream-testing branch from 6b99913 to caa308d Compare July 25, 2023 00:34
@elliottt elliottt force-pushed the trevor/stdio-stream-testing branch from caa308d to 6b99913 Compare July 25, 2023 00:36
@github-actions github-actions bot added the wasi Issues pertaining to WASI label Jul 25, 2023
Pat Hickey added 2 commits July 25, 2023 10:37
the tasks will exit on their own if the receiver drops, but this should
terminate them while they are awaiting on read/write.
this has still got at least one serious bug, noted with FIXME.
also has a bunch of changes which can be backed out because they were
chasing red herrings.

the major bug was that, for some inexplicable reason, i didn't actually
set the fd to nonblocking just prior to asyncfd creation. switching from
the fdflags.difference to fdflags.union operator fixed that bug.
@pchickey pchickey force-pushed the trevor/stdio-stream-testing branch from e463a36 to f74d6c7 Compare July 26, 2023 00:02
@elliottt elliottt force-pushed the trevor/stdio-stream-testing branch from bc40aaf to c61a9e3 Compare July 26, 2023 18:34
@elliottt elliottt marked this pull request as ready for review July 27, 2023 22:43
@elliottt elliottt requested a review from a team as a code owner July 27, 2023 22:43
@elliottt elliottt requested review from fitzgen and removed request for a team July 27, 2023 22:43
prtest:full
@elliottt elliottt force-pushed the trevor/stdio-stream-testing branch from d2d1efa to f001df3 Compare July 27, 2023 22:44
@elliottt elliottt requested a review from pchickey July 27, 2023 22:45
@pchickey pchickey enabled auto-merge July 27, 2023 22:45
@pchickey pchickey added this pull request to the merge queue Jul 31, 2023
Merged via the queue into main with commit c61899a Jul 31, 2023
@pchickey pchickey deleted the trevor/stdio-stream-testing branch July 31, 2023 23:12
geekbeast pushed a commit to geekbeast/wasmtime that referenced this pull request Aug 1, 2023
* main: (47 commits)
  Add core dump support to the runtime (bytecodealliance#6513)
  Resource table tracks child relationships (bytecodealliance#6779)
  Wasmtime: Move `OnDemandInstanceAllocator` to its own module (bytecodealliance#6790)
  wasi: Test the stdio streams implementation (bytecodealliance#6764)
  Don't generate same-named imports in fact modules (bytecodealliance#6783)
  Wasmtime: Add support for Wasm tail calls (bytecodealliance#6774)
  Cranelift: Fix `ABIMachineSpec::gen_add_imm` for riscv64 (bytecodealliance#6780)
  Update the wasm-tools family of crates, disallow empty component types (bytecodealliance#6777)
  Fix broken link to WASI API documentation (bytecodealliance#6775)
  A bunch of cleanups for cranelift-codegen-meta (bytecodealliance#6772)
  Implement component-to-component calls with resources (bytecodealliance#6769)
  Ignore async_stack_size if async_support is disabled (bytecodealliance#6771)
  A bunch of minor cleanups (bytecodealliance#6767)
  Fix flaky tests in preview2 streams (bytecodealliance#6763)
  Refactor and simplify component trampolines (bytecodealliance#6751)
  Cranelift: Implement tail calls on riscv64 (bytecodealliance#6749)
  WASI Preview 2: rewrite streams and pollable implementation (bytecodealliance#6556)
  cranelift-wasm: Add support for translating Wasm tail calls to CLIF (bytecodealliance#6760)
  Cranelift: Get tail calls working on aarch64 (bytecodealliance#6723)
  Implement component model resources in Wasmtime (bytecodealliance#6691)
  ...
eduardomourar pushed a commit to eduardomourar/wasmtime that referenced this pull request Aug 18, 2023
* Add a helper for writing stdin tests

* Test a use of preview2::stdio::Stdin on unix

* Abstract the stdin test, and apply it to tokio::stdin and worker_thread_stdin

* re-implement worker thread stdin with a watch

* poll_oneoff_stdio should work on windows now

* comments

* test: show that restarting

* reap tasks from AsyncReadStream and AsyncWriteStream when dropped

the tasks will exit on their own if the receiver drops, but this should
terminate them while they are awaiting on read/write.

* rewrite most of the asyncfd based stdin

this has still got at least one serious bug, noted with FIXME.
also has a bunch of changes which can be backed out because they were
chasing red herrings.

the major bug was that, for some inexplicable reason, i didn't actually
set the fd to nonblocking just prior to asyncfd creation. switching from
the fdflags.difference to fdflags.union operator fixed that bug.

* Refactor to avoid `as_mut` and `.0 .0`

* Rework the stdin implementation to hold the stream in a mutex

* Detect when the task backing stdin has exited

* Have the thread managing stdin exit when it encounters EOF

* Refactor the test to restart the runtime as well

* Format

prtest:full

* internal tokio runtime used for sync interfaces is now new_current_thread

* Remove println from test for stdout

* Remove unneeded `vec!`

---------

Co-authored-by: Pat Hickey <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
wasi Issues pertaining to WASI
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants