Nothing to see here, move along meow
0

Configure Feed

Select the types of activity you want to include in your feed.

at main 2.3 kB View raw
1use lancer_core::addr; 2use proptest::prelude::*; 3 4#[test] 5fn phys_to_virt_adds_offset() { 6 let result = addr::phys_to_virt(0x1000, 0xFFFF_8000_0000_0000); 7 assert_eq!(result, Some(0xFFFF_8000_0000_1000)); 8} 9 10#[test] 11fn virt_to_phys_subtracts_offset() { 12 let result = addr::virt_to_phys(0xFFFF_8000_0000_1000, 0xFFFF_8000_0000_0000); 13 assert_eq!(result, Some(0x1000)); 14} 15 16#[test] 17fn phys_to_virt_zero_is_offset() { 18 let hhdm = 0xFFFF_8000_0000_0000; 19 assert_eq!(addr::phys_to_virt(0, hhdm), Some(hhdm)); 20} 21 22#[test] 23fn phys_to_virt_overflow_returns_none() { 24 let result = addr::phys_to_virt(u64::MAX, 1); 25 assert_eq!(result, None); 26} 27 28#[test] 29fn virt_to_phys_underflow_returns_none() { 30 let result = addr::virt_to_phys(0, 1); 31 assert_eq!(result, None); 32} 33 34#[test] 35fn virt_to_phys_below_hhdm_returns_none() { 36 let hhdm = 0xFFFF_8000_0000_0000; 37 let result = addr::virt_to_phys(hhdm - 1, hhdm); 38 assert_eq!(result, None); 39} 40 41#[test] 42fn canonical_low_half() { 43 assert!(addr::is_canonical(0)); 44 assert!(addr::is_canonical(0x0000_7FFF_FFFF_FFFF)); 45} 46 47#[test] 48fn canonical_high_half() { 49 assert!(addr::is_canonical(0xFFFF_8000_0000_0000)); 50 assert!(addr::is_canonical(0xFFFF_FFFF_FFFF_FFFF)); 51} 52 53#[test] 54fn non_canonical_hole() { 55 assert!(!addr::is_canonical(0x0000_8000_0000_0000)); 56 assert!(!addr::is_canonical(0xFFFF_7FFF_FFFF_FFFF)); 57 assert!(!addr::is_canonical(0x0001_0000_0000_0000)); 58} 59 60proptest! { 61 #[test] 62 fn round_trip_phys_virt_phys(phys in 0u64..0x000F_FFFF_FFFF_F000u64) { 63 let hhdm = 0xFFFF_8000_0000_0000u64; 64 let virt = addr::phys_to_virt(phys, hhdm); 65 if let Some(v) = virt { 66 let back = addr::virt_to_phys(v, hhdm); 67 prop_assert_eq!(back, Some(phys)); 68 } 69 } 70 71 #[test] 72 fn phys_to_virt_never_panics(phys: u64, offset: u64) { 73 let _ = addr::phys_to_virt(phys, offset); 74 } 75 76 #[test] 77 fn virt_to_phys_never_panics(virt: u64, offset: u64) { 78 let _ = addr::virt_to_phys(virt, offset); 79 } 80 81 #[test] 82 fn canonical_classification_consistent(addr: u64) { 83 let top_bits = addr >> 47; 84 let expected = top_bits == 0 || top_bits == 0x1FFFF; 85 prop_assert_eq!(lancer_core::addr::is_canonical(addr), expected); 86 } 87}