diff --git a/crates/specctra-core/fuzz/fuzz_targets/fuzz_target_2.rs b/crates/specctra-core/fuzz/fuzz_targets/fuzz_target_2.rs index eeffd22..384c923 100644 --- a/crates/specctra-core/fuzz/fuzz_targets/fuzz_target_2.rs +++ b/crates/specctra-core/fuzz/fuzz_targets/fuzz_target_2.rs @@ -5,7 +5,7 @@ use libfuzzer_sys::fuzz_target; fuzz_target!(|data: &str| { let cursor = std::io::Cursor::new(data); - use specctra_core::{read::ListTokenizer, write::ListWriter, structure::Structure}; + use specctra_core::{read::ListTokenizer, structure::Structure, write::ListWriter}; let mut tkz = ListTokenizer::new(cursor); @@ -13,7 +13,16 @@ fuzz_target!(|data: &str| { if let Ok(val) = res { let mut dat = Vec::new(); - let mut lw = ListWriter::new(&mut dat); - let _ = lw.write_value(&val); + { + let mut lw = ListWriter::new(&mut dat); + let _ = lw.write_value(&val).unwrap(); + } + + let cursor = std::io::Cursor::new(dat); + let mut tkz = ListTokenizer::new(cursor); + let val2 = tkz.read_value::().unwrap(); + + // make sure that serialization+parsing after parsing is identity + assert_eq!(val, val2); } }); diff --git a/crates/specctra-core/src/structure.rs b/crates/specctra-core/src/structure.rs index b8e4951..385065e 100644 --- a/crates/specctra-core/src/structure.rs +++ b/crates/specctra-core/src/structure.rs @@ -7,7 +7,7 @@ use crate::ListToken; use specctra_derive::ReadDsn; use specctra_derive::WriteSes; -#[derive(ReadDsn, WriteSes, Debug)] +#[derive(ReadDsn, WriteSes, Debug, Clone, PartialEq)] pub struct Dummy {} #[derive(ReadDsn, WriteSes, Debug)] @@ -15,27 +15,27 @@ pub struct SesFile { pub session: Session, } -#[derive(ReadDsn, WriteSes, Debug)] +#[derive(ReadDsn, WriteSes, Debug, Clone, PartialEq)] pub struct Session { #[anon] pub id: String, pub routes: Routes, } -#[derive(ReadDsn, WriteSes, Debug)] +#[derive(ReadDsn, WriteSes, Debug, Clone, PartialEq)] pub struct Routes { pub resolution: Resolution, pub library_out: Library, pub network_out: NetworkOut, } -#[derive(ReadDsn, WriteSes, Debug)] +#[derive(ReadDsn, WriteSes, Debug, Clone, PartialEq)] pub struct NetworkOut { #[vec("net")] pub net: Vec, } -#[derive(ReadDsn, WriteSes, Debug)] +#[derive(ReadDsn, WriteSes, Debug, Clone, PartialEq)] pub struct NetOut { #[anon] pub name: String, @@ -50,7 +50,7 @@ pub struct DsnFile { pub pcb: Pcb, } -#[derive(ReadDsn, WriteSes, Debug)] +#[derive(ReadDsn, WriteSes, Debug, Clone, PartialEq)] pub struct Pcb { #[anon] pub name: String, @@ -64,7 +64,7 @@ pub struct Pcb { pub wiring: Wiring, } -#[derive(WriteSes, Debug)] +#[derive(WriteSes, Debug, Clone, PartialEq)] pub struct Parser { pub string_quote: Option, pub space_in_quoted_tokens: Option, @@ -72,7 +72,7 @@ pub struct Parser { pub host_version: Option, } -#[derive(ReadDsn, WriteSes, Debug)] +#[derive(ReadDsn, WriteSes, Debug, Clone, PartialEq)] pub struct Resolution { #[anon] pub unit: String, @@ -80,7 +80,7 @@ pub struct Resolution { pub value: f32, } -#[derive(WriteSes, Debug)] +#[derive(WriteSes, Debug, Clone, PartialEq)] pub struct Structure { #[vec("layer")] pub layers: Vec, @@ -120,7 +120,7 @@ impl ReadDsn for Structure { } } -#[derive(ReadDsn, WriteSes, Debug)] +#[derive(ReadDsn, WriteSes, Debug, Clone, PartialEq)] pub struct Layer { #[anon] pub name: String, @@ -128,30 +128,30 @@ pub struct Layer { pub property: Option, } -#[derive(ReadDsn, WriteSes, Debug)] +#[derive(ReadDsn, WriteSes, Debug, Clone, PartialEq)] pub struct Property { pub index: usize, } -#[derive(ReadDsn, WriteSes, Debug)] +#[derive(ReadDsn, WriteSes, Debug, Clone, PartialEq)] pub struct Boundary { pub path: Path, } -#[derive(ReadDsn, WriteSes, Debug)] +#[derive(ReadDsn, WriteSes, Debug, Clone, PartialEq)] pub struct Plane { #[anon] pub net: String, pub polygon: Polygon, } -#[derive(ReadDsn, WriteSes, Debug)] +#[derive(ReadDsn, WriteSes, Debug, Clone, PartialEq)] pub struct ViaNames { #[anon_vec] pub names: Vec, } -#[derive(ReadDsn, WriteSes, Debug)] +#[derive(ReadDsn, WriteSes, Debug, Clone, PartialEq)] pub struct Grid { #[anon] pub kind: String, @@ -159,20 +159,20 @@ pub struct Grid { pub value: f64, } -#[derive(ReadDsn, WriteSes, Debug)] +#[derive(ReadDsn, WriteSes, Debug, Clone, PartialEq)] pub struct StructureRule { pub width: Option, #[vec("clearance", "clear")] pub clearances: Vec, } -#[derive(ReadDsn, WriteSes, Debug)] +#[derive(ReadDsn, WriteSes, Debug, Clone, PartialEq)] pub struct Placement { #[vec("component")] pub components: Vec, } -#[derive(ReadDsn, WriteSes, Debug)] +#[derive(ReadDsn, WriteSes, Debug, Clone, PartialEq)] pub struct Component { #[anon] pub name: String, @@ -180,7 +180,7 @@ pub struct Component { pub places: Vec, } -#[derive(ReadDsn, WriteSes, Debug)] +#[derive(ReadDsn, WriteSes, Debug, Clone, PartialEq)] #[allow(non_snake_case)] pub struct Place { #[anon] @@ -205,7 +205,7 @@ impl Place { } } -#[derive(ReadDsn, WriteSes, Debug)] +#[derive(ReadDsn, WriteSes, Debug, Clone, PartialEq)] pub struct Library { #[vec("image")] pub images: Vec, @@ -219,7 +219,7 @@ impl Library { } } -#[derive(ReadDsn, WriteSes, Debug)] +#[derive(ReadDsn, WriteSes, Debug, Clone, PartialEq)] pub struct Image { #[anon] pub name: String, @@ -231,12 +231,12 @@ pub struct Image { pub keepouts: Vec, } -#[derive(ReadDsn, WriteSes, Debug)] +#[derive(ReadDsn, WriteSes, Debug, Clone, PartialEq)] pub struct Outline { pub path: Path, } -#[derive(ReadDsn, WriteSes, Debug)] +#[derive(ReadDsn, WriteSes, Debug, Clone, PartialEq)] pub struct Pin { #[anon] pub name: String, @@ -258,7 +258,7 @@ impl Pin { } } -#[derive(ReadDsn, WriteSes, Debug)] +#[derive(ReadDsn, WriteSes, Debug, Clone, PartialEq)] pub struct Keepout { #[anon] pub idk: String, @@ -266,7 +266,7 @@ pub struct Keepout { pub shape: Shape, } -#[derive(ReadDsn, WriteSes, Debug)] +#[derive(ReadDsn, WriteSes, Debug, Clone, PartialEq)] pub struct Padstack { #[anon] pub name: String, @@ -276,7 +276,7 @@ pub struct Padstack { } // TODO: derive for enums if more than this single one is needed -#[derive(Debug)] +#[derive(Debug, Clone, PartialEq)] pub enum Shape { Circle(Circle), Rect(Rect), @@ -311,7 +311,7 @@ impl WriteSes for Shape { } } -#[derive(ReadDsn, WriteSes, Debug)] +#[derive(ReadDsn, WriteSes, Debug, Clone, PartialEq)] pub struct Circle { #[anon] pub layer: String, @@ -321,7 +321,7 @@ pub struct Circle { pub offset: Option, } -#[derive(ReadDsn, WriteSes, Debug)] +#[derive(ReadDsn, WriteSes, Debug, Clone, PartialEq)] pub struct Network { #[vec("net")] pub nets: Vec, @@ -329,7 +329,7 @@ pub struct Network { pub classes: Vec, } -#[derive(ReadDsn, WriteSes, Debug)] +#[derive(ReadDsn, WriteSes, Debug, Clone, PartialEq)] // dsn names this "net", but it's a structure unrelated to "net" in wiring or elsewhere pub struct NetPinAssignments { #[anon] @@ -337,13 +337,13 @@ pub struct NetPinAssignments { pub pins: Option, } -#[derive(ReadDsn, WriteSes, Debug)] +#[derive(ReadDsn, WriteSes, Debug, Clone, PartialEq)] pub struct Pins { #[anon_vec] pub names: Vec, } -#[derive(ReadDsn, WriteSes, Debug)] +#[derive(ReadDsn, WriteSes, Debug, Clone, PartialEq)] pub struct Class { #[anon] pub name: String, @@ -353,12 +353,12 @@ pub struct Class { pub rule: Rule, } -#[derive(ReadDsn, WriteSes, Debug)] +#[derive(ReadDsn, WriteSes, Debug, Clone, PartialEq)] pub struct Circuit { pub use_via: String, } -#[derive(ReadDsn, WriteSes, Debug)] +#[derive(ReadDsn, WriteSes, Debug, Clone, PartialEq)] pub struct Wiring { #[vec("wire")] pub wires: Vec, @@ -366,14 +366,14 @@ pub struct Wiring { pub vias: Vec, } -#[derive(ReadDsn, WriteSes, Debug)] +#[derive(ReadDsn, WriteSes, Debug, Clone, PartialEq)] pub struct Wire { pub path: Path, pub net: String, pub r#type: String, } -#[derive(ReadDsn, WriteSes, Debug)] +#[derive(ReadDsn, WriteSes, Debug, Clone, PartialEq)] pub struct WireOut { pub path: Path, } @@ -386,7 +386,7 @@ pub struct WireOut { // more conveniently represented as fields on the enclosing struct) // It exists to give a way to read arrays of coordinates // (and enforce that such an array actually contains a whole number of points) -#[derive(Debug)] +#[derive(Debug, Clone, PartialEq)] pub struct Point { pub x: f64, pub y: f64, @@ -439,7 +439,7 @@ impl WriteSes for Option { } } -#[derive(ReadDsn, WriteSes, Debug)] +#[derive(ReadDsn, WriteSes, Debug, Clone, PartialEq)] pub struct Polygon { #[anon] pub layer: String, @@ -449,7 +449,7 @@ pub struct Polygon { pub coords: Vec, } -#[derive(ReadDsn, WriteSes, Debug)] +#[derive(ReadDsn, WriteSes, Debug, Clone, PartialEq)] pub struct Path { #[anon] pub layer: String, @@ -459,7 +459,7 @@ pub struct Path { pub coords: Vec, } -#[derive(ReadDsn, WriteSes, Debug)] +#[derive(ReadDsn, WriteSes, Debug, Clone, PartialEq)] pub struct Rect { #[anon] pub layer: String, @@ -473,7 +473,7 @@ pub struct Rect { pub y2: f64, } -#[derive(ReadDsn, WriteSes, Debug)] +#[derive(ReadDsn, WriteSes, Debug, Clone, PartialEq)] pub struct Via { #[anon] pub name: String, @@ -485,14 +485,14 @@ pub struct Via { pub r#type: String, } -#[derive(ReadDsn, WriteSes, Debug)] +#[derive(ReadDsn, WriteSes, Debug, Clone, PartialEq)] pub struct Rule { pub width: f32, #[vec("clearance")] pub clearances: Vec, } -#[derive(ReadDsn, WriteSes, Clone, Debug)] +#[derive(ReadDsn, WriteSes, Debug, Clone, PartialEq)] pub struct Clearance { #[anon] pub value: f32,