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 |
| 21 | PACKAGECONFIG ??= "bpf vm" |
| 22 | PACKAGECONFIG_remove_x86 = "bpf" |
| 23 | PACKAGECONFIG_remove_arm = "bpf" |
| 24 | |
| 25 | PACKAGECONFIG[bpf] = ",,elfutils libcap libcap-ng rsync-native," |
| 26 | PACKAGECONFIG[vm] = ",,libcap,libgcc bash" |
| 27 | |
| 28 | do_patch[depends] += "virtual/kernel:do_shared_workdir" |
| 29 | |
| 30 | inherit linux-kernel-base kernel-arch ptest |
| 31 | |
| 32 | S = "${WORKDIR}/${BP}" |
| 33 | |
| 34 | TEST_LIST = "\ |
| 35 | ${@bb.utils.filter('PACKAGECONFIG', 'bpf vm', d)} \ |
| 36 | " |
| 37 | |
| 38 | EXTRA_OEMAKE = '\ |
| 39 | CROSS_COMPILE=${TARGET_PREFIX} \ |
| 40 | ARCH=${ARCH} \ |
| 41 | CC="${CC}" \ |
Brad Bishop | 0f291cc | 2019-09-01 15:16:57 -0400 | [diff] [blame] | 42 | CLANG="clang -fno-stack-protector" \ |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 43 | AR="${AR}" \ |
| 44 | LD="${LD}" \ |
| 45 | DESTDIR="${D}" \ |
| 46 | ' |
| 47 | |
| 48 | KERNEL_SELFTEST_SRC ?= "Makefile \ |
| 49 | include \ |
| 50 | tools \ |
| 51 | scripts \ |
| 52 | arch \ |
| 53 | LICENSES \ |
| 54 | " |
| 55 | |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 56 | do_compile() { |
Brad Bishop | 0f291cc | 2019-09-01 15:16:57 -0400 | [diff] [blame] | 57 | if [ ${@bb.utils.contains('DEPENDS', 'clang-native', 'True', 'False', d)} = 'False' ]; then |
| 58 | bbwarn "clang >= 6.0 with bpf support is needed with kernel 4.18+ so |
| 59 | either install it and add it to HOSTTOOLS, or add clang-native from meta-clang to dependency" |
| 60 | fi |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 61 | for i in ${TEST_LIST} |
| 62 | do |
| 63 | oe_runmake -C ${S}/tools/testing/selftests/${i} |
| 64 | done |
| 65 | } |
| 66 | |
| 67 | do_install() { |
| 68 | for i in ${TEST_LIST} |
| 69 | do |
| 70 | oe_runmake -C ${S}/tools/testing/selftests/${i} INSTALL_PATH=${D}/usr/kernel-selftest/${i} install |
| 71 | done |
| 72 | if [ -e ${D}/usr/kernel-selftest/bpf/test_offload.py ]; then |
| 73 | sed -i -e '1s,#!.*python3,#! /usr/bin/env python3,' ${D}/usr/kernel-selftest/bpf/test_offload.py |
| 74 | fi |
| 75 | chown root:root -R ${D}/usr/kernel-selftest |
| 76 | } |
| 77 | |
| 78 | do_configure() { |
| 79 | install -D -m 0644 ${WORKDIR}/COPYING ${S}/COPYING |
| 80 | } |
| 81 | |
| 82 | do_patch[prefuncs] += "copy_kselftest_source_from_kernel remove_unrelated" |
| 83 | python copy_kselftest_source_from_kernel() { |
| 84 | sources = (d.getVar("KERNEL_SELFTEST_SRC") or "").split() |
| 85 | src_dir = d.getVar("STAGING_KERNEL_DIR") |
| 86 | dest_dir = d.getVar("S") |
| 87 | bb.utils.mkdirhier(dest_dir) |
| 88 | for s in sources: |
| 89 | src = oe.path.join(src_dir, s) |
| 90 | dest = oe.path.join(dest_dir, s) |
| 91 | if os.path.isdir(src): |
| 92 | oe.path.copytree(src, dest) |
| 93 | else: |
| 94 | bb.utils.copyfile(src, dest) |
| 95 | } |
| 96 | |
| 97 | remove_unrelated() { |
| 98 | if ${@bb.utils.contains('PACKAGECONFIG','bpf','true','false',d)} ; then |
| 99 | test -f ${S}/tools/testing/selftests/bpf/Makefile && \ |
| 100 | sed -i -e 's/test_pkt_access.*$/\\/' \ |
| 101 | -e 's/test_pkt_md_access.*$/\\/' \ |
| 102 | -e 's/sockmap_verdict_prog.*$/\\/' \ |
| 103 | ${S}/tools/testing/selftests/bpf/Makefile || \ |
| 104 | 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" |
| 105 | fi |
| 106 | } |
| 107 | |
| 108 | PACKAGE_ARCH = "${MACHINE_ARCH}" |
| 109 | |
| 110 | INHIBIT_PACKAGE_DEBUG_SPLIT="1" |
| 111 | FILES_${PN} += "/usr/kernel-selftest" |
| 112 | |
| 113 | RDEPENDS_${PN} += "python3" |
| 114 | # tools/testing/selftests/vm/Makefile doesn't respect LDFLAGS and tools/testing/selftests/Makefile explicitly overrides to empty |
| 115 | INSANE_SKIP_${PN} += "ldflags" |
Brad Bishop | 26bdd44 | 2019-08-16 17:08:17 -0400 | [diff] [blame] | 116 | |
Brad Bishop | 0f291cc | 2019-09-01 15:16:57 -0400 | [diff] [blame] | 117 | SECURITY_CFLAGS = "" |