diff --git a/tests/Makefile.am b/tests/Makefile.am index 11174d9..ee42c45 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -41,6 +41,3 @@ EXTRA_DIST=$(TESTS) \ data/tpmstate2/pwdfile.txt \ data/tpmstate2/README \ test_swtpm_cert - -# Cannot run the tests in parallel... -.NOTPARALLEL: diff --git a/tests/test_encrypted_state b/tests/test_encrypted_state index c015967..feeaf28 100755 --- a/tests/test_encrypted_state +++ b/tests/test_encrypted_state @@ -3,36 +3,35 @@ # For the license, see the LICENSE file in the root directory. #set -x +if [ "$(id -u)" -ne 0 ]; then + echo "Need to be root to run this test." + exit 77 +fi + DIR=$(dirname "$0") ROOT=${DIR}/.. SWTPM=swtpm_cuse SWTPM_EXE=$ROOT/src/swtpm/$SWTPM CUSE_TPM_IOCTL=$ROOT/src/swtpm_ioctl/swtpm_ioctl -MAJOR=255 -MINOR=100 -VTPM_NAME=$(printf "vtpm-%d-%d" $MAJOR $MINOR) -export TPM_PATH=/tmp +VTPM_NAME="vtpm-test-encrypted-state" +export TPM_PATH=$(mktemp -d) STATE_FILE=$TPM_PATH/tpm-00.permall VOLATILE_STATE_FILE=$TPM_PATH/tpm-00.volatilestate KEY=1234567890abcdef1234567890abcdef -if [ "$(id -u)" -ne 0 ]; then - echo "Need to be root to run this test." - exit 77 -fi - keyfile=$(mktemp) logfile=$(mktemp) echo "$KEY" > $keyfile function cleanup() { - pid=$(ps aux | grep $SWTPM | grep $VTPM_NAME | gawk '{print $2}') + pid=$(ps aux | grep $SWTPM | grep -E "$VTPM_NAME " | gawk '{print $2}') if [ -n "$pid" ]; then kill -9 $pid fi rm -f $keyfile $logfile + rm -rf $TPM_PATH } trap "cleanup" EXIT @@ -46,7 +45,7 @@ $SWTPM_EXE -n $VTPM_NAME --key file=$keyfile,mode=aes-cbc,format=hex \ #sleep 20 #echo "continuing" sleep 0.5 -PID=$(ps aux | grep $SWTPM | grep $VTPM_NAME | gawk '{print $2}') +PID=$(ps aux | grep $SWTPM | grep -E "$VTPM_NAME " | gawk '{print $2}') ps aux | grep $SWTPM | grep -v grep @@ -114,13 +113,13 @@ $CUSE_TPM_IOCTL -s /dev/$VTPM_NAME $SWTPM_EXE -n $VTPM_NAME --key file=$keyfile,mode=aes-cbc,format=hex,remove \ --log file=$logfile sleep 0.5 -PID=$(ps aux | grep $SWTPM | grep $VTPM_NAME | gawk '{print $2}') +PID=$(ps aux | grep $SWTPM | grep -E "$VTPM_NAME " | gawk '{print $2}') ps aux | grep $SWTPM | grep -v grep kill -0 $PID if [ $? -ne 0 ]; then - echo "Error: CUSE TPM did not start." + echo "Error (2): CUSE TPM did not start." exit 1 fi diff --git a/tests/test_getcap b/tests/test_getcap index 1ac42c1..757576d 100755 --- a/tests/test_getcap +++ b/tests/test_getcap @@ -3,29 +3,28 @@ # For the license, see the LICENSE file in the root directory. #set -x -DIR=$(dirname "$0") -ROOT=${DIR}/.. -SWTPM=swtpm_cuse -SWTPM_EXE=$ROOT/src/swtpm/$SWTPM -CUSE_TPM_IOCTL=$ROOT/src/swtpm_ioctl/swtpm_ioctl -MAJOR=255 -MINOR=100 -VTPM_NAME=$(printf "vtpm-%d-%d" $MAJOR $MINOR) -export TPM_PATH=/tmp -STATE_FILE=$TPM_PATH/tpm-00.permall -VOLATILE_STATE_FILE=$TPM_PATH/tpm-00.volatilestate - if [ "$(id -u)" -ne 0 ]; then echo "Need to be root to run this test." exit 77 fi +DIR=$(dirname "$0") +ROOT=${DIR}/.. +SWTPM=swtpm_cuse +SWTPM_EXE=$ROOT/src/swtpm/$SWTPM +CUSE_TPM_IOCTL=$ROOT/src/swtpm_ioctl/swtpm_ioctl +VTPM_NAME="vtpm-test-getcap" +export TPM_PATH=$(mktemp -d) +STATE_FILE=$TPM_PATH/tpm-00.permall +VOLATILE_STATE_FILE=$TPM_PATH/tpm-00.volatilestate + function cleanup() { - pid=$(ps aux | grep $SWTPM | grep $VTPM_NAME | gawk '{print $2}') + pid=$(ps aux | grep $SWTPM | grep -E "$VTPM_NAME\$" | gawk '{print $2}') if [ -n "$pid" ]; then kill -9 $pid fi + rm -rf $TPM_PATH } trap "cleanup" EXIT @@ -36,9 +35,10 @@ rm -f $STATE_FILE $VOLATILE_STATE_FILE 2>/dev/null $SWTPM_EXE -n $VTPM_NAME sleep 0.5 -PID=$(ps aux | grep $SWTPM | grep $VTPM_NAME | gawk '{print $2}') +PID=$(ps aux | grep $SWTPM | grep -E "$VTPM_NAME\$" | gawk '{print $2}') ps aux | grep $SWTPM | grep -v grep +ls -l /dev/vtpm* kill -0 $PID if [ $? -ne 0 ]; then diff --git a/tests/test_hashing b/tests/test_hashing index 9a5329f..a01f496 100755 --- a/tests/test_hashing +++ b/tests/test_hashing @@ -3,29 +3,28 @@ # For the license, see the LICENSE file in the root directory. #set -x -DIR=$(dirname "$0") -ROOT=${DIR}/.. -SWTPM=swtpm_cuse -SWTPM_EXE=$ROOT/src/swtpm/$SWTPM -CUSE_TPM_IOCTL=$ROOT/src/swtpm_ioctl/swtpm_ioctl -MAJOR=255 -MINOR=100 -VTPM_NAME=$(printf "vtpm-%d-%d" $MAJOR $MINOR) -export TPM_PATH=/tmp -STATE_FILE=$TPM_PATH/tpm-00.permall -VOLATILE_STATE_FILE=$TPM_PATH/tpm-00.volatilestate - if [ "$(id -u)" -ne 0 ]; then echo "Need to be root to run this test." exit 77 fi +DIR=$(dirname "$0") +ROOT=${DIR}/.. +SWTPM=swtpm_cuse +SWTPM_EXE=$ROOT/src/swtpm/$SWTPM +CUSE_TPM_IOCTL=$ROOT/src/swtpm_ioctl/swtpm_ioctl +VTPM_NAME="vtpm-test-hashing" +export TPM_PATH=$(mktemp -d) +STATE_FILE=$TPM_PATH/tpm-00.permall +VOLATILE_STATE_FILE=$TPM_PATH/tpm-00.volatilestate + function cleanup() { - pid=$(ps aux | grep $SWTPM | grep $VTPM_NAME | gawk '{print $2}') + pid=$(ps aux | grep $SWTPM | grep -E "$VTPM_NAME\$" | gawk '{print $2}') if [ -n "$pid" ]; then kill -9 $pid fi + rm -rf $TPM_PATH } trap "cleanup" EXIT @@ -36,7 +35,7 @@ rm -f $STATE_FILE $VOLATILE_STATE_FILE 2>/dev/null $SWTPM_EXE -n $VTPM_NAME sleep 0.5 -PID=$(ps aux | grep $SWTPM | grep $VTPM_NAME | gawk '{print $2}') +PID=$(ps aux | grep $SWTPM | grep -E "$VTPM_NAME\$" | gawk '{print $2}') ps aux | grep $SWTPM | grep -v grep diff --git a/tests/test_hashing2 b/tests/test_hashing2 index a821485..3253060 100755 --- a/tests/test_hashing2 +++ b/tests/test_hashing2 @@ -3,29 +3,28 @@ # For the license, see the LICENSE file in the root directory. #set -x -DIR=$(dirname "$0") -ROOT=${DIR}/.. -SWTPM=swtpm_cuse -SWTPM_EXE=$ROOT/src/swtpm/$SWTPM -CUSE_TPM_IOCTL=$ROOT/src/swtpm_ioctl/swtpm_ioctl -MAJOR=255 -MINOR=100 -VTPM_NAME=$(printf "vtpm-%d-%d" $MAJOR $MINOR) -export TPM_PATH=/tmp -STATE_FILE=$TPM_PATH/tpm-00.permall -VOLATILE_STATE_FILE=$TPM_PATH/tpm-00.volatilestate - if [ "$(id -u)" -ne 0 ]; then echo "Need to be root to run this test." exit 77 fi +DIR=$(dirname "$0") +ROOT=${DIR}/.. +SWTPM=swtpm_cuse +SWTPM_EXE=$ROOT/src/swtpm/$SWTPM +CUSE_TPM_IOCTL=$ROOT/src/swtpm_ioctl/swtpm_ioctl +VTPM_NAME="vtpm-test-hashing2" +export TPM_PATH=$(mktemp -d) +STATE_FILE=$TPM_PATH/tpm-00.permall +VOLATILE_STATE_FILE=$TPM_PATH/tpm-00.volatilestate + function cleanup() { - pid=$(ps aux | grep $SWTPM | grep $VTPM_NAME | gawk '{print $2}') + pid=$(ps aux | grep $SWTPM | grep -E "$VTPM_NAME\$" | gawk '{print $2}') if [ -n "$pid" ]; then kill -9 $pid fi + rm -rf $TPM_PATH } trap "cleanup" EXIT @@ -36,7 +35,7 @@ rm -f $STATE_FILE $VOLATILE_STATE_FILE 2>/dev/null $SWTPM_EXE -n $VTPM_NAME sleep 0.5 -PID=$(ps aux | grep $SWTPM | grep $VTPM_NAME | gawk '{print $2}') +PID=$(ps aux | grep $SWTPM | grep -E "$VTPM_NAME\$" | gawk '{print $2}') ps aux | grep $SWTPM | grep -v grep diff --git a/tests/test_init b/tests/test_init index 25a3352..0a46ca0 100755 --- a/tests/test_init +++ b/tests/test_init @@ -3,29 +3,28 @@ # For the license, see the LICENSE file in the root directory. #set -x -DIR=$(dirname "$0") -ROOT=${DIR}/.. -SWTPM=swtpm_cuse -SWTPM_EXE=$ROOT/src/swtpm/$SWTPM -CUSE_TPM_IOCTL=$ROOT/src/swtpm_ioctl/swtpm_ioctl -MAJOR=255 -MINOR=100 -VTPM_NAME=$(printf "vtpm-%d-%d" $MAJOR $MINOR) -export TPM_PATH=/tmp -STATE_FILE=$TPM_PATH/tpm-00.permall -VOLATILE_STATE_FILE=$TPM_PATH/tpm-00.volatilestate - if [ "$(id -u)" -ne 0 ]; then echo "Need to be root to run this test." exit 77 fi +DIR=$(dirname "$0") +ROOT=${DIR}/.. +SWTPM=swtpm_cuse +SWTPM_EXE=$ROOT/src/swtpm/$SWTPM +CUSE_TPM_IOCTL=$ROOT/src/swtpm_ioctl/swtpm_ioctl +VTPM_NAME="vtpm-test-init" +export TPM_PATH=$(mktemp -d) +STATE_FILE=$TPM_PATH/tpm-00.permall +VOLATILE_STATE_FILE=$TPM_PATH/tpm-00.volatilestate + function cleanup() { - pid=$(ps aux | grep $SWTPM | grep $VTPM_NAME | gawk '{print $2}') + pid=$(ps aux | grep $SWTPM | grep -E "$VTPM_NAME\$" | gawk '{print $2}') if [ -n "$pid" ]; then kill -9 $pid fi + rm -rf $TPM_PATH } trap "cleanup" EXIT @@ -36,7 +35,7 @@ rm -f $STATE_FILE $VOLATILE_STATE_FILE 2>/dev/null $SWTPM_EXE -n $VTPM_NAME sleep 0.5 -PID=$(ps aux | grep $SWTPM | grep $VTPM_NAME | gawk '{print $2}') +PID=$(ps aux | grep $SWTPM | grep -E "$VTPM_NAME\$" | gawk '{print $2}') ps aux | grep $SWTPM | grep -v grep diff --git a/tests/test_locality b/tests/test_locality index ea1a0a4..9c94480 100755 --- a/tests/test_locality +++ b/tests/test_locality @@ -3,29 +3,28 @@ # For the license, see the LICENSE file in the root directory. #set -x -DIR=$(dirname "$0") -ROOT=${DIR}/.. -SWTPM=swtpm_cuse -SWTPM_EXE=$ROOT/src/swtpm/$SWTPM -CUSE_TPM_IOCTL=$ROOT/src/swtpm_ioctl/swtpm_ioctl -MAJOR=255 -MINOR=100 -VTPM_NAME=$(printf "vtpm-%d-%d" $MAJOR $MINOR) -export TPM_PATH=/tmp -STATE_FILE=$TPM_PATH/tpm-00.permall -VOLATILE_STATE_FILE=$TPM_PATH/tpm-00.volatilestate - if [ "$(id -u)" -ne 0 ]; then echo "Need to be root to run this test." exit 77 fi +DIR=$(dirname "$0") +ROOT=${DIR}/.. +SWTPM=swtpm_cuse +SWTPM_EXE=$ROOT/src/swtpm/$SWTPM +CUSE_TPM_IOCTL=$ROOT/src/swtpm_ioctl/swtpm_ioctl +VTPM_NAME="vtpm-test-locality" +export TPM_PATH=$(mktemp -d) +STATE_FILE=$TPM_PATH/tpm-00.permall +VOLATILE_STATE_FILE=$TPM_PATH/tpm-00.volatilestate + function cleanup() { - pid=$(ps aux | grep $SWTPM | grep $VTPM_NAME | gawk '{print $2}') + pid=$(ps aux | grep $SWTPM | grep -E "$VTPM_NAME\$" | gawk '{print $2}') if [ -n "$pid" ]; then kill -9 $pid fi + rm -rf $TPM_PATH } trap "cleanup" EXIT @@ -36,7 +35,7 @@ rm -f $STATE_FILE $VOLATILE_STATE_FILE 2>/dev/null $SWTPM_EXE -n $VTPM_NAME sleep 0.5 -PID=$(ps aux | grep $SWTPM | grep $VTPM_NAME | gawk '{print $2}') +PID=$(ps aux | grep $SWTPM | grep -E "$VTPM_NAME\$" | gawk '{print $2}') ps aux | grep $SWTPM | grep -v grep diff --git a/tests/test_parameters b/tests/test_parameters index d477330..937b8d5 100755 --- a/tests/test_parameters +++ b/tests/test_parameters @@ -47,6 +47,11 @@ FILESIZES=( 1712 ) +if [ "$(id -u)" -ne 0 ]; then + echo "Need to be root to run this test." + exit 77 +fi + SWTPM=swtpm SWTPM_EXE=$ROOT/src/swtpm/$SWTPM TCSD=`type -P tcsd` @@ -57,12 +62,6 @@ TPMAUTHORING="$ROOT/src/swtpm_setup/swtpm_setup --config ${SWTPM_SETUP_CONF} --r PATH=${PWD}/${ROOT}/src/swtpm_bios:$PATH PATH=${PWD}/${ROOT}/src/swtpm_setup:$PATH -if [ "$(id -u)" -ne 0 ]; then - echo "Need to be root to run this test." - exit 77 -fi - - trap "cleanup" SIGTERM EXIT if test "$TCSD" = ""; then diff --git a/tests/test_resume_volatile b/tests/test_resume_volatile index 2537056..91f1c5b 100755 --- a/tests/test_resume_volatile +++ b/tests/test_resume_volatile @@ -3,19 +3,17 @@ # For the license, see the LICENSE file in the root directory. #set -x +if [ "$(id -u)" -ne 0 ]; then + echo "Need to be root to run this test." + exit 77 +fi + DIR=$(dirname "$0") ROOT=${DIR}/.. SWTPM=swtpm_cuse SWTPM_EXE=$ROOT/src/swtpm/$SWTPM CUSE_TPM_IOCTL=$ROOT/src/swtpm_ioctl/swtpm_ioctl -MAJOR=255 -MINOR=100 -VTPM_NAME=$(printf "vtpm-%d-%d" $MAJOR $MINOR) - -if [ "$(id -u)" -ne 0 ]; then - echo "Need to be root to run this test." - exit 77 -fi +VTPM_NAME="vtpm-test-resume-volatile" function cleanup() { diff --git a/tests/test_volatilestate b/tests/test_volatilestate index 4ce7112..9505c11 100755 --- a/tests/test_volatilestate +++ b/tests/test_volatilestate @@ -3,29 +3,28 @@ # For the license, see the LICENSE file in the root directory. #set -x -DIR=$(dirname "$0") -ROOT=${DIR}/.. -SWTPM=swtpm_cuse -SWTPM_EXE=$ROOT/src/swtpm/$SWTPM -CUSE_TPM_IOCTL=$ROOT/src/swtpm_ioctl/swtpm_ioctl -MAJOR=255 -MINOR=100 -VTPM_NAME=$(printf "vtpm-%d-%d" $MAJOR $MINOR) -export TPM_PATH=/tmp -STATE_FILE=$TPM_PATH/tpm-00.permall -VOLATILE_STATE_FILE=$TPM_PATH/tpm-00.volatilestate - if [ "$(id -u)" -ne 0 ]; then echo "Need to be root to run this test." exit 77 fi +DIR=$(dirname "$0") +ROOT=${DIR}/.. +SWTPM=swtpm_cuse +SWTPM_EXE=$ROOT/src/swtpm/$SWTPM +CUSE_TPM_IOCTL=$ROOT/src/swtpm_ioctl/swtpm_ioctl +VTPM_NAME="vtpm-test-volatilestate" +export TPM_PATH=$(mktemp -d) +STATE_FILE=$TPM_PATH/tpm-00.permall +VOLATILE_STATE_FILE=$TPM_PATH/tpm-00.volatilestate + function cleanup() { - pid=$(ps aux | grep $SWTPM | grep $VTPM_NAME | gawk '{print $2}') + pid=$(ps aux | grep $SWTPM | grep -E "$VTPM_NAME\$" | gawk '{print $2}') if [ -n "$pid" ]; then kill -9 $pid fi + rm -rf $TPM_PATH } trap "cleanup" EXIT @@ -36,7 +35,7 @@ rm -f $STATE_FILE $VOLATILE_STATE_FILE 2>/dev/null $SWTPM_EXE -n $VTPM_NAME sleep 0.5 -PID=$(ps aux | grep $SWTPM | grep $VTPM_NAME | gawk '{print $2}') +PID=$(ps aux | grep $SWTPM | grep -E "$VTPM_NAME\$" | gawk '{print $2}') ps aux | grep $SWTPM | grep -v grep diff --git a/tests/test_wrongorder b/tests/test_wrongorder index 41cd682..fe611b3 100755 --- a/tests/test_wrongorder +++ b/tests/test_wrongorder @@ -3,29 +3,28 @@ # For the license, see the LICENSE file in the root directory. #set -x -DIR=$(dirname "$0") -ROOT=${DIR}/.. -SWTPM=swtpm_cuse -SWTPM_EXE=$ROOT/src/swtpm/$SWTPM -CUSE_TPM_IOCTL=$ROOT/src/swtpm_ioctl/swtpm_ioctl -MAJOR=255 -MINOR=100 -VTPM_NAME=$(printf "vtpm-%d-%d" $MAJOR $MINOR) -export TPM_PATH=/tmp -STATE_FILE=$TPM_PATH/tpm-00.permall -VOLATILE_STATE_FILE=$TPM_PATH/tpm-00.volatilestate - if [ "$(id -u)" -ne 0 ]; then echo "Need to be root to run this test." exit 77 fi +DIR=$(dirname "$0") +ROOT=${DIR}/.. +SWTPM=swtpm_cuse +SWTPM_EXE=$ROOT/src/swtpm/$SWTPM +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 +VOLATILE_STATE_FILE=$TPM_PATH/tpm-00.volatilestate + function cleanup() { - pid=$(ps aux | grep $SWTPM | grep $VTPM_NAME | gawk '{print $2}') + pid=$(ps aux | grep $SWTPM | grep -E "$VTPM_NAME\$" | gawk '{print $2}') if [ -n "$pid" ]; then kill -9 $pid fi + rm -rf $TPM_PATH } trap "cleanup" EXIT @@ -36,7 +35,7 @@ rm -f $STATE_FILE $VOLATILE_STATE_FILE 2>/dev/null $SWTPM_EXE -n $VTPM_NAME sleep 0.5 -PID=$(ps aux | grep $SWTPM | grep $VTPM_NAME | gawk '{print $2}') +PID=$(ps aux | grep $SWTPM | grep -E "$VTPM_NAME\$" | gawk '{print $2}') ps aux | grep $SWTPM | grep -v grep