Skip to content

Commit

Permalink
add more variable types and better error messages for diff test
Browse files Browse the repository at this point in the history
  • Loading branch information
ekiwi committed Nov 10, 2023
1 parent 0a88d03 commit 5055bc9
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 5 deletions.
19 changes: 16 additions & 3 deletions src/hierarchy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,10 +124,23 @@ pub enum ScopeType {

#[derive(Debug, Clone, Copy)]
pub enum VarType {
Wire,
Reg,
Parameter,
Event,
Integer,
Parameter,
Real,
Reg,
Supply0,
Supply1,
Time,
Tri,
TriAnd,
TriOr,
TriReg,
Tri0,
Tri1,
WAnd,
Wire,
WOr,
String,
}

Expand Down
13 changes: 13 additions & 0 deletions src/vcd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,19 @@ fn convert_var_tpe(tpe: &[u8]) -> VarType {
b"parameter" => VarType::Parameter,
b"integer" => VarType::Integer,
b"string" => VarType::String,
b"event" => VarType::Event,
b"real" => VarType::Real,
b"supply0" => VarType::Supply0,
b"supply1" => VarType::Supply1,
b"time" => VarType::Time,
b"tri" => VarType::Tri,
b"triand" => VarType::TriAnd,
b"trior" => VarType::TriOr,
b"trireg" => VarType::TriReg,
b"tri0" => VarType::Tri0,
b"tri1" => VarType::Tri1,
b"wand" => VarType::WAnd,
b"wor" => VarType::WOr,
_ => panic!("TODO: convert {}", String::from_utf8_lossy(tpe)),
}
}
Expand Down
52 changes: 50 additions & 2 deletions tests/diff_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,19 @@ fn waveform_var_type_to_string(tpe: VarType) -> &'static str {
VarType::Parameter => "parameter",
VarType::Integer => "integer",
VarType::String => "string",
VarType::Event => "event",
VarType::Real => "real",
VarType::Supply0 => "supply0",
VarType::Supply1 => "supply1",
VarType::Time => "time",
VarType::Tri => "tri",
VarType::TriAnd => "triand",
VarType::TriOr => "trior",
VarType::TriReg => "trireg",
VarType::Tri0 => "tri0",
VarType::Tri1 => "tri1",
VarType::WAnd => "wand",
VarType::WOr => "wor",
}
}

Expand Down Expand Up @@ -165,7 +178,16 @@ fn diff_signals<R: BufRead>(ref_reader: &mut vcd::Parser<R>, our: &mut Waveform)
let signal_ref = vcd_lib_id_to_signal_ref(id);
let our_value = our.get_signal_value_at(signal_ref, time_table_idx as u32);
let our_value_str = our_value.to_bit_string().unwrap();
assert_eq!(our_value_str, value.to_string());
assert_eq!(
our_value_str,
value.to_string(),
"{} ({:?}) = {} @ {} ({})",
id,
signal_ref,
value,
current_time,
our_value_str
);
}
vcd::Command::ChangeVector(id, value) => {
let signal_ref = vcd_lib_id_to_signal_ref(id);
Expand Down Expand Up @@ -197,7 +219,16 @@ fn diff_signals<R: BufRead>(ref_reader: &mut vcd::Parser<R>, our: &mut Waveform)
}
}
} else {
assert_eq!(our_value_str, value.to_string());
assert_eq!(
our_value_str,
value.to_string(),
"{} ({:?}) = {} @ {} ({})",
id,
signal_ref,
value,
current_time,
our_value_str
);
}
}
vcd::Command::ChangeReal(_, _) => {
Expand Down Expand Up @@ -307,6 +338,23 @@ fn diff_icarus_test1() {
run_diff_test("inputs/icarus/test1.vcd", "inputs/icarus/test1.vcd.fst");
}

#[test]
fn diff_model_sim_clkdiv2n_tb() {
run_diff_test(
"inputs/model-sim/clkdiv2n_tb.vcd",
"inputs/model-sim/clkdiv2n_tb.vcd.fst",
);
}

#[test]
#[ignore] // TODO: this file has a delta cycle, i.e. the same signal (`p`) changes twice in the same cycle (20000)
fn diff_model_sim_cpu_design() {
run_diff_test(
"inputs/model-sim/CPU_Design.msim.vcd",
"inputs/model-sim/CPU_Design.msim.vcd.fst",
);
}

#[test]
fn diff_treadle_gcd() {
run_diff_test("inputs/treadle/GCD.vcd", "inputs/treadle/GCD.vcd.fst");
Expand Down

0 comments on commit 5055bc9

Please sign in to comment.