【问题标题】:SV constraints scope and randomizationSV 约束范围和随机化
【发布时间】:2022-11-03 02:26:44
【问题描述】:

在 SystemVerilog UVM 测试平台中,我们将事务对象随机化,对于一些特定的测试,我们创建了额外的约束。但是,如果您调用测试用例randomize() 方法而不是obj.randomize(),则这些测试用例约束仅由随机化引擎使用。这很令人困惑。

我想知道为什么不管调用哪个 randomize 都不使用对象上的所有约束?为什么约束有范围?

例如:

class trans;
   rand int addr;
 
   constraint addr_c;  // Method 1: constraint prototype

   function void post_randomize();
     $display("addr %d",addr);
   endfunction
endclass

//////////////////// Test case code /////////////////

// Method 1: extend constraint prototype addr_c external to test class.
// constraint trans::addr_c { addr > 0 && addr < 10; } 
// works but requires prototype, careful if trans is in another package

class my_test;
  trans trans1;
  
  // Method 2: Add constraint to the test
  constraint test_constraint_c { trans1.addr > 11 && trans1.addr < 20; }
  
  function new();
    trans1 = new;
    repeat (20) begin
      // This doesn't use test_constraint_c (why??)
      assert(trans1.randomize()) else $display("TEST", "Randomization Failed");
      // This uses test_constraint_c
      assert(randomize(trans1)) else $display("TEST", "Randomization Failed");
    end
  endfunction
endclass

module tb;
  my_test test1;
  initial test1 = new;
endmodule 

【问题讨论】:

    标签: constraints system-verilog verification


    【解决方案1】:

    您有 2 个彼此无关的类:transmy_test

    trans 类不知道 test_constraint_c 约束,因为该约束只是 my_test 类的一部分。因此,当您在对象上调用randomize 函数时,它没有应用任何约束。

    在测试中,当您在trans 变量上调用randomize 方法时,它将应用my_test 类中的任何活动约束,即test_constraint_c

    另一种方法是使用新的约束块扩展trans 类。

    【讨论】:

      猜你喜欢
      • 2015-06-21
      • 1970-01-01
      • 2020-06-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-02-17
      • 1970-01-01
      相关资源
      最近更新 更多