]> git.proxmox.com Git - swtpm.git/blame - tests/test_ctrlchannel4
tests: Support filenames with spaces in some functions
[swtpm.git] / tests / test_ctrlchannel4
CommitLineData
8f0f381f 1#!/usr/bin/env bash
1eef338e
SB
2
3# For the license, see the LICENSE file in the root directory.
4
313cf75c
SB
5ROOT=${abs_top_builddir:-$(dirname "$0")/..}
6TESTDIR=${abs_top_testdir:-$(dirname "$0")}
7
cce7503c 8TPMDIR="$(mktemp -d)" || exit 1
1eef338e
SB
9SWTPM_CTRL_UNIX_PATH=$TPMDIR/sock
10PID_FILE=$TPMDIR/swtpm.pid
11LOG_FILE=$TPMDIR/swtpm.log
12
313cf75c 13source ${TESTDIR}/test_common
1eef338e
SB
14
15trap "cleanup" SIGTERM EXIT
16
17function cleanup()
18{
19 rm -rf $TPMDIR
20 if [ -n "$PID" ]; then
47c7ea77 21 kill_quiet -SIGTERM $PID 2>/dev/null
1eef338e
SB
22 fi
23}
24
25SWTPM_INTERFACE=socket+unix
313cf75c 26source ${TESTDIR}/common
346dc3d5 27skip_test_no_chardev "${SWTPM_EXE}"
f1adde9f 28skip_test_no_tpm12 "${SWTPM_EXE}"
1eef338e
SB
29
30# Test 1: test the control channel on the chardev tpm
31
32exec 100<>/dev/ptmx
33$SWTPM_EXE chardev \
34 --fd 100 \
35 --tpmstate dir=$TPMDIR \
36 --pid file=$PID_FILE \
37 --ctrl type=unixio,path=$SWTPM_CTRL_UNIX_PATH \
930c7ba1
SB
38 --log file=$LOG_FILE,level=20 \
39 ${SWTPM_TEST_SECCOMP_OPT} &
1eef338e
SB
40
41exec 100>&-
42
43if wait_for_file $PID_FILE 3; then
44 echo "Error: Chardev TPM did not write pidfile."
45 exit 1
46fi
47
48PID="$(cat $PID_FILE)"
49
50# Get the capability bits: CMD_GET_CAPABILITY = 0x00 00 00 01
51res="$(swtpm_ctrl_tx ${SWTPM_INTERFACE} '\x00\x00\x00\x01')"
2b8a668d 52exp=" 00 00 00 00 00 00 7f ff"
1eef338e
SB
53if [ "$res" != "$exp" ]; then
54 echo "Error: Unexpected response from CMD_GET_CAPABILITY:"
55 echo " actual : $res"
56 echo " expected: $exp"
57 exit 1
58fi
59
60# Send TPM_Init to the TPM: CMD_INIT = 0x00 00 00 02 + flags
61res="$(swtpm_ctrl_tx ${SWTPM_INTERFACE} '\x00\x00\x00\x02\x00\x00\x00\x00')"
62exp=" 00 00 00 00"
63if [ "$res" != "$exp" ]; then
64 echo "Error: Unexpected response from CMD_INIT:"
65 echo " actual : $res"
66 echo " expected: $exp"
67 exit 1
68fi
69
70# Send unknown command to the TPM
71res="$(swtpm_ctrl_tx ${SWTPM_INTERFACE} '\x00\x00\xff\xff')"
72exp=" 00 00 00 0a"
73if [ "$res" != "$exp" ]; then
74 echo "Error: Unexpected response from sending unsupported command:"
75 echo " actual : $res"
76 echo " expected: $exp"
77 exit 1
78fi
79
80# Save the volatile state: CMD_STORE_VOLATILE = 0x00 00 00 0a
81res="$(swtpm_ctrl_tx ${SWTPM_INTERFACE} '\x00\x00\x00\x0a')"
82exp=" 00 00 00 00"
83if [ "$res" != "$exp" ]; then
84 echo "Error: Unexpected response from CMD_STORE_VOLATILE:"
85 echo " actual : $res"
86 echo " expected: $exp"
87 exit 1
88fi
89
90if [ ! -r $TPMDIR/tpm-00.volatilestate ]; then
91 echo "Error: Socket TPM: Did not write volatile state file"
92 exit 1
93fi
94
95# Send stop command to the TPM: CMD_STOP = 00 00 00 0e
96res="$(swtpm_ctrl_tx ${SWTPM_INTERFACE} '\x00\x00\x00\x0e')"
97exp=" 00 00 00 00"
98if [ "$res" != "$exp" ]; then
99 echo "Error: Socket TPM: Unexpected response from CMD_STOP:"
100 echo " actual : $res"
101 echo " expected: $exp"
102 exit 1
103fi
104
105# Send get config command to the TPM: CMD_GET_CONFIG = 00 00 00 0f
106res="$(swtpm_ctrl_tx ${SWTPM_INTERFACE} '\x00\x00\x00\x0f')"
107exp=" 00 00 00 00 00 00 00 00"
108if [ "$res" != "$exp" ]; then
109 echo "Error: Socket TPM: Unexpected response from CMD_GET_CONFIG:"
110 echo " actual : $res"
111 echo " expected: $exp"
112 exit 1
113fi
114
115# Send shutdown command to the TPM: CMD_SHUTDOWN = 00 00 00 03
116res="$(swtpm_ctrl_tx ${SWTPM_INTERFACE} '\x00\x00\x00\x03')"
117exp=" 00 00 00 00"
118if [ "$res" != "$exp" ]; then
119 echo "Error: Unexpected response from CMD_SHUTDOWN:"
120 echo " actual : $res"
121 echo " expected: $exp"
122 exit 1
123fi
124
45d2d092 125if wait_process_gone ${PID} 4; then
1eef338e
SB
126 echo "Error: TPM should not be running anymore."
127 exit 1
128fi
129
ead37845
SB
130if wait_file_gone $PID_FILE 2; then
131 echo "Error: TPM should have removed PID file by now."
1eef338e
SB
132 exit 1
133fi
134
135check_logfile_patterns_level_20 $LOG_FILE
136rm -f $LOG_FILE
137
138echo "OK"