# Copyright 2025-2026, Intel Corporation
# SPDX-License-Identifier: BSD-3-Clause

name: RISC-V Tests

permissions: read-all

on:
  workflow_call:
    inputs:
      artifact_name:
        description: 'Name of the artifact to test'
        required: true
        type: string

jobs:
  riscv-test:
    name: RISC-V rvv-x4 test
    runs-on: ubuntu-22.04
    container:
      # archlinux allows to use qemu 10.1.2 which has support of float16 in RISC-V
      image: archlinux@sha256:2fcdd55448255f87dd337ef5c0fdbd5e4fec432345db1aa5faea4bf2764b4ca8
      options: --privileged

    steps:
    - name: Setup Arch Linux
      run: |
        pacman-key --init
        pacman-key --populate archlinux
        # Update keyring first, then re-populate to trust new signing keys
        pacman -Sy --noconfirm archlinux-keyring
        pacman-key --populate archlinux
        pacman -Su --noconfirm
        pacman -S --needed --noconfirm git cmake make gcc-libs glibc lib32-glibc gcc m4 flex bison python onetbb
        pacman -S --needed --noconfirm riscv64-linux-gnu-gcc qemu-user

    - uses: actions/checkout@1af3b93b6815bc44a9784bd300feb67ff0d1eeb3 # v6.0.0

    - name: Download package
      uses: actions/download-artifact@37930b1c2abaa49bbe596cd826c3c89aef350131 # v7.0.0
      with:
        name: ${{ inputs.artifact_name }}

    - name: Install dependencies and unpack artifacts
      run: |
        ISPC_TAR=$(ls ispc-*-linux.tar.gz)
        tar xf "$ISPC_TAR"
        ISPC_DIR=$(basename "$ISPC_TAR" .tar.gz)
        echo "$GITHUB_WORKSPACE/$ISPC_DIR/bin" >> "$GITHUB_PATH"

    - name: Check tools
      run: |
        riscv64-linux-gnu-gcc --version
        qemu-riscv64 --version

    - name: Run RISC-V tests
      run: |
        python scripts/run_tests.py \
          --target=rvv-x4 \
          --arch=riscv64 \
          -f "--cpu=spacemit-x60" \
          --wrap-exe="qemu-riscv64 -cpu max,v=true,g=true,vlen=256" \
          --compiler=riscv64-linux-gnu-g++ \
          -o O2
