【验证小bai】randomize中的this.指的是哪个this呢

简介: 【验证小bai】randomize中的this.指的是哪个this呢

为啥小白是标题中的禁止词呢,有点摸不着头脑啊。


今天一精神小伙突然发现一个问题,简化讲就是在seq中对某一transaction进行randomize时,this的含义竟然指的不是这个seq中的值,而是transaction中的值!


示意代码如下:

class my_transaction extends uvm_sequence_item;
  rand bit [8-1:0] data;
  rand bit       par_err;
    bit [8 -1:0] test_value = 8'hFF;
endclass
class sanity_case_seq extends my_sequence;
  extern function new(string name = "sanity_case_seq");
  extern virtual task body();
    bit [8 -1:0] test_value = 8'hAA;
  `uvm_object_utils(sanity_case_seq)
endclass: sanity_case_seq
function sanity_case_seq::new(string name = "sanity_case_seq");
  super.new(name);
endfunction: new
task sanity_case_seq::body();
    bit [8 -1:0] test_value = 8'hBB;
  repeat(1) begin
    `uvm_do_with(my_tr, {my_tr.par_err == 0; my_tr.data == this.test_value;})
  end
  #100;
endtask: body


其中,

`uvm_do_with(my_tr, {my_tr.par_err == 0; my_tr.data == this.test_value;})

这个this.test_value指的是哪个值呢?没错,指的是class my_transaction中的test_value = 8'hFF,看下波形也能知道:



我当时大感惊奇,这this难道不是应该指的seq里的量么?后来下班路上我才想明白,这不就是相当于我在class my_transaction里做约束吗?my_transaction里constraint中的this一定是指的本身内部的值,这里也一定是呀!


这实验做得就有一点没有意义了哈哈哈


当然了,如果transaction内没有this.test_value这个值,那么此时会取哪个值呢?答案是会取class sanity_case_seq中的bit [8 -1:0] test_value = 8'hAA,如波形:



当然,此时VCS会给你告警,告诉你是他往外扩大了范围去找的:

Warning-[ETLIIC] Extended this/super lookup
../tc/sanity_case.sv, 21
"\this .test_value"
  A member 'test_value' is not found in the randomized object. It is present 
  in the class of the method containing the randomize-with call.In inline 
  constraints, this/super refers to the object being randomized. VCS supports 
  an extended lookup in the class of the method, where randomize call is 
  present, for backwards compatibility. This may be removed in the future.
  If you intend to access the this/super of the containing method in a 
  portable way, you may want to create a local object aliased to this/super. 
  To promote this warning to error, use '-error=ETLIIC'.

那么要怎么取到body()函数中的bit [8 -1:0] test_value = 8'hBB呢?需要把this去掉:

`uvm_do_with(my_tr, {my_tr.par_err == 0; my_tr.data == test_value;})

此时就是取值函数内的值:



还有一点,就是如果transaction和seq类内都没有这个值,只在function内有的话,VCS是会报error的,this必须是类内的变量,不能只在function中。



相关文章
|
2月前
|
C++
【PTA】L1-016 验证身份(C++)
【PTA】L1-016 验证身份(C++)
58 0
【PTA】L1-016 验证身份(C++)
|
1月前
Open3D Intrinsic shape signatures (ISS) 固有形状特征码
Open3D Intrinsic shape signatures (ISS) 固有形状特征码
|
15天前
|
数据库
大事件后端项目25-------更新文章分类和添加文章分类---分组校验
大事件后端项目25-------更新文章分类和添加文章分类---分组校验
|
18天前
|
运维 IDE Serverless
函数计算产品使用问题之非匿名的HTTP函数该如何调用
函数计算产品作为一种事件驱动的全托管计算服务,让用户能够专注于业务逻辑的编写,而无需关心底层服务器的管理与运维。你可以有效地利用函数计算产品来支撑各类应用场景,从简单的数据处理到复杂的业务逻辑,实现快速、高效、低成本的云上部署与运维。以下是一些关于使用函数计算产品的合集和要点,帮助你更好地理解和应用这一服务。
|
9月前
|
移动开发
【验证小bai】关于多个声明域变量名重名时如何取用的问题——还是以随机约束为例
【验证小bai】关于多个声明域变量名重名时如何取用的问题——还是以随机约束为例
if双分支根据位置变量识别用户输入的 IP 地址判断连通 信
if双分支根据位置变量识别用户输入的 IP 地址判断连通 信
44 0
|
人工智能
CF1556D. Take a Guess(交互 性质)
CF1556D. Take a Guess(交互 性质)
72 0
CF1556D. Take a Guess(交互 性质)
|
数据安全/隐私保护
PTA 1081 检查密码 (15 分)
本题要求你帮助某网站的用户注册模块写一个密码合法性检查的小功能。该网站要求用户设置的密码必须由不少于6个字符组成,并且只能有英文字母、数字和小数点 .,还必须既有字母也有数字。
389 0
|
PHP
tp自动验证流程和返回空数组的问题
tp自动验证流程和返回空数组的问题
99 0
|
测试技术
软件测试面试题:lr中,哪个函数是用来截取虚拟用户脚本中的动态值?(手工关联)
软件测试面试题:lr中,哪个函数是用来截取虚拟用户脚本中的动态值?(手工关联)
94 0