Blame test/difftree.sh

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