]> git.proxmox.com Git - swtpm.git/blob - tests/test_tpm2_save_load_state_2_block
swtpm: Use sys/mount.h and support block devs only if BLKGETSIZE64 exists
[swtpm.git] / tests / test_tpm2_save_load_state_2_block
1 #!/bin/bash
2
3 if ! [[ "$(uname -s)" =~ Linux ]]; then
4 echo "This test currently only runs on Linux."
5 exit 77
6 fi
7
8 if [ "$(id -u)" -ne 0 ]; then
9 echo "Need to be root to run this test."
10 exit 77
11 fi
12
13 STATEDIR=$(mktemp -d)
14 STATEIMG=$STATEDIR/tpm2.img
15 STATEFILE=""
16
17 trap "cleanup" SIGTERM EXIT
18 function cleanup()
19 {
20 rm -rf $STATEDIR
21 if [ -n "$STATEFILE" ]; then
22 losetup -d $STATEFILE
23 fi
24 }
25
26 # allocate 4 MiB file
27 fallocate -x -l $((4 * 1024 * 1024)) "$STATEIMG"
28 # and loop mount it
29 STATEFILE=$(losetup --show -f $STATEIMG)
30
31 export SWTPM_TEST_LINEAR_FILE=1
32 export TPM_COMMAND_PORT=65462
33 export STATEFILE
34
35 # don't exec so cleanup will remove the loop device
36 $(dirname $0)/test_tpm2_save_load_state_2