如何在verilog中运行多个测试用例?

时间:2015-09-18 06:00:22

标签: verilog modelsim

我在“tc1.v”和“tc2.v”中写了我的测试用例。测试用例采用任务的形式。例如:

//tc1.v

task tc1(input reg [31:0] j,input reg Reset,output reg dataValidIn);

 //logic
endtask

//tc2.v

task tc2(input reg [31:0] counter,input reg Reset,output reg dataValidIn);

//logic

endtask


module top_test;

  //inputs and outputs
  //logic

   `ifdef testcase1
      `include "tc1.v";
   `else 
     `include "tc2.v"
   `endif


endmodule

问题是我想为每个posedge时钟运行测试用例。如果我将'ifdef部分包含在always块中,modelsim会抛出错误。无论如何我能做到这一点吗?

2 个答案:

答案 0 :(得分:1)

我使用的另一个解决方案是使用运行时开关为模拟器指定测试用例。这使您无需为每个测试重新编译测试/设计,并且无需重新编译即可批量运行所有测试。

Verilog有一个系统调用$value$plusargs (string, variable),它可以从模拟器参数中提取任何变量。您可以使用它来提取测试名称,并使用ifcase语句在上述答案中选择不同的来源。

您可以像<simulator> +TESTNAME=tc1

一样启动模拟器

在您的测试平台代码中,您将提取TESTNAME参数

if ($value$plusargs("TESTNAME=%s", testname)) begin
  $display("Running test %0s.", testname);
  if (testname == "tc1")
    `include "tc1.v"
  else if (testname == "tc2)
    `include "tc2.v"
end

答案 1 :(得分:0)

从上面的代码中,所有`include包含的是任务声明,而不是实际的任务调用。在代码中的其他位置,您必须在tc1(x, y, z);initial块中调用always之类的内容。另外,为了使其更具可扩展性,我建议不要有条件地包括任务声明,并将其留给调用以确定要运行的任务。因此,您只需在任务调用中添加所需的代码,而不是包含任务:

// Have a macro for your test case, you can also declare this in the commandline
`define TESTCASE 1

module top_test;
  ...
  `include "tc1.v"
  `include "tc2.v"
  ...
  always @(posedge clk) begin
    // Switch on the test case to determine which to use
    // NOTE THAT IF THE TASK TAKES LONGER THAN 1 CLOCK CYCLE TO COMPLETE, THIS WILL NOT WORK FOR A TASK PER CLOCK
    case (`TESTCASE)
     1: tc1(...);
     2: tc2(...);
     default: begin
       $display("ERROR: Bad Testcase supplied %d", `TESTCASE);
       $finish;
     end
   endcase
 end
 ...
endmodule
相关问题