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