From 2b95832cf7f5369af3bd707765794ac4159485e8 Mon Sep 17 00:00:00 2001 From: Mikolaj Wielgus Date: Sat, 19 Jul 2025 16:11:08 +0200 Subject: [PATCH] test: Test tht_de9_to_tht_de9 with permuted autorouting as well --- tests/common/mod.rs | 32 ++++++- tests/single_layer.rs | 9 +- .../tht_de9_to_tht_de9/autoroute_all.cmd | 92 +++++++++++++++++++ 3 files changed, 127 insertions(+), 6 deletions(-) create mode 100644 tests/single_layer/tht_de9_to_tht_de9/autoroute_all.cmd diff --git a/tests/common/mod.rs b/tests/common/mod.rs index 0a71a2b..588081a 100644 --- a/tests/common/mod.rs +++ b/tests/common/mod.rs @@ -12,7 +12,7 @@ use topola::{ Autorouter, }, board::{edit::BoardEdit, AccessMesadata, Board}, - drawing::graph::GetMaybeNet, + drawing::graph::{GetMaybeNet, PrimitiveIndex}, geometry::{shape::MeasureLength, GenericNode, GetLayer}, graph::{GetPetgraphIndex, MakeRef}, router::{navmesh::Navmesh, RouterOptions}, @@ -77,10 +77,7 @@ pub fn replay_and_assert(invoker: &mut Invoker, filename: &str let file = File::open(filename).unwrap(); let history: History = serde_json::from_reader(file).unwrap(); - for _ in 0..history.done().len() { - invoker.undo().unwrap(); - } - + undo_all_and_assert(invoker); invoker.replay(history); assert_eq!( @@ -89,6 +86,31 @@ pub fn replay_and_assert(invoker: &mut Invoker, filename: &str ); } +pub fn undo_all_and_assert(invoker: &mut Invoker) { + for _ in 0..invoker.history().done().len() { + invoker.undo().unwrap(); + } + + assert!(matches!( + invoker.undo(), + Err(InvokerError::History(HistoryError::NoPreviousCommand)) + )); + + assert_no_loose_nodes(invoker.autorouter()); +} + +pub fn assert_no_loose_nodes(autorouter: &Autorouter) { + for node in autorouter.board().layout().drawing().primitive_nodes() { + match node { + PrimitiveIndex::LooseDot(..) + | PrimitiveIndex::LoneLooseSeg(..) + | PrimitiveIndex::SeqLooseSeg(..) + | PrimitiveIndex::LooseBend(..) => assert!(false), + _ => (), + } + } +} + pub fn assert_navnode_count( autorouter: &mut Autorouter, origin_pin: &str, diff --git a/tests/single_layer.rs b/tests/single_layer.rs index dc290de..b086445 100644 --- a/tests/single_layer.rs +++ b/tests/single_layer.rs @@ -24,9 +24,16 @@ fn test_tht_de9_to_tht_de9() { "tests/single_layer/tht_de9_to_tht_de9/autoroute_all_in_an_order.cmd", ); - let (mut autorouter, ..) = invoker.dissolve(); + let (mut autorouter, history, ..) = invoker.dissolve(); common::assert_single_layer_groundless_autoroute(&mut autorouter, "F.Cu"); + + invoker = Invoker::new_with_history(autorouter, history); + common::undo_all_and_assert(&mut invoker); + common::replay_and_assert( + &mut invoker, + "tests/single_layer/tht_de9_to_tht_de9/autoroute_all.cmd", + ); } #[test] diff --git a/tests/single_layer/tht_de9_to_tht_de9/autoroute_all.cmd b/tests/single_layer/tht_de9_to_tht_de9/autoroute_all.cmd new file mode 100644 index 0000000..66f30ee --- /dev/null +++ b/tests/single_layer/tht_de9_to_tht_de9/autoroute_all.cmd @@ -0,0 +1,92 @@ +{ + "done": [ + { + "Autoroute": [ + [ + { + "pin": "J1-1", + "layer": "F.Cu" + }, + { + "pin": "J1-2", + "layer": "F.Cu" + }, + { + "pin": "J1-3", + "layer": "F.Cu" + }, + { + "pin": "J1-4", + "layer": "F.Cu" + }, + { + "pin": "J1-5", + "layer": "F.Cu" + }, + { + "pin": "J1-6", + "layer": "F.Cu" + }, + { + "pin": "J1-7", + "layer": "F.Cu" + }, + { + "pin": "J1-8", + "layer": "F.Cu" + }, + { + "pin": "J1-9", + "layer": "F.Cu" + }, + { + "pin": "J2-1", + "layer": "F.Cu" + }, + { + "pin": "J2-2", + "layer": "F.Cu" + }, + { + "pin": "J2-3", + "layer": "F.Cu" + }, + { + "pin": "J2-4", + "layer": "F.Cu" + }, + { + "pin": "J2-5", + "layer": "F.Cu" + }, + { + "pin": "J2-6", + "layer": "F.Cu" + }, + { + "pin": "J2-7", + "layer": "F.Cu" + }, + { + "pin": "J2-8", + "layer": "F.Cu" + }, + { + "pin": "J2-9", + "layer": "F.Cu" + } + ], + { + "presort_by": "RatlineIntersectionCountAndLength", + "permutate": true, + "router_options": { + "routed_band_width": 100.0, + "wrap_around_bands": true, + "squeeze_through_under_bends": true + } + } + ] + } + ], + "undone": [] +} \ No newline at end of file