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/descriptor.rs b/src/descriptor.rs
index ef78d13..6f370ec 100644
--- a/src/descriptor.rs
+++ b/src/descriptor.rs
@@ -300,408 +300,414 @@
     }
 }
 
-#[test]
-fn test_attributes() {
-    let attributes = Attributes::default();
-    assert_eq!(0u64, attributes.into());
+#[cfg(test)]
+mod tests {
+    use super::*;
 
-    let attributes = Attributes {
-        uxn: true,
-        ..Default::default()
-    };
-    assert_eq!(1u64 << 54, attributes.into());
+    #[test]
+    fn test_attributes() {
+        let attributes = Attributes::default();
+        assert_eq!(0u64, attributes.into());
 
-    let attributes = Attributes {
-        pxn: true,
-        ..Default::default()
-    };
-    assert_eq!(1u64 << 53, attributes.into());
-
-    let attributes = Attributes {
-        contiguous: true,
-        ..Default::default()
-    };
-    assert_eq!(1u64 << 52, attributes.into());
-
-    let attributes = Attributes {
-        not_global: true,
-        ..Default::default()
-    };
-    assert_eq!(1u64 << 11, attributes.into());
-
-    let attributes = Attributes {
-        access_flag: true,
-        ..Default::default()
-    };
-    assert_eq!(1u64 << 10, attributes.into());
-
-    let attributes = Attributes {
-        non_secure: true,
-        ..Default::default()
-    };
-    assert_eq!(1u64 << 5, attributes.into());
-
-    let attributes = Attributes {
-        mem_attr_index: MemoryAttributesIndex::Normal_IWBWA_OWBWA,
-        ..Default::default()
-    };
-    assert_eq!(
-        (MemoryAttributesIndex::Normal_IWBWA_OWBWA as u64) << 2,
-        attributes.into()
-    );
-
-    let attributes: Attributes = 0.into();
-    assert!(!attributes.uxn);
-    assert!(!attributes.pxn);
-    assert!(!attributes.contiguous);
-    assert!(!attributes.not_global);
-    assert!(!attributes.access_flag);
-    assert_eq!(Shareability::NonShareable, attributes.shareability);
-    assert_eq!(
-        DataAccessPermissions::ReadWrite_None,
-        attributes.data_access_permissions
-    );
-    assert!(!attributes.non_secure);
-    assert_eq!(
-        MemoryAttributesIndex::Device_nGnRnE,
-        attributes.mem_attr_index
-    );
-}
-
-#[test]
-fn test_next_level_attributes() {
-    let next_level_attributes = NextLevelAttributes::default();
-    assert_eq!(0u64, next_level_attributes.into());
-
-    let next_level_attributes = NextLevelAttributes {
-        ns_table: true,
-        ..Default::default()
-    };
-    assert_eq!(1u64 << 63, next_level_attributes.into());
-
-    let next_level_attributes = NextLevelAttributes {
-        ap_table: 3.into(),
-        ..Default::default()
-    };
-    assert_eq!(3u64 << 61, next_level_attributes.into());
-
-    let next_level_attributes = NextLevelAttributes {
-        xn_table: true,
-        ..Default::default()
-    };
-    assert_eq!(1u64 << 60, next_level_attributes.into());
-
-    let next_level_attributes = NextLevelAttributes {
-        pxn_table: true,
-        ..Default::default()
-    };
-    assert_eq!(1u64 << 59, next_level_attributes.into());
-
-    let next_level_attributes: NextLevelAttributes = 0.into();
-    assert!(!next_level_attributes.ns_table);
-    assert_eq!(0u8, next_level_attributes.ap_table.into());
-    assert!(!next_level_attributes.xn_table);
-    assert!(!next_level_attributes.pxn_table);
-
-    let next_level_attributes: NextLevelAttributes = u64::MAX.into();
-    assert!(next_level_attributes.ns_table);
-    assert_eq!(3u8, next_level_attributes.ap_table.into());
-    assert!(next_level_attributes.xn_table);
-    assert!(next_level_attributes.pxn_table);
-}
-
-#[test]
-fn test_descriptor_get_type() {
-    let descriptor = Descriptor {
-        cell: UnsafeCell::new(0),
-    };
-    assert_eq!(DescriptorType::Invalid, descriptor.get_descriptor_type(1));
-
-    let descriptor = Descriptor {
-        cell: UnsafeCell::new(1),
-    };
-    assert_eq!(DescriptorType::Block, descriptor.get_descriptor_type(1));
-
-    let descriptor = Descriptor {
-        cell: UnsafeCell::new(3),
-    };
-    assert_eq!(DescriptorType::Table, descriptor.get_descriptor_type(1));
-
-    let descriptor = Descriptor {
-        cell: UnsafeCell::new(0),
-    };
-    assert_eq!(DescriptorType::Invalid, descriptor.get_descriptor_type(3));
-
-    let descriptor = Descriptor {
-        cell: UnsafeCell::new(3),
-    };
-    assert_eq!(DescriptorType::Block, descriptor.get_descriptor_type(3));
-}
-
-#[test]
-fn test_descriptor_is_valid() {
-    let descriptor = Descriptor {
-        cell: UnsafeCell::new(0),
-    };
-    assert!(!descriptor.is_valid());
-
-    let descriptor = Descriptor {
-        cell: UnsafeCell::new(1),
-    };
-    assert!(descriptor.is_valid());
-}
-
-#[test]
-fn test_descriptor_set_block_to_block_again() {
-    let mut descriptor = Descriptor {
-        cell: UnsafeCell::new(1),
-    };
-
-    descriptor.set_block_descriptor(1, 0, Attributes::default());
-    assert_eq!(0x1, descriptor.get());
-}
-
-#[test]
-#[should_panic]
-fn test_descriptor_set_block_invalid_oa() {
-    let mut descriptor = Descriptor {
-        cell: UnsafeCell::new(0),
-    };
-
-    descriptor.set_block_descriptor(1, 1 << 63, Attributes::default());
-}
-
-#[test]
-fn test_descriptor_block() {
-    let mut descriptor = Descriptor {
-        cell: UnsafeCell::new(0),
-    };
-
-    descriptor.set_block_descriptor(
-        1,
-        0x0000000f_c0000000,
-        Attributes {
+        let attributes = Attributes {
             uxn: true,
             ..Default::default()
-        },
-    );
-    assert_eq!(0x0040000f_c0000001, descriptor.get());
+        };
+        assert_eq!(1u64 << 54, attributes.into());
 
-    let mut descriptor = Descriptor {
-        cell: UnsafeCell::new(0),
-    };
-
-    descriptor.set_block_descriptor(
-        3,
-        0x0000000f_fffff000,
-        Attributes {
-            uxn: true,
-            ..Default::default()
-        },
-    );
-    assert_eq!(0x0040000f_fffff003, descriptor.get());
-
-    assert_eq!(0x0000000f_fffff000, descriptor.get_block_output_address(3));
-    assert_eq!(
-        Attributes {
-            uxn: true,
-            ..Default::default()
-        },
-        descriptor.get_block_attributes(3)
-    );
-
-    descriptor.set_block_attributes(
-        3,
-        Attributes {
+        let attributes = Attributes {
             pxn: true,
             ..Default::default()
-        },
-    );
-    assert_eq!(
-        Attributes {
-            pxn: true,
+        };
+        assert_eq!(1u64 << 53, attributes.into());
+
+        let attributes = Attributes {
+            contiguous: true,
             ..Default::default()
-        },
-        descriptor.get_block_attributes(3)
-    );
-}
+        };
+        assert_eq!(1u64 << 52, attributes.into());
 
-#[test]
-#[should_panic]
-fn test_descriptor_invalid_block_to_invalid() {
-    let mut descriptor = Descriptor {
-        cell: UnsafeCell::new(0),
-    };
+        let attributes = Attributes {
+            not_global: true,
+            ..Default::default()
+        };
+        assert_eq!(1u64 << 11, attributes.into());
 
-    descriptor.set_block_descriptor_to_invalid(0);
-}
+        let attributes = Attributes {
+            access_flag: true,
+            ..Default::default()
+        };
+        assert_eq!(1u64 << 10, attributes.into());
 
-#[test]
-fn test_descriptor_block_to_invalid() {
-    let mut descriptor = Descriptor {
-        cell: UnsafeCell::new(3),
-    };
+        let attributes = Attributes {
+            non_secure: true,
+            ..Default::default()
+        };
+        assert_eq!(1u64 << 5, attributes.into());
 
-    descriptor.set_block_descriptor_to_invalid(3);
-    assert_eq!(0, descriptor.get());
-}
+        let attributes = Attributes {
+            mem_attr_index: MemoryAttributesIndex::Normal_IWBWA_OWBWA,
+            ..Default::default()
+        };
+        assert_eq!(
+            (MemoryAttributesIndex::Normal_IWBWA_OWBWA as u64) << 2,
+            attributes.into()
+        );
 
-#[test]
-#[should_panic]
-fn test_descriptor_level3_to_table() {
-    let mut next_level_table = [Descriptor {
-        cell: UnsafeCell::new(0),
-    }];
-    let mut descriptor = Descriptor {
-        cell: UnsafeCell::new(0),
-    };
-
-    unsafe {
-        descriptor.set_table_descriptor(3, &mut next_level_table, None);
-    }
-}
-
-#[test]
-fn test_descriptor_block_to_table() {
-    let next_level_table =
-        unsafe { core::slice::from_raw_parts_mut(0x1000 as *mut Descriptor, 512) };
-    let mut descriptor = Descriptor {
-        cell: UnsafeCell::new(1),
-    };
-
-    unsafe {
-        descriptor.set_table_descriptor(0, next_level_table, None);
-    }
-    assert_eq!(0x1003, descriptor.get());
-}
-
-#[test]
-#[should_panic]
-fn test_descriptor_table_invalid_count() {
-    let next_level_table =
-        unsafe { core::slice::from_raw_parts_mut(0x800 as *mut Descriptor, 511) };
-    let mut descriptor = Descriptor {
-        cell: UnsafeCell::new(0),
-    };
-
-    unsafe {
-        descriptor.set_table_descriptor(0, next_level_table, None);
-    }
-}
-
-#[test]
-#[should_panic]
-fn test_descriptor_table_non_aligned() {
-    let next_level_table =
-        unsafe { core::slice::from_raw_parts_mut(0x800 as *mut Descriptor, 512) };
-    let mut descriptor = Descriptor {
-        cell: UnsafeCell::new(0),
-    };
-
-    unsafe {
-        descriptor.set_table_descriptor(0, next_level_table, None);
-    }
-}
-
-#[test]
-fn test_descriptor_table() {
-    let next_level_table =
-        unsafe { core::slice::from_raw_parts_mut(0x0000_000c_ba98_7000 as *mut Descriptor, 512) };
-    let mut descriptor = Descriptor {
-        cell: UnsafeCell::new(0),
-    };
-
-    unsafe {
-        descriptor.set_table_descriptor(0, next_level_table, None);
-    }
-    assert_eq!(0x0000_000c_ba98_7003, descriptor.get());
-}
-
-#[test]
-fn test_descriptor_table_next_level_attr() {
-    const NEXT_LEVEL_ADDR: u64 = 0x0000_000c_ba98_7000;
-    let next_level_table =
-        unsafe { core::slice::from_raw_parts_mut(NEXT_LEVEL_ADDR as *mut Descriptor, 512) };
-    let mut descriptor = Descriptor {
-        cell: UnsafeCell::new(0),
-    };
-
-    unsafe {
-        descriptor.set_table_descriptor(
-            0,
-            next_level_table,
-            Some(NextLevelAttributes {
-                ns_table: true,
-                ..Default::default()
-            }),
+        let attributes: Attributes = 0.into();
+        assert!(!attributes.uxn);
+        assert!(!attributes.pxn);
+        assert!(!attributes.contiguous);
+        assert!(!attributes.not_global);
+        assert!(!attributes.access_flag);
+        assert_eq!(Shareability::NonShareable, attributes.shareability);
+        assert_eq!(
+            DataAccessPermissions::ReadWrite_None,
+            attributes.data_access_permissions
+        );
+        assert!(!attributes.non_secure);
+        assert_eq!(
+            MemoryAttributesIndex::Device_nGnRnE,
+            attributes.mem_attr_index
         );
     }
-    assert_eq!(NEXT_LEVEL_ADDR | 0x8000_0000_0000_0003, descriptor.get());
-}
 
-#[test]
-fn test_descriptor_table_get_next_level_table() {
-    const NEXT_LEVEL_ADDR: u64 = 0x0000_000c_ba98_7000;
-    let descriptor = Descriptor {
-        cell: UnsafeCell::new(NEXT_LEVEL_ADDR | 0x8000_0000_0000_0003),
-    };
-    assert_eq!(KernelSpace::pa_to_kernel(NEXT_LEVEL_ADDR), unsafe {
-        descriptor.get_next_level_table(0).as_ptr() as u64
-    });
-}
+    #[test]
+    fn test_next_level_attributes() {
+        let next_level_attributes = NextLevelAttributes::default();
+        assert_eq!(0u64, next_level_attributes.into());
 
-#[test]
-fn test_descriptor_table_get_next_level_table_mut() {
-    const NEXT_LEVEL_ADDR: u64 = 0x0000_000c_ba98_7000;
-    let mut descriptor = Descriptor {
-        cell: UnsafeCell::new(NEXT_LEVEL_ADDR | 0x8000_0000_0000_0003),
-    };
-    assert_eq!(KernelSpace::pa_to_kernel(NEXT_LEVEL_ADDR), unsafe {
-        descriptor.get_next_level_table_mut(0).as_ptr() as *mut Descriptor as u64
-    });
-}
-
-#[test]
-fn test_descriptor_table_get_next_level_attr() {
-    const NEXT_LEVEL_ADDR: u64 = 0x0000_000c_ba98_7000;
-    let descriptor = Descriptor {
-        cell: UnsafeCell::new(NEXT_LEVEL_ADDR | 0x8000_0000_0000_0003),
-    };
-    assert_eq!(
-        NextLevelAttributes {
+        let next_level_attributes = NextLevelAttributes {
             ns_table: true,
             ..Default::default()
-        },
-        descriptor.get_next_level_attributes(0)
-    );
-}
+        };
+        assert_eq!(1u64 << 63, next_level_attributes.into());
 
-#[test]
-fn test_descriptor_table_set_to_invalid() {
-    const NEXT_LEVEL_ADDR: u64 = 0x0000_000c_ba98_7000;
-    let mut descriptor = Descriptor {
-        cell: UnsafeCell::new(NEXT_LEVEL_ADDR | 0x8000_0000_0000_0003),
-    };
-    assert_eq!(KernelSpace::pa_to_kernel(NEXT_LEVEL_ADDR), unsafe {
-        descriptor.set_table_descriptor_to_invalid(0).as_ptr() as *mut Descriptor as u64
-    });
-    assert_eq!(0, descriptor.get());
-}
+        let next_level_attributes = NextLevelAttributes {
+            ap_table: 3.into(),
+            ..Default::default()
+        };
+        assert_eq!(3u64 << 61, next_level_attributes.into());
 
-#[test]
-fn test_descriptor_raw_interface() {
-    let cell_value = 0x01234567_89abcdefu64;
-    let cell_new_value = 0x12345678_9abcdef0u64;
+        let next_level_attributes = NextLevelAttributes {
+            xn_table: true,
+            ..Default::default()
+        };
+        assert_eq!(1u64 << 60, next_level_attributes.into());
 
-    let mut descriptor = Descriptor {
-        cell: UnsafeCell::new(cell_value),
-    };
+        let next_level_attributes = NextLevelAttributes {
+            pxn_table: true,
+            ..Default::default()
+        };
+        assert_eq!(1u64 << 59, next_level_attributes.into());
 
-    assert_eq!(cell_value, descriptor.get());
+        let next_level_attributes: NextLevelAttributes = 0.into();
+        assert!(!next_level_attributes.ns_table);
+        assert_eq!(0u8, next_level_attributes.ap_table.into());
+        assert!(!next_level_attributes.xn_table);
+        assert!(!next_level_attributes.pxn_table);
 
-    descriptor.set(cell_new_value);
-    assert_eq!(cell_new_value, descriptor.get());
+        let next_level_attributes: NextLevelAttributes = u64::MAX.into();
+        assert!(next_level_attributes.ns_table);
+        assert_eq!(3u8, next_level_attributes.ap_table.into());
+        assert!(next_level_attributes.xn_table);
+        assert!(next_level_attributes.pxn_table);
+    }
 
-    descriptor.modify(|d| d + 1);
-    assert_eq!(cell_new_value + 1, descriptor.get());
+    #[test]
+    fn test_descriptor_get_type() {
+        let descriptor = Descriptor {
+            cell: UnsafeCell::new(0),
+        };
+        assert_eq!(DescriptorType::Invalid, descriptor.get_descriptor_type(1));
+
+        let descriptor = Descriptor {
+            cell: UnsafeCell::new(1),
+        };
+        assert_eq!(DescriptorType::Block, descriptor.get_descriptor_type(1));
+
+        let descriptor = Descriptor {
+            cell: UnsafeCell::new(3),
+        };
+        assert_eq!(DescriptorType::Table, descriptor.get_descriptor_type(1));
+
+        let descriptor = Descriptor {
+            cell: UnsafeCell::new(0),
+        };
+        assert_eq!(DescriptorType::Invalid, descriptor.get_descriptor_type(3));
+
+        let descriptor = Descriptor {
+            cell: UnsafeCell::new(3),
+        };
+        assert_eq!(DescriptorType::Block, descriptor.get_descriptor_type(3));
+    }
+
+    #[test]
+    fn test_descriptor_is_valid() {
+        let descriptor = Descriptor {
+            cell: UnsafeCell::new(0),
+        };
+        assert!(!descriptor.is_valid());
+
+        let descriptor = Descriptor {
+            cell: UnsafeCell::new(1),
+        };
+        assert!(descriptor.is_valid());
+    }
+
+    #[test]
+    fn test_descriptor_set_block_to_block_again() {
+        let mut descriptor = Descriptor {
+            cell: UnsafeCell::new(1),
+        };
+
+        descriptor.set_block_descriptor(1, 0, Attributes::default());
+        assert_eq!(0x1, descriptor.get());
+    }
+
+    #[test]
+    #[should_panic]
+    fn test_descriptor_set_block_invalid_oa() {
+        let mut descriptor = Descriptor {
+            cell: UnsafeCell::new(0),
+        };
+
+        descriptor.set_block_descriptor(1, 1 << 63, Attributes::default());
+    }
+
+    #[test]
+    fn test_descriptor_block() {
+        let mut descriptor = Descriptor {
+            cell: UnsafeCell::new(0),
+        };
+
+        descriptor.set_block_descriptor(
+            1,
+            0x0000000f_c0000000,
+            Attributes {
+                uxn: true,
+                ..Default::default()
+            },
+        );
+        assert_eq!(0x0040000f_c0000001, descriptor.get());
+
+        let mut descriptor = Descriptor {
+            cell: UnsafeCell::new(0),
+        };
+
+        descriptor.set_block_descriptor(
+            3,
+            0x0000000f_fffff000,
+            Attributes {
+                uxn: true,
+                ..Default::default()
+            },
+        );
+        assert_eq!(0x0040000f_fffff003, descriptor.get());
+
+        assert_eq!(0x0000000f_fffff000, descriptor.get_block_output_address(3));
+        assert_eq!(
+            Attributes {
+                uxn: true,
+                ..Default::default()
+            },
+            descriptor.get_block_attributes(3)
+        );
+
+        descriptor.set_block_attributes(
+            3,
+            Attributes {
+                pxn: true,
+                ..Default::default()
+            },
+        );
+        assert_eq!(
+            Attributes {
+                pxn: true,
+                ..Default::default()
+            },
+            descriptor.get_block_attributes(3)
+        );
+    }
+
+    #[test]
+    #[should_panic]
+    fn test_descriptor_invalid_block_to_invalid() {
+        let mut descriptor = Descriptor {
+            cell: UnsafeCell::new(0),
+        };
+
+        descriptor.set_block_descriptor_to_invalid(0);
+    }
+
+    #[test]
+    fn test_descriptor_block_to_invalid() {
+        let mut descriptor = Descriptor {
+            cell: UnsafeCell::new(3),
+        };
+
+        descriptor.set_block_descriptor_to_invalid(3);
+        assert_eq!(0, descriptor.get());
+    }
+
+    #[test]
+    #[should_panic]
+    fn test_descriptor_level3_to_table() {
+        let mut next_level_table = [Descriptor {
+            cell: UnsafeCell::new(0),
+        }];
+        let mut descriptor = Descriptor {
+            cell: UnsafeCell::new(0),
+        };
+
+        unsafe {
+            descriptor.set_table_descriptor(3, &mut next_level_table, None);
+        }
+    }
+
+    #[test]
+    fn test_descriptor_block_to_table() {
+        let next_level_table =
+            unsafe { core::slice::from_raw_parts_mut(0x1000 as *mut Descriptor, 512) };
+        let mut descriptor = Descriptor {
+            cell: UnsafeCell::new(1),
+        };
+
+        unsafe {
+            descriptor.set_table_descriptor(0, next_level_table, None);
+        }
+        assert_eq!(0x1003, descriptor.get());
+    }
+
+    #[test]
+    #[should_panic]
+    fn test_descriptor_table_invalid_count() {
+        let next_level_table =
+            unsafe { core::slice::from_raw_parts_mut(0x800 as *mut Descriptor, 511) };
+        let mut descriptor = Descriptor {
+            cell: UnsafeCell::new(0),
+        };
+
+        unsafe {
+            descriptor.set_table_descriptor(0, next_level_table, None);
+        }
+    }
+
+    #[test]
+    #[should_panic]
+    fn test_descriptor_table_non_aligned() {
+        let next_level_table =
+            unsafe { core::slice::from_raw_parts_mut(0x800 as *mut Descriptor, 512) };
+        let mut descriptor = Descriptor {
+            cell: UnsafeCell::new(0),
+        };
+
+        unsafe {
+            descriptor.set_table_descriptor(0, next_level_table, None);
+        }
+    }
+
+    #[test]
+    fn test_descriptor_table() {
+        let next_level_table = unsafe {
+            core::slice::from_raw_parts_mut(0x0000_000c_ba98_7000 as *mut Descriptor, 512)
+        };
+        let mut descriptor = Descriptor {
+            cell: UnsafeCell::new(0),
+        };
+
+        unsafe {
+            descriptor.set_table_descriptor(0, next_level_table, None);
+        }
+        assert_eq!(0x0000_000c_ba98_7003, descriptor.get());
+    }
+
+    #[test]
+    fn test_descriptor_table_next_level_attr() {
+        const NEXT_LEVEL_ADDR: u64 = 0x0000_000c_ba98_7000;
+        let next_level_table =
+            unsafe { core::slice::from_raw_parts_mut(NEXT_LEVEL_ADDR as *mut Descriptor, 512) };
+        let mut descriptor = Descriptor {
+            cell: UnsafeCell::new(0),
+        };
+
+        unsafe {
+            descriptor.set_table_descriptor(
+                0,
+                next_level_table,
+                Some(NextLevelAttributes {
+                    ns_table: true,
+                    ..Default::default()
+                }),
+            );
+        }
+        assert_eq!(NEXT_LEVEL_ADDR | 0x8000_0000_0000_0003, descriptor.get());
+    }
+
+    #[test]
+    fn test_descriptor_table_get_next_level_table() {
+        const NEXT_LEVEL_ADDR: u64 = 0x0000_000c_ba98_7000;
+        let descriptor = Descriptor {
+            cell: UnsafeCell::new(NEXT_LEVEL_ADDR | 0x8000_0000_0000_0003),
+        };
+        assert_eq!(KernelSpace::pa_to_kernel(NEXT_LEVEL_ADDR), unsafe {
+            descriptor.get_next_level_table(0).as_ptr() as u64
+        });
+    }
+
+    #[test]
+    fn test_descriptor_table_get_next_level_table_mut() {
+        const NEXT_LEVEL_ADDR: u64 = 0x0000_000c_ba98_7000;
+        let mut descriptor = Descriptor {
+            cell: UnsafeCell::new(NEXT_LEVEL_ADDR | 0x8000_0000_0000_0003),
+        };
+        assert_eq!(KernelSpace::pa_to_kernel(NEXT_LEVEL_ADDR), unsafe {
+            descriptor.get_next_level_table_mut(0).as_ptr() as *mut Descriptor as u64
+        });
+    }
+
+    #[test]
+    fn test_descriptor_table_get_next_level_attr() {
+        const NEXT_LEVEL_ADDR: u64 = 0x0000_000c_ba98_7000;
+        let descriptor = Descriptor {
+            cell: UnsafeCell::new(NEXT_LEVEL_ADDR | 0x8000_0000_0000_0003),
+        };
+        assert_eq!(
+            NextLevelAttributes {
+                ns_table: true,
+                ..Default::default()
+            },
+            descriptor.get_next_level_attributes(0)
+        );
+    }
+
+    #[test]
+    fn test_descriptor_table_set_to_invalid() {
+        const NEXT_LEVEL_ADDR: u64 = 0x0000_000c_ba98_7000;
+        let mut descriptor = Descriptor {
+            cell: UnsafeCell::new(NEXT_LEVEL_ADDR | 0x8000_0000_0000_0003),
+        };
+        assert_eq!(KernelSpace::pa_to_kernel(NEXT_LEVEL_ADDR), unsafe {
+            descriptor.set_table_descriptor_to_invalid(0).as_ptr() as *mut Descriptor as u64
+        });
+        assert_eq!(0, descriptor.get());
+    }
+
+    #[test]
+    fn test_descriptor_raw_interface() {
+        let cell_value = 0x01234567_89abcdefu64;
+        let cell_new_value = 0x12345678_9abcdef0u64;
+
+        let mut descriptor = Descriptor {
+            cell: UnsafeCell::new(cell_value),
+        };
+
+        assert_eq!(cell_value, descriptor.get());
+
+        descriptor.set(cell_new_value);
+        assert_eq!(cell_new_value, descriptor.get());
+
+        descriptor.modify(|d| d + 1);
+        assert_eq!(cell_new_value + 1, descriptor.get());
+    }
 }