blob: 3687c267e12a42586c1c4b66bdd295be9c6d7e28 [file] [log] [blame]
Brad Bishop1a4b7ee2018-12-16 17:11:34 -08001SUMMARY = "Kernel selftest for Linux"
2DESCRIPTION = "Kernel selftest for Linux"
3LICENSE = "GPLv2"
4
5LIC_FILES_CHKSUM = "file://../COPYING;md5=bbea815ee2795b2f4230826c0c6b8814"
6
7DEPENDS = "rsync-native llvm-native"
8
9# for musl libc
10SRC_URI_append_libc-musl = "\
11 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
Andrew Geissler82c905d2020-04-13 13:39:40 -050021PACKAGECONFIG ??= "bpf firmware vm"
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080022PACKAGECONFIG_remove_x86 = "bpf"
23PACKAGECONFIG_remove_arm = "bpf"
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);
27PACKAGECONFIG_remove_qemumips = "bpf"
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080028
29PACKAGECONFIG[bpf] = ",,elfutils libcap libcap-ng rsync-native,"
Andrew Geissler82c905d2020-04-13 13:39:40 -050030PACKAGECONFIG[firmware] = ",,libcap, bash"
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080031PACKAGECONFIG[vm] = ",,libcap,libgcc bash"
32
33do_patch[depends] += "virtual/kernel:do_shared_workdir"
34
35inherit linux-kernel-base kernel-arch ptest
36
37S = "${WORKDIR}/${BP}"
38
39TEST_LIST = "\
Andrew Geissler82c905d2020-04-13 13:39:40 -050040 ${@bb.utils.filter('PACKAGECONFIG', 'bpf firmware vm', d)} \
Brad Bishope42b3e32020-01-15 22:08:42 -050041 rtc \
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080042"
43
44EXTRA_OEMAKE = '\
45 CROSS_COMPILE=${TARGET_PREFIX} \
46 ARCH=${ARCH} \
47 CC="${CC}" \
Andrew Geissler82c905d2020-04-13 13:39:40 -050048 CLANG="clang -fno-stack-protector -target ${TARGET_ARCH} ${TOOLCHAIN_OPTIONS}" \
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080049 AR="${AR}" \
50 LD="${LD}" \
51 DESTDIR="${D}" \
52'
53
54KERNEL_SELFTEST_SRC ?= "Makefile \
55 include \
56 tools \
57 scripts \
58 arch \
59 LICENSES \
60"
61
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080062do_compile() {
Andrew Geissler82c905d2020-04-13 13:39:40 -050063 if [ ${@bb.utils.contains('PACKAGECONFIG', 'bpf', 'True', 'False', d)} = 'True' ]; then
Brad Bishop0f291cc2019-09-01 15:16:57 -040064 if [ ${@bb.utils.contains('DEPENDS', 'clang-native', 'True', 'False', d)} = 'False' ]; then
65 bbwarn "clang >= 6.0 with bpf support is needed with kernel 4.18+ so
66either install it and add it to HOSTTOOLS, or add clang-native from meta-clang to dependency"
67 fi
Andrew Geissler82c905d2020-04-13 13:39:40 -050068 fi
69
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080070 for i in ${TEST_LIST}
71 do
72 oe_runmake -C ${S}/tools/testing/selftests/${i}
73 done
74}
75
76do_install() {
77 for i in ${TEST_LIST}
78 do
79 oe_runmake -C ${S}/tools/testing/selftests/${i} INSTALL_PATH=${D}/usr/kernel-selftest/${i} install
80 done
81 if [ -e ${D}/usr/kernel-selftest/bpf/test_offload.py ]; then
82 sed -i -e '1s,#!.*python3,#! /usr/bin/env python3,' ${D}/usr/kernel-selftest/bpf/test_offload.py
83 fi
84 chown root:root -R ${D}/usr/kernel-selftest
85}
86
87do_configure() {
88 install -D -m 0644 ${WORKDIR}/COPYING ${S}/COPYING
89}
90
91do_patch[prefuncs] += "copy_kselftest_source_from_kernel remove_unrelated"
92python copy_kselftest_source_from_kernel() {
93 sources = (d.getVar("KERNEL_SELFTEST_SRC") or "").split()
94 src_dir = d.getVar("STAGING_KERNEL_DIR")
95 dest_dir = d.getVar("S")
96 bb.utils.mkdirhier(dest_dir)
97 for s in sources:
98 src = oe.path.join(src_dir, s)
99 dest = oe.path.join(dest_dir, s)
100 if os.path.isdir(src):
101 oe.path.copytree(src, dest)
102 else:
103 bb.utils.copyfile(src, dest)
104}
105
106remove_unrelated() {
107 if ${@bb.utils.contains('PACKAGECONFIG','bpf','true','false',d)} ; then
108 test -f ${S}/tools/testing/selftests/bpf/Makefile && \
109 sed -i -e 's/test_pkt_access.*$/\\/' \
110 -e 's/test_pkt_md_access.*$/\\/' \
111 -e 's/sockmap_verdict_prog.*$/\\/' \
112 ${S}/tools/testing/selftests/bpf/Makefile || \
113 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"
114 fi
115}
116
117PACKAGE_ARCH = "${MACHINE_ARCH}"
118
119INHIBIT_PACKAGE_DEBUG_SPLIT="1"
120FILES_${PN} += "/usr/kernel-selftest"
121
122RDEPENDS_${PN} += "python3"
123# tools/testing/selftests/vm/Makefile doesn't respect LDFLAGS and tools/testing/selftests/Makefile explicitly overrides to empty
124INSANE_SKIP_${PN} += "ldflags"
Brad Bishop26bdd442019-08-16 17:08:17 -0400125
Brad Bishop0f291cc2019-09-01 15:16:57 -0400126SECURITY_CFLAGS = ""
Brad Bishop5f78ea12019-09-10 07:20:03 -0400127COMPATIBLE_HOST_libc-musl = 'null'
128
Brad Bishopdec060e2019-09-23 08:01:31 -0400129# It has native clang/llvm dependency, poky distro is reluctant to include them as deps
130# this helps with world builds on AB
131EXCLUDE_FROM_WORLD = "1"
132