]> git.proxmox.com Git - swtpm.git/blame - tests/_test_tpm2_setbuffersize
swtpm: Disable fsync on file & dir due to TPM timeouts (issue #597)
[swtpm.git] / tests / _test_tpm2_setbuffersize
CommitLineData
3008874c
SB
1#!/bin/bash
2
3# For the license, see the LICENSE file in the root directory.
4#set -x
5
313cf75c
SB
6ROOT=${abs_top_builddir:-$(pwd)/..}
7TESTDIR=${abs_top_testdir:-$(dirname "$0")}
8
3008874c
SB
9VTPM_NAME="vtpm-test-tpm2-setbuffersize"
10SWTPM_DEV_NAME="/dev/${VTPM_NAME}"
11export TPM_PATH=$(mktemp -d)
12STATE_FILE=$TPM_PATH/tpm2-00.permall
13OUTFILE=$TPM_PATH/output
14VOLATILE_STATE_FILE=$TPM_PATH/tpm2-00.volatilestate
15SWTPM_CMD_UNIX_PATH=${TPM_PATH}/unix-cmd.sock
16SWTPM_CTRL_UNIX_PATH=${TPM_PATH}/unix-ctrl.sock
17SWTPM_INTERFACE=${SWTPM_INTERFACE:-cuse}
18
19function cleanup()
20{
21 pid=${SWTPM_PID}
22 if [ -n "$pid" ]; then
47c7ea77 23 kill_quiet -9 $pid
3008874c
SB
24 fi
25 rm -rf $TPM_PATH
26}
27
28trap "cleanup" EXIT
29
313cf75c
SB
30[ "${SWTPM_INTERFACE}" == cuse ] && source ${TESTDIR}/test_cuse
31source ${TESTDIR}/common
3008874c
SB
32
33rm -f $STATE_FILE $VOLATILE_STATE_FILE 2>/dev/null
34
35run_swtpm ${SWTPM_INTERFACE} --tpm2
36
47c7ea77 37kill_quiet -0 ${SWTPM_PID}
3008874c
SB
38if [ $? -ne 0 ]; then
39 echo "Error: ${SWTPM_INTERFACE} TPM did not start."
40 exit 1
41fi
42
43# Check the buffer size
44run_swtpm_ioctl ${SWTPM_INTERFACE} -b 0 > ${OUTFILE}
45if [ $? -ne 0 ]; then
46 echo "Error: Could not get the buffersize of the ${SWTPM_INTERFACE} TPM."
47 exit 1
48fi
49cat ${OUTFILE}
50
51if [ -z "$(grep "TPM buffersize" ${OUTFILE} | grep 4096)" ]; then
468f7e61 52 echo "Error: The TPM buffersize of the ${SWTPM_INTERFACE} TPM is not 4096."
3008874c
SB
53 exit 1
54fi
55
56# set the buffer size -- it's not going to change but command must not fail
57run_swtpm_ioctl ${SWTPM_INTERFACE} -b 4000 > ${OUTFILE}
58if [ $? -ne 0 ]; then
59 echo "Error: Could not set the buffersize of the ${SWTPM_INTERFACE} TPM."
60 exit 1
61fi
62cat ${OUTFILE}
63
64if [ -z "$(grep "TPM buffersize" ${OUTFILE} | grep 4000)" ]; then
468f7e61 65 echo "Error: Could not set the buffersize of the ${SWTPM_INTERFACE} TPM to 4000."
3008874c
SB
66 exit 1
67fi
68
69# Init the TPM
70run_swtpm_ioctl ${SWTPM_INTERFACE} -i
71if [ $? -ne 0 ]; then
72 echo "Error: Could not initialize the ${SWTPM_INTERFACE} TPM."
73 exit 1
74fi
75
47c7ea77 76kill_quiet -0 ${SWTPM_PID} 2>/dev/null
3008874c
SB
77if [ $? -ne 0 ]; then
78 echo "Error: ${SWTPM_INTERFACE} TPM not running anymore after INIT."
79 exit 1
80fi
81
82# Set the buffer size -- should fail
f759520c 83ERR="$(run_swtpm_ioctl ${SWTPM_INTERFACE} -b 4096 2>&1)"
3008874c
SB
84if [ $? -eq 0 ]; then
85 echo "Error: Could set the buffersize while the ${SWTPM_INTERFACE} TPM is running."
86 exit 1
87fi
f759520c
SB
88exp="TPM result from PTM_SET_BUFFERSIZE: 0xa"
89if [ "$ERR" != "$exp" ]; then
90 echo "Error: Unexpected error message"
91 echo "Received: $ERR"
92 echo "Expected: $exp"
93 exit 1
94fi
3008874c
SB
95
96# Startup the TPM2
97swtpm_open_cmddev ${SWTPM_INTERFACE} 100
98RES=$(swtpm_cmd_tx ${SWTPM_INTERFACE} '\x80\x01\x00\x00\x00\x0c\x00\x00\x01\x44\x00\x00')
99exp=' 80 01 00 00 00 0a 00 00 00 00'
100if [ "$RES" != "$exp" ]; then
101 echo "Error: Did not get expected result from TPM2_Startup(SU_Clear)"
102 echo "expected: $exp"
103 echo "received: $RES"
104 exit 1
105fi
106
107# Read the Buffer sizes; we want to see '4000' (0xfa0) in the buffer sizes now
108swtpm_open_cmddev ${SWTPM_INTERFACE} 100
109RES=$(swtpm_cmd_tx ${SWTPM_INTERFACE} '\x80\x01\x00\x00\x00\x16\x00\x00\x01\x7a\x00\x00\x00\x06\x00\x00\x01\x1e\x00\x00\x00\x02')
110exp=' 80 01 00 00 00 23 00 00 00 00 01 00 00 00 06 00 00 00 02 00 00 01 1e 00 00 0f a0 00 00 01 1f 00 00 0f a0'
111if [ "$RES" != "$exp" ]; then
112 echo "Error: Did not get expected result from TPM2_GetCapability()"
113 echo "expected: $exp"
114 echo "received: $RES"
115 exit 1
116fi
117
118run_swtpm_ioctl ${SWTPM_INTERFACE} -s
119if [ $? -ne 0 ]; then
120 echo "Error: Could not shut down the ${SWTPM_INTERFACE} TPM."
121 exit 1
122fi
123
45d2d092 124if wait_process_gone ${SWTPM_PID} 4; then
3008874c
SB
125 echo "Error: ${SWTPM_INTERFACE} TPM should not be running anymore."
126 exit 1
127fi
128
129if [ ! -e $STATE_FILE ]; then
130 echo "Error: TPM state file $STATE_FILE does not exist."
131 exit 1
132fi
133
134echo "OK"
135
136exit 0