]> git.proxmox.com Git - swtpm.git/blame - tests/test_tpm2_ibmtss2
tests: Apply patches to IBM TSS2 test suite
[swtpm.git] / tests / test_tpm2_ibmtss2
CommitLineData
03c7fe45
SB
1#!/usr/bin/env bash
2
3if [ ${SWTPM_TEST_EXPENSIVE:-0} -eq 0 ]; then
4 exit 77
5fi
6
7ROOT=${abs_top_builddir:-$(pwd)/..}
8TESTDIR=${abs_top_testdir:-$(dirname "$0")}
605e823f 9ABSTESTDIR=$(cd ${TESTDIR} &>/dev/null;echo ${PWD})
03c7fe45 10
e78c9db2
SB
11PATCHESDIR=${ABSTESTDIR}/patches
12
03c7fe45 13SWTPM_SERVER_PORT=65426
3e7555c4 14SWTPM_SERVER_NAME=127.0.0.1
03c7fe45
SB
15SWTPM_CTRL_PORT=65427
16SWTPM_INTERFACE=socket+socket
17
18function cleanup() {
19 pid=${SWTPM_PID}
20 if [ -n "$pid" ]; then
21 kill_quiet -9 $pid
22 fi
23 if [ -n ${WORKDIR} ]; then
24 rm -rf ${WORKDIR}
25 fi
26}
27
28trap "cleanup" EXIT
29
30source ${TESTDIR}/common
31WORKDIR=$(mktemp -d)
32
33REGLOG=${WORKDIR}/reglog
34
35SWTPM_SERVER_NO_DISCONNECT="1" run_swtpm ${SWTPM_INTERFACE} \
36 --tpm2 \
37 --tpmstate dir=${WORKDIR} \
38 --flags not-need-init
39
40pushd ${WORKDIR} &>/dev/null
41
42git clone https://git.code.sf.net/p/ibmtpm20tss/tss ibmtpm20tss-tss
43
4ba6012c 44pushd ibmtpm20tss-tss &>/dev/null
03c7fe45 45
4d4d24fb 46git checkout tags/v1.6.0
03c7fe45
SB
47if [ $? -ne 0 ]; then
48 echo "'Git checkout' failed."
49 exit 1
50fi
51
4d4d24fb 52# A v1.6.0 bug work-around:
8415d39d
SB
53# We cannot run the EK certificate tests since rootcerts.txt points to
54# files we do not have
e78c9db2 55git am < ${PATCHESDIR}/0001-Deactivate-test-cases-accessing-rootcerts.txt.patch
8415d39d 56
e78c9db2
SB
57# Implement 'powerup' for swtpm
58git am < ${PATCHESDIR}/0002-Implement-powerup-for-swtpm.patch
4ba6012c 59
e78c9db2
SB
60# set CRYPTOLIBRARY=openssl
61git am < ${PATCHESDIR}/0003-Set-CRYPTOLIBRARY-to-openssl.patch
62
63# Store volatile state at every step
64git am < ${PATCHESDIR}/0004-Store-volatile-state-at-every-step.patch
65
66# Disable 'Events' test
67git am < ${PATCHESDIR}/0005-Disable-tests-related-to-events.patch
8dc2415d 68
605e823f
SB
69rsa3072=$(run_swtpm_ioctl ${SWTPM_INTERFACE} --info 4 |
70 sed -n 's/.*"RSAKeySizes":\[\([0-9,]*\)\].*/\1/p' |
71 grep 3072)
72if [ -z "$rsa3072" ]; then
73 echo "Modifying test cases related to RSA 3072 keys."
e78c9db2 74 git am < ${PATCHESDIR}/0006-Disable-testing-with-RSA-3072.patch
605e823f 75else
468f7e61 76 echo "swtpm/libtpms support RSA 3072 bit keys"
605e823f
SB
77fi
78
8dc2415d
SB
79# Adjust test suite to TPM 2.0 revision libtpms is implementing
80revision=$(run_swtpm_ioctl ${SWTPM_INTERFACE} --info 1 |
81 sed 's/.*,"revision":\([^\}]*\).*/\1/')
82echo "Libtpms implements TPM 2.0 revision ${revision}."
83if [ $revision -lt 155 ]; then
e78c9db2
SB
84 echo "Removing revision 155 and later test cases."
85 git am < ${PATCHESDIR}/0007-Disable-rev155-test-cases.patch
86 git am < ${PATCHESDIR}/0008-Disable-x509-test-cases.patch
87 git am < ${PATCHESDIR}/0009-Disable-getcapability-TPM_CAP_ACT.patch
8dc2415d
SB
88fi
89
e78c9db2
SB
90autoreconf --force --install
91unset CFLAGS LDFLAGS LIBS
92./configure --disable-tpm-1.2
93make -j4
94
95pushd utils
96
3e7555c4 97export TPM_SERVER_NAME=127.0.0.1
a1c9aedd 98export TPM_INTERFACE_TYPE=socsim
03c7fe45
SB
99export TPM_COMMAND_PORT=${SWTPM_SERVER_PORT}
100export TPM_PLATFORM_PORT=${SWTPM_CTRL_PORT}
101
102export SWTPM_IOCTL
103
03c7fe45
SB
104./startup
105if [ $? -ne 0 ]; then
106 echo "Startup of TPM2 failed"
107 exit 1
108fi
109
110./reg.sh -a 2>&1 | tee ${REGLOG}
111
112ret=0
113
114if [ -n "$(grep -E "^ ERROR:" ${REGLOG})" ]; then
115 echo "There were test failures running the IBM TSS 2 tests"
116 grep -E "^ ERROR:" ${REGLOG} -B2 -A2
117 ret=1
118fi
119
120# Shut down
121run_swtpm_ioctl ${SWTPM_INTERFACE} -s
122if [ $? -ne 0 ]; then
123 echo "Error: Could not shut down the ${SWTPM_INTERFACE} TPM."
124 ret=1
125fi
126
127if wait_process_gone ${SWTPM_PID} 4; then
128 echo "Error: ${SWTPM_INTERFACE} TPM should not be running anymore."
129 ret=1
130fi
131
4ba6012c 132popd &>/dev/null
03c7fe45
SB
133popd &>/dev/null
134popd &>/dev/null
135
136[ $ret -eq 0 ] && echo "OK"
137
138exit $ret