From 152dada37992964a9913a7e49add26878c0c8ad1 Mon Sep 17 00:00:00 2001 From: Nicolas Boichat Date: Sun, 23 Mar 2025 17:35:52 +0100 Subject: [PATCH 1/3] tests/common/util: Make sure test_altering_umask is run in correct shell On Android CI, `sh` would point at a different flavor of shell shipped with termux (dash). The current umask test expects that `/system/bin/sh` is used though, so create a new function TestScenario:cmd_shell that runs a command in the default shell (that could be used in more tests). Fixes one part of #7542. --- tests/common/util.rs | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/tests/common/util.rs b/tests/common/util.rs index 79b3a5de1..1a4717170 100644 --- a/tests/common/util.rs +++ b/tests/common/util.rs @@ -1215,6 +1215,17 @@ impl TestScenario { command } + /// Returns builder for invoking a command in shell (e.g. sh -c 'cmd'). + /// Paths given are treated relative to the environment's unique temporary + /// test directory. + pub fn cmd_shell>(&self, cmd: S) -> UCommand { + let mut command = UCommand::new(); + // Intentionally leave bin_path unset. + command.arg(cmd); + command.temp_dir(self.tmpd.clone()); + command + } + /// Returns builder for invoking any uutils command. Paths given are treated /// relative to the environment's unique temporary test directory. pub fn ccmd>(&self, util_name: S) -> UCommand { @@ -4052,8 +4063,7 @@ mod tests { }; let ts = TestScenario::new("util"); - ts.cmd("sh") - .args(&["-c", "umask"]) + ts.cmd_shell("umask") .umask(c_umask) .succeeds() .stdout_is(expected); From 7eb873c326188a6883b7c2117c72484bd7d36466 Mon Sep 17 00:00:00 2001 From: Nicolas Boichat Date: Sun, 23 Mar 2025 14:47:05 +0100 Subject: [PATCH 2/3] test_env: Try to execute an empty file instead of `.` For some unclear reason, Android _now_ sometimes returns an IsADirectory error, instead of PermissionDenied, when trying to execute `.`. Since this test really wants to test PermissionDenied, we try to execute a file in the fixture instead, that doesn't have exec permission. Also, limit this test to Unix. Fixes part of #7542. --- tests/by-util/test_env.rs | 6 ++++-- tests/fixtures/env/empty | 0 2 files changed, 4 insertions(+), 2 deletions(-) create mode 100644 tests/fixtures/env/empty diff --git a/tests/by-util/test_env.rs b/tests/by-util/test_env.rs index 4a7ea96c0..1b8974a90 100644 --- a/tests/by-util/test_env.rs +++ b/tests/by-util/test_env.rs @@ -81,11 +81,13 @@ fn test_env_version() { } #[test] +#[cfg(unix)] fn test_env_permissions() { + // Try to execute `empty` in test fixture, that does not have exec permission. new_ucmd!() - .arg(".") + .arg("./empty") .fails_with_code(126) - .stderr_is("env: '.': Permission denied\n"); + .stderr_is("env: './empty': Permission denied\n"); } #[test] diff --git a/tests/fixtures/env/empty b/tests/fixtures/env/empty new file mode 100644 index 000000000..e69de29bb From b142b9e748acec1efa8ab2e8ad6dfc3002e238fb Mon Sep 17 00:00:00 2001 From: Nicolas Boichat Date: Sun, 23 Mar 2025 18:14:10 +0100 Subject: [PATCH 3/3] test_*: Disable tests that require setting rlimit on Android See #7542, it's not totally clear where the problem comes from, but blanking LD_PRELOAD set by termux seems to fix the problem (but introduces other issues. Let's just disable these tests for now. --- tests/by-util/test_cat.rs | 4 +++- tests/by-util/test_sort.rs | 4 +++- tests/by-util/test_split.rs | 4 +++- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/tests/by-util/test_cat.rs b/tests/by-util/test_cat.rs index 1011b3f37..ee89f1639 100644 --- a/tests/by-util/test_cat.rs +++ b/tests/by-util/test_cat.rs @@ -98,7 +98,9 @@ fn test_fifo_symlink() { } #[test] -#[cfg(any(target_os = "linux", target_os = "android"))] +// 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")] 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. diff --git a/tests/by-util/test_sort.rs b/tests/by-util/test_sort.rs index 213c567e4..5e13369ca 100644 --- a/tests/by-util/test_sort.rs +++ b/tests/by-util/test_sort.rs @@ -1090,7 +1090,9 @@ fn test_merge_batch_size() { } #[test] -#[cfg(any(target_os = "linux", target_os = "android"))] +// 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")] fn test_merge_batch_size_with_limit() { use rlimit::Resource; // Currently need... diff --git a/tests/by-util/test_split.rs b/tests/by-util/test_split.rs index 5c2eb4c8c..c21299eaa 100644 --- a/tests/by-util/test_split.rs +++ b/tests/by-util/test_split.rs @@ -1627,7 +1627,9 @@ fn test_round_robin() { } #[test] -#[cfg(any(target_os = "linux", target_os = "android"))] +// TODO(#7542): Re-enable on Android once we figure out why rlimit is broken. +// #[cfg(any(target_os = "linux", target_os = "android"))] +#[cfg(target_os = "linux")] fn test_round_robin_limited_file_descriptors() { new_ucmd!() .args(&["-n", "r/40", "onehundredlines.txt"])