博文精選】vcs産生code coverage與function coverage
2020-02-13 17:49
vcs仿真中,可以産生以下兩類coverage:
- code coverage
- function coverage
對于code coverage,在編譯和仿真需要加額外參數。對于function coverage,編譯和仿真不需要加額外參數。
一、code coverage
code coverage包含以下一些coverage:
- line coverage
- toggle coverage
- condition coverage
- branch coverage
- FSM coverage
- assert coverage
要使能這些coverage,vcs的-cm選項,來控制,是否産生這些coverage
-cm <cov_metrics_name> |
關于cov_metrics_name,有如下選擇:
- line:使能line coverage
- cond:使能cond coverage
- tgl:使能toggle coverage
- fsm:使能FSM coverage
- branch:使能branch coverage
- assert:使能assert coverage
多個選項之間,使用+進行連接配接。例如,要使能line,fsm coverage,使用如下選項:
-cm line+fsm |
code coverage選項,在編譯和仿真的時候,都必須要有,否則不能正常的生成coverage。
編譯如果帶有coverage coverage選項,會在編譯目錄下,生成simv.vdb目錄,裡面包含了coverage model。
二、function coverage
function coverage,沒有選項控制,因為是在代碼中指定的。
在編譯的時候,不會生成simv.vdb目錄,因為function coverage不需要coverage model。
三、coverage其他選
-cm_dir選項
官方解釋:
The -cm_dir <directory_path_name> option enables you to specify an alternative name or location for saving the default simv.vdb directory. If not specified, VCS automatically generates the coverage database with the name simv.vdb or <exe_name>.vdb where, exe_name is the argument to -o option if included during compilation. |
帶上coverage選項,vcs編譯完畢後,預設會在編譯目錄,生成simv.vdb檔案夾。該檔案夾裡面,包含了coverage model。
可以通過-cm_dir選項,更改預設的coverage model生成的目錄。
仿真的時候,如果沒有指定-cm_dir選項,那麼使用編譯時候指定的simv.vdb的目錄。也可以仿真帶有-cm_dir選項,修改仿真時,生成的simv.vdb目錄位置。
- -cm_name選項
官方解釋:
The -cm_name <filename> option as a compile-time or runtime option enables you to specify an alternative test name instead of the default name. The default test name is test |
對于每一個test,生成的coverage資料,預設是在simv.vdb/snps/coverage/db/testdata/test目錄下
預設coverage資料,是在test目錄下,可以通過-cm_name選項,修改預設的test目錄。
比如-cm_name load_test,那麼coverage資料,就會生成在simv.vdb/snps/coverage/db/testdata/load_test目錄下。
3. -cm_hier選項
該選項,在coverage technology reference manual手冊上有介紹。
官方解釋該選項:
The -cm_hier option is a compile-time option to specify module definitions, instances and sub-hierarchies, and source files that you want VCS to either exclude from coverage or exclusively compile for coverage. |
在收集code coverage的時候,工具預設會收集所有子產品的coverage。但是有時候,我們隻關心某一層子產品以及之下的coverage。此時就需要-cm_hier選項來指定層次。
-cm_hier選項,指定一個coverage配置檔案。該配置檔案,指定了收集coverage的子產品。
對于這個coverage配置檔案,有如下一些文法:
3.1 +tree instance_name [level_number]
VC VCS compile only the specified instance and the instances under it for coverage. These instances can be Verilog module or VHDL entity instances. VCS exclude all other instances from coverage. A level number of 0 (or no level number) specifies the entire subhierarchy, 1 specifies only this instance, 2 specifies this instance and those instances directly under this instance, 3 specifies this instance and instances in the subhierarchies that are one and two levels below the specified instance. There is no limit to the integer you specify as the level number. If the subhierarchy includes instances in the other HDL, VCS does not include these instances. |
隻對指定層次的子產品,以及該層次下的子產品,統計coverage。level_number,表示從該層次子產品,向下統計coverage的層次。0表示統計所有,1表示隻統計目前層,2表示統計目前層和下一層,之後依次類推。
3.2 -tree instance_name [level_number]
VC VCS exclude this instance from coverage and other instances under it. These instances can be Verilog module or VHDL entity instances. VCS include all other instances in coverage. A level number of 0 (or no level number) specifies the entire subhierarchy, 1 specifies only this instance, 2 specifies this instance and those instances directly under this instance, and so on. If the subhierarchy includes instances in the other HDL, VCS does not exclude these instances. |
隻對指定層次的子產品,以及該層次下的子產品,不統計coverage。level_number,表示從該層次子產品,向下不統計coverage的層次。0表示不統計所有,1表示隻不統計目前層,2表示不統計目前層和下一層,之後依次類推。
3.3 +module module_name | entity_name
VCS compiles all instances of the specified Verilog module or VHDL entity definition, and excludes all other definitions under it, for coverage. |
隻對指定子產品統計coverage。
3.4 -module module_name | entity_name
VCS does not compile all instances of the specified Verilog module or VHDL entity definition, and includes all other definitions under it, for coverage. |
隻對指定子產品不統計coverage
3.5 +file file_name
VCS compile for coverage only the code in this file. If the file is not in the current directory, specify the path name of the file. |
對指定的檔案,統計該檔案内子產品的coverage。如果file_name不是目前路徑下,那麼需要使用絕對路徑。
3.6 -file file_name
VCS exclude the code in this file from coverage. If the file is not in the current directory, specify the path name of the file. |
對指定的檔案,不統計該檔案内子產品的coverage。如果file_name不是目前路徑下,那麼需要使用絕對路徑。
3.7 +filelist file_name
VCS compile for coverage only the source files listed in the specified file. |
隻對file_name檔案,統計該檔案裡面指定的源檔案中子產品的coverage。
3.8 -filelist file_name
VCS exclude from coverage the source files listed in the specified file. |
隻對file_name檔案,不統計該檔案裡面指定的源檔案中子產品的coverage。
3.9 +moduletree module_name [level_number]
VCS provides coverage metrics for all instances of the specified module and for all module instances in the hierarchy below the specified module. In other words, each hierarchy tree starting at each instance of the specified module will have coverage metrics provided. The coverage metrics are only provided for the number of levels of hierarchy specified by the optional level_number. |
對指定的子產品,以及該子產品下的子產品,統計coverage。level_number,表示從該子產品,向下統計coverage的層次。0表示統計所有,1表示隻統計目前層,2表示統計目前層和下一層,之後依次類推。
3.10 -moduletree module_name [level_number]
VCS excludes coverage metrics for all instances of the specified module and for all module instances in the hierarchy below the specified module. In other words, each hierarchy tree starting at each instance of the specified module will have coverage metrics excluded. The coverage metrics are only excluded for the number of levels of hierarchy specified by the optional level_number. |
對指定的子產品,以及該子產品下的子產品,不統計coverage。level_number,表示從該子產品,向下統計coverage的層次。0表示統計所有,1表示隻統計目前層,2表示統計目前層和下一層,之後依次類推。
3.11 +/-node
Excludes or includes a signal in toggle coverage. |
去除或者包括對指定信号toggle coverage的統計。後面跟信号的絕對路徑,可以使用通配符*。
如:
+node top.cnt_inst*.out[7:5] //對該信号,不統計toggler -node top.cnt_inst*.out[4:0] //對該信号,統計toggler |
比如我們想收集,tb_top.aaa.bbb.ccc 這個子產品,以及子產品之下的coverage,那config檔案内容如下:
+tree tb_top.aaa.bbb.ccc 0 |
比如我們想收集,ccc 這個子產品,以及子產品之下的coverage,那config檔案内容如下:
+moduletree ccc 0 |
如果隻想收集ccc這個子產品呢:
+moduletree ccc 1 |
四、檢視coverage
1. dve
如果使用dve,使用如下指令檢視coverage資料:
dve -full64 -cov -dir simv.vdb |
2. verdi
如果使用verdi,使用如下指令檢視coverage資料:
verdi -cov -cov_dir simv.vdb |
- urg
urg指令,可以将coverage資料,轉換成html。
urg -dir simv.vdb |
在目前目錄下,會生成 urgReport 目錄,裡面有生成的html檔案,使用浏覽器即可檢視這些檔案。