swtpm/tests/test_tpm2_save_load_state_2_block
Stefan Berger 0bee3d2f5e tests: Use /usr/bin/env bash rather than /bin/bash (BSDs)
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2021-10-05 13:50:45 -04:00

37 lines
706 B
Bash
Executable File

#!/usr/bin/env bash
if ! [[ "$(uname -s)" =~ Linux ]]; then
echo "This test currently only runs on Linux."
exit 77
fi
if [ "$(id -u)" -ne 0 ]; then
echo "Need to be root to run this test."
exit 77
fi
STATEDIR=$(mktemp -d)
STATEIMG=$STATEDIR/tpm2.img
STATEFILE=""
trap "cleanup" SIGTERM EXIT
function cleanup()
{
rm -rf $STATEDIR
if [ -n "$STATEFILE" ]; then
losetup -d $STATEFILE
fi
}
# allocate 4 MiB file
fallocate -x -l $((4 * 1024 * 1024)) "$STATEIMG"
# and loop mount it
STATEFILE=$(losetup --show -f $STATEIMG)
export SWTPM_TEST_LINEAR_FILE=1
export TPM_COMMAND_PORT=65462
export STATEFILE
# don't exec so cleanup will remove the loop device
$(dirname $0)/test_tpm2_save_load_state_2