自动检测fifo empty

前面有一篇文章介绍了使用verdi的NPI来读取design里面的hierarchy,并提取所有fifo信号,并做检查。但是这种方案需要编译两次,比较麻烦,本文介绍一种不用重新编译的方法。

本方案的想法是,使用ucli命令来找到所有fifo和empty信号,然后检查值是否为1。

首先需要在仿真参数中增加-ucli

1
simv [opts] -ucli run.tcl

然后在top_tb.sv里面,在仿真结束之前,给tcl传递一个信号。

1
2
3
4
5
6
7
8
9
10
11
12
reg test_finished_to_tcl;
reg test_check_fifo_enable;
reg test_failed_to_tcl;

initial begin
test_finished_to_tcl = 0;
test_check_fifo_enable = 1;
test_failed_to_tcl = 0;
wait(test_finish);
test_finished_to_tcl = 1;
$finish();
end

最后是tcl脚本。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
run -posedge top_tb.test_finished_to_tcl
set check_fifo_failed 0
set test_check_fifo_enable [get top_tb.test_check_fifo_enable -radix decimal]
if {$test_check_fifo_enable == 1} {
set log [ open "check_fifo.log" "w"]
set fifos [search -instance *fifo* -l 8192 -scope top_tb]
set $len [llength $fifos]
for {set i 0} {$i<$len} {incr i} {
set fifo [lindex $fifos $i]
set empties [search -scope $fifo -out o_empty -depth 1]
for {set j 0} {$j < [llength $empties]} {incr j} {
set empty [lindex $empties $j]
set value [get $empty -radix decimal]
put $log "signal=$empty value=$value"
if {$value != 1} {
put "Error: fifo is not empty. $empty $value"
set check_fifo_failed 1
}
}
}
}

set test_failed_to_tcl [get top_tb.test_failed_to_tcl -radix decimal]
if {$test_failed_to_tcl == 0 && check_fifo_failed == 0} {
puts "\nTEST PASSED\n"
} else {
puts "\nTEST FAILED\n"
}