blob: 4d6e0e371757292cbd377ba104bfbcb882ac3965 [file] [log] [blame]
Brad Bishop1a4b7ee2018-12-16 17:11:34 -08001SUMMARY = "Kernel selftest for Linux"
2DESCRIPTION = "Kernel selftest for Linux"
Andrew Geissler9aee5002022-03-30 16:27:02 +00003LICENSE = "GPL-2.0-only"
Brad Bishop1a4b7ee2018-12-16 17:11:34 -08004
5LIC_FILES_CHKSUM = "file://../COPYING;md5=bbea815ee2795b2f4230826c0c6b8814"
6
7DEPENDS = "rsync-native llvm-native"
8
9# for musl libc
Patrick Williams213cb262021-08-07 19:21:33 -050010SRC_URI:append:libc-musl = "\
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080011 file://userfaultfd.patch \
12 "
13SRC_URI += "file://run-ptest \
14 file://COPYING \
15 "
16
17# now we just test bpf and vm
18# we will append other kernel selftest in the future
19# bpf was added in 4.10 with: https://github.com/torvalds/linux/commit/5aa5bd14c5f8660c64ceedf14a549781be47e53d
20# if you have older kernel than that you need to remove it from PACKAGECONFIG
Patrick Williams213cb262021-08-07 19:21:33 -050021PACKAGECONFIG ??= "firmware"
22PACKAGECONFIG:remove:x86 = "bpf"
23PACKAGECONFIG:remove:arm = "bpf vm"
Andrew Geissler82c905d2020-04-13 13:39:40 -050024# host ptrace.h is used to compile BPF target but mips ptrace.h is needed
25# progs/loop1.c:21:9: error: incomplete definition of type 'struct user_pt_regs'
26# m = PT_REGS_RC(ctx);
Andrew Geisslerd688a012020-09-18 13:36:00 -050027# vm tests need libhugetlbfs starting 5.8+ (https://lkml.org/lkml/2020/4/22/1654)
Patrick Williams213cb262021-08-07 19:21:33 -050028PACKAGECONFIG:remove:qemumips = "bpf vm"
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080029
Andrew Geissler4b7c1152020-11-30 19:55:29 -060030# riscv does not support libhugetlbfs yet
Patrick Williams213cb262021-08-07 19:21:33 -050031PACKAGECONFIG:remove:riscv64 = "vm"
32PACKAGECONFIG:remove:riscv32 = "vm"
Andrew Geissler4b7c1152020-11-30 19:55:29 -060033
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080034PACKAGECONFIG[bpf] = ",,elfutils libcap libcap-ng rsync-native,"
Andrew Geissler82c905d2020-04-13 13:39:40 -050035PACKAGECONFIG[firmware] = ",,libcap, bash"
Andrew Geisslerd688a012020-09-18 13:36:00 -050036PACKAGECONFIG[vm] = ",,libcap libhugetlbfs,libgcc bash"
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080037
38do_patch[depends] += "virtual/kernel:do_shared_workdir"
39
40inherit linux-kernel-base kernel-arch ptest
41
42S = "${WORKDIR}/${BP}"
43
44TEST_LIST = "\
Andrew Geissler82c905d2020-04-13 13:39:40 -050045 ${@bb.utils.filter('PACKAGECONFIG', 'bpf firmware vm', d)} \
Brad Bishope42b3e32020-01-15 22:08:42 -050046 rtc \
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080047"
48
49EXTRA_OEMAKE = '\
50 CROSS_COMPILE=${TARGET_PREFIX} \
51 ARCH=${ARCH} \
52 CC="${CC}" \
Andrew Geissler82c905d2020-04-13 13:39:40 -050053 CLANG="clang -fno-stack-protector -target ${TARGET_ARCH} ${TOOLCHAIN_OPTIONS}" \
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080054 AR="${AR}" \
55 LD="${LD}" \
56 DESTDIR="${D}" \
Andrew Geisslerd688a012020-09-18 13:36:00 -050057 MACHINE="${ARCH}" \
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080058'
59
60KERNEL_SELFTEST_SRC ?= "Makefile \
61 include \
Andrew Geisslerd688a012020-09-18 13:36:00 -050062 kernel \
63 lib \
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080064 tools \
65 scripts \
66 arch \
67 LICENSES \
68"
69
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080070do_compile() {
Andrew Geissler82c905d2020-04-13 13:39:40 -050071 if [ ${@bb.utils.contains('PACKAGECONFIG', 'bpf', 'True', 'False', d)} = 'True' ]; then
Brad Bishop0f291cc2019-09-01 15:16:57 -040072 if [ ${@bb.utils.contains('DEPENDS', 'clang-native', 'True', 'False', d)} = 'False' ]; then
73 bbwarn "clang >= 6.0 with bpf support is needed with kernel 4.18+ so
74either install it and add it to HOSTTOOLS, or add clang-native from meta-clang to dependency"
75 fi
Andrew Geissler82c905d2020-04-13 13:39:40 -050076 fi
Andrew Geissler220dafd2023-10-04 10:18:08 -050077 oe_runmake -C ${S} headers
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080078 for i in ${TEST_LIST}
79 do
80 oe_runmake -C ${S}/tools/testing/selftests/${i}
81 done
82}
83
84do_install() {
85 for i in ${TEST_LIST}
86 do
87 oe_runmake -C ${S}/tools/testing/selftests/${i} INSTALL_PATH=${D}/usr/kernel-selftest/${i} install
Andrew Geisslerd5838332022-05-27 11:33:10 -050088 # Install kselftest-list.txt that required by kselftest runner.
89 oe_runmake -s --no-print-directory COLLECTION=${i} -C ${S}/tools/testing/selftests/${i} emit_tests \
90 >> ${D}/usr/kernel-selftest/kselftest-list.txt
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080091 done
Andrew Geisslerd5838332022-05-27 11:33:10 -050092 # Install kselftest runner.
93 install -m 0755 ${S}/tools/testing/selftests/run_kselftest.sh ${D}/usr/kernel-selftest/
94 cp -R --no-dereference --preserve=mode,links -v ${S}/tools/testing/selftests/kselftest ${D}/usr/kernel-selftest/
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080095 if [ -e ${D}/usr/kernel-selftest/bpf/test_offload.py ]; then
96 sed -i -e '1s,#!.*python3,#! /usr/bin/env python3,' ${D}/usr/kernel-selftest/bpf/test_offload.py
97 fi
98 chown root:root -R ${D}/usr/kernel-selftest
99}
100
101do_configure() {
102 install -D -m 0644 ${WORKDIR}/COPYING ${S}/COPYING
103}
104
105do_patch[prefuncs] += "copy_kselftest_source_from_kernel remove_unrelated"
106python copy_kselftest_source_from_kernel() {
107 sources = (d.getVar("KERNEL_SELFTEST_SRC") or "").split()
108 src_dir = d.getVar("STAGING_KERNEL_DIR")
109 dest_dir = d.getVar("S")
110 bb.utils.mkdirhier(dest_dir)
111 for s in sources:
112 src = oe.path.join(src_dir, s)
113 dest = oe.path.join(dest_dir, s)
114 if os.path.isdir(src):
115 oe.path.copytree(src, dest)
116 else:
117 bb.utils.copyfile(src, dest)
118}
119
120remove_unrelated() {
121 if ${@bb.utils.contains('PACKAGECONFIG','bpf','true','false',d)} ; then
122 test -f ${S}/tools/testing/selftests/bpf/Makefile && \
123 sed -i -e 's/test_pkt_access.*$/\\/' \
124 -e 's/test_pkt_md_access.*$/\\/' \
125 -e 's/sockmap_verdict_prog.*$/\\/' \
126 ${S}/tools/testing/selftests/bpf/Makefile || \
127 bberror "Your kernel is probably older than 4.10 and doesn't have tools/testing/selftests/bpf/Makefile file from https://github.com/torvalds/linux/commit/5aa5bd14c5f8660c64ceedf14a549781be47e53d, disable bpf PACKAGECONFIG"
128 fi
129}
130
131PACKAGE_ARCH = "${MACHINE_ARCH}"
132
133INHIBIT_PACKAGE_DEBUG_SPLIT="1"
Patrick Williams213cb262021-08-07 19:21:33 -0500134FILES:${PN} += "/usr/kernel-selftest"
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800135
Andrew Geisslerd5838332022-05-27 11:33:10 -0500136RDEPENDS:${PN} += "python3 perl"
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800137# tools/testing/selftests/vm/Makefile doesn't respect LDFLAGS and tools/testing/selftests/Makefile explicitly overrides to empty
Patrick Williams213cb262021-08-07 19:21:33 -0500138INSANE_SKIP:${PN} += "ldflags"
Brad Bishop26bdd442019-08-16 17:08:17 -0400139
Brad Bishop0f291cc2019-09-01 15:16:57 -0400140SECURITY_CFLAGS = ""
Patrick Williams213cb262021-08-07 19:21:33 -0500141COMPATIBLE_HOST:libc-musl = 'null'
Brad Bishop5f78ea12019-09-10 07:20:03 -0400142
Brad Bishopdec060e2019-09-23 08:01:31 -0400143# It has native clang/llvm dependency, poky distro is reluctant to include them as deps
144# this helps with world builds on AB
145EXCLUDE_FROM_WORLD = "1"