Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions src/diff.rs
Original file line number Diff line number Diff line change
Expand Up @@ -370,12 +370,22 @@ fn compare_signal_channels<W: Write>(
}

// Anything still in the buffer was in file2 but never matched by file1.
for ((time, handle), value) in &buffered2 {
// Sort rows before printing so diff output does not depend on HashMap
// iteration order.
let owned: Vec<((u64, usize), OwnedSignalValue)> = buffered2.drain().collect();
if !owned.is_empty() {
has_differences = true;
}
let mut file2_only_rows: Vec<(u64, String, usize)> = Vec::new();
for (idx, ((time, handle), _)) in owned.iter().enumerate() {
for name in format_handle_names(*handle, &hier2.signal_map, &hier2.names) {
writeln!(writer, "{} {} {} (only in file2)", time, name, value)?;
file2_only_rows.push((*time, name, idx));
}
}
file2_only_rows.sort_by(|a, b| a.0.cmp(&b.0).then_with(|| a.1.cmp(&b.1)));
for (time, name, idx) in file2_only_rows {
writeln!(writer, "{} {} {} (only in file2)", time, name, owned[idx].1)?;
}

// Drain any remaining file2 batches we never read from the channel.
if !source2_ended {
Expand Down
14 changes: 14 additions & 0 deletions tests/data/buffered_file2_base.vcd
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
$timescale 1 ns $end
$scope module t $end
$var wire 1 ! a $end
$var wire 1 " b $end
$var wire 1 # c $end
$upscope $end
$enddefinitions $end
$dumpvars
0!
0"
0#
$end
#20
1!
18 changes: 18 additions & 0 deletions tests/data/buffered_file2_extra.vcd
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
$timescale 1 ns $end
$scope module t $end
$var wire 1 ! a $end
$var wire 1 " b $end
$var wire 1 # c $end
$upscope $end
$enddefinitions $end
$dumpvars
0!
0"
0#
$end
#10
1!
1"
1#
#20
1!
4 changes: 4 additions & 0 deletions tests/data/expected/buffered_file2_base.cat
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
0 t.a 0
0 t.b 0
0 t.c 0
20 t.a 1
3 changes: 3 additions & 0 deletions tests/data/expected/buffered_file2_base.names
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
t.a
t.b
t.c
3 changes: 3 additions & 0 deletions tests/data/expected/buffered_file2_base.vcd.attrs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
t.a wire 1
t.b wire 1
t.c wire 1
7 changes: 7 additions & 0 deletions tests/data/expected/buffered_file2_extra.cat
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
0 t.a 0
0 t.b 0
0 t.c 0
10 t.a 1
10 t.b 1
10 t.c 1
20 t.a 1
3 changes: 3 additions & 0 deletions tests/data/expected/buffered_file2_extra.names
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
t.a
t.b
t.c
3 changes: 3 additions & 0 deletions tests/data/expected/buffered_file2_extra.vcd.attrs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
t.a wire 1
t.b wire 1
t.c wire 1
16 changes: 16 additions & 0 deletions tests/diff_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,22 @@ fn test_edge_time_diff() {
assert_eq!(output, expected, "Expected exact diff output");
}

#[test]
fn test_buffered_file2_only_diffs_are_sorted() {
let (has_diff, output) = run_wave_diff_test(
"tests/data/buffered_file2_base.vcd",
"tests/data/buffered_file2_extra.vcd",
);
assert!(has_diff, "file2-only intermediate changes should differ");

let expected = "\
10 t.a 1 (only in file2)
10 t.b 1 (only in file2)
10 t.c 1 (only in file2)
";
assert_eq!(output, expected, "Expected deterministic file2-only diff output");
}

#[test]
fn test_new_sig_diff() {
let (has_name_diff, msg) = check_signal_names(
Expand Down
Loading