Coverage Report

Created: 2025-01-09 07:53

/src/regalloc2/fuzz/fuzz_targets/ion_checker.rs
Line
Count
Source
1
/*
2
 * Released under the terms of the Apache 2.0 license with LLVM
3
 * exception. See `LICENSE` for details.
4
 */
5
6
#![no_main]
7
use regalloc2::fuzzing::arbitrary::{Arbitrary, Result, Unstructured};
8
use regalloc2::fuzzing::checker::Checker;
9
use regalloc2::fuzzing::func::{Func, Options};
10
use regalloc2::fuzzing::fuzz_target;
11
12
#[derive(Clone, Debug)]
13
struct TestCase {
14
    func: Func,
15
}
16
17
impl Arbitrary<'_> for TestCase {
18
11.3k
    fn arbitrary(u: &mut Unstructured) -> Result<TestCase> {
19
11.3k
        Ok(TestCase {
20
11.3k
            func: Func::arbitrary_with_options(
21
11.3k
                u,
22
11.3k
                &Options {
23
11.3k
                    reused_inputs: true,
24
11.3k
                    fixed_regs: true,
25
11.3k
                    fixed_nonallocatable: true,
26
11.3k
                    clobbers: true,
27
11.3k
                    reftypes: true,
28
11.3k
                },
29
11.3k
            )?,
30
        })
31
11.3k
    }
32
}
33
34
fuzz_target!(|testcase: TestCase| {
35
    let func = testcase.func;
36
    let _ = env_logger::try_init();
37
    log::trace!("func:\n{:?}", func);
38
    let env = regalloc2::fuzzing::func::machine_env();
39
40
    thread_local! {
41
        // We test that ctx is cleared properly between runs.
42
        static CTX: std::cell::RefCell<regalloc2::fuzzing::ion::Ctx> = std::cell::RefCell::default();
43
    }
44
45
11.3k
    CTX.with(|ctx| {
46
11.3k
        regalloc2::fuzzing::ion::run(&func, &env, &mut *ctx.borrow_mut(), true, false)
47
11.3k
            .expect("regalloc did not succeed");
48
11.3k
49
11.3k
        let mut checker = Checker::new(&func, &env);
50
11.3k
        checker.prepare(&ctx.borrow().output);
51
11.3k
        checker.run().expect("checker failed");
52
11.3k
    });
53
});