@@ -19,6 +19,7 @@ pub(crate) const AT_HWCAP2: usize = 26;
19
19
/// If an entry cannot be read all the bits in the bitfield are set to zero.
20
20
/// This should be interpreted as all the features being disabled.
21
21
#[ derive( Debug , Copy , Clone ) ]
22
+ #[ cfg_attr( test, derive( PartialEq ) ) ]
22
23
pub ( crate ) struct AuxVec {
23
24
pub hwcap : usize ,
24
25
#[ cfg( any(
@@ -174,9 +175,12 @@ pub(crate) fn auxv() -> Result<AuxVec, ()> {
174
175
/// Tries to read the `key` from the auxiliary vector by calling the
175
176
/// dynamically-linked `getauxval` function. If the function is not linked,
176
177
/// 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
+ )
180
184
) ) ]
181
185
fn getauxval ( key : usize ) -> Result < usize , ( ) > {
182
186
use libc;
@@ -262,35 +266,8 @@ fn auxv_from_buf(buf: &[usize]) -> Result<AuxVec, ()> {
262
266
263
267
#[ cfg( test) ]
264
268
mod tests {
265
- extern crate auxv as auxv_crate;
266
269
use super :: * ;
267
270
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
-
294
271
// FIXME: on mips/mips64 getauxval returns 0, and /proc/self/auxv
295
272
// does not always contain the AT_HWCAP key under qemu.
296
273
#[ cfg( any(
@@ -301,7 +278,7 @@ mod tests {
301
278
#[ test]
302
279
fn auxv_crate ( ) {
303
280
let v = auxv ( ) ;
304
- if let Some ( hwcap) = auxv_crate_getauxval ( AT_HWCAP ) {
281
+ if let Ok ( hwcap) = getauxval ( AT_HWCAP ) {
305
282
let rt_hwcap = v. expect ( "failed to find hwcap key" ) . hwcap ;
306
283
assert_eq ! ( rt_hwcap, hwcap) ;
307
284
}
@@ -314,7 +291,7 @@ mod tests {
314
291
target_arch = "powerpc64"
315
292
) ) ]
316
293
{
317
- if let Some ( hwcap2) = auxv_crate_getauxval ( AT_HWCAP2 ) {
294
+ if let Ok ( hwcap2) = getauxval ( AT_HWCAP2 ) {
318
295
let rt_hwcap2 = v. expect ( "failed to find hwcap2 key" ) . hwcap2 ;
319
296
assert_eq ! ( rt_hwcap2, hwcap2) ;
320
297
}
@@ -391,22 +368,8 @@ mod tests {
391
368
#[ test]
392
369
#[ cfg( feature = "std_detect_file_io" ) ]
393
370
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) ;
410
373
}
411
374
}
412
375
}
0 commit comments