From patchwork Tue Feb 23 13:23:21 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiri Olsa X-Patchwork-Id: 387129 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.0 required=3.0 tests=BAYES_00,INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 78904C433E9 for ; Tue, 23 Feb 2021 13:24:29 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 4666864E3F for ; Tue, 23 Feb 2021 13:24:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232714AbhBWNY2 convert rfc822-to-8bit (ORCPT ); Tue, 23 Feb 2021 08:24:28 -0500 Received: from us-smtp-delivery-44.mimecast.com ([207.211.30.44]:46029 "EHLO us-smtp-delivery-44.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232599AbhBWNY0 (ORCPT ); Tue, 23 Feb 2021 08:24:26 -0500 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-109-k6zqsN5wMZe5328MA6hBVg-1; Tue, 23 Feb 2021 08:23:28 -0500 X-MC-Unique: k6zqsN5wMZe5328MA6hBVg-1 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id BEF67107ACF2; Tue, 23 Feb 2021 13:23:25 +0000 (UTC) Received: from krava.cust.in.nbox.cz (unknown [10.40.193.171]) by smtp.corp.redhat.com (Postfix) with ESMTP id A7AF95D9D3; Tue, 23 Feb 2021 13:23:22 +0000 (UTC) From: Jiri Olsa To: Arnaldo Carvalho de Melo , Andrii Nakryiko Cc: dwarves@vger.kernel.org, netdev@vger.kernel.org, bpf@vger.kernel.org, Alexei Starovoitov , Yonghong Song , Hao Luo , Martin KaFai Lau , Song Liu , John Fastabend , KP Singh , Nathan Chancellor , Sedat Dilek Subject: [RFC] dwarves/pahole: Add test scripts Date: Tue, 23 Feb 2021 14:23:21 +0100 Message-Id: <20210223132321.220570-1-jolsa@kernel.org> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=jolsa@kernel.org X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org hi, I cleaned up a bit my testing scripts, that I'm using for testing btf encoding changes. It's far from ideal and convoluted, but let's have discussion if this could be kicked into something useful for everybody. There are 2 scripts: kernel-objects-build.sh - compiles kernel for several archs and stores vmlinux and kernel modules kernel-objects-test.sh - goes through objects stored by ^^^ and runs tests on each of them The general idea is that all objects are compiled already with BTF debuginfo with available pahole. The test script then: - takes each objects and dumps its current BTF data - then create new BTF data with given pahole binary - dumps the new BTF data and makes the comparison I was thinking about support for comparing 2 pahole binaries, but so far that did not fit into my workflow. Normally I have latest globally available pahole, which is used to build the kernel binaries and then I'm playing with new pahole binary, which I'm putting to the test. Example.. prepare vmlinux and modules for all archs: $ ./kernel-objects-build.sh output: /tmp/pahole.test.nsQ kdir: /home/jolsa/linux pahole: /opt/dwarves/bin/pahole objects: /home/jolsa/.pahole_test_objects cleanup /home/jolsa/linux ... All objects are stored under ~/pahole_test_objects/ directories: $ ls ~/.pahole_test_objects/ aarch64-clang aarch64-gcc powerpc-gcc powerpcle-gcc s390x-gcc x86-clang x86-gcc Each containing vmlinux and modules: $ ls ~/.pahole_test_objects/x86-gcc/ efivarfs.ko iptable_nat.ko nf_log_arp.ko nf_log_common.ko nf_log_ipv4.ko nf_log_ipv6.ko vmlinux x86_pkg_temp_thermal.ko xt_addrtype.ko xt_LOG.ko xt_mark.ko xt_MASQUERADE.ko xt_nat.ko Run test on all of them with new './pahole' binary: $ ./kernel-objects-test.sh -B ~/linux/tools/bpf/bpftool/bpftool -P ./pahole pahole: /home/jolsa/pahole/build/pahole bpftool: /home/jolsa/linux/tools/bpf/bpftool/bpftool base: /tmp/pahole.test.oxv objects: /home/jolsa/.pahole_test_objects fail: no cleanup: yes test_funcs on /home/jolsa/.pahole_test_objects/aarch64-clang/vmlinux ... OK test_format_c on /home/jolsa/.pahole_test_objects/aarch64-clang/vmlinux ... OK test_btfdiff on /home/jolsa/.pahole_test_objects/aarch64-clang/vmlinux ... FAIL test_funcs on /home/jolsa/.pahole_test_objects/aarch64-clang/8021q.ko ... OK test_format_c on /home/jolsa/.pahole_test_objects/aarch64-clang/8021q.ko ... OK test_funcs on /home/jolsa/.pahole_test_objects/aarch64-clang/act_gact.ko ... OK test_format_c on /home/jolsa/.pahole_test_objects/aarch64-clang/act_gact.ko ... OK ... There are several options that helps to set other binaries/dirs or stop and debug issues. thoughts? thanks, jirka --- kernel-objects-build.sh | 132 +++++++++++++++++++ kernel-objects-test.sh | 282 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 414 insertions(+) create mode 100755 kernel-objects-build.sh create mode 100755 kernel-objects-test.sh diff --git a/kernel-objects-build.sh b/kernel-objects-build.sh new file mode 100755 index 000000000000..b92729994ded --- /dev/null +++ b/kernel-objects-build.sh @@ -0,0 +1,132 @@ +#!/bin/bash +# SPDX-License-Identifier: GPL-2.0 + +set -u +set -e + +exec 2>&1 + +OBJECTS="${HOME}/.pahole_test_objects" +KDIR=${HOME}/linux +PAHOLE=$(which pahole) +OUTPUT= + +usage() +{ + cat < ${OUTPUT}/output 2>&1 + scripts/config \ + --file ${OUTPUT}/.config \ + -e BPF_SYSCALL \ + -e DEBUG_INFO \ + -e DEBUG_INFO_BTF \ + -e FTRACE \ + -e FUNCTION_TRACER \ + >> ${OUTPUT}/output 2>&1 + make ${opts} -j"$(nproc)" O=${OUTPUT} PAHOLE=${PAHOLE} olddefconfig all >> ${OUTPUT}/output 2>&1 + + cp ${OUTPUT}/vmlinux ${OBJECTS}/${name} + find ${OUTPUT} -name '*.ko' | xargs cp -t ${OBJECTS}/${name} + + rm -rf ${OUTPUT} + popd +} + +main() +{ + while getopts 'k:o:O:' opt; do + case ${opt} in + k) + KDIR="$OPTARG" + ;; + O) + OUTPUT="$OPTARG" + ;; + o) + OBJECTS="$OPTARG" + ;; + esac + done + shift $((OPTIND -1)) + + if [[ $# -ne 0 ]]; then + usage + exit 1 + fi + + if [[ "${OUTPUT}" == "" ]]; then + OUTPUT=$(mktemp -d /tmp/pahole.test.XXX) + fi + + PAHOLE=$(realpath ${PAHOLE}) + OBJECTS=$(realpath ${OBJECTS}) + + echo "output: ${OUTPUT}" + echo "kdir: ${KDIR}" + echo "pahole: ${PAHOLE}" + echo "objects: ${OBJECTS}" + echo + + mkdir -p ${OBJECTS} + + echo "cleanup ${KDIR}" + make -C ${KDIR} mrproper + + + build x86-clang "LLVM=1" + build x86-gcc "" + + build aarch64-clang "ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- LLVM=1" + build aarch64-gcc "ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu-" + +# build powerpc-clang "ARCH=powerpc CROSS_COMPILE=powerpc64-linux-gnu- LLVM=1" + build powerpc-gcc "ARCH=powerpc CROSS_COMPILE=powerpc64-linux-gnu-" + +# build powerpcle-clang "ARCH=powerpc CROSS_COMPILE=powerpc64le-linux-gnu- LLVM=1" + build powerpcle-gcc "ARCH=powerpc CROSS_COMPILE=powerpc64le-linux-gnu-" + +# build s390x-clang "ARCH=s390 CROSS_COMPILE=s390x-linux-gnu- LLVM=1" + build s390x-gcc "ARCH=s390 CROSS_COMPILE=s390x-linux-gnu-" +} + +catch() +{ + local exit_code=$1 + exit ${exit_code} +} + +trap 'catch "$?"' EXIT + +main "$@" diff --git a/kernel-objects-test.sh b/kernel-objects-test.sh new file mode 100755 index 000000000000..a34c22c2eb09 --- /dev/null +++ b/kernel-objects-test.sh @@ -0,0 +1,282 @@ +#!/bin/bash +# SPDX-License-Identifier: GPL-2.0 + +set -u + +exec 2>&1 + +PAHOLE=$(which pahole) +BPFTOOL=$(which bpftool) +BTFDIFF=$(which btfdiff) + +OBJECTS="$HOME/.pahole_test_objects" +CLEANUP="yes" +BASE= +FAIL="no" + +function test_funcs() +{ + local vmlinux=$1 + local obj=$2 + local err=0 + + cp ${obj} ${BASE}/object + + if [[ ${obj} == *.ko ]]; then + ${BPFTOOL} --base ${vmlinux} btf dump file ${BASE}/object > ${BASE}/btf.old + ${PAHOLE} -V -J --btf_base ${vmlinux} ${BASE}/object > ${BASE}/output + ${BPFTOOL} --base ${vmlinux} btf dump file ${BASE}/object > ${BASE}/btf.new + else + ${BPFTOOL} btf dump file ${BASE}/object > ${BASE}/btf.old + ${PAHOLE} -V -J ${BASE}/object > ${BASE}/output + ${BPFTOOL} btf dump file ${BASE}/object > ${BASE}/btf.new + fi + + diff -puw ${BASE}/btf.old ${BASE}/btf.new > ${BASE}/diff.all + if [ $? -ne 0 ]; then + funcs_old=${BASE}/funcs.old + funcs_new=${BASE}/funcs.new + + cat ${BASE}/btf.old | grep 'FUNC ' | awk '{ print $3 }' | sort | uniq > ${funcs_old} + cat ${BASE}/btf.new | grep 'FUNC ' | awk '{ print $3 }' | sort | uniq > ${funcs_new} + + diff -puw ${funcs_old} ${funcs_new} > ${BASE}/diff.funcs + fi + + if [[ $? -ne 0 ]]; then + err=1 + fi + + return ${err}; +} + +function test_format_c() +{ + local vmlinux=$1 + local obj=$2 + local err=0 + + cp ${obj} ${BASE}/object + + if [[ ${obj} == *.ko ]]; then + ${BPFTOOL} --base ${vmlinux} btf dump file ${BASE}/object format c > ${BASE}/c.old + ${PAHOLE} -V -J --btf_base ${vmlinux} ${BASE}/object > ${BASE}/output + ${BPFTOOL} --base ${vmlinux} btf dump file ${BASE}/object format c > ${BASE}/c.new + else + ${BPFTOOL} btf dump file ${BASE}/object format c > ${BASE}/c.old + ${PAHOLE} -V -J ${BASE}/object > ${BASE}/output + ${BPFTOOL} btf dump file ${BASE}/object format c > ${BASE}/c.new + fi + + diff -puw ${BASE}/c.old ${BASE}/c.new > ${BASE}/diff.all + if [[ $? -ne 0 ]]; then + err=1 + fi + + return ${err}; +} + +function test_btfdiff() +{ + local vmlinux=$1 + local obj=$2 + local err=0 + + if [[ -x ${BTFDIFF} ]]; then + ${BTFDIFF} ${obj} > ${BASE}/output + if [[ -s "${BASE}/output" ]]; then + err=1 + fi + else + err=2 + fi + + return ${err} +} + +usage() +{ + cat <