ez-Q2.5-Firmware-Design-Req.../代码覆盖率.md

64 lines
1.9 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

---
html:
toc: true
embed_local_images: true
embed_svg: true
---
# 1. exclude 命令的使用
在实际设计中可能存在不需要统计代码覆盖率的代码如常数变量、defalut 状态等),这些代码会导致代码覆盖率统计虚低。这时需要使用 coverage exclude 将这部分代码排除在代码覆盖率统计之外。
以 QuestaSim 仿真为例,使用 tcl 脚本执行 coverage exclude 命令(该命令需要在 vsim 命令之后执行)。不同的仿真软件在具体命令上可能存在区别。
## 1.1. 排除文件
以下命令将 fsm.v 整个文件排除覆盖率统计。
```
coverage exclude -srcfile fsm.v
```
## 1.2. 排除代码段
以下命令将 fsm.v 中的第 212 行至 219 行的代码排除覆盖率统计。
```
coverage exclude -srcfile fsm.v -linerange 212-219
```
另一种排除的方法是,在 RTL 代码中使用 "// pragma coverage off" 和 "// pragma coverage on",两者之间的代码会被排除覆盖率统计。这种方法只能在 QuestaSim 使用,其他仿真器不支持。
```
// pragma coverage off
RTL code ...
// pragma coverage on
```
## 1.3. 排除信号
以下命令将信号 addr 排除翻转覆盖率的统计。
```
coverage exclude -togglenode /TB_top/uut/addr
```
进一步地,也可以将信号的部分比特位排除翻转覆盖率的统计。
```
coverage exclude -togglenode /TB_top/uut/addr[31:16]
```
## 1.4. 排除状态
以下命令将状态机 state 的 st1 状态排除在状态机覆盖率统计之外。
```
coverage exclude -scope /TB_top/uut/addr -fstate state st1
```
## 1.5. 排除状态跳转
以下命令将状态机 state 的 st1->st0、st2->st0 两种跳转排除在状态机跳转覆盖率统计之外。
```
coverage exclude -scope /TB_top/uut/addr -ftrans state st1->st0 st2->st0
```
## 1.6. 其他
QuestaSim 中输入以下命令查看完整的 coverage exclude 的使用方法。
```
coverage exclude -help
```