Skip to content
Open
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
4 changes: 2 additions & 2 deletions .github/workflows/wasi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ jobs:
# Tests incompatible with WASI are annotated with
# #[cfg_attr(wasi_runner, ignore)] in the test source files.
# TODO: add integration tests for these tools as WASI support is extended:
# arch b2sum cat cksum cp csplit date dir dircolors fmt join
# arch b2sum cksum cp csplit date dir dircolors fmt join
# ls md5sum mkdir mv nproc pathchk pr printenv ptx pwd readlink
# realpath rm rmdir seq sha1sum sha224sum sha256sum sha384sum
# sha512sum shred sleep sort split tail touch tsort uname uniq
Expand All @@ -69,7 +69,7 @@ jobs:
UUTESTS_WASM_RUNNER=wasmtime \
cargo test --test tests -- \
test_base32:: test_base64:: test_basenc:: test_basename:: \
test_comm:: test_cut:: test_dirname:: test_echo:: \
test_cat:: test_comm:: test_cut:: test_dirname:: test_echo:: \
test_expand:: test_factor:: test_false:: test_fold:: \
test_head:: test_link:: test_ln:: test_nl:: test_numfmt:: \
test_od:: test_paste:: test_printf:: test_shuf:: test_sum:: \
Expand Down
6 changes: 5 additions & 1 deletion src/uu/cat/src/platform/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,11 @@ pub use self::unix::is_safe_overwrite;
#[cfg(windows)]
pub use self::windows::is_safe_overwrite;

// WASI: no fstat-based device/inode checks available; assume safe.
// WASI: when stdout is inherited from a host file descriptor, wasmtime
// reports its fstat as all-zero (st_dev == st_ino == 0), so the dev/inode
// comparison against any input file descriptor can never match. There is
// no reliable way to detect unsafe overwrite here; assume safe rather than
// risk a spurious error.
#[cfg(target_os = "wasi")]
pub fn is_safe_overwrite<I, O>(_input: &I, _output: &O) -> bool {
true
Expand Down
21 changes: 19 additions & 2 deletions tests/by-util/test_cat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
//
// For the full copyright and license information, please view the LICENSE
// file that was distributed with this source code.
// spell-checker:ignore NOFILE nonewline cmdline
// spell-checker:ignore NOFILE nonewline cmdline setrlimit ELOOP

#[cfg(any(target_os = "linux", target_os = "android"))]
use rlimit::Resource;
Expand Down Expand Up @@ -87,6 +87,7 @@ fn test_no_options_big_input() {

#[test]
#[cfg(unix)]
#[cfg_attr(wasi_runner, ignore = "WASI: no FIFO/mkfifo support")]
fn test_fifo_symlink() {
use std::io::Write;
use std::thread;
Expand Down Expand Up @@ -121,6 +122,7 @@ fn test_fifo_symlink() {
// TODO(#7542): Re-enable on Android once we figure out why setting limit is broken.
// #[cfg(any(target_os = "linux", target_os = "android"))]
#[cfg(target_os = "linux")]
#[cfg_attr(wasi_runner, ignore = "WASI: rlimit/setrlimit not supported")]
fn test_closes_file_descriptors() {
// Each file creates a pipe, which has two file descriptors.
// If they are not closed then five is certainly too many.
Expand All @@ -138,6 +140,7 @@ fn test_closes_file_descriptors() {

#[test]
#[cfg(unix)]
#[cfg_attr(wasi_runner, ignore = "WASI: no pipe/signal support")]
fn test_broken_pipe() {
let mut cmd = new_ucmd!();
let mut child = cmd
Expand Down Expand Up @@ -514,6 +517,7 @@ fn test_squeeze_blank_before_numbering() {
/// This tests reading from Unix character devices
#[test]
#[cfg(unix)]
#[cfg_attr(wasi_runner, ignore = "WASI sandbox: host paths not visible")]
fn test_dev_random() {
#[cfg(any(target_os = "linux", target_os = "android"))]
const DEV_RANDOM: &str = "/dev/urandom";
Expand Down Expand Up @@ -544,6 +548,7 @@ fn test_dev_random() {
/// Wikipedia says there is support on Linux, FreeBSD, and `NetBSD`.
#[test]
#[cfg(any(target_os = "linux", target_os = "freebsd", target_os = "netbsd"))]
#[cfg_attr(wasi_runner, ignore = "WASI sandbox: host paths not visible")]
fn test_dev_full() {
let mut proc = new_ucmd!()
.set_stdout(Stdio::piped())
Expand All @@ -559,6 +564,7 @@ fn test_dev_full() {

#[test]
#[cfg(any(target_os = "linux", target_os = "freebsd", target_os = "netbsd"))]
#[cfg_attr(wasi_runner, ignore = "WASI sandbox: host paths not visible")]
fn test_dev_full_show_all() {
let buf_len = 2048;
let mut proc = new_ucmd!()
Expand All @@ -581,6 +587,7 @@ fn test_dev_full_show_all() {
// without additional flush output gets reversed.
#[test]
#[cfg(target_os = "linux")]
#[cfg_attr(wasi_runner, ignore = "WASI sandbox: host paths not visible")]
fn test_write_fast_fallthrough_uses_flush() {
const PROC_INIT_CMDLINE: &str = "/proc/1/cmdline";
let cmdline = read_to_string(PROC_INIT_CMDLINE).unwrap();
Expand All @@ -593,6 +600,7 @@ fn test_write_fast_fallthrough_uses_flush() {

#[test]
#[cfg(unix)]
#[cfg_attr(wasi_runner, ignore = "WASI: no Unix domain socket support")]
fn test_domain_socket() {
use std::os::unix::net::UnixListener;

Expand All @@ -618,10 +626,11 @@ fn test_write_to_self_empty() {
.open(&file_path)
.unwrap();

s.ucmd().set_stdout(file).arg(&file_path).succeeds();
s.ucmd().set_stdout(file).arg("file.txt").succeeds();
}

#[test]
#[cfg_attr(wasi_runner, ignore = "WASI: cannot detect unsafe overwrite")]
fn test_write_to_self() {
let s = TestScenario::new(util_name!());
let file_path = s.fixtures.plus("first_file");
Expand Down Expand Up @@ -678,6 +687,7 @@ fn test_successful_write_to_read_write_self() {
///
/// `cat fx fx3 1<>fx3`
#[test]
#[cfg_attr(wasi_runner, ignore = "WASI: cannot detect unsafe overwrite")]
fn test_failed_write_to_read_write_self() {
let (at, mut ucmd) = at_and_ucmd!();
at.write("fx", "g");
Expand All @@ -703,6 +713,10 @@ fn test_failed_write_to_read_write_self() {
#[test]
#[cfg(unix)]
#[cfg(not(target_os = "openbsd"))]
#[cfg_attr(
wasi_runner,
ignore = "WASI: symlink loop traversal does not surface ELOOP ('Too many levels of symbolic links')"
)]
fn test_error_loop() {
let (at, mut ucmd) = at_and_ucmd!();
at.symlink_file("2", "1");
Expand All @@ -726,6 +740,7 @@ fn test_u_ignored() {

#[test]
#[cfg(unix)]
#[cfg_attr(wasi_runner, ignore = "WASI: errno/error-message mismatches")]
fn test_write_fast_read_error() {
use std::os::unix::fs::PermissionsExt;

Expand All @@ -746,6 +761,7 @@ fn test_write_fast_read_error() {

#[test]
#[cfg(target_os = "linux")]
#[cfg_attr(wasi_runner, ignore = "WASI: argv/filenames must be valid UTF-8")]
fn test_cat_non_utf8_paths() {
use std::ffi::OsStr;
use std::os::unix::ffi::OsStrExt;
Expand All @@ -770,6 +786,7 @@ fn test_cat_non_utf8_paths() {

#[test]
#[cfg(unix)]
#[cfg_attr(wasi_runner, ignore = "WASI: cannot detect unsafe overwrite")]
fn test_appending_same_input_output() {
let (at, mut ucmd) = at_and_ucmd!();

Expand Down
Loading