]>
git.proxmox.com Git - swtpm.git/blob - tests/_test_tpm2_setbuffersize
3 # For the license, see the LICENSE file in the root directory.
6 ROOT
=${abs_top_builddir:-$(pwd)/..}
7 TESTDIR
=${abs_top_testdir:-$(dirname "$0")}
9 VTPM_NAME
="vtpm-test-tpm2-setbuffersize"
10 SWTPM_DEV_NAME
="/dev/${VTPM_NAME}"
11 export TPM_PATH
="$(mktemp -d)" ||
exit 1
12 STATE_FILE
=$TPM_PATH/tpm2-00.permall
13 OUTFILE
=$TPM_PATH/output
14 VOLATILE_STATE_FILE
=$TPM_PATH/tpm2-00.volatilestate
15 SWTPM_CMD_UNIX_PATH
=${TPM_PATH}/unix-cmd.sock
16 SWTPM_CTRL_UNIX_PATH
=${TPM_PATH}/unix-ctrl.sock
17 SWTPM_INTERFACE
=${SWTPM_INTERFACE:-cuse}
22 if [ -n "$pid" ]; then
30 [ "${SWTPM_INTERFACE}" == cuse
] && source ${TESTDIR}/test_cuse
31 source ${TESTDIR}/common
33 rm -f $STATE_FILE $VOLATILE_STATE_FILE 2>/dev
/null
35 run_swtpm
${SWTPM_INTERFACE} --tpm2
37 kill_quiet
-0 ${SWTPM_PID}
39 echo "Error: ${SWTPM_INTERFACE} TPM did not start."
43 # Check the buffer size
44 run_swtpm_ioctl
${SWTPM_INTERFACE} -b 0 > ${OUTFILE}
46 echo "Error: Could not get the buffersize of the ${SWTPM_INTERFACE} TPM."
51 if [ -z "$(grep "TPM buffersize
" ${OUTFILE} | grep 4096)" ]; then
52 echo "Error: The TPM buffersize of the ${SWTPM_INTERFACE} TPM is not 4096."
56 # set the buffer size -- it's not going to change but command must not fail
57 run_swtpm_ioctl
${SWTPM_INTERFACE} -b 4000 > ${OUTFILE}
59 echo "Error: Could not set the buffersize of the ${SWTPM_INTERFACE} TPM."
64 if [ -z "$(grep "TPM buffersize
" ${OUTFILE} | grep 4000)" ]; then
65 echo "Error: Could not set the buffersize of the ${SWTPM_INTERFACE} TPM to 4000."
70 run_swtpm_ioctl
${SWTPM_INTERFACE} -i
72 echo "Error: Could not initialize the ${SWTPM_INTERFACE} TPM."
76 kill_quiet
-0 ${SWTPM_PID} 2>/dev
/null
78 echo "Error: ${SWTPM_INTERFACE} TPM not running anymore after INIT."
82 # Set the buffer size -- should fail
83 ERR
="$(run_swtpm_ioctl ${SWTPM_INTERFACE} -b 4096 2>&1)"
85 echo "Error: Could set the buffersize while the ${SWTPM_INTERFACE} TPM is running."
88 exp
="TPM result from PTM_SET_BUFFERSIZE: 0xa"
89 if [ "$ERR" != "$exp" ]; then
90 echo "Error: Unexpected error message"
97 RES
=$
(swtpm_cmd_tx
${SWTPM_INTERFACE} '\x80\x01\x00\x00\x00\x0c\x00\x00\x01\x44\x00\x00')
98 exp
=' 80 01 00 00 00 0a 00 00 00 00'
99 if [ "$RES" != "$exp" ]; then
100 echo "Error: Did not get expected result from TPM2_Startup(SU_Clear)"
101 echo "expected: $exp"
102 echo "received: $RES"
106 # Read the Buffer sizes; we want to see '4000' (0xfa0) in the buffer sizes now
107 RES
=$
(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')
108 exp
=' 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'
109 if [ "$RES" != "$exp" ]; then
110 echo "Error: Did not get expected result from TPM2_GetCapability()"
111 echo "expected: $exp"
112 echo "received: $RES"
116 run_swtpm_ioctl
${SWTPM_INTERFACE} -s
117 if [ $?
-ne 0 ]; then
118 echo "Error: Could not shut down the ${SWTPM_INTERFACE} TPM."
122 if wait_process_gone
${SWTPM_PID} 4; then
123 echo "Error: ${SWTPM_INTERFACE} TPM should not be running anymore."
127 if [ ! -e $STATE_FILE ]; then
128 echo "Error: TPM state file $STATE_FILE does not exist."