diff --git a/library/Cargo.lock b/library/Cargo.lock index f6c14bc58a044..080bfab7fd564 100644 --- a/library/Cargo.lock +++ b/library/Cargo.lock @@ -358,6 +358,10 @@ dependencies = [ "rustc-std-workspace-core", ] +[[package]] +name = "std_detect_tests" +version = "0.0.0" + [[package]] name = "sysroot" version = "0.0.0" diff --git a/library/Cargo.toml b/library/Cargo.toml index e30e624094285..2d9d4a959b111 100644 --- a/library/Cargo.toml +++ b/library/Cargo.toml @@ -7,6 +7,7 @@ members = [ "sysroot", "coretests", "alloctests", + "std_detect_tests", ] exclude = [ diff --git a/library/std_detect/src/detect/arch/mod.rs b/library/std_detect/src/detect/arch/mod.rs index 2be7f091c285e..2e545845f8176 100644 --- a/library/std_detect/src/detect/arch/mod.rs +++ b/library/std_detect/src/detect/arch/mod.rs @@ -66,7 +66,7 @@ cfg_select! { _ => { // Unimplemented architecture: #[doc(hidden)] - pub(crate) enum Feature { + pub enum Feature { Null } #[doc(hidden)] diff --git a/library/std_detect/src/detect/cache.rs b/library/std_detect/src/detect/cache.rs index c0c0b7b7f8635..e43b76d1419df 100644 --- a/library/std_detect/src/detect/cache.rs +++ b/library/std_detect/src/detect/cache.rs @@ -30,21 +30,21 @@ const CACHE_CAPACITY: u32 = 93; // The derived `Default` implementation will initialize the field to zero, // which is what we want. #[derive(Copy, Clone, Default, PartialEq, Eq)] -pub(crate) struct Initializer(u128); +pub struct Initializer(u128); // NOTE: the `debug_assert!` would catch that we do not add more Features than // the one fitting our cache. impl Initializer { /// Tests the `bit` of the cache. #[inline] - pub(crate) fn test(self, bit: u32) -> bool { + pub fn test(self, bit: u32) -> bool { debug_assert!(bit < CACHE_CAPACITY, "too many features, time to increase the cache size!"); test_bit(self.0, bit) } /// Sets the `bit` of the cache. #[inline] - pub(crate) fn set(&mut self, bit: u32) { + pub fn set(&mut self, bit: u32) { debug_assert!(bit < CACHE_CAPACITY, "too many features, time to increase the cache size!"); let v = self.0; self.0 = set_bit(v, bit); diff --git a/library/std_detect/src/detect/macros.rs b/library/std_detect/src/detect/macros.rs index 17140e15653d2..7a99be5bd2bc4 100644 --- a/library/std_detect/src/detect/macros.rs +++ b/library/std_detect/src/detect/macros.rs @@ -149,7 +149,7 @@ macro_rules! features { #[repr(u8)] #[unstable(feature = "stdarch_internal", issue = "none")] #[cfg($cfg)] - pub(crate) enum Feature { + pub enum Feature { $( $(#[$feature_comment])* $feature, diff --git a/library/std_detect/src/detect/mod.rs b/library/std_detect/src/detect/mod.rs index c888dd34d9db5..d41526aacd8cc 100644 --- a/library/std_detect/src/detect/mod.rs +++ b/library/std_detect/src/detect/mod.rs @@ -32,6 +32,11 @@ pub(crate) use self::arch::Feature; mod bit; mod cache; +pub mod __test { + pub use super::arch::Feature; + pub use super::cache::Initializer; +} + cfg_select! { miri => { // When running under miri all target-features that are not enabled at @@ -53,6 +58,14 @@ cfg_select! { mod riscv; #[path = "os/linux/mod.rs"] mod os; + #[unstable(feature = "stdarch_internal", issue = "none")] + pub mod __test_os { + #[cfg(any(target_arch = "riscv32", target_arch = "riscv64"))] + pub use super::riscv::imply_features; + #[cfg(target_arch = "aarch64")] + pub use super::os::aarch64::AtHwcap; + pub use super::os::auxvec::{auxv, auxv_from_file}; + } } target_os = "freebsd" => { #[cfg(target_arch = "aarch64")] diff --git a/library/std_detect/src/detect/os/linux/aarch64.rs b/library/std_detect/src/detect/os/linux/aarch64.rs index b733b8a9eb236..b3f6fbb273d20 100644 --- a/library/std_detect/src/detect/os/linux/aarch64.rs +++ b/library/std_detect/src/detect/os/linux/aarch64.rs @@ -35,106 +35,106 @@ pub(crate) fn detect_features() -> cache::Initializer { /// /// [hwcap]: https://github.com/torvalds/linux/blob/master/arch/arm64/include/uapi/asm/hwcap.h #[derive(Debug, Default, PartialEq)] -struct AtHwcap { +pub struct AtHwcap { // AT_HWCAP - fp: bool, - asimd: bool, - // evtstrm: No LLVM support. - aes: bool, - pmull: bool, - sha1: bool, - sha2: bool, - crc32: bool, - atomics: bool, - fphp: bool, - asimdhp: bool, - // cpuid: No LLVM support. - asimdrdm: bool, - jscvt: bool, - fcma: bool, - lrcpc: bool, - dcpop: bool, - sha3: bool, - sm3: bool, - sm4: bool, - asimddp: bool, - sha512: bool, - sve: bool, - fhm: bool, - dit: bool, - uscat: bool, - ilrcpc: bool, - flagm: bool, - ssbs: bool, - sb: bool, - paca: bool, - pacg: bool, + pub fp: bool, + pub asimd: bool, + // pub evtstrm: No LLVM support. + pub aes: bool, + pub pmull: bool, + pub sha1: bool, + pub sha2: bool, + pub crc32: bool, + pub atomics: bool, + pub fphp: bool, + pub asimdhp: bool, + // pub cpuid: No LLVM support. + pub asimdrdm: bool, + pub jscvt: bool, + pub fcma: bool, + pub lrcpc: bool, + pub dcpop: bool, + pub sha3: bool, + pub sm3: bool, + pub sm4: bool, + pub asimddp: bool, + pub sha512: bool, + pub sve: bool, + pub fhm: bool, + pub dit: bool, + pub uscat: bool, + pub ilrcpc: bool, + pub flagm: bool, + pub ssbs: bool, + pub sb: bool, + pub paca: bool, + pub pacg: bool, // AT_HWCAP2 - dcpodp: bool, - sve2: bool, - sveaes: bool, - svepmull: bool, - svebitperm: bool, - svesha3: bool, - svesm4: bool, - flagm2: bool, - frint: bool, - // svei8mm: See i8mm feature. - svef32mm: bool, - svef64mm: bool, - // svebf16: See bf16 feature. - i8mm: bool, - bf16: bool, - // dgh: No LLVM support. - rng: bool, - bti: bool, - mte: bool, - ecv: bool, - // afp: bool, - // rpres: bool, - // mte3: bool, - sme: bool, - smei16i64: bool, - smef64f64: bool, - // smei8i32: bool, - // smef16f32: bool, - // smeb16f32: bool, - // smef32f32: bool, - smefa64: bool, - wfxt: bool, - // ebf16: bool, - // sveebf16: bool, - cssc: bool, - // rprfm: bool, - sve2p1: bool, - sme2: bool, - sme2p1: bool, - // smei16i32: bool, - // smebi32i32: bool, - smeb16b16: bool, - smef16f16: bool, - mops: bool, - hbc: bool, - sveb16b16: bool, - lrcpc3: bool, - lse128: bool, - fpmr: bool, - lut: bool, - faminmax: bool, - f8cvt: bool, - f8fma: bool, - f8dp4: bool, - f8dp2: bool, - f8e4m3: bool, - f8e5m2: bool, - smelutv2: bool, - smef8f16: bool, - smef8f32: bool, - smesf8fma: bool, - smesf8dp4: bool, - smesf8dp2: bool, - // pauthlr: bool, + pub dcpodp: bool, + pub sve2: bool, + pub sveaes: bool, + pub svepmull: bool, + pub svebitperm: bool, + pub svesha3: bool, + pub svesm4: bool, + pub flagm2: bool, + pub frint: bool, + // pub svei8mm: See i8mm feature. + pub svef32mm: bool, + pub svef64mm: bool, + // pub svebf16: See bf16 feature. + pub i8mm: bool, + pub bf16: bool, + // pub dgh: No LLVM support. + pub rng: bool, + pub bti: bool, + pub mte: bool, + pub ecv: bool, + // pub afp: bool, + // pub rpres: bool, + // pub mte3: bool, + pub sme: bool, + pub smei16i64: bool, + pub smef64f64: bool, + // pub smei8i32: bool, + // pub smef16f32: bool, + // pub smeb16f32: bool, + // pub smef32f32: bool, + pub smefa64: bool, + pub wfxt: bool, + // pub ebf16: bool, + // pub sveebf16: bool, + pub cssc: bool, + // pub rprfm: bool, + pub sve2p1: bool, + pub sme2: bool, + pub sme2p1: bool, + // pub smei16i32: bool, + // pub smebi32i32: bool, + pub smeb16b16: bool, + pub smef16f16: bool, + pub mops: bool, + pub hbc: bool, + pub sveb16b16: bool, + pub lrcpc3: bool, + pub lse128: bool, + pub fpmr: bool, + pub lut: bool, + pub faminmax: bool, + pub f8cvt: bool, + pub f8fma: bool, + pub f8dp4: bool, + pub f8dp2: bool, + pub f8e4m3: bool, + pub f8e5m2: bool, + pub smelutv2: bool, + pub smef8f16: bool, + pub smef8f32: bool, + pub smesf8fma: bool, + pub smesf8dp4: bool, + pub smesf8dp2: bool, + // pub pauthlr: bool, } impl From for AtHwcap { @@ -403,7 +403,3 @@ impl AtHwcap { value } } - -#[cfg(target_endian = "little")] -#[cfg(test)] -mod tests; diff --git a/library/std_detect/src/detect/os/linux/auxvec.rs b/library/std_detect/src/detect/os/linux/auxvec.rs index c0bbc7d4efa88..2a5d475b5f403 100644 --- a/library/std_detect/src/detect/os/linux/auxvec.rs +++ b/library/std_detect/src/detect/os/linux/auxvec.rs @@ -20,8 +20,8 @@ pub(crate) const AT_HWCAP2: usize = 26; /// If an entry cannot be read all the bits in the bitfield are set to zero. /// This should be interpreted as all the features being disabled. #[derive(Debug, Copy, Clone)] -#[cfg_attr(test, derive(PartialEq))] -pub(crate) struct AuxVec { +#[derive(PartialEq)] +pub struct AuxVec { pub hwcap: usize, #[cfg(any( target_arch = "aarch64", @@ -68,7 +68,7 @@ pub(crate) struct AuxVec { /// [auxvec_h]: https://github.com/torvalds/linux/blob/master/include/uapi/linux/auxvec.h /// [auxv_docs]: https://docs.rs/auxv/0.3.3/auxv/ /// [`getauxval`]: https://man7.org/linux/man-pages/man3/getauxval.3.html -pub(crate) fn auxv() -> Result { +pub fn auxv() -> Result { // Try to call a getauxval function. if let Ok(hwcap) = getauxval(AT_HWCAP) { // Targets with only AT_HWCAP: @@ -146,13 +146,9 @@ fn getauxval(key: usize) -> Result { /// Tries to read the auxiliary vector from the `file`. If this fails, this /// function returns `Err`. -pub(super) fn auxv_from_file(file: &str) -> Result { - let file = super::read_file(file)?; - auxv_from_file_bytes(&file) -} +pub fn auxv_from_file(file: &str) -> Result { + let bytes = super::read_file(file)?; -/// Read auxiliary vector from a slice of bytes. -pub(super) fn auxv_from_file_bytes(bytes: &[u8]) -> Result { // See . // // The auxiliary vector contains at most 34 (key,value) fields: from @@ -216,6 +212,3 @@ fn auxv_from_buf(buf: &[usize]) -> Result { let _ = buf; Err(alloc::string::String::from("hwcap not found")) } - -#[cfg(test)] -mod tests; diff --git a/library/std_detect/src/detect/os/linux/mod.rs b/library/std_detect/src/detect/os/linux/mod.rs index aec94f963f5c1..fe810597bc745 100644 --- a/library/std_detect/src/detect/os/linux/mod.rs +++ b/library/std_detect/src/detect/os/linux/mod.rs @@ -2,7 +2,7 @@ use alloc::vec::Vec; -mod auxvec; +pub(super) mod auxvec; fn read_file(orig_path: &str) -> Result, alloc::string::String> { use alloc::format; @@ -37,7 +37,7 @@ fn read_file(orig_path: &str) -> Result, alloc::string::String> { cfg_select! { target_arch = "aarch64" => { - mod aarch64; + pub(super) mod aarch64; pub(crate) use self::aarch64::detect_features; } target_arch = "arm" => { diff --git a/library/std_detect/src/detect/os/riscv.rs b/library/std_detect/src/detect/os/riscv.rs index 9b9e0cba09d1c..1c59cb50e02c9 100644 --- a/library/std_detect/src/detect/os/riscv.rs +++ b/library/std_detect/src/detect/os/riscv.rs @@ -18,7 +18,7 @@ use crate::detect::{Feature, cache}; /// conflicting extensions and/or complicated requirements. Eliminating such /// inconsistencies is the responsibility of the feature detection logic and /// its provider(s). -pub(crate) fn imply_features(mut value: cache::Initializer) -> cache::Initializer { +pub fn imply_features(mut value: cache::Initializer) -> cache::Initializer { loop { // Check convergence of the feature flags later. let prev = value; @@ -153,7 +153,3 @@ pub(crate) fn imply_features(mut value: cache::Initializer) -> cache::Initialize } } } - -#[cfg(test)] -#[path = "riscv/tests.rs"] -mod tests; diff --git a/library/std_detect_tests/Cargo.toml b/library/std_detect_tests/Cargo.toml new file mode 100644 index 0000000000000..c908720e6125b --- /dev/null +++ b/library/std_detect_tests/Cargo.toml @@ -0,0 +1,6 @@ +[package] +name = "std_detect_tests" +version = "0.0.0" +license = "MIT OR Apache-2.0" +description = "Tests for std_detect" +edition = "2024" diff --git a/library/std_detect/src/detect/test_data/linux-artificial-aarch64.auxv b/library/std_detect_tests/test_data/linux-artificial-aarch64.auxv similarity index 100% rename from library/std_detect/src/detect/test_data/linux-artificial-aarch64.auxv rename to library/std_detect_tests/test_data/linux-artificial-aarch64.auxv diff --git a/library/std_detect/src/detect/test_data/linux-empty-hwcap2-aarch64.auxv b/library/std_detect_tests/test_data/linux-empty-hwcap2-aarch64.auxv similarity index 100% rename from library/std_detect/src/detect/test_data/linux-empty-hwcap2-aarch64.auxv rename to library/std_detect_tests/test_data/linux-empty-hwcap2-aarch64.auxv diff --git a/library/std_detect/src/detect/test_data/linux-hwcap2-aarch64.auxv b/library/std_detect_tests/test_data/linux-hwcap2-aarch64.auxv similarity index 100% rename from library/std_detect/src/detect/test_data/linux-hwcap2-aarch64.auxv rename to library/std_detect_tests/test_data/linux-hwcap2-aarch64.auxv diff --git a/library/std_detect/src/detect/test_data/linux-no-hwcap2-aarch64.auxv b/library/std_detect_tests/test_data/linux-no-hwcap2-aarch64.auxv similarity index 100% rename from library/std_detect/src/detect/test_data/linux-no-hwcap2-aarch64.auxv rename to library/std_detect_tests/test_data/linux-no-hwcap2-aarch64.auxv diff --git a/library/std_detect/src/detect/test_data/linux-rpi3.auxv b/library/std_detect_tests/test_data/linux-rpi3.auxv similarity index 100% rename from library/std_detect/src/detect/test_data/linux-rpi3.auxv rename to library/std_detect_tests/test_data/linux-rpi3.auxv diff --git a/library/std_detect/src/detect/test_data/macos-virtualbox-linux-x86-4850HQ.auxv b/library/std_detect_tests/test_data/macos-virtualbox-linux-x86-4850HQ.auxv similarity index 100% rename from library/std_detect/src/detect/test_data/macos-virtualbox-linux-x86-4850HQ.auxv rename to library/std_detect_tests/test_data/macos-virtualbox-linux-x86-4850HQ.auxv diff --git a/library/std_detect/src/detect/os/linux/auxvec/tests.rs b/library/std_detect_tests/tests/auxvec.rs similarity index 77% rename from library/std_detect/src/detect/os/linux/auxvec/tests.rs rename to library/std_detect_tests/tests/auxvec.rs index 88f0d6d493376..4b7de8c06480b 100644 --- a/library/std_detect/src/detect/os/linux/auxvec/tests.rs +++ b/library/std_detect_tests/tests/auxvec.rs @@ -1,4 +1,9 @@ -use super::*; +#![allow(internal_features)] +#![feature(cfg_select, stdarch_internal)] + +extern crate std_detect; + +use std_detect::detect::__test_os::{auxv, auxv_from_file}; // FIXME: on mips/mips64 getauxval returns 0, and /proc/self/auxv // does not always contain the AT_HWCAP key under qemu. @@ -47,17 +52,17 @@ cfg_select! { // files on disk, so we need to embed them with `include_bytes!`. #[test] fn linux_rpi3() { - let auxv = include_bytes!(concat!(env!("CARGO_MANIFEST_DIR"), "/src/detect/test_data/linux-rpi3.auxv")); - let v = auxv_from_file_bytes(auxv).unwrap(); + let file = concat!(env!("CARGO_MANIFEST_DIR"), "/test_data/linux-rpi3.auxv"); + let v = auxv_from_file(file).unwrap(); assert_eq!(v.hwcap, 4174038); assert_eq!(v.hwcap2, 16); } #[test] fn linux_macos_vb() { - let auxv = include_bytes!(concat!(env!("CARGO_MANIFEST_DIR"), "/src/detect/test_data/macos-virtualbox-linux-x86-4850HQ.auxv")); + let file = concat!(env!("CARGO_MANIFEST_DIR"), "/test_data/macos-virtualbox-linux-x86-4850HQ.auxv"); // The file contains HWCAP but not HWCAP2. In that case, we treat HWCAP2 as zero. - let v = auxv_from_file_bytes(auxv).unwrap(); + let v = auxv_from_file(file).unwrap(); assert_eq!(v.hwcap, 126614527); assert_eq!(v.hwcap2, 0); } @@ -66,16 +71,16 @@ cfg_select! { #[cfg(target_endian = "little")] #[test] fn linux_artificial_aarch64() { - let auxv = include_bytes!(concat!(env!("CARGO_MANIFEST_DIR"), "/src/detect/test_data/linux-artificial-aarch64.auxv")); - let v = auxv_from_file_bytes(auxv).unwrap(); + let file = concat!(env!("CARGO_MANIFEST_DIR"), "/test_data/linux-artificial-aarch64.auxv"); + let v = auxv_from_file(file).unwrap(); assert_eq!(v.hwcap, 0x0123456789abcdef); assert_eq!(v.hwcap2, 0x02468ace13579bdf); } #[cfg(target_endian = "little")] #[test] fn linux_no_hwcap2_aarch64() { - let auxv = include_bytes!(concat!(env!("CARGO_MANIFEST_DIR"), "/src/detect/test_data/linux-no-hwcap2-aarch64.auxv")); - let v = auxv_from_file_bytes(auxv).unwrap(); + let file = concat!(env!("CARGO_MANIFEST_DIR"), "/test_data/linux-no-hwcap2-aarch64.auxv"); + let v = auxv_from_file(file).unwrap(); // An absent HWCAP2 is treated as zero, and does not prevent acceptance of HWCAP. assert_ne!(v.hwcap, 0); assert_eq!(v.hwcap2, 0); diff --git a/library/std_detect/tests/cpu-detection.rs b/library/std_detect_tests/tests/cpu-detection.rs similarity index 100% rename from library/std_detect/tests/cpu-detection.rs rename to library/std_detect_tests/tests/cpu-detection.rs diff --git a/library/std_detect/src/detect/os/linux/aarch64/tests.rs b/library/std_detect_tests/tests/linux_aarch64.rs similarity index 73% rename from library/std_detect/src/detect/os/linux/aarch64/tests.rs rename to library/std_detect_tests/tests/linux_aarch64.rs index 4d7c9a419d386..3062f73b389ff 100644 --- a/library/std_detect/src/detect/os/linux/aarch64/tests.rs +++ b/library/std_detect_tests/tests/linux_aarch64.rs @@ -1,5 +1,15 @@ -use super::auxvec::auxv_from_file; -use super::*; +#![cfg(all( + any(target_os = "linux", target_os = "android"), + target_arch = "aarch64", + target_endian = "little" +))] +#![allow(internal_features)] +#![feature(stdarch_internal)] + +extern crate std_detect; + +use std_detect::detect::__test_os::{AtHwcap, auxv_from_file}; + // The baseline hwcaps used in the (artificial) auxv test files. fn baseline_hwcaps() -> AtHwcap { AtHwcap { @@ -24,10 +34,7 @@ fn baseline_hwcaps() -> AtHwcap { #[test] fn linux_empty_hwcap2_aarch64() { - let file = concat!( - env!("CARGO_MANIFEST_DIR"), - "/src/detect/test_data/linux-empty-hwcap2-aarch64.auxv" - ); + let file = concat!(env!("CARGO_MANIFEST_DIR"), "/test_data/linux-empty-hwcap2-aarch64.auxv"); println!("file: {file}"); let v = auxv_from_file(file).unwrap(); println!("HWCAP : 0x{:0x}", v.hwcap); @@ -36,8 +43,7 @@ fn linux_empty_hwcap2_aarch64() { } #[test] fn linux_no_hwcap2_aarch64() { - let file = - concat!(env!("CARGO_MANIFEST_DIR"), "/src/detect/test_data/linux-no-hwcap2-aarch64.auxv"); + let file = concat!(env!("CARGO_MANIFEST_DIR"), "/test_data/linux-no-hwcap2-aarch64.auxv"); println!("file: {file}"); let v = auxv_from_file(file).unwrap(); println!("HWCAP : 0x{:0x}", v.hwcap); @@ -46,8 +52,7 @@ fn linux_no_hwcap2_aarch64() { } #[test] fn linux_hwcap2_aarch64() { - let file = - concat!(env!("CARGO_MANIFEST_DIR"), "/src/detect/test_data/linux-hwcap2-aarch64.auxv"); + let file = concat!(env!("CARGO_MANIFEST_DIR"), "/test_data/linux-hwcap2-aarch64.auxv"); println!("file: {file}"); let v = auxv_from_file(file).unwrap(); println!("HWCAP : 0x{:0x}", v.hwcap); diff --git a/library/std_detect/tests/macro_trailing_commas.rs b/library/std_detect_tests/tests/macro_trailing_commas.rs similarity index 100% rename from library/std_detect/tests/macro_trailing_commas.rs rename to library/std_detect_tests/tests/macro_trailing_commas.rs diff --git a/library/std_detect/src/detect/os/riscv/tests.rs b/library/std_detect_tests/tests/riscv.rs similarity index 76% rename from library/std_detect/src/detect/os/riscv/tests.rs rename to library/std_detect_tests/tests/riscv.rs index 99a81dee05a6c..417fb6a35d93c 100644 --- a/library/std_detect/src/detect/os/riscv/tests.rs +++ b/library/std_detect_tests/tests/riscv.rs @@ -1,8 +1,15 @@ -use super::*; +#![cfg(any(target_arch = "riscv32", target_arch = "riscv64"))] +#![allow(internal_features)] +#![feature(stdarch_internal)] + +extern crate std_detect; + +use std_detect::detect::__test::{Feature, Initializer}; +use std_detect::detect::__test_os::imply_features; #[test] fn simple_direct() { - let mut value = cache::Initializer::default(); + let mut value = Initializer::default(); value.set(Feature::f as u32); // F (and other extensions with CSRs) -> Zicsr assert!(imply_features(value).test(Feature::zicsr as u32)); @@ -10,7 +17,7 @@ fn simple_direct() { #[test] fn simple_indirect() { - let mut value = cache::Initializer::default(); + let mut value = Initializer::default(); value.set(Feature::q as u32); // Q -> D, D -> F, F -> Zicsr assert!(imply_features(value).test(Feature::zicsr as u32)); @@ -18,7 +25,7 @@ fn simple_indirect() { #[test] fn complex_zcd() { - let mut value = cache::Initializer::default(); + let mut value = Initializer::default(); // C & D -> Zcd value.set(Feature::c as u32); assert!(!imply_features(value).test(Feature::zcd as u32)); @@ -28,7 +35,7 @@ fn complex_zcd() { #[test] fn group_simple_forward() { - let mut value = cache::Initializer::default(); + let mut value = Initializer::default(); // A -> Zalrsc & Zaamo (forward implication) value.set(Feature::a as u32); let value = imply_features(value); @@ -38,7 +45,7 @@ fn group_simple_forward() { #[test] fn group_simple_backward() { - let mut value = cache::Initializer::default(); + let mut value = Initializer::default(); // Zalrsc & Zaamo -> A (reverse implication) value.set(Feature::zalrsc as u32); value.set(Feature::zaamo as u32); @@ -47,7 +54,7 @@ fn group_simple_backward() { #[test] fn group_complex_convergence() { - let mut value = cache::Initializer::default(); + let mut value = Initializer::default(); // Needs 3 iterations to converge // (and 4th iteration for convergence checking): // 1. [Zvksc] -> Zvks & Zvbc diff --git a/library/std_detect/tests/x86-specific.rs b/library/std_detect_tests/tests/x86-specific.rs similarity index 100% rename from library/std_detect/tests/x86-specific.rs rename to library/std_detect_tests/tests/x86-specific.rs diff --git a/src/bootstrap/src/core/build_steps/check.rs b/src/bootstrap/src/core/build_steps/check.rs index f983c59f9bf8c..73b16a1cbf96c 100644 --- a/src/bootstrap/src/core/build_steps/check.rs +++ b/src/bootstrap/src/core/build_steps/check.rs @@ -33,7 +33,7 @@ pub struct Std { } impl Std { - const CRATE_OR_DEPS: &[&str] = &["sysroot", "coretests", "alloctests"]; + const CRATE_OR_DEPS: &[&str] = &["sysroot", "coretests", "alloctests", "std_detect_tests"]; } impl Step for Std { diff --git a/src/bootstrap/src/core/build_steps/test.rs b/src/bootstrap/src/core/build_steps/test.rs index f3a1c6b0e3dde..1c76e9643b697 100644 --- a/src/bootstrap/src/core/build_steps/test.rs +++ b/src/bootstrap/src/core/build_steps/test.rs @@ -3005,7 +3005,10 @@ impl Step for Crate { type Output = (); fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> { - run.crate_or_deps("sysroot").crate_or_deps("coretests").crate_or_deps("alloctests") + run.crate_or_deps("sysroot") + .crate_or_deps("coretests") + .crate_or_deps("alloctests") + .crate_or_deps("std_detect_tests") } fn is_default_step(_builder: &Builder<'_>) -> bool { @@ -3125,6 +3128,9 @@ impl Step for Crate { if crates.iter().any(|crate_| crate_ == "alloc") { crates.push("alloctests".to_owned()); } + if crates.iter().any(|crate_| crate_ == "std_detect") { + crates.push("std_detect_tests".to_owned()); + } run_cargo_test(cargo, &[], &crates, &*crate_description(&self.crates), target, builder); } diff --git a/src/bootstrap/src/core/builder/cli_paths/snapshots/x_bench.snap b/src/bootstrap/src/core/builder/cli_paths/snapshots/x_bench.snap index 8a7815487913e..504f954b29951 100644 --- a/src/bootstrap/src/core/builder/cli_paths/snapshots/x_bench.snap +++ b/src/bootstrap/src/core/builder/cli_paths/snapshots/x_bench.snap @@ -15,6 +15,7 @@ expression: bench - Set({bench::library/rustc-std-workspace-core}) - Set({bench::library/std}) - Set({bench::library/std_detect}) + - Set({bench::library/std_detect_tests}) - Set({bench::library/sysroot}) - Set({bench::library/test}) - Set({bench::library/unwind}) diff --git a/src/bootstrap/src/core/builder/cli_paths/snapshots/x_check.snap b/src/bootstrap/src/core/builder/cli_paths/snapshots/x_check.snap index 0fe26fac57fc5..d7bbe88cfb457 100644 --- a/src/bootstrap/src/core/builder/cli_paths/snapshots/x_check.snap +++ b/src/bootstrap/src/core/builder/cli_paths/snapshots/x_check.snap @@ -129,6 +129,7 @@ expression: check - Set({check::library/rustc-std-workspace-core}) - Set({check::library/std}) - Set({check::library/std_detect}) + - Set({check::library/std_detect_tests}) - Set({check::library/sysroot}) - Set({check::library/test}) - Set({check::library/unwind}) diff --git a/src/bootstrap/src/core/builder/cli_paths/snapshots/x_check_compiletest_include_default_paths.snap b/src/bootstrap/src/core/builder/cli_paths/snapshots/x_check_compiletest_include_default_paths.snap index dae515c67ec6d..56af0b77bf3c3 100644 --- a/src/bootstrap/src/core/builder/cli_paths/snapshots/x_check_compiletest_include_default_paths.snap +++ b/src/bootstrap/src/core/builder/cli_paths/snapshots/x_check_compiletest_include_default_paths.snap @@ -129,6 +129,7 @@ expression: check compiletest --include-default-paths - Set({check::library/rustc-std-workspace-core}) - Set({check::library/std}) - Set({check::library/std_detect}) + - Set({check::library/std_detect_tests}) - Set({check::library/sysroot}) - Set({check::library/test}) - Set({check::library/unwind}) diff --git a/src/bootstrap/src/core/builder/cli_paths/snapshots/x_check_library.snap b/src/bootstrap/src/core/builder/cli_paths/snapshots/x_check_library.snap index 1a41aa98555b6..e1ef04dcf2669 100644 --- a/src/bootstrap/src/core/builder/cli_paths/snapshots/x_check_library.snap +++ b/src/bootstrap/src/core/builder/cli_paths/snapshots/x_check_library.snap @@ -16,6 +16,7 @@ expression: check library - Set({check::library/rustc-std-workspace-core}) - Set({check::library/std}) - Set({check::library/std_detect}) + - Set({check::library/std_detect_tests}) - Set({check::library/sysroot}) - Set({check::library/test}) - Set({check::library/unwind}) diff --git a/src/bootstrap/src/core/builder/cli_paths/snapshots/x_fix.snap b/src/bootstrap/src/core/builder/cli_paths/snapshots/x_fix.snap index 222c0ffb40503..d7a8b466fc80e 100644 --- a/src/bootstrap/src/core/builder/cli_paths/snapshots/x_fix.snap +++ b/src/bootstrap/src/core/builder/cli_paths/snapshots/x_fix.snap @@ -129,6 +129,7 @@ expression: fix - Set({fix::library/rustc-std-workspace-core}) - Set({fix::library/std}) - Set({fix::library/std_detect}) + - Set({fix::library/std_detect_tests}) - Set({fix::library/sysroot}) - Set({fix::library/test}) - Set({fix::library/unwind}) diff --git a/src/bootstrap/src/core/builder/cli_paths/snapshots/x_miri.snap b/src/bootstrap/src/core/builder/cli_paths/snapshots/x_miri.snap index 552697b378bcc..e61249a6e7f34 100644 --- a/src/bootstrap/src/core/builder/cli_paths/snapshots/x_miri.snap +++ b/src/bootstrap/src/core/builder/cli_paths/snapshots/x_miri.snap @@ -15,6 +15,7 @@ expression: miri - Set({miri::library/rustc-std-workspace-core}) - Set({miri::library/std}) - Set({miri::library/std_detect}) + - Set({miri::library/std_detect_tests}) - Set({miri::library/sysroot}) - Set({miri::library/test}) - Set({miri::library/unwind}) diff --git a/src/bootstrap/src/core/builder/cli_paths/snapshots/x_test.snap b/src/bootstrap/src/core/builder/cli_paths/snapshots/x_test.snap index 4ab84c3cabc1a..70271cab48bf5 100644 --- a/src/bootstrap/src/core/builder/cli_paths/snapshots/x_test.snap +++ b/src/bootstrap/src/core/builder/cli_paths/snapshots/x_test.snap @@ -65,6 +65,7 @@ expression: test - Set({test::library/rustc-std-workspace-core}) - Set({test::library/std}) - Set({test::library/std_detect}) + - Set({test::library/std_detect_tests}) - Set({test::library/sysroot}) - Set({test::library/test}) - Set({test::library/unwind}) diff --git a/src/bootstrap/src/core/builder/cli_paths/snapshots/x_test_library.snap b/src/bootstrap/src/core/builder/cli_paths/snapshots/x_test_library.snap index dfc397597a877..b74912ce7f460 100644 --- a/src/bootstrap/src/core/builder/cli_paths/snapshots/x_test_library.snap +++ b/src/bootstrap/src/core/builder/cli_paths/snapshots/x_test_library.snap @@ -15,6 +15,7 @@ expression: test library - Set({test::library/rustc-std-workspace-core}) - Set({test::library/std}) - Set({test::library/std_detect}) + - Set({test::library/std_detect_tests}) - Set({test::library/sysroot}) - Set({test::library/test}) - Set({test::library/unwind}) diff --git a/src/bootstrap/src/core/builder/cli_paths/snapshots/x_test_skip_coverage.snap b/src/bootstrap/src/core/builder/cli_paths/snapshots/x_test_skip_coverage.snap index 2a4805e4fd687..bba6987da7b06 100644 --- a/src/bootstrap/src/core/builder/cli_paths/snapshots/x_test_skip_coverage.snap +++ b/src/bootstrap/src/core/builder/cli_paths/snapshots/x_test_skip_coverage.snap @@ -64,6 +64,7 @@ expression: test --skip=coverage - Set({test::library/rustc-std-workspace-core}) - Set({test::library/std}) - Set({test::library/std_detect}) + - Set({test::library/std_detect_tests}) - Set({test::library/sysroot}) - Set({test::library/test}) - Set({test::library/unwind}) diff --git a/src/bootstrap/src/core/builder/cli_paths/snapshots/x_test_skip_tests.snap b/src/bootstrap/src/core/builder/cli_paths/snapshots/x_test_skip_tests.snap index 1468964c78189..fcd5e0da39ccf 100644 --- a/src/bootstrap/src/core/builder/cli_paths/snapshots/x_test_skip_tests.snap +++ b/src/bootstrap/src/core/builder/cli_paths/snapshots/x_test_skip_tests.snap @@ -1,6 +1,5 @@ --- source: src/bootstrap/src/core/builder/cli_paths/tests.rs -assertion_line: 68 expression: test --skip=tests --- [Test] test::Tidy @@ -29,6 +28,7 @@ expression: test --skip=tests - Set({test::library/rustc-std-workspace-core}) - Set({test::library/std}) - Set({test::library/std_detect}) + - Set({test::library/std_detect_tests}) - Set({test::library/sysroot}) - Set({test::library/test}) - Set({test::library/unwind}) diff --git a/src/tools/tidy/src/unit_tests.rs b/src/tools/tidy/src/unit_tests.rs index 74b6c4a3845a6..7d36797b270e0 100644 --- a/src/tools/tidy/src/unit_tests.rs +++ b/src/tools/tidy/src/unit_tests.rs @@ -3,7 +3,7 @@ //! //! `core` and `alloc` cannot be tested directly due to duplicating lang items. //! All tests and benchmarks must be written externally in -//! `{coretests,alloctests}/{tests,benches}`. +//! `*tests/{tests,benches}`. //! //! Outside of the standard library, tests and benchmarks should be outlined //! into separate files named `tests.rs` or `benches.rs`, or directories named @@ -52,7 +52,7 @@ pub fn check(root_path: &Path, stdlib: bool, tidy_ctx: TidyCtx) { if is_dir { // FIXME remove those exceptions once no longer necessary - file_name == "std_detect" || file_name == "std" || file_name == "test" + file_name == "std" || file_name == "test" } else { // Tests which use non-public internals and, as such, need to // have the types in the same crate as the tests themselves. See