From 91480453b3ebd0c1a41a3069757f769a1b816d93 Mon Sep 17 00:00:00 2001 From: Mikolaj Wielgus Date: Fri, 7 Jun 2024 02:14:05 +0200 Subject: [PATCH] tests: add 3-pin XLR THT female to THT female test Hardly functional so far. --- src/autorouter/invoker.rs | 6 +- tests/common/mod.rs | 28 +++++-- tests/single_layer.rs | 76 ++++++------------- .../~0603_breakout.kicad_pcb.lck | 1 - .../autoroute_all.cmd | 35 +++++++++ 5 files changed, 87 insertions(+), 59 deletions(-) delete mode 100644 tests/single_layer/data/0603_breakout/~0603_breakout.kicad_pcb.lck create mode 100644 tests/single_layer/data/3pin_xlr_tht_female_to_tht_female/autoroute_all.cmd diff --git a/src/autorouter/invoker.rs b/src/autorouter/invoker.rs index 6ba43e6..c747869 100644 --- a/src/autorouter/invoker.rs +++ b/src/autorouter/invoker.rs @@ -58,9 +58,13 @@ pub struct Invoker { impl Invoker { pub fn new(autorouter: Autorouter) -> Self { + Self::new_with_history(autorouter, History::new()) + } + + pub fn new_with_history(autorouter: Autorouter, history: History) -> Self { Self { autorouter, - history: History::new(), + history, } } diff --git a/tests/common/mod.rs b/tests/common/mod.rs index 91812f0..a8bbb68 100644 --- a/tests/common/mod.rs +++ b/tests/common/mod.rs @@ -1,4 +1,4 @@ -use petgraph::{unionfind::UnionFind, visit::NodeIndexable}; +use petgraph::{stable_graph::NodeIndex, unionfind::UnionFind, visit::NodeIndexable}; use topola::{ autorouter::{board::Board, Autorouter}, drawing::{ @@ -8,10 +8,7 @@ use topola::{ graph::GetNodeIndex, }; -pub fn assert_single_layer_groundless_autoroute( - autorouter: &mut Autorouter, - layername: &str, -) { +fn unionfind(autorouter: &mut Autorouter) -> UnionFind> { for ratline in autorouter.ratsnest().graph().edge_indices() { // Accessing endpoints may create new dots because apex construction is lazy, so we access // tem all before starting unionfind, as it requires a constant index bound. @@ -40,6 +37,15 @@ pub fn assert_single_layer_groundless_autoroute( } } + unionfind +} + +pub fn assert_single_layer_groundless_autoroute( + autorouter: &mut Autorouter, + layername: &str, +) { + let unionfind = unionfind(autorouter); + for ratline in autorouter.ratsnest().graph().edge_indices() { let (source_dot, target_dot) = autorouter.ratline_endpoints(ratline); @@ -100,6 +106,18 @@ pub fn assert_single_layer_groundless_autoroute( } } +/*pub fn assert_number_of_conncomps( + autorouter: &mut Autorouter, + conncomp_count: usize, +) { + let unionfind = unionfind(autorouter); + let mut labels = unionfind.into_labeling(); + labels.sort_unstable(); + labels.dedup(); + + assert_eq!(labels.len(), conncomp_count); +}*/ + pub fn assert_band_length( board: &Board, source: &str, diff --git a/tests/single_layer.rs b/tests/single_layer.rs index 22deaf4..8e377eb 100644 --- a/tests/single_layer.rs +++ b/tests/single_layer.rs @@ -27,59 +27,10 @@ fn test_0603_breakout() { let file = File::open("tests/single_layer/data/0603_breakout/autoroute_all.cmd").unwrap(); invoker.replay(serde_json::from_reader(file).unwrap()); - let mut unionfind = UnionFind::new( - invoker - .autorouter() - .board() - .layout() - .drawing() - .geometry() - .graph() - .node_bound(), - ); + let (mut autorouter, ..) = invoker.destruct(); - for edge in invoker - .autorouter() - .board() - .layout() - .drawing() - .geometry() - .graph() - .edge_references() - { - unionfind.union(edge.source(), edge.target()); - } - - assert_eq!( - invoker - .autorouter() - .ratsnest() - .graph() - .edge_indices() - .collect::>() - .len(), - 2 - ); - - for ratline in invoker.autorouter().ratsnest().graph().edge_references() { - let from_index = invoker - .autorouter() - .ratsnest() - .graph() - .node_weight(ratline.source()) - .unwrap() - .trianvertex_index() - .node_index(); - let to_index = invoker - .autorouter() - .ratsnest() - .graph() - .node_weight(ratline.target()) - .unwrap() - .trianvertex_index() - .node_index(); - assert_eq!(unionfind.find(from_index), unionfind.find(to_index)); - } + common::assert_single_layer_groundless_autoroute(&mut autorouter, "F.Cu"); + //common::assert_number_of_conncomps(&mut autorouter, 2); } #[test] @@ -97,6 +48,7 @@ fn test_tht_diode_bridge_rectifier() { let (mut autorouter, ..) = invoker.destruct(); common::assert_single_layer_groundless_autoroute(&mut autorouter, "F.Cu"); + //common::assert_number_of_conncomps(&mut autorouter, 4); common::assert_band_length(autorouter.board(), "J2-2", "D4-2", 15511.0, 0.5); } @@ -116,4 +68,24 @@ fn test_four_3rd_order_smd_lc_filters() { let (mut autorouter, ..) = invoker.destruct(); common::assert_single_layer_groundless_autoroute(&mut autorouter, "F.Cu"); + //common::assert_number_of_conncomps(&mut autorouter, 16); +} + +#[test] +fn test_3pin_xlr_tht_female_to_tht_female() { + let design = DsnDesign::load_from_file( + "tests/single_layer/data/3pin_xlr_tht_female_to_tht_female/3pin_xlr_tht_female_to_tht_female.dsn" + ); + let board = design.unwrap().make_board(); + + let mut invoker = Invoker::new(Autorouter::new(board).unwrap()); + let file = + File::open("tests/single_layer/data/3pin_xlr_tht_female_to_tht_female/autoroute_all.cmd") + .unwrap(); + invoker.replay(serde_json::from_reader(file).unwrap()); + + let (mut autorouter, ..) = invoker.destruct(); + + // FIXME: The routing result is pretty bad. + common::assert_single_layer_groundless_autoroute(&mut autorouter, "F.Cu"); } diff --git a/tests/single_layer/data/0603_breakout/~0603_breakout.kicad_pcb.lck b/tests/single_layer/data/0603_breakout/~0603_breakout.kicad_pcb.lck deleted file mode 100644 index 5cac09d..0000000 --- a/tests/single_layer/data/0603_breakout/~0603_breakout.kicad_pcb.lck +++ /dev/null @@ -1 +0,0 @@ -{"hostname":"luckmann","username":"mikolaj"} \ No newline at end of file diff --git a/tests/single_layer/data/3pin_xlr_tht_female_to_tht_female/autoroute_all.cmd b/tests/single_layer/data/3pin_xlr_tht_female_to_tht_female/autoroute_all.cmd new file mode 100644 index 0000000..62b938f --- /dev/null +++ b/tests/single_layer/data/3pin_xlr_tht_female_to_tht_female/autoroute_all.cmd @@ -0,0 +1,35 @@ +{ + "done": [ + { + "Autoroute": { + "selectors": [ + { + "pin": "J2-2", + "layer": "F.Cu" + }, + { + "pin": "J1-2", + "layer": "F.Cu" + }, + { + "pin": "J2-3", + "layer": "F.Cu" + }, + { + "pin": "J2-1", + "layer": "F.Cu" + }, + { + "pin": "J1-3", + "layer": "F.Cu" + }, + { + "pin": "J1-1", + "layer": "F.Cu" + } + ] + } + } + ], + "undone": [] +} \ No newline at end of file