]> git.proxmox.com Git - swtpm.git/blame - tests/test_parameters
tests: Enable test_ctrchannel on DragonFly BSD
[swtpm.git] / tests / test_parameters
CommitLineData
e46a2b66
SB
1#!/bin/bash
2
3# For the license, see the LICENSE file in the root directory.
4
313cf75c
SB
5ROOT=${abs_top_builddir:-$(dirname "$0")/..}
6TESTDIR=${abs_top_testdir:=$(dirname "$0")}
c51c07a0 7SRCDIR=${abs_top_srcdir:-$(dirname "$0")/..}
e46a2b66
SB
8
9PARAMETERS=(
10 ""
11 "--createek"
12 "--take-ownership"
13 "--createek --lock-nvram"
14 "--take-ownership --lock-nvram"
15 "--lock-nvram"
16 "--take-ownership --ownerpass OOO"
17 "--take-ownership --srkpass SSS"
18 "--take-ownership --ownerpass OO --srkpass SS"
19 "--take-ownership --lock-nvram --display"
20 "--display"
21 "--lock-nvram --display"
22 "--take-ownership --srk-well-known"
23 "--take-ownership --owner-well-known"
24 "--take-ownership --srk-well-known --owner-well-known"
313cf75c
SB
25 "--createek --create-ek-cert --create-platform-cert --lock-nvram --config ${TESTDIR}/swtpm_setup.conf --vmid test --display"
26 "--createek --create-ek-cert --create-platform-cert --lock-nvram --config ${TESTDIR}/swtpm_setup.conf --vmid test --display --keyfile ${TESTDIR}/data/keyfile.txt"
27 "--createek --create-ek-cert --create-platform-cert --lock-nvram --config ${TESTDIR}/swtpm_setup.conf --vmid test --display --pwdfile ${TESTDIR}/data/pwdfile.txt"
e46a2b66
SB
28)
29
30FILESIZES=(
27bf9db6
SB
31 1185
32 1605
33 2066
34 1605
35 2066
36 1185
37 2066
38 2066
39 2066
40 2066
41 1185
42 1185
43 2066
44 2066
45 2066
46 1721
638bd3ba
SB
47 1788
48 1788
e46a2b66
SB
49)
50
e150007d
SB
51if [ "$(id -u)" -ne 0 ]; then
52 echo "Need to be root to run this test."
53 exit 77
54fi
55
e46a2b66 56SWTPM=swtpm
19e05751 57SWTPM_EXE=${SWTPM_EXE:-$ROOT/src/swtpm/$SWTPM}
e2951df7 58SWTPM_IOCTL=${SWTPM_IOCTL:-$ROOT/src/swtpm_ioctl/swtpm_ioctl}
e46a2b66
SB
59TCSD=`type -P tcsd`
60TPMDIR=`mktemp -d`
c51c07a0 61SWTPM_SETUP_CONF=$SRCDIR/etc/swtpm_setup.conf
e46a2b66
SB
62# filesystem privileges require to run swtpm_setup as root during test
63TPMAUTHORING="$ROOT/src/swtpm_setup/swtpm_setup --config ${SWTPM_SETUP_CONF} --runas root"
c51c07a0 64PATH=${ROOT}/src/swtpm_bios:${TESTDIR}:$PATH
e46a2b66 65
313cf75c 66source ${TESTDIR}/test_config
6e7df39f 67
e46a2b66
SB
68trap "cleanup" SIGTERM EXIT
69
70if test "$TCSD" = ""; then
71 echo "TCSD executable 'tcsd' was not found in path."
72 exit 1
73fi
74
75function cleanup()
76{
77 rm -rf $TPMDIR
78}
79
6e7df39f 80chown $TSS_USER:$TSS_GROUP $TPMDIR 2>/dev/null
e46a2b66 81if [ $? -ne 0 ]; then
6e7df39f 82 echo "Could not change ownership of $TPMDIR to $TSS_USER:$TSS_GROUP." \
e46a2b66
SB
83 "You need to be root."
84 exit 1
85fi
86
84d2e89a
SB
87# swtpm_setup.conf points to the local create_certs.sh
88# For create_certs.sh to be found (with out full path)
89# add this directory to the PATH
90PATH=$PATH:$PWD
91
e46a2b66
SB
92for (( i=0; i<${#PARAMETERS[*]}; i++)); do
93 rm -rf $TPMDIR/*
94 echo -n "Test $i: "
95 $TPMAUTHORING \
96 --tpm-state $TPMDIR \
97 --tpm "$SWTPM_EXE socket" \
e2951df7 98 --swtpm_ioctl "$SWTPM_IOCTL" \
e46a2b66
SB
99 ${PARAMETERS[$i]} 2>&1 >/dev/null
100
101 if [ $? -ne 0 ]; then
102 echo "ERROR: Test with parameters '${PARAMETERS[$i]}' failed."
103 exit 1
104 elif [ ! -f $TPMDIR/tpm-00.permall ]; then
105 echo "ERROR: Test with parameters '${PARAMETERS[$i]}' did not
106 produce file $TPMDIR/tpm-00.permall."
107 exit 1
108 fi
109
110 FILESIZE=`stat -c%s $TPMDIR/tpm-00.permall`
111 if [ ${FILESIZE} -ne ${FILESIZES[$i]} ]; then
112 echo "ERROR: Unexpected file size of $FILESIZE, "\
113 "expected ${FILESIZES[$i]}. Parameters: ${PARAMETERS[$i]}"
114 exit 1
115 fi
116
117 echo "SUCCESS with parameters '${PARAMETERS[$i]}'."
118done