more work on test case
This commit is contained in:
parent
9f68cbb953
commit
540a91878c
2 changed files with 28 additions and 36 deletions
|
|
@ -44,9 +44,10 @@ pub fn main_memory(config: &CpuConfig) {
|
||||||
// note that `read_addr` is `UInt<2>` since the memory only has 4 elements
|
// note that `read_addr` is `UInt<2>` since the memory only has 4 elements
|
||||||
//need to connect addr en clk and data->out
|
//need to connect addr en clk and data->out
|
||||||
connect_any(read_port.addr, addr); //FIXME
|
connect_any(read_port.addr, addr); //FIXME
|
||||||
connect(read_port.en, en);
|
connect_any(read_port.en, addr.cmp_lt(4u64));
|
||||||
connect(read_port.clk, cd.clk);
|
connect(read_port.clk, cd.clk);
|
||||||
connect(read_data,read_port.data);
|
connect(read_data,read_port.data);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -18,11 +18,9 @@ use fayalite::{
|
||||||
};
|
};
|
||||||
use std::num::NonZeroUsize;
|
use std::num::NonZeroUsize;
|
||||||
|
|
||||||
#[hdl]
|
//new test - much simpler
|
||||||
#[test]
|
#[test]
|
||||||
fn test_main_memory() {
|
fn test_main_memory() {
|
||||||
// see reg_alloc.rs for reference
|
|
||||||
let _n = SourceLocation::normalize_files_for_tests();
|
|
||||||
let mut config = CpuConfig::new(
|
let mut config = CpuConfig::new(
|
||||||
vec![
|
vec![
|
||||||
UnitConfig::new(UnitKind::AluBranch),
|
UnitConfig::new(UnitKind::AluBranch),
|
||||||
|
|
@ -30,35 +28,28 @@ fn test_main_memory() {
|
||||||
],
|
],
|
||||||
NonZeroUsize::new(20).unwrap(),
|
NonZeroUsize::new(20).unwrap(),
|
||||||
);
|
);
|
||||||
config.fetch_width = NonZeroUsize::new(2).unwrap(); //unchanged for now
|
// create a simulation from main_memory()
|
||||||
let m = main_memory(&config);
|
let mut sim = Simulation::new(main_memory(&config));
|
||||||
let mut sim = Simulation::new(m);
|
// add a .vcd writer that writes to main_memory.vcd -- this is simple for demo purposes,
|
||||||
let mut writer = RcWriter::default();
|
// but for our actual code we should do better than just writing
|
||||||
sim.add_trace_writer(VcdWriterDecls::new(writer.clone()));
|
// to main_memory.vcd in the repository's root
|
||||||
sim.write_clock(sim.io().cd.clk, false);
|
//WRONG: sim.add_trace_writer(std::fs::File::create("main_memory.vcd").unwrap());
|
||||||
sim.write_reset(sim.io().cd.rst, true);
|
|
||||||
//TODO sim.write_bool
|
let out_file = std::fs::File::create("main_memory.vcd").unwrap();
|
||||||
//TODO sim.write(
|
sim.add_trace_writer(VcdWriterDecls::new(out_file));
|
||||||
//footer for tests
|
|
||||||
// FIXME: vcd is just whatever reg_alloc does now, which isn't known to be correct
|
sim.write(sim.io().en, true);
|
||||||
let vcd = String::from_utf8(writer.take()).unwrap();
|
sim.write(sim.io().cd.rst, false);
|
||||||
println!("####### VCD:\n{vcd}\n#######");
|
sim.write(sim.io().cd.clk, false);
|
||||||
//if vcd != include_str!("expected/reg_alloc.vcd") { //FIXME panic on result compare
|
|
||||||
// panic!(); //test is incomplete here, getting panic
|
// TODO convert to for loop
|
||||||
//}
|
// you need to write an initial value to all inputs before you can start running the simulation
|
||||||
// #[rustfmt::skip] // work around https://github.com/rust-lang/rustfmt/issues/6161
|
sim.write(sim.io().addr, 0x12345u64);
|
||||||
// assert_export_firrtl! {
|
// now wait 1us because why not
|
||||||
// m =>
|
sim.advance_time(SimDuration::from_micros(1)); //panic here at simulation
|
||||||
// options: ExportOptions {
|
|
||||||
// simplify_enums: None,
|
dbg!(sim.read(sim.io().read_data)); // dbg! macro just displays the value you pass to it
|
||||||
// ..ExportOptions::default()
|
|
||||||
// },
|
|
||||||
// "/test/reg_alloc.fir": "",
|
sim.flush_traces().unwrap(); // make sure everything is written to the output file
|
||||||
// };
|
}
|
||||||
// let sim_debug = format!("{sim:#?}");
|
|
||||||
// println!("#######\n{sim_debug}\n#######");
|
|
||||||
// if sim_debug != include_str!("expected/reg_alloc.txt") {
|
|
||||||
// panic!();
|
|
||||||
// }
|
|
||||||
|
|
||||||
}
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue