• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 #[cfg(any(
2     all(target_os = "android", target_pointer_width = "64"),
3     target_os = "linux",
4 ))]
5 use rustix::param::linux_hwcap;
6 use rustix::param::{clock_ticks_per_second, page_size};
7 
8 #[test]
test_page_size()9 fn test_page_size() {
10     let size = page_size();
11     assert_ne!(size, 0);
12     assert!(size.is_power_of_two());
13     assert_eq!(size, page_size());
14     assert_eq!(size, unsafe { libc::sysconf(libc::_SC_PAGESIZE) as usize });
15 }
16 
17 #[test]
test_clock_ticks_per_second()18 fn test_clock_ticks_per_second() {
19     let size = clock_ticks_per_second();
20     assert_ne!(size, 0);
21     assert_eq!(size, unsafe { libc::sysconf(libc::_SC_CLK_TCK) as u64 });
22 }
23 
24 #[cfg(any(
25     all(target_os = "android", target_pointer_width = "64"),
26     target_os = "linux",
27 ))]
28 #[test]
test_linux_hwcap()29 fn test_linux_hwcap() {
30     weak!(fn getauxval(libc::c_ulong) -> libc::c_ulong);
31 
32     if let Some(libc_getauxval) = getauxval.get() {
33         let (_hwcap, hwcap2) = linux_hwcap();
34 
35         // GLIBC seems to return a different value than `LD_SHOW_AUXV=1` reports.
36         #[cfg(not(target_env = "gnu"))]
37         assert_eq!(_hwcap, unsafe { libc_getauxval(libc::AT_HWCAP) } as usize);
38 
39         assert_eq!(hwcap2, unsafe { libc_getauxval(libc::AT_HWCAP2) } as usize);
40     }
41 }
42