Moving tests into their own module in each file
This is a common pattern and it limits the scope of entities made only
for testing purposes.
Signed-off-by: Imre Kis <imre.kis@arm.com>
Change-Id: I4338a5f68471377b87653240fbb0debf3d80e924
diff --git a/src/region.rs b/src/region.rs
index fb13db9..f5e6ab8 100644
--- a/src/region.rs
+++ b/src/region.rs
@@ -244,389 +244,396 @@
}
#[cfg(test)]
-use super::page_pool::PagePoolArea;
+mod tests {
+ use super::super::page_pool::PagePoolArea;
+ use super::*;
-#[test]
-#[should_panic]
-fn test_physical_region_unused() {
- let region = PhysicalRegion::Unused;
- region.get_pa();
-}
+ #[test]
+ #[should_panic]
+ fn test_physical_region_unused() {
+ let region = PhysicalRegion::Unused;
+ region.get_pa();
+ }
-#[test]
-fn test_physical_region() {
- const PA: usize = 0x0123_4567_89ab_cdef;
- const LENGTH: usize = 0x8000_0000_0000;
+ #[test]
+ fn test_physical_region() {
+ const PA: usize = 0x0123_4567_89ab_cdef;
+ const LENGTH: usize = 0x8000_0000_0000;
- static PAGE_POOL_AREA: PagePoolArea<16> = PagePoolArea::new();
- let region =
- PhysicalRegion::Allocated(PagePool::new(&PAGE_POOL_AREA), Pages::new(PA, LENGTH, true));
- assert_eq!(PA, region.get_pa());
+ static PAGE_POOL_AREA: PagePoolArea<16> = PagePoolArea::new();
+ let region =
+ PhysicalRegion::Allocated(PagePool::new(&PAGE_POOL_AREA), Pages::new(PA, LENGTH, true));
+ assert_eq!(PA, region.get_pa());
- let region = PhysicalRegion::PhysicalAddress(PA);
- assert_eq!(PA, region.get_pa());
-}
+ let region = PhysicalRegion::PhysicalAddress(PA);
+ assert_eq!(PA, region.get_pa());
+ }
-#[test]
-fn test_virtual_region() {
- const VA: usize = 0x0123_4567_89ab_cdef;
- const PA: usize = 0xfedc_ba98_7654_3210;
- const LENGTH: usize = 0x8000_0000_0000;
+ #[test]
+ fn test_virtual_region() {
+ const VA: usize = 0x0123_4567_89ab_cdef;
+ const PA: usize = 0xfedc_ba98_7654_3210;
+ const LENGTH: usize = 0x8000_0000_0000;
- let region = VirtualRegion::new(VA, LENGTH);
- assert_eq!(VA, region.va);
- assert_eq!(VA, region.base());
- assert_eq!(LENGTH, region.length);
- assert_eq!(LENGTH, region.length());
- assert!(matches!(region.physical_region, PhysicalRegion::Unused));
- assert!(!region.used());
+ let region = VirtualRegion::new(VA, LENGTH);
+ assert_eq!(VA, region.va);
+ assert_eq!(VA, region.base());
+ assert_eq!(LENGTH, region.length);
+ assert_eq!(LENGTH, region.length());
+ assert!(matches!(region.physical_region, PhysicalRegion::Unused));
+ assert!(!region.used());
- let region = VirtualRegion::new_with_pa(PA, VA, LENGTH);
- assert_eq!(VA, region.va);
- assert_eq!(VA, region.base());
- assert_eq!(LENGTH, region.length);
- assert_eq!(LENGTH, region.length());
- assert!(matches!(
- region.physical_region,
- PhysicalRegion::PhysicalAddress(_)
- ));
- assert_eq!(PA, region.get_pa());
- assert!(region.used());
-}
+ let region = VirtualRegion::new_with_pa(PA, VA, LENGTH);
+ assert_eq!(VA, region.va);
+ assert_eq!(VA, region.base());
+ assert_eq!(LENGTH, region.length);
+ assert_eq!(LENGTH, region.length());
+ assert!(matches!(
+ region.physical_region,
+ PhysicalRegion::PhysicalAddress(_)
+ ));
+ assert_eq!(PA, region.get_pa());
+ assert!(region.used());
+ }
-#[test]
-fn test_virtual_region_get_pa_for_va() {
- let region = VirtualRegion::new_with_pa(0x8000_0000_0000_0000, 0x4000_0000_0000_0000, 0x1000);
- assert_eq!(
- 0x8000_0000_0000_0000,
- region.get_pa_for_va(0x4000_0000_0000_0000)
- );
- assert_eq!(
- 0x8000_0000_0000_0001,
- region.get_pa_for_va(0x4000_0000_0000_0001)
- );
- assert_eq!(
- 0x8000_0000_0000_0fff,
- region.get_pa_for_va(0x4000_0000_0000_0fff)
- );
-}
+ #[test]
+ fn test_virtual_region_get_pa_for_va() {
+ let region =
+ VirtualRegion::new_with_pa(0x8000_0000_0000_0000, 0x4000_0000_0000_0000, 0x1000);
+ assert_eq!(
+ 0x8000_0000_0000_0000,
+ region.get_pa_for_va(0x4000_0000_0000_0000)
+ );
+ assert_eq!(
+ 0x8000_0000_0000_0001,
+ region.get_pa_for_va(0x4000_0000_0000_0001)
+ );
+ assert_eq!(
+ 0x8000_0000_0000_0fff,
+ region.get_pa_for_va(0x4000_0000_0000_0fff)
+ );
+ }
-#[test]
-#[should_panic]
-fn test_virtual_region_get_pa_for_va_low_va() {
- let region = VirtualRegion::new_with_pa(0x8000_0000_0000_0000, 0x4000_0000_0000_0000, 0x1000);
- region.get_pa_for_va(0x3fff_ffff_ffff_ffff);
-}
+ #[test]
+ #[should_panic]
+ fn test_virtual_region_get_pa_for_va_low_va() {
+ let region =
+ VirtualRegion::new_with_pa(0x8000_0000_0000_0000, 0x4000_0000_0000_0000, 0x1000);
+ region.get_pa_for_va(0x3fff_ffff_ffff_ffff);
+ }
-#[test]
-#[should_panic]
-fn test_virtual_region_get_pa_for_va_high_va() {
- let region = VirtualRegion::new_with_pa(0x8000_0000_0000_0000, 0x4000_0000_0000_0000, 0x1000);
- region.get_pa_for_va(0x4000_0000_0000_1000);
-}
+ #[test]
+ #[should_panic]
+ fn test_virtual_region_get_pa_for_va_high_va() {
+ let region =
+ VirtualRegion::new_with_pa(0x8000_0000_0000_0000, 0x4000_0000_0000_0000, 0x1000);
+ region.get_pa_for_va(0x4000_0000_0000_1000);
+ }
-#[test]
-fn test_virtual_region_contains() {
- const VA: usize = 0x8000_0000_0000_0000;
- const LENGTH: usize = 0x8000_0000_0000;
+ #[test]
+ fn test_virtual_region_contains() {
+ const VA: usize = 0x8000_0000_0000_0000;
+ const LENGTH: usize = 0x8000_0000_0000;
- let region_overflow_end = VirtualRegion::new(0x8000_0000_0000_0000, 0x8000_0000_0000_0000);
- assert!(!region_overflow_end.contains(0x8000_0000_0000_0000, 1));
+ let region_overflow_end = VirtualRegion::new(0x8000_0000_0000_0000, 0x8000_0000_0000_0000);
+ assert!(!region_overflow_end.contains(0x8000_0000_0000_0000, 1));
- let region = VirtualRegion::new(0x4000_0000_0000_0000, 0x8000_0000_0000_0000);
- assert!(!region.contains(0x8000_0000_0000_0000, 0x8000_0000_0000_0000));
+ let region = VirtualRegion::new(0x4000_0000_0000_0000, 0x8000_0000_0000_0000);
+ assert!(!region.contains(0x8000_0000_0000_0000, 0x8000_0000_0000_0000));
- assert!(!region.contains(0x4000_0000_0000_0000, 0x8000_0000_0000_0001));
- assert!(!region.contains(0x3fff_ffff_ffff_ffff, 0x8000_0000_0000_0000));
- assert!(region.contains(0x4000_0000_0000_0000, 0x8000_0000_0000_0000));
- assert!(region.contains(0x4000_0000_0000_0000, 0x7fff_ffff_ffff_ffff));
- assert!(region.contains(0x4000_0000_0000_0001, 0x7fff_ffff_ffff_ffff));
-}
+ assert!(!region.contains(0x4000_0000_0000_0000, 0x8000_0000_0000_0001));
+ assert!(!region.contains(0x3fff_ffff_ffff_ffff, 0x8000_0000_0000_0000));
+ assert!(region.contains(0x4000_0000_0000_0000, 0x8000_0000_0000_0000));
+ assert!(region.contains(0x4000_0000_0000_0000, 0x7fff_ffff_ffff_ffff));
+ assert!(region.contains(0x4000_0000_0000_0001, 0x7fff_ffff_ffff_ffff));
+ }
-#[test]
-fn test_virtual_region_try_append() {
- // Both unused
- let mut region_unused0 = VirtualRegion::new(0x4000_0000, 0x1000);
- let mut region_unused1 = VirtualRegion::new(0x4000_1000, 0x1000);
+ #[test]
+ fn test_virtual_region_try_append() {
+ // Both unused
+ let mut region_unused0 = VirtualRegion::new(0x4000_0000, 0x1000);
+ let mut region_unused1 = VirtualRegion::new(0x4000_1000, 0x1000);
- assert!(!region_unused1.try_append(®ion_unused0));
- assert_eq!(0x4000_0000, region_unused0.va);
- assert_eq!(0x1000, region_unused0.length);
- assert_eq!(0x4000_1000, region_unused1.va);
- assert_eq!(0x1000, region_unused1.length);
+ assert!(!region_unused1.try_append(®ion_unused0));
+ assert_eq!(0x4000_0000, region_unused0.va);
+ assert_eq!(0x1000, region_unused0.length);
+ assert_eq!(0x4000_1000, region_unused1.va);
+ assert_eq!(0x1000, region_unused1.length);
- assert!(region_unused0.try_append(®ion_unused1));
- assert_eq!(0x4000_0000, region_unused0.va);
- assert_eq!(0x2000, region_unused0.length);
- assert_eq!(0x4000_1000, region_unused1.va);
- assert_eq!(0x1000, region_unused1.length);
+ assert!(region_unused0.try_append(®ion_unused1));
+ assert_eq!(0x4000_0000, region_unused0.va);
+ assert_eq!(0x2000, region_unused0.length);
+ assert_eq!(0x4000_1000, region_unused1.va);
+ assert_eq!(0x1000, region_unused1.length);
- // Unused and PA region
- let mut region_unused = VirtualRegion::new(0x4000_0000, 0x1000);
- let region_physical = VirtualRegion::new_with_pa(0x8000_0000, 0x4000_1000, 0x1000);
- assert!(!region_unused.try_append(®ion_physical));
- assert_eq!(0x4000_0000, region_unused.va);
- assert_eq!(0x1000, region_unused.length);
- assert_eq!(0x4000_1000, region_physical.va);
- assert_eq!(0x1000, region_physical.length);
+ // Unused and PA region
+ let mut region_unused = VirtualRegion::new(0x4000_0000, 0x1000);
+ let region_physical = VirtualRegion::new_with_pa(0x8000_0000, 0x4000_1000, 0x1000);
+ assert!(!region_unused.try_append(®ion_physical));
+ assert_eq!(0x4000_0000, region_unused.va);
+ assert_eq!(0x1000, region_unused.length);
+ assert_eq!(0x4000_1000, region_physical.va);
+ assert_eq!(0x1000, region_physical.length);
- // Both PA regions but non-consecutive PA ranges
- let mut region_physical0 = VirtualRegion::new_with_pa(0x8000_0000, 0x4000_0000, 0x1000);
- let region_physical1 = VirtualRegion::new_with_pa(0x9000_0000, 0x4000_1000, 0x1000);
- assert!(!region_physical0.try_append(®ion_physical1));
- assert_eq!(0x4000_0000, region_physical0.va);
- assert_eq!(0x1000, region_physical0.length);
- assert_eq!(0x4000_1000, region_physical1.va);
- assert_eq!(0x1000, region_physical1.length);
+ // Both PA regions but non-consecutive PA ranges
+ let mut region_physical0 = VirtualRegion::new_with_pa(0x8000_0000, 0x4000_0000, 0x1000);
+ let region_physical1 = VirtualRegion::new_with_pa(0x9000_0000, 0x4000_1000, 0x1000);
+ assert!(!region_physical0.try_append(®ion_physical1));
+ assert_eq!(0x4000_0000, region_physical0.va);
+ assert_eq!(0x1000, region_physical0.length);
+ assert_eq!(0x4000_1000, region_physical1.va);
+ assert_eq!(0x1000, region_physical1.length);
- // Both PA regions with consecutive PA ranges
- let mut region_physical0 = VirtualRegion::new_with_pa(0x8000_0000, 0x4000_0000, 0x1000);
- let region_physical1 = VirtualRegion::new_with_pa(0x8000_1000, 0x4000_1000, 0x1000);
- assert!(region_physical0.try_append(®ion_physical1));
- assert_eq!(0x4000_0000, region_physical0.va);
- assert_eq!(0x2000, region_physical0.length);
- assert_eq!(0x4000_1000, region_physical1.va);
- assert_eq!(0x1000, region_physical1.length);
+ // Both PA regions with consecutive PA ranges
+ let mut region_physical0 = VirtualRegion::new_with_pa(0x8000_0000, 0x4000_0000, 0x1000);
+ let region_physical1 = VirtualRegion::new_with_pa(0x8000_1000, 0x4000_1000, 0x1000);
+ assert!(region_physical0.try_append(®ion_physical1));
+ assert_eq!(0x4000_0000, region_physical0.va);
+ assert_eq!(0x2000, region_physical0.length);
+ assert_eq!(0x4000_1000, region_physical1.va);
+ assert_eq!(0x1000, region_physical1.length);
- // VA overflow
- let mut region_unused0 = VirtualRegion::new(0x8000_0000_0000_0000, 0x8000_0000_0000_0000);
- let mut region_unused1 = VirtualRegion::new(0x4000_1000, 0x1000);
+ // VA overflow
+ let mut region_unused0 = VirtualRegion::new(0x8000_0000_0000_0000, 0x8000_0000_0000_0000);
+ let mut region_unused1 = VirtualRegion::new(0x4000_1000, 0x1000);
- assert!(!region_unused0.try_append(®ion_unused1));
- assert_eq!(0x8000_0000_0000_0000, region_unused0.va);
- assert_eq!(0x8000_0000_0000_0000, region_unused0.length);
- assert_eq!(0x4000_1000, region_unused1.va);
- assert_eq!(0x1000, region_unused1.length);
+ assert!(!region_unused0.try_append(®ion_unused1));
+ assert_eq!(0x8000_0000_0000_0000, region_unused0.va);
+ assert_eq!(0x8000_0000_0000_0000, region_unused0.length);
+ assert_eq!(0x4000_1000, region_unused1.va);
+ assert_eq!(0x1000, region_unused1.length);
- assert!(!region_unused1.try_append(®ion_unused0));
- assert_eq!(0x8000_0000_0000_0000, region_unused0.va);
- assert_eq!(0x8000_0000_0000_0000, region_unused0.length);
- assert_eq!(0x4000_1000, region_unused1.va);
- assert_eq!(0x1000, region_unused1.length);
+ assert!(!region_unused1.try_append(®ion_unused0));
+ assert_eq!(0x8000_0000_0000_0000, region_unused0.va);
+ assert_eq!(0x8000_0000_0000_0000, region_unused0.length);
+ assert_eq!(0x4000_1000, region_unused1.va);
+ assert_eq!(0x1000, region_unused1.length);
- // PA overflow
- let mut region_physical0 =
- VirtualRegion::new_with_pa(0x8000_0000_0000_0000, 0x4000_0000, 0x8000_0000_0000_0000);
- let region_physical1 = VirtualRegion::new_with_pa(0x9000_0000, 0x8000_0000_4000_0000, 0x1000);
- assert!(!region_physical0.try_append(®ion_physical1));
- assert_eq!(0x4000_0000, region_physical0.va);
- assert_eq!(0x8000_0000_0000_0000, region_physical0.length);
- assert_eq!(0x8000_0000_4000_0000, region_physical1.va);
- assert_eq!(0x1000, region_physical1.length);
-}
+ // PA overflow
+ let mut region_physical0 =
+ VirtualRegion::new_with_pa(0x8000_0000_0000_0000, 0x4000_0000, 0x8000_0000_0000_0000);
+ let region_physical1 =
+ VirtualRegion::new_with_pa(0x9000_0000, 0x8000_0000_4000_0000, 0x1000);
+ assert!(!region_physical0.try_append(®ion_physical1));
+ assert_eq!(0x4000_0000, region_physical0.va);
+ assert_eq!(0x8000_0000_0000_0000, region_physical0.length);
+ assert_eq!(0x8000_0000_4000_0000, region_physical1.va);
+ assert_eq!(0x1000, region_physical1.length);
+ }
-#[test]
-fn test_virtual_region_create_split_by_used() {
- let region_unused = VirtualRegion::new(0x4000_0000, 0x4000);
+ #[test]
+ fn test_virtual_region_create_split_by_used() {
+ let region_unused = VirtualRegion::new(0x4000_0000, 0x4000);
- // New region at the start
- let (new_region, splitted_regions) = region_unused.create_split(
- 0x4000_0000,
- 0x1000,
- Some(PhysicalRegion::PhysicalAddress(0x8000_0000)),
- );
+ // New region at the start
+ let (new_region, splitted_regions) = region_unused.create_split(
+ 0x4000_0000,
+ 0x1000,
+ Some(PhysicalRegion::PhysicalAddress(0x8000_0000)),
+ );
- assert_eq!(0x4000_0000, new_region.va);
- assert_eq!(0x1000, new_region.length);
- assert_eq!(0x8000_0000, new_region.get_pa());
- assert!(matches!(
- new_region.physical_region,
- PhysicalRegion::PhysicalAddress(_)
- ));
+ assert_eq!(0x4000_0000, new_region.va);
+ assert_eq!(0x1000, new_region.length);
+ assert_eq!(0x8000_0000, new_region.get_pa());
+ assert!(matches!(
+ new_region.physical_region,
+ PhysicalRegion::PhysicalAddress(_)
+ ));
- assert_eq!(0x4000_0000, splitted_regions[0].va);
- assert_eq!(0x1000, splitted_regions[0].length);
- assert_eq!(0x8000_0000, splitted_regions[0].get_pa());
- assert!(matches!(
- splitted_regions[0].physical_region,
- PhysicalRegion::PhysicalAddress(_)
- ));
+ assert_eq!(0x4000_0000, splitted_regions[0].va);
+ assert_eq!(0x1000, splitted_regions[0].length);
+ assert_eq!(0x8000_0000, splitted_regions[0].get_pa());
+ assert!(matches!(
+ splitted_regions[0].physical_region,
+ PhysicalRegion::PhysicalAddress(_)
+ ));
- assert_eq!(0x4000_1000, splitted_regions[1].va);
- assert_eq!(0x3000, splitted_regions[1].length);
- assert!(matches!(
- splitted_regions[1].physical_region,
- PhysicalRegion::Unused
- ));
+ assert_eq!(0x4000_1000, splitted_regions[1].va);
+ assert_eq!(0x3000, splitted_regions[1].length);
+ assert!(matches!(
+ splitted_regions[1].physical_region,
+ PhysicalRegion::Unused
+ ));
- // New region in the middle
- let (new_region, splitted_regions) = region_unused.create_split(
- 0x4000_1000,
- 0x1000,
- Some(PhysicalRegion::PhysicalAddress(0x8000_0000)),
- );
+ // New region in the middle
+ let (new_region, splitted_regions) = region_unused.create_split(
+ 0x4000_1000,
+ 0x1000,
+ Some(PhysicalRegion::PhysicalAddress(0x8000_0000)),
+ );
- assert_eq!(0x4000_1000, new_region.va);
- assert_eq!(0x1000, new_region.length);
- assert_eq!(0x8000_0000, new_region.get_pa());
- assert!(matches!(
- new_region.physical_region,
- PhysicalRegion::PhysicalAddress(_)
- ));
+ assert_eq!(0x4000_1000, new_region.va);
+ assert_eq!(0x1000, new_region.length);
+ assert_eq!(0x8000_0000, new_region.get_pa());
+ assert!(matches!(
+ new_region.physical_region,
+ PhysicalRegion::PhysicalAddress(_)
+ ));
- assert_eq!(0x4000_0000, splitted_regions[0].va);
- assert_eq!(0x1000, splitted_regions[0].length);
- assert!(matches!(
- splitted_regions[0].physical_region,
- PhysicalRegion::Unused
- ));
+ assert_eq!(0x4000_0000, splitted_regions[0].va);
+ assert_eq!(0x1000, splitted_regions[0].length);
+ assert!(matches!(
+ splitted_regions[0].physical_region,
+ PhysicalRegion::Unused
+ ));
- assert_eq!(0x4000_1000, splitted_regions[1].va);
- assert_eq!(0x1000, splitted_regions[1].length);
- assert_eq!(0x8000_0000, splitted_regions[1].get_pa());
- assert!(matches!(
- splitted_regions[1].physical_region,
- PhysicalRegion::PhysicalAddress(_)
- ));
+ assert_eq!(0x4000_1000, splitted_regions[1].va);
+ assert_eq!(0x1000, splitted_regions[1].length);
+ assert_eq!(0x8000_0000, splitted_regions[1].get_pa());
+ assert!(matches!(
+ splitted_regions[1].physical_region,
+ PhysicalRegion::PhysicalAddress(_)
+ ));
- assert_eq!(0x4000_2000, splitted_regions[2].va);
- assert_eq!(0x2000, splitted_regions[2].length);
- assert!(matches!(
- splitted_regions[2].physical_region,
- PhysicalRegion::Unused
- ));
+ assert_eq!(0x4000_2000, splitted_regions[2].va);
+ assert_eq!(0x2000, splitted_regions[2].length);
+ assert!(matches!(
+ splitted_regions[2].physical_region,
+ PhysicalRegion::Unused
+ ));
- // New region at the end
- let (new_region, splitted_regions) = region_unused.create_split(
- 0x4000_3000,
- 0x1000,
- Some(PhysicalRegion::PhysicalAddress(0x8000_0000)),
- );
+ // New region at the end
+ let (new_region, splitted_regions) = region_unused.create_split(
+ 0x4000_3000,
+ 0x1000,
+ Some(PhysicalRegion::PhysicalAddress(0x8000_0000)),
+ );
- assert_eq!(0x4000_3000, new_region.va);
- assert_eq!(0x1000, new_region.length);
- assert_eq!(0x8000_0000, new_region.get_pa());
- assert!(matches!(
- new_region.physical_region,
- PhysicalRegion::PhysicalAddress(_)
- ));
+ assert_eq!(0x4000_3000, new_region.va);
+ assert_eq!(0x1000, new_region.length);
+ assert_eq!(0x8000_0000, new_region.get_pa());
+ assert!(matches!(
+ new_region.physical_region,
+ PhysicalRegion::PhysicalAddress(_)
+ ));
- assert_eq!(0x4000_0000, splitted_regions[0].va);
- assert_eq!(0x3000, splitted_regions[0].length);
- assert!(matches!(
- splitted_regions[0].physical_region,
- PhysicalRegion::Unused
- ));
+ assert_eq!(0x4000_0000, splitted_regions[0].va);
+ assert_eq!(0x3000, splitted_regions[0].length);
+ assert!(matches!(
+ splitted_regions[0].physical_region,
+ PhysicalRegion::Unused
+ ));
- assert_eq!(0x4000_3000, splitted_regions[1].va);
- assert_eq!(0x1000, splitted_regions[1].length);
- assert_eq!(0x8000_0000, splitted_regions[1].get_pa());
- assert!(matches!(
- splitted_regions[1].physical_region,
- PhysicalRegion::PhysicalAddress(_)
- ));
-}
+ assert_eq!(0x4000_3000, splitted_regions[1].va);
+ assert_eq!(0x1000, splitted_regions[1].length);
+ assert_eq!(0x8000_0000, splitted_regions[1].get_pa());
+ assert!(matches!(
+ splitted_regions[1].physical_region,
+ PhysicalRegion::PhysicalAddress(_)
+ ));
+ }
-#[test]
-fn test_virtual_region_create_split_by_unused() {
- let region_unused = VirtualRegion::new_with_pa(0x8000_0000, 0x4000_0000, 0x4000);
+ #[test]
+ fn test_virtual_region_create_split_by_unused() {
+ let region_unused = VirtualRegion::new_with_pa(0x8000_0000, 0x4000_0000, 0x4000);
- // New region at the start
- let (new_region, splitted_regions) = region_unused.create_split(0x4000_0000, 0x1000, None);
+ // New region at the start
+ let (new_region, splitted_regions) = region_unused.create_split(0x4000_0000, 0x1000, None);
- assert_eq!(0x4000_0000, new_region.va);
- assert_eq!(0x1000, new_region.length);
- assert!(matches!(new_region.physical_region, PhysicalRegion::Unused));
+ assert_eq!(0x4000_0000, new_region.va);
+ assert_eq!(0x1000, new_region.length);
+ assert!(matches!(new_region.physical_region, PhysicalRegion::Unused));
- assert_eq!(0x4000_0000, splitted_regions[0].va);
- assert_eq!(0x1000, splitted_regions[0].length);
- assert!(matches!(
- splitted_regions[0].physical_region,
- PhysicalRegion::Unused
- ));
+ assert_eq!(0x4000_0000, splitted_regions[0].va);
+ assert_eq!(0x1000, splitted_regions[0].length);
+ assert!(matches!(
+ splitted_regions[0].physical_region,
+ PhysicalRegion::Unused
+ ));
- assert_eq!(0x4000_1000, splitted_regions[1].va);
- assert_eq!(0x3000, splitted_regions[1].length);
- assert_eq!(0x8000_1000, splitted_regions[1].get_pa());
- assert!(matches!(
- splitted_regions[1].physical_region,
- PhysicalRegion::PhysicalAddress(_)
- ));
+ assert_eq!(0x4000_1000, splitted_regions[1].va);
+ assert_eq!(0x3000, splitted_regions[1].length);
+ assert_eq!(0x8000_1000, splitted_regions[1].get_pa());
+ assert!(matches!(
+ splitted_regions[1].physical_region,
+ PhysicalRegion::PhysicalAddress(_)
+ ));
- // New region in the middle
- let (new_region, splitted_regions) = region_unused.create_split(0x4000_1000, 0x1000, None);
+ // New region in the middle
+ let (new_region, splitted_regions) = region_unused.create_split(0x4000_1000, 0x1000, None);
- assert_eq!(0x4000_1000, new_region.va);
- assert_eq!(0x1000, new_region.length);
- assert!(matches!(new_region.physical_region, PhysicalRegion::Unused));
+ assert_eq!(0x4000_1000, new_region.va);
+ assert_eq!(0x1000, new_region.length);
+ assert!(matches!(new_region.physical_region, PhysicalRegion::Unused));
- assert_eq!(0x4000_0000, splitted_regions[0].va);
- assert_eq!(0x1000, splitted_regions[0].length);
- assert_eq!(0x8000_0000, splitted_regions[0].get_pa());
- assert!(matches!(
- splitted_regions[0].physical_region,
- PhysicalRegion::PhysicalAddress(_)
- ));
+ assert_eq!(0x4000_0000, splitted_regions[0].va);
+ assert_eq!(0x1000, splitted_regions[0].length);
+ assert_eq!(0x8000_0000, splitted_regions[0].get_pa());
+ assert!(matches!(
+ splitted_regions[0].physical_region,
+ PhysicalRegion::PhysicalAddress(_)
+ ));
- assert_eq!(0x4000_1000, splitted_regions[1].va);
- assert_eq!(0x1000, splitted_regions[1].length);
- assert!(matches!(
- splitted_regions[1].physical_region,
- PhysicalRegion::Unused
- ));
+ assert_eq!(0x4000_1000, splitted_regions[1].va);
+ assert_eq!(0x1000, splitted_regions[1].length);
+ assert!(matches!(
+ splitted_regions[1].physical_region,
+ PhysicalRegion::Unused
+ ));
- assert_eq!(0x4000_2000, splitted_regions[2].va);
- assert_eq!(0x2000, splitted_regions[2].length);
- assert_eq!(0x8000_2000, splitted_regions[2].get_pa());
- assert!(matches!(
- splitted_regions[2].physical_region,
- PhysicalRegion::PhysicalAddress(_)
- ));
+ assert_eq!(0x4000_2000, splitted_regions[2].va);
+ assert_eq!(0x2000, splitted_regions[2].length);
+ assert_eq!(0x8000_2000, splitted_regions[2].get_pa());
+ assert!(matches!(
+ splitted_regions[2].physical_region,
+ PhysicalRegion::PhysicalAddress(_)
+ ));
- // New region at the end
- let (new_region, splitted_regions) = region_unused.create_split(0x4000_3000, 0x1000, None);
+ // New region at the end
+ let (new_region, splitted_regions) = region_unused.create_split(0x4000_3000, 0x1000, None);
- assert_eq!(0x4000_3000, new_region.va);
- assert_eq!(0x1000, new_region.length);
- assert!(matches!(new_region.physical_region, PhysicalRegion::Unused));
+ assert_eq!(0x4000_3000, new_region.va);
+ assert_eq!(0x1000, new_region.length);
+ assert!(matches!(new_region.physical_region, PhysicalRegion::Unused));
- assert_eq!(0x4000_0000, splitted_regions[0].va);
- assert_eq!(0x3000, splitted_regions[0].length);
- assert_eq!(0x8000_0000, splitted_regions[0].get_pa());
- assert!(matches!(
- splitted_regions[0].physical_region,
- PhysicalRegion::PhysicalAddress(_)
- ));
+ assert_eq!(0x4000_0000, splitted_regions[0].va);
+ assert_eq!(0x3000, splitted_regions[0].length);
+ assert_eq!(0x8000_0000, splitted_regions[0].get_pa());
+ assert!(matches!(
+ splitted_regions[0].physical_region,
+ PhysicalRegion::PhysicalAddress(_)
+ ));
- assert_eq!(0x4000_3000, splitted_regions[1].va);
- assert_eq!(0x1000, splitted_regions[1].length);
+ assert_eq!(0x4000_3000, splitted_regions[1].va);
+ assert_eq!(0x1000, splitted_regions[1].length);
- assert!(matches!(
- splitted_regions[1].physical_region,
- PhysicalRegion::Unused
- ));
-}
+ assert!(matches!(
+ splitted_regions[1].physical_region,
+ PhysicalRegion::Unused
+ ));
+ }
-#[test]
-#[should_panic]
-fn test_virtual_region_does_not_contain() {
- let region = VirtualRegion::new(0x4000_0000, 0x1000);
- region.create_split(
- 0x8000_0000,
- 0x1000,
- Some(PhysicalRegion::PhysicalAddress(0xc000_0000)),
- );
-}
+ #[test]
+ #[should_panic]
+ fn test_virtual_region_does_not_contain() {
+ let region = VirtualRegion::new(0x4000_0000, 0x1000);
+ region.create_split(
+ 0x8000_0000,
+ 0x1000,
+ Some(PhysicalRegion::PhysicalAddress(0xc000_0000)),
+ );
+ }
-#[test]
-#[should_panic]
-fn test_virtual_region_create_split_same_used() {
- let region = VirtualRegion::new(0x4000_0000, 0x1000);
- region.create_split(0x4000_0000, 0x1000, Some(PhysicalRegion::Unused));
-}
+ #[test]
+ #[should_panic]
+ fn test_virtual_region_create_split_same_used() {
+ let region = VirtualRegion::new(0x4000_0000, 0x1000);
+ region.create_split(0x4000_0000, 0x1000, Some(PhysicalRegion::Unused));
+ }
-#[test]
-fn test_virtual_region_drop() {
- const PA: usize = 0x0123_4567_89ab_cdef;
- const LENGTH: usize = 0x8000_0000_0000;
+ #[test]
+ fn test_virtual_region_drop() {
+ const PA: usize = 0x0123_4567_89ab_cdef;
+ const LENGTH: usize = 0x8000_0000_0000;
- static PAGE_POOL_AREA: PagePoolArea<8192> = PagePoolArea::new();
- let page_pool = PagePool::new(&PAGE_POOL_AREA);
- let page = page_pool.allocate_pages(4096).unwrap();
+ static PAGE_POOL_AREA: PagePoolArea<8192> = PagePoolArea::new();
+ let page_pool = PagePool::new(&PAGE_POOL_AREA);
+ let page = page_pool.allocate_pages(4096).unwrap();
- let physical_region = PhysicalRegion::Allocated(page_pool, page);
+ let physical_region = PhysicalRegion::Allocated(page_pool, page);
- // Testing physical region drop through virtualregion
- let virtual_region = VirtualRegion::new_from_fields(0x4000_0000, 1000, physical_region);
- drop(virtual_region);
+ // Testing physical region drop through virtualregion
+ let virtual_region = VirtualRegion::new_from_fields(0x4000_0000, 1000, physical_region);
+ drop(virtual_region);
+ }
}