1#!/usr/bin/env bash 2#;**********************************************************************; 3# Copyright (c) 2017 - 2018, Intel Corporation 4# Copyright (c) 2018 Fraunhofer SIT sponsored by Infineon Technologies AG 5# All rights reserved. 6# All rights reserved. 7# 8# Redistribution and use in source and binary forms, with or without 9# modification, are permitted provided that the following conditions are met: 10# 11# 1. Redistributions of source code must retain the above copyright notice, 12# this list of conditions and the following disclaimer. 13# 14# 2. Redistributions in binary form must reproduce the above copyright notice, 15# this list of conditions and the following disclaimer in the documentation 16# and/or other materials provided with the distribution. 17# 18# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 19# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 22# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 23# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 24# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 26# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 27# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 28# THE POSSIBILITY OF SUCH DAMAGE. 29#;**********************************************************************; 30set -u 31 32usage_error () 33{ 34 echo "$0: $*" >&2 35 print_usage >&2 36 exit 2 37} 38print_usage () 39{ 40 cat <<END 41Usage: 42 int-log-compiler.sh --ptpm=DEVICE 43 TEST-SCRIPT [TEST-SCRIPT-ARGUMENTS] 44The '--simulator-bin' option is mandatory. 45END 46} 47while test $# -gt 0; do 48 case $1 in 49 --help) print_usage; exit $?;; 50 -d|--ptpm) PTPM=$2; shift;; 51 -d=*|--ptpm=*) PTPM="${1#*=}";; 52 --) shift; break;; 53 -*) usage_error "invalid option: '$1'";; 54 *) break;; 55 esac 56 shift 57done 58 59# Verify the running shell and OS environment is sufficient to run these tests. 60sanity_test () 61{ 62 # Check special file 63 if [ ! -e /dev/urandom ]; then 64 echo "Missing file /dev/urandom; exiting" 65 exit 1 66 fi 67 68 # Check ps 69 PS_LINES=$(ps -e 2>/dev/null | wc -l) 70 if [ "$PS_LINES" -eq 0 ] ; then 71 echo "Command ps not listing processes; exiting" 72 exit 1 73 fi 74} 75 76sanity_test 77 78# Once option processing is done, $@ should be the name of the test executable 79# followed by all of the options passed to the test executable. 80TEST_BIN=$(realpath "$1") 81TEST_DIR=$(dirname "$1") 82TEST_NAME=$(basename "${TEST_BIN}") 83 84while true; do 85 86env TPM20TEST_TCTI_NAME="device" \ 87 TPM20TEST_DEVICE_FILE=${PTPM} \ 88 G_MESSAGES_DEBUG=all ./test/helper/tpm_transientempty 89if [ $? -ne 0 ]; then 90 echo "TPM transient area not empty => skipping" 91 ret=99 92 break 93fi 94 95TPMSTATE_FILE1=${TEST_BIN}_state1 96TPMSTATE_FILE2=${TEST_BIN}_state2 97 98env TPM20TEST_TCTI_NAME="device" \ 99 TPM20TEST_DEVICE_FILE=${PTPM} \ 100 TPM20TEST_TCTI="device:${PTPM}" \ 101 G_MESSAGES_DEBUG=all ./test/helper/tpm_dumpstate>$TPMSTATE_FILE1 102if [ $? -ne 0 ]; then 103 echo "Error during dumpstate" 104 ret=99 105 break 106fi 107 108echo "Execute the test script" 109env TPM20TEST_TCTI_NAME="device" \ 110 TPM20TEST_DEVICE_FILE=${PTPM} \ 111 TPM20TEST_TCTI="device:${PTPM}" \ 112 G_MESSAGES_DEBUG=all $@ 113ret=$? 114echo "Script returned $ret" 115 116env TPM20TEST_TCTI_NAME="device" \ 117 TPM20TEST_DEVICE_FILE=${PTPM} \ 118 TPM20TEST_TCTI="device:${PTPM}" \ 119 G_MESSAGES_DEBUG=all ./test/helper/tpm_dumpstate>$TPMSTATE_FILE2 120if [ $? -ne 0 ]; then 121 echo "Error during dumpstate" 122 ret=99 123 break 124fi 125 126if [ "$(cat $TPMSTATE_FILE1)" != "$(cat $TPMSTATE_FILE2)" ]; then 127 echo "TPM changed state during test" 128 echo "State before ($TPMSTATE_FILE1):" 129 cat $TPMSTATE_FILE1 130 echo "State after ($TPMSTATE_FILE2):" 131 cat $TPMSTATE_FILE2 132 ret=1 133 break 134fi 135 136break 137done 138 139exit $ret 140