{#
################################################################################
#
# Copyright 2020 OpenHW Group
#
# Licensed under the Solderpad Hardware Licence, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     https://solderpad.org/licenses/
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# SPDX-License-Identifier:Apache-2.0 WITH SHL-2.0
#
################################################################################
# metrics.json.j2: Jinja2 template for rendering metrics.json files for cv_regress

#}

{% import 'regress_macros.j2' as regress_macros %}

{% set common_dsim_make_vars = "CV_CORE=" + project + " COMP=0 DSIM_WORK=/mux-flow/build/repo/dsim_work SIM_RESULTS=/mux-flow/build/results" %}
{% set common_dsim_make_vars_waves = "CV_CORE=" + project + " COMP=0 DSIM_WORK=/mux-flow/build/repo/dsim_work SIM_RESULTS=/mux-flow/build/results WAVES=1" %}
[
{% for r in regressions %}
{% for t in r.tests.values()|sort(attribute='name') %}
{% set is_last_test = loop.last %}
{# For Metrics, the name is description if available, otherwise use name, with index #}
{% if t.description %}{% set test_name = t.description %}{% else %}{% set test_name = t.name %}{% endif %}
{% for build in t.builds %}
{% set is_last_build = loop.last %}
{% set test_suffix = '/0' %}
    {
        "name": "{{test_name}}" ,
        "build": "{{r.builds[build].name}}",
        "cmd": "cd {{t.dir}}; {{t.cmd}} CV_CORE={{project}} CFG={{r.builds[build].cfg}} {{toolchain|upper}}=1 SIMULATOR={{t.simulator}} USE_ISS={{regress_macros.yesorno(t.iss)}} RNDSEED=<seed> {{common_dsim_make_vars}} {{makeargs}} {{t.makearg}}",
        "wavesCmd": "cd {{t.dir}}; {{t.cmd}} CV_CORE={{project}} CFG={{r.builds[build].cfg}} {{toolchain|upper}}=1 SIMULATOR={{t.simulator}} USE_ISS={{regress_macros.yesorno(t.iss)}} RNDSEED=<seed> {{common_dsim_make_vars_waves}} {{makeargs}} {{t.makearg}}",
{% if t.results %}
        "metricsFile": "{{r.builds[build].cfg}}/{{t.results}}{{test_suffix}}/metrics.db",
        "wavesFile": "{{r.builds[build].cfg}}/{{t.results}}{{test_suffix}}/dsim.vcd",
{% else %}
        "metricsFile": "{{r.builds[build].cfg}}/{{t.name}}{{test_suffix}}/metrics.db",
        "wavesFile": "{{r.builds[build].cfg}}/{{t.name}}{{test_suffix}}/dsim.vcd",
{% endif %}
        "seed" : "random",
        "iterations": {{t.num}},
        "isPass": "{{t.simulation_passed}}",
        "isFail": "{{t.simulation_failed}}"
    }{% if not is_last_test or not is_last_build%},{% endif %}

{% endfor %}
{% endfor %}
{% endfor %}
]

