diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index e293128..b98321f 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -1,19 +1,17 @@ name: libbpf-ci -on: +on: pull_request: push: schedule: - cron: '0 18 * * *' -concurrency: +concurrency: group: ci-test-${{ github.head_ref }} cancel-in-progress: true jobs: vmtest: - runs-on: ${{ matrix.runs_on }} - name: Kernel ${{ matrix.kernel }} on ${{ matrix.arch }} + selftests strategy: fail-fast: false matrix: @@ -21,15 +19,13 @@ jobs: - kernel: 'LATEST' runs_on: ubuntu-24.04 arch: 'x86_64' - steps: - - uses: actions/checkout@v4 - name: Checkout - - uses: ./.github/actions/setup - name: Setup - - uses: ./.github/actions/vmtest - name: vmtest - continue-on-error: false - timeout-minutes: 180 - with: - kernel: ${{ matrix.kernel }} - arch: ${{ matrix.arch }} + llvm-version: '17' + pahole: 'master' + name: ${{ matrix.kernel }} kernel llvm-${{ matrix.llvm-version }} pahole@${{ matrix.pahole }} + uses: ./.github/workflows/vmtest.yml + with: + runs_on: ${{ matrix.runs_on }} + kernel: ${{ matrix.kernel }} + arch: ${{ matrix.arch }} + llvm-version: ${{ matrix.llvm-version }} + pahole: ${{ matrix.pahole }} diff --git a/.github/workflows/vmtest.yml b/.github/workflows/vmtest.yml new file mode 100644 index 0000000..d9b2ed5 --- /dev/null +++ b/.github/workflows/vmtest.yml @@ -0,0 +1,134 @@ +name: 'Build kernel and selftests/bpf, run selftests via vmtest' + +on: + workflow_call: + inputs: + runs_on: + required: true + default: 'ubuntu-24.04' + type: string + arch: + description: 'what arch to test' + required: true + default: 'x86_64' + type: string + kernel: + description: 'kernel version or LATEST' + required: true + default: 'LATEST' + type: string + pahole: + description: 'pahole rev or branch' + required: false + default: 'master' + type: string + llvm-version: + description: 'llvm version' + required: false + default: '17' + type: string +jobs: + vmtest: + runs-on: ${{ inputs.runs_on }} + steps: + + - uses: actions/checkout@v4 + + - name: Setup environment + uses: theihor/libbpf-ci/setup-build-env@run-vmtest-v2 + with: + pahole: ${{ inputs.pahole }} + arch: ${{ inputs.arch }} + llvm-version: ${{ inputs.llvm-version }} + + - name: Get checkpoint commit + shell: bash + run: | + cat CHECKPOINT-COMMIT + echo "CHECKPOINT=$(cat CHECKPOINT-COMMIT)" >> $GITHUB_ENV + + - name: Get kernel source at checkpoint + uses: theihor/libbpf-ci/get-linux-source@run-vmtest-v2 + with: + repo: 'https://git.kernel.org/pub/scm/linux/kernel/git/bpf/bpf-next.git' + rev: ${{ env.CHECKPOINT }} + dest: '${{ github.workspace }}/.kernel' + + - name: Patch kernel source + uses: theihor/libbpf-ci/patch-kernel@run-vmtest-v2 + with: + patches-root: '${{ github.workspace }}/ci/diffs' + repo-root: '.kernel' + + - name: Configure kernel build + shell: bash + run: | + cd .kernel + cat tools/testing/selftests/bpf/config \ + tools/testing/selftests/bpf/config.${{ inputs.arch }} > .config + # this file might or mihgt not exist depending on kernel version + cat tools/testing/selftests/bpf/config.vm >> .config || : + make olddefconfig && make prepare + cd - + + - name: Build kernel image + if: ${{ inputs.kernel == 'LATEST' }} + shell: bash + run: | + cd .kernel + make -j $((4*$(nproc))) all + cp vmlinux ${{ github.workspace }} + cd - + + - name: Download prebuilt kernel + if: ${{ inputs.kernel != 'LATEST' }} + uses: theihor/libbpf-ci/download-vmlinux@run-vmtest-v2 + with: + kernel: ${{ inputs.kernel }} + arch: ${{ inputs.arch }} + + - name: Prepare to build selftests + shell: bash + env: + PREPARE_SCRIPT: ${{ github.workspace }}/ci/vmtest/prepare-selftests-build-${{ inputs.kernel }}.sh + SELFTESTS_BPF: ${{ github.workspace }}/.kernel/tools/testing/selftests/bpf + run: | + if [ -f "${PREPARE_SCRIPT}" ]; then + bash "${PREPARE_SCRIPT}" + fi + + - name: Build selftests/bpf + uses: theihor/libbpf-ci/build-selftests@run-vmtest-v2 + env: + MAX_MAKE_JOBS: 32 + VMLINUX_BTF: ${{ github.workspace }}/vmlinux + VMLINUX_H: ${{ inputs.kernel != 'LATEST' && format('{0}/.github/actions/build-selftests/vmlinux.h', github.workspace) || '' }} + with: + arch: ${{ inputs.arch }} + kernel-root: ${{ github.workspace }}/.kernel + llvm-version: ${{ inputs.llvm-version }} + + - name: Prepare to run selftests + env: + ALLOWLIST_FILE: /tmp/allowlist + DENYLIST_FILE: /tmp/denylist + ARCH: ${{ inputs.arch }} + KERNEL: ${{ inputs.kernel }} + SELFTESTS_BPF: ${{ github.workspace }}/.kernel/tools/testing/selftests/bpf + VMTEST_CONFIGS: ${{ github.workspace }}/ci/vmtest/configs + shell: bash + run: ${{ github.workspace }}/ci/vmtest/prepare-selftests-run.sh + + - name: Run selftests + env: + ALLOWLIST_FILE: /tmp/allowlist + DENYLIST_FILE: /tmp/denylist + KERNEL: ${{ inputs.kernel }} + VMLINUX: ${{ github.workspace }}/vmlinux + uses: theihor/libbpf-ci/run-vmtest@run-vmtest-v2 + with: + arch: ${{ inputs.arch }} + kbuild-output: ${{ github.workspace }}/.kernel + kernel-root: ${{ github.workspace }}/.kernel + kernel-test: ${{ env.KERNEL_TEST || '' }} + vmlinuz: ${{ inputs.arch }}/vmlinuz-${{ inputs.kernel }} diff --git a/ci/vmtest/prepare-selftests-LATEST.sh b/ci/vmtest/prepare-selftests-LATEST.sh new file mode 100755 index 0000000..d73036e --- /dev/null +++ b/ci/vmtest/prepare-selftests-LATEST.sh @@ -0,0 +1,12 @@ +#!/bin/bash + +set -euo pipefail + +# noop script: it's here as a reminder that we might need it for other kernel versions + +# for 4.9.0 and 5.5.0 code was: +# cd "${SELFTESTS_BPF}" +# printf "all:\n\ttouch bpf_testmod.ko\n\nclean:\n" > bpf_testmod/Makefile +# printf "all:\n\ttouch bpf_test_no_cfi.ko\n\nclean:\n" > bpf_test_no_cfi/Makefile + +exit 0 diff --git a/ci/vmtest/prepare-selftests-build-5.5.0.sh b/ci/vmtest/prepare-selftests-build-5.5.0.sh deleted file mode 100755 index 03bc373..0000000 --- a/ci/vmtest/prepare-selftests-build-5.5.0.sh +++ /dev/null @@ -1,8 +0,0 @@ -#!/bin/bash - -set -euo pipefail - -cd "${SELFTESTS_BPF}" -printf "all:\n\ttouch bpf_testmod.ko\n\nclean:\n" > bpf_testmod/Makefile -printf "all:\n\ttouch bpf_test_no_cfi.ko\n\nclean:\n" > bpf_test_no_cfi/Makefile - diff --git a/ci/vmtest/prepare-selftests-run.sh b/ci/vmtest/prepare-selftests-run.sh index 2934a8e..cee1756 100755 --- a/ci/vmtest/prepare-selftests-run.sh +++ b/ci/vmtest/prepare-selftests-run.sh @@ -36,6 +36,6 @@ if [[ "${KERNEL}" == "5.5.0" ]]; then echo "KERNEL_TEST=test_progs test_progs_no_alu32" >> $GITHUB_ENV fi -mkdir "${GITHUB_WORKSPACE}/selftests" +mkdir -p "${GITHUB_WORKSPACE}/selftests" cp -R "${SELFTESTS_BPF}" "${GITHUB_WORKSPACE}/selftests"