1
1
#! /bin/bash
2
2
# SPDX-License-Identifier: GPL-2.0
3
3
4
- set -u
5
4
set -e
6
5
7
6
# This script currently only works for the following platforms,
8
7
# as it is based on the VM image used by the BPF CI, which is
9
8
# available only for these architectures. We can also specify
10
9
# the local rootfs image generated by the following script:
11
10
# https://github.com/libbpf/ci/blob/main/rootfs/mkrootfs_debian.sh
12
- ARCH =" $( uname -m) "
13
- case " ${ARCH } " in
11
+ PLATFORM =" ${PLATFORM :- $ (uname -m)} "
12
+ case " ${PLATFORM } " in
14
13
s390x)
15
14
QEMU_BINARY=qemu-system-s390x
16
15
QEMU_CONSOLE=" ttyS1"
17
- QEMU_FLAGS=(-smp 2)
16
+ HOST_FLAGS=(-smp 2 -enable-kvm)
17
+ CROSS_FLAGS=(-smp 2)
18
18
BZIMAGE=" arch/s390/boot/vmlinux"
19
+ ARCH=" s390"
19
20
;;
20
21
x86_64)
21
22
QEMU_BINARY=qemu-system-x86_64
22
23
QEMU_CONSOLE=" ttyS0,115200"
23
- QEMU_FLAGS=(-cpu host -smp 8)
24
+ HOST_FLAGS=(-cpu host -enable-kvm -smp 8)
25
+ CROSS_FLAGS=(-smp 8)
24
26
BZIMAGE=" arch/x86/boot/bzImage"
27
+ ARCH=" x86"
25
28
;;
26
29
aarch64)
27
30
QEMU_BINARY=qemu-system-aarch64
28
31
QEMU_CONSOLE=" ttyAMA0,115200"
29
- QEMU_FLAGS=(-M virt,gic-version=3 -cpu host -smp 8)
32
+ HOST_FLAGS=(-M virt,gic-version=3 -cpu host -enable-kvm -smp 8)
33
+ CROSS_FLAGS=(-M virt,gic-version=3 -cpu cortex-a76 -smp 8)
30
34
BZIMAGE=" arch/arm64/boot/Image"
35
+ ARCH=" arm64"
31
36
;;
32
37
* )
33
38
echo " Unsupported architecture"
@@ -41,7 +46,7 @@ ROOTFS_IMAGE="root.img"
41
46
OUTPUT_DIR=" $HOME /.bpf_selftests"
42
47
KCONFIG_REL_PATHS=(" tools/testing/selftests/bpf/config"
43
48
" tools/testing/selftests/bpf/config.vm"
44
- " tools/testing/selftests/bpf/config.${ARCH } " )
49
+ " tools/testing/selftests/bpf/config.${PLATFORM } " )
45
50
INDEX_URL=" https://raw.githubusercontent.com/libbpf/ci/master/INDEX"
46
51
NUM_COMPILE_JOBS=" $( nproc) "
47
52
LOG_FILE_BASE=" $( date +" bpf_selftests.%Y-%m-%d_%H-%M-%S" ) "
@@ -61,6 +66,10 @@ tools/testing/selftests/bpf. e.g:
61
66
If no command is specified and a debug shell (-s) is not requested,
62
67
"${DEFAULT_COMMAND} " will be run by default.
63
68
69
+ Using PLATFORM= and CROSS_COMPILE= options will enable cross platform testing:
70
+
71
+ PLATFORM=<platform> CROSS_COMPILE=<toolchain> $0 -- ./test_progs -t test_lsm
72
+
64
73
If you build your kernel using KBUILD_OUTPUT= or O= options, these
65
74
can be passed as environment variables to the script:
66
75
@@ -100,7 +109,7 @@ newest_rootfs_version()
100
109
{
101
110
{
102
111
for file in " ${! URLS[@]} " ; do
103
- if [[ $file =~ ^" ${ARCH } " /libbpf-vmtest-rootfs-(.* )\. tar\. zst$ ]]; then
112
+ if [[ $file =~ ^" ${PLATFORM } " /libbpf-vmtest-rootfs-(.* )\. tar\. zst$ ]]; then
104
113
echo " ${BASH_REMATCH[1]} "
105
114
fi
106
115
done
@@ -112,7 +121,7 @@ download_rootfs()
112
121
populate_url_map
113
122
114
123
local rootfsversion=" $( newest_rootfs_version) "
115
- local file=" ${ARCH } /libbpf-vmtest-rootfs-$rootfsversion .tar.zst"
124
+ local file=" ${PLATFORM } /libbpf-vmtest-rootfs-$rootfsversion .tar.zst"
116
125
117
126
if [[ ! -v URLS[$file ] ]]; then
118
127
echo " $file not found" >&2
@@ -253,12 +262,17 @@ EOF
253
262
exit 1
254
263
fi
255
264
265
+ if [[ " ${PLATFORM} " != " $( uname -m) " ]]; then
266
+ QEMU_FLAGS=(" ${CROSS_FLAGS[@]} " )
267
+ else
268
+ QEMU_FLAGS=(" ${HOST_FLAGS[@]} " )
269
+ fi
270
+
256
271
${QEMU_BINARY} \
257
272
-nodefaults \
258
273
-display none \
259
274
-serial mon:stdio \
260
275
" ${QEMU_FLAGS[@]} " \
261
- -enable-kvm \
262
276
-m 4G \
263
277
-drive file=" ${rootfs_img} " ,format=raw,index=1,media=disk,if=virtio,cache=none \
264
278
-kernel " ${kernel_bzimage} " \
@@ -389,14 +403,20 @@ main()
389
403
390
404
trap ' catch "$?"' EXIT
391
405
406
+ if [[ " ${PLATFORM} " != " $( uname -m) " ]] && [[ -z " ${CROSS_COMPILE} " ]]; then
407
+ echo " Cross-platform testing needs to specify CROSS_COMPILE"
408
+ exit 1
409
+ fi
410
+
392
411
if [[ $# -eq 0 && " ${debug_shell} " == " no" ]]; then
393
412
echo " No command specified, will run ${DEFAULT_COMMAND} in the vm"
394
413
else
395
414
command=" $@ "
396
415
fi
397
416
398
417
local kconfig_file=" ${OUTPUT_DIR} /latest.config"
399
- local make_command=" make -j ${NUM_COMPILE_JOBS} KCONFIG_CONFIG=${kconfig_file} "
418
+ local make_command=" make ARCH=${ARCH} CROSS_COMPILE=${CROSS_COMPILE} \
419
+ -j ${NUM_COMPILE_JOBS} KCONFIG_CONFIG=${kconfig_file} "
400
420
401
421
# Figure out where the kernel is being built.
402
422
# O takes precedence over KBUILD_OUTPUT.
0 commit comments