Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 1 | SUMMARY = "Kernel selftest for Linux" |
| 2 | DESCRIPTION = "Kernel selftest for Linux" |
Andrew Geissler | 9aee500 | 2022-03-30 16:27:02 +0000 | [diff] [blame] | 3 | LICENSE = "GPL-2.0-only" |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 4 | |
| 5 | LIC_FILES_CHKSUM = "file://../COPYING;md5=bbea815ee2795b2f4230826c0c6b8814" |
| 6 | |
| 7 | DEPENDS = "rsync-native llvm-native" |
| 8 | |
| 9 | # for musl libc |
Patrick Williams | 213cb26 | 2021-08-07 19:21:33 -0500 | [diff] [blame] | 10 | SRC_URI:append:libc-musl = "\ |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 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 |
Patrick Williams | 213cb26 | 2021-08-07 19:21:33 -0500 | [diff] [blame] | 21 | PACKAGECONFIG ??= "firmware" |
Andrew Geissler | 2013739 | 2023-10-12 04:59:14 -0600 | [diff] [blame^] | 22 | # bpf needs working clang compiler anyway |
| 23 | PACKAGECONFIG:append:toolchain-clang:x86-64 = " bpf" |
Patrick Williams | 213cb26 | 2021-08-07 19:21:33 -0500 | [diff] [blame] | 24 | PACKAGECONFIG:remove:x86 = "bpf" |
| 25 | PACKAGECONFIG:remove:arm = "bpf vm" |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 26 | # host ptrace.h is used to compile BPF target but mips ptrace.h is needed |
| 27 | # progs/loop1.c:21:9: error: incomplete definition of type 'struct user_pt_regs' |
| 28 | # m = PT_REGS_RC(ctx); |
Andrew Geissler | d688a01 | 2020-09-18 13:36:00 -0500 | [diff] [blame] | 29 | # vm tests need libhugetlbfs starting 5.8+ (https://lkml.org/lkml/2020/4/22/1654) |
Patrick Williams | 213cb26 | 2021-08-07 19:21:33 -0500 | [diff] [blame] | 30 | PACKAGECONFIG:remove:qemumips = "bpf vm" |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 31 | |
Andrew Geissler | 4b7c115 | 2020-11-30 19:55:29 -0600 | [diff] [blame] | 32 | # riscv does not support libhugetlbfs yet |
Andrew Geissler | 2013739 | 2023-10-12 04:59:14 -0600 | [diff] [blame^] | 33 | PACKAGECONFIG:remove:riscv64 = "bpf vm" |
| 34 | PACKAGECONFIG:remove:riscv32 = "bpf vm" |
Andrew Geissler | 4b7c115 | 2020-11-30 19:55:29 -0600 | [diff] [blame] | 35 | |
Andrew Geissler | 2013739 | 2023-10-12 04:59:14 -0600 | [diff] [blame^] | 36 | PACKAGECONFIG[bpf] = ",,elfutils elfutils-native libcap libcap-ng rsync-native python3-docutils-native," |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 37 | PACKAGECONFIG[firmware] = ",,libcap, bash" |
Andrew Geissler | d688a01 | 2020-09-18 13:36:00 -0500 | [diff] [blame] | 38 | PACKAGECONFIG[vm] = ",,libcap libhugetlbfs,libgcc bash" |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 39 | |
| 40 | do_patch[depends] += "virtual/kernel:do_shared_workdir" |
Andrew Geissler | 2013739 | 2023-10-12 04:59:14 -0600 | [diff] [blame^] | 41 | do_compile[depends] += "virtual/kernel:do_install" |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 42 | |
Andrew Geissler | 2013739 | 2023-10-12 04:59:14 -0600 | [diff] [blame^] | 43 | inherit linux-kernel-base module-base kernel-arch ptest siteinfo |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 44 | |
| 45 | S = "${WORKDIR}/${BP}" |
| 46 | |
Andrew Geissler | 2013739 | 2023-10-12 04:59:14 -0600 | [diff] [blame^] | 47 | DEBUG_PREFIX_MAP:remove = "-fcanon-prefix-map" |
| 48 | |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 49 | TEST_LIST = "\ |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 50 | ${@bb.utils.filter('PACKAGECONFIG', 'bpf firmware vm', d)} \ |
Brad Bishop | e42b3e3 | 2020-01-15 22:08:42 -0500 | [diff] [blame] | 51 | rtc \ |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 52 | " |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 53 | EXTRA_OEMAKE = '\ |
| 54 | CROSS_COMPILE=${TARGET_PREFIX} \ |
| 55 | ARCH=${ARCH} \ |
| 56 | CC="${CC}" \ |
| 57 | AR="${AR}" \ |
| 58 | LD="${LD}" \ |
Andrew Geissler | 2013739 | 2023-10-12 04:59:14 -0600 | [diff] [blame^] | 59 | CLANG="clang -fno-stack-protector -target ${TARGET_ARCH} ${TOOLCHAIN_OPTIONS} -isystem ${S} -D__WORDSIZE=\'64\' -Wno-error=unused-command-line-argument" \ |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 60 | DESTDIR="${D}" \ |
Andrew Geissler | 2013739 | 2023-10-12 04:59:14 -0600 | [diff] [blame^] | 61 | V=1 \ |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 62 | ' |
Andrew Geissler | 2013739 | 2023-10-12 04:59:14 -0600 | [diff] [blame^] | 63 | EXTRA_OEMAKE:append:toolchain-clang = "\ |
| 64 | LLVM=1 CONFIG_CC_IS_GCC= CONFIG_CC_IS_CLANG=y CONFIG_CC_IMPLICIT_FALLTHROUGH= \ |
| 65 | HOSTCC="clang -unwindlib=libgcc -rtlib=libgcc -stdlib=libstdc++ ${BUILD_CFLAGS} ${BUILD_LDFLAGS} -Wno-error=unused-command-line-argument" \ |
| 66 | HOSTLD="clang ${BUILD_LDFLAGS} -unwindlib=libgcc -rtlib=libgcc -stdlib=libstdc++" \ |
| 67 | " |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 68 | |
| 69 | KERNEL_SELFTEST_SRC ?= "Makefile \ |
| 70 | include \ |
Andrew Geissler | d688a01 | 2020-09-18 13:36:00 -0500 | [diff] [blame] | 71 | kernel \ |
| 72 | lib \ |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 73 | tools \ |
| 74 | scripts \ |
| 75 | arch \ |
| 76 | LICENSES \ |
| 77 | " |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 78 | do_compile() { |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 79 | if [ ${@bb.utils.contains('PACKAGECONFIG', 'bpf', 'True', 'False', d)} = 'True' ]; then |
Brad Bishop | 0f291cc | 2019-09-01 15:16:57 -0400 | [diff] [blame] | 80 | if [ ${@bb.utils.contains('DEPENDS', 'clang-native', 'True', 'False', d)} = 'False' ]; then |
| 81 | bbwarn "clang >= 6.0 with bpf support is needed with kernel 4.18+ so |
| 82 | either install it and add it to HOSTTOOLS, or add clang-native from meta-clang to dependency" |
| 83 | fi |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 84 | fi |
Andrew Geissler | 2013739 | 2023-10-12 04:59:14 -0600 | [diff] [blame^] | 85 | mkdir -p ${S}/include/config ${S}/bits |
| 86 | install -Dm 0644 ${STAGING_KERNEL_BUILDDIR}/.config ${S}/include/config/auto.conf |
| 87 | if [ "${SITEINFO_BITS}" != "32" ]; then |
| 88 | for f in long-double endianness floatn struct_rwlock; do |
| 89 | cp ${RECIPE_SYSROOT}${includedir}/bits/$f-64.h ${S}/bits/$f-32.h |
| 90 | done |
| 91 | fi |
Andrew Geissler | 220dafd | 2023-10-04 10:18:08 -0500 | [diff] [blame] | 92 | oe_runmake -C ${S} headers |
Andrew Geissler | 2013739 | 2023-10-12 04:59:14 -0600 | [diff] [blame^] | 93 | sed -i -e 's|^all: docs|all:|' ${S}/tools/testing/selftests/bpf/Makefile |
| 94 | sed -i -e '/mrecord-mcount/d' ${S}/Makefile |
| 95 | sed -i -e '/Wno-alloc-size-larger-than/d' ${S}/Makefile |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 96 | for i in ${TEST_LIST} |
| 97 | do |
| 98 | oe_runmake -C ${S}/tools/testing/selftests/${i} |
| 99 | done |
| 100 | } |
| 101 | |
| 102 | do_install() { |
| 103 | for i in ${TEST_LIST} |
| 104 | do |
| 105 | oe_runmake -C ${S}/tools/testing/selftests/${i} INSTALL_PATH=${D}/usr/kernel-selftest/${i} install |
Andrew Geissler | d583833 | 2022-05-27 11:33:10 -0500 | [diff] [blame] | 106 | # Install kselftest-list.txt that required by kselftest runner. |
| 107 | oe_runmake -s --no-print-directory COLLECTION=${i} -C ${S}/tools/testing/selftests/${i} emit_tests \ |
| 108 | >> ${D}/usr/kernel-selftest/kselftest-list.txt |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 109 | done |
Andrew Geissler | d583833 | 2022-05-27 11:33:10 -0500 | [diff] [blame] | 110 | # Install kselftest runner. |
| 111 | install -m 0755 ${S}/tools/testing/selftests/run_kselftest.sh ${D}/usr/kernel-selftest/ |
| 112 | cp -R --no-dereference --preserve=mode,links -v ${S}/tools/testing/selftests/kselftest ${D}/usr/kernel-selftest/ |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 113 | if [ -e ${D}/usr/kernel-selftest/bpf/test_offload.py ]; then |
| 114 | sed -i -e '1s,#!.*python3,#! /usr/bin/env python3,' ${D}/usr/kernel-selftest/bpf/test_offload.py |
| 115 | fi |
| 116 | chown root:root -R ${D}/usr/kernel-selftest |
| 117 | } |
| 118 | |
| 119 | do_configure() { |
| 120 | install -D -m 0644 ${WORKDIR}/COPYING ${S}/COPYING |
| 121 | } |
| 122 | |
| 123 | do_patch[prefuncs] += "copy_kselftest_source_from_kernel remove_unrelated" |
| 124 | python copy_kselftest_source_from_kernel() { |
| 125 | sources = (d.getVar("KERNEL_SELFTEST_SRC") or "").split() |
| 126 | src_dir = d.getVar("STAGING_KERNEL_DIR") |
| 127 | dest_dir = d.getVar("S") |
| 128 | bb.utils.mkdirhier(dest_dir) |
| 129 | for s in sources: |
| 130 | src = oe.path.join(src_dir, s) |
| 131 | dest = oe.path.join(dest_dir, s) |
| 132 | if os.path.isdir(src): |
| 133 | oe.path.copytree(src, dest) |
| 134 | else: |
| 135 | bb.utils.copyfile(src, dest) |
| 136 | } |
| 137 | |
| 138 | remove_unrelated() { |
| 139 | if ${@bb.utils.contains('PACKAGECONFIG','bpf','true','false',d)} ; then |
| 140 | test -f ${S}/tools/testing/selftests/bpf/Makefile && \ |
| 141 | sed -i -e 's/test_pkt_access.*$/\\/' \ |
| 142 | -e 's/test_pkt_md_access.*$/\\/' \ |
| 143 | -e 's/sockmap_verdict_prog.*$/\\/' \ |
| 144 | ${S}/tools/testing/selftests/bpf/Makefile || \ |
| 145 | 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" |
| 146 | fi |
| 147 | } |
| 148 | |
| 149 | PACKAGE_ARCH = "${MACHINE_ARCH}" |
| 150 | |
| 151 | INHIBIT_PACKAGE_DEBUG_SPLIT="1" |
Patrick Williams | 213cb26 | 2021-08-07 19:21:33 -0500 | [diff] [blame] | 152 | FILES:${PN} += "/usr/kernel-selftest" |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 153 | |
Andrew Geissler | 2013739 | 2023-10-12 04:59:14 -0600 | [diff] [blame^] | 154 | RDEPENDS:${PN} += "python3 perl perl-module-io-handle" |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 155 | # tools/testing/selftests/vm/Makefile doesn't respect LDFLAGS and tools/testing/selftests/Makefile explicitly overrides to empty |
Andrew Geissler | 2013739 | 2023-10-12 04:59:14 -0600 | [diff] [blame^] | 156 | INSANE_SKIP:${PN} += "ldflags libdir" |
Brad Bishop | 26bdd44 | 2019-08-16 17:08:17 -0400 | [diff] [blame] | 157 | |
Brad Bishop | 0f291cc | 2019-09-01 15:16:57 -0400 | [diff] [blame] | 158 | SECURITY_CFLAGS = "" |
Patrick Williams | 213cb26 | 2021-08-07 19:21:33 -0500 | [diff] [blame] | 159 | COMPATIBLE_HOST:libc-musl = 'null' |
Brad Bishop | 5f78ea1 | 2019-09-10 07:20:03 -0400 | [diff] [blame] | 160 | |
Brad Bishop | dec060e | 2019-09-23 08:01:31 -0400 | [diff] [blame] | 161 | # It has native clang/llvm dependency, poky distro is reluctant to include them as deps |
| 162 | # this helps with world builds on AB |
| 163 | EXCLUDE_FROM_WORLD = "1" |