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: action to test bpf using danobi/vmtest #117

Merged
merged 3 commits into from
Jan 25, 2024
Merged
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
6 changes: 3 additions & 3 deletions .github/workflows/scripts_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ on:
- master

jobs:
test_run_qemu:
name: Test run-qemu
test_run_vmtest:
name: Test run-vmtest
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Test print_test_summary
run: ./run-qemu/print_test_summary.py -j run-qemu/fixtures/test_progs.json -s "${GITHUB_STEP_SUMMARY}"
run: ./run-vmtest/print_test_summary.py -j run-vmtest/fixtures/test_progs.json -s "${GITHUB_STEP_SUMMARY}"
2 changes: 1 addition & 1 deletion run-qemu/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ then
if [ $? ]
then
## Job summary
"${GITHUB_ACTION_PATH}/print_test_summary.py" -s "${GITHUB_STEP_SUMMARY}" -j "${KERNEL_TEST}.json"
"${GITHUB_ACTION_PATH}/../run-vmtest/print_test_summary.py" -s "${GITHUB_STEP_SUMMARY}" -j "${KERNEL_TEST}.json"
fi
fi

Expand Down
64 changes: 64 additions & 0 deletions run-vmtest/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
name: 'run vmtest'
description: 'Run vmtest and print summary'
inputs:
arch:
description: 'arch'
required: true
img:
description: 'img path'
required: true
vmlinuz:
description: 'vmlinuz path'
required: true
kernel-root:
description: 'kernel source dir'
default: '.'
max-cpu:
description: 'Maximum number of CPU allocated to a VM (regardless of number of CPUs available on the host). Default is unset, e.g it will default to the number of CPU on the host.'
default: ''
kernel-test:
description: 'Test to run'
default: ''
output-dir:
description: |
Some sub-commands produce output dir within VM file system (/command_output/).
If this option is set that dir's content would be copied to corresponding location.
default: ''
runs:
using: "composite"
steps:
- name: Find kernel
id: find-kernel
shell: bash
run: |
BUILDDIR=$(realpath kbuild-output)
vmlinuz="$BUILDDIR/$(KBUILD_OUTPUT="${BUILDDIR}" make -C "${{ inputs.kernel-root }}" -s image_name)"
cp "$vmlinuz" ${{ inputs.vmlinuz }}
- name: Download vmtest
shell: bash
# FIXME: move to proper release
run: |
curl -L https://github.com/chantra/danobi-vmtest/releases/download/v2.2.0/vmtest-$(uname -m) > /usr/bin/vmtest && chmod 755 /usr/bin/vmtest
- name: install qemu tools and selftest dependencies
shell: bash
run: |
source "${GITHUB_ACTION_PATH}/../helpers.sh"
foldable start install_qemu "Installing QEMU tools"
# need gawk to support `--field-separator`
sudo apt-get update && sudo apt-get install -y cpu-checker qemu-kvm qemu-utils qemu-system-x86 qemu-system-s390x qemu-system-arm qemu-guest-agent \
ethtool keyutils iptables \
gawk
foldable end install_qemu
- name: Run vmtest
shell: bash
env:
VMLINUZ: ${{ inputs.vmlinuz }}
IMG: ${{ inputs.img }}
KERNEL_ROOT: ${{ inputs.kernel-root }}
MAX_CPU: ${{ inputs.max-cpu }}
KERNEL_TEST: ${{ inputs.kernel-test }}
OUTPUT_DIR: ${{ inputs.output-dir }}
PROJECT_NAME: "/mnt/vmtest"
run: |
${GITHUB_ACTION_PATH}/run.sh

File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
# https://docs.github.com/en/actions/using-workflows/workflow-commands-for-github-actions#adding-a-job-summary
#
# To test the output of the GH test summary:
# python3 run-qemu/print_test_summary.py -j run-qemu/fixtures/test_progs.json -s /dev/stderr > /dev/null
# python3 run-vmtest/print_test_summary.py -j run-vmtest/fixtures/test_progs.json -s /dev/stderr > /dev/null
# To test the output of the console:
# python3 run-qemu/print_test_summary.py -j run-qemu/fixtures/test_progs.json -s /dev/stderr 2> /dev/null
# python3 run-vmtest/print_test_summary.py -j run-vmtest/fixtures/test_progs.json -s /dev/stderr 2> /dev/null

import argparse
import json
Expand Down
80 changes: 80 additions & 0 deletions run-vmtest/run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
#!/bin/bash

set -euo pipefail
trap 'exit 2' ERR

source $(cd $(dirname $0) && pwd)/../helpers.sh

foldable start bpftool_checks "Running bpftool checks..."
bpftool_exitstatus=0

# bpftool checks are aimed at checking type names, documentation, shell
# completion etc. against the current kernel, so only run on LATEST.
if [[ "${KERNEL}" = 'LATEST' ]]; then
# "&& true" does not change the return code (it is not executed if the
# Python script fails), but it prevents the trap on ERR set at the top
# of this file to trigger on failure.
"${REPO_ROOT}/${KERNEL_ROOT}/tools/testing/selftests/bpf/test_bpftool_synctypes.py" && true
bpftool_exitstatus=$?
if [[ $bpftool_exitstatus -eq 0 ]]; then
echo "bpftool checks passed successfully."
else
echo "bpftool checks returned ${bpftool_exitstatus}."
fi
else
echo "bpftool checks skipped."
fi

bpftool_exitstatus="bpftool:${bpftool_exitstatus}"
foldable end bpftool_checks

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 ',' ' ')
# HACK: We need to unmount /tmp to access /tmp from the container....
vmtest -k "${VMLINUZ}" --kargs "panic=-1 sysctl.vm.panic_on_oom=1" "umount /tmp && \
/bin/mount bpffs /sys/fs/bpf -t bpf && \
ip link set lo up && \
cd '${GITHUB_WORKSPACE}' && \
./ci/vmtest/vmtest_selftests.sh ${T}"

foldable end vmtest

foldable start collect_status "Collecting exit status"

exitfile="${bpftool_exitstatus}\n"
exitfile+="$(cat exitstatus 2>/dev/null)"
exitstatus="$(echo -e "$exitfile" | awk --field-separator ':' \
'BEGIN { s=0 } { if ($2) {s=1} } END { print s }')"

if [[ "$exitstatus" =~ ^[0-9]+$ ]]; then
printf '\nTests exit status: %s\n' "$exitstatus" >&2
else
printf '\nCould not read tests exit status ("%s")\n' "$exitstatus" >&2
exitstatus=1
fi

foldable end collect_status

# Try to collect json summary from VM
if [[ -n ${KERNEL_TEST} && ${KERNEL_TEST} =~ test_progs* ]]
then
## Job summary
"${GITHUB_ACTION_PATH}/print_test_summary.py" -s "${GITHUB_STEP_SUMMARY}" -j "${KERNEL_TEST}.json"
fi

# Final summary - Don't use a fold, keep it visible
echo -e "\033[1;33mTest Results:\033[0m"
echo -e "$exitfile" | while read result; do
testgroup=${result%:*}
status=${result#*:}
# Print final result for each group of tests
if [[ "$status" -eq 0 ]]; then
printf "%20s: \033[1;32mPASS\033[0m\n" "$testgroup"
else
printf "%20s: \033[1;31mFAIL\033[0m (returned %s)\n" "$testgroup" "$status"
fi
done

exit "$exitstatus"
Loading