Bläddra i källkod

Merge pull request #128 from rust-osdev/ci-miri

ci: run miri + adjustments for miri
Philipp Schuster 1 år sedan
förälder
incheckning
6ea885a506

+ 12 - 0
.github/workflows/_build-rust.yml

@@ -50,6 +50,11 @@ on:
         required: false
         default: true
         description: Execute tests.
+      do-miri:
+        type: boolean
+        required: false
+        default: false
+        description: Execute unit tests with miri.
 
 jobs:
   rust:
@@ -104,3 +109,10 @@ jobs:
           Expand-Archive .\cargo-nextest.zip
           cp .\cargo-nextest/cargo-nextest.exe .
           .\cargo-nextest.exe nextest run --features ${{ inputs.features }} --no-default-features
+      - name: Unit Test with Miri
+        if: inputs.do-miri
+        # "--tests" so that the doctests are skipped. Currently, the doctest
+        # in miri fails.
+        run: |
+          rustup component add miri
+          cargo miri test --tests

+ 11 - 0
.github/workflows/rust.yml

@@ -161,3 +161,14 @@ jobs:
       - run: cd integration-test && nix-shell --run "echo OK" && cd ..
       # Now, run the actual test.
       - run: cd integration-test && nix-shell --run ./run.sh && cd ..
+
+  miri:
+    name: tests with miri (nightly)
+    needs: build_nightly
+    uses: ./.github/workflows/_build-rust.yml
+    with:
+      rust-version: nightly
+      do-style-check: false
+      do-test: false
+      do-miri: true
+      features: builder,unstable

+ 1 - 0
multiboot2-header/src/builder/header.rs

@@ -356,6 +356,7 @@ mod tests {
     }
 
     #[test]
+    #[cfg_attr(miri, ignore)]
     fn test_builder() {
         // Step 1/2: Build Header
         let mb2_hdr_data = create_builder().build();

+ 1 - 0
multiboot2-header/src/builder/information_request.rs

@@ -98,6 +98,7 @@ mod tests {
     use crate::{HeaderTagFlag, InformationRequestHeaderTag, MbiTagType, MbiTagTypeId};
 
     #[test]
+    #[cfg_attr(miri, ignore)]
     fn test_builder() {
         let builder = InformationRequestHeaderTagBuilder::new(HeaderTagFlag::Required)
             .add_ir(MbiTagType::EfiMmap)

+ 1 - 0
multiboot2-header/src/builder/traits.rs

@@ -51,6 +51,7 @@ mod tests {
     use super::*;
 
     #[test]
+    #[cfg_attr(miri, ignore)]
     fn test_as_bytes() {
         struct Foobar {
             a: u32,

+ 2 - 1
multiboot2/src/boot_loader_name.rs

@@ -82,7 +82,7 @@ mod tests {
 
     const MSG: &str = "hello";
 
-    /// Returns the tag structure in bytes in native endian format.
+    /// Returns the tag structure in bytes in little endian format.
     fn get_bytes() -> std::vec::Vec<u8> {
         // size is: 4 bytes for tag + 4 bytes for size + length of null-terminated string
         let size = (4 + 4 + MSG.as_bytes().len() + 1) as u32;
@@ -101,6 +101,7 @@ mod tests {
 
     /// Tests to parse a string with a terminating null byte from the tag (as the spec defines).
     #[test]
+    #[cfg_attr(miri, ignore)]
     fn test_parse_str() {
         let tag = get_bytes();
         let tag = unsafe { &*tag.as_ptr().cast::<Tag>() };

+ 1 - 0
multiboot2/src/builder/information.rs

@@ -408,6 +408,7 @@ mod tests {
     }
 
     #[test]
+    #[cfg_attr(miri, ignore)]
     fn test_builder() {
         // Step 1/2: Build MBI
         let mb2i_data = create_builder().build();

+ 1 - 1
multiboot2/src/builder/mod.rs

@@ -139,7 +139,7 @@ mod tests {
         let tag_type_id = 1337_u32;
         let content = "hallo";
 
-        let tag = unsafe { BoxedDst::<CustomTag>::new(tag_type_id, content.as_bytes()) };
+        let tag = BoxedDst::<CustomTag>::new(tag_type_id, content.as_bytes());
         assert_eq!(tag.typ, tag_type_id);
         assert_eq!(tag.size as usize, METADATA_SIZE + content.len());
         assert_eq!(tag.string(), Ok(content));

+ 2 - 1
multiboot2/src/command_line.rs

@@ -91,7 +91,7 @@ mod tests {
 
     const MSG: &str = "hello";
 
-    /// Returns the tag structure in bytes in native endian format.
+    /// Returns the tag structure in bytes in little endian format.
     fn get_bytes() -> std::vec::Vec<u8> {
         // size is: 4 bytes for tag + 4 bytes for size + length of null-terminated string
         let size = (4 + 4 + MSG.as_bytes().len() + 1) as u32;
@@ -110,6 +110,7 @@ mod tests {
 
     /// Tests to parse a string with a terminating null byte from the tag (as the spec defines).
     #[test]
+    #[cfg_attr(miri, ignore)]
     fn test_parse_str() {
         let tag = get_bytes();
         let tag = unsafe { &*tag.as_ptr().cast::<Tag>() };

+ 12 - 2
multiboot2/src/lib.rs

@@ -145,7 +145,7 @@ impl core::error::Error for MbiLoadError {}
 
 /// The basic header of a boot information.
 #[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
-#[repr(C, align(8))]
+#[repr(C)]
 pub struct BootInformationHeader {
     // size is multiple of 8
     total_size: u32,
@@ -661,6 +661,7 @@ mod tests {
     }
 
     #[test]
+    #[cfg_attr(miri, ignore)]
     fn name_tag() {
         #[repr(C, align(8))]
         struct Bytes([u8; 32]);
@@ -695,6 +696,7 @@ mod tests {
     }
 
     #[test]
+    #[cfg_attr(miri, ignore)]
     fn framebuffer_tag_rgb() {
         // direct RGB mode test:
         // taken from GRUB2 running in QEMU at
@@ -755,6 +757,7 @@ mod tests {
     }
 
     #[test]
+    #[cfg_attr(miri, ignore)]
     fn framebuffer_tag_indexed() {
         // indexed mode test:
         // this is synthetic, as I can't get QEMU
@@ -826,6 +829,7 @@ mod tests {
     }
 
     #[test]
+    #[cfg_attr(miri, ignore)]
     fn vbe_info_tag() {
         //Taken from GRUB2 running in QEMU.
         #[repr(C, align(8))]
@@ -996,6 +1000,7 @@ mod tests {
     /// Tests to parse a MBI that was statically extracted from a test run with
     /// GRUB as bootloader.
     #[test]
+    #[cfg_attr(miri, ignore)]
     fn grub2() {
         #[repr(C, align(8))]
         struct Bytes([u8; 960]);
@@ -1411,6 +1416,7 @@ mod tests {
     }
 
     #[test]
+    #[cfg_attr(miri, ignore)]
     fn elf_sections() {
         #[repr(C, align(8))]
         struct Bytes([u8; 168]);
@@ -1487,6 +1493,7 @@ mod tests {
     }
 
     #[test]
+    #[cfg_attr(miri, ignore)]
     fn efi_memory_map() {
         #[repr(C, align(8))]
         struct Bytes([u8; 72]);
@@ -1565,6 +1572,7 @@ mod tests {
 
     /// Example for a custom tag.
     #[test]
+    #[cfg_attr(miri, ignore)]
     fn get_custom_tag_from_mbi() {
         const CUSTOM_TAG_ID: u32 = 0x1337;
 
@@ -1626,10 +1634,11 @@ mod tests {
 
     /// Example for a custom DST tag.
     #[test]
+    #[cfg_attr(miri, ignore)]
     fn get_custom_dst_tag_from_mbi() {
         const CUSTOM_TAG_ID: u32 = 0x1337;
 
-        #[repr(C, align(8))]
+        #[repr(C)]
         #[derive(crate::Pointee)]
         struct CustomTag {
             tag: TagTypeId,
@@ -1703,6 +1712,7 @@ mod tests {
 
     /// Tests that `get_tag` can consume multiple types that implement `Into<TagTypeId>`
     #[test]
+    #[cfg_attr(miri, ignore)]
     fn get_tag_into_variants() {
         #[repr(C, align(8))]
         struct Bytes([u8; 32]);

+ 2 - 1
multiboot2/src/module.rs

@@ -131,7 +131,7 @@ mod tests {
 
     const MSG: &str = "hello";
 
-    /// Returns the tag structure in bytes in native endian format.
+    /// Returns the tag structure in bytes in little endian format.
     fn get_bytes() -> std::vec::Vec<u8> {
         // size is: 4 bytes for tag + 4 bytes for size + length of null-terminated string
         //          4 bytes mod_start + 4 bytes mod_end
@@ -153,6 +153,7 @@ mod tests {
 
     /// Tests to parse a string with a terminating null byte from the tag (as the spec defines).
     #[test]
+    #[cfg_attr(miri, ignore)]
     fn test_parse_str() {
         let tag = get_bytes();
         let tag = unsafe { &*tag.as_ptr().cast::<Tag>() };

+ 1 - 0
multiboot2/src/smbios.rs

@@ -77,6 +77,7 @@ mod tests {
 
     /// Test to parse a given tag.
     #[test]
+    #[cfg_attr(miri, ignore)]
     fn test_parse() {
         let tag = get_bytes();
         let tag = unsafe { &*tag.as_ptr().cast::<Tag>() };