]>
Commit | Line | Data |
---|---|---|
5bc59a74 ET |
1 | #!/bin/bash |
2 | ||
3 | # For the license, see the LICENSE file in the root directory. | |
4 | #set -x | |
5 | ||
6 | ROOT=${abs_top_builddir:-$(pwd)/..} | |
7 | TESTDIR=${abs_top_testdir:-$(dirname "$0")} | |
8 | ||
9 | PATH=$ROOT/src/swtpm:$PATH | |
10 | ||
11 | [ "${SWTPM_IFACE}" == "cuse" ] && source ${TESTDIR}/test_cuse | |
12 | source ${TESTDIR}/common | |
13 | ||
14 | trap "cleanup" SIGTERM EXIT | |
15 | ||
16 | function cleanup() | |
17 | { | |
cce7503c | 18 | rm -rf "${workdir}" |
5bc59a74 ET |
19 | } |
20 | ||
21 | # Test 1: No states | |
22 | ||
cce7503c | 23 | workdir="$(mktemp -d)" || exit 1 |
5bc59a74 ET |
24 | msg="$(${SWTPM_EXE} ${SWTPM_IFACE} --print-states --tpm2 --tpmstate dir=${workdir} 2>&1)" |
25 | ||
26 | if [ $? -ne 0 ]; then | |
27 | echo "Error: Could not pass --print-states" | |
28 | echo "${msg}" | |
29 | exit 1 | |
30 | fi | |
31 | ||
32 | exp='\{ "type": "swtpm", "states": \[\] \}' | |
33 | if ! [[ ${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 | |
39 | fi | |
40 | ||
41 | echo "Test 1: OK" | |
42 | cleanup | |
43 | ||
44 | # Test 2: Existing state | |
45 | ||
cce7503c | 46 | workdir="$(mktemp -d)" || exit 1 |
5bc59a74 ET |
47 | statefile="${workdir}/tpm2-00.permall" |
48 | dummydata="DUMMY" | |
49 | echo $dummydata > ${statefile} | |
50 | ||
51 | msg="$(${SWTPM_EXE} ${SWTPM_IFACE} --print-states --tpm2 --tpmstate dir=${workdir} 2>&1)" | |
52 | ||
53 | if [ $? -ne 0 ]; then | |
54 | echo "Error: Could not pass --print-states" | |
55 | echo "${msg}" | |
56 | exit 1 | |
57 | fi | |
58 | ||
2fdb7c30 | 59 | exp='\{ "type": "swtpm", "states": \[ \{"name": "permall", "size": 6\} \] \}' |
5bc59a74 ET |
60 | if ! [[ ${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 | |
65 | fi | |
66 | ||
67 | echo "Test 2: OK" | |
68 | cleanup | |
69 | ||
70 | exit 0 |