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/lib.rs b/src/lib.rs
index ecaa6b5..7fc5839 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -730,25 +730,30 @@
}
}
-#[test]
-fn test_split_to_pages() {
- let pages = Xlat::split_region_to_blocks(0x3fff_c000, 0x3fff_c000, 0x4020_5000).unwrap();
- assert_eq!(Block::new(0x3fff_c000, 0x3fff_c000, 0x1000), pages[0]);
- assert_eq!(Block::new(0x3fff_d000, 0x3fff_d000, 0x1000), pages[1]);
- assert_eq!(Block::new(0x3fff_e000, 0x3fff_e000, 0x1000), pages[2]);
- assert_eq!(Block::new(0x3fff_f000, 0x3fff_f000, 0x1000), pages[3]);
- assert_eq!(Block::new(0x4000_0000, 0x4000_0000, 0x4000_0000), pages[4]);
- assert_eq!(Block::new(0x8000_0000, 0x8000_0000, 0x0020_0000), pages[5]);
- assert_eq!(Block::new(0x8020_0000, 0x8020_0000, 0x1000), pages[6]);
-}
+#[cfg(test)]
+mod tests {
+ use super::*;
-#[test]
-fn test_split_to_pages_unaligned() {
- let pages = Xlat::split_region_to_blocks(0x3fff_c000, 0x3f20_0000, 0x200000).unwrap();
- for (i, block) in pages.iter().enumerate().take(512) {
- assert_eq!(
- Block::new(0x3fff_c000 + (i << 12), 0x3f20_0000 + (i << 12), 0x1000),
- *block
- );
+ #[test]
+ fn test_split_to_pages() {
+ let pages = Xlat::split_region_to_blocks(0x3fff_c000, 0x3fff_c000, 0x4020_5000).unwrap();
+ assert_eq!(Block::new(0x3fff_c000, 0x3fff_c000, 0x1000), pages[0]);
+ assert_eq!(Block::new(0x3fff_d000, 0x3fff_d000, 0x1000), pages[1]);
+ assert_eq!(Block::new(0x3fff_e000, 0x3fff_e000, 0x1000), pages[2]);
+ assert_eq!(Block::new(0x3fff_f000, 0x3fff_f000, 0x1000), pages[3]);
+ assert_eq!(Block::new(0x4000_0000, 0x4000_0000, 0x4000_0000), pages[4]);
+ assert_eq!(Block::new(0x8000_0000, 0x8000_0000, 0x0020_0000), pages[5]);
+ assert_eq!(Block::new(0x8020_0000, 0x8020_0000, 0x1000), pages[6]);
+ }
+
+ #[test]
+ fn test_split_to_pages_unaligned() {
+ let pages = Xlat::split_region_to_blocks(0x3fff_c000, 0x3f20_0000, 0x200000).unwrap();
+ for (i, block) in pages.iter().enumerate().take(512) {
+ assert_eq!(
+ Block::new(0x3fff_c000 + (i << 12), 0x3f20_0000 + (i << 12), 0x1000),
+ *block
+ );
+ }
}
}