blob: 01f185adbae41ceca5a13a8eaa012b4b2a0535e8 [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"
Andrew Geissler20137392023-10-12 04:59:14 -060022# bpf needs working clang compiler anyway
23PACKAGECONFIG:append:toolchain-clang:x86-64 = " bpf"
Patrick Williams213cb262021-08-07 19:21:33 -050024PACKAGECONFIG:remove:x86 = "bpf"
25PACKAGECONFIG:remove:arm = "bpf vm"
Andrew Geissler82c905d2020-04-13 13:39:40 -050026# host ptrace.h is used to compile BPF target but mips ptrace.h is needed
27# progs/loop1.c:21:9: error: incomplete definition of type 'struct user_pt_regs'
28# m = PT_REGS_RC(ctx);
Andrew Geisslerd688a012020-09-18 13:36:00 -050029# vm tests need libhugetlbfs starting 5.8+ (https://lkml.org/lkml/2020/4/22/1654)
Patrick Williams213cb262021-08-07 19:21:33 -050030PACKAGECONFIG:remove:qemumips = "bpf vm"
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080031
Andrew Geissler4b7c1152020-11-30 19:55:29 -060032# riscv does not support libhugetlbfs yet
Andrew Geissler20137392023-10-12 04:59:14 -060033PACKAGECONFIG:remove:riscv64 = "bpf vm"
34PACKAGECONFIG:remove:riscv32 = "bpf vm"
Andrew Geissler4b7c1152020-11-30 19:55:29 -060035
Andrew Geissler20137392023-10-12 04:59:14 -060036PACKAGECONFIG[bpf] = ",,elfutils elfutils-native libcap libcap-ng rsync-native python3-docutils-native,"
Andrew Geissler82c905d2020-04-13 13:39:40 -050037PACKAGECONFIG[firmware] = ",,libcap, bash"
Andrew Geisslerd688a012020-09-18 13:36:00 -050038PACKAGECONFIG[vm] = ",,libcap libhugetlbfs,libgcc bash"
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080039
40do_patch[depends] += "virtual/kernel:do_shared_workdir"
Andrew Geissler20137392023-10-12 04:59:14 -060041do_compile[depends] += "virtual/kernel:do_install"
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080042
Andrew Geissler20137392023-10-12 04:59:14 -060043inherit linux-kernel-base module-base kernel-arch ptest siteinfo
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080044
45S = "${WORKDIR}/${BP}"
46
Andrew Geissler20137392023-10-12 04:59:14 -060047DEBUG_PREFIX_MAP:remove = "-fcanon-prefix-map"
48
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080049TEST_LIST = "\
Andrew Geissler82c905d2020-04-13 13:39:40 -050050 ${@bb.utils.filter('PACKAGECONFIG', 'bpf firmware vm', d)} \
Brad Bishope42b3e32020-01-15 22:08:42 -050051 rtc \
Patrick Williams73bd93f2024-02-20 08:07:48 -060052 ptp \
53 timers \
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080054"
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080055EXTRA_OEMAKE = '\
56 CROSS_COMPILE=${TARGET_PREFIX} \
57 ARCH=${ARCH} \
58 CC="${CC}" \
59 AR="${AR}" \
60 LD="${LD}" \
Andrew Geissler20137392023-10-12 04:59:14 -060061 CLANG="clang -fno-stack-protector -target ${TARGET_ARCH} ${TOOLCHAIN_OPTIONS} -isystem ${S} -D__WORDSIZE=\'64\' -Wno-error=unused-command-line-argument" \
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080062 DESTDIR="${D}" \
Andrew Geissler20137392023-10-12 04:59:14 -060063 V=1 \
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080064'
Andrew Geissler20137392023-10-12 04:59:14 -060065EXTRA_OEMAKE:append:toolchain-clang = "\
66 LLVM=1 CONFIG_CC_IS_GCC= CONFIG_CC_IS_CLANG=y CONFIG_CC_IMPLICIT_FALLTHROUGH= \
67 HOSTCC="clang -unwindlib=libgcc -rtlib=libgcc -stdlib=libstdc++ ${BUILD_CFLAGS} ${BUILD_LDFLAGS} -Wno-error=unused-command-line-argument" \
68 HOSTLD="clang ${BUILD_LDFLAGS} -unwindlib=libgcc -rtlib=libgcc -stdlib=libstdc++" \
69"
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080070
71KERNEL_SELFTEST_SRC ?= "Makefile \
72 include \
Andrew Geisslerd688a012020-09-18 13:36:00 -050073 kernel \
74 lib \
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080075 tools \
76 scripts \
77 arch \
78 LICENSES \
79"
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080080do_compile() {
Andrew Geissler82c905d2020-04-13 13:39:40 -050081 if [ ${@bb.utils.contains('PACKAGECONFIG', 'bpf', 'True', 'False', d)} = 'True' ]; then
Brad Bishop0f291cc2019-09-01 15:16:57 -040082 if [ ${@bb.utils.contains('DEPENDS', 'clang-native', 'True', 'False', d)} = 'False' ]; then
83 bbwarn "clang >= 6.0 with bpf support is needed with kernel 4.18+ so
84either install it and add it to HOSTTOOLS, or add clang-native from meta-clang to dependency"
85 fi
Andrew Geissler82c905d2020-04-13 13:39:40 -050086 fi
Andrew Geissler20137392023-10-12 04:59:14 -060087 mkdir -p ${S}/include/config ${S}/bits
88 install -Dm 0644 ${STAGING_KERNEL_BUILDDIR}/.config ${S}/include/config/auto.conf
89 if [ "${SITEINFO_BITS}" != "32" ]; then
90 for f in long-double endianness floatn struct_rwlock; do
91 cp ${RECIPE_SYSROOT}${includedir}/bits/$f-64.h ${S}/bits/$f-32.h
92 done
93 fi
Andrew Geissler220dafd2023-10-04 10:18:08 -050094 oe_runmake -C ${S} headers
Andrew Geissler20137392023-10-12 04:59:14 -060095 sed -i -e 's|^all: docs|all:|' ${S}/tools/testing/selftests/bpf/Makefile
96 sed -i -e '/mrecord-mcount/d' ${S}/Makefile
97 sed -i -e '/Wno-alloc-size-larger-than/d' ${S}/Makefile
Patrick Williams705982a2024-01-12 09:51:57 -060098 sed -i -e '/Wno-alloc-size-larger-than/d' ${S}/scripts/Makefile.*
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080099 for i in ${TEST_LIST}
100 do
101 oe_runmake -C ${S}/tools/testing/selftests/${i}
102 done
103}
104
105do_install() {
106 for i in ${TEST_LIST}
107 do
108 oe_runmake -C ${S}/tools/testing/selftests/${i} INSTALL_PATH=${D}/usr/kernel-selftest/${i} install
Andrew Geisslerd5838332022-05-27 11:33:10 -0500109 # Install kselftest-list.txt that required by kselftest runner.
110 oe_runmake -s --no-print-directory COLLECTION=${i} -C ${S}/tools/testing/selftests/${i} emit_tests \
111 >> ${D}/usr/kernel-selftest/kselftest-list.txt
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800112 done
Andrew Geisslerd5838332022-05-27 11:33:10 -0500113 # Install kselftest runner.
114 install -m 0755 ${S}/tools/testing/selftests/run_kselftest.sh ${D}/usr/kernel-selftest/
115 cp -R --no-dereference --preserve=mode,links -v ${S}/tools/testing/selftests/kselftest ${D}/usr/kernel-selftest/
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800116 if [ -e ${D}/usr/kernel-selftest/bpf/test_offload.py ]; then
117 sed -i -e '1s,#!.*python3,#! /usr/bin/env python3,' ${D}/usr/kernel-selftest/bpf/test_offload.py
118 fi
119 chown root:root -R ${D}/usr/kernel-selftest
120}
121
122do_configure() {
123 install -D -m 0644 ${WORKDIR}/COPYING ${S}/COPYING
124}
125
126do_patch[prefuncs] += "copy_kselftest_source_from_kernel remove_unrelated"
127python copy_kselftest_source_from_kernel() {
128 sources = (d.getVar("KERNEL_SELFTEST_SRC") or "").split()
129 src_dir = d.getVar("STAGING_KERNEL_DIR")
130 dest_dir = d.getVar("S")
131 bb.utils.mkdirhier(dest_dir)
132 for s in sources:
133 src = oe.path.join(src_dir, s)
134 dest = oe.path.join(dest_dir, s)
135 if os.path.isdir(src):
136 oe.path.copytree(src, dest)
137 else:
138 bb.utils.copyfile(src, dest)
139}
140
141remove_unrelated() {
142 if ${@bb.utils.contains('PACKAGECONFIG','bpf','true','false',d)} ; then
143 test -f ${S}/tools/testing/selftests/bpf/Makefile && \
144 sed -i -e 's/test_pkt_access.*$/\\/' \
145 -e 's/test_pkt_md_access.*$/\\/' \
146 -e 's/sockmap_verdict_prog.*$/\\/' \
147 ${S}/tools/testing/selftests/bpf/Makefile || \
148 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"
149 fi
150}
151
152PACKAGE_ARCH = "${MACHINE_ARCH}"
153
154INHIBIT_PACKAGE_DEBUG_SPLIT="1"
Patrick Williams213cb262021-08-07 19:21:33 -0500155FILES:${PN} += "/usr/kernel-selftest"
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800156
Andrew Geissler20137392023-10-12 04:59:14 -0600157RDEPENDS:${PN} += "python3 perl perl-module-io-handle"
Patrick Williams73bd93f2024-02-20 08:07:48 -0600158
159INSANE_SKIP:${PN} += "libdir"
Brad Bishop26bdd442019-08-16 17:08:17 -0400160
Brad Bishop0f291cc2019-09-01 15:16:57 -0400161SECURITY_CFLAGS = ""
Patrick Williams213cb262021-08-07 19:21:33 -0500162COMPATIBLE_HOST:libc-musl = 'null'
Brad Bishop5f78ea12019-09-10 07:20:03 -0400163
Brad Bishopdec060e2019-09-23 08:01:31 -0400164# It has native clang/llvm dependency, poky distro is reluctant to include them as deps
165# this helps with world builds on AB
166EXCLUDE_FROM_WORLD = "1"