瀏覽代碼

multiboot2-header: Improve builder test

Niklas Sombert 1 年之前
父節點
當前提交
09de5230ba
共有 2 個文件被更改,包括 17 次插入3 次删除
  1. 16 2
      multiboot2-header/src/builder/header.rs
  2. 1 1
      multiboot2-header/src/relocatable.rs

+ 16 - 2
multiboot2-header/src/builder/header.rs

@@ -244,7 +244,7 @@ mod tests {
     }
 
     #[test]
-    fn test_size_builder() {
+    fn test_builder() {
         let builder = Multiboot2HeaderBuilder::new(HeaderTagISA::I386);
         // Multiboot2 basic header + end tag
         let mut expected_len = 16 + 8;
@@ -274,14 +274,28 @@ mod tests {
             4096,
             RelocatableHeaderTagPreference::None,
         ));
+        expected_len += 0x18;
+        assert_eq!(builder.expected_len(), expected_len);
 
         println!("builder: {:#?}", builder);
         println!("expected_len: {} bytes", builder.expected_len());
 
         let mb2_hdr_data = builder.build();
         let mb2_hdr = mb2_hdr_data.as_ptr() as usize;
-        let mb2_hdr = unsafe { Multiboot2Header::from_addr(mb2_hdr) };
+        let mb2_hdr = unsafe { Multiboot2Header::from_addr(mb2_hdr) }
+            .expect("the generated header to be loadable");
         println!("{:#?}", mb2_hdr);
+        assert_eq!(
+            mb2_hdr.relocatable_tag().unwrap().flags(),
+            HeaderTagFlag::Required
+        );
+        assert_eq!(mb2_hdr.relocatable_tag().unwrap().min_addr(), 0x1337);
+        assert_eq!(mb2_hdr.relocatable_tag().unwrap().max_addr(), 0xdeadbeef);
+        assert_eq!(mb2_hdr.relocatable_tag().unwrap().align(), 4096);
+        assert_eq!(
+            mb2_hdr.relocatable_tag().unwrap().preference(),
+            RelocatableHeaderTagPreference::None
+        );
 
         /* you can write the binary to a file and a tool such as crate "bootinfo"
            will be able to fully parse the MB2 header

+ 1 - 1
multiboot2-header/src/relocatable.rs

@@ -8,7 +8,7 @@ use core::mem::size_of;
 /// but not lower than min addr and ‘2’ means load image at highest possible
 /// address but not higher than max addr.
 #[repr(u32)]
-#[derive(Copy, Clone, Debug)]
+#[derive(Copy, Clone, Debug, PartialEq)]
 pub enum RelocatableHeaderTagPreference {
     /// Let boot loader decide.
     None = 0,