]> git.proxmox.com Git - swtpm.git/blame - tests/_test_tpm_probe
packaging: track dbgsym package for swtpm-libs and swtpm-tools
[swtpm.git] / tests / _test_tpm_probe
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")}
3008874c 8
3008874c
SB
9VTPM_NAME="vtpm-test-tpm-probe"
10SWTPM_DEV_NAME="/dev/${VTPM_NAME}"
cce7503c 11export TPM_PATH="$(mktemp -d)" || exit 1
3008874c
SB
12STATE_FILE=$TPM_PATH/tpm-00.permall
13VOLATILE_STATE_FILE=$TPM_PATH/tpm-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}
35
100317d5 36display_processes_by_name "$SWTPM"
3008874c
SB
37
38kill -0 ${SWTPM_PID}
39if [ $? -ne 0 ]; then
40 echo "Error: ${SWTPM_INTERFACE} TPM did not start."
41 exit 1
42fi
43
3008874c
SB
44# Before TPM_INIT: Read PCR 17 -- this gives a TPM_FAIL
45RES=$(swtpm_cmd_tx ${SWTPM_INTERFACE} '\x00\xC1\x00\x00\x00\x0E\x00\x00\x00\x15\x00\x00\x00\x11')
46exp=' 00 c4 00 00 00 0a 00 00 00 09'
47if [ "$RES" != "$exp" ]; then
48 echo "Error: Before TPM_INIT: Did not get expected result from TPM_PCRRead(17)"
49 echo "expected: $exp"
50 echo "received: $RES"
51 exit 1
52fi
53
54# Init the TPM
55run_swtpm_ioctl ${SWTPM_INTERFACE} -i
56
57# Read PCR 17 -- this should give TPM_INVALID_POSTINIT
3008874c
SB
58RES=$(swtpm_cmd_tx ${SWTPM_INTERFACE} '\x00\xC1\x00\x00\x00\x0E\x00\x00\x00\x15\x00\x00\x00\x11')
59exp=' 00 c4 00 00 00 0a 00 00 00 26'
60if [ "$RES" != "$exp" ]; then
61 echo "Error: Did not get expected result from TPM_PCRRead(17)"
62 echo "expected: $exp"
63 echo "received: $RES"
64 exit 1
65fi
66
a3820b86
SB
67check_seccomp_profile "${SWTPM_EXE}" "${SWTPM_PID}" 2
68if [ $? -ne 0 ]; then
69 exit 1
70fi
71
148010c0
SB
72run_swtpm_ioctl ${SWTPM_INTERFACE} -s
73if [ $? -ne 0 ]; then
74 echo "Error: Could not shut down the ${SWTPM_INTERFACE} TPM."
75 exit 1
76fi
77
78if wait_process_gone ${SWTPM_PID} 4; then
79 echo "Error: ${SWTPM_INTERFACE} TPM should not be running anymore."
80 exit 1
81fi
82
3008874c
SB
83echo "OK"
84
85exit 0