tests: Refactor repetitive test scripts to use one common script

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
This commit is contained in:
Stefan Berger 2023-03-01 12:50:27 -05:00 committed by Stefan Berger
parent eb8a76807a
commit ddbc966ccc
5 changed files with 48 additions and 96 deletions

View File

@ -83,6 +83,7 @@ EXTRA_DIST = \
tpm2_createprimary.sh \
tpm2_pcr_read.c \
tpm2_pcr_read.sh \
tpm2_run_test.sh \
tpm2_selftest.c \
tpm2_selftest.sh \
fuzz.sh

View File

@ -2,36 +2,7 @@
# For the license, see the LICENSE file in the root directory.
ROOT=${abs_top_builddir:-$(pwd)/..}
TESTDIR=${abs_top_testdir:-$(dirname "$0")}
DIR=${PWD}
DIR=$(dirname "$0")
WORKDIR=$(mktemp -d)
. ${TESTDIR}/common
function cleanup()
{
rm -rf ${WORKDIR}
}
trap "cleanup" QUIT EXIT
pushd $WORKDIR &>/dev/null
${DIR}/tpm2_createprimary
rc=$?
fs=$(get_filesize NVChip)
[ $? -ne 0 ] && exit 1
exp=176832
if [ $fs -ne $exp ]; then
echo "Error: Unexpected size of NVChip file."
echo "Expected: $exp"
echo "Got : $fs"
rc=1
fi
popd &>/dev/null
exit $rc
"${DIR}/tpm2_run_test.sh" tpm2_createprimary
exit $?

View File

@ -2,36 +2,7 @@
# For the license, see the LICENSE file in the root directory.
ROOT=${abs_top_builddir:-$(pwd)/..}
TESTDIR=${abs_top_testdir:-$(dirname "$0")}
DIR=${PWD}
DIR=$(dirname "$0")
WORKDIR=$(mktemp -d)
. ${TESTDIR}/common
function cleanup()
{
rm -rf ${WORKDIR}
}
trap "cleanup" QUIT EXIT
pushd $WORKDIR &>/dev/null
${DIR}/tpm2_pcr_read
rc=$?
fs=$(get_filesize NVChip)
[ $? -ne 0 ] && exit 1
exp=176832
if [ $fs -ne $exp ]; then
echo "Error: Unexpected size of NVChip file."
echo "Expected: $exp"
echo "Got : $fs"
rc=1
fi
popd &>/dev/null
exit $rc
"${DIR}/tpm2_run_test.sh" tpm2_pcr_read
exit $?

38
tests/tpm2_run_test.sh Executable file
View File

@ -0,0 +1,38 @@
#!/usr/bin/env bash
# For the license, see the LICENSE file in the root directory.
ROOT=${abs_top_builddir:-$(pwd)/..}
TESTDIR=${abs_top_testdir:-$(dirname "$0")}
DIR=${PWD}
WORKDIR=$(mktemp -d)
. "${TESTDIR}/common"
function cleanup()
{
rm -rf "${WORKDIR}"
}
trap "cleanup" QUIT EXIT
pushd "$WORKDIR" &>/dev/null || exit 1
"${DIR}/${1}"
rc=$?
if ! fs=$(get_filesize NVChip); then
exit 1
fi
exp=176832
if [ "$fs" -ne "$exp" ]; then
echo "Error: Unexpected size of NVChip file."
echo "Expected: $exp"
echo "Got : $fs"
rc=1
fi
popd &>/dev/null || exit 1
exit $rc

View File

@ -2,36 +2,7 @@
# For the license, see the LICENSE file in the root directory.
ROOT=${abs_top_builddir:-$(pwd)/..}
TESTDIR=${abs_top_testdir:-$(dirname "$0")}
DIR=${PWD}
DIR=$(dirname "$0")
WORKDIR=$(mktemp -d)
. ${TESTDIR}/common
function cleanup()
{
rm -rf ${WORKDIR}
}
trap "cleanup" QUIT EXIT
pushd $WORKDIR &>/dev/null
${DIR}/tpm2_selftest
rc=$?
fs=$(get_filesize NVChip)
[ $? -ne 0 ] && exit 1
exp=176832
if [ $fs -ne $exp ]; then
echo "Error: Unexpected size of NVChip file."
echo "Expected: $exp"
echo "Got : $fs"
rc=1
fi
popd &>/dev/null
exit $rc
"${DIR}/tpm2_run_test.sh" tpm2_selftest
exit $?