From 597d06eeef8e14cb453e4b2323c59bf75ea676d3 Mon Sep 17 00:00:00 2001 From: Stefan Berger Date: Wed, 11 Oct 2017 14:27:38 -0400 Subject: [PATCH] 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 --- tests/_test_migration_key | 4 ++-- tests/common | 26 ++++++++++++++++++++++++++ 2 files changed, 28 insertions(+), 2 deletions(-) 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 +}