mirror of
https://github.com/stefanberger/swtpm.git
synced 2025-12-28 07:06:06 +00:00
106 lines
1.8 KiB
Bash
Executable File
106 lines
1.8 KiB
Bash
Executable File
#!/bin/bash
|
|
|
|
# For the license, see the LICENSE file in the root directory.
|
|
|
|
DIR=$(dirname "$0")
|
|
ROOT=${DIR}/..
|
|
SWTPM=swtpm
|
|
SWTPM_EXE=$ROOT/src/swtpm/$SWTPM
|
|
TPMDIR=`mktemp -d`
|
|
TPMAUTHORING=$ROOT/src/swtpm_setup/swtpm_setup
|
|
PATH=${PWD}/${ROOT}/src/swtpm:$PATH
|
|
PATH=${PWD}/${ROOT}/src/swtpm_setup:$PATH
|
|
PATH=${PWD}/${ROOT}/src/swtpm_bios:$PATH
|
|
|
|
trap "cleanup" SIGTERM EXIT
|
|
|
|
function cleanup()
|
|
{
|
|
rm -rf $TPMDIR
|
|
}
|
|
|
|
PORT=11234
|
|
|
|
export TCSD_TCP_DEVICE_HOSTNAME=localhost
|
|
export TCSD_TCP_DEVICE_PORT=$PORT
|
|
export TCSD_USE_TCP_DEVICE=1
|
|
|
|
# Test 1: test port and directory command line parameters
|
|
|
|
$SWTPM_EXE socket -p $PORT -i $TPMDIR &>/dev/null &
|
|
PID=$!
|
|
|
|
sleep 5
|
|
|
|
kill -0 $PID
|
|
if [ $? -ne 0 ]; then
|
|
echo "Test 1 failed: TPM process not running"
|
|
exit 1
|
|
fi
|
|
|
|
swtpm_bios &>/dev/null
|
|
|
|
if [ $? -ne 0 ]; then
|
|
echo "Test 1 failed: tpm_bios did not work"
|
|
exit 1
|
|
fi
|
|
|
|
kill -SIGTERM $PID &>/dev/null
|
|
sleep 1
|
|
|
|
exec 20<&1-; exec 21<&2-
|
|
kill -0 $PID &>/dev/null
|
|
RES=$?
|
|
exec 1<&20-; exec 2<&21-
|
|
|
|
if [ $RES -eq 0 ]; then
|
|
kill -SIGKILL $PID
|
|
echo "Test 1 failed: TPM process did not terminate on SIGTERM"
|
|
exit 1
|
|
fi
|
|
|
|
echo "Test 1 passed"
|
|
cleanup
|
|
|
|
# Test 2: test port, directory and terminate command line parameters
|
|
TPMDIR=`mktemp -d`
|
|
|
|
$SWTPM_EXE socket -p $PORT -i $TPMDIR -t &>/dev/null &
|
|
PID=$!
|
|
|
|
sleep 5
|
|
|
|
exec 20<&1-; exec 21<&2-
|
|
kill -0 $PID
|
|
exec 1<&20-; exec 2<&21-
|
|
|
|
if [ $? -ne 0 ]; then
|
|
echo "Test 2 failed: TPM process not running"
|
|
exit 1
|
|
fi
|
|
|
|
exec 200<> /dev/tcp/localhost/$PORT
|
|
|
|
if [ $? -ne 0 ]; then
|
|
echo "Test 2 failed: Could not connect to TPM"
|
|
exit 1
|
|
fi
|
|
|
|
exec 200>&-
|
|
|
|
# Give it time to shut down
|
|
sleep 2
|
|
|
|
exec 20<&1-; exec 21<&2-
|
|
kill -0 $PID
|
|
RES=$?
|
|
exec 1<&20-; exec 2<&21-
|
|
|
|
if [ $RES -eq 0 ]; then
|
|
kill -SIGKILL $PID
|
|
echo "Test 2 failed: TPM process did not terminate on connection loss"
|
|
exit 1
|
|
fi
|
|
|
|
echo "Test 2 passed"
|