Skip to content

Commit 47cb823

Browse files
authored
Remove old tests and reexport libfuzzer from fuzzing module (#69)
* Remove unused regalloc2-test crate This code doesn't build, and Chris says it's "a really old harness that existed prior to building the fuzzing and was used mainly to profile and get stats before integration with Cranelift". * Re-export libfuzzer/arbitrary from fuzzing module This avoids needing to keep dependencies on `arbitrary` in sync across the three different Cargo.toml files in this project. However, before version 0.4.2, libfuzzer-sys only supported using its macros if it was available at the top-level `libfuzzer_sys` path, which breaks when re-exporting it. So I'm upgrading to that version (or the newest patch release of it). Upgrading libfuzzer-sys in turn brings in the 1.0 release of the arbitrary crate, with a minor API change along the way.
1 parent 1f915bb commit 47cb823

12 files changed

Lines changed: 23 additions & 166 deletions

File tree

Cargo.toml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,7 @@ slice-group-by = "0.3.0"
2020
serde = { version = "1.0.136", features = ["derive"], optional = true }
2121

2222
# The below are only needed for fuzzing.
23-
# Keep this in sync with libfuzzer_sys's crate version:
24-
arbitrary = { version = "^0.4.6", optional = true }
23+
libfuzzer-sys = { version = "0.4.2", optional = true }
2524

2625
# When testing regalloc2 by itself, enable debug assertions and overflow checks
2726
[profile.release]
@@ -39,7 +38,7 @@ checker = []
3938
trace-log = []
4039

4140
# Exposes the internal API for fuzzing.
42-
fuzzing = ["arbitrary", "checker", "trace-log"]
41+
fuzzing = ["libfuzzer-sys", "checker", "trace-log"]
4342

4443
# Enables serde for exposed types.
4544
enable-serde = ["serde"]

fuzz/Cargo.toml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@ cargo-fuzz = true
1111

1212
[dependencies]
1313
regalloc2 = { path = "../", features = ["fuzzing"] }
14-
libfuzzer-sys = "0.3"
15-
arbitrary = { version = "^0.4.6", features = ["derive"] }
1614
log = { version = "0.4.8", default-features = false }
1715
env_logger = "0.8.3"
1816

fuzz/fuzz_targets/domtree.rs

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,23 +4,19 @@
44
*/
55

66
#![no_main]
7-
use libfuzzer_sys::arbitrary::{Arbitrary, Result, Unstructured};
8-
use libfuzzer_sys::fuzz_target;
7+
use regalloc2::fuzzing::arbitrary::{Arbitrary, Result, Unstructured};
8+
use regalloc2::fuzzing::{domtree, fuzz_target, postorder};
9+
use regalloc2::Block;
910
use std::collections::HashSet;
1011

11-
use regalloc2::{
12-
fuzzing::{domtree, postorder},
13-
Block,
14-
};
15-
1612
#[derive(Clone, Debug)]
1713
struct CFG {
1814
num_blocks: usize,
1915
preds: Vec<Vec<Block>>,
2016
succs: Vec<Vec<Block>>,
2117
}
2218

23-
impl Arbitrary for CFG {
19+
impl Arbitrary<'_> for CFG {
2420
fn arbitrary(u: &mut Unstructured) -> Result<CFG> {
2521
let num_blocks = u.int_in_range(1..=1000)?;
2622
let mut succs = vec![];
@@ -111,7 +107,7 @@ struct TestCase {
111107
path: Path,
112108
}
113109

114-
impl Arbitrary for TestCase {
110+
impl Arbitrary<'_> for TestCase {
115111
fn arbitrary(u: &mut Unstructured) -> Result<TestCase> {
116112
let cfg = CFG::arbitrary(u)?;
117113
let path = Path::choose_from_cfg(&cfg, u)?;

fuzz/fuzz_targets/ion.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,8 @@
44
*/
55

66
#![no_main]
7-
use libfuzzer_sys::fuzz_target;
8-
97
use regalloc2::fuzzing::func::Func;
8+
use regalloc2::fuzzing::fuzz_target;
109

1110
fuzz_target!(|func: Func| {
1211
let _ = env_logger::try_init();

fuzz/fuzz_targets/ion_checker.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,17 @@
44
*/
55

66
#![no_main]
7-
use libfuzzer_sys::arbitrary::{Arbitrary, Result, Unstructured};
8-
use libfuzzer_sys::fuzz_target;
9-
7+
use regalloc2::fuzzing::arbitrary::{Arbitrary, Result, Unstructured};
108
use regalloc2::fuzzing::checker::Checker;
119
use regalloc2::fuzzing::func::{Func, Options};
10+
use regalloc2::fuzzing::fuzz_target;
1211

1312
#[derive(Clone, Debug)]
1413
struct TestCase {
1514
func: Func,
1615
}
1716

18-
impl Arbitrary for TestCase {
17+
impl Arbitrary<'_> for TestCase {
1918
fn arbitrary(u: &mut Unstructured) -> Result<TestCase> {
2019
Ok(TestCase {
2120
func: Func::arbitrary_with_options(

fuzz/fuzz_targets/moves.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,8 @@
44
*/
55

66
#![no_main]
7-
use libfuzzer_sys::arbitrary::{Arbitrary, Result, Unstructured};
8-
use libfuzzer_sys::fuzz_target;
9-
7+
use regalloc2::fuzzing::arbitrary::{Arbitrary, Result, Unstructured};
8+
use regalloc2::fuzzing::fuzz_target;
109
use regalloc2::fuzzing::moves::{MoveAndScratchResolver, ParallelMoves};
1110
use regalloc2::{Allocation, PReg, RegClass, SpillSlot};
1211
use std::collections::{HashMap, HashSet};
@@ -17,7 +16,7 @@ struct TestCase {
1716
available_pregs: Vec<Allocation>,
1817
}
1918

20-
impl Arbitrary for TestCase {
19+
impl Arbitrary<'_> for TestCase {
2120
fn arbitrary(u: &mut Unstructured) -> Result<Self> {
2221
let mut ret = TestCase {
2322
moves: vec![],

fuzz/fuzz_targets/ssagen.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,18 @@
44
*/
55

66
#![no_main]
7-
use libfuzzer_sys::arbitrary::{Arbitrary, Result, Unstructured};
8-
use libfuzzer_sys::fuzz_target;
9-
7+
use regalloc2::fuzzing::arbitrary::{Arbitrary, Result, Unstructured};
108
use regalloc2::fuzzing::cfg::CFGInfo;
119
use regalloc2::fuzzing::func::{Func, Options};
10+
use regalloc2::fuzzing::fuzz_target;
1211
use regalloc2::fuzzing::ssa::validate_ssa;
1312

1413
#[derive(Debug)]
1514
struct TestCase {
1615
f: Func,
1716
}
1817

19-
impl Arbitrary for TestCase {
18+
impl Arbitrary<'_> for TestCase {
2019
fn arbitrary(u: &mut Unstructured) -> Result<Self> {
2120
Ok(TestCase {
2221
f: Func::arbitrary_with_options(

src/fuzzing/func.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ use crate::{
88
OperandConstraint, OperandKind, OperandPos, PReg, PRegSet, RegClass, VReg,
99
};
1010

11-
use arbitrary::Result as ArbitraryResult;
12-
use arbitrary::{Arbitrary, Unstructured};
11+
use super::arbitrary::Result as ArbitraryResult;
12+
use super::arbitrary::{Arbitrary, Unstructured};
1313

1414
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
1515
pub enum InstOpcode {
@@ -235,7 +235,7 @@ impl FuncBuilder {
235235
}
236236
}
237237

238-
impl Arbitrary for OperandConstraint {
238+
impl Arbitrary<'_> for OperandConstraint {
239239
fn arbitrary(u: &mut Unstructured) -> ArbitraryResult<Self> {
240240
Ok(*u.choose(&[OperandConstraint::Any, OperandConstraint::Reg])?)
241241
}
@@ -293,7 +293,7 @@ impl std::default::Default for Options {
293293
}
294294
}
295295

296-
impl Arbitrary for Func {
296+
impl Arbitrary<'_> for Func {
297297
fn arbitrary(u: &mut Unstructured) -> ArbitraryResult<Func> {
298298
Func::arbitrary_with_options(u, &Options::default())
299299
}

src/fuzzing/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,5 @@ pub mod ion {
2828
pub mod checker {
2929
pub use crate::checker::*;
3030
}
31+
32+
pub use libfuzzer_sys::{arbitrary, fuzz_target};

test/Cargo.toml

Lines changed: 0 additions & 28 deletions
This file was deleted.

0 commit comments

Comments
 (0)