]> git.proxmox.com Git - swtpm.git/blame - tests/test_tpm2_ibmtss2
RPM: Adjust version to 0.4.0 at beginning of dev cycle
[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")}
9
10SWTPM_SERVER_PORT=65426
11SWTPM_SERVER_NAME=localhost
12SWTPM_CTRL_PORT=65427
13SWTPM_INTERFACE=socket+socket
14
15function cleanup() {
16 pid=${SWTPM_PID}
17 if [ -n "$pid" ]; then
18 kill_quiet -9 $pid
19 fi
20 if [ -n ${WORKDIR} ]; then
21 rm -rf ${WORKDIR}
22 fi
23}
24
25trap "cleanup" EXIT
26
27source ${TESTDIR}/common
28WORKDIR=$(mktemp -d)
29
30REGLOG=${WORKDIR}/reglog
31
32SWTPM_SERVER_NO_DISCONNECT="1" run_swtpm ${SWTPM_INTERFACE} \
33 --tpm2 \
34 --tpmstate dir=${WORKDIR} \
35 --flags not-need-init
36
37pushd ${WORKDIR} &>/dev/null
38
39git clone https://git.code.sf.net/p/ibmtpm20tss/tss ibmtpm20tss-tss
40
4ba6012c 41pushd ibmtpm20tss-tss &>/dev/null
03c7fe45 42
8dc2415d 43git checkout tags/v1.3.0
03c7fe45
SB
44if [ $? -ne 0 ]; then
45 echo "'Git checkout' failed."
46 exit 1
47fi
48
4ba6012c 49autoreconf --force --install
8dc2415d
SB
50#FIXME: Need to pass LIBS on Ubuntu to avoid X509_free linker errors
51CFLAGS="" LDFLAGS="" LIBS="-lz -lssl -lcrypto" ./configure --disable-tpm-1.2
03c7fe45 52make -j4
4ba6012c
SB
53
54pushd utils
8dc2415d 55
4ba6012c 56sed -i 's/export CRYPTOLIBRARY.*/export CRYPTOLIBRARY=openssl/' reg.sh
03c7fe45 57
8dc2415d
SB
58# Adjust test suite to TPM 2.0 revision libtpms is implementing
59revision=$(run_swtpm_ioctl ${SWTPM_INTERFACE} --info 1 |
60 sed 's/.*,"revision":\([^\}]*\).*/\1/')
61echo "Libtpms implements TPM 2.0 revision ${revision}."
62if [ $revision -lt 155 ]; then
63 echo "Removing revision 155 test cases."
64 for t in regtests/testattest155.sh regtests/testx509.sh
65 do
66 rm "${t}"
67 touch "${t}"
68 chmod 777 "${t}"
69 done
70fi
71
03c7fe45 72export TPM_SERVER_NAME=localhost
a1c9aedd 73export TPM_INTERFACE_TYPE=socsim
03c7fe45
SB
74export TPM_COMMAND_PORT=${SWTPM_SERVER_PORT}
75export TPM_PLATFORM_PORT=${SWTPM_CTRL_PORT}
76
77export SWTPM_IOCTL
78
79cat <<_EOF_ > powerup
80#!/usr/bin/env bash
81\${SWTPM_IOCTL} -i --tcp \${TPM_SERVER_NAME}:\${TPM_PLATFORM_PORT}
82exit \$?
83_EOF_
84chmod 755 powerup
85
86./startup
87if [ $? -ne 0 ]; then
88 echo "Startup of TPM2 failed"
89 exit 1
90fi
91
92./reg.sh -a 2>&1 | tee ${REGLOG}
93
94ret=0
95
96if [ -n "$(grep -E "^ ERROR:" ${REGLOG})" ]; then
97 echo "There were test failures running the IBM TSS 2 tests"
98 grep -E "^ ERROR:" ${REGLOG} -B2 -A2
99 ret=1
100fi
101
102# Shut down
103run_swtpm_ioctl ${SWTPM_INTERFACE} -s
104if [ $? -ne 0 ]; then
105 echo "Error: Could not shut down the ${SWTPM_INTERFACE} TPM."
106 ret=1
107fi
108
109if wait_process_gone ${SWTPM_PID} 4; then
110 echo "Error: ${SWTPM_INTERFACE} TPM should not be running anymore."
111 ret=1
112fi
113
4ba6012c 114popd &>/dev/null
03c7fe45
SB
115popd &>/dev/null
116popd &>/dev/null
117
118[ $ret -eq 0 ] && echo "OK"
119
120exit $ret