tests: wrap sha1 and file size tools

OpenBSD uses different tools for sha1 and file size calculations,
so we wrap them in functions and check which one to call by using
uname -s.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
This commit is contained in:
Stefan Berger 2017-10-11 14:27:38 -04:00 committed by Stefan Berger
parent 415bf5563d
commit 597d06eeef
2 changed files with 28 additions and 2 deletions

View File

@ -126,7 +126,7 @@ if [ ! -r $volatilestatefile ]; then
fi
#ls -l $volatilestatefile
size=$(stat -c%s $volatilestatefile)
size=$(get_filesize $volatilestate)
expsize=1290
if [ $size -ne $expsize ]; then
echo "Error: Unexpected size of volatile state file."
@ -134,7 +134,7 @@ if [ $size -ne $expsize ]; then
exit 1
fi
hash=$(sha1sum $volatilestatefile | cut -f1 -d" ")
hash=$(get_sha1_file $volatilestatefile)
exphash="bafa4b918745dee45537484f1a1089f9967b7df7"
if [ "$hash" != "$exphash" ]; then
echo "Error: The checksum of the volatile state file is wrong."

View File

@ -304,3 +304,29 @@ function run_swtpm_bios()
exit 1
esac
}
# Get the size of a file in bytes
#
# @1: filename
function get_filesize()
{
if [[ "$(uname -s)" =~ (Linux|CYGWIN_NT-) ]]; then
stat -c%s $1
else
# OpenBSD
stat -f%z $1
fi
}
# Get the SHA1 of a file
#
# @1: filename
function get_sha1_file()
{
if [[ "$(uname -s)" =~ (Linux|CYGWIN_NT-) ]]; then
sha1sum $volatilestatefile | cut -f1 -d" "
else
# OpenBSD
sha1 $1 | cut -d "=" -f2 | tr -d " "
fi
}