]> git.proxmox.com Git - swtpm.git/blame - tests/_test_wrongorder
tests: Support filenames with spaces in some functions
[swtpm.git] / tests / _test_wrongorder
CommitLineData
01aa2ed3
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
01aa2ed3
SB
9VTPM_NAME="vtpm-test-wrongorder"
10SWTPM_DEV_NAME="/dev/${VTPM_NAME}"
cce7503c 11export TPM_PATH="$(mktemp -d)" || exit 1
01aa2ed3
SB
12STATE_FILE=$TPM_PATH/tpm-00.permall
13LOG_FILE=$TPM_PATH/tpm-00.log
14VOLATILE_STATE_FILE=$TPM_PATH/tpm-00.volatilestate
15SWTPM_CMD_UNIX_PATH=${TPM_PATH}/unix-cmd.sock
16SWTPM_CTRL_UNIX_PATH=${TPM_PATH}/unix-ctrl.sock
17SWTPM_INTERFACE=${SWTPM_INTERFACE:-cuse}
18
19function cleanup()
20{
21 pid=${SWTPM_PID}
22 if [ -n "$pid" ]; then
47c7ea77 23 kill_quiet -9 $pid
01aa2ed3
SB
24 fi
25 rm -rf $TPM_PATH
26}
27
28trap "cleanup" EXIT
29
313cf75c
SB
30[ "${SWTPM_INTERFACE}" == cuse ] && source ${TESTDIR}/test_cuse
31source ${TESTDIR}/common
32source ${TESTDIR}/test_common
01aa2ed3
SB
33
34rm -f $STATE_FILE $VOLATILE_STATE_FILE 2>/dev/null
35
36run_swtpm ${SWTPM_INTERFACE} --log file=$LOG_FILE,level=20
37
100317d5 38display_processes_by_name "$SWTPM"
01aa2ed3 39
47c7ea77 40kill_quiet -0 ${SWTPM_PID}
01aa2ed3
SB
41if [ $? -ne 0 ]; then
42 echo "Error: ${SWTPM_INTERFACE} TPM did not start."
43 exit 1
44fi
45
46if [ "${SWTPM_INTERFACE}" != "cuse" ]; then
47 run_swtpm_ioctl ${SWTPM_INTERFACE} --stop
48 if [ $? -ne 0 ]; then
49 echo "Error: Could not stop the ${SWTPM_INTERFACE} TPM"
50 exit 1
51 fi
52fi
53
54# Get the established bit before the TPM has been initialized
55# This should not work
56
57run_swtpm_ioctl ${SWTPM_INTERFACE} -e
58if [ $? -eq 0 ]; then
59 echo "Error: Could get established bit from ${SWTPM_INTERFACE} TPM before init."
60 exit 1
61fi
62
47c7ea77 63kill_quiet -0 ${SWTPM_PID}
01aa2ed3
SB
64if [ $? -ne 0 ]; then
65 echo "Error: ${SWTPM_INTERFACE} TPM must have crashed."
66 exit 1
67fi
68
69
70# Read PCR 17 -- this should give a fatal error response
71swtpm_open_cmddev ${SWTPM_INTERFACE} 100
72RES=$(swtpm_cmd_tx ${SWTPM_INTERFACE} '\x00\xC1\x00\x00\x00\x0E\x00\x00\x00\x15\x00\x00\x00\x11')
73exp=' 00 c4 00 00 00 0a 00 00 00 09'
74if [ "$RES" != "$exp" ]; then
75 echo "Error: Did not get expected result from TPM_PCRRead(17)"
76 echo "expected: $exp"
77 echo "received: $RES"
78 exit 1
79fi
80
81exec 100>&-
82
47c7ea77 83kill_quiet -0 ${SWTPM_PID}
01aa2ed3
SB
84if [ $? -ne 0 ]; then
85 echo "Error: ${SWTPM_INTERFACE} TPM must have crashed."
86 exit 1
87fi
88
89# Init the TPM
90run_swtpm_ioctl ${SWTPM_INTERFACE} -i
91if [ $? -ne 0 ]; then
92 echo "Error: Could not initialize the ${SWTPM_INTERFACE} TPM."
93 exit 1
94fi
95
47c7ea77 96kill_quiet -0 ${SWTPM_PID} 2>/dev/null
01aa2ed3
SB
97if [ $? -ne 0 ]; then
98 echo "Error: ${SWTPM_INTERFACE} TPM not running anymore after INIT."
99 exit 1
100fi
101
102run_swtpm_ioctl ${SWTPM_INTERFACE} -s
103if [ $? -ne 0 ]; then
104 echo "Error: Could not shut down the ${SWTPM_INTERFACE} TPM."
105 exit 1
106fi
107
45d2d092 108if wait_process_gone ${SWTPM_PID} 4; then
01aa2ed3
SB
109 echo "Error: ${SWTPM_INTERFACE} TPM should not be running anymore."
110 exit 1
111fi
112
113if [ ! -e $STATE_FILE ]; then
114 echo "Error: TPM state file $STATE_FILE does not exist."
115 exit 1
116fi
117
118check_logfile_patterns_level_20 $LOG_FILE
119rm -f $LOG_FILE
120
121echo "OK"
122
123exit 0