]> git.proxmox.com Git - swtpm.git/blame - tests/_test_print_capabilities
swtpm: Also advertise the flags-opt-startup option for the CUSE interface
[swtpm.git] / tests / _test_print_capabilities
CommitLineData
95bed8ce
SB
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
cc410ca9
SB
9PATH=$ROOT/src/swtpm:$PATH
10
95bed8ce
SB
11[ "${SWTPM_IFACE}" == "cuse" ] && source ${TESTDIR}/test_cuse
12source ${TESTDIR}/common
13
14msg="$(${SWTPM_EXE} ${SWTPM_IFACE} --print-capabilities 2>&1)"
15if [ $? -ne 0 ]; then
16 echo "Error: Could not pass --print-capabilities"
17 echo "${msg}"
18 exit 1
19fi
20
c359fed0 21if has_seccomp_support "${SWTPM_EXE}"; then
95bed8ce
SB
22 seccomp='"cmdarg-seccomp", '
23fi
24if [ "${SWTPM_IFACE}" != "cuse" ]; then
b3c32ed5 25 noncuse='"tpm-send-command-header", '
95bed8ce
SB
26fi
27
b3c32ed5 28exp='\{ "type": "swtpm", "features": \[ "tpm-1.2",( "tpm-2.0",)? '${noncuse}'"flags-opt-startup", '${seccomp}'"cmdarg-key-fd", "cmdarg-pwd-fd", "cmdarg-print-states", "nvram-backend-dir", "nvram-backend-file" \], "version": "[^"]*" \}'
da8752b1 29if ! [[ ${msg} =~ ${exp} ]]; then
95bed8ce
SB
30 echo "Unexpected response from ${SWTPM_IFACE} TPM to --print-capabilities:"
31 echo "Actual : ${msg}"
32 echo "Expected : ${exp}"
33 exit 1
34fi
35
0db8249c
SB
36echo "Test 1: OK"
37
38msg="$(${SWTPM_SETUP} --print-capabilities 2>&1)"
39if [ $? -ne 0 ]; then
40 echo "Error: Could not pass --print-capabilities"
41 echo "${msg}"
42 exit 1
43fi
44
1974f2ce 45# The are some variable parameters at the end, use regex
25d4ac2d 46exp='\{ "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": "[^"]*" \}'
1974f2ce 47if ! [[ ${msg} =~ ${exp} ]]; then
0db8249c
SB
48 echo "Unexpected response from ${SWTPM_SETUP} to --print-capabilities:"
49 echo "Actual : ${msg}"
50 echo "Expected : ${exp}"
51 exit 1
52fi
53
54echo "Test 2: OK"
95bed8ce 55
195353de
SB
56# SWTPM_CERT may be run by valgrind
57if [ -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
88c7bdc9 64
155ccdf5
MAL
65 exp='\{ "type": "swtpm_cert", "features": \[ "cmdarg-signkey-pwd", "cmdarg-parentkey-pwd" \], "version": "[^"]*" \}'
66 if ! [[ "${msg}" =~ ${exp} ]]; then
195353de
SB
67 echo "Unexpected response from ${SWTPM_CERT} to --print-capabilities:"
68 echo "Actual : ${msg}"
69 echo "Expected : ${exp}"
70 exit 1
71 fi
88c7bdc9 72
195353de
SB
73 echo "Test 3: OK"
74else
a9358619 75 echo "Test 3: SKIP -- ${SWTPM_CERT} not found or not an executable"
195353de 76fi
88c7bdc9 77
95bed8ce 78exit 0