2

我正在使用 UVM 命令行参数来设置 UVM 层次结构中的配置属性。

当我传入一个错误的配置选项时,我希望看到一个UVM_ERROR或另一个失败指示。实现这一目标的最简单方法是什么?

例如,如果我传入一个错误的选项,例如:

+uvm_set_config_int=bad,mode,5

sim 完成,我没有从日志中看到选项错误的任何迹象:

# UVM_INFO @ 0: reporter [UVM_CMDLINE_PROC] Applying config setting from the command line: +uvm_set_config_int=bad,mode,5

完整代码可以在这里运行:http ://www.edaplayground.com/s/4/673

4

3 回答 3

1

我不太确定您对错误配置选项的含义。当您执行 uvm_set_config_int 时,您的前两个参数仅指定实例和字段名称。不要求这两个实际存在。您基本上只是将此配置选项放在配置数据库中以供稍后访问。

您可能想要的是在您的代理中进行检查,以确保它实际上传递了它的“模式”字段的值。

class my_agent extends uvm_agent;

  //...  

  function void build_phase(uvm_phase phase);
    if (!uvm_config_db #(int)::get(this, "", "mode", mode))
      `uvm_fatal("CFGERR", "Agent was not passed a config")
  endfunction

endclass

我使用您的代码在 EDAPlayground 上对此进行了测试,但我不确定它是否已保存。

于 2013-12-20T11:13:53.220 回答
0

UVM 可以使用静态uvm_component::print_config_matches位输出有关配置设置的附加信息。

在示例中,在您的测试平台中设置以下内容:

uvm_component::print_config_matches = 1;

对于“良好”的配置设置,您将在输出中看到以下内容:

# UVM_INFO @ 0: reporter [UVM_CMDLINE_PROC] Applying config setting from the command line: +uvm_set_config_int=*,mode,5
# UVM_INFO @ 0: uvm_test_top.my_agent [CFGAPL] applying configuration settings
# UVM_INFO @ 0: uvm_test_top.my_agent [CFGAPL] applying configuration to field mode
# UVM_INFO testbench(40) @ 0: uvm_test_top [my_test] Running test with mode 5

对于“错误”的配置设置,您将在输出中看到以下内容:

# UVM_INFO @ 0: reporter [UVM_CMDLINE_PROC] Applying config setting from the command line: +uvm_set_config_int=bad,mode,5
# UVM_INFO @ 0: uvm_test_top.my_agent [CFGAPL] applying configuration settings
# UVM_INFO testbench(40) @ 0: uvm_test_top [my_test] Running test with mode 0

因此,现在您可以解析输出并检查[CFGAPL] applying configuration to field每个[UVM_CMDLINE_PROC] Applying config settings.

修改代码示例:http ://www.edaplayground.com/s/4/681

于 2013-12-20T17:13:14.180 回答
0

我创建了一个uvm_component可以标记错误选项的+uvm_set_config_选项。UVM_ERROR如果传入了错误的选项,它会抛出一个错误,例如:

# UVM_ERROR cmd_line_checker.svh(112) @ 0: uvm_test_top.cmd_line_checker [BAD_CONFIG] UVM match for command line config bad,mode not found

完整的例子可以在这里运行:http ://www.edaplayground.com/s/4/766

编码:

/**
 * This is a utility class to validate command line arguments in the form:
 * +uvm_set_config_int=<inst_name>,<field_name>,<value>
 * +uvm_set_config_string=<inst_name>,<field_name>,<value>
 */
class cmd_line_checker extends uvm_component;

  /**
   * The enable for this checker.
   */
  bit enable = 1'b1;

  `uvm_component_utils_begin(cmd_line_checker)
    `uvm_field_int(enable, UVM_ALL_ON)
  `uvm_component_utils_end

  /**
   * UVM constructor.
   */
  function new(string name, uvm_component parent);
    super.new(name, parent);
  endfunction

  /**
   * UVM connect phase.
   */
  function void connect_phase(uvm_phase phase);
    if (enable) begin
      check_command_line();
    end
  endfunction

  /**
   * Validate all command line arguments in the form:
   * +uvm_set_config_int=<inst_name>,<field_name>,<value>
   * +uvm_set_config_string=<inst_name>,<field_name>,<value>
   */
  function void check_command_line();
    string args[$];
    uvm_root root = uvm_root::get();

    void'(root.clp.get_arg_matches(
      "/^\\+(UVM_SET_CONFIG_INT|uvm_set_config_int)=/",args));
    foreach(args[i]) begin
      check_config(args[i].substr(20, args[i].len()-1));
    end
    void'(root.clp.get_arg_matches(
      "/^\\+(UVM_SET_CONFIG_STRING|uvm_set_config_string)=/",args));
    foreach(args[i]) begin
      check_config(args[i].substr(23, args[i].len()-1));
    end
  endfunction

  /**
   * Check a single command line argument.
   * The instance name and field name should exist.
   * @param cfg the command line argument in the form:
   *     <inst_name>,<field_name>,<value>
   */
  function void check_config(string cfg);
    string split_val[$];
    string inst_name;
    string field_name;
    uvm_root root;
    uvm_component components[$];
    bit match_found;

    uvm_split_string(cfg, ",", split_val);
    inst_name = split_val[0];
    field_name = split_val[1];

    `uvm_info("CHECK_CONFIG",
        $sformatf("checking inst_name:%s, field_name:%s",
          inst_name, field_name), UVM_HIGH);

    // Get every object in uvm hierarchy that matches
    root = uvm_root::get();
    root.find_all(inst_name, components);

    // If object matches inst_name, check whether a match for field_name exists
    foreach (components[i]) begin
      if (match_found) begin
        break;
      end else begin
        uvm_component component = components[i];
        uvm_status_container status = component.__m_uvm_status_container;
        component.__m_uvm_field_automation (null, UVM_CHECK_FIELDS, "");
        if (uvm_has_wildcard(field_name)) begin
          foreach (status.field_array[name]) begin
            if (!(uvm_re_match(uvm_glob_to_re(field_name), name))) begin
              match_found = 1;
              break;
            end
          end
        end else begin
          // No wildcards to match
          match_found = status.field_array[field_name];
        end
        status.field_array.delete();
        if (match_found) begin
          `uvm_info("MATCH_FOUND", $sformatf(
                "UVM match for command line config %s,%s found in %s",
                inst_name, field_name, component.get_full_name()), UVM_HIGH);
          break;
        end
      end
    end

    if (!match_found) begin
      `uvm_error("BAD_CONFIG",
          $sformatf("UVM match for command line config %s,%s not found",
          inst_name, field_name));
    end
  endfunction

endclass

上面的SVUnit测试在cmd_line_checker这里:http ://www.edaplayground.com/s/4/768

于 2014-01-03T13:15:37.407 回答