在specman中,如何测试变量或结构域的存在? [英] In specman how to test for the existence of a variable or struct field?

查看:130
本文介绍了在specman中,如何测试变量或结构域的存在?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

specman手册中很少有内容表明可以即时确定是否已创建特定变量. (不询问有关对数组索引或哈希成员进行测试的问题,这可以通过exist()完成)

Little in the specman manual would indicate that one can determine on the fly whether a specific variable has been created. (not asking about testing for array index or hash members, which can be done via exists() )

我仅注意到有关结构名称/路径解析的讨论确实表明,尝试对解析路径中不存在的结构字段进行保持"操作将导致错误,并且_must_be_被注释掉了...

I only noticed that discussion of struct name/path resolution does say that attempting a 'keep' on a struct field that does not exist within the path resolved will result in an error and _must_be_ commented out...

我的工作涉及模拟由多个电子代码开发人员不断更新的模型,并且只要有人简单地创建新变量来进一步指定模型,测试台就失去向后兼容性. TCM构建参数.

My work involves simulating a model constantly updated by multiple e-code developers, and test benches lose backwards compatibility whenever someone simply creates a new variable to further specify model & TCM build parameters.

推荐答案

您可以使用反射界面进行此操作.在文档中查找"rf_manager".并非所有内容都记录在案,但是...

You can do this with the reflection interface. Look up "rf_manager" in the docs. Not everything is documented, however...

在这里,我正在测试字段baz的存在:

Here, I'm testing for the existence of field baz:

struct foo {
   bar : int;
};

struct baz {
};

extend sys {
   run() is also {
      var f : foo = new;
      var rf_f : rf_struct = rf_manager.get_exact_subtype_of_instance(f);
      var f_bar_field : rf_field = rf_f.get_field("bar");

      if f_bar_field != NULL {
         message(NONE,"struct 'foo' has a field called 'bar'");
      } else {
         message(NONE,"struct 'foo' doesn't have a field called 'bar'");
      };

      var b : baz = new;
      var rf_b : rf_struct = rf_manager.get_exact_subtype_of_instance(b);
      var b_bar_field : rf_field = rf_b.get_field("bar");

      if b_bar_field != NULL {
         message(NONE,"struct 'baz' has a field called 'bar'");
      } else {
         message(NONE,"struct 'baz' doesn't have a field called 'bar'");
      };

   };
};

这产生

[...]
Starting the test ...
Running the test ...
[0] sys-@0: struct 'foo' has a field called 'bar'
[0] sys-@0: struct 'baz' doesn't have a field called 'bar'

如果您需要遍历字段,请执行以下操作:

If you need to iterate over the fields, do :

rf_manager.get_exact_subtype_of_instance(whatever).get_declared_fields()

这篇关于在specman中,如何测试变量或结构域的存在?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆