]> git.proxmox.com Git - swtpm.git/blob - tests/_test_setbuffersize
tests: Set test-check local user.name and user.email before git am
[swtpm.git] / tests / _test_setbuffersize
1 #!/bin/bash
2
3 # For the license, see the LICENSE file in the root directory.
4 # set -x
5
6 ROOT=${abs_top_builddir:-$(pwd)/..}
7 TESTDIR=${abs_top_testdir:-$(dirname "$0")}
8
9 VTPM_NAME="vtpm-test-setbuffersize"
10 SWTPM_DEV_NAME="/dev/${VTPM_NAME}"
11 export TPM_PATH=$(mktemp -d)
12 STATE_FILE=$TPM_PATH/tpm-00.permall
13 VOLATILE_STATE_FILE=$TPM_PATH/tpm-00.volatilestate
14 SWTPM_CMD_UNIX_PATH=${TPM_PATH}/unix-cmd.sock
15 SWTPM_CTRL_UNIX_PATH=${TPM_PATH}/unix-ctrl.sock
16 SWTPM_INTERFACE=${SWTPM_INTERFACE:-cuse}
17 OUTFILE=${TPM_PATH}/output
18
19 function cleanup()
20 {
21 pid=${SWTPM_PID}
22 if [ -n "$pid" ]; then
23 kill_quiet -9 $pid
24 fi
25 rm -rf $TPM_PATH
26 }
27
28 trap "cleanup" EXIT
29
30 [ "${SWTPM_INTERFACE}" == cuse ] && source ${TESTDIR}/test_cuse
31 source ${TESTDIR}/common
32
33 rm -f $STATE_FILE $VOLATILE_STATE_FILE 2>/dev/null
34
35 run_swtpm ${SWTPM_INTERFACE}
36
37 kill_quiet -0 ${SWTPM_PID}
38 if [ $? -ne 0 ]; then
39 echo "Error: ${SWTPM_INTERFACE} TPM did not start."
40 exit 1
41 fi
42
43 # Check the buffer size
44 run_swtpm_ioctl ${SWTPM_INTERFACE} -b 0 > ${OUTFILE}
45 if [ $? -ne 0 ]; then
46 echo "Error: Could not get the buffersize of the ${SWTPM_INTERFACE} TPM."
47 exit 1
48 fi
49 cat ${OUTFILE}
50
51 if [ -z "$(grep "TPM buffersize" ${OUTFILE} | grep 4096)" ]; then
52 echo "Error: The TPM buffersize of the ${SWTPM_INTERFACE} TPM is not 4096."
53 exit 1
54 fi
55
56 # set the buffer size
57 run_swtpm_ioctl ${SWTPM_INTERFACE} -b 4000 > ${OUTFILE}
58 if [ $? -ne 0 ]; then
59 echo "Error: Could not set the buffersize of the ${SWTPM_INTERFACE} TPM."
60 exit 1
61 fi
62 cat ${OUTFILE}
63
64 if [ -z "$(grep "TPM buffersize" ${OUTFILE} | grep 4000)" ]; then
65 echo "Error: The TPM buffersize of the ${SWTPM_INTERFACE} TPM is not 4000."
66 exit 1
67 fi
68
69 # Init the TPM
70 run_swtpm_ioctl ${SWTPM_INTERFACE} -i
71 if [ $? -ne 0 ]; then
72 echo "Error: Could not initialize the ${SWTPM_INTERFACE} TPM."
73 exit 1
74 fi
75
76 # Set the buffer size -- should fail
77 ERR="$(run_swtpm_ioctl ${SWTPM_INTERFACE} -b 4096 2>&1)"
78 if [ $? -eq 0 ]; then
79 echo "Error: Could set the buffersize while the ${SWTPM_INTERFACE} TPM is running."
80 exit 1
81 fi
82 exp="TPM result from PTM_SET_BUFFERSIZE: 0xa"
83 if [ "$ERR" != "$exp" ]; then
84 echo "Error: Unexpected error message"
85 echo "Received: $ERR"
86 echo "Expected: $exp"
87 exit 1
88 fi
89
90 kill_quiet -0 ${SWTPM_PID} 2>/dev/null
91 if [ $? -ne 0 ]; then
92 echo "Error: ${SWTPM_INTERFACE} TPM not running anymore after INIT."
93 exit 1
94 fi
95
96 run_swtpm_ioctl ${SWTPM_INTERFACE} -s
97 if [ $? -ne 0 ]; then
98 echo "Error: Could not shut down the ${SWTPM_INTERFACE} TPM."
99 exit 1
100 fi
101
102 if wait_process_gone ${SWTPM_PID} 4; then
103 echo "Error: ${SWTPM_INTERFACE} TPM should not be running anymore."
104 exit 1
105 fi
106
107 if [ ! -e $STATE_FILE ]; then
108 echo "Error: TPM state file $STATE_FILE does not exist."
109 exit 1
110 fi
111
112 echo "OK"
113
114 exit 0