Skip to content

Commit

Permalink
test-programs: cover both when stdio isatty and not
Browse files Browse the repository at this point in the history
prtest:full
  • Loading branch information
Pat Hickey committed Aug 14, 2023
1 parent f9d4be7 commit 0e59b26
Show file tree
Hide file tree
Showing 7 changed files with 78 additions and 5 deletions.
6 changes: 6 additions & 0 deletions crates/test-programs/tests/wasi-cap-std-sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,12 @@ fn sched_yield() {
fn stdio() {
run("stdio", 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
8 changes: 7 additions & 1 deletion crates/test-programs/tests/wasi-preview1-host-in-preview2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,8 @@ async fn interesting_paths() {
}
#[test_log::test(tokio::test(flavor = "multi_thread"))]
async fn isatty() {
run("isatty", false).await.unwrap()
// Inherit stdio: test asserts stdio isatty
run("isatty", true).await.unwrap()
}
#[test_log::test(tokio::test(flavor = "multi_thread"))]
async fn nofollow_errors() {
Expand Down Expand Up @@ -298,6 +299,11 @@ async fn stdio() {
run("stdio", false).await.unwrap()
}
#[test_log::test(tokio::test(flavor = "multi_thread"))]
async fn stdio_not_isatty() {
// Don't inherit stdio, test asserts each is not tty:
run("stdio_not_isatty", false).await.unwrap()
}
#[test_log::test(tokio::test(flavor = "multi_thread"))]
async fn symlink_create() {
run("symlink_create", false).await.unwrap()
}
Expand Down
8 changes: 7 additions & 1 deletion crates/test-programs/tests/wasi-preview2-components-sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,8 @@ fn interesting_paths() {
}
#[test_log::test]
fn isatty() {
run("isatty", false).unwrap()
// Inherit stdio, test asserts that each isatty
run("isatty", true).unwrap()
}
#[test_log::test]
fn nofollow_errors() {
Expand Down Expand Up @@ -276,6 +277,11 @@ fn stdio() {
run("stdio", false).unwrap()
}
#[test_log::test]
fn stdio_not_isatty() {
// Don't inherit stdio, test asserts not isatty:
run("stdio_not_isatty", false).unwrap()
}
#[test_log::test]
fn symlink_create() {
run("symlink_create", false).unwrap()
}
Expand Down
8 changes: 7 additions & 1 deletion crates/test-programs/tests/wasi-preview2-components.rs
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,8 @@ async fn interesting_paths() {
}
#[test_log::test(tokio::test(flavor = "multi_thread"))]
async fn isatty() {
run("isatty", false).await.unwrap()
// Inherit stdio, test asserts that each isatty
run("isatty", true).await.unwrap()
}
#[test_log::test(tokio::test(flavor = "multi_thread"))]
async fn nofollow_errors() {
Expand Down Expand Up @@ -284,6 +285,11 @@ async fn stdio() {
run("stdio", false).await.unwrap()
}
#[test_log::test(tokio::test(flavor = "multi_thread"))]
async fn stdio_not_isatty() {
// Don't inherit stdio, test asserts each is not tty:
run("stdio_not_isatty", false).await.unwrap()
}
#[test_log::test(tokio::test(flavor = "multi_thread"))]
async fn symlink_create() {
run("symlink_create", false).await.unwrap()
}
Expand Down
5 changes: 5 additions & 0 deletions crates/test-programs/tests/wasi-tokio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,11 @@ async fn stdio() {
run("stdio", true).await.unwrap()
}
#[test_log::test(tokio::test(flavor = "multi_thread"))]
async fn stdio_not_isatty() {
// Don't inherit stdio, test asserts each is not tty:
run("stdio_not_isatty", false).await.unwrap()
}
#[test_log::test(tokio::test(flavor = "multi_thread"))]
async fn symlink_create() {
run("symlink_create", true).await.unwrap()
}
Expand Down
23 changes: 21 additions & 2 deletions crates/test-programs/wasi-tests/src/bin/isatty.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,25 @@
use std::{env, process};
use wasi_tests::open_scratch_directory;

unsafe fn test_isatty(dir_fd: wasi::Fd) {
unsafe fn test_stdio_isatty() {
assert_eq!(
libc::isatty(libc::STDIN_FILENO as std::os::raw::c_int),
1,
"stdin is a tty"
);
assert_eq!(
libc::isatty(libc::STDOUT_FILENO as std::os::raw::c_int),
1,
"stdout is a tty"
);
assert_eq!(
libc::isatty(libc::STDERR_FILENO as std::os::raw::c_int),
1,
"stderr is a tty"
);
}

unsafe fn test_file_isatty(dir_fd: wasi::Fd) {
// Create a file in the scratch directory and test if it's a tty.
let file_fd =
wasi::path_open(dir_fd, 0, "file", wasi::OFLAGS_CREAT, 0, 0, 0).expect("opening a file");
Expand Down Expand Up @@ -38,5 +56,6 @@ fn main() {
};

// Run the tests.
unsafe { test_isatty(dir_fd) }
unsafe { test_file_isatty(dir_fd) }
unsafe { test_stdio_isatty() }
}
25 changes: 25 additions & 0 deletions crates/test-programs/wasi-tests/src/bin/stdio_not_isatty.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
use std::{env, process};
use wasi_tests::open_scratch_directory;

unsafe fn test_stdio_not_isatty() {
assert_eq!(
libc::isatty(libc::STDIN_FILENO as std::os::raw::c_int),
0,
"stdin is not a tty"
);
assert_eq!(
libc::isatty(libc::STDOUT_FILENO as std::os::raw::c_int),
0,
"stdout is not a tty"
);
assert_eq!(
libc::isatty(libc::STDERR_FILENO as std::os::raw::c_int),
0,
"stderr is not a tty"
);
}

fn main() {
// Run the tests.
unsafe { test_stdio_not_isatty() }
}

0 comments on commit 0e59b26

Please sign in to comment.