// Copyright lowRISC contributors.
// Licensed under the Apache License, Version 2.0, see LICENSE for details.
// SPDX-License-Identifier: Apache-2.0
{
  build_cmd:  "{job_prefix} xrun"
  run_cmd:    "{job_prefix} xrun"

  // Indicate the tool specific helper sources - these are copied over to the
  // {tool_srcs_dir} before running the simulation.
  tool_srcs:  ["{proj_root}/dv/uvm/data/xcelium/*"]

  build_opts: ["-elaborate -64bit -access +r -sv",
               "-licqueue",
               // TODO: duplicate primitives between OT and Ibex #1231
               "-ALLOWREDEFINITION",
               "-messages -errormax 50",
               "-timescale 1ns/1ps",
               "-f {sv_flist}",
               "-uvmhome {UVM_HOME}",
               "-xmlibdirname {build_dir}/xcelium.d"]

  run_opts:   ["-input {tool_srcs_dir}/xcelium_{dump}.tcl",
               "-licqueue",
               "-64bit -xmlibdirname {build_dir}/xcelium.d -R",
               "+SVSEED={seed}",
               "+UVM_TESTNAME={uvm_test}",
               "+UVM_TEST_SEQ={uvm_test_seq}"]

  // Vars that need to exported to the env.
  exports: [
    // Poll for an available license in all servers.
    CDS_LIC_QUEUE_POLL: 1
    // Poll for an available license every 1 min.
    CDS_LIC_QUEUE_POLL_INT: 60

    // Export the cov_report path so that the tcl file can read these as env vars.
    cov_merge_db_dir: "{cov_merge_db_dir}"
    cov_report_dir:   "{cov_report_dir}"
  ]

  // Coverage related.
  // By default, collect all coverage metrics: block:expr:fsm:toggle:functional.
  cov_metrics: all
  // Supply the cov configuration file.
  // Note that this needs to be set as -covfile <file>.
  xcelium_cov_cfg_file: ""
  // Supply the cov refinement file.
  // Note that this needs to be set as -load_refinement <file>.
  xcelium_cov_refine_file: ""

  // Set the coverage directories.
  cov_work_dir: "{scratch_path}/coverage"
  cov_db_dir:   "{cov_work_dir}/{build_mode}"

  // Individual test specific coverage data - this will be deleted if the test fails
  // so that coverage from failiing tests is not included in the final report.
  cov_db_test_dir_name: "{run_dir_name}.{seed}"
  cov_db_test_dir:      "{cov_db_dir}/{cov_db_test_dir_name}"

  // Merging coverage.
  // It is constructed by the tool itself.
  cov_merge_dir:    "{scratch_base_path}/cov_merge"
  cov_merge_db_dir: "{cov_merge_dir}/merged"
  cov_merge_cmd:    "{job_prefix} imc"
  cov_merge_opts:   ["-64bit",
                     "-licqueue",
                     "-exec {tool_srcs_dir}/cov_merge.tcl"]

  // Generate covreage reports in text as well as html.
  cov_report_dir:   "{scratch_base_path}/cov_report"
  cov_report_cmd:   "{job_prefix} imc"
  cov_report_opts:  ["-64bit",
                     "-licqueue",
                     "-exec {tool_srcs_dir}/cov_report.tcl"]
  cov_report_txt:   "{cov_report_dir}/cov_report.txt"
  cov_report_page:  "{cov_report_dir}/index.html"

  // Analyzing coverage - this is done by invoking --cov-analyze switch. It opens up the
  // GUI for visual analysis.
  cov_analyze_dir:  "{scratch_base_path}/cov_analyze"
  cov_analyze_cmd:  "{job_prefix} imc"
  cov_analyze_opts: ["-gui",
                     "-64bit",
                     "-licqueue",
                     "-load {cov_merge_db_dir}",
                     "{xcelium_cov_refine_file}"]

  // pass and fail patterns
  build_fail_patterns: ["\\*E.*$"]
  run_fail_patterns:   ["\\*E.*$"] // Null pointer error

  build_modes: [
    {
      name: xcelium_waves
      is_sim_mode: 1
    }
    {
      name: xcelium_cov
      is_sim_mode: 1
      build_opts: [// Enable the required cov metrics.
                   "-coverage {cov_metrics}",
                   // Limit the scope of coverage collection to the DUT.
                   "-covdut {dut}",
                   // Set the coverage configuration file.
                   "{xcelium_cov_cfg_file}"]
      run_opts:   [// Coverage database output location.
                   "-covworkdir {cov_work_dir}",
                   // Set the scope to the build mode name.
                   "-covscope {build_mode}",
                   // Test coverage dir name to create under cov_db_dir.
                   "-covtest {cov_db_test_dir_name}",
                   // Overwrite the coverage data of a specific test/seed if it already exists.
                   "-covoverwrite"]
    }
    // TODO support profile for xcelium
    {
      name: xcelium_profile
      is_sim_mode: 1
      build_opts: []
      run_opts:   []
    }
    {
      name: xcelium_xprop
      is_sim_mode: 1
      # -xverbose  << add to see which modules does not have xprop enabled
      build_opts: ["-xprop F"]
    }
  ]
}
