]> git.proxmox.com Git - swtpm.git/blame - tests/_test_tpm2_print_states
packaging: track dbgsym package for swtpm-libs and swtpm-tools
[swtpm.git] / tests / _test_tpm2_print_states
CommitLineData
5bc59a74
ET
1#!/bin/bash
2
3# For the license, see the LICENSE file in the root directory.
4#set -x
5
6ROOT=${abs_top_builddir:-$(pwd)/..}
7TESTDIR=${abs_top_testdir:-$(dirname "$0")}
8
9PATH=$ROOT/src/swtpm:$PATH
10
11[ "${SWTPM_IFACE}" == "cuse" ] && source ${TESTDIR}/test_cuse
12source ${TESTDIR}/common
13
14trap "cleanup" SIGTERM EXIT
15
16function cleanup()
17{
cce7503c 18 rm -rf "${workdir}"
5bc59a74
ET
19}
20
21# Test 1: No states
22
cce7503c 23workdir="$(mktemp -d)" || exit 1
5bc59a74
ET
24msg="$(${SWTPM_EXE} ${SWTPM_IFACE} --print-states --tpm2 --tpmstate dir=${workdir} 2>&1)"
25
26if [ $? -ne 0 ]; then
27 echo "Error: Could not pass --print-states"
28 echo "${msg}"
29 exit 1
30fi
31
32exp='\{ "type": "swtpm", "states": \[\] \}'
33if ! [[ ${msg} =~ ${exp} ]]; then
34 echo "Unexpected response from ${SWTPM_IFACE} TPM to --print-states:"
35 echo "Actual : ${msg}"
36 echo "Expected : ${exp}"
37 echo "Test 1: Failed"
38 exit 1
39fi
40
41echo "Test 1: OK"
42cleanup
43
44# Test 2: Existing state
45
cce7503c 46workdir="$(mktemp -d)" || exit 1
5bc59a74
ET
47statefile="${workdir}/tpm2-00.permall"
48dummydata="DUMMY"
49echo $dummydata > ${statefile}
50
51msg="$(${SWTPM_EXE} ${SWTPM_IFACE} --print-states --tpm2 --tpmstate dir=${workdir} 2>&1)"
52
53if [ $? -ne 0 ]; then
54 echo "Error: Could not pass --print-states"
55 echo "${msg}"
56 exit 1
57fi
58
2fdb7c30 59exp='\{ "type": "swtpm", "states": \[ \{"name": "permall", "size": 6\} \] \}'
5bc59a74
ET
60if ! [[ ${msg} =~ ${exp} ]]; then
61 echo "Unexpected response from ${SWTPM_IFACE} TPM to --print-states:"
62 echo "Actual : ${msg}"
63 echo "Expected : ${exp}"
64 exit 1
65fi
66
67echo "Test 2: OK"
68cleanup
69
70exit 0