diff --git a/.github/workflows/wasi.yml b/.github/workflows/wasi.yml index 7312282557f..b5c9e994797 100644 --- a/.github/workflows/wasi.yml +++ b/.github/workflows/wasi.yml @@ -59,7 +59,6 @@ jobs: run: | cargo test --target ${{ matrix.job.target }} --no-default-features --features fs -p uucore fs::tests - name: Run integration tests via wasmtime - if: matrix.job.target == 'wasm32-wasip1' env: RUSTFLAGS: ${{ matrix.job.rust-flags }} run: | @@ -75,26 +74,11 @@ jobs: # The binary above is built without default features, so it has no # caret diagnostics; the host test crate does have them, hence the # not(wasi_runner) in the cfg guarding every `mod diagnostics`. - # TODO: add integration tests for these tools as WASI support is extended: - # csplit ls rm seq sort # nproc is not part of the default feature set, so it needs to be # requested explicitly for the host test crate to compile its tests. UUTESTS_BINARY_PATH="$(pwd)/target/${{ matrix.job.target }}/debug/coreutils.wasm" \ UUTESTS_WASM_RUNNER=wasmtime \ - cargo test --test tests --features nproc -- \ - test_arch:: test_b2sum:: test_base32:: test_base64:: test_basenc:: \ - test_basename:: test_cat:: test_cksum:: test_comm:: test_cp:: test_cut:: test_date:: \ - test_dir:: test_dircolors:: test_dirname:: test_echo:: test_expand:: test_expr:: \ - test_factor:: test_false:: test_fmt:: test_fold:: test_head:: test_join:: test_link:: test_ln:: \ - test_ls::test_ls_a_dotdot_no_error_on_wasi \ - test_ls::test_ls_al_no_capabilities_insufficient_on_wasi \ - test_md5sum:: test_mkdir:: test_mktemp:: test_mv:: test_nl:: test_nproc:: test_numfmt:: test_od:: \ - test_paste:: test_pathchk:: test_pr:: test_printenv:: test_printf:: test_ptx:: \ - test_pwd:: test_readlink:: test_realpath:: test_rmdir:: test_sha1sum:: test_sha224sum:: test_sha256sum:: \ - test_sha384sum:: test_sha512sum:: test_shred:: test_shuf:: test_sleep:: \ - test_sort::sort_multiple test_sort::test_check test_split:: test_sum:: test_tail:: test_tee:: \ - test_test:: test_touch:: test_tr:: test_true:: test_truncate:: test_tsort:: test_uname:: \ - test_uniq:: test_unexpand:: test_unlink:: test_vdir:: test_wc:: test_yes:: + cargo test --test tests --features nproc # WASI tests on non-Linux hosts. These catch host-specific wasmtime differences test_wasi_other_host: diff --git a/.vscode/cspell.dictionaries/workspace.wordlist.txt b/.vscode/cspell.dictionaries/workspace.wordlist.txt index 78bb78c480f..96ad6a045ac 100644 --- a/.vscode/cspell.dictionaries/workspace.wordlist.txt +++ b/.vscode/cspell.dictionaries/workspace.wordlist.txt @@ -124,11 +124,13 @@ ENODATA ENOENT ENOSPC ENOSYS +ENOTDIR ENOTEMPTY EOPNOTSUPP EPERM EPIPE EROFS +ETXTBSY # * vars/fcntl F_GETFL @@ -183,8 +185,10 @@ addrlen blocksize canonname chroot +cmdline dlsym execvp +fchmod fdatasync freeaddrinfo getaddrinfo @@ -204,6 +208,7 @@ inodes isatty lchown pathlen +reflink setgid setgroups settime @@ -218,6 +223,7 @@ strerror strlen syncfs umask +unflushed waitpid # * vars/nix diff --git a/docs/src/wasi-test-gaps.md b/docs/src/wasi-test-gaps.md index 44b1c2b7eda..c239d46985a 100644 --- a/docs/src/wasi-test-gaps.md +++ b/docs/src/wasi-test-gaps.md @@ -8,10 +8,6 @@ Limitations that affect only `wasm32-wasip2` use `#[uutests::wasip2_ignore(Reaso To find all annotated tests: `grep -rnE 'wasi_ignore|wasip2_ignore' tests/`. For the full, authoritative list of reason keys and their text, see `tests/uutests_procs/src/lib.rs`. -## Tools not yet covered by integration tests - -arch, b2sum, cat, 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, vdir, yes - ## WASI sandbox: host paths not visible The WASI guest only sees directories explicitly mapped with `--dir`. Host paths like `/proc`, `/sys`, and `/dev` are not accessible. Affected tests include those that read `/proc/version`, `/proc/modules`, `/proc/cpuinfo`, `/proc/self/mem`, `/sys/kernel/profiling`, `/dev/null`, `/dev/zero`, `/dev/full`, and tests that rely on anonymous pipes or Linux-specific I/O error paths. diff --git a/src/bin/coreutils.rs b/src/bin/coreutils.rs index 697e972f440..c49ecb8e76e 100644 --- a/src/bin/coreutils.rs +++ b/src/bin/coreutils.rs @@ -134,7 +134,12 @@ fn main() -> ExitCode { // #[cfg(not(feature = "only_english"))] validation::setup_localization_or_exit(util); let code = uumain(vec![util_os].into_iter().chain(args)); + // WASI preview 2 maps every nonzero `ExitCode` returned from main to 1, + // so the code must go through exit to reach the host. + #[cfg(all(target_os = "wasi", target_env = "p2"))] + exit(code); // ExitCode only holds a u8; larger codes (Windows) go through exit. + #[cfg(not(all(target_os = "wasi", target_env = "p2")))] return u8::try_from(code).map_or_else(|_| exit(code), ExitCode::from); } // GNU coreutils --help string shows help for coreutils diff --git a/src/uu/cat/src/cat.rs b/src/uu/cat/src/cat.rs index e93d7921977..70291b3bd15 100644 --- a/src/uu/cat/src/cat.rs +++ b/src/uu/cat/src/cat.rs @@ -393,7 +393,14 @@ fn cat_path(path: &OsString, options: &OutputOptions, state: &mut OutputState) - #[cfg(unix)] InputType::Socket => Err(CatError::NoSuchDeviceOrAddress), _ => { - let file = File::open(path)?; + let file = File::open(path).map_err(|e| match e.kind() { + ErrorKind::IsADirectory => CatError::IsDirectory, + #[cfg(target_os = "wasi")] + _ if e.raw_os_error() == Some(rustix::io::Errno::LOOP.raw_os_error()) => { + CatError::TooManySymlinks + } + _ => CatError::from(e), + })?; if !is_safe_overwrite(&file, &io::stdout()) { return Err(CatError::OutputIsInput); } @@ -456,6 +463,9 @@ fn get_input_type(path: &OsString) -> CatResult { let ft = match metadata(path) { Ok(md) => md.file_type(), Err(e) => { + if e.kind() == ErrorKind::IsADirectory { + return Err(CatError::IsDirectory); + } if let Some(raw_error) = e.raw_os_error() { #[cfg(any(unix, target_os = "wasi"))] let too_many_symlink_code = rustix::io::Errno::LOOP.raw_os_error(); diff --git a/src/uu/csplit/src/csplit.rs b/src/uu/csplit/src/csplit.rs index 8588d3d8033..aa998422e92 100644 --- a/src/uu/csplit/src/csplit.rs +++ b/src/uu/csplit/src/csplit.rs @@ -113,7 +113,10 @@ where T: BufRead, { let enumerated_input_lines = LinesWithNewlines::new(input) - .map(|line| line.map_err_context(|| translate!("csplit-read-error"))) + .map(|line| { + line.map_err(uucore::error::wasi_normalize_read_error) + .map_err_context(|| translate!("csplit-read-error")) + }) .enumerate(); let mut input_iter = InputSplitter::new(enumerated_input_lines); let mut split_writer = SplitWriter::new(options); diff --git a/src/uu/factor/src/factor.rs b/src/uu/factor/src/factor.rs index 9ebabf9ef08..1ad1697341d 100644 --- a/src/uu/factor/src/factor.rs +++ b/src/uu/factor/src/factor.rs @@ -192,6 +192,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> { } Err(e) => { set_exit_code(1); + let e = uucore::error::wasi_normalize_read_error(e); show_error!( "{}", translate!("factor-error-reading-input", "error" => strip_errno(&e)) diff --git a/src/uu/od/src/multifile_reader.rs b/src/uu/od/src/multifile_reader.rs index 782a4fcbc42..a97cd0a09cf 100644 --- a/src/uu/od/src/multifile_reader.rs +++ b/src/uu/od/src/multifile_reader.rs @@ -237,6 +237,7 @@ impl io::Read for MultifileReader<'_> { Ok(0) => break, Ok(n) => n, Err(e) => { + let e = uucore::error::wasi_normalize_read_error(e); show_error!( "{}: {}", self.file_name diff --git a/src/uu/paste/src/paste.rs b/src/uu/paste/src/paste.rs index cd8b97cc896..987d98881a4 100644 --- a/src/uu/paste/src/paste.rs +++ b/src/uu/paste/src/paste.rs @@ -387,6 +387,7 @@ impl InputSource { let us = match self { Self::File(bu, name) => bu .read(buf) + .map_err(uucore::error::wasi_normalize_read_error) .map_err_context(|| name.maybe_quote().to_string())?, Self::StandardInput(rc) => rc .try_borrow() @@ -404,6 +405,7 @@ impl InputSource { let us = match self { Self::File(bu, name) => bu .read_until(byte, buf) + .map_err(uucore::error::wasi_normalize_read_error) .map_err_context(|| name.maybe_quote().to_string())?, Self::StandardInput(rc) => rc .try_borrow() diff --git a/src/uu/sort/src/sort.rs b/src/uu/sort/src/sort.rs index d596c752def..cd65d1ab769 100644 --- a/src/uu/sort/src/sort.rs +++ b/src/uu/sort/src/sort.rs @@ -2178,7 +2178,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> { for (line_num, line_res) in buf_reader.split(b'\0').enumerate() { let line = line_res.map_err(|error| SortError::ReadFailed { path: files0_from.clone(), - error, + error: uucore::error::wasi_normalize_read_error(error), })?; if line.as_slice() == STDIN_FILE.as_bytes() { return Err(SortError::MinusInStdIn.into()); @@ -3360,7 +3360,7 @@ fn open_with_open_failed_error(path: impl AsRef) -> UResult Ok(Box::new(f) as Box), Err(error) => Err(SortError::OpenFailed { path: path.to_owned(), - error, + error: uucore::error::wasi_normalize_open_error(error), } .into()), } diff --git a/src/uu/tac/src/tac.rs b/src/uu/tac/src/tac.rs index 9d7fa815f9d..7325c41ea6c 100644 --- a/src/uu/tac/src/tac.rs +++ b/src/uu/tac/src/tac.rs @@ -395,7 +395,10 @@ fn tac(filenames: &[OsString], before: bool, regex: bool, separator: &OsStr) -> &buf } Err(e) => { - show!(TacError::ReadError(filename.clone(), e)); + show!(TacError::ReadError( + filename.clone(), + uucore::error::wasi_normalize_read_error(e) + )); continue; } } diff --git a/src/uu/tail/src/tail.rs b/src/uu/tail/src/tail.rs index 1dd5c94723f..3da9b2b6a03 100644 --- a/src/uu/tail/src/tail.rs +++ b/src/uu/tail/src/tail.rs @@ -372,6 +372,9 @@ fn tail_stdin( ); } } else { + #[cfg(target_os = "wasi")] + let mut reader = BufReader::new(NormalizeReadErrors(stdin().take(limit))); + #[cfg(not(target_os = "wasi"))] let mut reader = BufReader::new(stdin().take(limit)); unbounded_tail(&mut reader, settings)?; } @@ -572,7 +575,58 @@ fn bounded_tail(file: &mut File, settings: &Settings, end: Option) -> UResu Ok(()) } +/// Reader that reports a directory read on WASI as `ErrorKind::IsADirectory`. +#[cfg(target_os = "wasi")] +struct NormalizeReadErrors(R); + +#[cfg(target_os = "wasi")] +impl Read for NormalizeReadErrors { + fn read(&mut self, buf: &mut [u8]) -> io::Result { + self.0 + .read(buf) + .map_err(uucore::error::wasi_normalize_read_error) + } +} + +/// Writer that ends the process silently once the reader of stdout has gone away. +/// +/// Unix signals this case with SIGPIPE. WASI has no signals, so the process exits +/// with the status that a SIGPIPE death reports. +#[cfg(target_os = "wasi")] +struct ExitOnClosedPipe(W); + +#[cfg(target_os = "wasi")] +impl ExitOnClosedPipe { + fn check(result: io::Result) -> io::Result { + // Preview 1 reports a closed pipe as a generic EIO instead of BrokenPipe. + #[cfg(target_env = "p1")] + const EIO: Option = Some(29); + #[cfg(not(target_env = "p1"))] + const EIO: Option = None; + if let Err(err) = &result + && (err.kind() == ErrorKind::BrokenPipe || (EIO.is_some() && err.raw_os_error() == EIO)) + { + std::process::exit(13); + } + result + } +} + +#[cfg(target_os = "wasi")] +impl Write for ExitOnClosedPipe { + fn write(&mut self, buf: &[u8]) -> io::Result { + Self::check(self.0.write(buf)) + } + + fn flush(&mut self) -> io::Result<()> { + Self::check(self.0.flush()) + } +} + fn unbounded_tail(reader: &mut BufReader, settings: &Settings) -> UResult<()> { + #[cfg(target_os = "wasi")] + let mut writer = BufWriter::new(ExitOnClosedPipe(stdout().lock())); + #[cfg(not(target_os = "wasi"))] let mut writer = BufWriter::new(stdout().lock()); match &settings.mode { FilterMode::Lines(Signum::Negative(count), sep) => { @@ -657,7 +711,11 @@ fn print_target_section< limit: Option, ) -> UResult<()> { let stdout = stdout(); - let mut stdout = stdout.lock(); + let stdout = stdout.lock(); + #[cfg(target_os = "wasi")] + let mut stdout = ExitOnClosedPipe(stdout); + #[cfg(not(target_os = "wasi"))] + let mut stdout = stdout; if let Some(limit) = limit { #[cfg(any(target_os = "linux", target_os = "android"))] uucore::pipes::send_n_bytes(file, &mut stdout, limit)?; diff --git a/src/uu/tee/src/tee.rs b/src/uu/tee/src/tee.rs index 8f1f6bf9d63..8b98cd9caea 100644 --- a/src/uu/tee/src/tee.rs +++ b/src/uu/tee/src/tee.rs @@ -232,6 +232,7 @@ impl MultiWriter { Ok(slice) => self.write_flush(slice)?, Err(e) if e.kind() == ErrorKind::Interrupted => {} Err(e) => { + let e = uucore::error::wasi_normalize_read_error(e); show_error!( "{}", translate!("tee-error-stdin", "error" => strip_errno(&e)) diff --git a/src/uu/tr/src/operation.rs b/src/uu/tr/src/operation.rs index 563796c45ed..b808ea82785 100644 --- a/src/uu/tr/src/operation.rs +++ b/src/uu/tr/src/operation.rs @@ -993,7 +993,10 @@ where Ok(0) => break, // EOF reached Ok(len) => len, Err(e) if e.kind() == std::io::ErrorKind::Interrupted => continue, - Err(e) => return Err(e.map_err_context(|| translate!("tr-error-read-error"))), + Err(e) => { + let e = uucore::error::wasi_normalize_read_error(e); + return Err(e.map_err_context(|| translate!("tr-error-read-error"))); + } }; // Process the buffer and collect translated chars to output diff --git a/src/uu/tr/src/simd.rs b/src/uu/tr/src/simd.rs index 0f31e242008..33f0ee26ca2 100644 --- a/src/uu/tr/src/simd.rs +++ b/src/uu/tr/src/simd.rs @@ -129,7 +129,10 @@ where Ok(0) => break, Ok(len) => len, Err(e) if e.kind() == std::io::ErrorKind::Interrupted => continue, - Err(e) => return Err(e.map_err_context(|| translate!("tr-error-read-error"))), + Err(e) => { + let e = uucore::error::wasi_normalize_read_error(e); + return Err(e.map_err_context(|| translate!("tr-error-read-error"))); + } }; output_buf.clear(); diff --git a/src/uu/wc/src/wc.rs b/src/uu/wc/src/wc.rs index 4c662a6948e..e85aa8e22e7 100644 --- a/src/uu/wc/src/wc.rs +++ b/src/uu/wc/src/wc.rs @@ -770,7 +770,10 @@ fn word_count_from_input(input: &Input<'_>, settings: &Settings) -> CountResult }; match maybe_err { None => CountResult::Success(total), - Some(err) => CountResult::Interrupted(total, err), + Some(err) => { + let err = uucore::error::wasi_normalize_open_error(err); + CountResult::Interrupted(total, err) + } } } @@ -882,7 +885,7 @@ fn files0_iter<'a>( Ok(Input::Path(PathBuf::from(s).into())) } } - Err(e) => Err(e.map_err_context( + Err(e) => Err(uucore::error::wasi_normalize_read_error(e).map_err_context( || translate!("wc-error-read-error", "path" => locale_aware_shell_escape(&err_path)), ) as Box), }), diff --git a/src/uucore/src/lib/features/fs.rs b/src/uucore/src/lib/features/fs.rs index 15c1db0ae74..3431bdfaa99 100644 --- a/src/uucore/src/lib/features/fs.rs +++ b/src/uucore/src/lib/features/fs.rs @@ -88,6 +88,10 @@ impl FileInformation { pub fn from_path(path: impl AsRef, dereference: bool) -> IOResult { #[cfg(any(unix, target_os = "wasi"))] { + #[cfg(all(target_os = "wasi", target_env = "p2"))] + if dereference && let Some(info) = Self::from_symlink_target_p2(path.as_ref()) { + return Ok(info); + } let stat = if dereference { rustix::fs::stat(path.as_ref()) } else { @@ -112,6 +116,20 @@ impl FileInformation { } } + /// Returns the identity of a symlink target on WASI preview 2. + /// + /// Path-based `stat` on a symlink reports the inode of the link itself, so two paths to + /// the same file compare as different. Statting an open descriptor reports the target. + #[cfg(all(target_os = "wasi", target_env = "p2"))] + fn from_symlink_target_p2(path: &Path) -> Option { + let link = rustix::fs::lstat(path).ok()?; + if rustix::fs::FileType::from_raw_mode(link.st_mode) != rustix::fs::FileType::Symlink { + return None; + } + let file = fs::File::open(path).ok()?; + Self::from_file(&file).ok() + } + pub fn file_size(&self) -> u64 { #[cfg(any(unix, target_os = "wasi"))] { diff --git a/src/uucore/src/lib/mods/error.rs b/src/uucore/src/lib/mods/error.rs index 270bdcb8832..152bd3c3dd5 100644 --- a/src/uucore/src/lib/mods/error.rs +++ b/src/uucore/src/lib/mods/error.rs @@ -509,6 +509,34 @@ pub fn strip_errno(err: &std::io::Error) -> String { msg } +/// Maps the WASI `EBADF` error for a directory to `ErrorKind::IsADirectory`. +/// +/// WASI returns `EBADF` where Unix returns `EISDIR`. This function does nothing on other targets. +pub fn wasi_normalize_open_error(err: std::io::Error) -> std::io::Error { + #[cfg(target_os = "wasi")] + if err.raw_os_error() == Some(8) { + return std::io::Error::new(std::io::ErrorKind::IsADirectory, "Is a directory"); + } + err +} + +/// Maps the WASI error for reading a directory to `ErrorKind::IsADirectory`. +/// +/// The errno depends on the preview version and on who opened the descriptor. +/// WASI defers the directory check from `open` to the first `read`. +/// This function does nothing on other targets. +pub fn wasi_normalize_read_error(err: std::io::Error) -> std::io::Error { + #[cfg(all(target_os = "wasi", target_env = "p1"))] + if matches!(err.raw_os_error(), Some(31 | 8)) { + return std::io::Error::new(std::io::ErrorKind::IsADirectory, "Is a directory"); + } + #[cfg(all(target_os = "wasi", target_env = "p2"))] + if matches!(err.raw_os_error(), Some(29 | 8)) { + return std::io::Error::new(std::io::ErrorKind::IsADirectory, "Is a directory"); + } + err +} + /// Enables the conversion from [`std::io::Error`] to [`UError`] and from [`std::io::Result`] to /// [`UResult`]. pub trait FromIo { diff --git a/tests/by-util/test_cat.rs b/tests/by-util/test_cat.rs index 42ca468bd40..c701000d795 100644 --- a/tests/by-util/test_cat.rs +++ b/tests/by-util/test_cat.rs @@ -200,6 +200,7 @@ fn test_piped_to_dev_null() { } } +#[uutests::wasip2_ignore(StreamWriteGenericIoError)] #[test] #[cfg(any(target_os = "linux", target_os = "freebsd", target_os = "netbsd"))] fn test_piped_to_dev_full() { @@ -653,7 +654,11 @@ fn test_domain_socket() { s.ucmd() .args(&[socket_path]) .fails() - .stderr_contains("No such device or address"); + .stderr_contains(if cfg!(wasi_runner) { + "No such file or directory" + } else { + "No such device or address" + }); } #[test] @@ -800,7 +805,6 @@ fn test_u_ignored() { } } -#[uutests::wasi_ignore(ErrnoMessageMismatch)] #[test] #[cfg(unix)] fn test_write_fast_read_error() { @@ -935,6 +939,7 @@ fn test_write_error_handling() { .stderr_contains("No space left on device"); } +#[uutests::wasip2_ignore(StreamWriteGenericIoError)] #[test] #[cfg(target_os = "linux")] fn test_version_help_dev_full() { diff --git a/tests/by-util/test_cksum.rs b/tests/by-util/test_cksum.rs index 35f34aa3213..2540a29c34c 100644 --- a/tests/by-util/test_cksum.rs +++ b/tests/by-util/test_cksum.rs @@ -712,6 +712,7 @@ fn dev_full() -> std::fs::File { .unwrap() } +#[uutests::wasip2_ignore(StreamWriteGenericIoError)] #[rstest] #[cfg(any(target_os = "linux", target_os = "freebsd", target_os = "netbsd"))] #[case::after_ok(true, "")] @@ -1048,6 +1049,7 @@ fn test_raw_multiple_files() { .stderr_contains("cksum: the --raw option is not supported with multiple files"); } +#[uutests::wasip2_ignore(StreamWriteGenericIoError)] #[test] #[cfg(any(target_os = "linux", target_os = "freebsd", target_os = "netbsd"))] fn test_write_error() { diff --git a/tests/by-util/test_comm.rs b/tests/by-util/test_comm.rs index 6681d423c2b..960885e6d03 100644 --- a/tests/by-util/test_comm.rs +++ b/tests/by-util/test_comm.rs @@ -805,6 +805,7 @@ fn test_c_locale_still_orders_by_bytes() { .stdout_only("a-b\n"); } +#[uutests::wasip2_ignore(StreamWriteGenericIoError)] #[test] #[cfg(target_os = "linux")] fn test_comm_write_error_dev_full() { diff --git a/tests/by-util/test_cp.rs b/tests/by-util/test_cp.rs index cf30fa8fccc..a861f26bd30 100644 --- a/tests/by-util/test_cp.rs +++ b/tests/by-util/test_cp.rs @@ -100,6 +100,7 @@ fn test_cp_stream_to_full() { .stderr_contains("No space"); } +#[uutests::wasip2_ignore(StreamWriteGenericIoError)] #[test] #[cfg(target_os = "linux")] fn test_cp_verbose_write_error_is_reported() { @@ -1328,7 +1329,7 @@ fn test_cp_recursive_dir_applies_umask() { // The umask alone never covers setuid/setgid, so a non-preserving `cp -r` // must clear them on the directories it creates. The sticky bit survives. -#[uutests::wasi_ignore(DirectoryModesUmaskNotFaithful)] +#[uutests::wasi_ignore(NoPermissionBits)] #[test] #[cfg(unix)] fn test_cp_recursive_dir_drops_setuid_setgid() { @@ -3284,6 +3285,7 @@ fn test_cp_conflicting_update() { .stderr_contains("--backup is mutually exclusive with -n or --update=none-fail"); } +#[uutests::wasi_ignore(NoPermissionBits)] #[test] #[cfg(any(target_os = "linux", target_os = "android"))] fn test_cp_reflink_insufficient_permission() { @@ -3302,6 +3304,7 @@ fn test_cp_reflink_insufficient_permission() { } #[cfg(target_os = "linux")] +#[uutests::wasi_ignore(HostPathsNotVisible)] #[test] fn test_closes_file_descriptors() { use rlimit::Resource; @@ -9620,9 +9623,9 @@ fn test_cp_p_preserves_posix_acls() { // `cp -r` without -p only copies the mode bits of the directories it // creates, like GNU; it must not copy their access or default ACLs. // `cp -rp` preserves them, as ACLs are part of the mode. +#[uutests::wasi_ignore(AclXattrPreservationFails)] #[test] #[cfg(target_os = "linux")] -#[cfg_attr(wasi_runner, ignore = "WASI: ACL/xattr syscalls are not implemented")] fn test_cp_r_copies_dir_posix_acls_only_with_p() { use std::process::Command; diff --git a/tests/by-util/test_csplit.rs b/tests/by-util/test_csplit.rs index 303fd5a5d5b..23595093aa7 100644 --- a/tests/by-util/test_csplit.rs +++ b/tests/by-util/test_csplit.rs @@ -1788,6 +1788,7 @@ fn repeat_everything() { } #[cfg(unix)] +#[uutests::wasi_ignore(NoFifo)] #[test] fn test_named_pipe_input_file() { let (at, mut ucmd) = at_and_ucmd!(); @@ -1845,6 +1846,7 @@ fn test_stdin_no_trailing_newline() { .stdout_only("2\n5\n"); } +#[uutests::wasi_ignore(NonUtf8ArgsUnsupported)] #[test] #[cfg(target_os = "linux")] fn test_csplit_non_utf8_paths() { @@ -1858,6 +1860,7 @@ fn test_csplit_non_utf8_paths() { } /// Test write error detection using /dev/full +#[uutests::wasi_ignore(HostPathsNotVisible)] #[test] #[cfg(target_os = "linux")] fn test_write_error_dev_full() { @@ -1874,6 +1877,7 @@ fn test_write_error_dev_full() { } /// Test write error with -k keeps files +#[uutests::wasi_ignore(HostPathsNotVisible)] #[test] #[cfg(target_os = "linux")] fn test_write_error_dev_full_keep_files() { diff --git a/tests/by-util/test_cut.rs b/tests/by-util/test_cut.rs index da1a46cda1e..5abf1671b68 100644 --- a/tests/by-util/test_cut.rs +++ b/tests/by-util/test_cut.rs @@ -1056,8 +1056,9 @@ fn test_emoji_delim() { .stdout_only("🌹\n"); } -#[cfg(target_os = "linux")] +#[uutests::wasip2_ignore(StreamWriteGenericIoError)] #[test] +#[cfg(target_os = "linux")] fn test_failed_write_is_reported() { new_ucmd!() .arg("-d=") diff --git a/tests/by-util/test_dir.rs b/tests/by-util/test_dir.rs index 08e519ea0e4..e6a6c5754c1 100644 --- a/tests/by-util/test_dir.rs +++ b/tests/by-util/test_dir.rs @@ -134,6 +134,7 @@ fn test_version() { .stdout_is(format!("dir {}\n", uucore::crate_version!())); } +#[uutests::wasip2_ignore(StreamWriteGenericIoError)] #[test] #[cfg(target_os = "linux")] fn test_write_error() { diff --git a/tests/by-util/test_expr.rs b/tests/by-util/test_expr.rs index 2157e8c4192..40372cf6086 100644 --- a/tests/by-util/test_expr.rs +++ b/tests/by-util/test_expr.rs @@ -2266,6 +2266,7 @@ expr: non-integer argument } } +#[uutests::wasip2_ignore(StreamWriteGenericIoError)] #[test] #[cfg(any(target_os = "linux", target_os = "freebsd", target_os = "netbsd"))] fn test_exit_with_3_write_error() { diff --git a/tests/by-util/test_factor.rs b/tests/by-util/test_factor.rs index 191270d787a..35e8ad9faa2 100644 --- a/tests/by-util/test_factor.rs +++ b/tests/by-util/test_factor.rs @@ -403,6 +403,7 @@ fn fails_on_invalid_number() { .stdout_contains("12: 2 2 3"); } +#[uutests::wasip2_ignore(StreamWriteGenericIoError)] #[test] #[cfg(any(target_os = "linux", target_os = "freebsd", target_os = "netbsd"))] fn short_circuit_write_error() { diff --git a/tests/by-util/test_false.rs b/tests/by-util/test_false.rs index 8c672c8fa6f..1f15bfe8e29 100644 --- a/tests/by-util/test_false.rs +++ b/tests/by-util/test_false.rs @@ -50,6 +50,7 @@ fn test_conflict() { .no_output(); } +#[uutests::wasip2_ignore(StreamWriteGenericIoError)] #[test] #[cfg(any(target_os = "linux", target_os = "freebsd", target_os = "netbsd"))] fn test_full() { diff --git a/tests/by-util/test_fold.rs b/tests/by-util/test_fold.rs index 011ed6066bd..24a8776f2dc 100644 --- a/tests/by-util/test_fold.rs +++ b/tests/by-util/test_fold.rs @@ -431,8 +431,9 @@ fn test_zero_width_data_line_counts() { ); } -#[cfg(any(target_os = "linux", target_os = "freebsd", target_os = "netbsd"))] +#[uutests::wasip2_ignore(StreamWriteGenericIoError)] #[test] +#[cfg(any(target_os = "linux", target_os = "freebsd", target_os = "netbsd"))] fn test_fold_reports_no_space_left_on_dev_full() { use std::fs::OpenOptions; use std::process::Stdio; diff --git a/tests/by-util/test_head.rs b/tests/by-util/test_head.rs index 0846daa9c3a..273ccc6a08c 100644 --- a/tests/by-util/test_head.rs +++ b/tests/by-util/test_head.rs @@ -1007,8 +1007,9 @@ fn test_all_but_last_lines() { .stdout_is_fixture("lorem_ipsum_backwards_15_lines.expected"); } -#[cfg(any(target_os = "linux", target_os = "freebsd", target_os = "netbsd"))] +#[uutests::wasip2_ignore(StreamWriteGenericIoError)] #[test] +#[cfg(any(target_os = "linux", target_os = "freebsd", target_os = "netbsd"))] fn test_write_to_dev_full() { use std::fs::OpenOptions; diff --git a/tests/by-util/test_ls.rs b/tests/by-util/test_ls.rs index a6b80e2aa89..11084a94f7c 100644 --- a/tests/by-util/test_ls.rs +++ b/tests/by-util/test_ls.rs @@ -13,7 +13,7 @@ )] use regex::Regex; -#[cfg(unix)] +#[cfg(all(unix, not(wasi_runner)))] use rlimit::Resource; #[cfg(not(target_os = "openbsd"))] use std::collections::HashMap; @@ -75,10 +75,11 @@ fn test_directory_in_file() { fn test_name_too_long() { let name = "a".repeat(300); let result = new_ucmd!().arg(&name).fails_with_code(2); - #[cfg(all(unix, not(target_env = "musl")))] + #[cfg(all(unix, not(target_env = "musl"), not(wasi_runner)))] result.stderr_is(format!("ls: cannot access '{name}': File name too long\n")); - // musl spells strerror(ENAMETOOLONG) "Filename too long" - #[cfg(any(not(unix), target_env = "musl"))] + // musl and wasi-libc spell strerror(ENAMETOOLONG) "Filename too long", unlike glibc's + // "File name too long". + #[cfg(any(not(unix), target_env = "musl", wasi_runner))] result .stderr_contains(format!("ls: cannot access '{name}': ")) .stderr_does_not_contain("os error"); @@ -275,6 +276,7 @@ fn get_filesystem_type(scene: &TestScenario, path: &Path) -> String { } #[cfg(all(feature = "truncate", feature = "dd"))] +#[uutests::wasi_ignore(HostPathsNotVisible)] #[test] // FIXME: fix this test for FreeBSD and OpenBSD #[cfg(not(target_os = "openbsd"))] fn test_ls_allocation_size() { @@ -517,6 +519,7 @@ fn test_ls_allocation_size() { } } +#[uutests::wasi_ignore(HostPathsNotVisible)] #[test] fn test_ls_devices() { let scene = TestScenario::new(util_name!()); @@ -1299,6 +1302,7 @@ fn test_ls_long_padding_of_size_column_with_multiple_files() { /// and `.` and `..` being present in `-a` all need to work for the test to pass. /// This test does not really test anything provided by `-l` but the file names and symlinks. #[cfg(all(feature = "ln", feature = "mkdir", feature = "touch"))] +#[uutests::wasi_ignore(NoPermissionBits)] #[test] #[cfg(all(feature = "ln", feature = "mkdir", feature = "touch"))] #[allow(clippy::items_after_statements)] @@ -1543,6 +1547,7 @@ fn test_ls_long_symlink_color() { /// We use "--color=always" as the colors are the same regardless of the color option being "auto" or "always" /// tests whether the specific color of the target and the `dangling_symlink` are equal and checks /// whether checks whether ls outputs the correct path for the symlink and the file it points to and applies the color code to it. +#[uutests::wasi_ignore(SymlinkHardlinkCaps)] #[test] fn test_ls_long_dangling_symlink_color() { let ts = TestScenario::new(util_name!()); @@ -1563,7 +1568,7 @@ fn test_ls_long_dangling_symlink_color() { // Ensure dangling link name uses `or=` and target uses `mi=`. let name_regex = Regex::new(r"(?:\x1b\[[0-9;]*m)*\x1b\[([0-9;]*)mdir1/dangling_symlink\x1b\[0m").unwrap(); - let target_path = regex::escape(&at.plus_as_string("foo")); + let target_path = regex::escape(&format!("..{}foo", std::path::MAIN_SEPARATOR)); let target_pattern = format!(r"(?:\x1b\[[0-9;]*m)*\x1b\[([0-9;]*)m{target_path}\x1b\[0m"); let target_regex = Regex::new(&target_pattern).unwrap(); @@ -1582,6 +1587,7 @@ fn test_ls_long_dangling_symlink_color() { } /// Mirrors GNU `tests/ls/ls-misc.pl::sl-dangle3`. +#[uutests::wasi_ignore(SymlinkHardlinkCaps)] #[test] fn test_ls_dangling_symlink_or_and_missing_colors() { let ts = TestScenario::new(util_name!()); @@ -1647,6 +1653,7 @@ fn test_ls_symlink_to_dir_with_mi_colors() { } /// Mirrors GNU `tests/ls/ls-misc.pl::sl-dangle4`. +#[uutests::wasi_ignore(SymlinkHardlinkCaps)] #[test] fn test_ls_dangling_symlink_ln_or_priority() { let ts = TestScenario::new(util_name!()); @@ -1676,6 +1683,7 @@ fn test_ls_dangling_symlink_ln_or_priority() { } /// Mirrors GNU `tests/ls/ls-misc.pl::sl-dangle5`. +#[uutests::wasi_ignore(SymlinkHardlinkCaps)] #[test] fn test_ls_dangling_symlink_ln_and_missing_colors() { let ts = TestScenario::new(util_name!()); @@ -1794,6 +1802,7 @@ fn test_ls_directory_dangling_symlink_uses_ln_when_or_blank() { ); } +#[uutests::wasi_ignore(NoPermissionBits)] #[test] #[cfg(not(target_os = "openbsd"))] fn test_ls_long_total_size() { @@ -2006,6 +2015,7 @@ fn test_ls_oneline() { } } +#[uutests::wasi_ignore(SymlinkHardlinkCaps)] #[test] fn test_ls_deref() { let scene = TestScenario::new(util_name!()); @@ -2272,6 +2282,7 @@ fn test_ls_order_size() { result.stdout_only("test-1\ntest-2\ntest-3\ntest-4\n"); } +#[uutests::wasi_ignore(UnsupportedStdApi)] #[test] fn test_ls_long_ctime() { let scene = TestScenario::new(util_name!()); @@ -2315,6 +2326,7 @@ fn test_ls_order_birthtime() { assert_eq!(result.stdout_str(), "test-birthtime-2 test-birthtime-1\n"); } +#[uutests::wasi_ignore(NoLocaleData)] #[test] fn test_ls_time_styles() { let scene = TestScenario::new(util_name!()); @@ -2681,6 +2693,7 @@ fn test_ls_order_time_breaks_ties_by_name() { } } +#[uutests::wasi_ignore(HostSystemStateDiffers)] #[test] fn test_ls_order_time() { let scene = TestScenario::new(util_name!()); @@ -2983,6 +2996,7 @@ mod quoting { // locale/clocale quoting styles use Unicode quotation marks U+2018/U+2019 // and must not escape embedded apostrophes or double quotes; in the C // locale they fall back to ASCII single/double quotes. + #[uutests::wasi_ignore(NoLocaleData)] #[test] fn test_ls_quoting_locale_utf8() { if !is_locale_available("en_US.UTF-8") { @@ -3502,6 +3516,7 @@ mod quoting { /// This test creates files with an UTF-8 encoded name and verify that it /// gets escaped depending on the used locale. #[cfg(not(any(target_vendor = "apple", windows, target_os = "openbsd")))] + #[uutests::wasi_ignore(NoLocaleData)] #[test] fn test_locale_aware_quoting() { let cases: &[(&[u8], _, _, &[&str])] = &[ @@ -3564,6 +3579,7 @@ mod quoting { } } + #[uutests::wasi_ignore(NoLocaleData)] #[test] fn test_c_dot_utf8_renders_utf8() { let scene = TestScenario::new(util_name!()); @@ -3650,6 +3666,7 @@ fn test_ls_color() { } #[cfg(unix)] +#[uutests::wasi_ignore(UnsupportedStdApi)] #[test] #[cfg(not(feature = "selinux"))] // Disabled on the SELinux runner for now @@ -3693,6 +3710,7 @@ fn test_ls_inode() { assert_eq!(inode_short, inode_long); } +#[uutests::wasi_ignore(NoFifo)] #[test] #[cfg(not(windows))] fn test_ls_indicator_style() { @@ -3790,8 +3808,9 @@ fn test_ls_indicator_style() { } } -#[test] #[cfg(not(windows))] +#[uutests::wasi_ignore(SymlinkHardlinkCaps)] +#[test] fn test_ls_indicator_style_symlink_target_long() { let scene = TestScenario::new(util_name!()); let at = &scene.fixtures; @@ -3810,7 +3829,7 @@ fn test_ls_indicator_style_symlink_target_long() { .succeeds() .stdout_contains("dir_link -> ") .stdout_does_not_contain("dir_link@ -> ") - .stdout_contains("/dir/"); + .stdout_contains(" dir/"); } #[test] @@ -4458,6 +4477,7 @@ fn test_ls_invalid_quoting_style_env_var_warns() { } #[cfg(unix)] +#[uutests::wasi_ignore(NonUtf8ArgsUnsupported)] #[test] fn test_ls_invalid_quoting_style_env_var_non_utf8() { let scene = TestScenario::new(util_name!()); @@ -4910,6 +4930,7 @@ fn test_ls_ignore_negation() { .stdout_does_not_contain("boy"); } +#[uutests::wasi_ignore(SymlinkHardlinkCaps)] #[test] fn test_ls_directory() { let scene = TestScenario::new(util_name!()); @@ -4940,6 +4961,7 @@ fn test_ls_directory() { .stdout_is("nested_file\n"); } +#[uutests::wasi_ignore(SymlinkHardlinkCaps)] #[test] fn test_ls_deref_command_line() { let scene = TestScenario::new(util_name!()); @@ -5006,6 +5028,7 @@ fn test_ls_deref_command_line() { .stdout_contains("sym_file ->"); } +#[uutests::wasi_ignore(SymlinkHardlinkCaps)] #[test] fn test_ls_deref_command_line_dir() { let scene = TestScenario::new(util_name!()); @@ -5182,6 +5205,7 @@ fn test_ls_sort_extension() { ); } +#[uutests::wasi_ignore(HostPathsNotVisible)] #[test] fn test_ls_path() { let scene = TestScenario::new(util_name!()); @@ -5224,6 +5248,7 @@ fn test_ls_path() { .stdout_is(expected_stdout); } +#[uutests::wasi_ignore(UnsupportedStdApi)] #[test] fn test_ls_dangling_symlinks() { let scene = TestScenario::new(util_name!()); @@ -5305,6 +5330,7 @@ fn test_ls_dangling_symlinks() { } } +#[uutests::wasi_ignore(SymlinkHardlinkCaps)] #[test] fn test_ls_long_self_referential_dir_lists_contents() { // `ls -l` for a directory referenced via `.` (e.g. run from inside a symlinked @@ -5767,6 +5793,7 @@ fn test_tabsize_formatting() { } #[cfg(all(unix, not(target_os = "android")))] +#[uutests::wasi_ignore(HostPathsNotVisible)] #[test] fn test_device_number() { use std::fs::{metadata, read_dir}; @@ -5797,6 +5824,7 @@ fn test_device_number() { .stdout_contains(major_minor_str); } +#[uutests::wasi_ignore(NonUtf8ArgsUnsupported)] #[test] #[cfg(target_os = "linux")] fn test_invalid_utf8() { @@ -5878,6 +5906,7 @@ fn test_ls_dired_quoting_style_name() { } } +#[uutests::wasi_ignore(GuestRootPathResolution)] #[test] fn test_ls_dired_hyperlink() { // we will have link but not the DIRED output @@ -6539,6 +6568,7 @@ fn test_ls_cf_output_should_be_delimited_by_tab() { } #[cfg(all(unix, feature = "dd"))] +#[uutests::wasi_ignore(HostPathsNotVisible)] #[test] #[cfg(not(target_os = "openbsd"))] fn test_posixly_correct_and_block_size_env_vars() { @@ -6593,6 +6623,7 @@ fn test_posixly_correct_and_block_size_env_vars() { } #[cfg(all(unix, feature = "dd"))] +#[uutests::wasi_ignore(HostPathsNotVisible)] #[test] #[cfg(not(target_os = "openbsd"))] fn test_posixly_correct_and_block_size_env_vars_with_k() { @@ -6643,8 +6674,9 @@ fn test_posixly_correct_and_block_size_env_vars_with_k() { .stdout_contains(" 1024 "); } -#[test] #[cfg(unix)] +#[uutests::wasi_ignore(NoBlockSizeSupport)] +#[test] fn test_ls_block_size_rounds_up() { // A block that is only partly used still occupies a whole block, so // scaling an allocation to the block size rounds up. @@ -6697,6 +6729,7 @@ fn test_ls_invalid_block_size() { } #[cfg(all(unix, feature = "dd"))] +#[uutests::wasi_ignore(HostPathsNotVisible)] #[test] #[cfg(not(target_os = "openbsd"))] fn test_ls_invalid_block_size_in_env_var() { @@ -6744,6 +6777,7 @@ fn test_ls_invalid_block_size_in_env_var() { } #[cfg(all(unix, feature = "dd"))] +#[uutests::wasi_ignore(HostPathsNotVisible)] #[test] #[cfg(not(target_os = "openbsd"))] fn test_ls_block_size_override() { @@ -6856,6 +6890,7 @@ fn test_ls_block_size_override_self() { new_ucmd!().arg("--si").arg("--si").succeeds(); } +#[uutests::wasi_ignore(GuestRootPathResolution)] #[test] fn test_ls_hyperlink() { let scene = TestScenario::new(util_name!()); @@ -6933,6 +6968,7 @@ fn test_ls_hyperlink_encode_link() { } // spell-checker:enable +#[uutests::wasi_ignore(GuestRootPathResolution)] #[test] fn test_ls_hyperlink_dirs() { let scene = TestScenario::new(util_name!()); @@ -6977,6 +7013,7 @@ fn test_ls_hyperlink_dirs() { ); } +#[uutests::wasi_ignore(GuestRootPathResolution)] #[test] fn test_ls_hyperlink_recursive_dirs() { let scene = TestScenario::new(util_name!()); @@ -7020,6 +7057,7 @@ fn test_ls_hyperlink_recursive_dirs() { ); } +#[uutests::wasi_ignore(SymlinkHardlinkCaps)] #[test] fn test_ls_hyperlink_symlink_target_handling() { let scene = TestScenario::new(util_name!()); @@ -7174,6 +7212,7 @@ fn test_term_colorterm() { } #[cfg(all(unix, not(target_vendor = "apple")))] +#[uutests::wasi_ignore(NoPermissionBits)] #[test] fn test_acl_display() { use std::process::Command; @@ -7270,6 +7309,7 @@ fn test_user_xattr_is_not_acl() { // On macOS the ACL is not an xattr, and most files carry xattrs anyway, so // `+` comes from the ACL API (#15273). #[cfg(target_os = "macos")] +#[uutests::wasi_ignore(AclXattrPreservationFails)] #[test] fn test_acl_display_macos() { use std::process::Command; @@ -7298,6 +7338,7 @@ fn test_acl_display_macos() { // Regression test for https://github.com/uutils/coreutils/issues/10980 // Each file with an ACL must not inflate the link-count column width. #[cfg(all(unix, not(target_vendor = "apple")))] +#[uutests::wasi_ignore(NoPermissionBits)] #[test] fn test_acl_padding_not_inflated() { use std::process::Command; @@ -7350,6 +7391,7 @@ fn test_acl_padding_not_inflated() { // output and file names that don't have a designated color (unless the FILE // setting is also configured). #[cfg(unix)] +#[uutests::wasi_ignore(NoPermissionBits)] #[test] #[cfg(not(feature = "selinux"))] // Disabled on the SELinux runner for now @@ -7765,6 +7807,7 @@ fn test_unknown_format_specifier() { } #[cfg(all(unix, not(target_vendor = "apple")))] +#[uutests::wasi_ignore(NoPermissionBits)] #[test] fn test_acl_display_symlink() { use std::process::Command; @@ -7936,6 +7979,7 @@ fn test_ls_time_style_iso_recent_and_older() { ); } +#[uutests::wasi_ignore(NoLocaleData)] #[test] fn test_ls_time_style_posix_locale_override() { let scene = TestScenario::new(util_name!()); @@ -8327,6 +8371,7 @@ fn test_f_flag_combined_behavior() { assert!(!result.contains("\x1b[")); } +#[uutests::wasi_ignore(NoPermissionBits)] #[test] fn test_f_with_long_format() { // Test that -f works with long format (-l) @@ -8349,6 +8394,7 @@ fn test_f_with_long_format() { assert!(result.contains("-rw")); } +#[uutests::wasi_ignore(HostPathsNotVisible)] #[test] #[cfg(target_os = "linux")] fn test_ls_proc_self_fd_no_errors() { @@ -8365,7 +8411,7 @@ fn test_ls_proc_self_fd_no_errors() { } #[test] -#[cfg(unix)] +#[cfg(all(unix, not(wasi_runner)))] fn test_ls_recursive_no_fd_leak() { let scene = TestScenario::new(util_name!()); let at = &scene.fixtures; @@ -8385,6 +8431,7 @@ fn test_ls_recursive_no_fd_leak() { .no_stderr(); } +#[uutests::wasi_ignore(NonUtf8ArgsUnsupported)] #[test] #[cfg(all(unix, not(target_vendor = "apple")))] fn test_ls_non_utf8_hidden() { @@ -8512,6 +8559,7 @@ fn test_dired_write_error() { } #[cfg(unix)] +#[uutests::wasi_ignore(SymlinkHardlinkCaps)] #[test] fn test_ls_long_stat_failure_is_reported() { use rustix::process::geteuid; @@ -8730,8 +8778,9 @@ fn test_dereferenced_metadata_is_cached(#[case] args: &[&str], #[case] path: &st assert_eq!(count, 1, "expected one metadata lookup of {path}: {trace}"); } -#[rstest::rstest] #[cfg(unix)] +#[uutests::wasi_ignore(SymlinkHardlinkCaps)] +#[rstest::rstest] fn test_dereferenced_context_reports_error_once( #[values("-LZ", "-lL", "-lLZ")] flag: &str, #[values(false, true)] command_line: bool, diff --git a/tests/by-util/test_mktemp.rs b/tests/by-util/test_mktemp.rs index 9f652933c76..25233513bce 100644 --- a/tests/by-util/test_mktemp.rs +++ b/tests/by-util/test_mktemp.rs @@ -604,7 +604,7 @@ fn test_respect_template_directory() { } #[cfg(unix)] -#[uutests::wasi_ignore(PathCreateDirectoryNoModeParam)] +#[uutests::wasi_ignore(NoPermissionBits)] #[test] fn test_directory_permissions() { let (at, mut ucmd) = at_and_ucmd!(); @@ -1318,6 +1318,7 @@ fn test_mktemp_hidden_file_single_dot() { // When the name cannot be printed the caller never learns it, so the file must // not be left behind for nothing to clean up. +#[uutests::wasip2_ignore(StreamWriteGenericIoError)] #[test] #[cfg(target_os = "linux")] fn test_write_error_removes_the_temporary_file() { @@ -1336,6 +1337,7 @@ fn test_write_error_removes_the_temporary_file() { assert!(leftovers.is_empty(), "left behind: {leftovers:?}"); } +#[uutests::wasip2_ignore(StreamWriteGenericIoError)] #[test] #[cfg(target_os = "linux")] fn test_write_error_removes_the_temporary_directory() { diff --git a/tests/by-util/test_mv.rs b/tests/by-util/test_mv.rs index 1eb9349949f..b341e229a66 100644 --- a/tests/by-util/test_mv.rs +++ b/tests/by-util/test_mv.rs @@ -1515,7 +1515,7 @@ fn test_mv_verbose() { )); } -#[uutests::wasi_ignore(PathCreateDirectoryNoModeParam)] +#[uutests::wasi_ignore(NoPermissionBits)] #[test] #[cfg(any(target_os = "linux", target_os = "android"))] // mkdir does not support -m on windows. Freebsd doesn't return a permission error either. #[cfg(feature = "mkdir")] @@ -1766,7 +1766,6 @@ fn test_mv_seen_multiple_files_to_directory() { assert!(at.plus("c").join("g").exists()); } -#[uutests::wasi_ignore(ErrnoMessageMismatch)] #[test] fn test_mv_dir_into_file_where_both_are_files() { let scene = TestScenario::new(util_name!()); diff --git a/tests/by-util/test_nice.rs b/tests/by-util/test_nice.rs index c1d9c112789..19f3b6c63ed 100644 --- a/tests/by-util/test_nice.rs +++ b/tests/by-util/test_nice.rs @@ -8,18 +8,24 @@ #[cfg(unix)] use uutests::new_ucmd; -#[test] #[cfg(unix)] #[cfg(not(target_os = "android"))] +#[test] fn test_get_current_niceness() { - // Test that the nice command with no arguments returns the default nice value + // Test that the nice command with no arguments returns the default nice value. + // WASI has no getpriority syscall, so nice always reports a fixed niceness of 0 + // there, regardless of the host's actual value. + #[cfg(wasi_runner)] + let nice = 0; + #[cfg(not(wasi_runner))] let nice = rustix::process::getpriority_process(None).unwrap(); new_ucmd!().succeeds().stdout_is(format!("{nice}\n")); } -#[test] #[cfg(unix)] #[cfg(not(target_os = "android"))] +#[uutests::wasi_ignore(NoSubprocessSpawning)] +#[test] fn test_nice_adj_negative() { // This assumes the test suite is run as a normal (non-root) user, and as // such attempting to set a negative niceness value will be rejected by @@ -41,14 +47,16 @@ fn test_adjustment_with_no_command_should_error() { .usage_error("A command must be given with an adjustment."); } -#[test] #[cfg(unix)] +#[uutests::wasi_ignore(NoSubprocessSpawning)] +#[test] fn test_command_with_no_adjustment() { new_ucmd!().args(&["echo", "a"]).succeeds().stdout_is("a\n"); } -#[test] #[cfg(unix)] +#[uutests::wasi_ignore(NoSubprocessSpawning)] +#[test] fn test_command_with_no_args() { new_ucmd!() .args(&["-n", "19", "echo"]) @@ -56,8 +64,9 @@ fn test_command_with_no_args() { .stdout_is("\n"); } -#[test] #[cfg(unix)] +#[uutests::wasi_ignore(NoSubprocessSpawning)] +#[test] fn test_command_with_args() { new_ucmd!() .args(&["-n", "19", "echo", "a", "b", "c"]) @@ -65,8 +74,9 @@ fn test_command_with_args() { .stdout_is("a b c\n"); } -#[test] #[cfg(unix)] +#[uutests::wasi_ignore(NoSubprocessSpawning)] +#[test] fn test_command_where_command_takes_n_flag() { new_ucmd!() .args(&["-n", "19", "echo", "-n", "a"]) @@ -74,8 +84,9 @@ fn test_command_where_command_takes_n_flag() { .stdout_is("a"); } -#[test] #[cfg(unix)] +#[uutests::wasi_ignore(NonUtf8ArgsUnsupported)] +#[test] fn test_command_with_non_utf8_args() { use std::ffi::OsStr; use std::os::unix::ffi::OsStrExt; @@ -87,8 +98,9 @@ fn test_command_with_non_utf8_args() { .stdout_only_bytes(b"a\xffb\n"); } -#[test] #[cfg(unix)] +#[uutests::wasi_ignore(NoSubprocessSpawning)] +#[test] fn test_non_utf8_command_not_found() { use std::ffi::OsStr; use std::os::unix::ffi::OsStrExt; @@ -127,8 +139,9 @@ fn test_invalid_argument() { new_ucmd!().arg("--invalid").fails_with_code(125); } -#[test] #[cfg(unix)] +#[uutests::wasi_ignore(NoSubprocessSpawning)] +#[test] fn test_bare_adjustment() { new_ucmd!() .args(&["-1", "echo", "-n", "a"]) @@ -148,8 +161,9 @@ fn test_trailing_empty_adjustment() { ); } -#[test] #[cfg(unix)] +#[uutests::wasi_ignore(NoSubprocessSpawning)] +#[test] fn test_nice_huge() { new_ucmd!() .args(&[ @@ -161,15 +175,17 @@ fn test_nice_huge() { .no_stdout(); } -#[test] #[cfg(unix)] +#[uutests::wasi_ignore(NoSubprocessSpawning)] +#[test] fn test_nice_huge_negative() { new_ucmd!().args(&["-n", "-9999999999", "true"]).succeeds(); //.stderr_contains("Permission denied"); Depending on platform? } -#[test] #[cfg(unix)] +#[uutests::wasi_ignore(NoSubprocessSpawning)] +#[test] fn test_sign_middle() { new_ucmd!() .args(&["-n", "-2+4", "true"]) diff --git a/tests/by-util/test_numfmt.rs b/tests/by-util/test_numfmt.rs index 69840439c7b..638ad1431e4 100644 --- a/tests/by-util/test_numfmt.rs +++ b/tests/by-util/test_numfmt.rs @@ -2138,6 +2138,7 @@ mod field_diagnostics { } #[cfg(target_os = "linux")] +#[uutests::wasip2_ignore(StreamWriteGenericIoError)] #[test] fn test_write_error_is_reported_and_fatal() { // A full output device must be diagnosed, not panic, whatever --invalid says. diff --git a/tests/by-util/test_od.rs b/tests/by-util/test_od.rs index b665b8b99d1..b4825edef46 100644 --- a/tests/by-util/test_od.rs +++ b/tests/by-util/test_od.rs @@ -1558,6 +1558,7 @@ fn test_od_eintr_handling() { } // Regression test: od should handle write errors to /dev/full without aborting. +#[uutests::wasip2_ignore(StreamWriteGenericIoError)] #[test] #[cfg(target_os = "linux")] fn test_write_error_dev_full() { @@ -1591,7 +1592,6 @@ fn test_hex_lowercase() { )); } -#[uutests::wasi_ignore(ErrnoMessageMismatch)] #[test] #[cfg(not(windows))] fn test_is_a_directory() { diff --git a/tests/by-util/test_paste.rs b/tests/by-util/test_paste.rs index 667988e2110..f4c93ffe994 100644 --- a/tests/by-util/test_paste.rs +++ b/tests/by-util/test_paste.rs @@ -619,7 +619,6 @@ fn test_missing_file_is_named_in_error() { .stderr_only("paste: missing.txt: No such file or directory\n"); } -#[uutests::wasi_ignore(ErrnoMessageMismatch)] #[test] #[cfg(not(windows))] fn test_read_error_names_the_file() { diff --git a/tests/by-util/test_printf.rs b/tests/by-util/test_printf.rs index 25ffd9a4a2a..a26e15199e4 100644 --- a/tests/by-util/test_printf.rs +++ b/tests/by-util/test_printf.rs @@ -1073,6 +1073,7 @@ fn non_utf_8_input() { } #[cfg(target_os = "linux")] +#[uutests::wasip2_ignore(StreamWriteGenericIoError)] #[test] fn test_write_error_omits_errno() { let dev_full = std::fs::File::create("/dev/full").expect("failed to open /dev/full"); @@ -1167,6 +1168,7 @@ fn test_q_string_c1_control_char_with_quote() { // Output with no trailing newline stays in the buffer until the process exits, // so the failure is only visible when it is flushed. +#[uutests::wasip2_ignore(StreamWriteGenericIoError)] #[test] #[cfg(target_os = "linux")] fn test_unterminated_write_error_is_reported() { diff --git a/tests/by-util/test_ptx.rs b/tests/by-util/test_ptx.rs index 26943607e6e..a57bbab3635 100644 --- a/tests/by-util/test_ptx.rs +++ b/tests/by-util/test_ptx.rs @@ -238,6 +238,7 @@ fn test_format() { } #[cfg(target_os = "linux")] +#[uutests::wasip2_ignore(StreamWriteGenericIoError)] #[test] fn test_failed_write_is_reported() { new_ucmd!() diff --git a/tests/by-util/test_pwd.rs b/tests/by-util/test_pwd.rs index c12b7f69438..5291976b2ab 100644 --- a/tests/by-util/test_pwd.rs +++ b/tests/by-util/test_pwd.rs @@ -16,12 +16,14 @@ fn test_invalid_arg() { new_ucmd!().arg("--definitely-invalid").fails_with_code(1); } +#[uutests::wasi_ignore(GuestRootPathResolution)] #[test] fn test_default() { let (at, mut ucmd) = at_and_ucmd!(); ucmd.succeeds().stdout_is(at.root_dir_resolved() + "\n"); } +#[uutests::wasi_ignore(GuestRootPathResolution)] #[test] fn test_ignores_non_option_arguments() { // GNU pwd ignores non-option operands, warning on stderr but exiting 0. diff --git a/tests/by-util/test_rm.rs b/tests/by-util/test_rm.rs index 3acad56c46e..7d8464af9b6 100644 --- a/tests/by-util/test_rm.rs +++ b/tests/by-util/test_rm.rs @@ -522,6 +522,7 @@ fn test_force_then_interactive_no_operand() { } } +#[uutests::wasi_ignore(TrailingSlashOnRemoveRejected)] #[test] fn test_verbose_slash() { let (at, mut ucmd) = at_and_ucmd!(); @@ -946,8 +947,9 @@ fn test_remove_inaccessible_dir() { assert!(!at.dir_exists(dir_1)); } -#[test] #[cfg(not(windows))] +#[uutests::wasi_ignore(SandboxRootAliasesGuestCwd)] +#[test] fn test_current_or_parent_dir_rm4() { let ts = TestScenario::new(util_name!()); let at = &ts.fixtures; @@ -1179,6 +1181,7 @@ fn test_only_first_error_recursive() { } #[cfg(not(windows))] +#[uutests::wasi_ignore(NoPermissionBits)] #[test] fn test_unreadable_and_nonempty_dir() { let (at, mut ucmd) = at_and_ucmd!(); @@ -1193,6 +1196,7 @@ fn test_unreadable_and_nonempty_dir() { } #[cfg(not(windows))] +#[uutests::wasi_ignore(NoPermissionBits)] #[test] fn test_recursive_remove_unreadable_subdir() { // Regression test for https://github.com/uutils/coreutils/issues/10966 @@ -1233,6 +1237,7 @@ fn test_inaccessible_dir_nonempty() { } #[cfg(not(windows))] +#[uutests::wasi_ignore(NoPermissionBits)] #[test] fn test_inaccessible_dir_interactive() { let (at, mut ucmd) = at_and_ucmd!(); @@ -1565,6 +1570,7 @@ fn test_symlink_to_readonly_no_prompt() { /// Test that --preserve-root properly detects symlinks pointing to root. #[cfg(unix)] +#[uutests::wasi_ignore(AbsoluteSymlinkTargetsUnfollowable)] #[test] fn test_preserve_root_symlink_to_root() { let (at, mut ucmd) = at_and_ucmd!(); @@ -1587,6 +1593,7 @@ fn test_preserve_root_symlink_to_root() { /// Test that the "same as '/'" error escapes control characters in the name. #[cfg(unix)] +#[uutests::wasi_ignore(AbsoluteSymlinkTargetsUnfollowable)] #[test] fn test_preserve_root_symlink_to_root_escapes_name() { let (at, mut ucmd) = at_and_ucmd!(); @@ -1603,6 +1610,7 @@ fn test_preserve_root_symlink_to_root_escapes_name() { /// Test that --preserve-root properly detects nested symlinks pointing to root. #[cfg(unix)] +#[uutests::wasi_ignore(AbsoluteSymlinkTargetsUnfollowable)] #[test] fn test_preserve_root_nested_symlink_to_root() { let (at, mut ucmd) = at_and_ucmd!(); diff --git a/tests/by-util/test_rmdir.rs b/tests/by-util/test_rmdir.rs index f6ce53ba946..19453941a2b 100644 --- a/tests/by-util/test_rmdir.rs +++ b/tests/by-util/test_rmdir.rs @@ -61,6 +61,7 @@ fn test_rmdir_empty_directory_with_parents() { assert!(!at.dir_exists(DIR)); } +#[uutests::wasip2_ignore(StreamWriteGenericIoError)] #[test] #[cfg(target_os = "linux")] fn test_rmdir_verbose_write_error() { @@ -89,6 +90,7 @@ fn test_rmdir_verbose_write_error() { assert!(at.dir_exists("nonempty/child")); } +#[uutests::wasip2_ignore(StreamWriteGenericIoError)] #[test] #[cfg(target_os = "linux")] fn test_rmdir_verbose_write_error_with_removal_error() { diff --git a/tests/by-util/test_seq.rs b/tests/by-util/test_seq.rs index 16b06880e4c..f5bf674fca8 100644 --- a/tests/by-util/test_seq.rs +++ b/tests/by-util/test_seq.rs @@ -263,6 +263,7 @@ fn test_width_invalid_float() { .usage_error("invalid floating point argument: '1e2.3'"); } +#[uutests::wasi_ignore(NoSubprocessSpawning)] #[test] #[cfg(unix)] fn test_sigpipe_ignored_reports_write_error() { @@ -327,6 +328,7 @@ fn test_separator_and_terminator() { .stdout_is("2\\n3\\n4\\n5\\n6\n"); } +#[uutests::wasi_ignore(NonUtf8ArgsUnsupported)] #[test] #[cfg(unix)] fn test_separator_non_utf8() { @@ -350,6 +352,7 @@ fn test_separator_non_utf8() { } } +#[uutests::wasi_ignore(NonUtf8ArgsUnsupported)] #[test] #[cfg(unix)] fn test_terminator_non_utf8() { @@ -728,6 +731,7 @@ fn test_width_floats() { /// Test infinite sequences - these produce endless output, so we check they start correctly /// and terminate with SIGPIPE on Unix (or succeed on non-Unix where pipe behavior differs). +#[uutests::wasi_ignore(NoPipeSignalSupport)] #[rstest] #[case::neg_inf( &["--", "-inf", "0"], @@ -765,9 +769,10 @@ fn test_infinite_sequence(#[case] args: &[&str], #[case] expected_start: &[u8]) let result = new_ucmd!() .args(args) .run_stdout_starts_with(expected_start); - #[cfg(unix)] + // WASI and Windows have no signals, so only check that the process succeeded. + #[cfg(all(unix, not(wasi_runner)))] result.signal_name_is("PIPE"); - #[cfg(not(unix))] + #[cfg(any(not(unix), wasi_runner))] result.success(); } diff --git a/tests/by-util/test_shred.rs b/tests/by-util/test_shred.rs index 4426ba70fe4..65bb8f897a1 100644 --- a/tests/by-util/test_shred.rs +++ b/tests/by-util/test_shred.rs @@ -666,7 +666,6 @@ fn test_shred_dash_remove_truncates_but_does_not_unlink_stdout() { } } -#[uutests::wasi_ignore(StdioHandlesOpaque)] #[test] #[cfg(unix)] fn test_shred_dash_rejects_stdout_pipe() { diff --git a/tests/by-util/test_sort.rs b/tests/by-util/test_sort.rs index bd4b2e54bde..1c4ef870bd1 100644 --- a/tests/by-util/test_sort.rs +++ b/tests/by-util/test_sort.rs @@ -73,8 +73,8 @@ fn test_buffer_sizes() { } } +#[uutests::wasi_ignore(AutomaticBufferSizeDiffers)] #[test] -#[cfg(not(target_os = "wasi"))] fn test_buffer_size_limits_both_chunks() { let line = format!("{}\n", "b".repeat(1022)); let input = line.repeat(1200); @@ -570,9 +570,9 @@ fn test_random_source_reads_only_the_salt_length() { assert_eq!(from_16, from_longer); } -#[test] -#[uutests::wasi_ignore(NoFifo)] #[cfg(unix)] +#[uutests::wasi_ignore(NoFifo)] +#[test] fn test_random_source_pipe_only_needs_16_bytes() { use std::io::Write; use uutests::util_name; @@ -841,9 +841,9 @@ fn month_sort_input_expected(months: &[String]) -> (String, String) { (input, expected) } -#[test] #[cfg(unix)] #[uutests::wasi_ignore(NoLocaleData)] +#[test] fn test_month_sort_french_locale() { let locale = "fr_FR.UTF-8"; if !is_locale_available(locale) { @@ -885,9 +885,9 @@ fn test_month_sort_french_locale() { .stdout_is(expected); } -#[test] #[cfg(unix)] #[uutests::wasi_ignore(NoLocaleData)] +#[test] fn test_month_sort_hungarian_locale() { let locale = "hu_HU.UTF-8"; if !is_locale_available(locale) { @@ -929,9 +929,9 @@ fn test_month_sort_hungarian_locale() { /// Test that embedded blanks in month names cause a non-match (GNU compat). /// E.g. "av ril" should NOT match "avril" — GNU treats it as unknown. -#[test] #[cfg(unix)] #[uutests::wasi_ignore(NoLocaleData)] +#[test] fn test_month_sort_french_embedded_blanks() { let locale = "fr_FR.UTF-8"; if !is_locale_available(locale) { @@ -994,9 +994,9 @@ fn test_month_sort_french_embedded_blanks() { .stdout_is(expected); } -#[test] #[cfg(unix)] #[uutests::wasi_ignore(NoLocaleData)] +#[test] fn test_month_sort_japanese_locale() { let locale = "ja_JP.UTF-8"; if !is_locale_available(locale) { @@ -1381,8 +1381,8 @@ fn test_unterminated_file_not_fused_across_chunk_boundary() { } } -#[test] #[uutests::wasi_ignore(NoThreadSpawning)] +#[test] fn test_merge_interleaved() { new_ucmd!() .arg("-m") @@ -1393,8 +1393,8 @@ fn test_merge_interleaved() { .stdout_only_fixture("merge_ints_interleaved.expected"); } -#[test] #[uutests::wasi_ignore(NoThreadSpawning)] +#[test] fn test_merge_preserves_long_lines() { use std::fmt::Write; @@ -1452,9 +1452,9 @@ fn test_ext_sort_preserves_long_lines() { // Regression test: a failing write must not take the merge reader thread down with it. // The write error used to propagate straight out of `write_all_to`, dropping the chunk // receivers while the reader was still sending, and `chunks::read` unwraps that send. -#[test] #[cfg(target_os = "linux")] #[uutests::wasi_ignore(NoThreadSpawning)] +#[test] fn test_merge_write_error_does_not_panic() { use std::fs::File; @@ -1521,9 +1521,9 @@ fn test_spill_write_error_does_not_panic() { // A read error must be reported with context and without the raw io::Error suffix. // It used to print `sort: Input/output error (os error 5)`. +#[cfg(target_os = "linux")] #[uutests::wasi_ignore(HostPathsNotVisible)] #[test] -#[cfg(target_os = "linux")] fn test_read_error_message() { // Reading /proc/self/mem from offset 0 fails with EIO. let result = new_ucmd!().arg("/proc/self/mem").fails_with_code(2); @@ -1554,8 +1554,8 @@ fn test_merge_flush_error_is_reported() { .stderr_is("sort: write failed: 'standard output': No space left on device\n"); } -#[test] #[uutests::wasi_ignore(NoThreadSpawning)] +#[test] fn test_merge_unique() { new_ucmd!() .arg("-m") @@ -1570,8 +1570,8 @@ fn test_merge_unique() { .stdout_only_fixture("merge_ints_interleaved.expected"); } -#[test] #[uutests::wasi_ignore(NoThreadSpawning)] +#[test] fn test_merge_stable() { new_ucmd!() .arg("-m") @@ -1583,8 +1583,8 @@ fn test_merge_stable() { .stdout_only_fixture("merge_stable.expected"); } -#[test] #[uutests::wasi_ignore(NoThreadSpawning)] +#[test] fn test_merge_reversed() { new_ucmd!() .arg("-m") @@ -1864,9 +1864,9 @@ fn test_compress() { .stdout_only_fixture("ext_sort.expected"); } -#[test] #[cfg(any(target_os = "linux", target_os = "android"))] #[uutests::wasi_ignore(NoThreadSpawning)] +#[test] fn test_compress_merge() { new_ucmd!() .args(&[ @@ -1888,9 +1888,9 @@ fn test_compress_merge() { .stdout_only_fixture("merge_ints_interleaved.expected"); } -#[test] #[cfg(not(target_os = "android"))] #[uutests::wasi_ignore(CompressProgramBypassed)] +#[test] fn test_compress_fail() { let result = new_ucmd!() .args(&[ @@ -1960,8 +1960,8 @@ fn test_batch_size_too_large() { .stderr_contains("maximum --batch-size argument with current rlimit is"); } -#[test] #[uutests::wasi_ignore(NoThreadSpawning)] +#[test] fn test_merge_batch_size() { new_ucmd!() .arg("--batch-size=2") @@ -1977,11 +1977,11 @@ fn test_merge_batch_size() { .stdout_only_fixture("merge_ints_interleaved.expected"); } -#[test] // 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")] #[uutests::wasi_ignore(NoThreadSpawning)] +#[test] fn test_merge_batch_size_with_limit() { // Currently need... // 3 descriptors for stdin, stdout, stderr @@ -2134,8 +2134,9 @@ fn test_sigpipe_panic() { child.wait().unwrap().no_stderr(); } -#[test] #[cfg(unix)] +#[uutests::wasi_ignore(NoFifo)] +#[test] fn test_fifo_without_trailing_newline() { let (at, mut ucmd) = at_and_ucmd!(); at.mkfifo("FIFO"); @@ -2219,9 +2220,9 @@ fn test_verifies_files_after_keys() { .stderr_contains("invalid field specification '0'"); } -#[test] #[cfg(unix)] #[uutests::wasi_ignore(HostPathsNotVisible)] +#[test] fn test_verifies_input_files() { new_ucmd!() .args(&["/dev/random", "nonexistent_file"]) @@ -2229,8 +2230,9 @@ fn test_verifies_input_files() { .stderr_is("sort: cannot read: nonexistent_file: No such file or directory\n"); } -#[test] #[cfg(unix)] +#[uutests::wasi_ignore(NoFifo)] +#[test] fn test_verifies_input_files_without_opening_them() { // Opening a FIFO blocks until a writer shows up, so if the input check opened // the inputs, the missing second file would never be reported. @@ -2310,6 +2312,7 @@ fn test_same_separator_twice_ok(#[case] args: &[&str]) { .stdout_only("b:1\na:2\n"); } +#[uutests::wasi_ignore(AbsoluteHostTmpdirOutsideGuestRoot)] #[test] fn test_output_is_input() { let input = "a\nb\nc\n"; @@ -2323,6 +2326,7 @@ fn test_output_is_input() { assert_eq!(at.read("file"), input); } +#[uutests::wasi_ignore(AbsoluteHostTmpdirOutsideGuestRoot)] #[rstest] #[case::newline('\n', &[])] #[case::newline_unique('\n', &["-u"])] @@ -2350,6 +2354,7 @@ fn test_merge_output_is_hard_link_to_input(#[case] separator: char, #[case] args assert_eq!(at.read("output"), input); } +#[uutests::wasi_ignore(AbsoluteHostTmpdirOutsideGuestRoot)] #[rstest] #[case::single_batch(&[])] #[case::multiple_batches(&["--batch-size=2"])] @@ -2402,6 +2407,7 @@ fn test_output_file_is_truncated() { assert_eq!(at.read("shrinking"), "apple\nkiwi\n"); } +#[uutests::wasi_ignore(NoThreadSpawning)] #[test] fn test_merge_output_file_is_truncated() { let (at, mut ucmd) = at_and_ucmd!(); @@ -2418,9 +2424,9 @@ fn test_merge_output_file_is_truncated() { assert_eq!(at.read("merged"), "damson\nquince\n"); } -#[test] #[cfg(unix)] #[uutests::wasi_ignore(HostPathsNotVisible)] +#[test] fn test_output_device() { new_ucmd!() .args(&["-o", "/dev/null"]) @@ -2428,8 +2434,8 @@ fn test_output_device() { .succeeds(); } -#[test] #[uutests::wasi_ignore(NoThreadSpawning)] +#[test] fn test_merge_empty_input() { new_ucmd!() .args(&["-m", "empty.txt"]) @@ -2453,9 +2459,9 @@ fn test_wrong_args_exit_code() { .stderr_contains("--misspelled"); } -#[test] #[cfg(unix)] #[uutests::wasi_ignore(NoPipeSignalSupport)] +#[test] fn test_tmp_files_deleted_on_sigint() { use rand::{RngExt as _, SeedableRng, rngs::SmallRng}; use rustix::process::{Pid, Signal, kill_process}; @@ -2502,8 +2508,9 @@ fn test_tmp_files_deleted_on_sigint() { assert!(read_dir(at.plus("tmp_dir")).unwrap().next().is_none()); } -#[test] #[cfg(unix)] +#[uutests::wasi_ignore(AutomaticBufferSizeDiffers)] +#[test] fn test_tmp_files_are_private() { use rustix::process::{Pid, Signal, kill_process}; use std::os::unix::fs::PermissionsExt as _; @@ -2547,8 +2554,9 @@ fn test_tmp_files_are_private() { child.wait().unwrap().code_is(2); } -#[test] #[cfg(all(unix, not(target_os = "redox")))] +#[uutests::wasi_ignore(NoFifo)] +#[test] fn test_tmp_dir_replaced_by_a_symlink() { use rustix::process::{Pid, Signal, kill_process}; use std::{ @@ -2649,8 +2657,8 @@ fn test_args_check_conflict() { } #[cfg(target_os = "linux")] -#[test] #[uutests::wasip2_ignore(StreamWriteGenericIoError)] +#[test] fn test_failed_write_is_reported() { new_ucmd!() .pipe_in("hello") @@ -2769,9 +2777,9 @@ fn test_files0_from_empty_input_file() { .stderr_only("sort: no input from 'file'\n"); } -#[test] #[cfg(unix)] #[uutests::wasip2_ignore(OsStringRequiresUtf8)] +#[test] fn test_files0_from_non_utf8_filename() { new_ucmd!() .args(&["--files0-from", "-"]) @@ -2798,7 +2806,6 @@ fn test_read_error_on_reader_thread(#[case] args: &[&str]) { #[test] #[cfg(unix)] -#[uutests::wasip2_ignore(OsErrorMessageDiffers)] fn test_files0_from_unreadable_source() { new_ucmd!() .args(&["--files0-from", "."]) @@ -2807,9 +2814,9 @@ fn test_files0_from_unreadable_source() { } #[cfg(unix)] -#[test] // Test files0-from with non-regular empty file #[uutests::wasi_ignore(HostPathsNotVisible)] +#[test] fn test_files0_from_dev_null_is_empty() { new_ucmd!() .args(&["--files0-from", "/dev/null"]) @@ -2893,10 +2900,10 @@ fn test_files0_from_two_entries_trailing_nul() { .stdout_only("kiwi\nkiwi\nmango\nmango\n"); } -#[test] // Test files0-from with non-UTF-8 filenames #[cfg(all(unix, not(target_vendor = "apple")))] #[uutests::wasi_ignore(NonUtf8ArgsUnsupported)] +#[test] fn test_files0_from_non_utf8_content() { use std::os::unix::ffi::OsStringExt; let (at, mut ucmd) = at_and_ucmd!(); @@ -3882,8 +3889,8 @@ fn test_locale_collation_utf8() { } } -#[test] #[uutests::wasi_ignore(NoLocaleData)] +#[test] fn test_locale_interleaved_en_us_utf8() { // Test case for issue: locale-based collation support // In en_US.UTF-8, lowercase and uppercase letters should interleave @@ -3955,8 +3962,8 @@ fn test_locale_with_ignore_case_flag() { ); } -#[test] #[uutests::wasi_ignore(NoLocaleData)] +#[test] fn test_locale_complex_utf8_sorting() { // More complex test with mixed case and special characters // In en_US.UTF-8, should respect locale collation rules @@ -3980,8 +3987,8 @@ fn test_locale_posix_sort_debug_message() { .stderr_contains("text ordering performed using simple byte comparison"); } -#[test] #[uutests::wasi_ignore(NoLocaleData)] +#[test] fn test_locale_utf8_sort_debug_message() { new_ucmd!() .env("LC_ALL", "en_US.UTF-8") @@ -4035,8 +4042,8 @@ fn test_empty_input_empty_output() { assert_eq!(at.read("file"), ""); } -#[test] #[uutests::wasi_ignore(NoLocaleData)] +#[test] fn test_consistent_sorting_with_i18n_collate() { // Regression test for issue #11980 // Lexicographic fallback sorting for equal sorting keys for 01 and 0_1 @@ -4057,6 +4064,7 @@ fn test_consistent_sorting_with_i18n_collate() { .stdout_is(expected_output); } +#[uutests::wasi_ignore(NoThreadSpawning)] #[test] fn test_merge_locale_collation() { // `sort -m` compares lines lazily with the collator instead of precomputed diff --git a/tests/by-util/test_split.rs b/tests/by-util/test_split.rs index d66c5d1a97c..fc26335698c 100644 --- a/tests/by-util/test_split.rs +++ b/tests/by-util/test_split.rs @@ -1090,6 +1090,7 @@ creating file 'xaf' ); } +#[uutests::wasi_ignore(HostPathsNotVisible)] #[test] fn test_number_n() { let (at, mut ucmd) = at_and_ucmd!(); @@ -1106,6 +1107,7 @@ fn test_number_n() { .stdout_only(""); } +#[uutests::wasi_ignore(HostPathsNotVisible)] #[test] fn test_number_kth_of_n() { new_ucmd!() @@ -1151,6 +1153,7 @@ fn test_number_kth_of_n() { .stderr_contains("split: invalid number of chunks: '18446744073709551616'"); } +#[uutests::wasi_ignore(Usize32BitOverflow)] #[test] fn test_number_kth_of_n_round_robin() { new_ucmd!() diff --git a/tests/by-util/test_tac.rs b/tests/by-util/test_tac.rs index 6f8a46bed8b..37aa7ec9f80 100644 --- a/tests/by-util/test_tac.rs +++ b/tests/by-util/test_tac.rs @@ -274,8 +274,9 @@ fn test_null_separator() { .stdout_is("b\0a\0"); } -#[test] #[cfg(unix)] +#[uutests::wasi_ignore(NonUtf8ArgsUnsupported)] +#[test] fn test_non_utf8_separator() { use std::os::unix::ffi::OsStringExt; new_ucmd!() @@ -287,8 +288,9 @@ fn test_non_utf8_separator() { .stdout_is_bytes(b"21\xe9"); } -#[test] #[cfg(unix)] +#[uutests::wasi_ignore(NonUtf8ArgsUnsupported)] +#[test] fn test_non_utf8_regex_separator() { use std::os::unix::ffi::OsStringExt; diff --git a/tests/by-util/test_tail.rs b/tests/by-util/test_tail.rs index ca264360f33..e8e8acbfcc9 100644 --- a/tests/by-util/test_tail.rs +++ b/tests/by-util/test_tail.rs @@ -501,6 +501,7 @@ fn test_stdin_redirect_dir() { // FIXME: If `std::io::ErrorKind::IsADirectory` becomes stable or macos handles // redirected directories like linux show the correct message like in // `test_stdin_redirect_dir` +#[uutests::wasi_ignore(HostSystemStateDiffers)] #[test] #[cfg(all(target_vendor = "apple", not(wasi_runner)))] fn test_stdin_redirect_dir_when_target_os_is_macos() { @@ -4416,6 +4417,7 @@ fn test_when_follow_retry_then_initial_print_of_file_is_written_to_stdout() { } // TODO: Add test for the warning `--pid=PID is not supported on this system` +#[uutests::wasi_ignore(TailFollowDisabled)] #[test] fn test_args_when_settings_check_warnings_then_shows_warnings() { let scene = TestScenario::new(util_name!()); @@ -5502,7 +5504,6 @@ fn test_when_piped_input_then_no_broken_pipe() { } } -#[uutests::wasi_ignore(ClosedStdoutGenericIoError)] #[test] #[cfg(unix)] fn test_when_output_closed_then_no_broken_pipe() { @@ -5537,6 +5538,7 @@ fn test_child_when_run_with_stderr_to_stdout() { } #[cfg(target_os = "linux")] +#[uutests::wasip2_ignore(StreamWriteGenericIoError)] #[test] fn test_failed_write_is_reported() { new_ucmd!() @@ -5547,6 +5549,7 @@ fn test_failed_write_is_reported() { } #[cfg(target_os = "linux")] +#[uutests::wasip2_ignore(StreamWriteGenericIoError)] #[test] fn test_multiple_input_files_failed_write_is_reported() { let (at, mut ucmd) = at_and_ucmd!(); @@ -5571,6 +5574,7 @@ fn test_failed_warning_write_is_reported() { } #[cfg(target_os = "linux")] +#[uutests::wasip2_ignore(StreamWriteGenericIoError)] #[test] fn test_failed_write_is_reported_on_seekable_input() { let ts = TestScenario::new("tail"); diff --git a/tests/by-util/test_touch.rs b/tests/by-util/test_touch.rs index 37bc4ce1532..8ef9690cc90 100644 --- a/tests/by-util/test_touch.rs +++ b/tests/by-util/test_touch.rs @@ -1311,11 +1311,9 @@ fn test_touch_device_files() { #[test] #[cfg(unix)] fn test_touch_does_not_truncate_symlink_target() { - use std::os::unix::fs::symlink; - let (at, mut ucmd) = at_and_ucmd!(); at.write("victim", "do not truncate me"); - symlink(at.plus("victim"), at.plus("link")).unwrap(); + at.symlink_file("victim", "link"); ucmd.arg("link").succeeds(); @@ -1327,10 +1325,8 @@ fn test_touch_does_not_truncate_symlink_target() { #[test] #[cfg(unix)] fn test_touch_through_dangling_symlink_creates_target() { - use std::os::unix::fs::symlink; - let (at, mut ucmd) = at_and_ucmd!(); - symlink(at.plus("missing"), at.plus("link")).unwrap(); + at.symlink_file("missing", "link"); ucmd.arg("link").succeeds(); diff --git a/tests/by-util/test_tr.rs b/tests/by-util/test_tr.rs index 812f40de439..6017017ab36 100644 --- a/tests/by-util/test_tr.rs +++ b/tests/by-util/test_tr.rs @@ -1344,8 +1344,9 @@ fn test_octal_escape_ambiguous_followed_by_non_utf8() { .stderr_contains("warning: invalid utf8 sequence"); } -#[cfg(target_os = "linux")] +#[uutests::wasip2_ignore(StreamWriteGenericIoError)] #[test] +#[cfg(target_os = "linux")] fn test_failed_write_is_reported() { new_ucmd!() .pipe_in("hello") diff --git a/tests/by-util/test_true.rs b/tests/by-util/test_true.rs index 4e11449baee..b1eae2b77ba 100644 --- a/tests/by-util/test_true.rs +++ b/tests/by-util/test_true.rs @@ -53,6 +53,7 @@ fn test_conflict() { .no_output(); } +#[uutests::wasip2_ignore(StreamWriteGenericIoError)] #[test] #[cfg(any(target_os = "linux", target_os = "freebsd", target_os = "netbsd"))] fn test_full() { diff --git a/tests/by-util/test_tsort.rs b/tests/by-util/test_tsort.rs index 268717a61f9..ef9d3dc251e 100644 --- a/tests/by-util/test_tsort.rs +++ b/tests/by-util/test_tsort.rs @@ -257,6 +257,7 @@ fn test_nonexistent_file_error_includes_filename() { .stderr_only("tsort: nosuchfile.txt: No such file or directory\n"); } +#[uutests::wasip2_ignore(StreamWriteGenericIoError)] #[test] #[cfg(any(target_os = "linux", target_os = "freebsd", target_os = "netbsd"))] fn test_write_error() { diff --git a/tests/by-util/test_tty.rs b/tests/by-util/test_tty.rs index 5103a60efac..02fc7ade7b8 100644 --- a/tests/by-util/test_tty.rs +++ b/tests/by-util/test_tty.rs @@ -69,6 +69,7 @@ fn test_help() { new_ucmd!().args(&["--help"]).succeeds(); } +#[uutests::wasi_ignore(NoSubprocessSpawning)] #[test] // FixME: freebsd panic #[cfg(all(unix, not(target_os = "freebsd")))] diff --git a/tests/by-util/test_uname.rs b/tests/by-util/test_uname.rs index aa4a6395fc6..e837deaae31 100644 --- a/tests/by-util/test_uname.rs +++ b/tests/by-util/test_uname.rs @@ -103,11 +103,17 @@ fn test_uname_operating_system() { .arg("--operating-system") .succeeds() .stdout_is("Android\n"); - #[cfg(target_vendor = "apple")] + // Under the WASI runner, the binary under test reports "WASI", not the host OS. + #[cfg(all(target_vendor = "apple", not(wasi_runner)))] new_ucmd!() .arg("--operating-system") .succeeds() .stdout_is("Darwin\n"); + #[cfg(all(target_vendor = "apple", wasi_runner))] + new_ucmd!() + .arg("--operating-system") + .succeeds() + .stdout_is("WASI\n"); #[cfg(target_os = "freebsd")] new_ucmd!() .arg("--operating-system") diff --git a/tests/by-util/test_uniq.rs b/tests/by-util/test_uniq.rs index a66f30fc551..9a00639881a 100644 --- a/tests/by-util/test_uniq.rs +++ b/tests/by-util/test_uniq.rs @@ -1226,6 +1226,7 @@ fn test_c_locale_counts_bytes() { } #[cfg(target_os = "linux")] +#[uutests::wasip2_ignore(StreamWriteGenericIoError)] #[test] fn test_failed_write_is_reported() { new_ucmd!() diff --git a/tests/by-util/test_wc.rs b/tests/by-util/test_wc.rs index 3ec8a54fa02..4c45301f2be 100644 --- a/tests/by-util/test_wc.rs +++ b/tests/by-util/test_wc.rs @@ -311,17 +311,14 @@ fn test_read_error_order_with_stderr_to_stdout() { let (at, mut ucmd) = at_and_ucmd!(); at.mkdir("ioerrdir"); - let cmd = ucmd.arg("ioerrdir").stderr_to_stdout().fails(); - if std::env::var("UUTESTS_WASM_RUNNER").is_ok() { - // wasi-libc may report a different error string than the host libc - cmd.stdout_contains("wc: ioerrdir:"); - } else { - let expected = format!( - "{:>7} {:>7} {:>7} ioerrdir\nwc: ioerrdir: Is a directory\n", - 0, 0, 0 - ); - cmd.stdout_only(expected); - } + let expected = format!( + "{:>7} {:>7} {:>7} ioerrdir\nwc: ioerrdir: Is a directory\n", + 0, 0, 0 + ); + ucmd.arg("ioerrdir") + .stderr_to_stdout() + .fails() + .stdout_only(expected); } /// Test that getting counts from nonexistent file is an error. @@ -664,23 +661,17 @@ fn files0_from_dir() { const DOT_ERR: &str = dir_err!("."); // On Unix, `read(open("."))` fails. On Windows, `open(".")` fails. Thus, the errors happen in - // different contexts. On WASI, the error string may differ (e.g., "Bad file descriptor"). - let wasm = std::env::var("UUTESTS_WASM_RUNNER").is_ok(); - - let cmd = new_ucmd!().args(&["--files0-from=dir with spaces"]).fails(); - if wasm { - cmd.stderr_contains("wc: 'dir with spaces': read error:"); - } else { - cmd.stderr_only(dir_err!("'dir with spaces'")); - } + // different contexts. + new_ucmd!() + .args(&["--files0-from=dir with spaces"]) + .fails() + .stderr_only(dir_err!("'dir with spaces'")); // Those contexts have different rules about quoting in errors... - let cmd = new_ucmd!().args(&["--files0-from=."]).fails(); - if wasm { - cmd.stderr_contains("wc: .: read error:"); - } else { - cmd.stderr_only(DOT_ERR); - } + new_ucmd!() + .args(&["--files0-from=."]) + .fails() + .stderr_only(DOT_ERR); // That also means you cannot `< . wc --files0-from=-` on Windows. #[cfg(not(windows))] diff --git a/tests/uutests/Cargo.toml b/tests/uutests/Cargo.toml index 6535a98970d..a7031225676 100644 --- a/tests/uutests/Cargo.toml +++ b/tests/uutests/Cargo.toml @@ -31,6 +31,7 @@ uucore = { workspace = true, features = [ "process", "signals", "utmpx", + "fs", ] } uutests_procs = { workspace = true } diff --git a/tests/uutests_procs/src/lib.rs b/tests/uutests_procs/src/lib.rs index 3abb8a19964..dfc27ce7b4b 100644 --- a/tests/uutests_procs/src/lib.rs +++ b/tests/uutests_procs/src/lib.rs @@ -15,24 +15,24 @@ use syn::Item; fn wasi_reason(key: &str) -> Option<&'static str> { Some(match key { "AbsoluteHostTmpdirOutsideGuestRoot" => { - "WASI sandbox: absolute host tmpdir path is outside the mapped guest root, so cp cannot stat it" + "WASI sandbox: absolute host tmpdir path (e.g. /tmp) is outside the mapped guest root, so it cannot be statted or written to" } "AbsoluteSymlinkTargetsUnfollowable" => { "WASI sandbox: absolute symlink targets cannot be followed" } "AclXattrPreservationFails" => { - "WASI: ACL/xattr syscalls are not implemented, so attribute preservation (--archive, -p) always fails" + "WASI: ACL/xattr syscalls are not implemented, so attribute preservation (--archive, -p) and ACL display always report no ACLs" } "AddressSpaceLimitUnsuitable" => { "WASI runner target is not suitable for this address-space-limit regression test" } + "AutomaticBufferSizeDiffers" => { + "WASI: sort's automatic buffer-size heuristic (based on queried available memory) behaves differently under wasm32, so disk-spill thresholds don't match the host" + } "CannotDetectUnsafeOverwrite" => "WASI: cannot detect unsafe overwrite", "CannotExecShellFromDeletedCwd" => { "WASI: wasmtime cannot exec the binary via a raw shell from a deleted cwd" } - "ClosedStdoutGenericIoError" => { - "WASI: closed stdout reports a generic I/O error rather than BrokenPipe" - } "CompressProgramBypassed" => { "WASI: ext_sort bypasses --compress-program entirely (single-threaded in-memory path)" } @@ -40,19 +40,12 @@ fn wasi_reason(key: &str) -> Option<&'static str> { "WASI: --debug reports 'unsupported' instead of 'unknown' for this platform" } "DevNullNotSeekable" => "WASI sandbox: /dev/null is not a seekable device", - "DirectoryModesUmaskNotFaithful" => { - "WASI: directory modes/umask are not faithfully reproduced" - } "DirectorySizeFromMetadata" => { "WASI: the guest is not Unix, so a directory's size comes from its metadata rather than from a seek to its end" } "DotDotCanonicalizationDiffers" => { "WASI sandbox: relative '..' path canonicalization differs, causing a false self-copy detection" } - "EmptyPathResolvesToDirectory" => { - "WASI: an empty path argument resolves to a directory instead of ENOENT" - } - "ErrnoMessageMismatch" => "WASI: errno/error-message mismatches", "GuestRootPathResolution" => { "WASI sandbox: paths resolve against the guest's preopened root, so '..', UNC-style, canonicalized, symlinked-cwd and host absolute paths differ from the host" } @@ -77,14 +70,17 @@ fn wasi_reason(key: &str) -> Option<&'static str> { "WASI: no locale data; every locale (even one requested via LC_ALL or other locale env vars) behaves as C" } "NoPermissionBits" => { - "WASI: no permission bits/chmod syscall, so file mode cannot be restricted or observed, and explicit mode/ownership preservation always fails" + "WASI: no permission bits/chmod syscall and no mkdir mode parameter, so file and directory modes cannot be restricted, observed, or faithfully reproduced via umask" } "NoPipeSignalSupport" => "WASI: no pipe/signal support", + "NoProcessPrioritySupport" => { + "WASI: no process priority support (getpriority/setpriority), so nice always reports/applies a fixed niceness" + } "NoRlimitSetrlimitSupport" => "WASI: rlimit/setrlimit not supported", "NoStdoutFileRedirection" => "WASI: no stdout-to-file redirection", "NoSubprocessSpawning" => "WASI: no subprocess spawning", "NoThreadSpawning" => { - "WASI: sort -m spawns real OS threads for multi-file merge, unsupported under wasmtime's default config" + "WASI: this code path spawns a real OS thread, unsupported under wasmtime's default config" } "NoTzdb" => { "WASI: no tzdb; TZ env var is not honoured, so timezone-dependent behaviour (DST validation, timestamps) differs from the host" @@ -94,9 +90,6 @@ fn wasi_reason(key: &str) -> Option<&'static str> { "NonUtf8ArgsUnsupported" => { "WASI: argv, env values, and paths must be valid UTF-8; wasmtime cannot pass non-UTF-8 data through the sandboxed binary or the spawned test harness" } - "PathCreateDirectoryNoModeParam" => { - "WASI: path_create_directory has no mode parameter and chmod returns ENOSYS, so directories can't be created with restricted permissions" - } "PermissionErrorsSurfaceAsEnoent" => { "WASI: filesystem permission errors surface as ENOENT rather than EACCES" } @@ -109,6 +102,9 @@ fn wasi_reason(key: &str) -> Option<&'static str> { "RenameNotAtomicReplace" => { "WASI: path rename is not guaranteed to be an atomic replace, so a concurrent creator can win the race during a forced relink" } + "SandboxRootAliasesGuestCwd" => { + "WASI sandbox: the guest's preopened root is remapped to \"/\", so a path that resolves to the mapped root is indistinguishable from the real filesystem root" + } "StdinPositionNotPreserved" => "WASI: stdin file position not preserved through wasmtime", "StdioHandlesOpaque" => { "WASI sandbox: inherited stdin and stdout cannot be inspected, do not share a file offset and are not reachable through /dev/fd" @@ -118,6 +114,9 @@ fn wasi_reason(key: &str) -> Option<&'static str> { "WASI sandbox: symlink/hardlink capability restrictions cause dangling-symlink/same-file detection to differ" } "TailFollowDisabled" => "WASI: tail follow mode disabled", + "TrailingSlashOnRemoveRejected" => { + "WASI: path removal syscalls reject a trailing slash on the target, unlike POSIX unlink/rmdir" + } "UnsupportedStdApi" => { "WASI: the std or libc API is unsupported (File::try_clone, setlocale LC_* constants)" } @@ -133,9 +132,6 @@ fn wasip2_reason(key: &str) -> Option<&'static str> { "StreamWriteGenericIoError" => { "WASI P2: stream write errors report a generic I/O error instead of their errno, for example ENOSPC on a full device" } - "OsErrorMessageDiffers" => { - "WASI P2: the error message text for this OS error differs from native Unix" - } "OsStringRequiresUtf8" => "WASI P2: OsString requires valid UTF-8, unlike unix and WASI P1", _ => return None, })