mirror of
https://github.com/stefanberger/swtpm.git
synced 2026-01-16 06:17:52 +00:00
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:
parent
415bf5563d
commit
597d06eeef
@ -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."
|
||||
|
||||
26
tests/common
26
tests/common
@ -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
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user