1

Specman 手册中几乎没有表明可以动态确定是否已创建特定变量。(不询问数组索引或哈希成员的测试,这可以通过 exists() 完成)

我只注意到对结构名称/路径解析的讨论确实表明尝试在解析的路径中不存在的结构字段上“保留”将导致错误并且_must_be_被注释掉......

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

4

1 回答 1

2

您可以使用反射接口执行此操作。在文档中查找“rf_manager”。并非所有内容都记录在案,但是...

在这里,我正在测试 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'

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

rf_manager.get_exact_subtype_of_instance(whatever).get_declared_fields()
于 2011-02-11T21:43:52.670 回答