##
#  Copyright 2025 Inria
#  SPDX-License-Identifier: Apache-2.0 WITH SHL-2.1
##
##
#  Author     : Cesar Fuguet
#  Date       : October, 2024
#  Description: GitHub Action to run tests on pull requests and pushes
##
name: HPDcache Test CI
on:
  push:
    paths-ignore:
      - 'docs/**'
      - '**.md'
      - 'CODEOWNERS'
      - 'LICENSE'

  pull_request:
    paths-ignore:
      - 'docs/**'
      - '**.md'
      - 'CODEOWNERS'
      - 'LICENSE'

jobs:
  build:
    name: build
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@master

      #  Install Dependencies
      - name: Install Dependencies
        shell: bash
        run: |
          ./.github/scripts/install_deps_ubuntu.sh

      #  Install SystemC
      - name: Cache SystemC
        id: cache-systemc
        uses: actions/cache@v4
        with:
          path: build/systemc-3.0.1
          key: ${{ runner.os }}-build-systemc-${{ hashFiles('.github/scripts/install_systemc.sh') }}

      - name: Install SystemC
        shell: bash
        run: |
          . .github/scripts/env.sh
          ./.github/scripts/install_systemc.sh

      #  Install Verilator
      - name: Cache Verilator
        id: cache-verilator
        uses: actions/cache@v4
        with:
          path: build/verilator-v5.028
          key: ${{ runner.os }}-build-verilator-${{ hashFiles('.github/scripts/install_verilator.sh') }}

      - name: Install Verilator
        shell: bash
        run: |
          . .github/scripts/env.sh
          ./.github/scripts/install_verilator.sh


  #  Run the tests
  run_random_short:
    runs-on: ubuntu-latest
    name: run_random_short
    needs: build
    steps:
      - uses: actions/checkout@master

      - id: run_random_short_sequence
        uses: ./.github/actions/run_sequence
        with:
          seqname: 'random'
          ntrans: '10000'
          ntests: '64'
          config: 'configs/default_config.mk'

  run_random_long:
    runs-on: ubuntu-latest
    name: run_random_long
    needs: build
    steps:
      - uses: actions/checkout@master

      - id: run_random_long_sequence
        uses: ./.github/actions/run_sequence
        with:
          seqname: 'random'
          ntrans: '80000'
          ntests: '8'
          config: 'configs/default_config.mk'

  run_random_long_ecc:
    runs-on: ubuntu-latest
    name: run_random_long_ecc
    needs: build
    steps:
      - uses: actions/checkout@master

      - id: run_random_long_sequence_ecc
        uses: ./.github/actions/run_sequence
        with:
          seqname: 'random'
          ntrans: '80000'
          ntests: '8'
          config: 'configs/default_config.mk'
          inject_single_faults: '1'

  run_unique_set:
    runs-on: ubuntu-latest
    name: run_unique_set
    needs: build
    steps:
      - uses: actions/checkout@master

      - id: run_unique_set_sequence
        uses: ./.github/actions/run_sequence
        with:
          seqname: 'unique_set'
          ntrans: '20000'
          ntests: '16'
          config: 'configs/default_config.mk'

  run_random_short_hpc:
    runs-on: ubuntu-latest
    name: run_random_short_hpc
    needs: build
    steps:
      - uses: actions/checkout@master

      - id: run_random_short_sequence
        uses: ./.github/actions/run_sequence
        with:
          seqname: 'random'
          ntrans: '10000'
          ntests: '64'
          config: 'configs/hpc_config.mk'

  run_random_long_hpc:
    runs-on: ubuntu-latest
    name: run_random_long_hpc
    needs: build
    steps:
      - uses: actions/checkout@master

      - id: run_random_long_sequence
        uses: ./.github/actions/run_sequence
        with:
          seqname: 'random'
          ntrans: '80000'
          ntests: '8'
          config: 'configs/hpc_config.mk'

  run_unique_set_hpc:
    runs-on: ubuntu-latest
    name: run_unique_set_hpc
    needs: build
    steps:
      - uses: actions/checkout@master

      - id: run_unique_set_sequence
        uses: ./.github/actions/run_sequence
        with:
          seqname: 'unique_set'
          ntrans: '20000'
          ntests: '16'
          config: 'configs/hpc_config.mk'

  run_random_short_embedded:
    runs-on: ubuntu-latest
    name: run_random_short_embedded
    needs: build
    steps:
      - uses: actions/checkout@master

      - id: run_random_short_sequence
        uses: ./.github/actions/run_sequence
        with:
          seqname: 'random'
          ntrans: '10000'
          ntests: '64'
          config: 'configs/embedded_config.mk'

  run_random_long_embedded:
    runs-on: ubuntu-latest
    name: run_random_long_embedded
    needs: build
    steps:
      - uses: actions/checkout@master

      - id: run_random_long_sequence
        uses: ./.github/actions/run_sequence
        with:
          seqname: 'random'
          ntrans: '80000'
          ntests: '8'
          config: 'configs/embedded_config.mk'

  run_random_long_embedded_ecc:
    runs-on: ubuntu-latest
    name: run_random_long_embedded_ecc
    needs: build
    steps:
      - uses: actions/checkout@master

      - id: run_random_long_sequence_ecc
        uses: ./.github/actions/run_sequence
        with:
          seqname: 'random'
          ntrans: '80000'
          ntests: '8'
          config: 'configs/embedded_config.mk'
          inject_single_faults: '1'

  run_unique_set_embedded:
    runs-on: ubuntu-latest
    name: run_unique_set_embedded
    needs: build
    steps:
      - uses: actions/checkout@master

      - id: run_unique_set_sequence
        uses: ./.github/actions/run_sequence
        with:
          seqname: 'unique_set'
          ntrans: '20000'
          ntests: '16'
          config: 'configs/embedded_config.mk'

  run_random_short_directmap:
    runs-on: ubuntu-latest
    name: run_random_short_directmap
    needs: build
    steps:
      - uses: actions/checkout@master

      - id: run_random_short_sequence
        uses: ./.github/actions/run_sequence
        with:
          seqname: 'random'
          ntrans: '10000'
          ntests: '64'
          config: 'configs/directmap_config.mk'

  run_trace:
    runs-on: ubuntu-latest
    name: run_trace
    needs: build
    steps:
      - uses: actions/checkout@master

      - id: run_from_trace_sequence
        uses: ./.github/actions/run_sequence
        with:
          seqname: 'from_trace'
          ntrans: '800000'
          ntests: '1'
          filename: 'traces_lib/trace_spmv_2000x2000_0p001.bin.gz'
          config: 'configs/default_config.mk'

      - id: verify_perf
        uses: ./.github/actions/evaluate_trace
        with:
          config: 'configs/default_config.mk'
          trace_perf: 'perf_log/current_perf_default.txt'
          github_token: "${{ secrets.GITHUB_TOKEN }}"

  run_trace_hpc:
    runs-on: ubuntu-latest
    name: run_trace_hpc
    needs: build
    steps:
      - uses: actions/checkout@master

      - id: run_from_trace_sequence
        uses: ./.github/actions/run_sequence
        with:
          seqname: 'from_trace'
          ntrans: '800000'
          ntests: '1'
          filename: 'traces_lib/trace_spmv_2000x2000_0p001.bin.gz'
          config: 'configs/hpc_config.mk'

      - id: verify_perf
        uses: ./.github/actions/evaluate_trace
        with:
          config: 'configs/hpc_config.mk'
          trace_perf: 'perf_log/current_perf_hpc.txt'
          github_token: "${{ secrets.GITHUB_TOKEN }}"
