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