Files
diodeinc__pcb/crates/pcb-layout/tests/layout_generation.rs
Akhil Velagapudi 44c73baf2d [DIO-319] Add board config to pcb.toml, pcb info (#92)
* Add board config to pcb.toml, pcb info

Signed-off-by: akhilles <akhilvelagapudi@gmail.com>

* Choose first board (when sorted) as fallback default

Signed-off-by: akhilles <akhilvelagapudi@gmail.com>

* Add secondary heuristics pass to detect boards without pcb.toml

Signed-off-by: akhilles <akhilvelagapudi@gmail.com>

* Update snapshots

Signed-off-by: akhilles <akhilvelagapudi@gmail.com>

* Don't allow malformed pcb.toml

Empty pcb.toml is fine.

Signed-off-by: akhilles <akhilvelagapudi@gmail.com>

* Don't copy .pcb/cache into test fixture

Signed-off-by: akhilles <akhilvelagapudi@gmail.com>

* Replace test-workspace with snapshot tests of pcb info

Signed-off-by: akhilles <akhilvelagapudi@gmail.com>

---------

Signed-off-by: akhilles <akhilvelagapudi@gmail.com>
2025-08-21 15:20:16 -07:00

78 lines
2.7 KiB
Rust

use anyhow::Result;
use assert_fs::prelude::*;
use assert_fs::TempDir;
use pcb_layout::process_layout;
use serial_test::serial;
mod helpers;
use helpers::*;
macro_rules! layout_test {
($name:expr, $board_name:expr) => {
paste::paste! {
#[test]
#[serial]
fn [<test_layout_generation_with_ $name:snake>]() -> Result<()> {
// Create a temp directory and copy the test resources
let temp = TempDir::new()?.into_persistent();
let resource_path = get_resource_path($name);
temp.copy_from(&resource_path, &["**/*", "!.pcb/cache/**/*"])?;
// Find and evaluate the board zen file
let zen_file = temp.path().join(format!("{}.zen", $board_name));
assert!(zen_file.exists(), "{}.zen should exist", $board_name);
// Evaluate the Zen file to generate a schematic
let eval_result = pcb_zen::run(&zen_file, false);
// Check for errors in evaluation
if !eval_result.diagnostics.is_empty() {
eprintln!("Zen evaluation diagnostics:");
for diag in &eval_result.diagnostics {
eprintln!(" {:?}", diag);
}
}
let schematic = eval_result
.output
.expect("Zen evaluation should produce a schematic");
// Process the layout
let result = process_layout(&schematic, &zen_file)?;
// Verify the layout was created
assert!(result.pcb_file.exists(), "PCB file should exist");
assert!(result.netlist_file.exists(), "Netlist file should exist");
assert!(result.snapshot_file.exists(), "Snapshot file should exist");
assert!(result.log_file.exists(), "Log file should exist");
// Print the log file contents
let log_contents = std::fs::read_to_string(&result.log_file)?;
println!("Layout log file contents:");
println!("========================");
println!("{}", log_contents);
println!("========================");
// Check the snapshot matches
assert_file_snapshot!(
format!("{}.layout.json", $name),
result.snapshot_file
);
Ok(())
}
}
};
}
// Schematic: A couple BMI270 modules in Starlark.
layout_test!("simple", "MyBoard");
layout_test!("module_layout", "Main");
layout_test!("component_side_sync", "Board");
layout_test!("multi_pads", "MultiPads");
layout_test!("dnp", "MyBoard");