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

Sync wasi-cli with wit definitions in standards repo #6806

Merged
merged 19 commits into from
Aug 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ system-interface = { version = "0.26.0", features = ["cap_std_impls"] }
io-lifetimes = { version = "2.0.2", default-features = false }
io-extras = "0.18.0"
rustix = "0.38.4"

is-terminal = "0.4.0"
# wit-bindgen:
wit-bindgen = { version = "0.9.0", default-features = false }

Expand Down
2 changes: 2 additions & 0 deletions crates/test-programs/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ cargo_metadata = "0.15.3"
wit-component = { workspace = true }
heck = { workspace = true }

[dependencies]
is-terminal = { workspace = true }

[dev-dependencies]
anyhow = { workspace = true }
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use command_tests::wasi::cli_base::environment;
use command_tests::wasi::cli_base::stdin;
use command_tests::wasi::cli::environment;
use command_tests::wasi::cli::stdin;
use command_tests::wasi::io::streams;
use command_tests::wasi::poll::poll;

Expand Down
7 changes: 7 additions & 0 deletions crates/test-programs/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,10 @@ pub fn wasi_tests_environment() -> &'static [(&'static str, &'static str)] {
]
}
}

pub fn stdio_is_terminal() -> bool {
use is_terminal::is_terminal;
is_terminal(&std::io::stdin())
&& is_terminal(&std::io::stdout())
&& is_terminal(&std::io::stderr())
}
46 changes: 32 additions & 14 deletions crates/test-programs/tests/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use wasmtime::{
use wasmtime_wasi::preview2::{
command::{add_to_linker, Command},
pipe::MemoryInputPipe,
DirPerms, FilePerms, HostMonotonicClock, HostWallClock, Table, WasiCtx, WasiCtxBuilder,
DirPerms, FilePerms, HostMonotonicClock, HostWallClock, IsATTY, Table, WasiCtx, WasiCtxBuilder,
WasiView,
};

Expand Down Expand Up @@ -68,6 +68,7 @@ async fn hello_stdout() -> Result<()> {
let (mut store, command) =
instantiate(get_component("hello_stdout"), CommandCtx { table, wasi }).await?;
command
.wasi_cli_run()
.call_run(&mut store)
.await?
.map_err(|()| anyhow::anyhow!("command returned with failing exit status"))
Expand All @@ -90,7 +91,7 @@ async fn panic() -> Result<()> {
.build(&mut table)?;
let (mut store, command) =
instantiate(get_component("panic"), CommandCtx { table, wasi }).await?;
let r = command.call_run(&mut store).await;
let r = command.wasi_cli_run().call_run(&mut store).await;
assert!(r.is_err());
println!("{:?}", r);
Ok(())
Expand All @@ -105,6 +106,7 @@ async fn args() -> Result<()> {
let (mut store, command) =
instantiate(get_component("args"), CommandCtx { table, wasi }).await?;
command
.wasi_cli_run()
.call_run(&mut store)
.await?
.map_err(|()| anyhow::anyhow!("command returned with failing exit status"))
Expand All @@ -118,6 +120,7 @@ async fn random() -> Result<()> {
instantiate(get_component("random"), CommandCtx { table, wasi }).await?;

command
.wasi_cli_run()
.call_run(&mut store)
.await?
.map_err(|()| anyhow::anyhow!("command returned with failing exit status"))
Expand Down Expand Up @@ -164,6 +167,7 @@ async fn time() -> Result<()> {
instantiate(get_component("time"), CommandCtx { table, wasi }).await?;

command
.wasi_cli_run()
.call_run(&mut store)
.await?
.map_err(|()| anyhow::anyhow!("command returned with failing exit status"))
Expand All @@ -173,15 +177,17 @@ async fn time() -> Result<()> {
async fn stdin() -> Result<()> {
let mut table = Table::new();
let wasi = WasiCtxBuilder::new()
.stdin(MemoryInputPipe::new(
"So rested he by the Tumtum tree".into(),
))
.stdin(
MemoryInputPipe::new("So rested he by the Tumtum tree".into()),
IsATTY::No,
)
.build(&mut table)?;

let (mut store, command) =
instantiate(get_component("stdin"), CommandCtx { table, wasi }).await?;

command
.wasi_cli_run()
.call_run(&mut store)
.await?
.map_err(|()| anyhow::anyhow!("command returned with failing exit status"))
Expand All @@ -191,15 +197,17 @@ async fn stdin() -> Result<()> {
async fn poll_stdin() -> Result<()> {
let mut table = Table::new();
let wasi = WasiCtxBuilder::new()
.stdin(MemoryInputPipe::new(
"So rested he by the Tumtum tree".into(),
))
.stdin(
MemoryInputPipe::new("So rested he by the Tumtum tree".into()),
IsATTY::No,
)
.build(&mut table)?;

let (mut store, command) =
instantiate(get_component("poll_stdin"), CommandCtx { table, wasi }).await?;

command
.wasi_cli_run()
.call_run(&mut store)
.await?
.map_err(|()| anyhow::anyhow!("command returned with failing exit status"))
Expand All @@ -217,6 +225,7 @@ async fn env() -> Result<()> {
instantiate(get_component("env"), CommandCtx { table, wasi }).await?;

command
.wasi_cli_run()
.call_run(&mut store)
.await?
.map_err(|()| anyhow::anyhow!("command returned with failing exit status"))
Expand All @@ -239,6 +248,7 @@ async fn file_read() -> Result<()> {
instantiate(get_component("file_read"), CommandCtx { table, wasi }).await?;

command
.wasi_cli_run()
.call_run(&mut store)
.await?
.map_err(|()| anyhow::anyhow!("command returned with failing exit status"))
Expand All @@ -261,6 +271,7 @@ async fn file_append() -> Result<()> {
let (mut store, command) =
instantiate(get_component("file_append"), CommandCtx { table, wasi }).await?;
command
.wasi_cli_run()
.call_run(&mut store)
.await?
.map_err(|()| anyhow::anyhow!("command returned with failing exit status"))?;
Expand Down Expand Up @@ -294,6 +305,7 @@ async fn file_dir_sync() -> Result<()> {
instantiate(get_component("file_dir_sync"), CommandCtx { table, wasi }).await?;

command
.wasi_cli_run()
.call_run(&mut store)
.await?
.map_err(|()| anyhow::anyhow!("command returned with failing exit status"))
Expand All @@ -307,7 +319,7 @@ async fn exit_success() -> Result<()> {
let (mut store, command) =
instantiate(get_component("exit_success"), CommandCtx { table, wasi }).await?;

let r = command.call_run(&mut store).await;
let r = command.wasi_cli_run().call_run(&mut store).await;
let err = r.unwrap_err();
let status = err
.downcast_ref::<wasmtime_wasi::preview2::I32Exit>()
Expand All @@ -324,7 +336,7 @@ async fn exit_default() -> Result<()> {
let (mut store, command) =
instantiate(get_component("exit_default"), CommandCtx { table, wasi }).await?;

let r = command.call_run(&mut store).await?;
let r = command.wasi_cli_run().call_run(&mut store).await?;
assert!(r.is_ok());
Ok(())
}
Expand All @@ -337,7 +349,7 @@ async fn exit_failure() -> Result<()> {
let (mut store, command) =
instantiate(get_component("exit_failure"), CommandCtx { table, wasi }).await?;

let r = command.call_run(&mut store).await;
let r = command.wasi_cli_run().call_run(&mut store).await;
let err = r.unwrap_err();
let status = err
.downcast_ref::<wasmtime_wasi::preview2::I32Exit>()
Expand All @@ -354,7 +366,7 @@ async fn exit_panic() -> Result<()> {
let (mut store, command) =
instantiate(get_component("exit_panic"), CommandCtx { table, wasi }).await?;

let r = command.call_run(&mut store).await;
let r = command.wasi_cli_run().call_run(&mut store).await;
let err = r.unwrap_err();
// The panic should trap.
assert!(err
Expand Down Expand Up @@ -387,6 +399,7 @@ async fn directory_list() -> Result<()> {
instantiate(get_component("directory_list"), CommandCtx { table, wasi }).await?;

command
.wasi_cli_run()
.call_run(&mut store)
.await?
.map_err(|()| anyhow::anyhow!("command returned with failing exit status"))
Expand All @@ -401,6 +414,7 @@ async fn default_clocks() -> Result<()> {
instantiate(get_component("default_clocks"), CommandCtx { table, wasi }).await?;

command
.wasi_cli_run()
.call_run(&mut store)
.await?
.map_err(|()| anyhow::anyhow!("command returned with failing exit status"))
Expand All @@ -417,6 +431,7 @@ async fn export_cabi_realloc() -> Result<()> {
.await?;

command
.wasi_cli_run()
.call_run(&mut store)
.await?
.map_err(|()| anyhow::anyhow!("command returned with failing exit status"))
Expand All @@ -439,6 +454,7 @@ async fn read_only() -> Result<()> {
instantiate(get_component("read_only"), CommandCtx { table, wasi }).await?;

command
.wasi_cli_run()
.call_run(&mut store)
.await?
.map_err(|()| anyhow::anyhow!("command returned with failing exit status"))
Expand All @@ -452,7 +468,7 @@ async fn stream_pollable_lifetimes() -> Result<()> {
let mut table = Table::new();
let wasi = WasiCtxBuilder::new()
.args(&["correct"])
.stdin(MemoryInputPipe::new(" ".into()))
.stdin(MemoryInputPipe::new(" ".into()), IsATTY::No)
.build(&mut table)?;

let (mut store, command) = instantiate(
Expand All @@ -462,6 +478,7 @@ async fn stream_pollable_lifetimes() -> Result<()> {
.await?;

command
.wasi_cli_run()
.call_run(&mut store)
.await?
.map_err(|()| anyhow::anyhow!("command returned with failing exit status"))?;
Expand All @@ -471,7 +488,7 @@ async fn stream_pollable_lifetimes() -> Result<()> {
let mut table = Table::new();
let wasi = WasiCtxBuilder::new()
.args(&["trap"])
.stdin(MemoryInputPipe::new(" ".into()))
.stdin(MemoryInputPipe::new(" ".into()), IsATTY::No)
.build(&mut table)?;

let (mut store, command) = instantiate(
Expand All @@ -481,6 +498,7 @@ async fn stream_pollable_lifetimes() -> Result<()> {
.await?;

let trap = command
.wasi_cli_run()
.call_run(&mut store)
.await
.err()
Expand Down
30 changes: 20 additions & 10 deletions crates/test-programs/tests/reactor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,16 @@ wasmtime::component::bindgen!({
"wasi:io/streams": preview2::bindings::io::streams,
"wasi:filesystem/types": preview2::bindings::filesystem::types,
"wasi:filesystem/preopens": preview2::bindings::filesystem::preopens,
"wasi:cli-base/environment": preview2::bindings::cli_base::environment,
"wasi:cli-base/exit": preview2::bindings::cli_base::exit,
"wasi:cli-base/stdin": preview2::bindings::cli_base::stdin,
"wasi:cli-base/stdout": preview2::bindings::cli_base::stdout,
"wasi:cli-base/stderr": preview2::bindings::cli_base::stderr,
"wasi:cli/environment": preview2::bindings::cli::environment,
"wasi:cli/exit": preview2::bindings::cli::exit,
"wasi:cli/stdin": preview2::bindings::cli::stdin,
"wasi:cli/stdout": preview2::bindings::cli::stdout,
"wasi:cli/stderr": preview2::bindings::cli::stderr,
"wasi:cli/terminal_input": preview2::bindings::cli::terminal_input,
"wasi:cli/terminal_output": preview2::bindings::cli::terminal_output,
"wasi:cli/terminal_stdin": preview2::bindings::cli::terminal_stdin,
"wasi:cli/terminal_stdout": preview2::bindings::cli::terminal_stdout,
"wasi:cli/terminal_stderr": preview2::bindings::cli::terminal_stderr,
},
ownership: Borrowing {
duplicate_if_necessary: false
Expand Down Expand Up @@ -71,11 +76,16 @@ async fn instantiate(
preview2::bindings::filesystem::types::add_to_linker(&mut linker, |x| x)?;
preview2::bindings::filesystem::preopens::add_to_linker(&mut linker, |x| x)?;
preview2::bindings::io::streams::add_to_linker(&mut linker, |x| x)?;
preview2::bindings::cli_base::environment::add_to_linker(&mut linker, |x| x)?;
preview2::bindings::cli_base::exit::add_to_linker(&mut linker, |x| x)?;
preview2::bindings::cli_base::stdin::add_to_linker(&mut linker, |x| x)?;
preview2::bindings::cli_base::stdout::add_to_linker(&mut linker, |x| x)?;
preview2::bindings::cli_base::stderr::add_to_linker(&mut linker, |x| x)?;
preview2::bindings::cli::environment::add_to_linker(&mut linker, |x| x)?;
preview2::bindings::cli::exit::add_to_linker(&mut linker, |x| x)?;
preview2::bindings::cli::stdin::add_to_linker(&mut linker, |x| x)?;
preview2::bindings::cli::stdout::add_to_linker(&mut linker, |x| x)?;
preview2::bindings::cli::stderr::add_to_linker(&mut linker, |x| x)?;
preview2::bindings::cli::terminal_input::add_to_linker(&mut linker, |x| x)?;
preview2::bindings::cli::terminal_output::add_to_linker(&mut linker, |x| x)?;
preview2::bindings::cli::terminal_stdin::add_to_linker(&mut linker, |x| x)?;
preview2::bindings::cli::terminal_stdout::add_to_linker(&mut linker, |x| x)?;
preview2::bindings::cli::terminal_stderr::add_to_linker(&mut linker, |x| x)?;

let mut store = Store::new(&ENGINE, wasi_ctx);

Expand Down
17 changes: 15 additions & 2 deletions crates/test-programs/tests/wasi-cap-std-sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -160,8 +160,8 @@ fn interesting_paths() {
run("interesting_paths", true).unwrap()
}
#[test_log::test]
fn isatty() {
run("isatty", true).unwrap()
fn regular_file_isatty() {
run("regular_file_isatty", true).unwrap()
}
#[test_log::test]
fn nofollow_errors() {
Expand Down Expand Up @@ -253,6 +253,19 @@ fn sched_yield() {
fn stdio() {
run("stdio", true).unwrap()
}
#[test_log::test]
fn stdio_isatty() {
if test_programs::stdio_is_terminal() {
// Inherit stdio, which is a terminal in the test runner's environment:
run("stdio_isatty", true).unwrap()
}
}
#[test_log::test]
fn stdio_not_isatty() {
// Don't inherit stdio, test asserts each is not tty:
run("stdio_not_isatty", false).unwrap()
}

#[test_log::test]
fn symlink_create() {
run("symlink_create", true).unwrap()
Expand Down
Loading