From 9d0fbc5f467cbb27e989c7ea019693bc92b3a7cd Mon Sep 17 00:00:00 2001 From: Zhiwei Liang Date: Mon, 21 Sep 2026 22:53:05 -0400 Subject: [PATCH] cksum: only report x86 hardware features on x86 targets Signed-off-by: Zhiwei Liang --- src/uu/cksum/src/cksum.rs | 8 +++++--- tests/by-util/test_cksum.rs | 27 +++++++++++++++++++++++++++ 2 files changed, 32 insertions(+), 3 deletions(-) diff --git a/src/uu/cksum/src/cksum.rs b/src/uu/cksum/src/cksum.rs index 5f567cc51c1..183687ac83e 100644 --- a/src/uu/cksum/src/cksum.rs +++ b/src/uu/cksum/src/cksum.rs @@ -34,9 +34,11 @@ fn print_cpu_debug_info() { let features = SimdPolicy::detect(); // x86/x86_64 - print_feature("avx512", features.has_avx512()); - print_feature("avx2", features.has_avx2()); - print_feature("pclmul", features.has_pclmul()); + if cfg!(any(target_arch = "x86", target_arch = "x86_64")) { + print_feature("avx512", features.has_avx512()); + print_feature("avx2", features.has_avx2()); + print_feature("pclmul", features.has_pclmul()); + } // ARM aarch64 if cfg!(target_arch = "aarch64") { diff --git a/tests/by-util/test_cksum.rs b/tests/by-util/test_cksum.rs index 39617aa6b5a..1178a58a5a0 100644 --- a/tests/by-util/test_cksum.rs +++ b/tests/by-util/test_cksum.rs @@ -3065,6 +3065,7 @@ mod debug_flag { use super::*; #[test] + #[cfg(any(target_arch = "x86", target_arch = "x86_64"))] fn test_debug_flag() { // Test with default CRC algorithm - should output CPU feature detection new_ucmd!() @@ -3121,6 +3122,7 @@ mod debug_flag { } #[test] + #[cfg(any(target_arch = "x86", target_arch = "x86_64"))] fn test_debug_with_algorithms() { // Test with SHA256 - CPU detection should be same regardless of algorithm new_ucmd!() @@ -3168,6 +3170,31 @@ mod debug_flag { .stderr_contains("avx2") .stderr_contains("pclmul"); } + + #[test] + #[cfg(target_arch = "aarch64")] + fn test_debug_flag_aarch64() { + new_ucmd!() + .arg("--debug") + .arg("lorem_ipsum.txt") + .succeeds() + .stdout_is_fixture("crc_single_file.expected") + .stderr_str_check(|stderr| { + stderr == "using vmull hardware support\n" + || stderr == "vmull support not detected\n" + }); + } + + #[test] + #[cfg(not(any(target_arch = "x86", target_arch = "x86_64", target_arch = "aarch64")))] + fn test_debug_flag_no_hardware_features() { + new_ucmd!() + .arg("--debug") + .arg("lorem_ipsum.txt") + .succeeds() + .stdout_is_fixture("crc_single_file.expected") + .no_stderr(); + } } #[test]