blob: 181e97cac9668f870678fa63c36f9c6857e44e59 [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}" \
42 AR="${AR}" \
43 LD="${LD}" \
44 DESTDIR="${D}" \
45'
46
47KERNEL_SELFTEST_SRC ?= "Makefile \
48 include \
49 tools \
50 scripts \
51 arch \
52 LICENSES \
53"
54
55python __anonymous () {
56 import re
57
58 var = d.getVar('TARGET_CC_ARCH')
59 pattern = '_FORTIFY_SOURCE=[^0]'
60
61 if re.search(pattern, var):
62 d.appendVar('TARGET_CC_ARCH', " -O")
63}
64
65do_compile() {
66 bbwarn "clang >= 6.0 with bpf support is needed with kernel 4.18+ so \
67either install it and add it to HOSTTOOLS, or add \
68clang-native from meta-clang to dependency"
69 for i in ${TEST_LIST}
70 do
71 oe_runmake -C ${S}/tools/testing/selftests/${i}
72 done
73}
74
75do_install() {
76 for i in ${TEST_LIST}
77 do
78 oe_runmake -C ${S}/tools/testing/selftests/${i} INSTALL_PATH=${D}/usr/kernel-selftest/${i} install
79 done
80 if [ -e ${D}/usr/kernel-selftest/bpf/test_offload.py ]; then
81 sed -i -e '1s,#!.*python3,#! /usr/bin/env python3,' ${D}/usr/kernel-selftest/bpf/test_offload.py
82 fi
83 chown root:root -R ${D}/usr/kernel-selftest
84}
85
86do_configure() {
87 install -D -m 0644 ${WORKDIR}/COPYING ${S}/COPYING
88}
89
90do_patch[prefuncs] += "copy_kselftest_source_from_kernel remove_unrelated"
91python copy_kselftest_source_from_kernel() {
92 sources = (d.getVar("KERNEL_SELFTEST_SRC") or "").split()
93 src_dir = d.getVar("STAGING_KERNEL_DIR")
94 dest_dir = d.getVar("S")
95 bb.utils.mkdirhier(dest_dir)
96 for s in sources:
97 src = oe.path.join(src_dir, s)
98 dest = oe.path.join(dest_dir, s)
99 if os.path.isdir(src):
100 oe.path.copytree(src, dest)
101 else:
102 bb.utils.copyfile(src, dest)
103}
104
105remove_unrelated() {
106 if ${@bb.utils.contains('PACKAGECONFIG','bpf','true','false',d)} ; then
107 test -f ${S}/tools/testing/selftests/bpf/Makefile && \
108 sed -i -e 's/test_pkt_access.*$/\\/' \
109 -e 's/test_pkt_md_access.*$/\\/' \
110 -e 's/sockmap_verdict_prog.*$/\\/' \
111 ${S}/tools/testing/selftests/bpf/Makefile || \
112 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"
113 fi
114}
115
116PACKAGE_ARCH = "${MACHINE_ARCH}"
117
118INHIBIT_PACKAGE_DEBUG_SPLIT="1"
119FILES_${PN} += "/usr/kernel-selftest"
120
121RDEPENDS_${PN} += "python3"
122# tools/testing/selftests/vm/Makefile doesn't respect LDFLAGS and tools/testing/selftests/Makefile explicitly overrides to empty
123INSANE_SKIP_${PN} += "ldflags"