在specman中如何测试变量或结构字段是否存在?

发布于 2024-10-16 18:42:34 字数 240 浏览 6 评论 0原文

Specman 手册中几乎没有表明人们可以即时确定是否已创建特定变量。 (不询问数组索引或散列成员的测试,这可以通过 contains() 完成)

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

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

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() )

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...

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

熊抱啵儿 2024-10-23 18:42:34

您可以使用反射接口来完成此操作。在文档中查找“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()

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

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'");
      };

   };
};

This yields

[...]
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()
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文