在specman中如何测试变量或结构域的存在?

时间:2011-02-10 22:05:07

标签: specman

specman手册中很少表明可以动态确定是否已创建特定变量。 (不要求测试数组索引或散列成员,可以通过exists()来完成)

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

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

1 个答案:

答案 0 :(得分:2)

您可以使用反射界面执行此操作。在文档中查找“rf_manager”。然而,并非所有内容都有记录......

在这里,我正在测试字段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()