]> git.proxmox.com Git - swtpm.git/blob - tests/_test_print_capabilities
packaging: track dbgsym package for swtpm-libs and swtpm-tools
[swtpm.git] / tests / _test_print_capabilities
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 msg="$(${SWTPM_EXE} ${SWTPM_IFACE} --print-capabilities 2>&1)"
15 if [ $? -ne 0 ]; then
16 echo "Error: Could not pass --print-capabilities"
17 echo "${msg}"
18 exit 1
19 fi
20
21 if has_seccomp_support "${SWTPM_EXE}"; then
22 seccomp='"cmdarg-seccomp", '
23 fi
24 if [ "${SWTPM_IFACE}" != "cuse" ]; then
25 noncuse='"tpm-send-command-header", '
26 fi
27
28 exp='\{ "type": "swtpm", "features": \[ "tpm-1.2",( "tpm-2.0",)? '${noncuse}'"flags-opt-startup", "flags-opt-disable-auto-shutdown", "ctrl-opt-terminate", '${seccomp}'"cmdarg-key-fd", "cmdarg-pwd-fd", "cmdarg-print-states", "cmdarg-chroot", "cmdarg-migration", "nvram-backend-dir", "nvram-backend-file" \], "version": "[^"]*" \}'
29 if ! [[ ${msg} =~ ${exp} ]]; then
30 echo "Unexpected response from ${SWTPM_IFACE} TPM to --print-capabilities:"
31 echo "Actual : ${msg}"
32 echo "Expected : ${exp}"
33 exit 1
34 fi
35
36 echo "Test 1: OK"
37
38 msg="$(${SWTPM_SETUP} --print-capabilities 2>&1)"
39 if [ $? -ne 0 ]; then
40 echo "Error: Could not pass --print-capabilities"
41 echo "${msg}"
42 exit 1
43 fi
44
45 # The are some variable parameters at the end, use regex
46 exp='\{ "type": "swtpm_setup", "features": \[ "tpm-1.2",( "tpm-2.0",)? "cmdarg-keyfile-fd", "cmdarg-pwdfile-fd", "tpm12-not-need-root", "cmdarg-write-ek-cert-files", "cmdarg-create-config-files", "cmdarg-reconfigure-pcr-banks"(, "tpm2-rsa-keysize-2048")?(, "tpm2-rsa-keysize-3072")? \], "version": "[^"]*" \}'
47 if ! [[ ${msg} =~ ${exp} ]]; then
48 echo "Unexpected response from ${SWTPM_SETUP} to --print-capabilities:"
49 echo "Actual : ${msg}"
50 echo "Expected : ${exp}"
51 exit 1
52 fi
53
54 echo "Test 2: OK"
55
56 # SWTPM_CERT may be run by valgrind
57 if [ -x "$(type -P $(echo "${SWTPM_CERT}" | cut -d" " -f1) )" ]; then
58 msg="$(${SWTPM_CERT} --print-capabilities 2>&1)"
59 if [ $? -ne 0 ]; then
60 echo "Error: Could not pass --print-capabilities to ${SWTPM_CERT}"
61 echo "${msg}"
62 exit 1
63 fi
64
65 exp='\{ "type": "swtpm_cert", "features": \[ "cmdarg-signkey-pwd", "cmdarg-parentkey-pwd" \], "version": "[^"]*" \}'
66 if ! [[ "${msg}" =~ ${exp} ]]; then
67 echo "Unexpected response from ${SWTPM_CERT} to --print-capabilities:"
68 echo "Actual : ${msg}"
69 echo "Expected : ${exp}"
70 exit 1
71 fi
72
73 echo "Test 3: OK"
74 else
75 echo "Test 3: SKIP -- ${SWTPM_CERT} not found or not an executable"
76 fi
77
78 exit 0