From 20f241eb50637b21f416fac47f069cea8eefa586 Mon Sep 17 00:00:00 2001 From: zhoushuang Date: Fri, 8 May 2026 16:23:05 +0800 Subject: [PATCH] add coverage doc --- 代码覆盖率.md | 64 ++++++++++++++++++ ...告_V0.0.1.docx => 国盾仿真报告模板(仅供参考).docx | Bin 2 files changed, 64 insertions(+) create mode 100644 代码覆盖率.md rename LogicStandard_08_xx项目xx配置项单元测试报告_V0.0.1.docx => 国盾仿真报告模板(仅供参考).docx (100%) diff --git a/代码覆盖率.md b/代码覆盖率.md new file mode 100644 index 0000000..3ae236e --- /dev/null +++ b/代码覆盖率.md @@ -0,0 +1,64 @@ +--- +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 +``` \ No newline at end of file diff --git a/LogicStandard_08_xx项目xx配置项单元测试报告_V0.0.1.docx b/国盾仿真报告模板(仅供参考).docx similarity index 100% rename from LogicStandard_08_xx项目xx配置项单元测试报告_V0.0.1.docx rename to 国盾仿真报告模板(仅供参考).docx