2020-05-04 20:46:48 +00:00
|
|
|
#!/bin/bash
|
|
|
|
# Test the current package under a different kernel.
|
|
|
|
# Requires virtme and qemu to be installed.
|
|
|
|
|
|
|
|
set -eu
|
|
|
|
set -o pipefail
|
|
|
|
|
|
|
|
if [[ "${1:-}" = "--in-vm" ]]; then
|
|
|
|
shift
|
|
|
|
|
|
|
|
mount -t bpf bpf /sys/fs/bpf
|
2021-04-14 18:11:13 +00:00
|
|
|
mount -t tracefs tracefs /sys/kernel/debug/tracing
|
2020-05-04 20:46:48 +00:00
|
|
|
export CGO_ENABLED=0
|
2020-08-10 17:43:49 +00:00
|
|
|
export GOFLAGS=-mod=readonly
|
|
|
|
export GOPATH=/run/go-path
|
2021-04-14 18:11:13 +00:00
|
|
|
export GOPROXY=file:///run/go-path/pkg/mod/cache/download
|
|
|
|
export GOSUMDB=off
|
2020-08-10 17:43:49 +00:00
|
|
|
export GOCACHE=/run/go-cache
|
|
|
|
|
|
|
|
if [[ -d "/run/input/bpf" ]]; then
|
2021-04-14 18:11:13 +00:00
|
|
|
export KERNEL_SELFTESTS="/run/input/bpf"
|
2020-08-10 17:43:49 +00:00
|
|
|
fi
|
2020-05-04 20:46:48 +00:00
|
|
|
|
2021-04-14 18:11:13 +00:00
|
|
|
readonly output="${1}"
|
|
|
|
shift
|
|
|
|
|
2020-05-04 20:46:48 +00:00
|
|
|
echo Running tests...
|
2021-04-14 18:11:13 +00:00
|
|
|
go test -v -coverpkg=./... -coverprofile="$output/coverage.txt" -count 1 ./...
|
|
|
|
touch "$output/success"
|
2020-05-04 20:46:48 +00:00
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Pull all dependencies, so that we can run tests without the
|
|
|
|
# vm having network access.
|
2020-08-10 17:43:49 +00:00
|
|
|
go mod download
|
2020-05-04 20:46:48 +00:00
|
|
|
|
|
|
|
# Use sudo if /dev/kvm isn't accessible by the current user.
|
|
|
|
sudo=""
|
|
|
|
if [[ ! -r /dev/kvm || ! -w /dev/kvm ]]; then
|
|
|
|
sudo="sudo"
|
|
|
|
fi
|
|
|
|
readonly sudo
|
|
|
|
|
|
|
|
readonly kernel_version="${1:-}"
|
|
|
|
if [[ -z "${kernel_version}" ]]; then
|
|
|
|
echo "Expecting kernel version as first argument"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
readonly kernel="linux-${kernel_version}.bz"
|
2020-08-10 17:43:49 +00:00
|
|
|
readonly selftests="linux-${kernel_version}-selftests-bpf.bz"
|
|
|
|
readonly input="$(mktemp -d)"
|
2020-05-04 20:46:48 +00:00
|
|
|
readonly output="$(mktemp -d)"
|
2020-08-10 17:43:49 +00:00
|
|
|
readonly tmp_dir="${TMPDIR:-/tmp}"
|
|
|
|
readonly branch="${BRANCH:-master}"
|
2020-05-04 20:46:48 +00:00
|
|
|
|
2020-08-10 17:43:49 +00:00
|
|
|
fetch() {
|
|
|
|
echo Fetching "${1}"
|
|
|
|
wget -nv -N -P "${tmp_dir}" "https://github.com/cilium/ci-kernels/raw/${branch}/${1}"
|
2020-05-04 20:46:48 +00:00
|
|
|
}
|
|
|
|
|
2020-08-10 17:43:49 +00:00
|
|
|
fetch "${kernel}"
|
|
|
|
|
|
|
|
if fetch "${selftests}"; then
|
|
|
|
mkdir "${input}/bpf"
|
|
|
|
tar --strip-components=4 -xjf "${tmp_dir}/${selftests}" -C "${input}/bpf"
|
|
|
|
else
|
|
|
|
echo "No selftests found, disabling"
|
|
|
|
fi
|
|
|
|
|
|
|
|
echo Testing on "${kernel_version}"
|
|
|
|
$sudo virtme-run --kimg "${tmp_dir}/${kernel}" --memory 512M --pwd \
|
2021-04-14 18:11:13 +00:00
|
|
|
--rw \
|
2020-08-10 17:43:49 +00:00
|
|
|
--rwdir=/run/input="${input}" \
|
|
|
|
--rwdir=/run/output="${output}" \
|
|
|
|
--rodir=/run/go-path="$(go env GOPATH)" \
|
|
|
|
--rwdir=/run/go-cache="$(go env GOCACHE)" \
|
2021-04-14 18:11:13 +00:00
|
|
|
--script-sh "PATH=\"$PATH\" $(realpath "$0") --in-vm /run/output" \
|
2020-08-10 17:43:49 +00:00
|
|
|
--qemu-opts -smp 2 # need at least two CPUs for some tests
|
2020-05-04 20:46:48 +00:00
|
|
|
|
|
|
|
if [[ ! -e "${output}/success" ]]; then
|
|
|
|
echo "Test failed on ${kernel_version}"
|
|
|
|
exit 1
|
|
|
|
else
|
|
|
|
echo "Test successful on ${kernel_version}"
|
2021-04-14 18:11:13 +00:00
|
|
|
if [[ -v COVERALLS_TOKEN ]]; then
|
|
|
|
goveralls -coverprofile="${output}/coverage.txt" -service=semaphore -repotoken "$COVERALLS_TOKEN"
|
2020-05-04 20:46:48 +00:00
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
2020-08-10 17:43:49 +00:00
|
|
|
$sudo rm -r "${input}"
|
2020-05-04 20:46:48 +00:00
|
|
|
$sudo rm -r "${output}"
|