IC 仿真实践 SoC V3.0 · RISC-V 精进版 SOC3.0 资料 VERIFICATION_SCRIPT_ANALYSIS.md

soc/sw/VERIFICATION_SCRIPT_ANALYSIS.md

SOC 验证脚本测试覆盖分析报告

一、验证脚本期望的测试用例

根据 soc_test.py 验证脚本,期望的测试用例列表如下:

1.1 C 语言测试(非 UVM,uvm_en='0'

序号 测试名称 重复次数 TAG 状态
1 spi_test 1 TEST1 ✅ 存在
2 spi1_test 5 TEST1 ✅ 存在
3 spi2_test 1 TEST1 ✅ 存在
4 uart_test 1 TEST2 ✅ 存在
5 soc_dma_test 1 TEST2 ✅ 存在
6 isp_test 1 TEST3 ✅ 存在
7 cnn_test 1 TEST4 ✅ 存在
8 jtag_test 1 TEST4 ✅ 存在
9 pwm_test 1 TEST4 ✅ 存在
10 i2c_read_test 1 TEST4 ✅ 存在
11 i2c_write_test 1 TEST4 ✅ 存在
12 soc_dma_test 1 TEST4 ✅ 存在(重复)
13 soc_dma_test1 1 TEST4 ✅ 存在
14 soc_dma_test2 1 TEST4 ✅ 存在
15 led 1 TEST4 ✅ 存在
16 sram_test 1 TEST4 ✅ 存在

C 测试总计: 16 个测试用例(其中 soc_dma_test 重复定义)

1.2 UVM 测试(uvm_en='1'

序号 测试名称 编译配置 状态
1 soc_base_test soc_uvm_test ✅ 存在
2 cnn_uvm_test soc_uvm_test ✅ 存在
3 i2c_read_uvm_test soc_uvm_test ✅ 存在
4 i2c_write_uvm_test soc_uvm_test ✅ 存在
5 jtag_uvm_test soc_uvm_test ✅ 存在
6 pwm_uvm_test soc_uvm_test ✅ 存在
7 spi_uvm_test soc_uvm_test ✅ 存在
8 isp_uvm_test soc_uvm_test ✅ 存在
9 soc_dma_uvm_test soc_uvm_test ✅ 存在
10 soc_dma_uvm_test1 soc_uvm_test ✅ 存在
11 soc_dma_uvm_test2 soc_uvm_test ✅ 存在
12 sram_uvm_test soc_uvm_test ✅ 存在
13 uart_uvm_test soc_uvm_test ✅ 存在

UVM 测试总计: 13 个测试用例

1.3 验证脚本总测试数

  • C 测试: 16 个(含重复)
  • UVM 测试: 13 个
  • 总计: 29 个测试用例

二、实际存在的测试文件

2.1 C 语言测试文件(soc_test_c/

测试文件 对应验证脚本测试 状态
spi1_test/spi1_test.c spi1_test ✅ 匹配
spi2_test/spi2_test.c spi2_test ✅ 匹配
uart_test/uart_test.c uart_test ✅ 匹配
soc_dma_test/soc_dma_test.c soc_dma_test ✅ 匹配
soc_dma_test1/soc_dma_test1.c soc_dma_test1 ✅ 匹配
soc_dma_test2/soc_dma_test2.c soc_dma_test2 ✅ 匹配
isp_test/isp_test.c isp_test ✅ 匹配
cnn_test/cnn_test.c cnn_test ✅ 匹配
jtag_test/jtag_test.c jtag_test ✅ 匹配
pwm_test/pwm_test.c pwm_test ✅ 匹配
i2c_read_test/i2c_read_test.c i2c_read_test ✅ 匹配
i2c_write_test/i2c_write_test.c i2c_write_test ✅ 匹配
led/led.c led ✅ 匹配
sram_test/sram_test.c sram_test ✅ 匹配
缺失 spi_test 缺失

2.2 UVM 测试文件(soc_test_uvm/

测试文件 对应验证脚本测试 状态
soc_base_test/soc_base_test.sv soc_base_test ✅ 匹配
cnn_uvm_test/cnn_uvm_test.sv cnn_uvm_test ✅ 匹配
i2c_read_uvm_test/i2c_read_uvm_test.sv i2c_read_uvm_test ✅ 匹配
i2c_write_uvm_test/i2c_write_uvm_test.sv i2c_write_uvm_test ✅ 匹配
jtag_uvm_test/jtag_uvm_test.sv jtag_uvm_test ✅ 匹配
pwm_uvm_test/pwm_uvm_test.sv pwm_uvm_test ✅ 匹配
spi_uvm_test/spi_uvm_test.sv spi_uvm_test ✅ 匹配
isp_uvm_test/isp_uvm_test.sv isp_uvm_test ✅ 匹配
soc_dma_uvm_test/soc_dma_uvm_test.sv soc_dma_uvm_test ✅ 匹配
soc_dma_uvm_test1/soc_dma_uvm_test1.sv soc_dma_uvm_test1 ✅ 匹配
soc_dma_uvm_test2/soc_dma_uvm_test2.sv soc_dma_uvm_test2 ✅ 匹配
sram_uvm_test/sram_uvm_test.sv sram_uvm_test ✅ 匹配
uart_uvm_test/uart_uvm_test.sv uart_uvm_test ✅ 匹配

UVM 测试: 全部匹配 ✅

三、验证脚本 vs 实际测试对比

3.1 匹配情况

类别 验证脚本期望 实际存在 匹配数 匹配率
C 测试 16 15 15 93.75%
UVM 测试 13 13 13 100%
总计 29 28 28 96.55%

3.2 缺失的测试

⚠️ 有问题的测试(1个)

  1. spi_test - C 语言测试
  2. 验证脚本期望: spi_test (第 9 行)
  3. 实际文件: ❌ 在 soc_test_c/ 中不存在
  4. 验证结果: spi_test_0 编译失败(从回归测试结果看)
  5. 配置: 使用 +UVM_TESTNAME=1111,但 uvm_en=''(空),配置可能有问题
  6. 影响: 验证脚本会尝试运行此测试,但可能无法正常工作
  7. 建议:
    • 如果不需要,从验证脚本中删除
    • 如果需要,创建 soc_test_c/spi_test/spi_test.c
    • 或者修复配置问题(UVM_TESTNAME 与 uvm_en 不匹配)

3.3 重复定义问题

  • soc_dma_test 在验证脚本中定义了两次(第 50 行和第 120 行)
  • 第一次: TAG=TEST2
  • 第二次: TAG=TEST4
  • 影响: 可能导致测试重复运行
  • 建议: 删除其中一个重复定义

四、验证脚本分析

4.1 测试分类(TAG)

验证脚本使用 TAG 对测试进行分类:

  • TEST1: spi_test, spi1_test, spi2_test (SPI 相关)
  • TEST2: uart_test, soc_dma_test (基础功能)
  • TEST3: isp_test (ISP 功能)
  • TEST4: 其他所有测试(C 和 UVM)

4.2 特殊配置

  1. spi1_test: repeat=5 - 会运行 5 次,用于稳定性测试
  2. UVM 测试: 使用 soc_uvm_test 编译配置,启用 +define+SOC_TB_MODE
  3. C 测试: 使用 soc_test 编译配置

4.3 覆盖率配置

所有测试都启用了覆盖率收集:
- -cm line+cond+tgl - 行覆盖率、条件覆盖率、翻转覆盖率

五、测试完整性评估

5.1 从验证脚本角度

测试完整性: 96.55%

  • UVM 测试: 100% 完整
  • ⚠️ C 测试: 93.75% 完整(spi_test 文件缺失或配置有问题)

5.2 主要问题

  1. spi_test 缺失或配置错误 ⚠️
  2. 验证脚本期望但 soc_test_c/ 中文件不存在
  3. 从回归测试结果看,spi_test_0 编译失败
  4. 配置可能有问题:使用 +UVM_TESTNAME=1111uvm_en=''(空)
  5. 可能导致验证流程失败

  6. soc_dma_test 重复定义 ⚠️

  7. 在验证脚本中定义了两次
  8. 可能导致测试重复运行

  9. I2C1 测试缺失 ⚠️

  10. 硬件有 I2C0 和 I2C1,但只有 I2C0 测试
  11. 验证脚本中没有 I2C1 测试

六、建议

6.1 必须修复(高优先级)

  1. 修复 spi_test
  2. 选项1: 创建 soc_test_c/spi_test/spi_test.c(如果确实需要独立测试)
  3. 选项2: 从验证脚本中删除 spi_test 定义(如果 spi1_testspi2_test 已足够)
  4. 选项3: 修复配置问题(如果 spi_test 是 UVM 测试,应设置 uvm_en='1'

  5. 修复重复定义

  6. 删除 soc_test.py 中重复的 soc_dma_test 定义(保留一个)

6.2 建议补充(中优先级)

  1. 添加 I2C1 测试
  2. 在验证脚本中添加 i2c1_read_testi2c1_write_test
  3. 创建对应的测试文件

  4. 明确 SPI 测试命名

  5. spi1_test 实际测试 SPI0
  6. spi2_test 实际测试 SPI1
  7. 建议重命名或添加注释说明

6.3 可选改进(低优先级)

  1. 添加 Pinmux 测试
  2. 如果 Pinmux 功能重要,应添加专门测试

  3. 测试文档化

  4. 添加测试说明文档
  5. 说明每个测试对应的硬件模块

七、验证脚本运行机制分析

7.1 测试文件复制机制

根据 v3flow_run.py 代码(第 301-318 行):

  • UVM 测试 (uvm_en='1'):
  • sw/soc_test_uvm/{test_name}/ 复制文件
  • 不编译 C 代码,直接运行 UVM 仿真

  • C 测试 (uvm_en=''uvm_en='0'):

  • sw/soc_test_c/{test_name}/ 复制文件
  • 使用 Makefile 编译 C 代码生成 .vmem 文件
  • .vmem 重命名为 mem.data 供仿真使用

7.2 spi_test 问题分析

  • 配置: uvm_en=''(空字符串,视为非 UVM 测试)
  • 期望路径: sw/soc_test_c/spi_test/
  • 实际状态: ❌ 目录不存在
  • 验证结果: spi_test_0 编译失败(从回归测试结果看)
  • 配置异常: 使用了 +UVM_TESTNAME=1111,但 uvm_en='',配置不一致

八、总结

8.1 验证脚本覆盖度

  • 总体匹配率: 96.55%
  • UVM 测试: 100%
  • C 测试: 93.75% ⚠️

8.2 关键发现

  1. 大部分测试完整 - 28/29 个测试用例存在
  2. spi_test 缺失 - 验证脚本期望但 soc_test_c/spi_test/ 目录不存在
  3. ⚠️ 重复定义 - soc_dma_test 在脚本中定义两次(第 50 行和第 120 行)
  4. ⚠️ I2C1 未测试 - 硬件存在但验证脚本和测试文件都缺失
  5. ⚠️ UVM 测试编译失败 - 从回归测试结果看,所有 UVM 测试都编译失败(可能是环境问题)

8.3 验证脚本运行状态

从回归测试结果 (result.log) 看:

通过的测试 (15个):
- led_0, i2c_write_test_0, i2c_read_test_0, isp_test_0, soc_dma_test2_0,
- spi2_test_0, spi1_test_0/1/2/3/4, jtag_test_0, pwm_test_0,
- soc_dma_test1_0, soc_dma_test_0, cnn_test_0, uart_test_0, sram_test_0

失败的测试:
- spi_test_0 - 编译失败(文件缺失)
- 所有 UVM 测试 - 编译失败(可能是环境配置问题)

8.4 结论

从验证脚本角度分析:

  1. 测试文件完整性: 96.55%
  2. 28/29 个测试用例有对应文件
  3. 只有 spi_test 缺失

  4. 验证流程问题:

  5. ⚠️ spi_test 缺失 - 必须修复
  6. ⚠️ UVM 测试编译失败 - 可能是环境配置问题,需要检查
  7. ⚠️ 重复定义 - soc_dma_test 定义两次

  8. 硬件覆盖问题:

  9. ⚠️ I2C1 未测试 - 硬件存在但验证脚本和测试文件都缺失

8.5 修复建议优先级

必须修复(影响验证流程):
1. 修复 spi_test - 创建文件或删除脚本定义
2. 修复 UVM 测试编译问题 - 检查环境配置
3. 删除重复的 soc_dma_test 定义

建议补充(提高覆盖度):
4. 添加 I2C1 测试到验证脚本和测试文件

修复这些问题后,测试覆盖度可达 100%(从验证脚本角度)。