Skip to content

ci: run miri + adjustments for miri #128

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions .github/workflows/_build-rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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 changes: 11 additions & 0 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 change: 1 addition & 0 deletions multiboot2-header/src/builder/header.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
1 change: 1 addition & 0 deletions multiboot2-header/src/builder/information_request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions multiboot2-header/src/builder/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ mod tests {
use super::*;

#[test]
#[cfg_attr(miri, ignore)]
fn test_as_bytes() {
struct Foobar {
a: u32,
Expand Down
3 changes: 2 additions & 1 deletion multiboot2/src/boot_loader_name.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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>() };
Expand Down
1 change: 1 addition & 0 deletions multiboot2/src/builder/information.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion multiboot2/src/builder/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
3 changes: 2 additions & 1 deletion multiboot2/src/command_line.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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>() };
Expand Down
14 changes: 12 additions & 2 deletions multiboot2/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -661,6 +661,7 @@ mod tests {
}

#[test]
#[cfg_attr(miri, ignore)]
fn name_tag() {
#[repr(C, align(8))]
struct Bytes([u8; 32]);
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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))]
Expand Down Expand Up @@ -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]);
Expand Down Expand Up @@ -1411,6 +1416,7 @@ mod tests {
}

#[test]
#[cfg_attr(miri, ignore)]
fn elf_sections() {
#[repr(C, align(8))]
struct Bytes([u8; 168]);
Expand Down Expand Up @@ -1487,6 +1493,7 @@ mod tests {
}

#[test]
#[cfg_attr(miri, ignore)]
fn efi_memory_map() {
#[repr(C, align(8))]
struct Bytes([u8; 72]);
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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]);
Expand Down
3 changes: 2 additions & 1 deletion multiboot2/src/module.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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>() };
Expand Down
1 change: 1 addition & 0 deletions multiboot2/src/smbios.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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>() };
Expand Down