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}" \ |
| 42 | AR="${AR}" \ |
| 43 | LD="${LD}" \ |
| 44 | DESTDIR="${D}" \ |
| 45 | ' |
| 46 | |
| 47 | KERNEL_SELFTEST_SRC ?= "Makefile \ |
| 48 | include \ |
| 49 | tools \ |
| 50 | scripts \ |
| 51 | arch \ |
| 52 | LICENSES \ |
| 53 | " |
| 54 | |
| 55 | python __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 | |
| 65 | do_compile() { |
| 66 | bbwarn "clang >= 6.0 with bpf support is needed with kernel 4.18+ so \ |
| 67 | either install it and add it to HOSTTOOLS, or add \ |
| 68 | clang-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 | |
| 75 | do_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 | |
| 86 | do_configure() { |
| 87 | install -D -m 0644 ${WORKDIR}/COPYING ${S}/COPYING |
| 88 | } |
| 89 | |
| 90 | do_patch[prefuncs] += "copy_kselftest_source_from_kernel remove_unrelated" |
| 91 | python 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 | |
| 105 | remove_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 | |
| 116 | PACKAGE_ARCH = "${MACHINE_ARCH}" |
| 117 | |
| 118 | INHIBIT_PACKAGE_DEBUG_SPLIT="1" |
| 119 | FILES_${PN} += "/usr/kernel-selftest" |
| 120 | |
| 121 | RDEPENDS_${PN} += "python3" |
| 122 | # tools/testing/selftests/vm/Makefile doesn't respect LDFLAGS and tools/testing/selftests/Makefile explicitly overrides to empty |
| 123 | INSANE_SKIP_${PN} += "ldflags" |