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