卢骏 · 2020年05月27日

vcs产生code coverage与function coverage

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其他选项

1.-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目录位置。

2.-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

3.urg

urg命令,可以将coverage数据,转换成html。

urg -dir simv.vdb

在当前目录下,会生成 urgReport 目录,里面有生成的html文件,使用浏览器即可查看这些文件。

更多相关阅读

verdi中如何查看force信号信息
sv利用fork join_none实现信号打拍操作
使用fsdbedit工具修改fsdb波形的层次结构

原文首发于骏的世界博客
作者:卢骏
更多IC设计相关的文章请关注IC设计极术专栏,每日更新。

推荐阅读
关注数
10943
内容数
1209
主要交流IC以及SoC设计流程相关的技术和知识
目录
极术微信服务号
关注极术微信号
实时接收点赞提醒和评论通知
安谋科技学堂公众号
关注安谋科技学堂
实时获取安谋科技及 Arm 教学资源
安谋科技招聘公众号
关注安谋科技招聘
实时获取安谋科技中国职位信息