Browse Source

wasi-cap-std-sync: use std::io::Std{in,out,err} to impl {read,write}_vectored (#6825)

* add new wasi-test printing unicode on stdout

there's not yet a way to show this test is actually doing what we
intend, I'm using CI to see how this runs on all platforms

Reported in #6824

prtest:full

* cap-std-sync: use std::io::Std{in,out,err}'s {read,write}_vectored directly

instead of using AsFilelike to view these as a File.

This means we also have to use std's mutexes to access these descriptors,
which also seems like a good idea.

We believe will fix unicode output on windows issues:
https://github.com/bytecodealliance/wasmtime/issues/6824
pull/7032/head
Pat Hickey 1 year ago
committed by GitHub
parent
commit
ce4950e420
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 4
      crates/test-programs/tests/wasi-cap-std-sync.rs
  2. 4
      crates/test-programs/tests/wasi-preview1-host-in-preview2.rs
  3. 4
      crates/test-programs/tests/wasi-preview2-components-sync.rs
  4. 4
      crates/test-programs/tests/wasi-preview2-components.rs
  5. 4
      crates/test-programs/tests/wasi-tokio.rs
  6. 15
      crates/test-programs/wasi-tests/src/bin/unicode_output.rs
  7. 6
      crates/wasi-common/cap-std-sync/src/stdio.rs

4
crates/test-programs/tests/wasi-cap-std-sync.rs

@ -291,3 +291,7 @@ fn unlink_file_trailing_slashes() {
fn path_open_preopen() {
run("path_open_preopen", true).unwrap()
}
#[test_log::test]
fn unicode_output() {
run("unicode_output", true).unwrap()
}

4
crates/test-programs/tests/wasi-preview1-host-in-preview2.rs

@ -335,3 +335,7 @@ async fn unlink_file_trailing_slashes() {
async fn path_open_preopen() {
run("path_open_preopen", false).await.unwrap()
}
#[test_log::test(tokio::test(flavor = "multi_thread"))]
async fn unicode_output() {
run("unicode_output", true).await.unwrap()
}

4
crates/test-programs/tests/wasi-preview2-components-sync.rs

@ -312,3 +312,7 @@ fn unlink_file_trailing_slashes() {
fn path_open_preopen() {
run("path_open_preopen", false).unwrap()
}
#[test_log::test]
fn unicode_output() {
run("unicode_output", true).unwrap()
}

4
crates/test-programs/tests/wasi-preview2-components.rs

@ -320,3 +320,7 @@ async fn unlink_file_trailing_slashes() {
async fn path_open_preopen() {
run("path_open_preopen", false).await.unwrap()
}
#[test_log::test(tokio::test(flavor = "multi_thread"))]
async fn unicode_output() {
run("unicode_output", true).await.unwrap()
}

4
crates/test-programs/tests/wasi-tokio.rs

@ -297,3 +297,7 @@ async fn unlink_file_trailing_slashes() {
async fn path_open_preopen() {
run("path_open_preopen", true).await.unwrap()
}
#[test_log::test(tokio::test(flavor = "multi_thread"))]
async fn unicode_output() {
run("unicode_output", true).await.unwrap()
}

15
crates/test-programs/wasi-tests/src/bin/unicode_output.rs

@ -0,0 +1,15 @@
use wasi_tests::STDOUT_FD;
fn main() {
let text = "مرحبا بكم\n";
let ciovecs = [wasi::Ciovec {
buf: text.as_bytes().as_ptr(),
buf_len: text.as_bytes().len(),
}];
let written = unsafe { wasi::fd_write(STDOUT_FD, &ciovecs) }.expect("write succeeds");
assert_eq!(
written,
text.as_bytes().len(),
"full contents should be written"
);
}

6
crates/wasi-common/cap-std-sync/src/stdio.rs

@ -1,10 +1,8 @@
use crate::file::convert_systimespec;
use fs_set_times::SetTimes;
use io_lifetimes::AsFilelike;
use is_terminal::IsTerminal;
use std::any::Any;
use std::convert::TryInto;
use std::fs::File;
use std::io;
use std::io::{Read, Write};
use system_interface::io::ReadReady;
@ -50,7 +48,7 @@ impl WasiFile for Stdin {
}
}
async fn read_vectored<'a>(&self, bufs: &mut [io::IoSliceMut<'a>]) -> Result<u64, Error> {
let n = (&*self.0.as_filelike_view::<File>()).read_vectored(bufs)?;
let n = self.0.lock().read_vectored(bufs)?;
Ok(n.try_into().map_err(|_| Error::range())?)
}
async fn read_vectored_at<'a>(
@ -128,7 +126,7 @@ macro_rules! wasi_file_write_impl {
Ok(FdFlags::APPEND)
}
async fn write_vectored<'a>(&self, bufs: &[io::IoSlice<'a>]) -> Result<u64, Error> {
let n = (&*self.0.as_filelike_view::<File>()).write_vectored(bufs)?;
let n = self.0.lock().write_vectored(bufs)?;
Ok(n.try_into().map_err(|_| {
Error::range().context("converting write_vectored total length")
})?)

Loading…
Cancel
Save