librtas/vpdupdate-regress

146 lines
3.6 KiB
Plaintext
Raw Permalink Normal View History

#!/bin/bash
# Created by argbash-init v2.10.0
# ARG_OPTIONAL_SINGLE([old],[],[old librtas DSO],[/lib64/librtas.so.2])
# ARG_OPTIONAL_SINGLE([new],[],[new librtas DSO],[$PWD/.libs/librtas.so.2])
# ARG_HELP([Test the vpdupdate command against a development build of librtas])
# ARGBASH_GO()
# needed because of Argbash --> m4_ignore([
### START OF CODE GENERATED BY Argbash v2.10.0 one line above ###
# Argbash is a bash code generator used to get arguments parsing right.
# Argbash is FREE SOFTWARE, see https://argbash.io for more info
die()
{
local _ret="${2:-1}"
test "${_PRINT_HELP:-no}" = yes && print_help >&2
echo "$1" >&2
exit "${_ret}"
}
begins_with_short_option()
{
local first_option all_short_options='h'
first_option="${1:0:1}"
test "$all_short_options" = "${all_short_options/$first_option/}" && return 1 || return 0
}
# THE DEFAULTS INITIALIZATION - OPTIONALS
_arg_old="/lib64/librtas.so.2"
_arg_new="$PWD/.libs/librtas.so.2"
print_help()
{
printf '%s\n' "Test the vpdupdate command against a development build of librtas"
printf 'Usage: %s [--old <arg>] [--new <arg>] [-h|--help]\n' "$0"
printf '\t%s\n' "--old: old librtas DSO (default: '/lib64/librtas.so.2')"
printf '\t%s\n' "--new: new librtas DSO (default: '$PWD/.libs/librtas.so.2')"
printf '\t%s\n' "-h, --help: Prints help"
}
parse_commandline()
{
while test $# -gt 0
do
_key="$1"
case "$_key" in
--old)
test $# -lt 2 && die "Missing value for the optional argument '$_key'." 1
_arg_old="$2"
shift
;;
--old=*)
_arg_old="${_key##--old=}"
;;
--new)
test $# -lt 2 && die "Missing value for the optional argument '$_key'." 1
_arg_new="$2"
shift
;;
--new=*)
_arg_new="${_key##--new=}"
;;
-h|--help)
print_help
exit 0
;;
-h*)
print_help
exit 0
;;
*)
_PRINT_HELP=yes die "FATAL ERROR: Got an unexpected argument '$1'" 1
;;
esac
shift
done
}
parse_commandline "$@"
# OTHER STUFF GENERATED BY Argbash
### END OF CODE GENERATED BY Argbash (sortof) ### ])
# [ <-- needed because of Argbash
set -eu
set -o pipefail
workdir="$(mktemp -d)"
chmod 0775 "$workdir" # vpdupdate refuses to create the db without this?
# vpdupdate unlinks files in the same directory as the target named
# vpd.db*, use separate directories
vpd_db_old="${workdir}/old/vpd.db"
vpd_db_new="${workdir}/new/vpd.db"
# Interested in detecting leaks from within librtas, but not vpd code.
leak_suppressions="${workdir}/suppressions.txt"
cat > "$leak_suppressions" <<EOF
leak:^lsvpd::SysFSTreeCollector::
EOF
# ASAN_OPTIONS=alloc_dealloc_mismatch=0 is for new[]/delete
# mismatches in vpdupdate code.
export LSAN_OPTIONS="suppressions=$leak_suppressions"
export ASAN_OPTIONS=alloc_dealloc_mismatch=0
preload_sanitizers=/lib64/libasan.so.8:/lib64/libubsan.so.1
export LD_PRELOAD="${preload_sanitizers}":"$_arg_old"
vpdupdate -p "$vpd_db_old"
test -s "$vpd_db_old" || {
echo "error: VPD database ${vpd_db_old} is empty!?"
exit 1
}
export LD_PRELOAD="${preload_sanitizers}":"$_arg_new"
vpdupdate -p "$vpd_db_new"
test -s "$vpd_db_new" || {
echo "error: VPD database ${vpd_db_new} is empty!?"
exit 1
}
export -n LSAN_OPTIONS ASAN_OPTIONS LD_PRELOAD
cmp "$vpd_db_old" "$vpd_db_new" || {
echo "error: VPD database ${vpd_db_old} differs from ${vpd_db_new}"
exit 1
}
sizes="${workdir}/sizes"
sums="${workdir}/sums"
du -h "$vpd_db_old" "$vpd_db_new" > "$sizes"
md5sum "$vpd_db_old" "$vpd_db_new" > "$sums"
join -j 2 "$sizes" "$sums"
echo "Tested $(type -P vpdupdate) with ${_arg_old} and ${_arg_new}, no differences detected."
test -d "$workdir" && rm -fr "$workdir"
# ] <-- needed because of Argbash