2014-08-08 18:45:15 +00:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
# The purpose of this test script is to determine if create-diff-object can
|
|
|
|
# properly recognize object file equivalence when passed the same file for both
|
|
|
|
# the original and patched objects. This verifies that create-diff-object is
|
|
|
|
# correctly parsing, correlating, and comparing the different elements of the
|
|
|
|
# object file. In practice, a situation similar to the test case occurs when a
|
|
|
|
# commonly included header file changes, causing Make to rebuild many objects
|
|
|
|
# that have no functional change.
|
|
|
|
|
|
|
|
# This script requires a built kernel object tree to be in the kpatch cache
|
|
|
|
# directory at $HOME/.kpatch/obj
|
|
|
|
|
|
|
|
#set -x
|
|
|
|
|
|
|
|
OBJDIR="$HOME/.kpatch/obj"
|
2020-06-03 09:02:59 +00:00
|
|
|
SCRIPTDIR=$(readlink -f $(dirname $(type -p "$0")))
|
2014-08-08 18:45:15 +00:00
|
|
|
TEMPDIR=$(mktemp -d)
|
|
|
|
RESULTSDIR="$TEMPDIR/results"
|
|
|
|
|
|
|
|
if [[ ! -d $OBJDIR ]]; then
|
|
|
|
echo "please run kpatch-build to populate the object tree in $OBJDIR"
|
|
|
|
fi
|
|
|
|
|
|
|
|
cd "$OBJDIR" || exit 1
|
2020-06-03 08:26:12 +00:00
|
|
|
# shellcheck disable=SC2044
|
2020-06-03 08:07:10 +00:00
|
|
|
for i in $(find ./* -name '*.o')
|
2014-08-08 18:45:15 +00:00
|
|
|
do
|
|
|
|
# copied from kpatch-build/kpatch-gcc; keep in sync
|
|
|
|
case $i in
|
|
|
|
*.mod.o|\
|
|
|
|
*built-in.o|\
|
2018-03-20 09:46:50 +00:00
|
|
|
*built-in.a|\
|
2014-08-08 18:45:15 +00:00
|
|
|
vmlinux.o|\
|
|
|
|
.tmp_kallsyms1.o|\
|
|
|
|
.tmp_kallsyms2.o|\
|
|
|
|
init/version.o|\
|
|
|
|
arch/x86/boot/version.o|\
|
|
|
|
arch/x86/boot/compressed/eboot.o|\
|
|
|
|
arch/x86/boot/header.o|\
|
|
|
|
arch/x86/boot/compressed/efi_stub_64.o|\
|
|
|
|
arch/x86/boot/compressed/piggy.o|\
|
|
|
|
kernel/system_certificates.o|\
|
|
|
|
.*.o)
|
|
|
|
continue
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
# skip objects that are the linked product of more than one object file
|
2020-06-03 09:02:59 +00:00
|
|
|
[[ $(readelf -s "$i" | awk '$4=="FILE" {n++} END {print n}') -ne 1 ]] && continue
|
|
|
|
"$SCRIPTDIR"/../kpatch-build/create-diff-object "$i" "$i" "/usr/lib/debug/lib/modules/$(uname -r)/vmlinux" "$TEMPDIR/output.o" > "$TEMPDIR/log.txt" 2>&1
|
2014-08-08 18:45:15 +00:00
|
|
|
RETCODE=$?
|
|
|
|
# expect RETCODE to be 3 indicating no change
|
|
|
|
[[ $RETCODE -eq 3 ]] && continue
|
|
|
|
# otherwise record error
|
2020-06-03 09:02:59 +00:00
|
|
|
mkdir -p "$RESULTSDIR"/$(dirname "$i") || exit 1
|
2014-08-08 18:45:15 +00:00
|
|
|
cp "$i" "$RESULTSDIR/$i" || exit 1
|
|
|
|
case $RETCODE in
|
|
|
|
139)
|
|
|
|
echo "$i: segfault" | tee
|
|
|
|
if [[ ! -e core ]]; then
|
|
|
|
echo "no corefile, run "ulimit -c unlimited" to capture corefile"
|
|
|
|
else
|
|
|
|
mv core "$RESULTSDIR/$i.core" || exit 1
|
|
|
|
fi
|
|
|
|
;;
|
|
|
|
0)
|
|
|
|
echo "$i: incorrectly detected change"
|
|
|
|
mv "$TEMPDIR/log.txt" "$RESULTSDIR/$i.log" || exit 1
|
|
|
|
;;
|
|
|
|
1|2)
|
|
|
|
echo "$i: error code $RETCODE"
|
|
|
|
mv "$TEMPDIR/log.txt" "$RESULTSDIR/$i.log" || exit 1
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
exit 1 # script error
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
rm -f "$TEMPDIR/log.txt" > /dev/null 2>&1
|
|
|
|
|
|
|
|
# try to group the errors together in some meaningful way
|
|
|
|
cd "$RESULTSDIR" || exit 1
|
|
|
|
echo ""
|
|
|
|
echo "Results:"
|
2020-06-03 08:26:12 +00:00
|
|
|
# shellcheck disable=SC2044
|
2020-06-03 08:07:10 +00:00
|
|
|
for i in $(find ./* -iname '*.log')
|
2014-08-08 18:45:15 +00:00
|
|
|
do
|
2020-06-03 08:20:54 +00:00
|
|
|
head -1 "$i" | cut -f2-3 -d':'
|
2014-08-08 18:45:15 +00:00
|
|
|
done | sort | uniq -c | sort -n -r | tee "$TEMPDIR/results.log"
|
|
|
|
|
|
|
|
echo "results are in $TEMPDIR"
|