Attribute Macro x86test_macro::x86test

source · []
#[x86test]
Expand description

The x86test macro adds and initializes a X86TestFn struct for every test function. That X86TestFn in turn is annotated with #[test_case] therefore all these structs are aggregated with by the custom test framework runner which is declared in runner.rs.

Example

As an example, if we add x86test to a function, we do the following:

#[x86test(ram(0x10000, 0x11000), ioport(0x1, 0xfe), should_panic)]
fn use_the_port() {
    unsafe {
        kassert!(x86::io::inw(0x1) == 0xff, "`inw` instruction didn't read correct value");
    }
}

Will expand to:

fn use_the_port() {
    unsafe {
        kassert!(x86::io::inw(0x1) == 0xff, "`inw` instruction didn't read correct value");
    }
}

#[allow(non_upper_case_globals)]
#[test_case]
static use_the_port_genkvmtest: X86TestFn = X86TestFn {
    name: "use_the_port",
    ignore: false,
    identity_map: true,
    physical_memory: (0x10000, 0x11000),
    ioport_enable: (0x1, 0xfe),
    should_panic: true,
    testfn: x86test::StaticTestFn(|| {
        use_the_port()
        // Tell our "hypervisor" that we finished the test
        unsafe { x86::io::outw(0xf4, 0x00); }
    })
};