mirror of
https://github.com/stefanberger/swtpm.git
synced 2026-08-20 07:20:04 +00:00
test: Add --log parameter to test logging
Add the --log parameter to test log levels 1 and 20. Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
This commit is contained in:
parent
51c41a4862
commit
89d85f9a93
@ -9,10 +9,13 @@ SWTPM_EXE=$ROOT/src/swtpm/$SWTPM
|
||||
TPMDIR=`mktemp -d`
|
||||
TPMAUTHORING=$ROOT/src/swtpm_setup/swtpm_setup
|
||||
PID_FILE=$TPMDIR/${SWTPM}.pid
|
||||
LOG_FILE=$TPMDIR/${SWTPM}.log
|
||||
PATH=${PWD}/${ROOT}/src/swtpm:$PATH
|
||||
PATH=${PWD}/${ROOT}/src/swtpm_setup:$PATH
|
||||
PATH=${PWD}/${ROOT}/src/swtpm_bios:$PATH
|
||||
|
||||
source ${DIR}/test_common
|
||||
|
||||
trap "cleanup" SIGTERM EXIT
|
||||
|
||||
function cleanup()
|
||||
@ -64,9 +67,13 @@ function wait_port_closed()
|
||||
return 1
|
||||
}
|
||||
|
||||
# Test 1: test port and directory command line parameters
|
||||
# Test 1: test port and directory command line parameters; use log level 20
|
||||
|
||||
$SWTPM_EXE socket -p $PORT --tpmstate dir=$TPMDIR --pid file=$PID_FILE &>/dev/null &
|
||||
$SWTPM_EXE socket \
|
||||
-p $PORT \
|
||||
--tpmstate dir=$TPMDIR \
|
||||
--pid file=$PID_FILE \
|
||||
--log file=$LOG_FILE,level=20 &
|
||||
PID=$!
|
||||
|
||||
wait_port_open $PORT $PID
|
||||
@ -96,6 +103,9 @@ if [ $? -ne 0 ]; then
|
||||
exit 1
|
||||
fi
|
||||
|
||||
check_logfile_patterns_level_20 $LOG_FILE
|
||||
rm -f $LOG_FILE
|
||||
|
||||
kill -SIGTERM $PID &>/dev/null
|
||||
sleep 1
|
||||
|
||||
|
||||
@ -15,3 +15,43 @@ function wait_for_file()
|
||||
return 0
|
||||
}
|
||||
|
||||
function check_logfile_patterns_level_20()
|
||||
{
|
||||
local logfile="$1"
|
||||
|
||||
for pattern in \
|
||||
"^ [[:print:]]+$" \
|
||||
"^ [[:print:]]+$" \
|
||||
"^ [[:print:]]+$" \
|
||||
"^ [[:print:]]+$" \
|
||||
"^ [[:print:]]+$" \
|
||||
"^ [[:print:]]+$" \
|
||||
"^ [[:print:]]+$" \
|
||||
; do
|
||||
shift
|
||||
ctr=$(grep -E "${pattern}" $logfile | wc -l)
|
||||
if [ $ctr -eq 0 ]; then
|
||||
echo "Counted $ctr occurrences of pattern '${pattern}' in logfile; expected at least 1"
|
||||
exit 1
|
||||
fi
|
||||
echo "'${pattern}' occurrences: $ctr (OK)"
|
||||
done
|
||||
}
|
||||
|
||||
function check_logfile_patterns_level_1()
|
||||
{
|
||||
local logfile="$1"
|
||||
local minocc="$2"
|
||||
|
||||
for pattern in \
|
||||
"^[[:print:]]+$" \
|
||||
; do
|
||||
shift
|
||||
ctr=$(grep -E "${pattern}" $logfile | wc -l)
|
||||
if [ $ctr -lt $minocc ]; then
|
||||
echo "Counted $ctr occurrences of pattern '${pattern}' in logfile; expected at least $minocc"
|
||||
exit 1
|
||||
fi
|
||||
echo "'${pattern}' occurrences: $ctr (OK)"
|
||||
done
|
||||
}
|
||||
|
||||
@ -8,6 +8,7 @@ SWTPM=swtpm
|
||||
SWTPM_EXE=$ROOT/src/swtpm/$SWTPM
|
||||
TPMDIR=`mktemp -d`
|
||||
PID_FILE=$TPMDIR/${SWTPM}.pid
|
||||
LOG_FILE=$TPMDIR/${SWTPM}.log
|
||||
SOCK_PATH=$TPMDIR/sock
|
||||
CMD_PATH=$TPMDIR/cmd
|
||||
RESP_PATH=$TPMDIR/resp
|
||||
@ -28,7 +29,12 @@ function cleanup()
|
||||
|
||||
# use a pseudo terminal
|
||||
exec 100<>/dev/ptmx
|
||||
$SWTPM_EXE chardev --fd 100 --tpmstate dir=$TPMDIR --pid file=$PID_FILE --ctrl type=unixio,path=$SOCK_PATH &
|
||||
$SWTPM_EXE chardev \
|
||||
--fd 100 \
|
||||
--tpmstate dir=$TPMDIR \
|
||||
--pid file=$PID_FILE \
|
||||
--ctrl type=unixio,path=$SOCK_PATH \
|
||||
--log file=$LOG_FILE,level=20 &
|
||||
|
||||
if wait_for_file $PID_FILE 3; then
|
||||
echo "Error: Chardev TPM did not write pidfile."
|
||||
@ -155,6 +161,9 @@ if [ -f $PID_FILE ]; then
|
||||
exit 1
|
||||
fi
|
||||
|
||||
check_logfile_patterns_level_20 $LOG_FILE
|
||||
rm -f $LOG_FILE
|
||||
|
||||
echo "OK"
|
||||
|
||||
|
||||
@ -163,7 +172,12 @@ echo "OK"
|
||||
# There are a few more tests here that require sending commands to the TPM
|
||||
|
||||
# use a pseudo terminal
|
||||
$SWTPM_EXE socket --server port=65530,disconnect=true --tpmstate dir=$TPMDIR --pid file=$PID_FILE --ctrl type=unixio,path=$SOCK_PATH &
|
||||
$SWTPM_EXE socket \
|
||||
--server port=65530,disconnect=true \
|
||||
--tpmstate dir=$TPMDIR \
|
||||
--pid file=$PID_FILE \
|
||||
--ctrl type=unixio,path=$SOCK_PATH \
|
||||
--log file=$LOG_FILE &
|
||||
|
||||
if wait_for_file $PID_FILE 3; then
|
||||
echo "Error: Socket TPM did not write pidfile."
|
||||
@ -450,6 +464,10 @@ if [ -f $PID_FILE ]; then
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Expecting to see an error message for the unknown command
|
||||
check_logfile_patterns_level_1 $LOG_FILE 1
|
||||
rm -f $LOG_FILE
|
||||
|
||||
echo "OK"
|
||||
|
||||
|
||||
@ -463,7 +481,8 @@ $SWTPM_EXE socket \
|
||||
--tpmstate dir=$TPMDIR \
|
||||
--pid file=$PID_FILE \
|
||||
--ctrl type=unixio,path=$SOCK_PATH \
|
||||
--key pwdfile=${PWD}/${DIR}/data/tpmstate2/pwdfile.txt &
|
||||
--key pwdfile=${PWD}/${DIR}/data/tpmstate2/pwdfile.txt \
|
||||
--log file=$LOG_FILE,level=20 &
|
||||
|
||||
if wait_for_file $PID_FILE 3; then
|
||||
echo "Error: Socket TPM did not write pidfile."
|
||||
@ -527,6 +546,10 @@ if [ -f $PID_FILE ]; then
|
||||
exit 1
|
||||
fi
|
||||
|
||||
check_logfile_patterns_level_20 $LOG_FILE
|
||||
rm -f $LOG_FILE
|
||||
|
||||
echo "OK"
|
||||
|
||||
# remove volatile state
|
||||
rm -f $TPMDIR/*.volatilestate
|
||||
@ -536,7 +559,8 @@ $SWTPM_EXE socket \
|
||||
--tpmstate dir=$TPMDIR \
|
||||
--pid file=$PID_FILE \
|
||||
--ctrl type=unixio,path=$SOCK_PATH \
|
||||
--key pwdfile=${PWD}/${DIR}/data/tpmstate2/pwdfile.txt &
|
||||
--key pwdfile=${PWD}/${DIR}/data/tpmstate2/pwdfile.txt \
|
||||
--log file=$LOG_FILE &
|
||||
|
||||
if wait_for_file $PID_FILE 3; then
|
||||
echo "Error: Socket TPM did not write pidfile."
|
||||
@ -689,6 +713,10 @@ if [ -f $PID_FILE ]; then
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# (Currently) expecting to see nothing in the log file
|
||||
check_logfile_patterns_level_1 $LOG_FILE 0
|
||||
rm -f $LOG_FILE
|
||||
|
||||
echo "OK"
|
||||
|
||||
exit 0
|
||||
|
||||
@ -16,6 +16,7 @@ CUSE_TPM_IOCTL=$ROOT/src/swtpm_ioctl/swtpm_ioctl
|
||||
VTPM_NAME="vtpm-test-wrongorder"
|
||||
export TPM_PATH=$(mktemp -d)
|
||||
STATE_FILE=$TPM_PATH/tpm-00.permall
|
||||
LOG_FILE=$TPM_PATH/tpm-00.log
|
||||
VOLATILE_STATE_FILE=$TPM_PATH/tpm-00.volatilestate
|
||||
|
||||
function cleanup()
|
||||
@ -30,10 +31,11 @@ function cleanup()
|
||||
trap "cleanup" EXIT
|
||||
|
||||
source ${DIR}/test_cuse
|
||||
source ${DIR}/test_common
|
||||
|
||||
rm -f $STATE_FILE $VOLATILE_STATE_FILE 2>/dev/null
|
||||
|
||||
$SWTPM_EXE -n $VTPM_NAME
|
||||
$SWTPM_EXE --log file=$LOG_FILE,level=20 -n $VTPM_NAME
|
||||
sleep 0.5
|
||||
PID=$(ps aux | grep $SWTPM | grep -E "$VTPM_NAME\$" | gawk '{print $2}')
|
||||
|
||||
@ -114,6 +116,9 @@ if [ ! -e $STATE_FILE ]; then
|
||||
exit 1
|
||||
fi
|
||||
|
||||
check_logfile_patterns_level_20 $LOG_FILE
|
||||
rm -f $LOG_FILE
|
||||
|
||||
echo "OK"
|
||||
|
||||
exit 0
|
||||
|
||||
Loading…
Reference in New Issue
Block a user