Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
run-vmtest: change allow/denylist handling
Browse files Browse the repository at this point in the history
theihor committed Jan 9, 2025
1 parent 835e83e commit cf9969d
Showing 6 changed files with 909 additions and 133 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/kernel-build.yml
Original file line number Diff line number Diff line change
@@ -114,7 +114,7 @@ jobs:

- if: ${{ env.BUILD_BPF_GCC }}
name: Build GCC for BPF selftests
uses: theihor/libbpf-ci/build-bpf-gcc@bpf-gcc
uses: ./build-bpf-gcc
with:
install-dir: ${{ env.BPF_GCC_INSTALL_DIR }}

14 changes: 9 additions & 5 deletions build-bpf-gcc/build-and-install.sh
Original file line number Diff line number Diff line change
@@ -12,8 +12,12 @@ else
exit 1
fi

test -f $BINUTILS_TARBALL || wget $BINUTILS_URL
test -f $GCC_TARBALL || wget $GCC_URL
foldable start download_tarballs "Downloading $BINUTILS_URL and $GCC_URL"

test -f $BINUTILS_TARBALL || wget -q $BINUTILS_URL
test -f $GCC_TARBALL || wget -q $GCC_URL

foldable end download_tarballs

foldable start build_binutils "Building $BINUTILS_BASENAME"

@@ -27,7 +31,7 @@ if [ ! -f "${INSTALLDIR}/${BINUTILS_BASENAME}.built" ]; then
cd -
fi

foldable end build_binutils "Building $BINUTILS_BASENAME"
foldable end build_binutils

foldable start build_gcc "Building $GCC_BASENAME"

@@ -39,11 +43,11 @@ if [ ! -f "${INSTALLDIR}/${GCC_BASENAME}.built" ]; then
mkdir -p ${GCC_BASENAME}/build-bpf
cd ${GCC_BASENAME}/build-bpf
../configure --target=bpf-unknown-none --prefix=$INSTALLDIR
make -j $(nproc) && make install
make -j$(nproc) && make install
touch ${INSTALLDIR}/${GCC_BASENAME}.built
cd -
fi

foldable end build_gcc "Building $GCC_BASENAME"
foldable end build_gcc

exit 0
943 changes: 830 additions & 113 deletions ci/vmtest/configs/DENYLIST.test_progs-bpf_gcc

Large diffs are not rendered by default.

39 changes: 39 additions & 0 deletions ci/vmtest/merge_test_lists.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#!/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]
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)


11 changes: 8 additions & 3 deletions ci/vmtest/prepare-selftests-run.sh
Original file line number Diff line number Diff line change
@@ -2,17 +2,22 @@

set -euo pipefail

function append_into() {
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
cat "$out" | python3 "$(dirname "$0")/merge_test_lists.py" > "$out"
}

allowlists=(
@@ -24,7 +29,7 @@ allowlists=(
"${VMTEST_CONFIGS}/ALLOWLIST.${KERNEL_TEST}"
)

append_into "${ALLOWLIST_FILE}" "${allowlists[@]}"
merge_test_lists_into "${ALLOWLIST_FILE}" "${allowlists[@]}"

denylists=(
"${SELFTESTS_BPF}/DENYLIST"
@@ -35,6 +40,6 @@ denylists=(
"${VMTEST_CONFIGS}/DENYLIST.${KERNEL_TEST}"
)

append_into "${DENYLIST_FILE}" "${denylists[@]}"
merge_test_lists_into "${DENYLIST_FILE}" "${denylists[@]}"

exit 0
33 changes: 22 additions & 11 deletions run-vmtest/run-bpf-selftests.sh
Original file line number Diff line number Diff line change
@@ -23,16 +23,24 @@ 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}")
if [ -f "${ALLOWLIST_FILE:-}" ]; then
ALLOWLIST_ARG="-a@${ALLOWLIST_FILE}"
else
ALLOWLIST_ARG=
fi

if [ -f "${DENYLIST_FILE:-}" ]; then
DENYLIST_ARG="-d@${DENYLIST_FILE}"
else
DENYLIST_ARG=
fi

test_progs_helper() {
local selftest="test_progs${1}"
local args="$2"

args+=" ${TEST_PROGS_WATCHDOG_TIMEOUT:+-w$TEST_PROGS_WATCHDOG_TIMEOUT}"
args+=" ${ALLOWLIST_ARG} ${DENYLIST_ARG}"

json_file=${selftest/-/_}
if [ "$2" == "-j" ]
@@ -42,11 +50,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}
}
@@ -86,7 +94,6 @@ test_verifier() {
}

test_progs-bpf_gcc() {
echo $(pwd)
test_progs_helper "-bpf_gcc" ""
}

@@ -139,13 +146,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

@@ -157,6 +167,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.

0 comments on commit cf9969d

Please sign in to comment.