]> git.proxmox.com Git - swtpm.git/blame - tests/test_ctrlchannel4
tests: Set test-check local user.name and user.email before git am
[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
1eef338e
SB
8TPMDIR=`mktemp -d`
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
1eef338e
SB
27
28# Test 1: test the control channel on the chardev tpm
29
30exec 100<>/dev/ptmx
31$SWTPM_EXE chardev \
32 --fd 100 \
33 --tpmstate dir=$TPMDIR \
34 --pid file=$PID_FILE \
35 --ctrl type=unixio,path=$SWTPM_CTRL_UNIX_PATH \
930c7ba1
SB
36 --log file=$LOG_FILE,level=20 \
37 ${SWTPM_TEST_SECCOMP_OPT} &
1eef338e
SB
38
39exec 100>&-
40
41if wait_for_file $PID_FILE 3; then
42 echo "Error: Chardev TPM did not write pidfile."
43 exit 1
44fi
45
46PID="$(cat $PID_FILE)"
47
48# Get the capability bits: CMD_GET_CAPABILITY = 0x00 00 00 01
49res="$(swtpm_ctrl_tx ${SWTPM_INTERFACE} '\x00\x00\x00\x01')"
2b8a668d 50exp=" 00 00 00 00 00 00 7f ff"
1eef338e
SB
51if [ "$res" != "$exp" ]; then
52 echo "Error: Unexpected response from CMD_GET_CAPABILITY:"
53 echo " actual : $res"
54 echo " expected: $exp"
55 exit 1
56fi
57
58# Send TPM_Init to the TPM: CMD_INIT = 0x00 00 00 02 + flags
59res="$(swtpm_ctrl_tx ${SWTPM_INTERFACE} '\x00\x00\x00\x02\x00\x00\x00\x00')"
60exp=" 00 00 00 00"
61if [ "$res" != "$exp" ]; then
62 echo "Error: Unexpected response from CMD_INIT:"
63 echo " actual : $res"
64 echo " expected: $exp"
65 exit 1
66fi
67
68# Send unknown command to the TPM
69res="$(swtpm_ctrl_tx ${SWTPM_INTERFACE} '\x00\x00\xff\xff')"
70exp=" 00 00 00 0a"
71if [ "$res" != "$exp" ]; then
72 echo "Error: Unexpected response from sending unsupported command:"
73 echo " actual : $res"
74 echo " expected: $exp"
75 exit 1
76fi
77
78# Save the volatile state: CMD_STORE_VOLATILE = 0x00 00 00 0a
79res="$(swtpm_ctrl_tx ${SWTPM_INTERFACE} '\x00\x00\x00\x0a')"
80exp=" 00 00 00 00"
81if [ "$res" != "$exp" ]; then
82 echo "Error: Unexpected response from CMD_STORE_VOLATILE:"
83 echo " actual : $res"
84 echo " expected: $exp"
85 exit 1
86fi
87
88if [ ! -r $TPMDIR/tpm-00.volatilestate ]; then
89 echo "Error: Socket TPM: Did not write volatile state file"
90 exit 1
91fi
92
93# Send stop command to the TPM: CMD_STOP = 00 00 00 0e
94res="$(swtpm_ctrl_tx ${SWTPM_INTERFACE} '\x00\x00\x00\x0e')"
95exp=" 00 00 00 00"
96if [ "$res" != "$exp" ]; then
97 echo "Error: Socket TPM: Unexpected response from CMD_STOP:"
98 echo " actual : $res"
99 echo " expected: $exp"
100 exit 1
101fi
102
103# Send get config command to the TPM: CMD_GET_CONFIG = 00 00 00 0f
104res="$(swtpm_ctrl_tx ${SWTPM_INTERFACE} '\x00\x00\x00\x0f')"
105exp=" 00 00 00 00 00 00 00 00"
106if [ "$res" != "$exp" ]; then
107 echo "Error: Socket TPM: Unexpected response from CMD_GET_CONFIG:"
108 echo " actual : $res"
109 echo " expected: $exp"
110 exit 1
111fi
112
113# Send shutdown command to the TPM: CMD_SHUTDOWN = 00 00 00 03
114res="$(swtpm_ctrl_tx ${SWTPM_INTERFACE} '\x00\x00\x00\x03')"
115exp=" 00 00 00 00"
116if [ "$res" != "$exp" ]; then
117 echo "Error: Unexpected response from CMD_SHUTDOWN:"
118 echo " actual : $res"
119 echo " expected: $exp"
120 exit 1
121fi
122
45d2d092 123if wait_process_gone ${PID} 4; then
1eef338e
SB
124 echo "Error: TPM should not be running anymore."
125 exit 1
126fi
127
ead37845
SB
128if wait_file_gone $PID_FILE 2; then
129 echo "Error: TPM should have removed PID file by now."
1eef338e
SB
130 exit 1
131fi
132
133check_logfile_patterns_level_20 $LOG_FILE
134rm -f $LOG_FILE
135
136echo "OK"