aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorArnaldo Carvalho de Melo <acme@redhat.com>2024-04-02 14:35:51 -0300
committerArnaldo Carvalho de Melo <acme@redhat.com>2024-04-15 14:51:21 -0300
commitc933676ce2780325a20b67dececf9616d6e610bf (patch)
treee3597f8cb52064f3e5bf100aea5f8bb03ba33210
parentdba7b5e847529cded71c6f46b8e281bad71c9fb7 (diff)
downloaddwarves-c933676ce2780325a20b67dececf9616d6e610bf.tar.gz
tests: Add a BTF reproducible generation test
$ time tests/reproducible_build.sh vmlinux Parallel reproducible DWARF Loading/Serial BTF encoding: Ok real 1m13.844s user 3m3.601s sys 0m9.049s $ If the number of threads started by pahole is different than what was requests via its -j command line option, it will fail as well as if the output of 'bpftool btf dump' differs from the BTF encoded totally serially to one of the detached BTF encoded using reproducible DWARF loading/BTF encoding. Reviewed-by: Alan Maguire <alan.maguire@oracle.com> Tested-by: Alan Maguire <alan.maguire@oracle.com> Cc: Kui-Feng Lee <kuifeng@fb.com> Cc: Thomas Weißschuh <linux@weissschuh.net> Link: https://lore.kernel.org/lkml/20240412211604.789632-13-acme@kernel.org Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
-rwxr-xr-xtests/reproducible_build.sh56
1 files changed, 56 insertions, 0 deletions
diff --git a/tests/reproducible_build.sh b/tests/reproducible_build.sh
new file mode 100755
index 0000000..9c72d54
--- /dev/null
+++ b/tests/reproducible_build.sh
@@ -0,0 +1,56 @@
+#!/bin/bash
+# SPDX-License-Identifier: GPL-2.0-only
+#
+# Test if BTF generated serially matches reproducible parallel DWARF loading + serial BTF encoding
+# Arnaldo Carvalho de Melo <acme@redhat.com> (C) 2024-
+
+vmlinux=$1
+outdir=$(mktemp -d /tmp/reproducible_build.sh.XXXXXX)
+
+echo -n "Parallel reproducible DWARF Loading/Serial BTF encoding: "
+
+test -n "$VERBOSE" && printf "\nserial encoding...\n"
+
+pahole --btf_encode_detached=$outdir/vmlinux.btf.serial $vmlinux
+bpftool btf dump file $outdir/vmlinux.btf.serial > $outdir/bpftool.output.vmlinux.btf.serial
+
+nr_proc=$(getconf _NPROCESSORS_ONLN)
+
+for threads in $(seq $nr_proc) ; do
+ test -n "$VERBOSE" && echo $threads threads encoding
+ pahole -j$threads --reproducible_build --btf_encode_detached=$outdir/vmlinux.btf.parallel.reproducible $vmlinux &
+ pahole=$!
+ # HACK: Wait a bit for pahole to start its threads
+ sleep 0.3s
+ # PID part to remove ps output headers
+ nr_threads_started=$(ps -L -C pahole | grep -v PID | wc -l)
+
+ if [ $threads -gt 1 ] ; then
+ ((nr_threads_started -= 1))
+ fi
+
+ if [ $threads != $nr_threads_started ] ; then
+ echo "ERROR: pahole asked to start $threads encoding threads, started $nr_threads_started"
+ exit 1;
+ fi
+
+ # ps -L -C pahole | grep -v PID | nl
+ test -n "$VERBOSE" && echo $nr_threads_started threads started
+ wait $pahole
+ rm -f $outdir/bpftool.output.vmlinux.btf.parallel.reproducible
+ bpftool btf dump file $outdir/vmlinux.btf.parallel.reproducible > $outdir/bpftool.output.vmlinux.btf.parallel.reproducible
+ test -n "$VERBOSE" && echo "diff from serial encoding:"
+ diff -u $outdir/bpftool.output.vmlinux.btf.serial $outdir/bpftool.output.vmlinux.btf.parallel.reproducible > $outdir/diff
+ if [ -s $outdir/diff ] ; then
+ echo "ERROR: BTF generated from DWARF in parallel is different from the one generated in serial!"
+ exit 1
+ fi
+ test -n "$VERBOSE" && echo -----------------------------
+done
+
+rm $outdir/*
+rmdir $outdir
+
+echo "Ok"
+
+exit 0