blob: cc151ff3c6af3f07716f7e03e235a6c4b6fe3450 [file] [log] [blame]
#!/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)" || exit 1
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