xref: /aosp_15_r20/external/libbpf/ci/vmtest/run_selftests.sh (revision f7c14bbac8cf49633f2740db462ea43457973ec4)
1#!/bin/bash
2
3set -euo pipefail
4
5source $(cd $(dirname $0) && pwd)/helpers.sh
6
7ARCH=$(uname -m)
8
9STATUS_FILE=/exitstatus
10
11read_lists() {
12	(for path in "$@"; do
13		if [[ -s "$path" ]]; then
14			cat "$path"
15		fi;
16	done) | cut -d'#' -f1 | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//' | tr -s '\n' ','
17}
18
19test_progs() {
20	if [[ "${KERNEL}" != '4.9.0' ]]; then
21		foldable start test_progs "Testing test_progs"
22		# "&& true" does not change the return code (it is not executed
23		# if the Python script fails), but it prevents exiting on a
24		# failure due to the "set -e".
25		./test_progs ${DENYLIST:+-d"$DENYLIST"} ${ALLOWLIST:+-a"$ALLOWLIST"} && true
26		echo "test_progs:$?" >> "${STATUS_FILE}"
27		foldable end test_progs
28	fi
29}
30
31test_progs_no_alu32() {
32	foldable start test_progs-no_alu32 "Testing test_progs-no_alu32"
33	./test_progs-no_alu32 ${DENYLIST:+-d"$DENYLIST"} ${ALLOWLIST:+-a"$ALLOWLIST"} && true
34	echo "test_progs-no_alu32:$?" >> "${STATUS_FILE}"
35	foldable end test_progs-no_alu32
36}
37
38test_maps() {
39	if [[ "${KERNEL}" == 'latest' ]]; then
40		foldable start test_maps "Testing test_maps"
41		./test_maps && true
42		echo "test_maps:$?" >> "${STATUS_FILE}"
43		foldable end test_maps
44	fi
45}
46
47test_verifier() {
48	if [[ "${KERNEL}" == 'latest' ]]; then
49		foldable start test_verifier "Testing test_verifier"
50		./test_verifier && true
51		echo "test_verifier:$?" >> "${STATUS_FILE}"
52		foldable end test_verifier
53	fi
54}
55
56foldable end vm_init
57
58foldable start kernel_config "Kconfig"
59
60zcat /proc/config.gz
61
62foldable end kernel_config
63
64
65configs_path=/${PROJECT_NAME}/selftests/bpf
66local_configs_path=${PROJECT_NAME}/vmtest/configs
67DENYLIST=$(read_lists \
68	"$configs_path/DENYLIST" \
69	"$configs_path/DENYLIST.${ARCH}" \
70	"$local_configs_path/DENYLIST-${KERNEL}" \
71	"$local_configs_path/DENYLIST-${KERNEL}.${ARCH}" \
72)
73ALLOWLIST=$(read_lists \
74	"$configs_path/ALLOWLIST" \
75	"$configs_path/ALLOWLIST.${ARCH}" \
76	"$local_configs_path/ALLOWLIST-${KERNEL}" \
77	"$local_configs_path/ALLOWLIST-${KERNEL}.${ARCH}" \
78)
79
80echo "DENYLIST: ${DENYLIST}"
81echo "ALLOWLIST: ${ALLOWLIST}"
82
83cd ${PROJECT_NAME}/selftests/bpf
84
85if [ $# -eq 0 ]; then
86	test_progs
87	test_progs_no_alu32
88	# test_maps
89	test_verifier
90else
91	for test_name in "$@"; do
92		"${test_name}"
93	done
94fi
95