diff --git a/tests/_test_migration_key b/tests/_test_migration_key index 3b6db9a..c5b1cc3 100755 --- a/tests/_test_migration_key +++ b/tests/_test_migration_key @@ -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." diff --git a/tests/common b/tests/common index 6c66c70..733f9ce 100644 --- a/tests/common +++ b/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 +}