# Copyright 2026 OpenHW Group
# Licensed under the Apache License, Version 2.0, see LICENSE for details.
# SPDX-License-Identifier: Apache-2.0
# ================================================================================
# OpenHW CVA6 CI - Tier 1: Fast Verilator Sanity
# ================================================================================
#
# PURPOSE:
#   Fast Verilator-based sanity regression for the three phase-1 "green"
#   configurations selected for the first GitHub CI rollout.
#   Runs one representative smoke or directed test per approved
#   configuration to provide automatic sanity checks for pull-requests.
#
# TRIGGER POLICY:
#   pull_request      -> Automatic sanity checks for PRs targeting master
#   workflow_dispatch -> On-demand rerun for manual validation
#
# COVERED CONFIGURATIONS (Phase-1 Green Config subset):
#   RV32:
#     - cv32a65x                        (dual-issue, no MMU)
#     - cv32a60x                        (single-issue, no MMU)
#   RV64:
#     - cv64a6_imafdc_sv39_hpdcache_wb  (HPDcache + write-back)
#
# TEST SUITES PER CONFIG:
#   - cv32a65x                       -> smoke-tests-cv32a65x
#   - cv32a60x                       -> cv32a6_tests
#   - cv64a6_imafdc_sv39_hpdcache_wb -> cv64a6_imafdc_tests
#
# NOTES:
#   - Phase 1 Tier 1 is Verilator-only.
#   - Tier 1 is intentionally narrower than Tier 2: the goal is fast signal,
#     not broad regression depth.
# ================================================================================

name: openhw-cva6-ci-tier1

on:
  pull_request:
    branches:
      - master
  workflow_dispatch:

concurrency:
  group: openhw-cva6-ci-tier1-${{ github.ref }}
  cancel-in-progress: true

env:
  SPIKE_TANDEM: 1
  NUM_JOBS: 8
  FORCE_JAVASCRIPT_ACTIONS_TO_NODE24: "true"

jobs:
  # ============================================================
  # Stage 1: Populate tool cache
  # ============================================================
  setup-tools:
    name: Setup Tools
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v7
        with:
          submodules: recursive

      - name: Setup CVA6 Environment
        uses: ./.github/actions/setup-cva6-env
        with:
          install-tools: "true"

  # ============================================================
  # Stage 2: RV32 Fast Sanity (parallel matrix jobs)
  # ============================================================
  execute-rv32-tier1:
    name: RV32 Tier1 ${{ matrix.config }} / ${{ matrix.testcase }}
    runs-on: ubuntu-latest
    needs: setup-tools
    strategy:
      fail-fast: false
      matrix:
        include:
          # ----------------------------------------------------------
          # cv32a65x - dual-issue RV32, no MMU
          # ----------------------------------------------------------
          # Quickest RV32 sanity signal for the higher-feature RV32 core
          - config: cv32a65x
            testcase: smoke-tests-cv32a65x
            mode: script
            simulator: veri-testharness,spike
            install_script: ""
            testlist: ""
            test_name: ""
            linker: ""

          # ----------------------------------------------------------
          # cv32a60x - single-issue RV32, no MMU
          # ----------------------------------------------------------
          # Directed sanity regression; no dedicated workflow-native smoke exists
          - config: cv32a60x
            testcase: cv32a6_tests
            mode: script
            simulator: veri-testharness,spike
            install_script: ""
            testlist: ""
            test_name: ""
            linker: ""

    steps:
      - uses: actions/checkout@v7
        with:
          submodules: recursive

      - name: Setup CVA6 Environment
        uses: ./.github/actions/setup-cva6-env

      - name: Install prerequisites
        run: source ci/install-prereq.sh

      - name: Run Tier 1 for ${{ matrix.config }} / ${{ matrix.testcase }}
        env:
          TIER_NAME: Tier 1
          TIER_MODE: ${{ matrix.mode }}
          TIER_CONFIG: ${{ matrix.config }}
          TIER_TESTCASE: ${{ matrix.testcase }}
          TIER_SIMULATOR: ${{ matrix.simulator }}
          TIER_INSTALL_SCRIPT: ${{ matrix.install_script }}
          TIER_TESTLIST: ${{ matrix.testlist }}
          TIER_TEST_NAME: ${{ matrix.test_name }}
          TIER_LINKER: ${{ matrix.linker }}
        run: bash .github/scripts/run-tier-regression.sh

      - name: Upload Results
        if: always()
        uses: actions/upload-artifact@v4
        with:
          name: tier1-rv32-${{ matrix.config }}-${{ matrix.testcase }}
          path: |
            ci-results/
            verif/sim/out*/
          retention-days: 14

  # ============================================================
  # Stage 3: RV64 Fast Sanity
  # ============================================================
  execute-rv64-tier1:
    name: RV64 Tier1 ${{ matrix.config }} / ${{ matrix.testcase }}
    runs-on: ubuntu-latest
    needs: setup-tools
    strategy:
      fail-fast: false
      matrix:
        include:
          # ----------------------------------------------------------
          # cv64a6_imafdc_sv39_hpdcache_wb - RV64 HPDcache + write-back
          # ----------------------------------------------------------
          # Fast RV64 sanity using the existing directed script
          - config: cv64a6_imafdc_sv39_hpdcache_wb
            testcase: cv64a6_imafdc_tests
            mode: script
            simulator: veri-testharness,spike
            install_script: ""
            testlist: ""
            test_name: ""
            linker: ""

    steps:
      - uses: actions/checkout@v7
        with:
          submodules: recursive

      - name: Setup CVA6 Environment
        uses: ./.github/actions/setup-cva6-env

      - name: Install prerequisites
        run: source ci/install-prereq.sh

      - name: Run Tier 1 for ${{ matrix.config }} / ${{ matrix.testcase }}
        env:
          TIER_NAME: Tier 1
          TIER_MODE: ${{ matrix.mode }}
          TIER_CONFIG: ${{ matrix.config }}
          TIER_TESTCASE: ${{ matrix.testcase }}
          TIER_SIMULATOR: ${{ matrix.simulator }}
          TIER_INSTALL_SCRIPT: ${{ matrix.install_script }}
          TIER_TESTLIST: ${{ matrix.testlist }}
          TIER_TEST_NAME: ${{ matrix.test_name }}
          TIER_LINKER: ${{ matrix.linker }}
        run: bash .github/scripts/run-tier-regression.sh

      - name: Upload Results
        if: always()
        uses: actions/upload-artifact@v4
        with:
          name: tier1-rv64-${{ matrix.config }}-${{ matrix.testcase }}
          path: |
            ci-results/
            verif/sim/out*/
          retention-days: 14
