我有一个模块,当检测到不应该出现的先决条件时,它有一个断言。当我为模块提供无效输入时,如何编写基于此断言失败的测试通过?
过去,我曾使用 Verilog PLI 完成此类工作。我正在学习 SystemVerilog,如果可能的话,我更愿意使用一些 Verilog 或 SV 结构并避免运行单独的程序。
最佳答案
我认为您的想法是错误的。
I have a module that has an assert when a pre-condition that should never occur is detected. How can I write a test that passes based on this assert failing when I give the module invalid inputs?
这听起来很困惑。如果模块对给定的输入做了正确的事情,则测试应该通过。如果模块做出正确的响应,则为模块提供无效输入不应导致测试失败。正确的做法可能是标记错误、引发中断或可能只是忽略输入。
因此,您永远不需要要求测试失败。
我想你的意思是:
I want to test a module with "invalid" stimulus, and I want to make sure the module notices (e.g. by flagging an error)
在这种情况下断言变成:
assert @some_event (invalid_input |=> error_caught);
然后您使用覆盖率来确保测试导致断言在某个时间点完成。
关于unit-testing - 如何进行仅在断言失败时通过的测试?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18343502/