Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

run-vmtest: introduce run-vmtest.env #166

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 5 additions & 9 deletions .github/workflows/kernel-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand All @@ -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 }}
Expand Down
23 changes: 5 additions & 18 deletions .github/workflows/kernel-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,31 +60,18 @@ 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
# booleans are weird in GH.
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 }}
Expand Down
38 changes: 38 additions & 0 deletions ci/vmtest/configs/run-vmtest.env
Original file line number Diff line number Diff line change
@@ -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[*]}")

41 changes: 41 additions & 0 deletions run-vmtest/merge_test_lists.py
Original file line number Diff line number Diff line change
@@ -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)


30 changes: 30 additions & 0 deletions run-vmtest/prepare-bpf-selftests.sh
Original file line number Diff line number Diff line change
@@ -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
27 changes: 16 additions & 11 deletions run-vmtest/run-bpf-selftests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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" ]
Expand All @@ -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}
}
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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

Expand All @@ -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.
Expand Down
17 changes: 12 additions & 5 deletions run-vmtest/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading