Skip to content

Commit 88a9c46

Browse files
bjorn3Amanieu
authored andcommitted
Remove use of auv crate from tests
1 parent 33ec0e3 commit 88a9c46

File tree

1 file changed

+11
-48
lines changed
  • crates/std_detect/src/detect/os/linux

1 file changed

+11
-48
lines changed

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

Lines changed: 11 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ pub(crate) const AT_HWCAP2: usize = 26;
1919
/// If an entry cannot be read all the bits in the bitfield are set to zero.
2020
/// This should be interpreted as all the features being disabled.
2121
#[derive(Debug, Copy, Clone)]
22+
#[cfg_attr(test, derive(PartialEq))]
2223
pub(crate) struct AuxVec {
2324
pub hwcap: usize,
2425
#[cfg(any(
@@ -174,9 +175,12 @@ pub(crate) fn auxv() -> Result<AuxVec, ()> {
174175
/// Tries to read the `key` from the auxiliary vector by calling the
175176
/// dynamically-linked `getauxval` function. If the function is not linked,
176177
/// this function return `Err`.
177-
#[cfg(all(
178-
feature = "std_detect_dlsym_getauxval",
179-
not(all(target_os = "linux", target_env = "gnu"))
178+
#[cfg(any(
179+
test,
180+
all(
181+
feature = "std_detect_dlsym_getauxval",
182+
not(all(target_os = "linux", target_env = "gnu"))
183+
)
180184
))]
181185
fn getauxval(key: usize) -> Result<usize, ()> {
182186
use libc;
@@ -262,35 +266,8 @@ fn auxv_from_buf(buf: &[usize]) -> Result<AuxVec, ()> {
262266

263267
#[cfg(test)]
264268
mod tests {
265-
extern crate auxv as auxv_crate;
266269
use super::*;
267270

268-
// Reads the Auxiliary Vector key from /proc/self/auxv
269-
// using the auxv crate.
270-
#[cfg(feature = "std_detect_file_io")]
271-
fn auxv_crate_getprocfs(key: usize) -> Option<usize> {
272-
use self::auxv_crate::procfs::search_procfs_auxv;
273-
use self::auxv_crate::AuxvType;
274-
let k = key as AuxvType;
275-
match search_procfs_auxv(&[k]) {
276-
Ok(v) => Some(v[&k] as usize),
277-
Err(_) => None,
278-
}
279-
}
280-
281-
// Reads the Auxiliary Vector key from getauxval()
282-
// using the auxv crate.
283-
#[cfg(not(any(target_arch = "mips", target_arch = "mips64")))]
284-
fn auxv_crate_getauxval(key: usize) -> Option<usize> {
285-
use self::auxv_crate::getauxval::Getauxval;
286-
use self::auxv_crate::AuxvType;
287-
let q = auxv_crate::getauxval::NativeGetauxval {};
288-
match q.getauxval(key as AuxvType) {
289-
Ok(v) => Some(v as usize),
290-
Err(_) => None,
291-
}
292-
}
293-
294271
// FIXME: on mips/mips64 getauxval returns 0, and /proc/self/auxv
295272
// does not always contain the AT_HWCAP key under qemu.
296273
#[cfg(any(
@@ -301,7 +278,7 @@ mod tests {
301278
#[test]
302279
fn auxv_crate() {
303280
let v = auxv();
304-
if let Some(hwcap) = auxv_crate_getauxval(AT_HWCAP) {
281+
if let Ok(hwcap) = getauxval(AT_HWCAP) {
305282
let rt_hwcap = v.expect("failed to find hwcap key").hwcap;
306283
assert_eq!(rt_hwcap, hwcap);
307284
}
@@ -314,7 +291,7 @@ mod tests {
314291
target_arch = "powerpc64"
315292
))]
316293
{
317-
if let Some(hwcap2) = auxv_crate_getauxval(AT_HWCAP2) {
294+
if let Ok(hwcap2) = getauxval(AT_HWCAP2) {
318295
let rt_hwcap2 = v.expect("failed to find hwcap2 key").hwcap2;
319296
assert_eq!(rt_hwcap2, hwcap2);
320297
}
@@ -391,22 +368,8 @@ mod tests {
391368
#[test]
392369
#[cfg(feature = "std_detect_file_io")]
393370
fn auxv_crate_procfs() {
394-
let v = auxv();
395-
if let Some(hwcap) = auxv_crate_getprocfs(AT_HWCAP) {
396-
assert_eq!(v.unwrap().hwcap, hwcap);
397-
}
398-
399-
// Targets with AT_HWCAP and AT_HWCAP2:
400-
#[cfg(any(
401-
target_arch = "aarch64",
402-
target_arch = "arm",
403-
target_arch = "powerpc",
404-
target_arch = "powerpc64"
405-
))]
406-
{
407-
if let Some(hwcap2) = auxv_crate_getprocfs(AT_HWCAP2) {
408-
assert_eq!(v.unwrap().hwcap2, hwcap2);
409-
}
371+
if let Ok(procfs_auxv) = auxv_from_file("/proc/self/auxv") {
372+
assert_eq!(auxv().unwrap(), procfs_auxv);
410373
}
411374
}
412375
}

0 commit comments

Comments
 (0)