Skip to content

Commit 591d6c1

Browse files
committed
fix(tests): refine feature checks for SELinux
1 parent 0baa689 commit 591d6c1

10 files changed

Lines changed: 120 additions & 30 deletions

File tree

tests/by-util/test_chcon.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,10 @@
44
// file that was distributed with this source code.
55
// spell-checker:ignore (jargon) xattributes
66
#![allow(clippy::missing_errors_doc, clippy::similar_names)]
7-
#![cfg(feature = "feat_selinux")]
7+
#![cfg(all(
8+
feature = "feat_selinux",
9+
any(target_os = "linux", target_os = "android")
10+
))]
811

912
use std::ffi::CString;
1013
use std::path::Path;

tests/by-util/test_cp.rs

Lines changed: 40 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,10 @@
88
#[cfg(unix)]
99
use rstest::rstest;
1010
use uucore::display::Quotable;
11-
#[cfg(feature = "feat_selinux")]
11+
#[cfg(all(
12+
feature = "feat_selinux",
13+
any(target_os = "linux", target_os = "android")
14+
))]
1215
use uucore::selinux::get_getfattr_output;
1316
use uutests::util::TestScenario;
1417
use uutests::{at_and_ucmd, new_ucmd, path_concat, util_name};
@@ -6771,7 +6774,10 @@ fn test_cp_from_stream_permission() {
67716774
}
67726775

67736776
#[test]
6774-
#[cfg(feature = "feat_selinux")]
6777+
#[cfg(all(
6778+
feature = "feat_selinux",
6779+
any(target_os = "linux", target_os = "android")
6780+
))]
67756781
fn test_cp_selinux() {
67766782
let ts = TestScenario::new(util_name!());
67776783
let at = &ts.fixtures;
@@ -6820,7 +6826,10 @@ fn test_cp_selinux_invalid() {
68206826
}
68216827

68226828
#[test]
6823-
#[cfg(feature = "feat_selinux")]
6829+
#[cfg(all(
6830+
feature = "feat_selinux",
6831+
any(target_os = "linux", target_os = "android")
6832+
))]
68246833
fn test_cp_preserve_selinux() {
68256834
let ts = TestScenario::new(util_name!());
68266835
let at = &ts.fixtures;
@@ -6858,7 +6867,10 @@ fn test_cp_preserve_selinux() {
68586867
}
68596868

68606869
#[test]
6861-
#[cfg(feature = "feat_selinux")]
6870+
#[cfg(all(
6871+
feature = "feat_selinux",
6872+
any(target_os = "linux", target_os = "android")
6873+
))]
68626874
fn test_cp_preserve_selinux_admin_context() {
68636875
let ts = TestScenario::new(util_name!());
68646876
let at = &ts.fixtures;
@@ -6917,7 +6929,10 @@ fn test_cp_preserve_selinux_admin_context() {
69176929
}
69186930

69196931
#[test]
6920-
#[cfg(feature = "feat_selinux")]
6932+
#[cfg(all(
6933+
feature = "feat_selinux",
6934+
any(target_os = "linux", target_os = "android")
6935+
))]
69216936
fn test_cp_selinux_context_priority() {
69226937
// This test verifies that -Z takes priority over --context
69236938

@@ -6997,7 +7012,10 @@ fn test_cp_selinux_context_priority() {
69977012
}
69987013

69997014
#[test]
7000-
#[cfg(feature = "feat_selinux")]
7015+
#[cfg(all(
7016+
feature = "feat_selinux",
7017+
any(target_os = "linux", target_os = "android")
7018+
))]
70017019
fn test_cp_selinux_empty_context() {
70027020
// This test verifies that --context without a value works like -Z
70037021

@@ -7043,7 +7061,10 @@ fn test_cp_selinux_empty_context() {
70437061
}
70447062

70457063
#[test]
7046-
#[cfg(feature = "feat_selinux")]
7064+
#[cfg(all(
7065+
feature = "feat_selinux",
7066+
any(target_os = "linux", target_os = "android")
7067+
))]
70477068
fn test_cp_selinux_recursive() {
70487069
// Test SELinux context preservation in recursive directory copies
70497070

@@ -7097,7 +7118,10 @@ fn test_cp_selinux_recursive() {
70977118
}
70987119

70997120
#[test]
7100-
#[cfg(feature = "feat_selinux")]
7121+
#[cfg(all(
7122+
feature = "feat_selinux",
7123+
any(target_os = "linux", target_os = "android")
7124+
))]
71017125
fn test_cp_preserve_context_root() {
71027126
use uutests::util::run_ucmd_as_root;
71037127
let scene = TestScenario::new(util_name!());
@@ -7800,7 +7824,10 @@ fn test_cp_gnu_preserve_mode() {
78007824
}
78017825

78027826
#[test]
7803-
#[cfg(feature = "feat_selinux")]
7827+
#[cfg(all(
7828+
feature = "feat_selinux",
7829+
any(target_os = "linux", target_os = "android")
7830+
))]
78047831
fn test_cp_a_z_overrides_context() {
78057832
// Verifies -aZ succeeds (-Z overrides implicit --preserve=context from -a)
78067833
use std::path::Path;
@@ -7818,7 +7845,10 @@ fn test_cp_a_z_overrides_context() {
78187845
}
78197846

78207847
#[test]
7821-
#[cfg(feature = "feat_selinux")]
7848+
#[cfg(all(
7849+
feature = "feat_selinux",
7850+
any(target_os = "linux", target_os = "android")
7851+
))]
78227852
fn test_cp_a_preserves_context() {
78237853
use std::path::Path;
78247854
use uucore::selinux::{get_selinux_security_context, set_selinux_security_context};

tests/by-util/test_id.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -383,7 +383,10 @@ fn test_id_zero() {
383383
}
384384

385385
#[test]
386-
#[cfg(feature = "feat_selinux")]
386+
#[cfg(all(
387+
feature = "feat_selinux",
388+
any(target_os = "linux", target_os = "android")
389+
))]
387390
fn test_id_context() {
388391
if !uucore::selinux::is_selinux_enabled() {
389392
println!("test skipped: Kernel has no support for SElinux context");

tests/by-util/test_install.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,10 @@ use std::process;
1515
#[cfg(any(target_os = "linux", target_os = "android"))]
1616
use std::thread::sleep;
1717
use uucore::process::{getegid, geteuid};
18-
#[cfg(feature = "feat_selinux")]
18+
#[cfg(all(
19+
feature = "feat_selinux",
20+
any(target_os = "linux", target_os = "android")
21+
))]
1922
use uucore::selinux::get_getfattr_output;
2023
use uutests::at_and_ucmd;
2124
use uutests::new_ucmd;
@@ -2334,7 +2337,10 @@ fn test_install_no_target_basic() {
23342337
}
23352338

23362339
#[test]
2337-
#[cfg(feature = "feat_selinux")]
2340+
#[cfg(all(
2341+
feature = "feat_selinux",
2342+
any(target_os = "linux", target_os = "android")
2343+
))]
23382344
fn test_selinux() {
23392345
let scene = TestScenario::new(util_name!());
23402346
let at = &scene.fixtures;

tests/by-util/test_ls.rs

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4656,7 +4656,10 @@ fn test_ls_dangling_symlinks() {
46564656
}
46574657

46584658
#[test]
4659-
#[cfg(feature = "feat_selinux")]
4659+
#[cfg(all(
4660+
feature = "feat_selinux",
4661+
any(target_os = "linux", target_os = "android")
4662+
))]
46604663
fn test_ls_context1() {
46614664
if !uucore::selinux::is_selinux_enabled() {
46624665
println!("test skipped: Kernel has no support for SElinux context");
@@ -4671,7 +4674,10 @@ fn test_ls_context1() {
46714674
}
46724675

46734676
#[test]
4674-
#[cfg(feature = "feat_selinux")]
4677+
#[cfg(all(
4678+
feature = "feat_selinux",
4679+
any(target_os = "linux", target_os = "android")
4680+
))]
46754681
fn test_ls_context2() {
46764682
if !uucore::selinux::is_selinux_enabled() {
46774683
println!("test skipped: Kernel has no support for SElinux context");
@@ -4687,7 +4693,10 @@ fn test_ls_context2() {
46874693
}
46884694

46894695
#[test]
4690-
#[cfg(feature = "feat_selinux")]
4696+
#[cfg(all(
4697+
feature = "feat_selinux",
4698+
any(target_os = "linux", target_os = "android")
4699+
))]
46914700
fn test_ls_context_long() {
46924701
if !uucore::selinux::is_selinux_enabled() {
46934702
return;
@@ -4706,7 +4715,10 @@ fn test_ls_context_long() {
47064715
}
47074716

47084717
#[test]
4709-
#[cfg(feature = "feat_selinux")]
4718+
#[cfg(all(
4719+
feature = "feat_selinux",
4720+
any(target_os = "linux", target_os = "android")
4721+
))]
47104722
fn test_ls_context_format() {
47114723
if !uucore::selinux::is_selinux_enabled() {
47124724
println!("test skipped: Kernel has no support for SElinux context");
@@ -4736,7 +4748,10 @@ fn test_ls_context_format() {
47364748
}
47374749

47384750
/// Helper function to validate `SELinux` context format
4739-
#[cfg(feature = "feat_selinux")]
4751+
#[cfg(all(
4752+
feature = "feat_selinux",
4753+
any(target_os = "linux", target_os = "android")
4754+
))]
47404755
fn validate_selinux_context(context: &str) {
47414756
assert!(
47424757
context.contains(':'),
@@ -4751,7 +4766,10 @@ fn validate_selinux_context(context: &str) {
47514766
}
47524767

47534768
#[test]
4754-
#[cfg(feature = "feat_selinux")]
4769+
#[cfg(all(
4770+
feature = "feat_selinux",
4771+
any(target_os = "linux", target_os = "android")
4772+
))]
47554773
fn test_ls_selinux_context_format() {
47564774
if !uucore::selinux::is_selinux_enabled() {
47574775
println!("test skipped: Kernel has no support for SElinux context");
@@ -4784,7 +4802,10 @@ fn test_ls_selinux_context_format() {
47844802
}
47854803

47864804
#[test]
4787-
#[cfg(feature = "feat_selinux")]
4805+
#[cfg(all(
4806+
feature = "feat_selinux",
4807+
any(target_os = "linux", target_os = "android")
4808+
))]
47884809
fn test_ls_selinux_context_indicator() {
47894810
if !uucore::selinux::is_selinux_enabled() {
47904811
println!("test skipped: Kernel has no support for SElinux context");

tests/by-util/test_mkdir.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,10 @@
1111
use libc::mode_t;
1212
#[cfg(not(windows))]
1313
use std::os::unix::fs::PermissionsExt;
14-
#[cfg(feature = "feat_selinux")]
14+
#[cfg(all(
15+
feature = "feat_selinux",
16+
any(target_os = "linux", target_os = "android")
17+
))]
1518
use uucore::selinux::get_getfattr_output;
1619
#[cfg(not(windows))]
1720
use uutests::at_and_ucmd;
@@ -449,7 +452,10 @@ fn test_empty_argument() {
449452
}
450453

451454
#[test]
452-
#[cfg(feature = "feat_selinux")]
455+
#[cfg(all(
456+
feature = "feat_selinux",
457+
any(target_os = "linux", target_os = "android")
458+
))]
453459
fn test_selinux() {
454460
let scene = TestScenario::new(util_name!());
455461
let at = &scene.fixtures;

tests/by-util/test_mkfifo.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,10 @@
55

66
// spell-checker:ignore nconfined
77

8-
#[cfg(feature = "feat_selinux")]
8+
#[cfg(all(
9+
feature = "feat_selinux",
10+
any(target_os = "linux", target_os = "android")
11+
))]
912
use uucore::selinux::get_getfattr_output;
1013
use uutests::new_ucmd;
1114
use uutests::util::TestScenario;
@@ -167,7 +170,10 @@ fn test_create_fifo_permission_denied() {
167170
}
168171

169172
#[test]
170-
#[cfg(feature = "feat_selinux")]
173+
#[cfg(all(
174+
feature = "feat_selinux",
175+
any(target_os = "linux", target_os = "android")
176+
))]
171177
fn test_mkfifo_selinux() {
172178
let ts = TestScenario::new(util_name!());
173179
let at = &ts.fixtures;

tests/by-util/test_mknod.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,10 @@
77

88
use std::os::unix::fs::PermissionsExt;
99

10-
#[cfg(feature = "feat_selinux")]
10+
#[cfg(all(
11+
feature = "feat_selinux",
12+
any(target_os = "linux", target_os = "android")
13+
))]
1114
use uucore::selinux::get_getfattr_output;
1215
use uutests::new_ucmd;
1316
use uutests::util::TestScenario;
@@ -184,7 +187,10 @@ fn test_mknod_mode_comma_separated() {
184187
}
185188

186189
#[test]
187-
#[cfg(feature = "feat_selinux")]
190+
#[cfg(all(
191+
feature = "feat_selinux",
192+
any(target_os = "linux", target_os = "android")
193+
))]
188194
fn test_mknod_selinux() {
189195
let ts = TestScenario::new(util_name!());
190196
let at = &ts.fixtures;

tests/by-util/test_mv.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,10 @@ use rstest::rstest;
1010
use std::io::Write;
1111
#[cfg(not(windows))]
1212
use std::path::Path;
13-
#[cfg(feature = "feat_selinux")]
13+
#[cfg(all(
14+
feature = "feat_selinux",
15+
any(target_os = "linux", target_os = "android")
16+
))]
1417
use uucore::selinux::get_getfattr_output;
1518
use uutests::new_ucmd;
1619
#[cfg(unix)]
@@ -2617,7 +2620,10 @@ fn test_mv_cross_device_permission_denied() {
26172620
}
26182621

26192622
#[test]
2620-
#[cfg(feature = "feat_selinux")]
2623+
#[cfg(all(
2624+
feature = "feat_selinux",
2625+
any(target_os = "linux", target_os = "android")
2626+
))]
26212627
fn test_mv_selinux_context() {
26222628
let test_cases = [
26232629
("-Z", None),

tests/by-util/test_runcon.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,10 @@
44
// file that was distributed with this source code.
55
// spell-checker:ignore (jargon) xattributes
66

7-
#![cfg(feature = "feat_selinux")]
7+
#![cfg(all(
8+
feature = "feat_selinux",
9+
any(target_os = "linux", target_os = "android")
10+
))]
811

912
use uutests::new_ucmd;
1013

0 commit comments

Comments
 (0)