diff --git a/.github/workflows/kernel-build.yml b/.github/workflows/kernel-build.yml index 67a3fc5..d2aa9f0 100644 --- a/.github/workflows/kernel-build.yml +++ b/.github/workflows/kernel-build.yml @@ -87,23 +87,18 @@ jobs: cd .. rmdir .kernel - uses: ./patch-kernel + with: patches-root: '${{ github.workspace }}/ci/diffs' repo-root: ${{ env.REPO_ROOT }} + - name: Setup build environment uses: ./setup-build-env with: arch: ${{ inputs.arch }} llvm-version: ${{ inputs.llvm-version }} pahole: master - - name: Print toolchain version used - shell: bash - run: | - TOOLCHAIN=${{ inputs.toolchain }} - if [ $TOOLCHAIN = "llvm" ]; then - TOOLCHAIN="clang-${{ inputs.llvm-version }}" - fi - ${TOOLCHAIN} --version + - name: Build kernel image uses: ./build-linux with: @@ -133,6 +128,7 @@ jobs: toolchain: ${{ inputs.toolchain }} llvm-version: ${{ inputs.llvm-version }} max-make-jobs: 32 + - if: ${{ github.event_name != 'push' }} name: Build samples uses: ./build-samples @@ -147,7 +143,7 @@ jobs: uses: ./tar-artifacts env: ARCHIVE_BPF_SELFTESTS: 'true' - ARCHIVE_MAKE_HELPERS: ${{ github.repository != 'kernel-patches/bpf' && 'true' || '' }} + ARCHIVE_MAKE_HELPERS: 'true' ARCHIVE_SCHED_EXT_SELFTESTS: ${{ env.BUILD_SCHED_EXT_SELFTESTS }} with: arch: ${{ inputs.arch }} diff --git a/.github/workflows/kernel-test.yml b/.github/workflows/kernel-test.yml index 53153c2..fe641b1 100644 --- a/.github/workflows/kernel-test.yml +++ b/.github/workflows/kernel-test.yml @@ -60,24 +60,6 @@ jobs: # zstd is installed by default in the runner images. run: zstd -d -T0 vmlinux-${{ inputs.arch }}-${{ inputs.toolchain_full }}.tar.zst --stdout | tar -xf - - - name: Prepare ALLOW/DENYLIST - env: - SELFTESTS_BPF: ${{ github.workspace }}/selftests/bpf - VMTEST_CONFIGS: ${{ github.workspace }}/ci/vmtest/configs - run: | - cat "${SELFTESTS_BPF}/ALLOWLIST" \ - "${SELFTESTS_BPF}/ALLOWLIST.${ARCH}" \ - "${VMTEST_CONFIGS}/ALLOWLIST" \ - "${VMTEST_CONFIGS}/ALLOWLIST.${ARCH}" \ - 2> /dev/null > "${ALLOWLIST_FILE}" || true - - cat "${SELFTESTS_BPF}/DENYLIST" \ - "${SELFTESTS_BPF}/DENYLIST.${ARCH}" \ - "${VMTEST_CONFIGS}/DENYLIST" \ - "${VMTEST_CONFIGS}/DENYLIST.${ARCH}" \ - "${VMTEST_CONFIGS}/DENYLIST.${DEPLOYMENT}" \ - 2> /dev/null > "${DENYLIST_FILE}" || true - - name: Run selftests uses: ./run-vmtest # https://github.com/actions/runner/issues/1483#issuecomment-1031671517 @@ -85,6 +67,11 @@ jobs: continue-on-error: ${{ fromJSON(env.CONTINUE_ON_ERROR) }} timeout-minutes: ${{ inputs.timeout_minutes }} env: + ARCH: ${{ inputs.arch }} + DEPLOYMENT: ${{ env.DEPLOYMENT }} + KERNEL_TEST: ${{ inputs.test }} + SELFTESTS_BPF: ${{ github.workspace }}/selftests/bpf + VMTEST_CONFIGS: ${{ github.workspace }}/ci/vmtest/configs TEST_PROGS_WATCHDOG_TIMEOUT: 300 with: arch: ${{ inputs.arch }} diff --git a/ci/vmtest/configs/run-vmtest.env b/ci/vmtest/configs/run-vmtest.env new file mode 100644 index 0000000..dd6e750 --- /dev/null +++ b/ci/vmtest/configs/run-vmtest.env @@ -0,0 +1,38 @@ +#!/bin/bash + +# This file is sourced by libbpf/ci/run-vmtest Github Action scripts. +# +# The primary reason it exists is that assembling ALLOWLIST and +# DENYLIST for a particular test run is not a trivial operation. +# +# Users of libbpf/ci/run-vmtest action need to be able to specify a +# list of allow/denylist **files**, that later has to be correctly +# merged into a single allow/denylist passed to a test runner. +# +# Obviously it's perferrable for the scripts merging many lists into +# one to be reusable, and not copy-pasted between repositories which +# use libbpf/ci actions. And specifying the lists should be trivial. +# This file is a solution to that. + +ALLOWLIST_FILES=( + "${SELFTESTS_BPF}/ALLOWLIST" + "${SELFTESTS_BPF}/ALLOWLIST.${ARCH}" + "${VMTEST_CONFIGS}/ALLOWLIST" + "${VMTEST_CONFIGS}/ALLOWLIST.${ARCH}" + "${VMTEST_CONFIGS}/ALLOWLIST.${DEPLOYMENT}" + "${VMTEST_CONFIGS}/ALLOWLIST.${KERNEL_TEST}" +) + +DENYLIST_FILES=( + "${SELFTESTS_BPF}/DENYLIST" + "${SELFTESTS_BPF}/DENYLIST.${ARCH}" + "${VMTEST_CONFIGS}/DENYLIST" + "${VMTEST_CONFIGS}/DENYLIST.${ARCH}" + "${VMTEST_CONFIGS}/DENYLIST.${DEPLOYMENT}" + "${VMTEST_CONFIGS}/DENYLIST.${KERNEL_TEST}" +) + +# 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[*]}") + diff --git a/run-vmtest/merge_test_lists.py b/run-vmtest/merge_test_lists.py new file mode 100755 index 0000000..7505187 --- /dev/null +++ b/run-vmtest/merge_test_lists.py @@ -0,0 +1,41 @@ +#!/usr/bin/python3 + +import sys + +def clean_line(line: str) -> str: + line = line.split('#')[0] # remove comment + line = line.strip() # strip whitespace + return line + +def read_clean_and_sort_input() -> list[str]: + input = [] + for line in sys.stdin: + line = clean_line(line) + if len(line) == 0: + continue + input.append(line) + input.sort() + return input + +def dedup_subtests(lines: list[str]): + i = 0 + j = 1 + while j < len(lines): + l1 = lines[i] + l2 = lines[j] + # for a pair of "foo_test" and "foo_test/subtest" + # remove a subtest from the list + if l1 == l2 or ('/' not in l1) and ('/' in l2) and l2.startswith(l1): + # print(f"removing '{l2}' because '{l1}' is in the list") + lines.remove(l2) + else: + i += 1 + j += 1 + +if __name__ == '__main__': + lines = read_clean_and_sort_input() + dedup_subtests(lines) + for line in lines: + print(line) + + diff --git a/run-vmtest/prepare-bpf-selftests.sh b/run-vmtest/prepare-bpf-selftests.sh new file mode 100755 index 0000000..ed027eb --- /dev/null +++ b/run-vmtest/prepare-bpf-selftests.sh @@ -0,0 +1,30 @@ +#!/bin/bash + +set -euo pipefail + +function merge_test_lists_into() { + local out="$1" + shift + local files=("$@") + echo -n > "$out" + + # first, append all the input lists into one + for file in "${files[@]}"; do + if [[ -f "$file" ]]; then + echo "cat $file >> $out" + cat "$file" >> "$out" + fi + done + + # then merge the list of test names + cat "$out" | python3 "$(dirname $0)/merge_test_lists.py" > "$out" +} + +# Read arrays from pipe-separated strings +IFS="|" read -a ALLOWLIST_FILES <<< "$SELFTESTS_BPF_ALLOWLIST_FILES" +IFS="|" read -a DENYLIST_FILES <<< "$SELFTESTS_BPF_DENYLIST_FILES" + +merge_test_lists_into "${ALLOWLIST_FILE}" "${ALLOWLIST_FILES[@]}" +merge_test_lists_into "${DENYLIST_FILE}" "${DENYLIST_FILES[@]}" + +exit 0 diff --git a/run-vmtest/run-bpf-selftests.sh b/run-vmtest/run-bpf-selftests.sh index 8ba6903..4ec229d 100755 --- a/run-vmtest/run-bpf-selftests.sh +++ b/run-vmtest/run-bpf-selftests.sh @@ -23,16 +23,13 @@ export SELFTESTS_BPF=${SELFTESTS_BPF:-/mnt/vmtest/selftests/bpf} STATUS_FILE=${STATUS_FILE:-/mnt/vmtest/exitstatus} OUTPUT_DIR=${OUTPUT_DIR:-/mnt/vmtest} -ALLOWLIST_FILE=${ALLOWLIST_FILE:-} -ALLOWLIST=$(read_lists "${ALLOWLIST_FILE}") -DENYLIST_FILE=${DENYLIST_FILE:-} -DENYLIST=$(read_lists "${DENYLIST_FILE}") - test_progs_helper() { local selftest="test_progs${1}" local args="$2" args+=" ${TEST_PROGS_WATCHDOG_TIMEOUT:+-w$TEST_PROGS_WATCHDOG_TIMEOUT}" + args+=" ${ALLOWLIST_FILE:+-a@$ALLOWLIST_FILE}" + args+=" ${DENYLIST_FILE:+-d@$DENYLIST_FILE}" json_file=${selftest/-/_} if [ "$2" == "-j" ] @@ -42,11 +39,11 @@ test_progs_helper() { json_file="${OUTPUT_DIR}/${json_file}.json" foldable start ${selftest} "Testing ${selftest}" - echo "./${selftest} ${args} ${DENYLIST:+-d\"$DENYLIST\"} ${ALLOWLIST:+-a\"$ALLOWLIST\"} --json-summary \"${json_file}\"" + echo "./${selftest} ${args} --json-summary \"${json_file}\"" # "&& true" does not change the return code (it is not executed # if the Python script fails), but it prevents exiting on a # failure due to the "set -e". - ./${selftest} ${args} ${DENYLIST:+-d"$DENYLIST"} ${ALLOWLIST:+-a"$ALLOWLIST"} --json-summary "${json_file}" && true + ./${selftest} ${args} --json-summary "${json_file}" && true echo "${selftest}:$?" >>"${STATUS_FILE}" foldable end ${selftest} } @@ -85,6 +82,10 @@ test_verifier() { foldable end test_verifier } +test_progs-bpf_gcc() { + test_progs_helper "-bpf_gcc" "" +} + export VERISTAT_CONFIGS=${VERISTAT_CONFIGS:-/mnt/vmtest/ci/vmtest/configs} export WORKING_DIR=$(pwd) # veristat config expects this variable @@ -134,13 +135,16 @@ run_veristat_meta() { foldable end vm_init foldable start kernel_config "Kconfig" - zcat /proc/config.gz - foldable end kernel_config -echo "DENYLIST: ${DENYLIST}" -echo "ALLOWLIST: ${ALLOWLIST}" +foldable start allowlist "ALLOWLIST" +test -f "${ALLOWLIST_FILE:-}" && cat "${ALLOWLIST_FILE}" +foldable end allowlist + +foldable start denylist "DENYLIST" +test -f "${DENYLIST_FILE:-}" && cat "${DENYLIST_FILE}" +foldable end denylist cd $SELFTESTS_BPF @@ -152,6 +156,7 @@ if [ ${#TEST_NAMES[@]} -eq 0 ]; then test_progs_cpuv4 test_maps test_verifier + test -f test_progs-bpf_gcc && test_progs-bpf_gcc else # else we run the tests passed as command-line arguments and through boot # parameter. diff --git a/run-vmtest/run.sh b/run-vmtest/run.sh index 4f4add9..0234175 100755 --- a/run-vmtest/run.sh +++ b/run-vmtest/run.sh @@ -40,13 +40,20 @@ then RUN_BPFTOOL_CHECKS=true fi +VMTEST_CONFIGS=${VMTEST_CONFIGS:-} +if [[ -n "$VMTEST_CONFIGS" && -f "${VMTEST_CONFIGS}/run-vmtest.env" ]]; +then + source "${VMTEST_CONFIGS:-}/run-vmtest.env" +fi + VMTEST_SCRIPT=${VMTEST_SCRIPT:-} -if [[ -z "$VMTEST_SCRIPT" \ - && "$KERNEL_TEST" != "sched_ext" ]]; +if [[ -z "$VMTEST_SCRIPT" && "$KERNEL_TEST" == "sched_ext" ]]; then - VMTEST_SCRIPT="${GITHUB_ACTION_PATH}/run-bpf-selftests.sh" -else - VMTEST_SCRIPT="${GITHUB_ACTION_PATH}/run-scx-selftests.sh" + VMTEST_SCRIPT="${GITHUB_ACTION_PATH}/run-scx-selftests.sh" +elif [[ -z "$VMTEST_SCRIPT" ]]; +then + ${GITHUB_ACTION_PATH}/prepare-bpf-selftests.sh + VMTEST_SCRIPT="${GITHUB_ACTION_PATH}/run-bpf-selftests.sh" fi # clear exitstatus file