]> git.proxmox.com Git - swtpm.git/blame - tests/_test_tpm2_getcap
tests: Apply patches to IBM TSS2 test suite
[swtpm.git] / tests / _test_tpm2_getcap
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-getcap"
10SWTPM_DEV_NAME="/dev/${VTPM_NAME}"
11export TPM_PATH=$(mktemp -d)
12STATE_FILE=$TPM_PATH/tpm2-00.permall
13VOLATILE_STATE_FILE=$TPM_PATH/tpm2-00.volatilestate
14SWTPM_INTERFACE=${SWTPM_INTERFACE:-cuse}
15SWTPM_CMD_UNIX_PATH=${TPM_PATH}/unix-cmd.sock
16SWTPM_CTRL_UNIX_PATH=${TPM_PATH}/unix-ctrl.sock
17
18function cleanup()
19{
20 pid=${SWTPM_PID}
21 if [ -n "$pid" ]; then
47c7ea77 22 kill_quiet -9 $pid
3008874c
SB
23 fi
24 rm -rf $TPM_PATH
25}
26
27trap "cleanup" EXIT
28
313cf75c
SB
29[ "${SWTPM_INTERFACE}" == "cuse" ] && source ${TESTDIR}/test_cuse
30source ${TESTDIR}/common
3008874c
SB
31
32rm -f $STATE_FILE $VOLATILE_STATE_FILE 2>/dev/null
33
34run_swtpm ${SWTPM_INTERFACE} --tpm2
35
100317d5 36display_processes_by_name "$SWTPM"
3008874c 37
47c7ea77 38kill_quiet -0 ${SWTPM_PID}
3008874c
SB
39if [ $? -ne 0 ]; then
40 echo "Error: ${SWTPM_INTERFACE} TPM did not start."
41 exit 1
42fi
43
44# Init the TPM
45run_swtpm_ioctl ${SWTPM_INTERFACE} -i
46if [ $? -ne 0 ]; then
47 echo "Error: Could not initialize the ${SWTPM_INTERFACE} TPM."
48 exit 1
49fi
50
47c7ea77 51kill_quiet -0 ${SWTPM_PID} 2>/dev/null
3008874c
SB
52if [ $? -ne 0 ]; then
53 echo "Error: ${SWTPM_INTERFACE} TPM not running anymore after INIT."
54 exit 1
55fi
56
57# Get the capabilities flags from the TPM
58act=$(run_swtpm_ioctl ${SWTPM_INTERFACE} -c)
59if [ $? -ne 0 ]; then
60 echo "Error: Could not get the capability flags of the ${SWTPM_INTERFACE} TPM."
61 exit 1
62fi
47c7ea77 63kill_quiet -0 ${SWTPM_PID} 2>/dev/null
3008874c
SB
64if [ $? -ne 0 ]; then
65 echo "Error: ${SWTPM_INTERFACE} TPM not running anymore after getting capabilities."
66 exit 1
67fi
68
69exp="ptm capability is 0x([[:xdigit:]]+)"
70if ! [[ "$act" =~ ^${exp}$ ]]; then
71 echo "Error: Expected string following regular expression '$exp' from ioctl tool but got '$act'."
72 exit 1
73fi
74
75run_swtpm_ioctl ${SWTPM_INTERFACE} -s
76if [ $? -ne 0 ]; then
77 echo "Error: Could not shut down the ${SWTPM_INTERFACE} TPM."
78 exit 1
79fi
80
45d2d092 81if wait_process_gone ${SWTPM_PID} 4; then
3008874c
SB
82 echo "Error: ${SWTPM_INTERFACE} TPM should not be running anymore."
83 exit 1
84fi
85
86if [ ! -e $STATE_FILE ]; then
87 echo "Error: TPM state file $STATE_FILE does not exist."
88 exit 1
89fi
90
91echo "OK"
92
93exit 0