blob: 02c56bee60333760035a1cb9d679a07ad289d8dd [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)} \
Brad Bishope42b3e32020-01-15 22:08:42 -050036 rtc \
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080037"
38
39EXTRA_OEMAKE = '\
40 CROSS_COMPILE=${TARGET_PREFIX} \
41 ARCH=${ARCH} \
42 CC="${CC}" \
Brad Bishop0f291cc2019-09-01 15:16:57 -040043 CLANG="clang -fno-stack-protector" \
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080044 AR="${AR}" \
45 LD="${LD}" \
46 DESTDIR="${D}" \
47'
48
49KERNEL_SELFTEST_SRC ?= "Makefile \
50 include \
51 tools \
52 scripts \
53 arch \
54 LICENSES \
55"
56
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080057do_compile() {
Brad Bishop0f291cc2019-09-01 15:16:57 -040058 if [ ${@bb.utils.contains('DEPENDS', 'clang-native', 'True', 'False', d)} = 'False' ]; then
59 bbwarn "clang >= 6.0 with bpf support is needed with kernel 4.18+ so
60either install it and add it to HOSTTOOLS, or add clang-native from meta-clang to dependency"
61 fi
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080062 for i in ${TEST_LIST}
63 do
64 oe_runmake -C ${S}/tools/testing/selftests/${i}
65 done
66}
67
68do_install() {
69 for i in ${TEST_LIST}
70 do
71 oe_runmake -C ${S}/tools/testing/selftests/${i} INSTALL_PATH=${D}/usr/kernel-selftest/${i} install
72 done
73 if [ -e ${D}/usr/kernel-selftest/bpf/test_offload.py ]; then
74 sed -i -e '1s,#!.*python3,#! /usr/bin/env python3,' ${D}/usr/kernel-selftest/bpf/test_offload.py
75 fi
76 chown root:root -R ${D}/usr/kernel-selftest
77}
78
79do_configure() {
80 install -D -m 0644 ${WORKDIR}/COPYING ${S}/COPYING
81}
82
83do_patch[prefuncs] += "copy_kselftest_source_from_kernel remove_unrelated"
84python copy_kselftest_source_from_kernel() {
85 sources = (d.getVar("KERNEL_SELFTEST_SRC") or "").split()
86 src_dir = d.getVar("STAGING_KERNEL_DIR")
87 dest_dir = d.getVar("S")
88 bb.utils.mkdirhier(dest_dir)
89 for s in sources:
90 src = oe.path.join(src_dir, s)
91 dest = oe.path.join(dest_dir, s)
92 if os.path.isdir(src):
93 oe.path.copytree(src, dest)
94 else:
95 bb.utils.copyfile(src, dest)
96}
97
98remove_unrelated() {
99 if ${@bb.utils.contains('PACKAGECONFIG','bpf','true','false',d)} ; then
100 test -f ${S}/tools/testing/selftests/bpf/Makefile && \
101 sed -i -e 's/test_pkt_access.*$/\\/' \
102 -e 's/test_pkt_md_access.*$/\\/' \
103 -e 's/sockmap_verdict_prog.*$/\\/' \
104 ${S}/tools/testing/selftests/bpf/Makefile || \
105 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"
106 fi
107}
108
109PACKAGE_ARCH = "${MACHINE_ARCH}"
110
111INHIBIT_PACKAGE_DEBUG_SPLIT="1"
112FILES_${PN} += "/usr/kernel-selftest"
113
114RDEPENDS_${PN} += "python3"
115# tools/testing/selftests/vm/Makefile doesn't respect LDFLAGS and tools/testing/selftests/Makefile explicitly overrides to empty
116INSANE_SKIP_${PN} += "ldflags"
Brad Bishop26bdd442019-08-16 17:08:17 -0400117
Brad Bishop0f291cc2019-09-01 15:16:57 -0400118SECURITY_CFLAGS = ""
Brad Bishop5f78ea12019-09-10 07:20:03 -0400119COMPATIBLE_HOST_libc-musl = 'null'
120
Brad Bishopdec060e2019-09-23 08:01:31 -0400121# It has native clang/llvm dependency, poky distro is reluctant to include them as deps
122# this helps with world builds on AB
123EXCLUDE_FROM_WORLD = "1"
124