swtpm/tests/test_tpm2_save_load_state_2_block
Stefan Berger cce7503cbf tests: exit with error code if mktemp fails
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2021-11-02 08:35:49 -04:00

37 lines
718 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)" || 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