Skip to content

Commit de9b57a

Browse files
committed
Move all std_detect unit tests to integration tests
1 parent 6decb69 commit de9b57a

11 files changed

Lines changed: 147 additions & 130 deletions

File tree

library/std_detect/src/detect/arch/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ cfg_select! {
6666
_ => {
6767
// Unimplemented architecture:
6868
#[doc(hidden)]
69-
pub(crate) enum Feature {
69+
pub enum Feature {
7070
Null
7171
}
7272
#[doc(hidden)]

library/std_detect/src/detect/cache.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,21 +30,21 @@ const CACHE_CAPACITY: u32 = 93;
3030
// The derived `Default` implementation will initialize the field to zero,
3131
// which is what we want.
3232
#[derive(Copy, Clone, Default, PartialEq, Eq)]
33-
pub(crate) struct Initializer(u128);
33+
pub struct Initializer(u128);
3434

3535
// NOTE: the `debug_assert!` would catch that we do not add more Features than
3636
// the one fitting our cache.
3737
impl Initializer {
3838
/// Tests the `bit` of the cache.
3939
#[inline]
40-
pub(crate) fn test(self, bit: u32) -> bool {
40+
pub fn test(self, bit: u32) -> bool {
4141
debug_assert!(bit < CACHE_CAPACITY, "too many features, time to increase the cache size!");
4242
test_bit(self.0, bit)
4343
}
4444

4545
/// Sets the `bit` of the cache.
4646
#[inline]
47-
pub(crate) fn set(&mut self, bit: u32) {
47+
pub fn set(&mut self, bit: u32) {
4848
debug_assert!(bit < CACHE_CAPACITY, "too many features, time to increase the cache size!");
4949
let v = self.0;
5050
self.0 = set_bit(v, bit);

library/std_detect/src/detect/macros.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ macro_rules! features {
149149
#[repr(u8)]
150150
#[unstable(feature = "stdarch_internal", issue = "none")]
151151
#[cfg($cfg)]
152-
pub(crate) enum Feature {
152+
pub enum Feature {
153153
$(
154154
$(#[$feature_comment])*
155155
$feature,

library/std_detect/src/detect/mod.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,11 @@ pub(crate) use self::arch::Feature;
3232
mod bit;
3333
mod cache;
3434

35+
pub mod __test {
36+
pub use super::arch::Feature;
37+
pub use super::cache::Initializer;
38+
}
39+
3540
cfg_select! {
3641
miri => {
3742
// When running under miri all target-features that are not enabled at
@@ -53,6 +58,14 @@ cfg_select! {
5358
mod riscv;
5459
#[path = "os/linux/mod.rs"]
5560
mod os;
61+
#[unstable(feature = "stdarch_internal", issue = "none")]
62+
pub mod __test_os {
63+
#[cfg(any(target_arch = "riscv32", target_arch = "riscv64"))]
64+
pub use super::riscv::imply_features;
65+
#[cfg(target_arch = "aarch64")]
66+
pub use super::os::aarch64::AtHwcap;
67+
pub use super::os::auxvec::{auxv, auxv_from_file};
68+
}
5669
}
5770
target_os = "freebsd" => {
5871
#[cfg(target_arch = "aarch64")]

library/std_detect/src/detect/os/linux/aarch64.rs

Lines changed: 97 additions & 101 deletions
Original file line numberDiff line numberDiff line change
@@ -35,106 +35,106 @@ pub(crate) fn detect_features() -> cache::Initializer {
3535
///
3636
/// [hwcap]: https://github.com/torvalds/linux/blob/master/arch/arm64/include/uapi/asm/hwcap.h
3737
#[derive(Debug, Default, PartialEq)]
38-
struct AtHwcap {
38+
pub struct AtHwcap {
3939
// AT_HWCAP
40-
fp: bool,
41-
asimd: bool,
42-
// evtstrm: No LLVM support.
43-
aes: bool,
44-
pmull: bool,
45-
sha1: bool,
46-
sha2: bool,
47-
crc32: bool,
48-
atomics: bool,
49-
fphp: bool,
50-
asimdhp: bool,
51-
// cpuid: No LLVM support.
52-
asimdrdm: bool,
53-
jscvt: bool,
54-
fcma: bool,
55-
lrcpc: bool,
56-
dcpop: bool,
57-
sha3: bool,
58-
sm3: bool,
59-
sm4: bool,
60-
asimddp: bool,
61-
sha512: bool,
62-
sve: bool,
63-
fhm: bool,
64-
dit: bool,
65-
uscat: bool,
66-
ilrcpc: bool,
67-
flagm: bool,
68-
ssbs: bool,
69-
sb: bool,
70-
paca: bool,
71-
pacg: bool,
40+
pub fp: bool,
41+
pub asimd: bool,
42+
// pub evtstrm: No LLVM support.
43+
pub aes: bool,
44+
pub pmull: bool,
45+
pub sha1: bool,
46+
pub sha2: bool,
47+
pub crc32: bool,
48+
pub atomics: bool,
49+
pub fphp: bool,
50+
pub asimdhp: bool,
51+
// pub cpuid: No LLVM support.
52+
pub asimdrdm: bool,
53+
pub jscvt: bool,
54+
pub fcma: bool,
55+
pub lrcpc: bool,
56+
pub dcpop: bool,
57+
pub sha3: bool,
58+
pub sm3: bool,
59+
pub sm4: bool,
60+
pub asimddp: bool,
61+
pub sha512: bool,
62+
pub sve: bool,
63+
pub fhm: bool,
64+
pub dit: bool,
65+
pub uscat: bool,
66+
pub ilrcpc: bool,
67+
pub flagm: bool,
68+
pub ssbs: bool,
69+
pub sb: bool,
70+
pub paca: bool,
71+
pub pacg: bool,
7272

7373
// AT_HWCAP2
74-
dcpodp: bool,
75-
sve2: bool,
76-
sveaes: bool,
77-
svepmull: bool,
78-
svebitperm: bool,
79-
svesha3: bool,
80-
svesm4: bool,
81-
flagm2: bool,
82-
frint: bool,
83-
// svei8mm: See i8mm feature.
84-
svef32mm: bool,
85-
svef64mm: bool,
86-
// svebf16: See bf16 feature.
87-
i8mm: bool,
88-
bf16: bool,
89-
// dgh: No LLVM support.
90-
rng: bool,
91-
bti: bool,
92-
mte: bool,
93-
ecv: bool,
94-
// afp: bool,
95-
// rpres: bool,
96-
// mte3: bool,
97-
sme: bool,
98-
smei16i64: bool,
99-
smef64f64: bool,
100-
// smei8i32: bool,
101-
// smef16f32: bool,
102-
// smeb16f32: bool,
103-
// smef32f32: bool,
104-
smefa64: bool,
105-
wfxt: bool,
106-
// ebf16: bool,
107-
// sveebf16: bool,
108-
cssc: bool,
109-
// rprfm: bool,
110-
sve2p1: bool,
111-
sme2: bool,
112-
sme2p1: bool,
113-
// smei16i32: bool,
114-
// smebi32i32: bool,
115-
smeb16b16: bool,
116-
smef16f16: bool,
117-
mops: bool,
118-
hbc: bool,
119-
sveb16b16: bool,
120-
lrcpc3: bool,
121-
lse128: bool,
122-
fpmr: bool,
123-
lut: bool,
124-
faminmax: bool,
125-
f8cvt: bool,
126-
f8fma: bool,
127-
f8dp4: bool,
128-
f8dp2: bool,
129-
f8e4m3: bool,
130-
f8e5m2: bool,
131-
smelutv2: bool,
132-
smef8f16: bool,
133-
smef8f32: bool,
134-
smesf8fma: bool,
135-
smesf8dp4: bool,
136-
smesf8dp2: bool,
137-
// pauthlr: bool,
74+
pub dcpodp: bool,
75+
pub sve2: bool,
76+
pub sveaes: bool,
77+
pub svepmull: bool,
78+
pub svebitperm: bool,
79+
pub svesha3: bool,
80+
pub svesm4: bool,
81+
pub flagm2: bool,
82+
pub frint: bool,
83+
// pub svei8mm: See i8mm feature.
84+
pub svef32mm: bool,
85+
pub svef64mm: bool,
86+
// pub svebf16: See bf16 feature.
87+
pub i8mm: bool,
88+
pub bf16: bool,
89+
// pub dgh: No LLVM support.
90+
pub rng: bool,
91+
pub bti: bool,
92+
pub mte: bool,
93+
pub ecv: bool,
94+
// pub afp: bool,
95+
// pub rpres: bool,
96+
// pub mte3: bool,
97+
pub sme: bool,
98+
pub smei16i64: bool,
99+
pub smef64f64: bool,
100+
// pub smei8i32: bool,
101+
// pub smef16f32: bool,
102+
// pub smeb16f32: bool,
103+
// pub smef32f32: bool,
104+
pub smefa64: bool,
105+
pub wfxt: bool,
106+
// pub ebf16: bool,
107+
// pub sveebf16: bool,
108+
pub cssc: bool,
109+
// pub rprfm: bool,
110+
pub sve2p1: bool,
111+
pub sme2: bool,
112+
pub sme2p1: bool,
113+
// pub smei16i32: bool,
114+
// pub smebi32i32: bool,
115+
pub smeb16b16: bool,
116+
pub smef16f16: bool,
117+
pub mops: bool,
118+
pub hbc: bool,
119+
pub sveb16b16: bool,
120+
pub lrcpc3: bool,
121+
pub lse128: bool,
122+
pub fpmr: bool,
123+
pub lut: bool,
124+
pub faminmax: bool,
125+
pub f8cvt: bool,
126+
pub f8fma: bool,
127+
pub f8dp4: bool,
128+
pub f8dp2: bool,
129+
pub f8e4m3: bool,
130+
pub f8e5m2: bool,
131+
pub smelutv2: bool,
132+
pub smef8f16: bool,
133+
pub smef8f32: bool,
134+
pub smesf8fma: bool,
135+
pub smesf8dp4: bool,
136+
pub smesf8dp2: bool,
137+
// pub pauthlr: bool,
138138
}
139139

140140
impl From<auxvec::AuxVec> for AtHwcap {
@@ -403,7 +403,3 @@ impl AtHwcap {
403403
value
404404
}
405405
}
406-
407-
#[cfg(target_endian = "little")]
408-
#[cfg(test)]
409-
mod tests;

library/std_detect/src/detect/os/linux/auxvec.rs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ pub(crate) const AT_HWCAP2: usize = 26;
2020
/// If an entry cannot be read all the bits in the bitfield are set to zero.
2121
/// This should be interpreted as all the features being disabled.
2222
#[derive(Debug, Copy, Clone)]
23-
#[cfg_attr(test, derive(PartialEq))]
24-
pub(crate) struct AuxVec {
23+
#[derive(PartialEq)]
24+
pub struct AuxVec {
2525
pub hwcap: usize,
2626
#[cfg(any(
2727
target_arch = "aarch64",
@@ -68,7 +68,7 @@ pub(crate) struct AuxVec {
6868
/// [auxvec_h]: https://github.com/torvalds/linux/blob/master/include/uapi/linux/auxvec.h
6969
/// [auxv_docs]: https://docs.rs/auxv/0.3.3/auxv/
7070
/// [`getauxval`]: https://man7.org/linux/man-pages/man3/getauxval.3.html
71-
pub(crate) fn auxv() -> Result<AuxVec, ()> {
71+
pub fn auxv() -> Result<AuxVec, ()> {
7272
// Try to call a getauxval function.
7373
if let Ok(hwcap) = getauxval(AT_HWCAP) {
7474
// Targets with only AT_HWCAP:
@@ -146,7 +146,7 @@ fn getauxval(key: usize) -> Result<usize, ()> {
146146

147147
/// Tries to read the auxiliary vector from the `file`. If this fails, this
148148
/// function returns `Err`.
149-
pub(super) fn auxv_from_file(file: &str) -> Result<AuxVec, alloc::string::String> {
149+
pub fn auxv_from_file(file: &str) -> Result<AuxVec, alloc::string::String> {
150150
let bytes = super::read_file(file)?;
151151

152152
// See <https://github.com/torvalds/linux/blob/v5.15/include/uapi/linux/auxvec.h>.
@@ -212,6 +212,3 @@ fn auxv_from_buf(buf: &[usize]) -> Result<AuxVec, alloc::string::String> {
212212
let _ = buf;
213213
Err(alloc::string::String::from("hwcap not found"))
214214
}
215-
216-
#[cfg(test)]
217-
mod tests;

library/std_detect/src/detect/os/linux/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
33
use alloc::vec::Vec;
44

5-
mod auxvec;
5+
pub(super) mod auxvec;
66

77
fn read_file(orig_path: &str) -> Result<Vec<u8>, alloc::string::String> {
88
use alloc::format;
@@ -37,7 +37,7 @@ fn read_file(orig_path: &str) -> Result<Vec<u8>, alloc::string::String> {
3737

3838
cfg_select! {
3939
target_arch = "aarch64" => {
40-
mod aarch64;
40+
pub(super) mod aarch64;
4141
pub(crate) use self::aarch64::detect_features;
4242
}
4343
target_arch = "arm" => {

library/std_detect/src/detect/os/riscv.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ use crate::detect::{Feature, cache};
1818
/// conflicting extensions and/or complicated requirements. Eliminating such
1919
/// inconsistencies is the responsibility of the feature detection logic and
2020
/// its provider(s).
21-
pub(crate) fn imply_features(mut value: cache::Initializer) -> cache::Initializer {
21+
pub fn imply_features(mut value: cache::Initializer) -> cache::Initializer {
2222
loop {
2323
// Check convergence of the feature flags later.
2424
let prev = value;
@@ -153,7 +153,3 @@ pub(crate) fn imply_features(mut value: cache::Initializer) -> cache::Initialize
153153
}
154154
}
155155
}
156-
157-
#[cfg(test)]
158-
#[path = "riscv/tests.rs"]
159-
mod tests;

library/std_detect/src/detect/os/linux/auxvec/tests.rs renamed to library/std_detect/tests/auxvec.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
use super::{auxv, auxv_from_file};
1+
#![allow(internal_features)]
2+
#![feature(cfg_select, stdarch_internal)]
3+
4+
use std_detect::detect::__test_os::{auxv, auxv_from_file};
25

36
// FIXME: on mips/mips64 getauxval returns 0, and /proc/self/auxv
47
// does not always contain the AT_HWCAP key under qemu.

library/std_detect/src/detect/os/linux/aarch64/tests.rs renamed to library/std_detect/tests/linux_aarch64.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
1-
use super::AtHwcap;
2-
use super::auxvec::auxv_from_file;
1+
#![cfg(all(
2+
any(target_os = "linux", target_os = "android"),
3+
target_arch = "aarch64",
4+
target_endian = "little"
5+
))]
6+
#![allow(internal_features)]
7+
#![feature(stdarch_internal)]
8+
9+
use std_detect::detect::__test_os::{AtHwcap, auxv_from_file};
310
// The baseline hwcaps used in the (artificial) auxv test files.
411
fn baseline_hwcaps() -> AtHwcap {
512
AtHwcap {

0 commit comments

Comments
 (0)