1SUMMARY = "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 ??= "firmware vm" 22PACKAGECONFIG_remove_x86 = "bpf" 23PACKAGECONFIG_remove_arm = "bpf vm" 24# 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); 27# vm tests need libhugetlbfs starting 5.8+ (https://lkml.org/lkml/2020/4/22/1654) 28PACKAGECONFIG_remove_qemumips = "bpf vm" 29 30# riscv does not support libhugetlbfs yet 31PACKAGECONFIG_remove_riscv64 = "vm" 32PACKAGECONFIG_remove_riscv32 = "vm" 33 34PACKAGECONFIG[bpf] = ",,elfutils libcap libcap-ng rsync-native," 35PACKAGECONFIG[firmware] = ",,libcap, bash" 36PACKAGECONFIG[vm] = ",,libcap libhugetlbfs,libgcc bash" 37 38do_patch[depends] += "virtual/kernel:do_shared_workdir" 39 40inherit linux-kernel-base kernel-arch ptest 41 42S = "${WORKDIR}/${BP}" 43 44TEST_LIST = "\ 45 ${@bb.utils.filter('PACKAGECONFIG', 'bpf firmware vm', d)} \ 46 rtc \ 47" 48 49EXTRA_OEMAKE = '\ 50 CROSS_COMPILE=${TARGET_PREFIX} \ 51 ARCH=${ARCH} \ 52 CC="${CC}" \ 53 CLANG="clang -fno-stack-protector -target ${TARGET_ARCH} ${TOOLCHAIN_OPTIONS}" \ 54 AR="${AR}" \ 55 LD="${LD}" \ 56 DESTDIR="${D}" \ 57 MACHINE="${ARCH}" \ 58' 59 60KERNEL_SELFTEST_SRC ?= "Makefile \ 61 include \ 62 kernel \ 63 lib \ 64 tools \ 65 scripts \ 66 arch \ 67 LICENSES \ 68" 69 70do_compile() { 71 if [ ${@bb.utils.contains('PACKAGECONFIG', 'bpf', 'True', 'False', d)} = 'True' ]; then 72 if [ ${@bb.utils.contains('DEPENDS', 'clang-native', 'True', 'False', d)} = 'False' ]; then 73 bbwarn "clang >= 6.0 with bpf support is needed with kernel 4.18+ so 74either install it and add it to HOSTTOOLS, or add clang-native from meta-clang to dependency" 75 fi 76 fi 77 78 for i in ${TEST_LIST} 79 do 80 oe_runmake -C ${S}/tools/testing/selftests/${i} 81 done 82} 83 84do_install() { 85 for i in ${TEST_LIST} 86 do 87 oe_runmake -C ${S}/tools/testing/selftests/${i} INSTALL_PATH=${D}/usr/kernel-selftest/${i} install 88 done 89 if [ -e ${D}/usr/kernel-selftest/bpf/test_offload.py ]; then 90 sed -i -e '1s,#!.*python3,#! /usr/bin/env python3,' ${D}/usr/kernel-selftest/bpf/test_offload.py 91 fi 92 chown root:root -R ${D}/usr/kernel-selftest 93} 94 95do_configure() { 96 install -D -m 0644 ${WORKDIR}/COPYING ${S}/COPYING 97} 98 99do_patch[prefuncs] += "copy_kselftest_source_from_kernel remove_unrelated" 100python copy_kselftest_source_from_kernel() { 101 sources = (d.getVar("KERNEL_SELFTEST_SRC") or "").split() 102 src_dir = d.getVar("STAGING_KERNEL_DIR") 103 dest_dir = d.getVar("S") 104 bb.utils.mkdirhier(dest_dir) 105 for s in sources: 106 src = oe.path.join(src_dir, s) 107 dest = oe.path.join(dest_dir, s) 108 if os.path.isdir(src): 109 oe.path.copytree(src, dest) 110 else: 111 bb.utils.copyfile(src, dest) 112} 113 114remove_unrelated() { 115 if ${@bb.utils.contains('PACKAGECONFIG','bpf','true','false',d)} ; then 116 test -f ${S}/tools/testing/selftests/bpf/Makefile && \ 117 sed -i -e 's/test_pkt_access.*$/\\/' \ 118 -e 's/test_pkt_md_access.*$/\\/' \ 119 -e 's/sockmap_verdict_prog.*$/\\/' \ 120 ${S}/tools/testing/selftests/bpf/Makefile || \ 121 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" 122 fi 123} 124 125PACKAGE_ARCH = "${MACHINE_ARCH}" 126 127INHIBIT_PACKAGE_DEBUG_SPLIT="1" 128FILES_${PN} += "/usr/kernel-selftest" 129 130RDEPENDS_${PN} += "python3" 131# tools/testing/selftests/vm/Makefile doesn't respect LDFLAGS and tools/testing/selftests/Makefile explicitly overrides to empty 132INSANE_SKIP_${PN} += "ldflags" 133 134SECURITY_CFLAGS = "" 135COMPATIBLE_HOST_libc-musl = 'null' 136 137# It has native clang/llvm dependency, poky distro is reluctant to include them as deps 138# this helps with world builds on AB 139EXCLUDE_FROM_WORLD = "1" 140 141