From a757576fe331c89fef10a3c45f9aa74b82be2c4b Mon Sep 17 00:00:00 2001 From: Mikolaj Wielgus Date: Sat, 25 May 2024 00:33:58 +0200 Subject: [PATCH] tests: fix 0603 breakout test by passing a command file --- src/bin/topola-egui/app.rs | 4 ++-- tests/0603_breakout.rs | 28 +++++++++++++++------- tests/data/0603_breakout/autoroute_all.cmd | 21 ++++++++++++++++ 3 files changed, 42 insertions(+), 11 deletions(-) create mode 100644 tests/data/0603_breakout/autoroute_all.cmd diff --git a/src/bin/topola-egui/app.rs b/src/bin/topola-egui/app.rs index a5e31eb..94d59b9 100644 --- a/src/bin/topola-egui/app.rs +++ b/src/bin/topola-egui/app.rs @@ -206,8 +206,8 @@ impl eframe::App for App { execute(async move { if let Some(file_handle) = task.await { let path = file_handle.path(); - let mut file = File::open(path).unwrap(); let mut invoker = invoker_arc_mutex.lock().unwrap(); + let mut file = File::open(path).unwrap(); invoker.replay(serde_json::from_reader(file).unwrap()); } }); @@ -223,8 +223,8 @@ impl eframe::App for App { execute(async move { if let Some(file_handle) = task.await { let path = file_handle.path(); - let mut file = File::create(path).unwrap(); let mut invoker = invoker_arc_mutex.lock().unwrap(); + let mut file = File::create(path).unwrap(); serde_json::to_writer_pretty(file, invoker.history()); } }); diff --git a/tests/0603_breakout.rs b/tests/0603_breakout.rs index 877b38a..db222ee 100644 --- a/tests/0603_breakout.rs +++ b/tests/0603_breakout.rs @@ -2,11 +2,17 @@ use petgraph::{ unionfind::UnionFind, visit::{EdgeRef, IntoEdgeReferences, NodeIndexable}, }; -use std::sync::{Arc, Mutex}; +use std::{ + fs::File, + sync::{Arc, Mutex}, +}; use topola::{ - autorouter::Autorouter, dsn::design::DsnDesign, graph::GetNodeIndex, - router::EmptyRouterObserver, triangulation::GetVertexIndex, + autorouter::{invoker::Invoker, Autorouter}, + dsn::design::DsnDesign, + graph::GetNodeIndex, + router::EmptyRouterObserver, + triangulation::GetVertexIndex, }; #[test] @@ -14,8 +20,9 @@ fn test() { let design = DsnDesign::load_from_file("tests/data/0603_breakout/0603_breakout.dsn").unwrap(); let layout_arc_mutex = Arc::new(Mutex::new(design.make_layout())); - let mut autorouter = Autorouter::new(layout_arc_mutex.clone()).unwrap(); - autorouter.autoroute(&mut EmptyRouterObserver); + let mut invoker = Invoker::new(Autorouter::new(layout_arc_mutex.clone()).unwrap()); + let file = File::open("tests/data/0603_breakout/autoroute_all.cmd").unwrap(); + invoker.replay(serde_json::from_reader(file).unwrap()); let layout = layout_arc_mutex.lock().unwrap(); let mut unionfind = UnionFind::new(layout.drawing().geometry().graph().node_bound()); @@ -25,7 +32,8 @@ fn test() { } assert_eq!( - autorouter + invoker + .autorouter() .ratsnest() .graph() .edge_indices() @@ -34,15 +42,17 @@ fn test() { 2 ); - for ratline in autorouter.ratsnest().graph().edge_references() { - let from_index = autorouter + for ratline in invoker.autorouter().ratsnest().graph().edge_references() { + let from_index = invoker + .autorouter() .ratsnest() .graph() .node_weight(ratline.source()) .unwrap() .vertex_index() .node_index(); - let to_index = autorouter + let to_index = invoker + .autorouter() .ratsnest() .graph() .node_weight(ratline.target()) diff --git a/tests/data/0603_breakout/autoroute_all.cmd b/tests/data/0603_breakout/autoroute_all.cmd new file mode 100644 index 0000000..145fe4b --- /dev/null +++ b/tests/data/0603_breakout/autoroute_all.cmd @@ -0,0 +1,21 @@ +{ + "done": [ + { + "Autoroute": { + "pins": [ + "R1-2", + "J1-2" + ] + } + }, + { + "Autoroute": { + "pins": [ + "J1-1", + "R1-1" + ] + } + } + ], + "undone": [] +} \ No newline at end of file