Skip to content

Commit

Permalink
run-vmtest@v2: make the scripts more reusable
Browse files Browse the repository at this point in the history
Various changes in the scripts aimed to make run-vmtest action usable
by libbpf/libbpf workflows:

* Change how ALLOWLIST and DENYLIST are set up. A script executing in
  qemu (vmtest) is now expecting a single $ALLOWLIST_FILE and
  $DENYLIST_FILE which are parsed by read_lists as usual. This change
  makes it easier for an action caller to modify the lists, as they are
  often composed from a number of files.

* Update vmtest init command (executed in qemu before the tests), to
  create a link from /boot to vmlinux being tested. This is necessary
  when older kernels are tested.

* Allow some env variables to be defined outside of the scripts to
  give the caller more control over the action. That is, before
  setting a default value, check if the variable is set.

* Remove env vars like $THISDIR, $PROJECT_NAME etc. in favor of
  $GITHUB_ACTION_PATH, $GITHUB_WORKSPACE and $KERNEL_ROOT

* Move selftests running scripts from ci/vmtest to run-vmtest, so that
  they are local to the action

Signed-off-by: Ihor Solodrai <ihor.solodrai@pm.me>
  • Loading branch information
theihor committed Nov 5, 2024
1 parent 75cb832 commit ff45d47
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 56 deletions.
21 changes: 6 additions & 15 deletions build-selftests/build_selftests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,13 @@

set -euo pipefail

THISDIR="$(cd $(dirname $0) && pwd)"

source "${THISDIR}"/../helpers.sh
source "${GITHUB_ACTION_PATH}/../helpers.sh"

TARGET_ARCH="$1"
KERNEL="$2"
TOOLCHAIN="$3"
export KBUILD_OUTPUT="$4"
VMLINUX_H=${VMLINUX_H:-}

ARCH="$(platform_to_kernel_arch ${TARGET_ARCH})"
CROSS_COMPILE=""
Expand All @@ -26,19 +25,11 @@ fi

foldable start build_selftests "Building selftests with $TOOLCHAIN"

PREPARE_SELFTESTS_SCRIPT=${THISDIR}/prepare_selftests-${KERNEL}.sh
PREPARE_SELFTESTS_SCRIPT=$(find $GITHUB_WORKSPACE -name prepare_selftests-${KERNEL}.sh)
if [ -f "${PREPARE_SELFTESTS_SCRIPT}" ]; then
(cd "${REPO_ROOT}/${REPO_PATH}/tools/testing/selftests/bpf" && ${PREPARE_SELFTESTS_SCRIPT})
fi

if [[ "${KERNEL}" = 'LATEST' ]]; then
VMLINUX_H=
else
VMLINUX_H=${THISDIR}/vmlinux.h
(cd "${KERNEL_ROOT}/tools/testing/selftests/bpf" && ${PREPARE_SELFTESTS_SCRIPT})
fi

cd ${REPO_ROOT}/${REPO_PATH}

MAKE_OPTS=$(cat <<EOF
ARCH=${ARCH}
CROSS_COMPILE=${CROSS_COMPILE}
Expand All @@ -50,10 +41,10 @@ MAKE_OPTS=$(cat <<EOF
EOF
)
SELF_OPTS=$(cat <<EOF
-C ${REPO_ROOT}/${REPO_PATH}/tools/testing/selftests/bpf
-C ${KERNEL_ROOT}/tools/testing/selftests/bpf
EOF
)
make ${MAKE_OPTS} headers
make ${MAKE_OPTS} -C ${KERNEL_ROOT} headers
make ${MAKE_OPTS} ${SELF_OPTS} clean
make ${MAKE_OPTS} ${SELF_OPTS} -j $(kernel_build_make_jobs)

Expand Down
2 changes: 1 addition & 1 deletion patch-kernel/patch_kernel.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ DIFF_DIR=$1
for ext in diff patch; do
if ls ${DIFF_DIR}/*.${ext} 1>/dev/null 2>&1; then
for file in ${DIFF_DIR}/*.${ext}; do
if patch --dry-run -p1 -s < "${file}" 2>/dev/null; then
if patch --dry-run -N --silent -p1 -s < "${file}" 2>/dev/null; then
patch -s -p1 < "${file}" 2>/dev/null
echo "Successfully applied ${file}!"
else
Expand Down
File renamed without changes.
46 changes: 16 additions & 30 deletions ci/vmtest/vmtest_selftests.sh → run-vmtest/run-bpf-selftests.sh
Original file line number Diff line number Diff line change
@@ -1,40 +1,26 @@
#!/bin/bash

# run_selftest.sh will run the tests within /${PROJECT_NAME}/selftests/bpf
# If no specific test names are given, all test will be ran, otherwise, it will
# run the test passed as parameters.
# There is 2 ways to pass test names.
# This script runs the tests within ${GITHUB_WORKSPACE}/selftests/bpf
# If no specific test names are given, all test runners will be
# executed. Otherwise, executed runners passed as parameters.
# There are 2 ways to pass test names.
# 1) command-line arguments to this script
# 2) a comma-separated list of test names passed as `run_tests` boot parameters.
# test names passed as any of those methods will be ran.
# 2) a comma-separated list of test names passed as `run_tests` boot
# parameters.

set -euo pipefail

source "$(cd "$(dirname "$0")" && pwd)/helpers.sh"
source "${GITHUB_ACTION_PATH}/helpers.sh"

ARCH=$(uname -m)
DEPLOYMENT=$(if [[ "$GITHUB_REPOSITORY" == "kernel-patches/bpf" ]]; then echo "prod"; else echo "rc"; fi)

STATUS_FILE=/mnt/vmtest/exitstatus
OUTPUT_DIR=/mnt/vmtest

WORKING_DIR="/${PROJECT_NAME}"
BPF_SELFTESTS_DIR="${WORKING_DIR}/selftests/bpf"
VMTEST_CONFIGS_PATH="${WORKING_DIR}/ci/vmtest/configs"

DENYLIST=$(read_lists \
"$BPF_SELFTESTS_DIR/DENYLIST" \
"$BPF_SELFTESTS_DIR/DENYLIST.${ARCH}" \
"$VMTEST_CONFIGS_PATH/DENYLIST" \
"$VMTEST_CONFIGS_PATH/DENYLIST.${ARCH}" \
"$VMTEST_CONFIGS_PATH/DENYLIST.${DEPLOYMENT}" \
)
ALLOWLIST=$(read_lists \
"$BPF_SELFTESTS_DIR/ALLOWLIST" \
"$BPF_SELFTESTS_DIR/ALLOWLIST.${ARCH}" \
"$VMTEST_CONFIGS_PATH/ALLOWLIST" \
"$VMTEST_CONFIGS_PATH/ALLOWLIST.${ARCH}" \
)

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}")

declare -a TEST_NAMES=()

Expand Down Expand Up @@ -168,7 +154,7 @@ foldable end kernel_config
echo "DENYLIST: ${DENYLIST}"
echo "ALLOWLIST: ${ALLOWLIST}"
cd ${PROJECT_NAME}/selftests/bpf
cd ${GITHUB_WORKSPACE}/selftests/bpf
# populate TEST_NAMES
read_test_names "$@"
Expand Down
File renamed without changes.
27 changes: 17 additions & 10 deletions run-vmtest/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,21 @@ if [[ -z "${VMLINUZ}" || ! -f "${VMLINUZ}" ]]; then
export VMLINUZ=$(realpath ${KERNEL_ROOT}/${image_name})
fi

RUN_BPFTOOL_CHECKS=
RUN_BPFTOOL_CHECKS=${RUN_BPFTOOL_CHECKS:-}
if [[ -z "${RUN_BPFTOOL_CHECKS}" \
&& "${KERNEL}" = 'LATEST' \
&& "$KERNEL_TEST" != "sched_ext" ]];
then
RUN_BPFTOOL_CHECKS=true
fi

if [[ "$KERNEL_TEST" != "sched_ext" ]]; then
VMTEST_SCRIPT="${GITHUB_ACTION_PATH}/../ci/vmtest/vmtest_selftests.sh"
if [[ "${KERNEL}" = 'LATEST' ]]; then
RUN_BPFTOOL_CHECKS=true
fi
VMTEST_SCRIPT=${VMTEST_SCRIPT:-}
if [[ -z "$VMTEST_SCRIPT" \
&& "$KERNEL_TEST" != "sched_ext" ]];
then
VMTEST_SCRIPT="${GITHUB_ACTION_PATH}/run-bpf-selftests.sh"
else
VMTEST_SCRIPT="${GITHUB_ACTION_PATH}/../ci/vmtest/sched_ext_selftests.sh"
VMTEST_SCRIPT="${GITHUB_ACTION_PATH}/run-scx-selftests.sh"
fi

# clear exitstatus file
Expand Down Expand Up @@ -52,9 +58,10 @@ foldable start vmtest "Starting virtual machine..."
# Tests may be comma-separated. vmtest_selftest expect them to come from CLI space-separated.
T=$(echo ${KERNEL_TEST} | tr -s ',' ' ')
vmtest -k "${VMLINUZ}" --kargs "panic=-1 sysctl.vm.panic_on_oom=1" \
"/bin/mount bpffs /sys/fs/bpf -t bpf && \
ip link set lo up && \
cd '${GITHUB_WORKSPACE}' && \
"ln -sf /mnt/vmtest/vmlinux /boot/vmlinux-$(uname -r) && \
/bin/mount bpffs /sys/fs/bpf -t bpf && \
ip link set lo up && \
cd '${GITHUB_WORKSPACE}' && \
${VMTEST_SCRIPT} ${T}"

foldable end vmtest
Expand Down

0 comments on commit ff45d47

Please sign in to comment.