In specman how to test for the existence of a variable or struct field?

穿精又带淫゛_ 提交于 2019-12-11 07:27:22

问题


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.


回答1:


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


来源:https://stackoverflow.com/questions/4963294/in-specman-how-to-test-for-the-existence-of-a-variable-or-struct-field

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!