1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72
|
#!/bin/bash
# Compare the IR generated for the shipped
# tools between two bpftrace builds
#
set -o pipefail
set -e
set -u
if [[ "$#" -ne 3 ]]; then
echo "Compare IR generated between two bpftrace builds"
echo ""
echo "USAGE:"
echo "$(basename $0) <bpftrace_A> <bpftrace_B> <tooldir>"
echo ""
echo "EXAMPLE:"
echo "$(basename $0) bpftrace bpftrace_master ./tools"
echo ""
exit 1
fi
TOOLDIR=$3
BPF_A=$(command -v "$1") || ( echo "ERROR: $1 not found"; exit 1 )
BPF_B=$(command -v "$2") || ( echo "ERROR: $2 not found"; exit 1 )
[[ -d "$TOOLDIR" ]] || (echo "tooldir does not appear to be a directory: ${TOOLDIR}"; exit 1)
# Set to 1 to only compare result after opt
AFTER_OPT=0
if [ $AFTER_OPT -eq 1 ]; then
FLAGS="-d"
else
FLAGS="-dd"
fi
TMPDIR=$(mktemp -d)
[[ $? -ne 0 || -z $TMPDIR ]] && (echo "Failed to create tmp dir"; exit 10)
cd $TMPDIR
set +e
function hash() {
file="${1}"
sha1sum "${1}" | awk '{print $1}'
}
function fix_timestamp() {
cat $@ | awk '/(add|sub) i64 %get_ns/ { $NF = ""} {print}'
}
echo "Using version $($BPF_A -V) and $($BPF_B -V)"
for script in ${TOOLDIR}/*.bt; do
s=$(basename ${script/.bt/})
echo "Checking $s"
2>&1 $BPF_A "$FLAGS" "$script" | fix_timestamp > "a_${s}"
2>&1 $BPF_B "$FLAGS" "$script" | fix_timestamp > "b_${s}"
if [ $? -ne 0 ]; then
echo "###############################"
echo "bpftrace failed on script: ${s}"
echo "###############################"
continue
fi
if [[ $(hash "a_${s}") != $(hash "b_${s}") ]]; then
echo "###############################"
echo "Change detected for script: ${s}"
diff -b -u "a_${s}" "b_${s}"
fi
done
[[ -n ${TMPDIR} ]] && rm -rf "${TMPDIR}"
|