#!/bin/bash

# This file is sourced by libbpf/ci/run-vmtest Github Action scripts.

# $SELFTESTS_BPF and $VMTEST_CONFIGS are set in the workflow, before
# libbpf/ci/run-vmtest action is called
# See .github/workflows/kernel-test.yml

ALLOWLIST_FILES=(
    "${SELFTESTS_BPF}/ALLOWLIST"
    "${SELFTESTS_BPF}/ALLOWLIST.${ARCH}"
    "${VMTEST_CONFIGS}/ALLOWLIST"
    "${VMTEST_CONFIGS}/ALLOWLIST-${KERNEL}"
    "${VMTEST_CONFIGS}/ALLOWLIST-${KERNEL}.${ARCH}"
)

DENYLIST_FILES=(
    "${SELFTESTS_BPF}/DENYLIST"
    "${SELFTESTS_BPF}/DENYLIST.${ARCH}"
    "${VMTEST_CONFIGS}/DENYLIST"
    "${VMTEST_CONFIGS}/DENYLIST-${KERNEL}"
    "${VMTEST_CONFIGS}/DENYLIST-${KERNEL}.${ARCH}"
)

# Export pipe-separated strings, because bash doesn't support array export
export SELFTESTS_BPF_ALLOWLIST_FILES=$(IFS="|"; echo "${ALLOWLIST_FILES[*]}")
export SELFTESTS_BPF_DENYLIST_FILES=$(IFS="|"; echo "${DENYLIST_FILES[*]}")

if [[ "${LLVM_VERSION}" -lt 18 ]]; then
    echo "KERNEL_TEST=test_progs test_progs_no_alu32 test_maps test_verifier" >> $GITHUB_ENV
else # all
    echo "KERNEL_TEST=test_progs test_progs_cpuv4 test_progs_no_alu32 test_maps test_verifier" >> $GITHUB_ENV
fi

echo "cp -R ${SELFTESTS_BPF} ${GITHUB_WORKSPACE}/selftests"
mkdir -p "${GITHUB_WORKSPACE}/selftests"
cp -R "${SELFTESTS_BPF}" "${GITHUB_WORKSPACE}/selftests"
