blob: fb4534dca82570386fc4269e33a3874d7ba22317 [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
21PACKAGECONFIG ??= "bpf vm"
22PACKAGECONFIG_remove_x86 = "bpf"
23PACKAGECONFIG_remove_arm = "bpf"
24
25PACKAGECONFIG[bpf] = ",,elfutils libcap libcap-ng rsync-native,"
26PACKAGECONFIG[vm] = ",,libcap,libgcc bash"
27
28do_patch[depends] += "virtual/kernel:do_shared_workdir"
29
30inherit linux-kernel-base kernel-arch ptest
31
32S = "${WORKDIR}/${BP}"
33
34TEST_LIST = "\
35 ${@bb.utils.filter('PACKAGECONFIG', 'bpf vm', d)} \
36"
37
38EXTRA_OEMAKE = '\
39 CROSS_COMPILE=${TARGET_PREFIX} \
40 ARCH=${ARCH} \
41 CC="${CC}" \
Brad Bishop0f291cc2019-09-01 15:16:57 -040042 CLANG="clang -fno-stack-protector" \
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080043 AR="${AR}" \
44 LD="${LD}" \
45 DESTDIR="${D}" \
46'
47
48KERNEL_SELFTEST_SRC ?= "Makefile \
49 include \
50 tools \
51 scripts \
52 arch \
53 LICENSES \
54"
55
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080056do_compile() {
Brad Bishop0f291cc2019-09-01 15:16:57 -040057 if [ ${@bb.utils.contains('DEPENDS', 'clang-native', 'True', 'False', d)} = 'False' ]; then
58 bbwarn "clang >= 6.0 with bpf support is needed with kernel 4.18+ so
59either install it and add it to HOSTTOOLS, or add clang-native from meta-clang to dependency"
60 fi
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080061 for i in ${TEST_LIST}
62 do
63 oe_runmake -C ${S}/tools/testing/selftests/${i}
64 done
65}
66
67do_install() {
68 for i in ${TEST_LIST}
69 do
70 oe_runmake -C ${S}/tools/testing/selftests/${i} INSTALL_PATH=${D}/usr/kernel-selftest/${i} install
71 done
72 if [ -e ${D}/usr/kernel-selftest/bpf/test_offload.py ]; then
73 sed -i -e '1s,#!.*python3,#! /usr/bin/env python3,' ${D}/usr/kernel-selftest/bpf/test_offload.py
74 fi
75 chown root:root -R ${D}/usr/kernel-selftest
76}
77
78do_configure() {
79 install -D -m 0644 ${WORKDIR}/COPYING ${S}/COPYING
80}
81
82do_patch[prefuncs] += "copy_kselftest_source_from_kernel remove_unrelated"
83python copy_kselftest_source_from_kernel() {
84 sources = (d.getVar("KERNEL_SELFTEST_SRC") or "").split()
85 src_dir = d.getVar("STAGING_KERNEL_DIR")
86 dest_dir = d.getVar("S")
87 bb.utils.mkdirhier(dest_dir)
88 for s in sources:
89 src = oe.path.join(src_dir, s)
90 dest = oe.path.join(dest_dir, s)
91 if os.path.isdir(src):
92 oe.path.copytree(src, dest)
93 else:
94 bb.utils.copyfile(src, dest)
95}
96
97remove_unrelated() {
98 if ${@bb.utils.contains('PACKAGECONFIG','bpf','true','false',d)} ; then
99 test -f ${S}/tools/testing/selftests/bpf/Makefile && \
100 sed -i -e 's/test_pkt_access.*$/\\/' \
101 -e 's/test_pkt_md_access.*$/\\/' \
102 -e 's/sockmap_verdict_prog.*$/\\/' \
103 ${S}/tools/testing/selftests/bpf/Makefile || \
104 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"
105 fi
106}
107
108PACKAGE_ARCH = "${MACHINE_ARCH}"
109
110INHIBIT_PACKAGE_DEBUG_SPLIT="1"
111FILES_${PN} += "/usr/kernel-selftest"
112
113RDEPENDS_${PN} += "python3"
114# tools/testing/selftests/vm/Makefile doesn't respect LDFLAGS and tools/testing/selftests/Makefile explicitly overrides to empty
115INSANE_SKIP_${PN} += "ldflags"
Brad Bishop26bdd442019-08-16 17:08:17 -0400116
Brad Bishop0f291cc2019-09-01 15:16:57 -0400117SECURITY_CFLAGS = ""
Brad Bishop5f78ea12019-09-10 07:20:03 -0400118COMPATIBLE_HOST_libc-musl = 'null'
119