tests: Fix shellcheck issue SC2181 by if cmd; ...
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
diff --git a/tests/Makefile.am b/tests/Makefile.am
index a7e19b0..535ccb1 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -242,8 +242,7 @@
# Sc2010: Don't use ls | grep. Use a glob or a for loop with a condition to allow non-alphanumeric filenames.
# SC2115: Use "${var:?}" to ensure this never expands to /*.
# SC2148: Tips depend on target shell and yours is unknown. Add a shebang or a 'shell' directive.
-# SC2181: Check exit code directly with e.g. if mycmd;, not indirectly with $?.
- shellcheck -e SC2001,SC2009,SC2010,SC2115,SC2148,SC2181 \
+ shellcheck -e SC2001,SC2009,SC2010,SC2115,SC2148 \
$(TESTS) $(TEST_UTILS) $(filter _test_%,$(EXTRA_DIST))
check: check-am check-display
diff --git a/tests/_test_encrypted_state b/tests/_test_encrypted_state
index c695fe5..40d6368 100755
--- a/tests/_test_encrypted_state
+++ b/tests/_test_encrypted_state
@@ -45,8 +45,7 @@
display_processes_by_name "$SWTPM"
-kill_quiet -0 "${SWTPM_PID}"
-if [ $? -ne 0 ]; then
+if ! kill_quiet -0 "${SWTPM_PID}"; then
echo "Error: ${SWTPM_INTERFACE} TPM did not start."
echo "TPM Logfile:"
cat "$logfile"
@@ -61,16 +60,14 @@
fi
# Init the TPM
-run_swtpm_ioctl "${SWTPM_INTERFACE}" -i
-if [ $? -ne 0 ]; then
+if ! run_swtpm_ioctl "${SWTPM_INTERFACE}" -i; then
echo "Error: ${SWTPM_INTERFACE} TPM initialization failed."
echo "TPM Logfile:"
cat "$logfile"
exit 1
fi
-kill_quiet -0 "${SWTPM_PID}" 2>/dev/null
-if [ $? -ne 0 ]; then
+if ! kill_quiet -0 "${SWTPM_PID}" 2>/dev/null; then
echo "Error: ${SWTPM_INTERFACE} TPM not running anymore after INIT."
echo "TPM Logfile:"
cat "$logfile"
@@ -87,8 +84,7 @@
exit 1
fi
-run_swtpm_ioctl "${SWTPM_INTERFACE}" -h 1234
-if [ $? -ne 0 ]; then
+if ! run_swtpm_ioctl "${SWTPM_INTERFACE}" -h 1234; then
echo "Error: Hash command did not work."
echo "TPM Logfile:"
cat "$logfile"
@@ -106,8 +102,7 @@
fi
# Save the volatile state
-run_swtpm_ioctl "${SWTPM_INTERFACE}" -v
-if [ $? -ne 0 ]; then
+if ! run_swtpm_ioctl "${SWTPM_INTERFACE}" -v; then
echo "Error: Saving the volatile state failed."
echo "TPM Logfile:"
cat "$logfile"
@@ -121,8 +116,7 @@
exit 1
fi
-tmp=$(run_swtpm_ioctl "${SWTPM_INTERFACE}" -g | cut -d":" -f2)
-if [ $? -ne 0 ]; then
+if ! tmp=$(run_swtpm_ioctl "${SWTPM_INTERFACE}" -g | cut -d":" -f2); then
echo "Error: Could not get the configration flags of the ${SWTPM_INTERFACE} TPM."
echo "TPM Logfile:"
cat "$logfile"
@@ -137,8 +131,7 @@
fi
# Shut the TPM down
-run_swtpm_ioctl "${SWTPM_INTERFACE}" -s
-if [ $? -ne 0 ]; then
+if ! run_swtpm_ioctl "${SWTPM_INTERFACE}" -s; then
echo "Error: Could not shut down the ${SWTPM_INTERFACE} TPM."
echo "TPM Logfile:"
cat "$logfile"
@@ -152,8 +145,7 @@
display_processes_by_name "$SWTPM"
-kill_quiet -0 "${SWTPM_PID}"
-if [ $? -ne 0 ]; then
+if ! kill_quiet -0 "${SWTPM_PID}"; then
echo "Error (2): ${SWTPM_INTERFACE} TPM did not start."
echo "TPM Logfile:"
cat "$logfile"
@@ -168,8 +160,7 @@
fi
# Init the TPM
-run_swtpm_ioctl "${SWTPM_INTERFACE}" -i
-if [ $? -ne 0 ]; then
+if ! run_swtpm_ioctl "${SWTPM_INTERFACE}" -i; then
echo "Error: ${SWTPM_INTERFACE} TPM initialization failed."
echo "TPM Logfile:"
cat "$logfile"
@@ -195,8 +186,7 @@
fi
# Save the volatile state again
-run_swtpm_ioctl "${SWTPM_INTERFACE}" -v
-if [ $? -ne 0 ]; then
+if ! run_swtpm_ioctl "${SWTPM_INTERFACE}" -v; then
echo "Error: Saving the volatile state failed."
echo "TPM Logfile:"
cat "$logfile"
@@ -211,8 +201,7 @@
fi
# Send a new TPM_Init
-run_swtpm_ioctl "${SWTPM_INTERFACE}" -i
-if [ $? -ne 0 ]; then
+if ! run_swtpm_ioctl "${SWTPM_INTERFACE}" -i; then
echo "Error: ${SWTPM_INTERFACE} TPM initialization failed."
echo "TPM Logfile:"
cat "$logfile"
@@ -239,8 +228,7 @@
# Final shut down
-run_swtpm_ioctl "${SWTPM_INTERFACE}" -s
-if [ $? -ne 0 ]; then
+if ! run_swtpm_ioctl "${SWTPM_INTERFACE}" -s; then
echo "Error: Could not shut down the ${SWTPM_INTERFACE} TPM."
echo "TPM Logfile:"
cat "$logfile"
diff --git a/tests/_test_getcap b/tests/_test_getcap
index 23aa710..84249ad 100755
--- a/tests/_test_getcap
+++ b/tests/_test_getcap
@@ -33,35 +33,30 @@
TPM_PATH=$TPM_PATH run_swtpm "${SWTPM_INTERFACE}"
-kill_quiet -0 "${SWTPM_PID}"
-if [ $? -ne 0 ]; then
+if ! kill_quiet -0 "${SWTPM_PID}"; then
echo "Error: ${SWTPM_INTERFACE} TPM did not start."
exit 1
fi
# Init the TPM
-run_swtpm_ioctl "${SWTPM_INTERFACE}" -i
-if [ $? -ne 0 ]; then
+if ! run_swtpm_ioctl "${SWTPM_INTERFACE}" -i; then
echo "Error: Could not initialize the ${SWTPM_INTERFACE} TPM."
exit 1
fi
-kill_quiet -0 "${SWTPM_PID}" 2>/dev/null
-if [ $? -ne 0 ]; then
+if ! kill_quiet -0 "${SWTPM_PID}" 2>/dev/null; then
echo "Error: ${SWTPM_INTERFACE} TPM not running anymore after INIT."
exit 1
fi
# Get the capabilities flags from the TPM
-act=$(run_swtpm_ioctl "${SWTPM_INTERFACE}" -c)
-if [ $? -ne 0 ]; then
+if ! act=$(run_swtpm_ioctl "${SWTPM_INTERFACE}" -c); then
echo "Error: Could not get the capability flags of the ${SWTPM_INTERFACE} TPM."
exit 1
fi
-kill_quiet -0 "${SWTPM_PID}" 2>/dev/null
-if [ $? -ne 0 ]; then
+if ! kill_quiet -0 "${SWTPM_PID}" 2>/dev/null; then
echo "Error: ${SWTPM_INTERFACE} TPM not running anymore after getting capabilities."
exit 1
fi
@@ -72,8 +67,7 @@
exit 1
fi
-run_swtpm_ioctl "${SWTPM_INTERFACE}" -s
-if [ $? -ne 0 ]; then
+if ! run_swtpm_ioctl "${SWTPM_INTERFACE}" -s; then
echo "Error: Could not shut down the ${SWTPM_INTERFACE} TPM."
exit 1
fi
diff --git a/tests/_test_hashing b/tests/_test_hashing
index b8879d5..7977cb8 100755
--- a/tests/_test_hashing
+++ b/tests/_test_hashing
@@ -35,21 +35,18 @@
display_processes_by_name "$SWTPM"
-kill_quiet -0 "${SWTPM_PID}"
-if [ $? -ne 0 ]; then
+if ! kill_quiet -0 "${SWTPM_PID}"; then
echo "Error: ${SWTPM_INTERFACE} TPM did not start."
exit 1
fi
# Init the TPM
-run_swtpm_ioctl "${SWTPM_INTERFACE}" -i
-if [ $? -ne 0 ]; then
+if ! run_swtpm_ioctl "${SWTPM_INTERFACE}" -i; then
echo "Error: Could not initialize the ${SWTPM_INTERFACE} TPM."
exit 1
fi
-kill_quiet -0 "${SWTPM_PID}" 2>/dev/null
-if [ $? -ne 0 ]; then
+if ! kill_quiet -0 "${SWTPM_PID}" 2>/dev/null; then
echo "Error: ${SWTPM_INTERFACE} TPM not running anymore after INIT."
exit 1
fi
@@ -65,8 +62,7 @@
fi
# Check the TPM Established bit before the hashing
-RES=$(run_swtpm_ioctl "${SWTPM_INTERFACE}" -e)
-if [ $? -ne 0 ]; then
+if ! RES=$(run_swtpm_ioctl "${SWTPM_INTERFACE}" -e); then
echo "Error: Could not get the TPM Established flag."
exit 1
fi
@@ -78,8 +74,7 @@
exit 1
fi
-run_swtpm_ioctl "${SWTPM_INTERFACE}" -h 1234
-if [ $? -ne 0 ]; then
+if ! run_swtpm_ioctl "${SWTPM_INTERFACE}" -h 1234; then
echo "Error: Hash command did not work."
exit 1
fi
@@ -95,8 +90,7 @@
fi
# Check the TPM Established bit after the hashing
-RES=$(run_swtpm_ioctl "${SWTPM_INTERFACE}" -e)
-if [ $? -ne 0 ]; then
+if ! RES=$(run_swtpm_ioctl "${SWTPM_INTERFACE}" -e); then
echo "Error: Could not get the TPM Established flag."
exit 1
fi
@@ -109,8 +103,7 @@
fi
# Reset the establishment bit via locality 3
-run_swtpm_ioctl "${SWTPM_INTERFACE}" -l 3
-if [ $? -ne -0 ]; then
+if ! run_swtpm_ioctl "${SWTPM_INTERFACE}" -l 3; then
echo "Error: Could not set locality 3"
exit 1
fi
@@ -126,8 +119,7 @@
fi
# Check the TPM Established bit after the reset
-RES=$(run_swtpm_ioctl "${SWTPM_INTERFACE}" -e)
-if [ $? -ne 0 ]; then
+if ! RES=$(run_swtpm_ioctl "${SWTPM_INTERFACE}" -e); then
echo "Error: Could not get the TPM Established flag."
exit 1
fi
@@ -140,8 +132,7 @@
fi
# back to locality 0
-run_swtpm_ioctl "${SWTPM_INTERFACE}" -l 0
-if [ $? -ne 0 ]; then
+if ! run_swtpm_ioctl "${SWTPM_INTERFACE}" -l 0; then
echo "Error: Could not set locality 0."
exit 1
fi
@@ -160,8 +151,7 @@
exit 1
fi
-run_swtpm_ioctl "${SWTPM_INTERFACE}" -s
-if [ $? -ne 0 ]; then
+if ! run_swtpm_ioctl "${SWTPM_INTERFACE}" -s; then
echo "Error: Could not shut down the ${SWTPM_INTERFACE} TPM."
exit 1
fi
diff --git a/tests/_test_hashing2 b/tests/_test_hashing2
index ae1e217..bb1cb59 100755
--- a/tests/_test_hashing2
+++ b/tests/_test_hashing2
@@ -35,23 +35,20 @@
display_processes_by_name "$SWTPM"
-kill_quiet -0 "${SWTPM_PID}"
-if [ $? -ne 0 ]; then
+if ! kill_quiet -0 "${SWTPM_PID}"; then
echo "Error: ${SWTPM_INTERFACE} TPM did not start."
exit 1
fi
# Init the TPM
-run_swtpm_ioctl "${SWTPM_INTERFACE}" -i
-if [ $? -ne 0 ]; then
+if ! run_swtpm_ioctl "${SWTPM_INTERFACE}" -i; then
echo "Error: ${SWTPM_INTERFACE} TPM initialization failed."
exit 1
fi
sleep 0.5
-kill_quiet -0 "${SWTPM_PID}" 2>/dev/null
-if [ $? -ne 0 ]; then
+if ! kill_quiet -0 "${SWTPM_PID}" 2>/dev/null; then
echo "Error: ${SWTPM_INTERFACE} TPM not running anymore after INIT."
exit 1
fi
@@ -67,8 +64,7 @@
fi
# Check the TPM Established bit before the hashing
-RES=$(run_swtpm_ioctl "${SWTPM_INTERFACE}" -e)
-if [ $? -ne 0 ]; then
+if ! RES=$(run_swtpm_ioctl "${SWTPM_INTERFACE}" -e); then
echo "Error: Could not get the TPM Established flag from the ${SWTPM_INTERFACE} TPM."
exit 1
fi
@@ -80,8 +76,7 @@
exit 1
fi
-run_swtpm_ioctl "${SWTPM_INTERFACE}" -h 1234
-if [ $? -ne 0 ]; then
+if ! run_swtpm_ioctl "${SWTPM_INTERFACE}" -h 1234; then
echo "Error: Hash command did not work."
exit 1
fi
@@ -97,8 +92,7 @@
fi
# Check the TPM Established bit after the hashing
-RES=$(run_swtpm_ioctl "${SWTPM_INTERFACE}" -e)
-if [ $? -ne 0 ]; then
+if ! RES=$(run_swtpm_ioctl "${SWTPM_INTERFACE}" -e); then
echo "Error: Could not get the TPM Established flag from the ${SWTPM_INTERFACE} TPM."
exit 1
fi
@@ -111,16 +105,14 @@
fi
# Reset the establishment bit; we switch to locality 0 and reset via locality 3
-run_swtpm_ioctl "${SWTPM_INTERFACE}" -l 0
-if [ $? -ne 0 ]; then
+if ! run_swtpm_ioctl "${SWTPM_INTERFACE}" -l 0; then
echo "Error: Could not set locality 0"
exit 1
fi
for ((l = 0; l <= 2; l++)); do
# Resetting via locality 2 must fail
- ERR="$(run_swtpm_ioctl "${SWTPM_INTERFACE}" -r "$l" 2>&1)"
- if [ $? -eq 0 ]; then
+ if ERR="$(run_swtpm_ioctl "${SWTPM_INTERFACE}" -r "$l" 2>&1)"; then
echo "Error: Could reset the establishment bit via locality $l"
exit 1
fi
@@ -136,8 +128,7 @@
# We expect the same results for the TPM_ResetEstablishment command
for ((l = 0; l <= 2; l++)); do
# Set locality
- run_swtpm_ioctl "${SWTPM_INTERFACE}" -l "$l"
- if [ $? -ne 0 ]; then
+ if ! run_swtpm_ioctl "${SWTPM_INTERFACE}" -l "$l"; then
echo "Error: Could not choose locality $l"
exit 1
fi
@@ -153,8 +144,7 @@
done
# Resetting via locality 3 must work
-run_swtpm_ioctl "${SWTPM_INTERFACE}" -l 3
-if [ $? -ne 0 ]; then
+if ! run_swtpm_ioctl "${SWTPM_INTERFACE}" -l 3; then
echo "Error: Could not reset the establishment bit via locality 3"
exit 1
fi
@@ -192,8 +182,7 @@
exit 1
fi
-run_swtpm_ioctl "${SWTPM_INTERFACE}" -s
-if [ $? -ne 0 ]; then
+if ! run_swtpm_ioctl "${SWTPM_INTERFACE}" -s; then
echo "Error: Could not shut down the ${SWTPM_INTERFACE} TPM."
exit 1
fi
diff --git a/tests/_test_init b/tests/_test_init
index 2b5c366..e841f4c 100755
--- a/tests/_test_init
+++ b/tests/_test_init
@@ -42,8 +42,7 @@
display_processes_by_name "$SWTPM"
-kill_quiet -0 "${SWTPM_PID}"
-if [ $? -ne 0 ]; then
+if ! kill_quiet -0 "${SWTPM_PID}"; then
echo "Error: ${SWTPM_INTERFACE} TPM did not start."
exit 1
fi
@@ -60,16 +59,14 @@
fi
# Init the TPM
-run_swtpm_ioctl "${SWTPM_INTERFACE}" -i
-if [ $? -ne 0 ]; then
+if ! run_swtpm_ioctl "${SWTPM_INTERFACE}" -i; then
echo "Error: Could not initialize the ${SWTPM_INTERFACE} TPM."
exit 1
fi
sleep 0.5
-kill_quiet -0 "${SWTPM_PID}" 2>/dev/null
-if [ $? -ne 0 ]; then
+if ! kill_quiet -0 "${SWTPM_PID}" 2>/dev/null; then
echo "Error: ${SWTPM_INTERFACE} TPM not running anymore after INIT."
exit 1
fi
@@ -78,45 +75,39 @@
# works if the TPM runs as non-root
if [ "$(id -u)" != "0" ]; then
chmod 000 "${STATE_FILE}"
- run_swtpm_ioctl "${SWTPM_INTERFACE}" -i
- if [ $? -eq 0 ]; then
+ if run_swtpm_ioctl "${SWTPM_INTERFACE}" -i; then
echo "Error: Unexpected initialization success of the ${SWTPM_INTERFACE} TPM."
exit 1
fi
sleep 0.5
- kill_quiet -0 "${SWTPM_PID}" 2>/dev/null
- if [ $? -ne 0 ]; then
+ if ! kill_quiet -0 "${SWTPM_PID}" 2>/dev/null; then
echo "Error: ${SWTPM_INTERFACE} TPM not running anymore after failed INIT."
exit 1
fi
chmod 644 "${STATE_FILE}"
# Init the TPM again; now with state file accessible again
- run_swtpm_ioctl "${SWTPM_INTERFACE}" -i
- if [ $? -ne 0 ]; then
+ if ! run_swtpm_ioctl "${SWTPM_INTERFACE}" -i; then
echo "Error: Could not initialize the ${SWTPM_INTERFACE} TPM."
exit 1
fi
sleep 0.5
- kill_quiet -0 "${SWTPM_PID}" 2>/dev/null
- if [ $? -ne 0 ]; then
+ if ! kill_quiet -0 "${SWTPM_PID}" 2>/dev/null; then
echo "Error: ${SWTPM_INTERFACE} TPM not running anymore after INIT."
exit 1
fi
fi
-check_seccomp_profile "${SWTPM_EXE}" ${SWTPM_PID} 0
-if [ $? -ne 0 ]; then
+if ! check_seccomp_profile "${SWTPM_EXE}" ${SWTPM_PID} 0; then
exit 1
fi
# Shut down
-run_swtpm_ioctl "${SWTPM_INTERFACE}" -s
-if [ $? -ne 0 ]; then
+if ! run_swtpm_ioctl "${SWTPM_INTERFACE}" -s; then
echo "Error: Could not shut down the ${SWTPM_INTERFACE} TPM."
exit 1
fi
diff --git a/tests/_test_locality b/tests/_test_locality
index ed71cf0..6b38f1d 100755
--- a/tests/_test_locality
+++ b/tests/_test_locality
@@ -35,49 +35,42 @@
display_processes_by_name "$SWTPM"
-kill_quiet -0 "${SWTPM_PID}"
-if [ $? -ne 0 ]; then
+if ! kill_quiet -0 "${SWTPM_PID}"; then
echo "Error: ${SWTPM_INTERFACE} TPM did not start."
exit 1
fi
# Init the TPM
-run_swtpm_ioctl "${SWTPM_INTERFACE}" -i
-if [ $? -ne 0 ]; then
+if ! run_swtpm_ioctl "${SWTPM_INTERFACE}" -i; then
echo "Error: Could not initialize the ${SWTPM_INTERFACE} TPM."
exit 1
fi
-kill_quiet -0 "${SWTPM_PID}" 2>/dev/null
-if [ $? -ne 0 ]; then
+if ! kill_quiet -0 "${SWTPM_PID}" 2>/dev/null; then
echo "Error: ${SWTPM_INTERFACE} TPM not running anymore after INIT."
exit 1
fi
# Set locality 4 on the TPM
-run_swtpm_ioctl "${SWTPM_INTERFACE}" -l 4
-if [ $? -ne 0 ]; then
+if ! run_swtpm_ioctl "${SWTPM_INTERFACE}" -l 4; then
echo "Error: ${SWTPM_INTERFACE} TPM did not accept locality 4."
exit 1
fi
# Set illegal locality 5 on the TPM
-run_swtpm_ioctl "${SWTPM_INTERFACE}" -l 5
-if [ $? -eq 0 ]; then
+if run_swtpm_ioctl "${SWTPM_INTERFACE}" -l 5; then
echo "Error: ${SWTPM_INTERFACE} TPM accepted locality 5."
exit 1
fi
# Set locality 0 on the TPM
-run_swtpm_ioctl "${SWTPM_INTERFACE}" -l 0
-if [ $? -ne 0 ]; then
+if ! run_swtpm_ioctl "${SWTPM_INTERFACE}" -l 0; then
echo "Error: ${SWTPM_INTERFACE} TPM did not accept locality 0."
exit 1
fi
# In locality 2 we can reset PCR 20
-run_swtpm_ioctl "${SWTPM_INTERFACE}" -l 2
-if [ $? -ne 0 ]; then
+if ! run_swtpm_ioctl "${SWTPM_INTERFACE}" -l 2; then
echo "Error: ${SWTPM_INTERFACE} TPM did not accept locality 2."
exit 1
fi
@@ -104,8 +97,7 @@
fi
# Shut down TPM
-run_swtpm_ioctl "${SWTPM_INTERFACE}" -s
-if [ $? -ne 0 ]; then
+if ! run_swtpm_ioctl "${SWTPM_INTERFACE}" -s; then
echo "Error: Could not shut down the ${SWTPM_INTERFACE} TPM."
exit 1
fi
diff --git a/tests/_test_migration_key b/tests/_test_migration_key
index 10481d2..72eea71 100755
--- a/tests/_test_migration_key
+++ b/tests/_test_migration_key
@@ -57,21 +57,18 @@
display_processes_by_name "$SWTPM"
-kill_quiet -0 "${SWTPM_PID}"
-if [ $? -ne 0 ]; then
+if ! kill_quiet -0 "${SWTPM_PID}"; then
echo "Error: ${SWTPM_INTERFACE} TPM did not start."
exit 1
fi
# Init the TPM
-run_swtpm_ioctl "${SWTPM_INTERFACE}" -i
-if [ $? -ne 0 ]; then
+if ! run_swtpm_ioctl "${SWTPM_INTERFACE}" -i; then
echo "Error: Initializing the ${SWTPM_INTERFACE} TPM failed."
exit 1
fi
-kill_quiet -0 "${SWTPM_PID}" 2>/dev/null
-if [ $? -ne 0 ]; then
+if ! kill_quiet -0 "${SWTPM_PID}" 2>/dev/null; then
echo "Error: ${SWTPM_INTERFACE} TPM not running anymore after INIT."
exit 1
fi
@@ -114,8 +111,7 @@
fi
# Save the volatile state into a file
-run_swtpm_ioctl "${SWTPM_INTERFACE}" --save volatile "$volatilestatefile"
-if [ $? -ne 0 ]; then
+if ! run_swtpm_ioctl "${SWTPM_INTERFACE}" --save volatile "$volatilestatefile"; then
echo "Error: Could not save the volatile state to ${volatilestatefile}."
exit 1
fi
@@ -133,8 +129,7 @@
exit 1
fi
-tmp=$(run_swtpm_ioctl "${SWTPM_INTERFACE}" -g | cut -d":" -f2)
-if [ $? -ne 0 ]; then
+if ! tmp=$(run_swtpm_ioctl "${SWTPM_INTERFACE}" -g | cut -d":" -f2); then
echo "Error: Could not get the configration flags of the ${SWTPM_INTERFACE} TPM."
exit 1
fi
@@ -156,8 +151,7 @@
display_processes_by_name "$SWTPM"
-kill_quiet -0 "${SWTPM_PID}"
-if [ $? -ne 0 ]; then
+if ! kill_quiet -0 "${SWTPM_PID}"; then
echo "Error: ${SWTPM_INTERFACE} TPM did not start."
exit 1
fi
@@ -165,15 +159,13 @@
# Do NOT init the TPM now; first load volatile state
# load the encrypted volatile state into it
-run_swtpm_ioctl "${SWTPM_INTERFACE}" --load volatile "$volatilestatefile"
-if [ $? -ne 0 ]; then
+if ! run_swtpm_ioctl "${SWTPM_INTERFACE}" --load volatile "$volatilestatefile"; then
echo "Error: Could not load encrypted volatile state into TPM."
exit 1
fi
# Now init the TPM
-run_swtpm_ioctl "${SWTPM_INTERFACE}" -i
-if [ $? -ne 0 ]; then
+if ! run_swtpm_ioctl "${SWTPM_INTERFACE}" -i; then
echo "Error: Initializing the ${SWTPM_INTERFACE} TPM failed."
exit 1
fi
@@ -190,8 +182,7 @@
# Shut the TPM down
exec 100>&-
-run_swtpm_ioctl "${SWTPM_INTERFACE}" -s
-if [ $? -ne 0 ]; then
+if ! run_swtpm_ioctl "${SWTPM_INTERFACE}" -s; then
echo "Error: Could not shut down the ${SWTPM_INTERFACE} TPM."
exit 1
fi
@@ -205,8 +196,7 @@
display_processes_by_name "$SWTPM"
-kill_quiet -0 "${SWTPM_PID}"
-if [ $? -ne 0 ]; then
+if ! kill_quiet -0 "${SWTPM_PID}"; then
echo "Error: ${SWTPM_INTERFACE} TPM did not start."
exit 1
fi
@@ -216,8 +206,7 @@
# load the encrypted volatile state into it
# This will not work; the TPM writes the data into the volatile state file
# and validates it
-ERR=$(run_swtpm_ioctl "${SWTPM_INTERFACE}" --load volatile "$volatilestatefile" 2>&1)
-if [ $? -eq 0 ]; then
+if ERR=$(run_swtpm_ioctl "${SWTPM_INTERFACE}" --load volatile "$volatilestatefile" 2>&1); then
echo "Error: Could load encrypted volatile state into TPM."
exit 1
fi
@@ -229,8 +218,7 @@
exit 1
fi
-run_swtpm_ioctl "${SWTPM_INTERFACE}" -s
-if [ $? -ne 0 ]; then
+if ! run_swtpm_ioctl "${SWTPM_INTERFACE}" -s; then
echo "Error: Could not shut down the ${SWTPM_INTERFACE} TPM."
exit 1
fi
@@ -245,22 +233,19 @@
display_processes_by_name "$SWTPM"
-kill_quiet -0 "${SWTPM_PID}"
-if [ $? -ne 0 ]; then
+if ! kill_quiet -0 "${SWTPM_PID}"; then
echo "Error: ${SWTPM_INTERFACE} TPM did not start."
exit 1
fi
# load the encrypted volatile state into it
-run_swtpm_ioctl "${SWTPM_INTERFACE}" --load volatile "$VOLATILESTATE"
-if [ $? -ne 0 ]; then
+if ! run_swtpm_ioctl "${SWTPM_INTERFACE}" --load volatile "$VOLATILESTATE"; then
echo "Error: Could not load encrypted volatile state into TPM."
exit 1
fi
# Now init the TPM; this must work
-run_swtpm_ioctl "${SWTPM_INTERFACE}" -i
-if [ $? -ne 0 ]; then
+if ! run_swtpm_ioctl "${SWTPM_INTERFACE}" -i; then
echo "Error: Could not initialize the ${SWTPM_INTERFACE} TPM."
exit 1
fi
@@ -277,8 +262,7 @@
# Shut the TPM down
exec 100>&-
-run_swtpm_ioctl "${SWTPM_INTERFACE}" -s
-if [ $? -ne 0 ]; then
+if ! run_swtpm_ioctl "${SWTPM_INTERFACE}" -s; then
echo "Error: Could not shut down the ${SWTPM_INTERFACE} TPM."
exit 1
fi
diff --git a/tests/_test_print_capabilities b/tests/_test_print_capabilities
index fe50661..4894baa 100755
--- a/tests/_test_print_capabilities
+++ b/tests/_test_print_capabilities
@@ -11,8 +11,7 @@
[ "${SWTPM_IFACE}" == "cuse" ] && source "${TESTDIR}/test_cuse"
source "${TESTDIR}/common"
-msg="$(${SWTPM_EXE} "${SWTPM_IFACE}" --print-capabilities 2>&1)"
-if [ $? -ne 0 ]; then
+if ! msg="$(${SWTPM_EXE} "${SWTPM_IFACE}" --print-capabilities 2>&1)"; then
echo "Error: Could not pass --print-capabilities"
echo "${msg}"
exit 1
@@ -35,8 +34,7 @@
echo "Test 1: OK"
-msg="$(${SWTPM_SETUP} --print-capabilities 2>&1)"
-if [ $? -ne 0 ]; then
+if ! msg="$(${SWTPM_SETUP} --print-capabilities 2>&1)"; then
echo "Error: Could not pass --print-capabilities"
echo "${msg}"
exit 1
@@ -55,8 +53,7 @@
# SWTPM_CERT may be run by valgrind
if [ -x "$(type -P "$(echo "${SWTPM_CERT}" | cut -d" " -f1)" )" ]; then
- msg="$(${SWTPM_CERT} --print-capabilities 2>&1)"
- if [ $? -ne 0 ]; then
+ if ! msg="$(${SWTPM_CERT} --print-capabilities 2>&1)"; then
echo "Error: Could not pass --print-capabilities to ${SWTPM_CERT}"
echo "${msg}"
exit 1
diff --git a/tests/_test_print_states b/tests/_test_print_states
index 05a07b3..c648ce5 100755
--- a/tests/_test_print_states
+++ b/tests/_test_print_states
@@ -21,9 +21,7 @@
# Test 1: No states
workdir="$(mktemp -d)" || exit 1
-msg="$(${SWTPM_EXE} "${SWTPM_IFACE}" --print-states --tpmstate "dir=${workdir}" 2>&1)"
-
-if [ $? -ne 0 ]; then
+if ! msg="$(${SWTPM_EXE} "${SWTPM_IFACE}" --print-states --tpmstate "dir=${workdir}" 2>&1)"; then
echo "Error: Could not pass --print-states"
echo "${msg}"
exit 1
@@ -48,9 +46,7 @@
dummydata="DUMMY"
echo "$dummydata" > "${statefile}"
-msg="$(${SWTPM_EXE} "${SWTPM_IFACE}" --print-states --tpmstate "dir=${workdir}" 2>&1)"
-
-if [ $? -ne 0 ]; then
+if ! msg="$(${SWTPM_EXE} "${SWTPM_IFACE}" --print-states --tpmstate "dir=${workdir}" 2>&1)"; then
echo "Error: Could not pass --print-states"
echo "${msg}"
exit 1
diff --git a/tests/_test_resume_volatile b/tests/_test_resume_volatile
index 69c7a12..083e539 100755
--- a/tests/_test_resume_volatile
+++ b/tests/_test_resume_volatile
@@ -43,21 +43,18 @@
display_processes_by_name "$SWTPM"
-kill_quiet -0 "${SWTPM_PID}"
-if [ $? -ne 0 ]; then
+if ! kill_quiet -0 "${SWTPM_PID}"; then
echo "Error: ${SWTPM_INTERFACE} TPM did not start."
exit 1
fi
# Init the TPM
-run_swtpm_ioctl "${SWTPM_INTERFACE}" -i
-if [ $? -ne 0 ]; then
+if ! run_swtpm_ioctl "${SWTPM_INTERFACE}" -i; then
echo "Error: Could not initialize the ${SWTPM_INTERFACE} TPM."
exit 1
fi
-kill_quiet -0 "${SWTPM_PID}" 2>/dev/null
-if [ $? -ne 0 ]; then
+if ! kill_quiet -0 "${SWTPM_PID}" 2>/dev/null; then
echo "Error: ${SWTPM_INTERFACE} TPM not running anymore after INIT."
exit 1
fi
@@ -73,8 +70,7 @@
fi
# Save the volatile state again
-run_swtpm_ioctl "${SWTPM_INTERFACE}" -v
-if [ $? -ne 0 ]; then
+if ! run_swtpm_ioctl "${SWTPM_INTERFACE}" -v; then
echo "Error: Could not have the ${SWTPM_INTERFACE} TPM write the volatile state to a file."
exit 1
fi
@@ -98,21 +94,18 @@
display_processes_by_name "$SWTPM"
-kill_quiet -0 "${SWTPM_PID}"
-if [ $? -ne 0 ]; then
+if ! kill_quiet -0 "${SWTPM_PID}"; then
echo "Error: ${SWTPM_INTERFACE} TPM did not start."
exit 1
fi
# Init the TPM
-run_swtpm_ioctl "${SWTPM_INTERFACE}" -i
-if [ $? -ne 0 ]; then
+if ! run_swtpm_ioctl "${SWTPM_INTERFACE}" -i; then
echo "Error: ${SWTPM_INTERFACE} TPM initialization failed."
exit 1
fi
-kill_quiet -0 "${SWTPM_PID}" 2>/dev/null
-if [ $? -ne 0 ]; then
+if ! kill_quiet -0 "${SWTPM_PID}" 2>/dev/null; then
echo "Error: ${SWTPM_INTERFACE} TPM not running anymore after INIT."
exit 1
fi
@@ -128,8 +121,7 @@
fi
# Save the volatile state again
-run_swtpm_ioctl "${SWTPM_INTERFACE}" -v
-if [ $? -ne 0 ]; then
+if ! run_swtpm_ioctl "${SWTPM_INTERFACE}" -v; then
echo "Error: Could not have the ${SWTPM_INTERFACE} TPM write the volatile state to a file."
exit 1
fi
@@ -139,8 +131,7 @@
fi
# Shut the TPM down
-run_swtpm_ioctl "${SWTPM_INTERFACE}" -s
-if [ $? -ne 0 ]; then
+if ! run_swtpm_ioctl "${SWTPM_INTERFACE}" -s; then
echo "Error: Could not shut down the ${SWTPM_INTERFACE} TPM."
exit 1
fi
@@ -156,21 +147,18 @@
display_processes_by_name "$SWTPM"
-kill_quiet -0 "${SWTPM_PID}"
-if [ $? -ne 0 ]; then
+if ! kill_quiet -0 "${SWTPM_PID}"; then
echo "Error: ${SWTPM_INTERFACE} TPM did not start."
exit 1
fi
# Init the TPM
-run_swtpm_ioctl "${SWTPM_INTERFACE}" -i
-if [ $? -ne 0 ]; then
+if ! run_swtpm_ioctl "${SWTPM_INTERFACE}" -i; then
echo "Error: ${SWTPM_INTERFACE} TPM initialization failed."
exit 1
fi
-kill_quiet -0 "${SWTPM_PID}" 2>/dev/null
-if [ $? -ne 0 ]; then
+if ! kill_quiet -0 "${SWTPM_PID}" 2>/dev/null; then
echo "Error: ${SWTPM_INTERFACE} TPM not running anymore after INIT."
exit 1
fi
@@ -186,8 +174,7 @@
fi
# Save the volatile state again
-run_swtpm_ioctl "${SWTPM_INTERFACE}" -v
-if [ $? -ne 0 ]; then
+if ! run_swtpm_ioctl "${SWTPM_INTERFACE}" -v; then
echo "Error: Could not have the ${SWTPM_INTERFACE} TPM write the volatile state to a file."
exit 1
fi
@@ -197,8 +184,7 @@
fi
# Shut the TPM down
-run_swtpm_ioctl "${SWTPM_INTERFACE}" -s
-if [ $? -ne 0 ]; then
+if ! run_swtpm_ioctl "${SWTPM_INTERFACE}" -s; then
echo "Error: Could not shut down the ${SWTPM_INTERFACE} TPM."
exit 1
fi
diff --git a/tests/_test_save_load_encrypted_state b/tests/_test_save_load_encrypted_state
index a096c24..df92f91 100755
--- a/tests/_test_save_load_encrypted_state
+++ b/tests/_test_save_load_encrypted_state
@@ -47,8 +47,7 @@
display_processes_by_name "$SWTPM"
-kill_quiet -0 "${SWTPM_PID}"
-if [ $? -ne 0 ]; then
+if ! kill_quiet -0 "${SWTPM_PID}"; then
echo "Error: ${SWTPM_INTERFACE} TPM did not start."
echo "TPM Logfile:"
cat "$logfile"
@@ -56,16 +55,14 @@
fi
# Init the TPM
-run_swtpm_ioctl "${SWTPM_INTERFACE}" -i
-if [ $? -ne 0 ]; then
+if ! run_swtpm_ioctl "${SWTPM_INTERFACE}" -i; then
echo "Error: ${SWTPM_INTERFACE} TPM initialization failed."
echo "TPM Logfile:"
cat "$logfile"
exit 1
fi
-kill_quiet -0 "${SWTPM_PID}" 2>/dev/null
-if [ $? -ne 0 ]; then
+if ! kill_quiet -0 "${SWTPM_PID}" 2>/dev/null; then
echo "Error: ${SWTPM_INTERFACE} TPM not running anymore after INIT."
echo "TPM Logfile:"
cat "$logfile"
@@ -82,8 +79,7 @@
exit 1
fi
-run_swtpm_ioctl "${SWTPM_INTERFACE}" -h 1234
-if [ $? -ne 0 ]; then
+if ! run_swtpm_ioctl "${SWTPM_INTERFACE}" -h 1234; then
echo "Error: Could not hash the data."
echo "TPM Logfile:"
cat "$logfile"
@@ -127,8 +123,7 @@
exit 1
fi
-run_swtpm_ioctl "${SWTPM_INTERFACE}" --save permanent "$MY_PERMANENT_STATE_FILE"
-if [ $? -ne 0 ]; then
+if ! run_swtpm_ioctl "${SWTPM_INTERFACE}" --save permanent "$MY_PERMANENT_STATE_FILE"; then
echo "Error: Could not write permanent state file $MY_PERMANENT_STATE_FILE."
echo "TPM Logfile:"
cat "$logfile"
@@ -142,8 +137,7 @@
fi
echo "Saved permanent state."
-run_swtpm_ioctl "${SWTPM_INTERFACE}" --save volatile "$MY_VOLATILE_STATE_FILE"
-if [ $? -ne 0 ]; then
+if ! run_swtpm_ioctl "${SWTPM_INTERFACE}" --save volatile "$MY_VOLATILE_STATE_FILE"; then
echo "Error: Could not write volatile state file $MY_PERMANENT_STATE_FILE."
echo "TPM Logfile:"
cat "$logfile"
@@ -164,16 +158,14 @@
rm -f "$VOLATILE_STATE_FILE" "$STATE_FILE"
# Stop the TPM; this will not shut it down
-run_swtpm_ioctl "${SWTPM_INTERFACE}" --stop
-if [ $? -ne 0 ]; then
+if ! run_swtpm_ioctl "${SWTPM_INTERFACE}" --stop; then
echo "Error (2): Could not stop the ${SWTPM_INTERFACE} TPM"
echo "TPM Logfile:"
cat "$logfile"
exit 1
fi
-kill_quiet -0 "${SWTPM_PID}"
-if [ $? -ne 0 ]; then
+if ! kill_quiet -0 "${SWTPM_PID}"; then
echo "Error (2): ${SWTPM_INTERFACE} TPM is not running anymore."
echo "TPM Logfile:"
cat "$logfile"
@@ -181,8 +173,7 @@
fi
# load state into the TPM
-run_swtpm_ioctl "${SWTPM_INTERFACE}" --load permanent "$MY_PERMANENT_STATE_FILE"
-if [ $? -ne 0 ]; then
+if ! run_swtpm_ioctl "${SWTPM_INTERFACE}" --load permanent "$MY_PERMANENT_STATE_FILE"; then
echo "Could not load permanent state into vTPM"
echo "TPM Logfile:"
cat "$logfile"
@@ -190,8 +181,7 @@
fi
echo "Loaded permanent state."
-run_swtpm_ioctl "${SWTPM_INTERFACE}" --load volatile "$MY_VOLATILE_STATE_FILE"
-if [ $? -ne 0 ]; then
+if ! run_swtpm_ioctl "${SWTPM_INTERFACE}" --load volatile "$MY_VOLATILE_STATE_FILE"; then
echo "Could not load volatile state into vTPM"
echo "TPM Logfile:"
cat "$logfile"
@@ -203,8 +193,7 @@
#sha1sum $(dirname $MY_VOLATILE_STATE_FILE)/*
# Init the TPM
-run_swtpm_ioctl "${SWTPM_INTERFACE}" -i
-if [ $? -ne 0 ]; then
+if ! run_swtpm_ioctl "${SWTPM_INTERFACE}" -i; then
echo "TPM Init failed."
echo "TPM Logfile:"
cat "$logfile"
@@ -230,8 +219,7 @@
fi
# Save the volatile state again
-run_swtpm_ioctl "${SWTPM_INTERFACE}" -v
-if [ $? -ne 0 ]; then
+if ! run_swtpm_ioctl "${SWTPM_INTERFACE}" -v; then
echo "Error: Could not have the ${SWTPM_INTERFACE} TPM write the volatile state to a file."
echo "TPM Logfile:"
cat "$logfile"
@@ -245,8 +233,7 @@
fi
# Send a new TPM_Init
-run_swtpm_ioctl "${SWTPM_INTERFACE}" -i
-if [ $? -ne 0 ]; then
+if ! run_swtpm_ioctl "${SWTPM_INTERFACE}" -i; then
echo "Error: ${SWTPM_INTERFACE} TPM initialization failed."
echo "TPM Logfile:"
cat "$logfile"
@@ -271,8 +258,7 @@
exit 1
fi
-run_swtpm_ioctl "${SWTPM_INTERFACE}" -s
-if [ $? -ne 0 ]; then
+if ! run_swtpm_ioctl "${SWTPM_INTERFACE}" -s; then
echo "Error: Could not shut down the ${SWTPM_INTERFACE} TPM."
echo "TPM Logfile:"
cat "$logfile"
@@ -306,8 +292,7 @@
display_processes_by_name "$SWTPM"
-kill_quiet -0 "${SWTPM_PID}"
-if [ $? -ne 0 ]; then
+if ! kill_quiet -0 "${SWTPM_PID}"; then
echo "Error: ${SWTPM_INTERFACE} TPM did not start."
echo "TPM Logfile:"
cat "$logfile"
@@ -315,8 +300,7 @@
fi
# Init the TPM
-ERR="$(run_swtpm_ioctl "${SWTPM_INTERFACE}" -i 2>&1)"
-if [ $? -eq 0 ]; then
+if ERR="$(run_swtpm_ioctl "${SWTPM_INTERFACE}" -i 2>&1)"; then
echo "Error: ${SWTPM_INTERFACE} TPM initialization should have failed."
echo "TPM Logfile:"
cat "$logfile"
@@ -330,8 +314,7 @@
exit 1
fi
-kill_quiet -0 "${SWTPM_PID}" 2>/dev/null
-if [ $? -ne 0 ]; then
+if ! kill_quiet -0 "${SWTPM_PID}" 2>/dev/null; then
echo "Error: ${SWTPM_INTERFACE} TPM not running anymore after failed INIT."
echo "TPM Logfile:"
cat "$logfile"
@@ -349,8 +332,7 @@
fi
# shut it down
-run_swtpm_ioctl "${SWTPM_INTERFACE}" -s
-if [ $? -ne 0 ]; then
+if ! run_swtpm_ioctl "${SWTPM_INTERFACE}" -s; then
echo "Error: Could not shut down the ${SWTPM_INTERFACE} TPM."
echo "TPM Logfile:"
cat "$logfile"
@@ -384,8 +366,7 @@
display_processes_by_name "$SWTPM"
-kill_quiet -0 "${SWTPM_PID}"
-if [ $? -ne 0 ]; then
+if ! kill_quiet -0 "${SWTPM_PID}"; then
echo "Error: ${SWTPM_INTERFACE} TPM did not start."
echo "TPM Logfile:"
cat "$logfile"
@@ -393,8 +374,7 @@
fi
# Init the TPM
-ERR="$(run_swtpm_ioctl "${SWTPM_INTERFACE}" -i 2>&1)"
-if [ $? -eq 0 ]; then
+if ERR="$(run_swtpm_ioctl "${SWTPM_INTERFACE}" -i 2>&1)"; then
echo "Error: ${SWTPM_INTERFACE} TPM initialization should have failed."
echo "TPM Logfile:"
cat "$logfile"
@@ -408,8 +388,7 @@
exit 1
fi
-kill_quiet -0 "${SWTPM_PID}" 2>/dev/null
-if [ $? -ne 0 ]; then
+if ! kill_quiet -0 "${SWTPM_PID}" 2>/dev/null; then
echo "Error: ${SWTPM_INTERFACE} TPM not running anymore after failed INIT."
echo "TPM Logfile:"
cat "$logfile"
@@ -429,8 +408,7 @@
echo "Test 3: Ok"
# Final shut down
-run_swtpm_ioctl "${SWTPM_INTERFACE}" -s
-if [ $? -ne 0 ]; then
+if ! run_swtpm_ioctl "${SWTPM_INTERFACE}" -s; then
echo "Error: Could not shut down the ${SWTPM_INTERFACE} TPM."
echo "TPM Logfile:"
cat "$logfile"
diff --git a/tests/_test_save_load_state b/tests/_test_save_load_state
index f168d31..2693c27 100755
--- a/tests/_test_save_load_state
+++ b/tests/_test_save_load_state
@@ -49,8 +49,7 @@
display_processes_by_name "$SWTPM"
-kill_quiet -0 "${SWTPM_PID}"
-if [ $? -ne 0 ]; then
+if ! kill_quiet -0 "${SWTPM_PID}"; then
echo "Error: ${SWTPM_INTERFACE} TPM did not start."
echo "TPM Logfile:"
cat "$logfile"
@@ -58,16 +57,14 @@
fi
# Init the TPM
-run_swtpm_ioctl "${SWTPM_INTERFACE}" -i
-if [ $? -ne 0 ]; then
+if ! run_swtpm_ioctl "${SWTPM_INTERFACE}" -i; then
echo "Error: Could not initialize the ${SWTPM_INTERFACE} TPM."
echo "TPM Logfile:"
cat "$logfile"
exit 1
fi
-kill_quiet -0 "${SWTPM_PID}" 2>/dev/null
-if [ $? -ne 0 ]; then
+if ! kill_quiet -0 "${SWTPM_PID}" 2>/dev/null; then
echo "Error: ${SWTPM_INTERFACE} TPM not running anymore after INIT."
echo "TPM Logfile:"
cat "$logfile"
@@ -84,8 +81,7 @@
exit 1
fi
-run_swtpm_ioctl "${SWTPM_INTERFACE}" -h 1234
-if [ $? -ne 0 ]; then
+if ! run_swtpm_ioctl "${SWTPM_INTERFACE}" -h 1234; then
echo "Error: Hash command did not work."
echo "TPM Logfile:"
cat "$logfile"
@@ -139,8 +135,7 @@
exit 1
fi
-run_swtpm_ioctl "${SWTPM_INTERFACE}" --save permanent "$MY_PERMANENT_STATE_FILE"
-if [ $? -ne 0 ]; then
+if ! run_swtpm_ioctl "${SWTPM_INTERFACE}" --save permanent "$MY_PERMANENT_STATE_FILE"; then
echo "Error: Could not write permanent state file $MY_PERMANENT_STATE_FILE."
echo "TPM Logfile:"
cat "$logfile"
@@ -154,8 +149,7 @@
fi
echo "Saved permanent state."
-run_swtpm_ioctl "${SWTPM_INTERFACE}" --save volatile "$MY_VOLATILE_STATE_FILE"
-if [ $? -ne 0 ]; then
+if ! run_swtpm_ioctl "${SWTPM_INTERFACE}" --save volatile "$MY_VOLATILE_STATE_FILE"; then
echo "Error: Could not write volatile state file $MY_VOLATILE_STATE_FILE."
echo "TPM Logfile:"
cat "$logfile"
@@ -169,8 +163,7 @@
fi
echo "Saved volatile state."
-run_swtpm_ioctl "${SWTPM_INTERFACE}" --save savestate "$MY_SAVESTATE_STATE_FILE"
-if [ $? -ne 0 ]; then
+if ! run_swtpm_ioctl "${SWTPM_INTERFACE}" --save savestate "$MY_SAVESTATE_STATE_FILE"; then
echo "Error: Could not write savestate state file $MY_SAVESTATE_STATE_FILE."
echo "TPM Logfile:"
cat "$logfile"
@@ -192,16 +185,14 @@
# Stop the TPM; this will not shut it down
exec 100>&-
-run_swtpm_ioctl "${SWTPM_INTERFACE}" --stop
-if [ $? -ne 0 ]; then
+if ! run_swtpm_ioctl "${SWTPM_INTERFACE}" --stop; then
echo "Error: Could not stop the ${SWTPM_INTERFACE} TPM."
echo "TPM Logfile:"
cat "$logfile"
exit 1
fi
-kill_quiet -0 "${SWTPM_PID}"
-if [ $? -ne 0 ]; then
+if ! kill_quiet -0 "${SWTPM_PID}"; then
echo "Error (2): ${SWTPM_INTERFACE} TPM is not running anymore."
echo "TPM Logfile:"
cat "$logfile"
@@ -209,8 +200,7 @@
fi
# load state into the TPM
-run_swtpm_ioctl "${SWTPM_INTERFACE}" --load permanent "$MY_PERMANENT_STATE_FILE"
-if [ $? -ne 0 ]; then
+if ! run_swtpm_ioctl "${SWTPM_INTERFACE}" --load permanent "$MY_PERMANENT_STATE_FILE"; then
echo "Could not load permanent state into vTPM"
echo "TPM Logfile:"
cat "$logfile"
@@ -218,8 +208,7 @@
fi
echo "Loaded permanent state."
-run_swtpm_ioctl "${SWTPM_INTERFACE}" --load volatile "$MY_VOLATILE_STATE_FILE"
-if [ $? -ne 0 ]; then
+if ! run_swtpm_ioctl "${SWTPM_INTERFACE}" --load volatile "$MY_VOLATILE_STATE_FILE"; then
echo "Could not load volatile state into vTPM"
echo "TPM Logfile:"
cat "$logfile"
@@ -227,8 +216,7 @@
fi
echo "Loaded volatile state."
-run_swtpm_ioctl "${SWTPM_INTERFACE}" --load savestate "$MY_SAVESTATE_STATE_FILE"
-if [ $? -ne 0 ]; then
+if ! run_swtpm_ioctl "${SWTPM_INTERFACE}" --load savestate "$MY_SAVESTATE_STATE_FILE"; then
echo "Could not load savestate state into vTPM"
echo "TPM Logfile:"
cat "$logfile"
@@ -240,8 +228,7 @@
#sha1sum $(dirname $MY_VOLATILE_STATE_FILE)/*
# Init the TPM
-run_swtpm_ioctl "${SWTPM_INTERFACE}" -i
-if [ $? -ne 0 ]; then
+if ! run_swtpm_ioctl "${SWTPM_INTERFACE}" -i; then
echo "TPM Init failed."
echo "TPM Logfile:"
cat "$logfile"
@@ -267,8 +254,7 @@
fi
# Save the volatile state again
-run_swtpm_ioctl "${SWTPM_INTERFACE}" -v
-if [ $? -ne 0 ]; then
+if ! run_swtpm_ioctl "${SWTPM_INTERFACE}" -v; then
echo "Error: Could not have the ${SWTPM_INTERFACE} TPM store the volatile state to a file."
echo "TPM Logfile:"
cat "$logfile"
@@ -283,8 +269,7 @@
fi
# Send a new TPM_Init
-run_swtpm_ioctl "${SWTPM_INTERFACE}" -i
-if [ $? -ne 0 ]; then
+if ! run_swtpm_ioctl "${SWTPM_INTERFACE}" -i; then
echo "Error: Could not initialize the ${SWTPM_INTERFACE} TPM."
echo "TPM Logfile:"
cat "$logfile"
@@ -311,8 +296,7 @@
# Final shut down
exec 100>&-
-run_swtpm_ioctl "${SWTPM_INTERFACE}" -s
-if [ $? -ne 0 ]; then
+if ! run_swtpm_ioctl "${SWTPM_INTERFACE}" -s; then
echo "Error: Could not shut down the ${SWTPM_INTERFACE} TPM."
echo "TPM Logfile:"
cat "$logfile"
diff --git a/tests/_test_setbuffersize b/tests/_test_setbuffersize
index 3709c99..bd5e688 100755
--- a/tests/_test_setbuffersize
+++ b/tests/_test_setbuffersize
@@ -34,15 +34,13 @@
TPM_PATH=$TPM_PATH run_swtpm "${SWTPM_INTERFACE}"
-kill_quiet -0 "${SWTPM_PID}"
-if [ $? -ne 0 ]; then
+if ! kill_quiet -0 "${SWTPM_PID}"; then
echo "Error: ${SWTPM_INTERFACE} TPM did not start."
exit 1
fi
# Check the buffer size
-run_swtpm_ioctl "${SWTPM_INTERFACE}" -b 0 > "${OUTFILE}"
-if [ $? -ne 0 ]; then
+if ! run_swtpm_ioctl "${SWTPM_INTERFACE}" -b 0 > "${OUTFILE}"; then
echo "Error: Could not get the buffersize of the ${SWTPM_INTERFACE} TPM."
exit 1
fi
@@ -52,10 +50,9 @@
echo "Error: The TPM buffersize of the ${SWTPM_INTERFACE} TPM is not 4096."
exit 1
fi
-
+
# set the buffer size
-run_swtpm_ioctl "${SWTPM_INTERFACE}" -b 4000 > "${OUTFILE}"
-if [ $? -ne 0 ]; then
+if ! run_swtpm_ioctl "${SWTPM_INTERFACE}" -b 4000 > "${OUTFILE}"; then
echo "Error: Could not set the buffersize of the ${SWTPM_INTERFACE} TPM."
exit 1
fi
@@ -67,15 +64,13 @@
fi
# Init the TPM
-run_swtpm_ioctl "${SWTPM_INTERFACE}" -i
-if [ $? -ne 0 ]; then
+if ! run_swtpm_ioctl "${SWTPM_INTERFACE}" -i; then
echo "Error: Could not initialize the ${SWTPM_INTERFACE} TPM."
exit 1
fi
# Set the buffer size -- should fail
-ERR="$(run_swtpm_ioctl "${SWTPM_INTERFACE}" -b 4096 2>&1)"
-if [ $? -eq 0 ]; then
+if ERR="$(run_swtpm_ioctl "${SWTPM_INTERFACE}" -b 4096 2>&1)"; then
echo "Error: Could set the buffersize while the ${SWTPM_INTERFACE} TPM is running."
exit 1
fi
@@ -87,14 +82,12 @@
exit 1
fi
-kill_quiet -0 "${SWTPM_PID}" 2>/dev/null
-if [ $? -ne 0 ]; then
+if ! kill_quiet -0 "${SWTPM_PID}" 2>/dev/null; then
echo "Error: ${SWTPM_INTERFACE} TPM not running anymore after INIT."
exit 1
fi
-run_swtpm_ioctl "${SWTPM_INTERFACE}" -s
-if [ $? -ne 0 ]; then
+if ! run_swtpm_ioctl "${SWTPM_INTERFACE}" -s; then
echo "Error: Could not shut down the ${SWTPM_INTERFACE} TPM."
exit 1
fi
diff --git a/tests/_test_swtpm_bios b/tests/_test_swtpm_bios
index f566329..908db58 100755
--- a/tests/_test_swtpm_bios
+++ b/tests/_test_swtpm_bios
@@ -37,8 +37,7 @@
display_processes_by_name "$SWTPM"
-kill_quiet -0 "${SWTPM_PID}"
-if [ $? -ne 0 ]; then
+if ! kill_quiet -0 "${SWTPM_PID}"; then
echo "Error: ${SWTPM_INTERFACE} TPM did not start."
exit 1
fi
@@ -55,37 +54,32 @@
fi
# Init the TPM
-run_swtpm_ioctl "${SWTPM_INTERFACE}" -i
-if [ $? -ne 0 ]; then
+if ! run_swtpm_ioctl "${SWTPM_INTERFACE}" -i; then
echo "Error: Could not initialize the ${SWTPM_INTERFACE} TPM."
exit 1
fi
sleep 0.5
-kill_quiet -0 "${SWTPM_PID}" 2>/dev/null
-if [ $? -ne 0 ]; then
+if ! kill_quiet -0 "${SWTPM_PID}" 2>/dev/null; then
echo "Error: ${SWTPM_INTERFACE} TPM not running anymore after INIT."
exit 1
fi
# must work
-res=$(run_swtpm_bios "${SWTPM_INTERFACE}" -o 2>&1)
-if [ $? -ne 0 ] || [ -n "$res" ]; then
+if ! res=$(run_swtpm_bios "${SWTPM_INTERFACE}" -o 2>&1) || [ -n "$res" ]; then
echo "Error: Could not startup the ${SWTPM_INTERFACE} TPM."
exit 1
fi
# must work
-res=$(run_swtpm_bios "${SWTPM_INTERFACE}" -n --cs 2>&1)
-if [ $? -ne 0 ] || [ -n "$res" ]; then
+if ! res=$(run_swtpm_bios "${SWTPM_INTERFACE}" -n --cs 2>&1) || [ -n "$res" ]; then
echo "Error: Could not self-test the ${SWTPM_INTERFACE} TPM."
exit 1
fi
# must work
-res=$(run_swtpm_bios "${SWTPM_INTERFACE}" -n -u 2>&1)
-if [ $? -ne 0 ] || [ -n "$res" ]; then
+if ! res=$(run_swtpm_bios "${SWTPM_INTERFACE}" -n -u 2>&1) || [ -n "$res" ]; then
echo "Error: Could not give up physical presence on the ${SWTPM_INTERFACE} TPM."
exit 1
fi
@@ -119,15 +113,13 @@
# RESET TPM
-run_swtpm_ioctl "${SWTPM_INTERFACE}" -i
-if [ $? -ne 0 ]; then
+if ! run_swtpm_ioctl "${SWTPM_INTERFACE}" -i; then
echo "Error: Could not initialize the ${SWTPM_INTERFACE} TPM."
exit 1
fi
# must work
-res=$(run_swtpm_bios "${SWTPM_INTERFACE}" --cs -u 2>&1)
-if [ $? -ne 0 ] || [ -n "$res" ]; then
+if ! res=$(run_swtpm_bios "${SWTPM_INTERFACE}" --cs -u 2>&1) || [ -n "$res" ]; then
echo "Error: Could not startup the ${SWTPM_INTERFACE} TPM."
exit 1
fi
@@ -145,8 +137,7 @@
exit 1
fi
-run_swtpm_ioctl "${SWTPM_INTERFACE}" -s
-if [ $? -ne 0 ]; then
+if ! run_swtpm_ioctl "${SWTPM_INTERFACE}" -s; then
echo "Error: Could not shut down the ${SWTPM_INTERFACE} TPM."
exit 1
fi
diff --git a/tests/_test_tpm2_avoid_da_lockout b/tests/_test_tpm2_avoid_da_lockout
index 2607b5f..74ee551 100755
--- a/tests/_test_tpm2_avoid_da_lockout
+++ b/tests/_test_tpm2_avoid_da_lockout
@@ -33,8 +33,7 @@
--log "file=$LOG_FILE,level=20" \
--flags not-need-init,startup-clear
-kill_quiet -0 "${SWTPM_PID}"
-if [ $? -ne 0 ]; then
+if ! kill_quiet -0 "${SWTPM_PID}"; then
echo "Error: ${SWTPM_INTERFACE} TPM did not start."
exit 1
fi
@@ -73,8 +72,7 @@
fi
# Abruptly init the TPM: swtpm will internally send TPM2_Shutdown()
-run_swtpm_ioctl "${SWTPM_INTERFACE}" -i
-if [ $? -ne 0 ]; then
+if ! run_swtpm_ioctl "${SWTPM_INTERFACE}" -i; then
echo "Error: Could not initialize the ${SWTPM_INTERFACE} TPM."
exit 1
fi
@@ -114,8 +112,7 @@
fi
# CMD_STOP: swtpm will internally send TPM2_Shutdown()
-run_swtpm_ioctl "${SWTPM_INTERFACE}" -s
-if [ $? -ne 0 ]; then
+if ! run_swtpm_ioctl "${SWTPM_INTERFACE}" -s; then
echo "Error: Could not shut down the ${SWTPM_INTERFACE} TPM."
exit 1
fi
@@ -130,8 +127,7 @@
--log "file=$LOG_FILE,level=20" \
--flags not-need-init,startup-clear
-kill_quiet -0 "${SWTPM_PID}"
-if [ $? -ne 0 ]; then
+if ! kill_quiet -0 "${SWTPM_PID}"; then
echo "Error: ${SWTPM_INTERFACE} TPM did not start."
exit 1
fi
@@ -148,8 +144,7 @@
exit 1
fi
-run_swtpm_ioctl "${SWTPM_INTERFACE}" -s
-if [ $? -ne 0 ]; then
+if ! run_swtpm_ioctl "${SWTPM_INTERFACE}" -s; then
echo "Error: Could not shut down the ${SWTPM_INTERFACE} TPM."
exit 1
fi
diff --git a/tests/_test_tpm2_derived_keys b/tests/_test_tpm2_derived_keys
index 371e83b..bdb50b1 100755
--- a/tests/_test_tpm2_derived_keys
+++ b/tests/_test_tpm2_derived_keys
@@ -40,8 +40,7 @@
TPM_PATH=$TPM_PATH run_swtpm "${SWTPM_INTERFACE}" --tpm2
-kill_quiet -0 "${SWTPM_PID}"
-if [ $? -ne 0 ]; then
+if ! kill_quiet -0 "${SWTPM_PID}"; then
echo "Error: ${SWTPM_INTERFACE} TPM did not start."
exit 1
fi
@@ -63,8 +62,7 @@
local RES tmp
if [ "$reset" != "0" ]; then
- run_swtpm_ioctl "${SWTPM_INTERFACE}" -i
- if [ $? -ne 0 ]; then
+ if ! run_swtpm_ioctl "${SWTPM_INTERFACE}" -i; then
echo "Error: Could not send TPM_INIT"
return 1
fi
@@ -270,8 +268,7 @@
revision=$(run_swtpm_ioctl "${SWTPM_INTERFACE}" --info 1 |
sed 's/.*,"revision":\([^\}]*\).*/\1/')
-run_swtpm_ioctl "${SWTPM_INTERFACE}" -s
-if [ $? -ne 0 ]; then
+if ! run_swtpm_ioctl "${SWTPM_INTERFACE}" -s; then
echo "Error: Could not shut down the ${SWTPM_INTERFACE} TPM."
exit 1
fi
@@ -298,8 +295,7 @@
TPM_PATH=$TPM_PATH run_swtpm "${SWTPM_INTERFACE}" --tpm2
-kill_quiet -0 "${SWTPM_PID}"
-if [ $? -ne 0 ]; then
+if ! kill_quiet -0 "${SWTPM_PID}"; then
echo "Error: ${SWTPM_INTERFACE} TPM did not start."
exit 1
fi
@@ -318,8 +314,7 @@
tx_cmd 1 1 "$test5_cmd1" "$test5_exp1" "" || exit 1
tx_cmd 0 0 "$test5_cmd2" "$test5_exp2" "" || exit 1 && echo "Test 5: OK"
-run_swtpm_ioctl "${SWTPM_INTERFACE}" -s
-if [ $? -ne 0 ]; then
+if ! run_swtpm_ioctl "${SWTPM_INTERFACE}" -s; then
echo "Error: Could not shut down the ${SWTPM_INTERFACE} TPM."
exit 1
fi
diff --git a/tests/_test_tpm2_encrypted_state b/tests/_test_tpm2_encrypted_state
index 38939bd..cc3c772 100755
--- a/tests/_test_tpm2_encrypted_state
+++ b/tests/_test_tpm2_encrypted_state
@@ -46,8 +46,7 @@
display_processes_by_name "$SWTPM"
-kill_quiet -0 "${SWTPM_PID}"
-if [ $? -ne 0 ]; then
+if ! kill_quiet -0 "${SWTPM_PID}"; then
echo "Error: ${SWTPM_INTERFACE} TPM did not start."
echo "TPM Logfile:"
cat "$logfile"
@@ -62,16 +61,14 @@
fi
# Init the TPM
-run_swtpm_ioctl "${SWTPM_INTERFACE}" -i
-if [ $? -ne 0 ]; then
+if ! run_swtpm_ioctl "${SWTPM_INTERFACE}" -i; then
echo "Error: ${SWTPM_INTERFACE} TPM initialization failed."
echo "TPM Logfile:"
cat "$logfile"
exit 1
fi
-kill_quiet -0 "${SWTPM_PID}" 2>/dev/null
-if [ $? -ne 0 ]; then
+if ! kill_quiet -0 "${SWTPM_PID}" 2>/dev/null; then
echo "Error: ${SWTPM_INTERFACE} TPM not running anymore after INIT."
echo "TPM Logfile:"
cat "$logfile"
@@ -88,8 +85,7 @@
exit 1
fi
-run_swtpm_ioctl "${SWTPM_INTERFACE}" -h 1234
-if [ $? -ne 0 ]; then
+if ! run_swtpm_ioctl "${SWTPM_INTERFACE}" -h 1234; then
echo "Error: Hash command did not work."
echo "TPM Logfile:"
cat "$logfile"
@@ -107,8 +103,7 @@
fi
# Save the volatile state
-run_swtpm_ioctl "${SWTPM_INTERFACE}" -v
-if [ $? -ne 0 ]; then
+if ! run_swtpm_ioctl "${SWTPM_INTERFACE}" -v; then
echo "Error: Saving the volatile state failed."
echo "TPM Logfile:"
cat "$logfile"
@@ -122,8 +117,7 @@
exit 1
fi
-tmp=$(run_swtpm_ioctl "${SWTPM_INTERFACE}" -g | cut -d":" -f2)
-if [ $? -ne 0 ]; then
+if ! tmp=$(run_swtpm_ioctl "${SWTPM_INTERFACE}" -g | cut -d":" -f2); then
echo "Error: Could not get the configration flags of the ${SWTPM_INTERFACE} TPM."
echo "TPM Logfile:"
cat "$logfile"
@@ -138,8 +132,7 @@
fi
# Shut the TPM down
-run_swtpm_ioctl "${SWTPM_INTERFACE}" -s
-if [ $? -ne 0 ]; then
+if ! run_swtpm_ioctl "${SWTPM_INTERFACE}" -s; then
echo "Error: Could not shut down the ${SWTPM_INTERFACE} TPM."
echo "TPM Logfile:"
cat "$logfile"
@@ -154,8 +147,7 @@
display_processes_by_name "$SWTPM"
-kill_quiet -0 "${SWTPM_PID}"
-if [ $? -ne 0 ]; then
+if ! kill_quiet -0 "${SWTPM_PID}"; then
echo "Error (2): ${SWTPM_INTERFACE} TPM did not start."
echo "TPM Logfile:"
cat "$logfile"
@@ -170,8 +162,7 @@
fi
# Init the TPM
-run_swtpm_ioctl "${SWTPM_INTERFACE}" -i
-if [ $? -ne 0 ]; then
+if ! run_swtpm_ioctl "${SWTPM_INTERFACE}" -i; then
echo "Error: ${SWTPM_INTERFACE} TPM initialization failed."
echo "TPM Logfile:"
cat "$logfile"
@@ -197,8 +188,7 @@
fi
# Save the volatile state again
-run_swtpm_ioctl "${SWTPM_INTERFACE}" -v
-if [ $? -ne 0 ]; then
+if ! run_swtpm_ioctl "${SWTPM_INTERFACE}" -v; then
echo "Error: Saving the volatile state failed."
echo "TPM Logfile:"
cat "$logfile"
@@ -213,8 +203,7 @@
fi
# Send a new TPM_Init
-run_swtpm_ioctl "${SWTPM_INTERFACE}" -i
-if [ $? -ne 0 ]; then
+if ! run_swtpm_ioctl "${SWTPM_INTERFACE}" -i; then
echo "Error: ${SWTPM_INTERFACE} TPM initialization failed."
echo "TPM Logfile:"
cat "$logfile"
@@ -241,8 +230,7 @@
# Final shut down
-run_swtpm_ioctl "${SWTPM_INTERFACE}" -s
-if [ $? -ne 0 ]; then
+if ! run_swtpm_ioctl "${SWTPM_INTERFACE}" -s; then
echo "Error: Could not shut down the ${SWTPM_INTERFACE} TPM."
echo "TPM Logfile:"
cat "$logfile"
diff --git a/tests/_test_tpm2_file_permissions b/tests/_test_tpm2_file_permissions
index ddc9fd9..6c48dc9 100644
--- a/tests/_test_tpm2_file_permissions
+++ b/tests/_test_tpm2_file_permissions
@@ -67,8 +67,7 @@
chown "${TESTUSER}:${TESTGROUP}" "${TPM_PATH}"/*
# Test-execute the swtpm program as $TESTUSER
-tmp=$(su -m "${TESTUSER}" -c "LD_LIBRARY_PATH=\"${SWTPM_LD_LIBRARY_PATH}\" \"${MY_SWTPM_EXE}\" --help 2>&1")
-if [ $? -ne 0 ]; then
+if ! tmp=$(su -m "${TESTUSER}" -c "LD_LIBRARY_PATH=\"${SWTPM_LD_LIBRARY_PATH}\" \"${MY_SWTPM_EXE}\" --help 2>&1"); then
echo "Could not run '${MY_SWTPM_EXE}' as ${TESTUSER}. Skipping swtpm_setup tests."
echo "Error: ${tmp}"
exit 77
@@ -84,15 +83,13 @@
--tpm2 \
--key "pwdfile=${PWDFILE},kdf=sha512"
-kill -0 "${SWTPM_PID}"
-if [ $? -ne 0 ]; then
+if ! kill -0 "${SWTPM_PID}"; then
echo "Error: ${SWTPM_INTERFACE} TPM did not start."
exit 1
fi
# Init the TPM
-run_swtpm_ioctl "${SWTPM_INTERFACE}" -i
-if [ $? -ne 0 ]; then
+if ! run_swtpm_ioctl "${SWTPM_INTERFACE}" -i; then
echo "Error: Could not initialize the ${SWTPM_INTERFACE} TPM."
exit 1
fi
@@ -149,8 +146,7 @@
exit 1
fi
-run_swtpm_ioctl "${SWTPM_INTERFACE}" -s
-if [ $? -ne 0 ]; then
+if ! run_swtpm_ioctl "${SWTPM_INTERFACE}" -s; then
echo "Error: Could not shut down the ${SWTPM_INTERFACE} TPM."
exit 1
fi
@@ -171,29 +167,25 @@
logsize=$(get_filesize "${LOGFILE}")
statefilehash=$(get_sha1_file "${STATE_FILE}")
-LD_LIBRARY_PATH="${SWTPM_LD_LIBRARY_PATH}" ${SWTPM_SETUP} \
+if LD_LIBRARY_PATH="${SWTPM_LD_LIBRARY_PATH}" ${SWTPM_SETUP} \
--tpm2 \
--tpmstate "${TPM_PATH}" \
--logfile "${LOGFILE}" \
--runas "${TESTUSER}" \
--config "${SWTPM_SETUP_CONF}" \
- --tpm "${MY_SWTPM_EXE} socket ${SWTPM_TEST_SECCOMP_OPT}"
-
-if [ $? -eq 0 ]; then
+ --tpm "${MY_SWTPM_EXE} socket ${SWTPM_TEST_SECCOMP_OPT}"; then
echo "Error: ${SWTPM_SETUP} should have refused to overwrite existing state."
exit 1
fi
-LD_LIBRARY_PATH="${SWTPM_LD_LIBRARY_PATH}" ${SWTPM_SETUP} \
+if ! LD_LIBRARY_PATH="${SWTPM_LD_LIBRARY_PATH}" ${SWTPM_SETUP} \
--tpm2 \
--tpmstate "${TPM_PATH}" \
--overwrite \
--logfile "${LOGFILE}" \
--runas "${TESTUSER}" \
--config "${SWTPM_SETUP_CONF}" \
- --tpm "${MY_SWTPM_EXE} socket ${SWTPM_TEST_SECCOMP_OPT}"
-
-if [ $? -ne 0 ]; then
+ --tpm "${MY_SWTPM_EXE} socket ${SWTPM_TEST_SECCOMP_OPT}"; then
echo "Error: ${SWTPM_SETUP} could not overwrite existing state. (1)"
cat "${LOGFILE}"
exit 1
@@ -221,7 +213,7 @@
statefilehash=$(get_sha1_file "${STATE_FILE}")
logsize=$(get_filesize "${LOGFILE}")
-LD_LIBRARY_PATH="${SWTPM_LD_LIBRARY_PATH}" ${SWTPM_SETUP} \
+if ! LD_LIBRARY_PATH="${SWTPM_LD_LIBRARY_PATH}" ${SWTPM_SETUP} \
--tpmstate "${TPM_PATH}" \
--overwrite \
--tpm2 \
@@ -229,9 +221,7 @@
--runas "${TESTUSER}" \
--config "${SWTPM_SETUP_CONF}" \
--tpm "${MY_SWTPM_EXE} socket ${SWTPM_TEST_SECCOMP_OPT}" \
- --pwdfile "${PWDFILE}"
-
-if [ $? -ne 0 ]; then
+ --pwdfile "${PWDFILE}"; then
echo "Error: ${SWTPM_SETUP} could not overwrite existing state."
exit 1
fi
diff --git a/tests/_test_tpm2_getcap b/tests/_test_tpm2_getcap
index c4cc7ac..67f4d65 100755
--- a/tests/_test_tpm2_getcap
+++ b/tests/_test_tpm2_getcap
@@ -35,33 +35,28 @@
display_processes_by_name "$SWTPM"
-kill_quiet -0 "${SWTPM_PID}"
-if [ $? -ne 0 ]; then
+if ! kill_quiet -0 "${SWTPM_PID}"; then
echo "Error: ${SWTPM_INTERFACE} TPM did not start."
exit 1
fi
# Init the TPM
-run_swtpm_ioctl "${SWTPM_INTERFACE}" -i
-if [ $? -ne 0 ]; then
+if ! run_swtpm_ioctl "${SWTPM_INTERFACE}" -i; then
echo "Error: Could not initialize the ${SWTPM_INTERFACE} TPM."
exit 1
fi
-kill_quiet -0 "${SWTPM_PID}" 2>/dev/null
-if [ $? -ne 0 ]; then
+if ! kill_quiet -0 "${SWTPM_PID}" 2>/dev/null; then
echo "Error: ${SWTPM_INTERFACE} TPM not running anymore after INIT."
exit 1
fi
# Get the capabilities flags from the TPM
-act=$(run_swtpm_ioctl "${SWTPM_INTERFACE}" -c)
-if [ $? -ne 0 ]; then
+if ! act=$(run_swtpm_ioctl "${SWTPM_INTERFACE}" -c); then
echo "Error: Could not get the capability flags of the ${SWTPM_INTERFACE} TPM."
exit 1
fi
-kill_quiet -0 "${SWTPM_PID}" 2>/dev/null
-if [ $? -ne 0 ]; then
+if ! kill_quiet -0 "${SWTPM_PID}" 2>/dev/null; then
echo "Error: ${SWTPM_INTERFACE} TPM not running anymore after getting capabilities."
exit 1
fi
@@ -72,8 +67,7 @@
exit 1
fi
-run_swtpm_ioctl "${SWTPM_INTERFACE}" -s
-if [ $? -ne 0 ]; then
+if ! run_swtpm_ioctl "${SWTPM_INTERFACE}" -s; then
echo "Error: Could not shut down the ${SWTPM_INTERFACE} TPM."
exit 1
fi
diff --git a/tests/_test_tpm2_hashing b/tests/_test_tpm2_hashing
index 2984db7..e0e67a2 100755
--- a/tests/_test_tpm2_hashing
+++ b/tests/_test_tpm2_hashing
@@ -36,21 +36,18 @@
display_processes_by_name "$SWTPM"
-kill_quiet -0 "${SWTPM_PID}"
-if [ $? -ne 0 ]; then
+if ! kill_quiet -0 "${SWTPM_PID}"; then
echo "Error: ${SWTPM_INTERFACE} TPM did not start."
exit 1
fi
# Init the TPM
-run_swtpm_ioctl "${SWTPM_INTERFACE}" -i
-if [ $? -ne 0 ]; then
+if ! run_swtpm_ioctl "${SWTPM_INTERFACE}" -i; then
echo "Error: Could not initialize the ${SWTPM_INTERFACE} TPM."
exit 1
fi
-kill_quiet -0 "${SWTPM_PID}" 2>/dev/null
-if [ $? -ne 0 ]; then
+if ! kill_quiet -0 "${SWTPM_PID}" 2>/dev/null; then
echo "Error: ${SWTPM_INTERFACE} TPM not running anymore after INIT."
exit 1
fi
@@ -66,8 +63,7 @@
fi
# Check the TPM Established bit before the hashing
-RES=$(run_swtpm_ioctl "${SWTPM_INTERFACE}" -e )
-if [ $? -ne 0 ]; then
+if ! RES=$(run_swtpm_ioctl "${SWTPM_INTERFACE}" -e ); then
echo "Error: Could not get the TPM Established bit from the ${SWTPM_INTERFACE} TPM."
exit 1
fi
@@ -80,8 +76,7 @@
exit 1
fi
-run_swtpm_ioctl "${SWTPM_INTERFACE}" -h 1234
-if [ $? -ne 0 ]; then
+if ! run_swtpm_ioctl "${SWTPM_INTERFACE}" -h 1234; then
echo "Error: The hash command failed."
exit 1
fi
@@ -99,8 +94,7 @@
fi
# Check the TPM Established bit after the hashing
-RES=$(run_swtpm_ioctl "${SWTPM_INTERFACE}" -e)
-if [ $? -ne 0 ]; then
+if ! RES=$(run_swtpm_ioctl "${SWTPM_INTERFACE}" -e); then
echo "Error: Could not get the TPM Established bit from the ${SWTPM_INTERFACE} TPM."
exit 1
fi
@@ -115,15 +109,13 @@
# Reset the establishment bit is not possible via a command
# So we do it directly here in locality 3
-run_swtpm_ioctl "${SWTPM_INTERFACE}" -r 3
-if [ $? -ne -0 ]; then
+if ! run_swtpm_ioctl "${SWTPM_INTERFACE}" -r 3; then
echo "Error: Could not reset establishment bit in locality 3"
exit 1
fi
# Check the TPM Established bit after the reset
-RES=$(run_swtpm_ioctl "${SWTPM_INTERFACE}" -e)
-if [ $? -ne 0 ]; then
+if ! RES=$(run_swtpm_ioctl "${SWTPM_INTERFACE}" -e); then
echo "Error: Could not get the TPM Established bit from the ${SWTPM_INTERFACE} TPM."
exit 1
fi
@@ -137,8 +129,7 @@
fi
# back to locality 0
-run_swtpm_ioctl "${SWTPM_INTERFACE}" -l 0
-if [ $? -ne 0 ]; then
+if ! run_swtpm_ioctl "${SWTPM_INTERFACE}" -l 0; then
echo "Error: Could not set the locality to 0."
exit 1
fi
@@ -158,8 +149,7 @@
exit 1
fi
-run_swtpm_ioctl "${SWTPM_INTERFACE}" -s
-if [ $? -ne 0 ]; then
+if ! run_swtpm_ioctl "${SWTPM_INTERFACE}" -s; then
echo "Error: Could not shut down the ${SWTPM_INTERFACE} TPM."
exit 1
fi
diff --git a/tests/_test_tpm2_hashing2 b/tests/_test_tpm2_hashing2
index a6d3acd..a36121e 100755
--- a/tests/_test_tpm2_hashing2
+++ b/tests/_test_tpm2_hashing2
@@ -35,21 +35,18 @@
display_processes_by_name "$SWTPM"
-kill_quiet -0 "${SWTPM_PID}"
-if [ $? -ne 0 ]; then
+if ! kill_quiet -0 "${SWTPM_PID}"; then
echo "Error: ${SWTPM_INTERFACE} TPM did not start."
exit 1
fi
# Init the TPM
-run_swtpm_ioctl "${SWTPM_INTERFACE}" -i
-if [ $? -ne 0 ]; then
+if ! run_swtpm_ioctl "${SWTPM_INTERFACE}" -i; then
echo "Error: Could not initialize the ${SWTPM_INTERFACE} TPM."
exit 1
fi
-kill_quiet -0 "${SWTPM_PID}" 2>/dev/null
-if [ $? -ne 0 ]; then
+if ! kill_quiet -0 "${SWTPM_PID}" 2>/dev/null; then
echo "Error: ${SWTPM_INTERFACE} TPM not running anymore after INIT."
exit 1
fi
@@ -65,8 +62,7 @@
fi
# Check the TPM Established bit before the hashing
-RES=$(run_swtpm_ioctl "${SWTPM_INTERFACE}" -e)
-if [ $? -ne 0 ]; then
+if ! RES=$(run_swtpm_ioctl "${SWTPM_INTERFACE}" -e); then
echo "Error: Could not get the TPM Established bit from the ${SWTPM_INTERFACE} TPM."
exit 1
fi
@@ -79,8 +75,7 @@
exit 1
fi
-run_swtpm_ioctl "${SWTPM_INTERFACE}" -h 1234
-if [ $? -ne 0 ]; then
+if ! run_swtpm_ioctl "${SWTPM_INTERFACE}" -h 1234; then
echo "Error: The hash command failed."
exit 1
fi
@@ -98,8 +93,7 @@
fi
# Check the TPM Established bit after the hashing
-RES=$(run_swtpm_ioctl "${SWTPM_INTERFACE}" -e)
-if [ $? -ne 0 ]; then
+if ! RES=$(run_swtpm_ioctl "${SWTPM_INTERFACE}" -e); then
echo "Error: Could not get the TPM Established bit from the ${SWTPM_INTERFACE} TPM."
exit 1
fi
@@ -113,16 +107,14 @@
fi
# Reset the establishment bit; we switch to locality 0 and reset via locality 3
-run_swtpm_ioctl "${SWTPM_INTERFACE}" -l 0
-if [ $? -ne 0 ]; then
+if ! run_swtpm_ioctl "${SWTPM_INTERFACE}" -l 0; then
echo "Error: Could not set locality 0"
exit 1
fi
for ((l = 0; l <= 2; l++)); do
# Resetting via locality 2 must fail
- ERR="$(run_swtpm_ioctl "${SWTPM_INTERFACE}" -r "$l" 2>&1)"
- if [ $? -eq 0 ]; then
+ if ERR="$(run_swtpm_ioctl "${SWTPM_INTERFACE}" -r "$l" 2>&1)"; then
echo "Error: Could reset the establishment bit via locality $l"
exit 1
fi
@@ -136,15 +128,13 @@
done
# Resetting via locality 3 must work
-run_swtpm_ioctl "${SWTPM_INTERFACE}" -r 3
-if [ $? -ne 0 ]; then
+if ! run_swtpm_ioctl "${SWTPM_INTERFACE}" -r 3; then
echo "Error: Could not reset the establishment bit via locality 3"
exit 1
fi
# Check the TPM Established bit after the reset
-RES=$(run_swtpm_ioctl "${SWTPM_INTERFACE}" -e)
-if [ $? -ne 0 ]; then
+if ! RES=$(run_swtpm_ioctl "${SWTPM_INTERFACE}" -e); then
echo "Error: Could not get the TPM Established bit from the ${SWTPM_INTERFACE} TPM."
exit 1
fi
@@ -173,16 +163,14 @@
exit 1
fi
-run_swtpm_ioctl "${SWTPM_INTERFACE}" -s
-if [ $? -ne 0 ]; then
+if ! run_swtpm_ioctl "${SWTPM_INTERFACE}" -s; then
echo "Error: Could not shut down the ${SWTPM_INTERFACE} TPM."
exit 1
fi
sleep 0.5
-kill_quiet -0 "${SWTPM_PID}" 2>/dev/null
-if [ $? -eq 0 ]; then
+if kill_quiet -0 "${SWTPM_PID}" 2>/dev/null; then
echo "Error: ${SWTPM_INTERFACE} TPM should not be running anymore."
exit 1
fi
diff --git a/tests/_test_tpm2_hashing3 b/tests/_test_tpm2_hashing3
index bbfb55e..6ff4c43 100755
--- a/tests/_test_tpm2_hashing3
+++ b/tests/_test_tpm2_hashing3
@@ -35,21 +35,18 @@
display_processes_by_name "$SWTPM"
-kill_quiet -0 "${SWTPM_PID}"
-if [ $? -ne 0 ]; then
+if ! kill_quiet -0 "${SWTPM_PID}"; then
echo "Error: ${SWTPM_INTERFACE} TPM did not start."
exit 1
fi
# Init the TPM
-run_swtpm_ioctl "${SWTPM_INTERFACE}" -i
-if [ $? -ne 0 ]; then
+if ! run_swtpm_ioctl "${SWTPM_INTERFACE}" -i; then
echo "Error: Could not initialize the ${SWTPM_INTERFACE} TPM."
exit 1
fi
-kill_quiet -0 "${SWTPM_PID}" 2>/dev/null
-if [ $? -ne 0 ]; then
+if ! kill_quiet -0 "${SWTPM_PID}" 2>/dev/null; then
echo "Error: ${SWTPM_INTERFACE} TPM not running anymore after INIT."
exit 1
fi
@@ -57,8 +54,7 @@
# We do NOT need to startup the TPM; Hashing will affect PCR 0
# Check the TPM Established bit before the hashing
-RES=$(run_swtpm_ioctl "${SWTPM_INTERFACE}" -e)
-if [ $? -ne 0 ]; then
+if ! RES=$(run_swtpm_ioctl "${SWTPM_INTERFACE}" -e); then
echo "Error: Could not get the TPM Established bit from the ${SWTPM_INTERFACE} TPM."
exit 1
fi
@@ -72,8 +68,7 @@
fi
# Hash
-run_swtpm_ioctl "${SWTPM_INTERFACE}" -h 1234
-if [ $? -ne 0 ]; then
+if ! run_swtpm_ioctl "${SWTPM_INTERFACE}" -h 1234; then
echo "Error: The hash command failed."
exit 1
fi
@@ -100,8 +95,7 @@
fi
# Check the TPM Established bit after the hashing
-RES=$(run_swtpm_ioctl "${SWTPM_INTERFACE}" -e)
-if [ $? -ne 0 ]; then
+if ! RES=$(run_swtpm_ioctl "${SWTPM_INTERFACE}" -e); then
echo "Error: Could not get the TPM Established bit from the ${SWTPM_INTERFACE} TPM."
exit 1
fi
@@ -114,8 +108,7 @@
exit 1
fi
-run_swtpm_ioctl "${SWTPM_INTERFACE}" -s
-if [ $? -ne 0 ]; then
+if ! run_swtpm_ioctl "${SWTPM_INTERFACE}" -s; then
echo "Error: Could not shut down the ${SWTPM_INTERFACE} TPM."
exit 1
fi
diff --git a/tests/_test_tpm2_init b/tests/_test_tpm2_init
index e296aa5..8948382 100755
--- a/tests/_test_tpm2_init
+++ b/tests/_test_tpm2_init
@@ -39,21 +39,18 @@
display_processes_by_name "$SWTPM"
-kill_quiet -0 "${SWTPM_PID}"
-if [ $? -ne 0 ]; then
+if ! kill_quiet -0 "${SWTPM_PID}"; then
echo "Error: ${SWTPM_INTERFACE} TPM did not start."
exit 1
fi
# Init the TPM
-run_swtpm_ioctl "${SWTPM_INTERFACE}" -i
-if [ $? -ne 0 ]; then
+if ! run_swtpm_ioctl "${SWTPM_INTERFACE}" -i; then
echo "Error: Could not initialize the ${SWTPM_INTERFACE} TPM."
exit 1
fi
-kill_quiet -0 "${SWTPM_PID}" 2>/dev/null
-if [ $? -ne 0 ]; then
+if ! kill_quiet -0 "${SWTPM_PID}" 2>/dev/null; then
echo "Error: ${SWTPM_INTERFACE} TPM not running anymore after INIT."
exit 1
fi
@@ -62,45 +59,39 @@
# works if the TPM runs as non-rootchmod 000 "${STATE_FILE}"
if [ "$(id -u)" != "0" ]; then
chmod 000 "${STATE_FILE}"
- run_swtpm_ioctl "${SWTPM_INTERFACE}" -i
- if [ $? -eq 0 ]; then
+ if run_swtpm_ioctl "${SWTPM_INTERFACE}" -i; then
echo "Error: Unexpected initialization success of the ${SWTPM_INTERFACE} TPM."
exit 1
fi
sleep 0.5
- kill_quiet -0 "${SWTPM_PID}" 2>/dev/null
- if [ $? -ne 0 ]; then
+ if ! kill_quiet -0 "${SWTPM_PID}" 2>/dev/null; then
echo "Error: ${SWTPM_INTERFACE} TPM not running anymore after failed INIT."
exit 1
fi
chmod 664 "${STATE_FILE}"
# Init the TPM again; now with state file accessible again
- run_swtpm_ioctl "${SWTPM_INTERFACE}" -i
- if [ $? -ne 0 ]; then
+ if ! run_swtpm_ioctl "${SWTPM_INTERFACE}" -i; then
echo "Error: Could not initialize the ${SWTPM_INTERFACE} TPM."
exit 1
fi
sleep 0.5
- kill_quiet -0 "${SWTPM_PID}" 2>/dev/null
- if [ $? -ne 0 ]; then
+ if ! kill_quiet -0 "${SWTPM_PID}" 2>/dev/null; then
echo "Error: ${SWTPM_INTERFACE} TPM not running anymore after INIT."
exit 1
fi
fi
-check_seccomp_profile "${SWTPM_EXE}" ${SWTPM_PID} 0
-if [ $? -ne 0 ]; then
+if ! check_seccomp_profile "${SWTPM_EXE}" ${SWTPM_PID} 0; then
exit 1
fi
# Shut down
-run_swtpm_ioctl "${SWTPM_INTERFACE}" -s
-if [ $? -ne 0 ]; then
+if ! run_swtpm_ioctl "${SWTPM_INTERFACE}" -s; then
echo "Error: Could not shut down the ${SWTPM_INTERFACE} TPM."
exit 1
fi
diff --git a/tests/_test_tpm2_locality b/tests/_test_tpm2_locality
index 55cc0d9..48e6b97 100755
--- a/tests/_test_tpm2_locality
+++ b/tests/_test_tpm2_locality
@@ -35,57 +35,49 @@
display_processes_by_name "$SWTPM"
-kill_quiet -0 "${SWTPM_PID}"
-if [ $? -ne 0 ]; then
+if ! kill_quiet -0 "${SWTPM_PID}"; then
echo "Error: ${SWTPM_INTERFACE} TPM did not start."
exit 1
fi
# Init the TPM
-run_swtpm_ioctl "${SWTPM_INTERFACE}" -i
-if [ $? -ne 0 ]; then
+if ! run_swtpm_ioctl "${SWTPM_INTERFACE}" -i; then
echo "Error: Could not initialize the ${SWTPM_INTERFACE} TPM."
exit 1
fi
-kill_quiet -0 "${SWTPM_PID}" 2>/dev/null
-if [ $? -ne 0 ]; then
+if ! kill_quiet -0 "${SWTPM_PID}" 2>/dev/null; then
echo "Error: ${SWTPM_INTERFACE} TPM not running anymore after INIT."
exit 1
fi
# Set locality 4 on the TPM
-run_swtpm_ioctl "${SWTPM_INTERFACE}" -l 4
-if [ $? -ne 0 ]; then
+if ! run_swtpm_ioctl "${SWTPM_INTERFACE}" -l 4; then
echo "Error: ${SWTPM_INTERFACE} TPM did not accept locality 4."
exit 1
fi
# Set illegal locality 5 on the TPM
-run_swtpm_ioctl "${SWTPM_INTERFACE}" -l 5
-if [ $? -eq 0 ]; then
+if run_swtpm_ioctl "${SWTPM_INTERFACE}" -l 5; then
echo "Error: ${SWTPM_INTERFACE} TPM accepted locality 5."
exit 1
fi
# Set locality 0 on the TPM
-run_swtpm_ioctl "${SWTPM_INTERFACE}" -l 0
-if [ $? -ne 0 ]; then
+if ! run_swtpm_ioctl "${SWTPM_INTERFACE}" -l 0; then
echo "Error: ${SWTPM_INTERFACE} TPM did not accept locality 0."
exit 1
fi
# In locality 2 we can reset PCR 20
-run_swtpm_ioctl "${SWTPM_INTERFACE}" -l 2
-if [ $? -ne 0 ]; then
+if ! run_swtpm_ioctl "${SWTPM_INTERFACE}" -l 2; then
echo "Error: ${SWTPM_INTERFACE} TPM did not accept locality 2."
exit 1
fi
# Need to set locality 0 or 3 for TPM2_Startup to work...
# TPM_Startup for TPM 1.2 worked in all localities
-run_swtpm_ioctl "${SWTPM_INTERFACE}" -l 3
-if [ $? -ne 0 ]; then
+if ! run_swtpm_ioctl "${SWTPM_INTERFACE}" -l 3; then
echo "Error: ${SWTPM_INTERFACE} TPM did not accept locality 3."
exit 1
fi
@@ -101,8 +93,7 @@
fi
# In locality 2 we can reset PCR 20
-run_swtpm_ioctl "${SWTPM_INTERFACE}" -l 2
-if [ $? -ne 0 ]; then
+if ! run_swtpm_ioctl "${SWTPM_INTERFACE}" -l 2; then
echo "Error: ${SWTPM_INTERFACE} TPM did not accept locality 2."
exit 1
fi
@@ -118,8 +109,7 @@
fi
# In locality 1 we can NOT reset PCR 20
-run_swtpm_ioctl "${SWTPM_INTERFACE}" -l 1
-if [ $? -ne 0 ]; then
+if ! run_swtpm_ioctl "${SWTPM_INTERFACE}" -l 1; then
echo "Error: ${SWTPM_INTERFACE} TPM did not accept locality 1."
exit 1
fi
@@ -135,8 +125,7 @@
fi
# Shut down TPM
-run_swtpm_ioctl "${SWTPM_INTERFACE}" -s
-if [ $? -ne 0 ]; then
+if ! run_swtpm_ioctl "${SWTPM_INTERFACE}" -s; then
echo "Error: Could not shut down the ${SWTPM_INTERFACE} TPM."
exit 1
fi
diff --git a/tests/_test_tpm2_migration_key b/tests/_test_tpm2_migration_key
index 428b5ad..7491880 100755
--- a/tests/_test_tpm2_migration_key
+++ b/tests/_test_tpm2_migration_key
@@ -59,21 +59,18 @@
--tpm2 \
--migration-key "pwdfile=$migpwdfile,remove=false,kdf=sha512"
-kill_quiet -0 $SWTPM_PID
-if [ $? -ne 0 ]; then
+if ! kill_quiet -0 $SWTPM_PID; then
echo "Error: ${SWTPM_INTERFACE} TPM did not start."
exit 1
fi
# Init the TPM
-run_swtpm_ioctl "${SWTPM_INTERFACE}" -i
-if [ $? -ne 0 ]; then
+if ! run_swtpm_ioctl "${SWTPM_INTERFACE}" -i; then
echo "Error: Initializing the ${SWTPM_INTERFACE} TPM failed."
exit 1
fi
-kill_quiet -0 $SWTPM_PID 2>/dev/null
-if [ $? -ne 0 ]; then
+if ! kill_quiet -0 $SWTPM_PID 2>/dev/null; then
echo "Error: ${SWTPM_INTERFACE} TPM not running anymore after INIT."
exit 1
fi
@@ -89,8 +86,7 @@
fi
# Save the volatile state into a file
-run_swtpm_ioctl "${SWTPM_INTERFACE}" --save volatile "$volatilestatefile"
-if [ $? -ne 0 ]; then
+if ! run_swtpm_ioctl "${SWTPM_INTERFACE}" --save volatile "$volatilestatefile"; then
echo "Error: Could not save the volatile state to ${volatilestatefile}."
exit 1
fi
@@ -107,8 +103,7 @@
exit 1
fi
-tmp=$(run_swtpm_ioctl "${SWTPM_INTERFACE}" -g | cut -d":" -f2)
-if [ $? -ne 0 ]; then
+if ! tmp=$(run_swtpm_ioctl "${SWTPM_INTERFACE}" -g | cut -d":" -f2); then
echo "Error: Could not get the configration flags of the ${SWTPM_INTERFACE} TPM."
exit 1
fi
@@ -133,8 +128,7 @@
display_processes_by_name "$SWTPM"
-kill_quiet -0 $SWTPM_PID
-if [ $? -ne 0 ]; then
+if ! kill_quiet -0 $SWTPM_PID; then
echo "Error: ${SWTPM_INTERFACE} TPM did not start."
exit 1
fi
@@ -144,8 +138,7 @@
# Do NOT init the TPM now; first load volatile state
# load the encrypted volatile state into it
-run_swtpm_ioctl "${SWTPM_INTERFACE}" --load volatile "$volatilestatefile"
-if [ $? -ne 0 ]; then
+if ! run_swtpm_ioctl "${SWTPM_INTERFACE}" --load volatile "$volatilestatefile"; then
echo "Error: Could not load encrypted volatile state into TPM."
echo "swtpm logfile: "
cat "$logfile"
@@ -153,8 +146,7 @@
fi
# Now init the TPM
-run_swtpm_ioctl "${SWTPM_INTERFACE}" -i
-if [ $? -ne 0 ]; then
+if ! run_swtpm_ioctl "${SWTPM_INTERFACE}" -i; then
echo "Error: Initializing the ${SWTPM_INTERFACE} TPM failed."
exit 1
fi
@@ -171,8 +163,7 @@
# Shut the TPM down
exec 100>&-
-run_swtpm_ioctl "${SWTPM_INTERFACE}" -s
-if [ $? -ne 0 ]; then
+if ! run_swtpm_ioctl "${SWTPM_INTERFACE}" -s; then
echo "Error: Could not shut down the ${SWTPM_INTERFACE} TPM."
exit 1
fi
@@ -188,8 +179,7 @@
display_processes_by_name "$SWTPM"
-kill_quiet -0 $SWTPM_PID
-if [ $? -ne 0 ]; then
+if ! kill_quiet -0 $SWTPM_PID; then
echo "Error: ${SWTPM_INTERFACE} TPM did not start."
exit 1
fi
@@ -201,8 +191,7 @@
# load the encrypted volatile state into it
# This will not work; the TPM writes the data into the volatile state file
# and validates it
-ERR="$(run_swtpm_ioctl "${SWTPM_INTERFACE}" --load volatile "$volatilestatefile" 2>&1)"
-if [ $? -eq 0 ]; then
+if ERR="$(run_swtpm_ioctl "${SWTPM_INTERFACE}" --load volatile "$volatilestatefile" 2>&1)"; then
echo "Error: Could load encrypted volatile state into TPM."
cat "$logfile"
exit 1
@@ -215,8 +204,7 @@
exit 1
fi
-run_swtpm_ioctl "${SWTPM_INTERFACE}" -s
-if [ $? -ne 0 ]; then
+if ! run_swtpm_ioctl "${SWTPM_INTERFACE}" -s; then
echo "Error: Could not shut down the ${SWTPM_INTERFACE} TPM."
exit 1
fi
@@ -236,8 +224,7 @@
display_processes_by_name "$SWTPM"
-kill_quiet -0 $SWTPM_PID
-if [ $? -ne 0 ]; then
+if ! kill_quiet -0 $SWTPM_PID; then
echo "Error: TPM did not start."
cat "$logfile"
exit 1
@@ -246,15 +233,13 @@
run_swtpm_ioctl "${SWTPM_INTERFACE}" --stop
# load the encrypted volatile state into it
-run_swtpm_ioctl "${SWTPM_INTERFACE}" --load volatile "$VOLATILESTATE"
-if [ $? -ne 0 ]; then
+if ! run_swtpm_ioctl "${SWTPM_INTERFACE}" --load volatile "$VOLATILESTATE"; then
echo "Error: Could not load encrypted volatile state into TPM."
exit 1
fi
# Now init the TPM; this must work
-run_swtpm_ioctl "${SWTPM_INTERFACE}" -i
-if [ $? -ne 0 ]; then
+if ! run_swtpm_ioctl "${SWTPM_INTERFACE}" -i; then
echo "Error: Could not initialize the ${SWTPM_INTERFACE} TPM."
exit 1
fi
@@ -271,8 +256,7 @@
# Shut the TPM down
exec 100>&-
-run_swtpm_ioctl "${SWTPM_INTERFACE}" -s
-if [ $? -ne 0 ]; then
+if ! run_swtpm_ioctl "${SWTPM_INTERFACE}" -s; then
echo "Error: Could not shut down the ${SWTPM_INTERFACE} TPM."
exit 1
fi
diff --git a/tests/_test_tpm2_print_capabilities b/tests/_test_tpm2_print_capabilities
index a7ead67..1de955c 100755
--- a/tests/_test_tpm2_print_capabilities
+++ b/tests/_test_tpm2_print_capabilities
@@ -11,8 +11,7 @@
[ "${SWTPM_IFACE}" == "cuse" ] && source "${TESTDIR}/test_cuse"
source "${TESTDIR}/common"
-msg="$(${SWTPM_EXE} "${SWTPM_IFACE}" --tpm2 --print-capabilities 2>&1)"
-if [ $? -ne 0 ]; then
+if ! msg="$(${SWTPM_EXE} "${SWTPM_IFACE}" --tpm2 --print-capabilities 2>&1)"; then
echo "Error: Could not pass --print-capabilities"
echo "${msg}"
exit 1
@@ -36,8 +35,7 @@
echo "Test 1: OK"
-msg="$(${SWTPM_SETUP} --tpm2 --print-capabilities 2>&1)"
-if [ $? -ne 0 ]; then
+if ! msg="$(${SWTPM_SETUP} --tpm2 --print-capabilities 2>&1)"; then
echo "Error: Could not pass --print-capabilities"
echo "${msg}"
exit 1
@@ -56,8 +54,7 @@
# SWTPM_CERT may be run by valgrind
if [ -x "$(type -P "$(echo "${SWTPM_CERT}" | cut -d" " -f1)" )" ]; then
- msg="$(${SWTPM_CERT} --tpm2 --print-capabilities 2>&1)"
- if [ $? -ne 0 ]; then
+ if ! msg="$(${SWTPM_CERT} --tpm2 --print-capabilities 2>&1)"; then
echo "Error: Could not pass --print-capabilities to ${SWTPM_CERT}"
echo "${msg}"
exit 1
diff --git a/tests/_test_tpm2_print_states b/tests/_test_tpm2_print_states
index 2e64f7e..f8f5e6c 100755
--- a/tests/_test_tpm2_print_states
+++ b/tests/_test_tpm2_print_states
@@ -21,9 +21,7 @@
# Test 1: No states
workdir="$(mktemp -d)" || exit 1
-msg="$(${SWTPM_EXE} "${SWTPM_IFACE}" --print-states --tpm2 --tpmstate "dir=${workdir}" 2>&1)"
-
-if [ $? -ne 0 ]; then
+if ! msg="$(${SWTPM_EXE} "${SWTPM_IFACE}" --print-states --tpm2 --tpmstate "dir=${workdir}" 2>&1)"; then
echo "Error: Could not pass --print-states"
echo "${msg}"
exit 1
@@ -48,9 +46,7 @@
dummydata="DUMMY"
echo "$dummydata" > "${statefile}"
-msg="$(${SWTPM_EXE} "${SWTPM_IFACE}" --print-states --tpm2 --tpmstate "dir=${workdir}" 2>&1)"
-
-if [ $? -ne 0 ]; then
+if ! msg="$(${SWTPM_EXE} "${SWTPM_IFACE}" --print-states --tpm2 --tpmstate "dir=${workdir}" 2>&1)"; then
echo "Error: Could not pass --print-states"
echo "${msg}"
exit 1
diff --git a/tests/_test_tpm2_probe b/tests/_test_tpm2_probe
index c7c0306..3947def 100755
--- a/tests/_test_tpm2_probe
+++ b/tests/_test_tpm2_probe
@@ -35,15 +35,13 @@
display_processes_by_name "$SWTPM"
-kill_quiet -0 "${SWTPM_PID}"
-if [ $? -ne 0 ]; then
+if ! kill_quiet -0 "${SWTPM_PID}"; then
echo "Error: ${SWTPM_INTERFACE} TPM did not start."
exit 1
fi
if [ "${SWTPM_INTERFACE}" != "cuse" ]; then
- run_swtpm_ioctl "${SWTPM_INTERFACE}" --stop
- if [ $? -ne 0 ]; then
+ if ! run_swtpm_ioctl "${SWTPM_INTERFACE}" --stop; then
echo "Error: Could not stop the ${SWTPM_INTERFACE} TPM"
exit 1
fi
@@ -61,8 +59,7 @@
fi
# Init the TPM
-run_swtpm_ioctl "${SWTPM_INTERFACE}" -i
-if [ $? -ne 0 ]; then
+if ! run_swtpm_ioctl "${SWTPM_INTERFACE}" -i; then
echo "Error: Could not initialize the ${SWTPM_INTERFACE} TPM."
exit 1
fi
@@ -77,13 +74,11 @@
exit 1
fi
-check_seccomp_profile "${SWTPM_EXE}" "${SWTPM_PID}" 2
-if [ $? -ne 0 ]; then
+if ! check_seccomp_profile "${SWTPM_EXE}" "${SWTPM_PID}" 2; then
exit 1
fi
-run_swtpm_ioctl "${SWTPM_INTERFACE}" -s
-if [ $? -ne 0 ]; then
+if ! run_swtpm_ioctl "${SWTPM_INTERFACE}" -s; then
echo "Error: Could not shut down the ${SWTPM_INTERFACE} TPM."
exit 1
fi
diff --git a/tests/_test_tpm2_resume_volatile b/tests/_test_tpm2_resume_volatile
index b47f16d..05d7abd 100755
--- a/tests/_test_tpm2_resume_volatile
+++ b/tests/_test_tpm2_resume_volatile
@@ -43,21 +43,18 @@
display_processes_by_name "$SWTPM"
-kill_quiet -0 "${SWTPM_PID}"
-if [ $? -ne 0 ]; then
+if ! kill_quiet -0 "${SWTPM_PID}"; then
echo "Error: CUSE TPM did not start."
exit 1
fi
# Init the TPM
-run_swtpm_ioctl "${SWTPM_INTERFACE}" -i
-if [ $? -ne 0 ]; then
+if ! run_swtpm_ioctl "${SWTPM_INTERFACE}" -i; then
echo "Error: Could not initialize the CUSE TPM."
exit 1
fi
-kill_quiet -0 "${SWTPM_PID}" 2>/dev/null
-if [ $? -ne 0 ]; then
+if ! kill_quiet -0 "${SWTPM_PID}" 2>/dev/null; then
echo "Error: CUSE TPM not running anymore after INIT."
exit 1
fi
@@ -73,8 +70,7 @@
fi
# Save the volatile state again
-run_swtpm_ioctl "${SWTPM_INTERFACE}" -v
-if [ $? -ne 0 ]; then
+if ! run_swtpm_ioctl "${SWTPM_INTERFACE}" -v; then
echo "Error: Could not have the CUSE TPM write the volatile state to a file."
exit 1
fi
@@ -98,21 +94,18 @@
display_processes_by_name "$SWTPM"
-kill_quiet -0 "${SWTPM_PID}"
-if [ $? -ne 0 ]; then
+if ! kill_quiet -0 "${SWTPM_PID}"; then
echo "Error: CUSE TPM did not start."
exit 1
fi
# Init the TPM
-run_swtpm_ioctl "${SWTPM_INTERFACE}" -i
-if [ $? -ne 0 ]; then
+if ! run_swtpm_ioctl "${SWTPM_INTERFACE}" -i; then
echo "Error: CUSE TPM initialization failed."
exit 1
fi
-kill_quiet -0 "${SWTPM_PID}" 2>/dev/null
-if [ $? -ne 0 ]; then
+if ! kill_quiet -0 "${SWTPM_PID}" 2>/dev/null; then
echo "Error: CUSE TPM not running anymore after INIT."
exit 1
fi
@@ -128,8 +121,7 @@
fi
# Save the volatile state again
-run_swtpm_ioctl "${SWTPM_INTERFACE}" -v
-if [ $? -ne 0 ]; then
+if ! run_swtpm_ioctl "${SWTPM_INTERFACE}" -v; then
echo "Error: Could not have the CUSE TPM write the volatile state to a file."
exit 1
fi
@@ -139,8 +131,7 @@
fi
# Shut the TPM down
-run_swtpm_ioctl "${SWTPM_INTERFACE}" -s
-if [ $? -ne 0 ]; then
+if ! run_swtpm_ioctl "${SWTPM_INTERFACE}" -s; then
echo "Error: Could not shut down the CUSE TPM."
exit 1
fi
@@ -157,21 +148,18 @@
display_processes_by_name "$SWTPM"
-kill_quiet -0 "${SWTPM_PID}"
-if [ $? -ne 0 ]; then
+if ! kill_quiet -0 "${SWTPM_PID}"; then
echo "Error: CUSE TPM did not start."
exit 1
fi
# Init the TPM
-run_swtpm_ioctl "${SWTPM_INTERFACE}" -i
-if [ $? -ne 0 ]; then
+if ! run_swtpm_ioctl "${SWTPM_INTERFACE}" -i; then
echo "Error: CUSE TPM initialization failed."
exit 1
fi
-kill_quiet -0 "${SWTPM_PID}" 2>/dev/null
-if [ $? -ne 0 ]; then
+if ! kill_quiet -0 "${SWTPM_PID}" 2>/dev/null; then
echo "Error: CUSE TPM not running anymore after INIT."
exit 1
fi
@@ -187,8 +175,7 @@
fi
# Save the volatile state again
-run_swtpm_ioctl "${SWTPM_INTERFACE}" -v
-if [ $? -ne 0 ]; then
+if ! run_swtpm_ioctl "${SWTPM_INTERFACE}" -v; then
echo "Error: Could not have the CUSE TPM write the volatile state to a file."
exit 1
fi
@@ -198,8 +185,7 @@
fi
# Shut the TPM down
-run_swtpm_ioctl "${SWTPM_INTERFACE}" -s
-if [ $? -ne 0 ]; then
+if ! run_swtpm_ioctl "${SWTPM_INTERFACE}" -s; then
echo "Error: Could not shut down the CUSE TPM."
exit 1
fi
diff --git a/tests/_test_tpm2_save_load_encrypted_state b/tests/_test_tpm2_save_load_encrypted_state
index e0fe2aa..af678c1 100755
--- a/tests/_test_tpm2_save_load_encrypted_state
+++ b/tests/_test_tpm2_save_load_encrypted_state
@@ -46,8 +46,7 @@
display_processes_by_name "$SWTPM"
-kill_quiet -0 "${SWTPM_PID}"
-if [ $? -ne 0 ]; then
+if ! kill_quiet -0 "${SWTPM_PID}"; then
echo "Error: ${SWTPM_INTERFACE} TPM did not start."
echo "TPM Logfile:"
cat "$logfile"
@@ -55,16 +54,14 @@
fi
# Init the TPM
-run_swtpm_ioctl "${SWTPM_INTERFACE}" -i
-if [ $? -ne 0 ]; then
+if ! run_swtpm_ioctl "${SWTPM_INTERFACE}" -i; then
echo "Error: ${SWTPM_INTERFACE} TPM initialization failed."
echo "TPM Logfile:"
cat "$logfile"
exit 1
fi
-kill_quiet -0 "${SWTPM_PID}" 2>/dev/null
-if [ $? -ne 0 ]; then
+if ! kill_quiet -0 "${SWTPM_PID}" 2>/dev/null; then
echo "Error: ${SWTPM_INTERFACE} TPM not running anymore after INIT."
echo "TPM Logfile:"
cat "$logfile"
@@ -81,8 +78,7 @@
exit 1
fi
-run_swtpm_ioctl "${SWTPM_INTERFACE}" -h 1234
-if [ $? -ne 0 ]; then
+if ! run_swtpm_ioctl "${SWTPM_INTERFACE}" -h 1234; then
echo "Error: Could not hash the data."
echo "TPM Logfile:"
cat "$logfile"
@@ -99,8 +95,7 @@
exit 1
fi
-run_swtpm_ioctl "${SWTPM_INTERFACE}" --save permanent "$MY_PERMANENT_STATE_FILE"
-if [ $? -ne 0 ]; then
+if ! run_swtpm_ioctl "${SWTPM_INTERFACE}" --save permanent "$MY_PERMANENT_STATE_FILE"; then
echo "Error: Could not write permanent state file $MY_PERMANENT_STATE_FILE."
echo "TPM Logfile:"
cat "$logfile"
@@ -114,8 +109,7 @@
fi
echo "Saved permanent state."
-run_swtpm_ioctl "${SWTPM_INTERFACE}" --save volatile "$MY_VOLATILE_STATE_FILE"
-if [ $? -ne 0 ]; then
+if ! run_swtpm_ioctl "${SWTPM_INTERFACE}" --save volatile "$MY_VOLATILE_STATE_FILE"; then
echo "Error: Could not write volatile state file $MY_PERMANENT_STATE_FILE."
echo "TPM Logfile:"
cat "$logfile"
@@ -138,8 +132,7 @@
# Stop the TPM; this will not shut it down
run_swtpm_ioctl "${SWTPM_INTERFACE}" --stop
-kill_quiet -0 "${SWTPM_PID}"
-if [ $? -ne 0 ]; then
+if ! kill_quiet -0 "${SWTPM_PID}"; then
echo "Error (2): ${SWTPM_INTERFACE} TPM is not running anymore."
echo "TPM Logfile:"
cat "$logfile"
@@ -147,8 +140,7 @@
fi
# load state into the TPM
-run_swtpm_ioctl "${SWTPM_INTERFACE}" --load permanent "$MY_PERMANENT_STATE_FILE"
-if [ $? -ne 0 ]; then
+if ! run_swtpm_ioctl "${SWTPM_INTERFACE}" --load permanent "$MY_PERMANENT_STATE_FILE"; then
echo "Could not load permanent state into vTPM"
echo "TPM Logfile:"
cat "$logfile"
@@ -156,8 +148,7 @@
fi
echo "Loaded permanent state."
-run_swtpm_ioctl "${SWTPM_INTERFACE}" --load volatile "$MY_VOLATILE_STATE_FILE"
-if [ $? -ne 0 ]; then
+if ! run_swtpm_ioctl "${SWTPM_INTERFACE}" --load volatile "$MY_VOLATILE_STATE_FILE"; then
echo "Could not load volatile state into vTPM"
echo "TPM Logfile:"
cat "$logfile"
@@ -169,8 +160,7 @@
#sha1sum $(dirname $MY_VOLATILE_STATE_FILE)/*
# Init the TPM
-run_swtpm_ioctl "${SWTPM_INTERFACE}" -i
-if [ $? -ne 0 ]; then
+if ! run_swtpm_ioctl "${SWTPM_INTERFACE}" -i; then
echo "TPM Init failed."
echo "TPM Logfile:"
cat "$logfile"
@@ -196,8 +186,7 @@
fi
# Save the volatile state again
-run_swtpm_ioctl "${SWTPM_INTERFACE}" -v
-if [ $? -ne 0 ]; then
+if ! run_swtpm_ioctl "${SWTPM_INTERFACE}" -v; then
echo "Error: Could not have the ${SWTPM_INTERFACE} TPM write the volatile state to a file."
echo "TPM Logfile:"
cat "$logfile"
@@ -211,8 +200,7 @@
fi
# Send a new TPM_Init
-run_swtpm_ioctl "${SWTPM_INTERFACE}" -i
-if [ $? -ne 0 ]; then
+if ! run_swtpm_ioctl "${SWTPM_INTERFACE}" -i; then
echo "Error: ${SWTPM_INTERFACE} TPM initialization failed."
echo "TPM Logfile:"
cat "$logfile"
@@ -237,8 +225,7 @@
exit 1
fi
-run_swtpm_ioctl "${SWTPM_INTERFACE}" -s
-if [ $? -ne 0 ]; then
+if ! run_swtpm_ioctl "${SWTPM_INTERFACE}" -s; then
echo "Error: Could not shut down the ${SWTPM_INTERFACE} TPM."
echo "TPM Logfile:"
cat "$logfile"
@@ -271,8 +258,7 @@
display_processes_by_name "$SWTPM"
-kill_quiet -0 "${SWTPM_PID}"
-if [ $? -ne 0 ]; then
+if ! kill_quiet -0 "${SWTPM_PID}"; then
echo "Error: ${SWTPM_INTERFACE} TPM did not start."
echo "TPM Logfile:"
cat "$logfile"
@@ -280,8 +266,7 @@
fi
# Init the TPM
-ERR="$(run_swtpm_ioctl "${SWTPM_INTERFACE}" -i 2>&1)"
-if [ $? -eq 0 ]; then
+if ERR="$(run_swtpm_ioctl "${SWTPM_INTERFACE}" -i 2>&1)"; then
echo "Error: ${SWTPM_INTERFACE} TPM initialization should have failed."
echo "TPM Logfile:"
cat "$logfile"
@@ -295,8 +280,7 @@
exit 1
fi
-kill_quiet -0 "${SWTPM_PID}" 2>/dev/null
-if [ $? -ne 0 ]; then
+if ! kill_quiet -0 "${SWTPM_PID}" 2>/dev/null; then
echo "Error: ${SWTPM_INTERFACE} TPM not running anymore after failed INIT."
echo "TPM Logfile:"
cat "$logfile"
@@ -313,8 +297,7 @@
exit 1
fi
-run_swtpm_ioctl "${SWTPM_INTERFACE}" -s
-if [ $? -ne 0 ]; then
+if ! run_swtpm_ioctl "${SWTPM_INTERFACE}" -s; then
echo "Error: Could not shut down the ${SWTPM_INTERFACE} TPM."
echo "TPM Logfile:"
cat "$logfile"
@@ -352,8 +335,7 @@
display_processes_by_name "$SWTPM"
-kill_quiet -0 "${SWTPM_PID}"
-if [ $? -ne 0 ]; then
+if ! kill_quiet -0 "${SWTPM_PID}"; then
echo "Error: ${SWTPM_INTERFACE} TPM did not start."
echo "TPM Logfile:"
cat "$logfile"
@@ -361,8 +343,7 @@
fi
# Init the TPM
-run_swtpm_ioctl "${SWTPM_INTERFACE}" -i
-if [ $? -eq 0 ]; then
+if run_swtpm_ioctl "${SWTPM_INTERFACE}" -i; then
echo "Error: ${SWTPM_INTERFACE} TPM initialization should have failed."
echo "TPM Logfile:"
cat "$logfile"
@@ -389,8 +370,7 @@
echo "Test 3: Ok"
# Final shut down
-run_swtpm_ioctl "${SWTPM_INTERFACE}" -s
-if [ $? -ne 0 ]; then
+if ! run_swtpm_ioctl "${SWTPM_INTERFACE}" -s; then
echo "Error: Could not shut down the ${SWTPM_INTERFACE} TPM."
echo "TPM Logfile:"
cat "$logfile"
diff --git a/tests/_test_tpm2_save_load_state b/tests/_test_tpm2_save_load_state
index 434435d..549d5d7 100755
--- a/tests/_test_tpm2_save_load_state
+++ b/tests/_test_tpm2_save_load_state
@@ -42,8 +42,7 @@
display_processes_by_name "$SWTPM"
-kill_quiet -0 "${SWTPM_PID}"
-if [ $? -ne 0 ]; then
+if ! kill_quiet -0 "${SWTPM_PID}"; then
echo "Error: ${SWTPM_INTERFACE} TPM did not start."
echo "TPM Logfile:"
cat "$logfile"
@@ -51,16 +50,14 @@
fi
# Init the TPM
-run_swtpm_ioctl "${SWTPM_INTERFACE}" -i
-if [ $? -ne 0 ]; then
+if ! run_swtpm_ioctl "${SWTPM_INTERFACE}" -i; then
echo "Error: Could not initialize the ${SWTPM_INTERFACE} TPM."
echo "TPM Logfile:"
cat "$logfile"
exit 1
fi
-kill_quiet -0 "${SWTPM_PID}" 2>/dev/null
-if [ $? -ne 0 ]; then
+if ! kill_quiet -0 "${SWTPM_PID}" 2>/dev/null; then
echo "Error: ${SWTPM_INTERFACE} TPM not running anymore after INIT."
echo "TPM Logfile:"
cat "$logfile"
@@ -77,8 +74,7 @@
exit 1
fi
-run_swtpm_ioctl "${SWTPM_INTERFACE}" -h 1234
-if [ $? -ne 0 ]; then
+if ! run_swtpm_ioctl "${SWTPM_INTERFACE}" -h 1234; then
echo "Error: Hash command did not work."
echo "TPM Logfile:"
cat "$logfile"
@@ -96,8 +92,7 @@
exit 1
fi
-run_swtpm_ioctl "${SWTPM_INTERFACE}" --save permanent "$MY_PERMANENT_STATE_FILE"
-if [ $? -ne 0 ]; then
+if ! run_swtpm_ioctl "${SWTPM_INTERFACE}" --save permanent "$MY_PERMANENT_STATE_FILE"; then
echo "Error: Could not write permanent state file $MY_PERMANENT_STATE_FILE."
echo "TPM Logfile:"
cat "$logfile"
@@ -111,8 +106,7 @@
fi
echo "Saved permanent state."
-run_swtpm_ioctl "${SWTPM_INTERFACE}" --save volatile "$MY_VOLATILE_STATE_FILE"
-if [ $? -ne 0 ]; then
+if ! run_swtpm_ioctl "${SWTPM_INTERFACE}" --save volatile "$MY_VOLATILE_STATE_FILE"; then
echo "Error: Could not write volatile state file $MY_VOLATILE_STATE_FILE."
echo "TPM Logfile:"
cat "$logfile"
@@ -133,16 +127,14 @@
rm -f "$VOLATILE_STATE_FILE" "$STATE_FILE"
# Stop the TPM; this will not shut it down
-run_swtpm_ioctl "${SWTPM_INTERFACE}" --stop
-if [ $? -ne 0 ]; then
+if ! run_swtpm_ioctl "${SWTPM_INTERFACE}" --stop; then
echo "Error: Could not stop the ${SWTPM_INTERFACE} TPM."
echo "TPM Logfile:"
cat "$logfile"
exit 1
fi
-kill_quiet -0 "${SWTPM_PID}"
-if [ $? -ne 0 ]; then
+if ! kill_quiet -0 "${SWTPM_PID}"; then
echo "Error (2): ${SWTPM_INTERFACE} TPM is not running anymore."
echo "TPM Logfile:"
cat "$logfile"
@@ -150,8 +142,7 @@
fi
# load state into the TPM
-run_swtpm_ioctl "${SWTPM_INTERFACE}" --load permanent "$MY_PERMANENT_STATE_FILE"
-if [ $? -ne 0 ]; then
+if ! run_swtpm_ioctl "${SWTPM_INTERFACE}" --load permanent "$MY_PERMANENT_STATE_FILE"; then
echo "Could not load permanent state into vTPM"
echo "TPM Logfile:"
cat "$logfile"
@@ -159,8 +150,7 @@
fi
echo "Loaded permanent state."
-run_swtpm_ioctl "${SWTPM_INTERFACE}" --load volatile "$MY_VOLATILE_STATE_FILE"
-if [ $? -ne 0 ]; then
+if ! run_swtpm_ioctl "${SWTPM_INTERFACE}" --load volatile "$MY_VOLATILE_STATE_FILE"; then
echo "Could not load volatile state into vTPM"
echo "TPM Logfile:"
cat "$logfile"
@@ -172,8 +162,7 @@
#sha1sum $(dirname $MY_VOLATILE_STATE_FILE)/*
# Init the TPM
-run_swtpm_ioctl "${SWTPM_INTERFACE}" -i
-if [ $? -ne 0 ]; then
+if ! run_swtpm_ioctl "${SWTPM_INTERFACE}" -i; then
echo "TPM Init failed."
echo "TPM Logfile:"
cat "$logfile"
@@ -199,8 +188,7 @@
fi
# Save the volatile state again
-run_swtpm_ioctl "${SWTPM_INTERFACE}" -v
-if [ $? -ne 0 ]; then
+if ! run_swtpm_ioctl "${SWTPM_INTERFACE}" -v; then
echo "Error: Could not have the ${SWTPM_INTERFACE} TPM store the volatile state to a file."
echo "TPM Logfile:"
cat "$logfile"
@@ -215,8 +203,7 @@
fi
# Send a new TPM_Init
-run_swtpm_ioctl "${SWTPM_INTERFACE}" -i
-if [ $? -ne 0 ]; then
+if ! run_swtpm_ioctl "${SWTPM_INTERFACE}" -i; then
echo "Error: Could not initialize the ${SWTPM_INTERFACE} TPM."
echo "TPM Logfile:"
cat "$logfile"
@@ -242,8 +229,7 @@
fi
# Final shut down
-run_swtpm_ioctl "${SWTPM_INTERFACE}" -s
-if [ $? -ne 0 ]; then
+if ! run_swtpm_ioctl "${SWTPM_INTERFACE}" -s; then
echo "Error: Could not shut down the ${SWTPM_INTERFACE} TPM."
echo "TPM Logfile:"
cat "$logfile"
diff --git a/tests/_test_tpm2_save_load_state_da_timeout b/tests/_test_tpm2_save_load_state_da_timeout
index 5e3cbe4..a74c19a 100755
--- a/tests/_test_tpm2_save_load_state_da_timeout
+++ b/tests/_test_tpm2_save_load_state_da_timeout
@@ -43,8 +43,7 @@
display_processes_by_name "$SWTPM"
-kill_quiet -0 "${SWTPM_PID}"
-if [ $? -ne 0 ]; then
+if ! kill_quiet -0 "${SWTPM_PID}"; then
echo "Error: ${SWTPM_INTERFACE} TPM did not start."
echo "TPM Logfile:"
cat "$logfile"
@@ -52,16 +51,14 @@
fi
# Init the TPM
-run_swtpm_ioctl "${SWTPM_INTERFACE}" -i
-if [ $? -ne 0 ]; then
+if ! run_swtpm_ioctl "${SWTPM_INTERFACE}" -i; then
echo "Error: Could not initialize the ${SWTPM_INTERFACE} TPM."
echo "TPM Logfile:"
cat "$logfile"
exit 1
fi
-kill_quiet -0 "${SWTPM_PID}" 2>/dev/null
-if [ $? -ne 0 ]; then
+if ! kill_quiet -0 "${SWTPM_PID}" 2>/dev/null; then
echo "Error: ${SWTPM_INTERFACE} TPM not running anymore after INIT."
echo "TPM Logfile:"
cat "$logfile"
@@ -186,8 +183,7 @@
timerecovery=$((timenow + 6))
# Save the state and restore it and then try to poll again
-run_swtpm_ioctl "${SWTPM_INTERFACE}" --save permanent "$MY_PERMANENT_STATE_FILE"
-if [ $? -ne 0 ]; then
+if ! run_swtpm_ioctl "${SWTPM_INTERFACE}" --save permanent "$MY_PERMANENT_STATE_FILE"; then
echo "Error: Could not write permanent state file $MY_PERMANENT_STATE_FILE."
echo "TPM Logfile:"
cat "$logfile"
@@ -201,8 +197,7 @@
fi
echo "Saved permanent state."
-run_swtpm_ioctl "${SWTPM_INTERFACE}" --save volatile "$MY_VOLATILE_STATE_FILE"
-if [ $? -ne 0 ]; then
+if ! run_swtpm_ioctl "${SWTPM_INTERFACE}" --save volatile "$MY_VOLATILE_STATE_FILE"; then
echo "Error: Could not write volatile state file $MY_VOLATILE_STATE_FILE."
echo "TPM Logfile:"
cat "$logfile"
@@ -220,16 +215,14 @@
rm -f "$VOLATILE_STATE_FILE" "$STATE_FILE"
# Stop the TPM; this will not shut it down
-run_swtpm_ioctl "${SWTPM_INTERFACE}" --stop
-if [ $? -ne 0 ]; then
+if ! run_swtpm_ioctl "${SWTPM_INTERFACE}" --stop; then
echo "Error: Could not stop the ${SWTPM_INTERFACE} TPM."
echo "TPM Logfile:"
cat "$logfile"
exit 1
fi
-kill_quiet -0 "${SWTPM_PID}"
-if [ $? -ne 0 ]; then
+if ! kill_quiet -0 "${SWTPM_PID}"; then
echo "Error (2): ${SWTPM_INTERFACE} TPM is not running anymore."
echo "TPM Logfile:"
cat "$logfile"
@@ -237,8 +230,7 @@
fi
# load state into the TPM
-run_swtpm_ioctl "${SWTPM_INTERFACE}" --load permanent "$MY_PERMANENT_STATE_FILE"
-if [ $? -ne 0 ]; then
+if ! run_swtpm_ioctl "${SWTPM_INTERFACE}" --load permanent "$MY_PERMANENT_STATE_FILE"; then
echo "Could not load permanent state into vTPM"
echo "TPM Logfile:"
cat "$logfile"
@@ -246,8 +238,7 @@
fi
echo "Loaded permanent state."
-run_swtpm_ioctl "${SWTPM_INTERFACE}" --load volatile "$MY_VOLATILE_STATE_FILE"
-if [ $? -ne 0 ]; then
+if ! run_swtpm_ioctl "${SWTPM_INTERFACE}" --load volatile "$MY_VOLATILE_STATE_FILE"; then
echo "Could not load volatile state into vTPM"
echo "TPM Logfile:"
cat "$logfile"
@@ -259,8 +250,7 @@
#sha1sum $(dirname $MY_VOLATILE_STATE_FILE)/*
# Init the TPM
-run_swtpm_ioctl "${SWTPM_INTERFACE}" -i
-if [ $? -ne 0 ]; then
+if ! run_swtpm_ioctl "${SWTPM_INTERFACE}" -i; then
echo "TPM Init failed."
echo "TPM Logfile:"
cat "$logfile"
@@ -317,8 +307,7 @@
fi
# Final shut down
-run_swtpm_ioctl "${SWTPM_INTERFACE}" -s
-if [ $? -ne 0 ]; then
+if ! run_swtpm_ioctl "${SWTPM_INTERFACE}" -s; then
echo "Error: Could not shut down the ${SWTPM_INTERFACE} TPM."
echo "TPM Logfile:"
cat "$logfile"
diff --git a/tests/_test_tpm2_save_load_state_locking b/tests/_test_tpm2_save_load_state_locking
index b71b8b6..93db17c 100755
--- a/tests/_test_tpm2_save_load_state_locking
+++ b/tests/_test_tpm2_save_load_state_locking
@@ -35,24 +35,21 @@
--migration release-lock-outgoing \
--tpm2
-kill_quiet -0 "${SWTPM_PID}"
-if [ $? -ne 0 ]; then
+if ! kill_quiet -0 "${SWTPM_PID}"; then
echo "Error: ${SWTPM_INTERFACE} TPM did not start."
exit 1
fi
check_swtpm_no_storage_lock "${SWTPM_PID}"
# Init the TPM
-run_swtpm_ioctl "${SWTPM_INTERFACE}" -i
-if [ $? -ne 0 ]; then
+if ! run_swtpm_ioctl "${SWTPM_INTERFACE}" -i; then
echo "Error: Could not initialize the ${SWTPM_INTERFACE} TPM."
exit 1
fi
check_swtpm_storage_locked "${SWTPM_PID}"
swtpm_lock_storage "re-lock"
-kill_quiet -0 "${SWTPM_PID}" 2>/dev/null
-if [ $? -ne 0 ]; then
+if ! kill_quiet -0 "${SWTPM_PID}" 2>/dev/null; then
echo "Error: ${SWTPM_INTERFACE} TPM not running anymore after INIT."
exit 1
fi
@@ -69,8 +66,7 @@
check_swtpm_storage_locked "${SWTPM_PID}"
swtpm_lock_storage "re-lock"
-run_swtpm_ioctl "${SWTPM_INTERFACE}" -h 1234
-if [ $? -ne 0 ]; then
+if ! run_swtpm_ioctl "${SWTPM_INTERFACE}" -h 1234; then
echo "Error: Hash command did not work."
exit 1
fi
@@ -86,8 +82,7 @@
exit 1
fi
-run_swtpm_ioctl "${SWTPM_INTERFACE}" --save permanent "$MY_PERMANENT_STATE_FILE"
-if [ $? -ne 0 ]; then
+if ! run_swtpm_ioctl "${SWTPM_INTERFACE}" --save permanent "$MY_PERMANENT_STATE_FILE"; then
echo "Error: Could not write permanent state file $MY_PERMANENT_STATE_FILE."
exit 1
fi
@@ -99,8 +94,7 @@
check_swtpm_storage_locked "${SWTPM_PID}"
swtpm_lock_storage "re-lock"
-run_swtpm_ioctl "${SWTPM_INTERFACE}" --save volatile "$MY_VOLATILE_STATE_FILE"
-if [ $? -ne 0 ]; then
+if ! run_swtpm_ioctl "${SWTPM_INTERFACE}" --save volatile "$MY_VOLATILE_STATE_FILE"; then
echo "Error: Could not write volatile state file $MY_VOLATILE_STATE_FILE."
exit 1
fi
@@ -112,8 +106,7 @@
check_swtpm_storage_locked "${SWTPM_PID}"
swtpm_lock_storage "re-lock"
-run_swtpm_ioctl "${SWTPM_INTERFACE}" --save savestate "$MY_SAVESTATE_STATE_FILE"
-if [ $? -ne 0 ]; then
+if ! run_swtpm_ioctl "${SWTPM_INTERFACE}" --save savestate "$MY_SAVESTATE_STATE_FILE"; then
echo "Error: Could not write savestate state file $MY_SAVESTATE_STATE_FILE."
exit 1
fi
@@ -142,8 +135,7 @@
check_swtpm_storage_locked "${SWTPM_PID}"
swtpm_lock_storage "re-lock"
-run_swtpm_ioctl "${SWTPM_INTERFACE}" -s
-if [ $? -ne 0 ]; then
+if ! run_swtpm_ioctl "${SWTPM_INTERFACE}" -s; then
echo "Error: Could not shut down the ${SWTPM_INTERFACE} TPM."
exit 1
fi
@@ -159,16 +151,14 @@
--migration incoming,release-lock-outgoing \
--tpm2
-kill_quiet -0 "${SWTPM_PID}"
-if [ $? -ne 0 ]; then
+if ! kill_quiet -0 "${SWTPM_PID}"; then
echo "Error: ${SWTPM_INTERFACE} TPM did not start."
exit 1
fi
check_swtpm_no_storage_lock "${SWTPM_PID}"
# load state into the TPM
-run_swtpm_ioctl "${SWTPM_INTERFACE}" --load permanent "$MY_PERMANENT_STATE_FILE"
-if [ $? -ne 0 ]; then
+if ! run_swtpm_ioctl "${SWTPM_INTERFACE}" --load permanent "$MY_PERMANENT_STATE_FILE"; then
echo "Could not load permanent state into vTPM"
exit 1
fi
@@ -176,8 +166,7 @@
check_swtpm_storage_locked "${SWTPM_PID}"
swtpm_lock_storage "re-lock"
-run_swtpm_ioctl "${SWTPM_INTERFACE}" --load volatile "$MY_VOLATILE_STATE_FILE"
-if [ $? -ne 0 ]; then
+if ! run_swtpm_ioctl "${SWTPM_INTERFACE}" --load volatile "$MY_VOLATILE_STATE_FILE"; then
echo "Could not load volatile state into vTPM"
exit 1
fi
@@ -185,8 +174,7 @@
check_swtpm_storage_locked "${SWTPM_PID}"
# Init the TPM
-run_swtpm_ioctl "${SWTPM_INTERFACE}" -i
-if [ $? -ne 0 ]; then
+if ! run_swtpm_ioctl "${SWTPM_INTERFACE}" -i; then
echo "TPM Init failed."
exit 1
fi
@@ -210,8 +198,7 @@
fi
# Save the volatile state again
-run_swtpm_ioctl "${SWTPM_INTERFACE}" -v
-if [ $? -ne 0 ]; then
+if ! run_swtpm_ioctl "${SWTPM_INTERFACE}" -v; then
echo "Error: Could not have the ${SWTPM_INTERFACE} TPM store the volatile state to a file."
exit 1
fi
@@ -222,8 +209,7 @@
fi
# Send a new TPM_Init
-run_swtpm_ioctl "${SWTPM_INTERFACE}" -i
-if [ $? -ne 0 ]; then
+if ! run_swtpm_ioctl "${SWTPM_INTERFACE}" -i; then
echo "Error: Could not initialize the ${SWTPM_INTERFACE} TPM."
exit 1
fi
@@ -245,8 +231,7 @@
fi
# Final shut down
-run_swtpm_ioctl "${SWTPM_INTERFACE}" -s
-if [ $? -ne 0 ]; then
+if ! run_swtpm_ioctl "${SWTPM_INTERFACE}" -s; then
echo "Error: Could not shut down the ${SWTPM_INTERFACE} TPM."
exit 1
fi
diff --git a/tests/_test_tpm2_savestate b/tests/_test_tpm2_savestate
index 5fa066d..565bdba 100755
--- a/tests/_test_tpm2_savestate
+++ b/tests/_test_tpm2_savestate
@@ -35,21 +35,18 @@
display_processes_by_name "$SWTPM"
-kill_quiet -0 "${SWTPM_PID}"
-if [ $? -ne 0 ]; then
+if ! kill_quiet -0 "${SWTPM_PID}"; then
echo "Error: ${SWTPM_INTERFACE} TPM did not start."
exit 1
fi
# Init the TPM
-run_swtpm_ioctl "${SWTPM_INTERFACE}" -i
-if [ $? -ne 0 ]; then
+if ! run_swtpm_ioctl "${SWTPM_INTERFACE}" -i; then
echo "Error: Could not initialize the ${SWTPM_INTERFACE} TPM."
exit 1
fi
-kill_quiet -0 "${SWTPM_PID}" 2>/dev/null
-if [ $? -ne 0 ]; then
+if ! kill_quiet -0 "${SWTPM_PID}" 2>/dev/null; then
echo "Error: ${SWTPM_INTERFACE} TPM not running anymore after INIT."
exit 1
fi
@@ -101,8 +98,7 @@
fi
# Init the TPM
-run_swtpm_ioctl "${SWTPM_INTERFACE}" -i
-if [ $? -ne 0 ]; then
+if ! run_swtpm_ioctl "${SWTPM_INTERFACE}" -i; then
echo "Error: Could not initialize the ${SWTPM_INTERFACE} TPM."
exit 1
fi
@@ -128,8 +124,7 @@
exit 1
fi
-run_swtpm_ioctl "${SWTPM_INTERFACE}" -s
-if [ $? -ne 0 ]; then
+if ! run_swtpm_ioctl "${SWTPM_INTERFACE}" -s; then
echo "Error: Could not shut down the ${SWTPM_INTERFACE} TPM."
exit 1
fi
diff --git a/tests/_test_tpm2_setbuffersize b/tests/_test_tpm2_setbuffersize
index 98e69b8..9a42ccf 100755
--- a/tests/_test_tpm2_setbuffersize
+++ b/tests/_test_tpm2_setbuffersize
@@ -34,15 +34,13 @@
TPM_PATH=$TPM_PATH run_swtpm "${SWTPM_INTERFACE}" --tpm2
-kill_quiet -0 "${SWTPM_PID}"
-if [ $? -ne 0 ]; then
+if ! kill_quiet -0 "${SWTPM_PID}"; then
echo "Error: ${SWTPM_INTERFACE} TPM did not start."
exit 1
fi
# Check the buffer size
-run_swtpm_ioctl "${SWTPM_INTERFACE}" -b 0 > "${OUTFILE}"
-if [ $? -ne 0 ]; then
+if ! run_swtpm_ioctl "${SWTPM_INTERFACE}" -b 0 > "${OUTFILE}"; then
echo "Error: Could not get the buffersize of the ${SWTPM_INTERFACE} TPM."
exit 1
fi
@@ -54,8 +52,7 @@
fi
# set the buffer size -- it's not going to change but command must not fail
-run_swtpm_ioctl "${SWTPM_INTERFACE}" -b 4000 > "${OUTFILE}"
-if [ $? -ne 0 ]; then
+if ! run_swtpm_ioctl "${SWTPM_INTERFACE}" -b 4000 > "${OUTFILE}"; then
echo "Error: Could not set the buffersize of the ${SWTPM_INTERFACE} TPM."
exit 1
fi
@@ -67,21 +64,18 @@
fi
# Init the TPM
-run_swtpm_ioctl "${SWTPM_INTERFACE}" -i
-if [ $? -ne 0 ]; then
+if ! run_swtpm_ioctl "${SWTPM_INTERFACE}" -i; then
echo "Error: Could not initialize the ${SWTPM_INTERFACE} TPM."
exit 1
fi
-kill_quiet -0 "${SWTPM_PID}" 2>/dev/null
-if [ $? -ne 0 ]; then
+if ! kill_quiet -0 "${SWTPM_PID}" 2>/dev/null; then
echo "Error: ${SWTPM_INTERFACE} TPM not running anymore after INIT."
exit 1
fi
# Set the buffer size -- should fail
-ERR="$(run_swtpm_ioctl "${SWTPM_INTERFACE}" -b 4096 2>&1)"
-if [ $? -eq 0 ]; then
+if ERR="$(run_swtpm_ioctl "${SWTPM_INTERFACE}" -b 4096 2>&1)"; then
echo "Error: Could set the buffersize while the ${SWTPM_INTERFACE} TPM is running."
exit 1
fi
@@ -113,8 +107,7 @@
exit 1
fi
-run_swtpm_ioctl "${SWTPM_INTERFACE}" -s
-if [ $? -ne 0 ]; then
+if ! run_swtpm_ioctl "${SWTPM_INTERFACE}" -s; then
echo "Error: Could not shut down the ${SWTPM_INTERFACE} TPM."
exit 1
fi
diff --git a/tests/_test_tpm2_swtpm_bios b/tests/_test_tpm2_swtpm_bios
index 913e7b3..46c4eee 100755
--- a/tests/_test_tpm2_swtpm_bios
+++ b/tests/_test_tpm2_swtpm_bios
@@ -36,8 +36,7 @@
display_processes_by_name "$SWTPM"
-kill_quiet -0 "${SWTPM_PID}"
-if [ $? -ne 0 ]; then
+if ! kill_quiet -0 "${SWTPM_PID}"; then
echo "Error: ${SWTPM_INTERFACE} TPM did not start."
exit 1
fi
@@ -54,8 +53,7 @@
fi
# Init the TPM
-run_swtpm_ioctl "${SWTPM_INTERFACE}" -i
-if [ $? -ne 0 ]; then
+if ! run_swtpm_ioctl "${SWTPM_INTERFACE}" -i; then
echo "Error: Could not initialize the ${SWTPM_INTERFACE} TPM."
exit 1
fi
@@ -66,22 +64,19 @@
fi
# must work
-res=$(run_swtpm_bios "${SWTPM_INTERFACE}" --tpm2 -o 2>&1)
-if [ $? -ne 0 ] || [ -n "$res" ]; then
+if ! res=$(run_swtpm_bios "${SWTPM_INTERFACE}" --tpm2 -o 2>&1) || [ -n "$res" ]; then
echo "Error: Could not startup the ${SWTPM_INTERFACE} TPM."
exit 1
fi
# must work
-res=$(run_swtpm_bios "${SWTPM_INTERFACE}" --tpm2 -n --cs 2>&1)
-if [ $? -ne 0 ] || [ -n "$res" ]; then
+if ! res=$(run_swtpm_bios "${SWTPM_INTERFACE}" --tpm2 -n --cs 2>&1) || [ -n "$res" ]; then
echo "Error: Could not self-test the ${SWTPM_INTERFACE} TPM."
exit 1
fi
# must work
-res=$(run_swtpm_bios "${SWTPM_INTERFACE}" --tpm2 -n -u 2>&1)
-if [ $? -ne 0 ] || [ -n "$res" ]; then
+if ! res=$(run_swtpm_bios "${SWTPM_INTERFACE}" --tpm2 -n -u 2>&1) || [ -n "$res" ]; then
echo "Error: Could not give up physical presence on the ${SWTPM_INTERFACE} TPM."
exit 1
fi
@@ -116,15 +111,13 @@
# RESET TPM
-run_swtpm_ioctl "${SWTPM_INTERFACE}" -i
-if [ $? -ne 0 ]; then
+if ! run_swtpm_ioctl "${SWTPM_INTERFACE}" -i; then
echo "Error: Could not initialize the ${SWTPM_INTERFACE} TPM."
exit 1
fi
# must work
-res=$(run_swtpm_bios "${SWTPM_INTERFACE}" --tpm2 --cs -u 2>&1)
-if [ $? -ne 0 ] || [ -n "$res" ]; then
+if ! res=$(run_swtpm_bios "${SWTPM_INTERFACE}" --tpm2 --cs -u 2>&1) || [ -n "$res" ]; then
echo "Error: Could not startup the ${SWTPM_INTERFACE} TPM."
exit 1
fi
@@ -142,8 +135,7 @@
exit 1
fi
-run_swtpm_ioctl "${SWTPM_INTERFACE}" -s
-if [ $? -ne 0 ]; then
+if ! run_swtpm_ioctl "${SWTPM_INTERFACE}" -s; then
echo "Error: Could not shut down the ${SWTPM_INTERFACE} TPM."
exit 1
fi
diff --git a/tests/_test_tpm2_volatilestate b/tests/_test_tpm2_volatilestate
index 47ac582..bbcfa0f 100755
--- a/tests/_test_tpm2_volatilestate
+++ b/tests/_test_tpm2_volatilestate
@@ -35,21 +35,18 @@
display_processes_by_name "$SWTPM"
-kill_quiet -0 "${SWTPM_PID}"
-if [ $? -ne 0 ]; then
+if ! kill_quiet -0 "${SWTPM_PID}"; then
echo "Error: ${SWTPM_INTERFACE} TPM did not start."
exit 1
fi
# Init the TPM
-run_swtpm_ioctl "${SWTPM_INTERFACE}" -i
-if [ $? -ne 0 ]; then
+if ! run_swtpm_ioctl "${SWTPM_INTERFACE}" -i; then
echo "Error: Could not initialize the ${SWTPM_INTERFACE} TPM."
exit 1
fi
-kill_quiet -0 "${SWTPM_PID}" 2>/dev/null
-if [ $? -ne 0 ]; then
+if ! kill_quiet -0 "${SWTPM_PID}" 2>/dev/null; then
echo "Error: ${SWTPM_INTERFACE} TPM not running anymore after INIT."
exit 1
fi
@@ -64,8 +61,7 @@
exit 1
fi
-run_swtpm_ioctl "${SWTPM_INTERFACE}" -h 1234
-if [ $? -ne 0 ]; then
+if ! run_swtpm_ioctl "${SWTPM_INTERFACE}" -h 1234; then
echo "Error: Hash command did not work."
exit 1
fi
@@ -92,8 +88,7 @@
fi
# Save the volatile state
-run_swtpm_ioctl "${SWTPM_INTERFACE}" -v
-if [ $? -ne 0 ]; then
+if ! run_swtpm_ioctl "${SWTPM_INTERFACE}" -v; then
echo "Error: Could not have the ${SWTPM_INTERFACE} TPM store the volatile state to a file."
exit 1
fi
@@ -104,8 +99,7 @@
fi
# Shut the TPM down
-run_swtpm_ioctl "${SWTPM_INTERFACE}" -s
-if [ $? -ne 0 ]; then
+if ! run_swtpm_ioctl "${SWTPM_INTERFACE}" -s; then
echo "Error: Could not shut down the ${SWTPM_INTERFACE} TPM."
exit 1
fi
@@ -115,15 +109,13 @@
display_processes_by_name "$SWTPM"
-kill_quiet -0 "${SWTPM_PID}"
-if [ $? -ne 0 ]; then
+if ! kill_quiet -0 "${SWTPM_PID}"; then
echo "Error: ${SWTPM_INTERFACE} TPM did not start."
exit 1
fi
# Init the TPM
-run_swtpm_ioctl "${SWTPM_INTERFACE}" -i
-if [ $? -ne 0 ]; then
+if ! run_swtpm_ioctl "${SWTPM_INTERFACE}" -i; then
echo "Error: Could not initialize the ${SWTPM_INTERFACE} TPM."
exit 1
fi
@@ -155,8 +147,7 @@
fi
# Save the volatile state again
-run_swtpm_ioctl "${SWTPM_INTERFACE}" -v
-if [ $? -ne 0 ]; then
+if ! run_swtpm_ioctl "${SWTPM_INTERFACE}" -v; then
echo "Error: Could not have the ${SWTPM_INTERFACE} TPM store the volatile state to a file."
exit 1
fi
@@ -167,8 +158,7 @@
fi
# Send a new TPM_Init
-run_swtpm_ioctl "${SWTPM_INTERFACE}" -i
-if [ $? -ne 0 ]; then
+if ! run_swtpm_ioctl "${SWTPM_INTERFACE}" -i; then
echo "Error: Could not initialize the ${SWTPM_INTERFACE} TPM."
exit 1
fi
@@ -190,8 +180,7 @@
fi
# Check that the TPM Established bit is still set
-RES=$(run_swtpm_ioctl "${SWTPM_INTERFACE}" -e)
-if [ $? -ne 0 ]; then
+if ! RES=$(run_swtpm_ioctl "${SWTPM_INTERFACE}" -e); then
echo "Error: Could not get the TPM Established flag from the ${SWTPM_INTERFACE} TPM."
exit 1
fi
@@ -204,8 +193,7 @@
fi
# Final shut down
-run_swtpm_ioctl "${SWTPM_INTERFACE}" -s
-if [ $? -ne 0 ]; then
+if ! run_swtpm_ioctl "${SWTPM_INTERFACE}" -s; then
echo "Error: Could not shut down the ${SWTPM_INTERFACE} TPM."
exit 1
fi
diff --git a/tests/_test_tpm2_wrongorder b/tests/_test_tpm2_wrongorder
index a003606..c41f478 100755
--- a/tests/_test_tpm2_wrongorder
+++ b/tests/_test_tpm2_wrongorder
@@ -35,8 +35,7 @@
display_processes_by_name "$SWTPM"
-kill_quiet -0 "${SWTPM_PID}"
-if [ $? -ne 0 ]; then
+if ! kill_quiet -0 "${SWTPM_PID}"; then
echo "Error: ${SWTPM_INTERFACE} TPM did not start."
exit 1
fi
@@ -45,15 +44,13 @@
# This should not work
if [ "${SWTPM_INTERFACE}" != "cuse" ]; then
- run_swtpm_ioctl "${SWTPM_INTERFACE}" --stop
- if [ $? -ne 0 ]; then
+ if ! run_swtpm_ioctl "${SWTPM_INTERFACE}" --stop; then
echo "Error: Could not stop the ${SWTPM_INTERFACE} TPM."
exit 1
fi
fi
-ERR="$(run_swtpm_ioctl "${SWTPM_INTERFACE}" -e 2>&1)"
-if [ $? -eq 0 ]; then
+if ERR="$(run_swtpm_ioctl "${SWTPM_INTERFACE}" -e 2>&1)"; then
echo "Error: Could get established bit from ${SWTPM_INTERFACE} TPM before init."
exit 1
fi
@@ -65,8 +62,7 @@
exit 1
fi
-kill_quiet -0 "${SWTPM_PID}"
-if [ $? -ne 0 ]; then
+if ! kill_quiet -0 "${SWTPM_PID}"; then
echo "Error: ${SWTPM_INTERFACE} TPM must have crashed."
exit 1
fi
@@ -82,27 +78,23 @@
exit 1
fi
-kill_quiet -0 "${SWTPM_PID}"
-if [ $? -ne 0 ]; then
+if ! kill_quiet -0 "${SWTPM_PID}"; then
echo "Error: ${SWTPM_INTERFACE} TPM must have crashed."
exit 1
fi
# Init the TPM
-run_swtpm_ioctl "${SWTPM_INTERFACE}" -i
-if [ $? -ne 0 ]; then
+if ! run_swtpm_ioctl "${SWTPM_INTERFACE}" -i; then
echo "Error: Could not initialize the ${SWTPM_INTERFACE} TPM."
exit 1
fi
-kill_quiet -0 "${SWTPM_PID}" 2>/dev/null
-if [ $? -ne 0 ]; then
+if ! kill_quiet -0 "${SWTPM_PID}" 2>/dev/null; then
echo "Error: ${SWTPM_INTERFACE} TPM not running anymore after INIT."
exit 1
fi
-run_swtpm_ioctl "${SWTPM_INTERFACE}" -s
-if [ $? -ne 0 ]; then
+if ! run_swtpm_ioctl "${SWTPM_INTERFACE}" -s; then
echo "Error: Could not shut down the ${SWTPM_INTERFACE} TPM."
exit 1
fi
diff --git a/tests/_test_tpm_probe b/tests/_test_tpm_probe
index 17a88f6..7de5ac5 100755
--- a/tests/_test_tpm_probe
+++ b/tests/_test_tpm_probe
@@ -35,8 +35,7 @@
display_processes_by_name "$SWTPM"
-kill -0 ${SWTPM_PID}
-if [ $? -ne 0 ]; then
+if ! kill -0 ${SWTPM_PID}; then
echo "Error: ${SWTPM_INTERFACE} TPM did not start."
exit 1
fi
@@ -64,13 +63,11 @@
exit 1
fi
-check_seccomp_profile "${SWTPM_EXE}" "${SWTPM_PID}" 2
-if [ $? -ne 0 ]; then
+if ! check_seccomp_profile "${SWTPM_EXE}" "${SWTPM_PID}" 2; then
exit 1
fi
-run_swtpm_ioctl "${SWTPM_INTERFACE}" -s
-if [ $? -ne 0 ]; then
+if ! run_swtpm_ioctl "${SWTPM_INTERFACE}" -s; then
echo "Error: Could not shut down the ${SWTPM_INTERFACE} TPM."
exit 1
fi
diff --git a/tests/_test_volatilestate b/tests/_test_volatilestate
index c796155..fa892d0 100755
--- a/tests/_test_volatilestate
+++ b/tests/_test_volatilestate
@@ -35,21 +35,18 @@
display_processes_by_name "$SWTPM"
-kill_quiet -0 "${SWTPM_PID}"
-if [ $? -ne 0 ]; then
+if ! kill_quiet -0 "${SWTPM_PID}"; then
echo "Error: ${SWTPM_INTERFACE} TPM did not start."
exit 1
fi
# Init the TPM
-run_swtpm_ioctl "${SWTPM_INTERFACE}" -i
-if [ $? -ne 0 ]; then
+if ! run_swtpm_ioctl "${SWTPM_INTERFACE}" -i; then
echo "Error: Could not initialize the ${SWTPM_INTERFACE} TPM."
exit 1
fi
-kill_quiet -0 "${SWTPM_PID}" 2>/dev/null
-if [ $? -ne 0 ]; then
+if ! kill_quiet -0 "${SWTPM_PID}" 2>/dev/null; then
echo "Error: ${SWTPM_INTERFACE} TPM not running anymore after INIT."
exit 1
fi
@@ -64,8 +61,7 @@
exit 1
fi
-run_swtpm_ioctl "${SWTPM_INTERFACE}" -h 1234
-if [ $? -ne 0 ]; then
+if ! run_swtpm_ioctl "${SWTPM_INTERFACE}" -h 1234; then
echo "Error: Hash command did not work."
exit 1
fi
@@ -91,8 +87,7 @@
fi
# Save the volatile state
-run_swtpm_ioctl "${SWTPM_INTERFACE}" -v
-if [ $? -ne 0 ]; then
+if ! run_swtpm_ioctl "${SWTPM_INTERFACE}" -v; then
echo "Error: Could not have the ${SWTPM_INTERFACE} TPM store the volatile state to a file."
exit 1
fi
@@ -103,8 +98,7 @@
fi
# Shut the TPM down
-run_swtpm_ioctl "${SWTPM_INTERFACE}" -s
-if [ $? -ne 0 ]; then
+if ! run_swtpm_ioctl "${SWTPM_INTERFACE}" -s; then
echo "Error: Could not shut down the ${SWTPM_INTERFACE} TPM."
exit 1
fi
@@ -114,15 +108,13 @@
display_processes_by_name "$SWTPM"
-kill_quiet -0 "${SWTPM_PID}"
-if [ $? -ne 0 ]; then
+if ! kill_quiet -0 "${SWTPM_PID}"; then
echo "Error: ${SWTPM_INTERFACE} TPM did not start."
exit 1
fi
# Init the TPM
-run_swtpm_ioctl "${SWTPM_INTERFACE}" -i
-if [ $? -ne 0 ]; then
+if ! run_swtpm_ioctl "${SWTPM_INTERFACE}" -i; then
echo "Error: Could not initialize the ${SWTPM_INTERFACE} TPM."
exit 1
fi
@@ -154,8 +146,7 @@
fi
# Save the volatile state again
-run_swtpm_ioctl "${SWTPM_INTERFACE}" -v
-if [ $? -ne 0 ]; then
+if ! run_swtpm_ioctl "${SWTPM_INTERFACE}" -v; then
echo "Error: Could not have the ${SWTPM_INTERFACE} TPM store the volatile state to a file."
exit 1
fi
@@ -166,8 +157,7 @@
fi
# Send a new TPM_Init
-run_swtpm_ioctl "${SWTPM_INTERFACE}" -i
-if [ $? -ne 0 ]; then
+if ! run_swtpm_ioctl "${SWTPM_INTERFACE}" -i; then
echo "Error: Could not initialize the ${SWTPM_INTERFACE} TPM."
exit 1
fi
@@ -189,8 +179,7 @@
fi
# Check that the TPM Established bit is still set
-RES=$(run_swtpm_ioctl "${SWTPM_INTERFACE}" -e)
-if [ $? -ne 0 ]; then
+if ! RES=$(run_swtpm_ioctl "${SWTPM_INTERFACE}" -e); then
echo "Error: Could not get the TPM Established flag from the ${SWTPM_INTERFACE} TPM."
exit 1
fi
@@ -203,8 +192,7 @@
fi
# Final shut down
-run_swtpm_ioctl "${SWTPM_INTERFACE}" -s
-if [ $? -ne 0 ]; then
+if ! run_swtpm_ioctl "${SWTPM_INTERFACE}" -s; then
echo "Error: Could not shut down the ${SWTPM_INTERFACE} TPM."
exit 1
fi
diff --git a/tests/_test_wrongorder b/tests/_test_wrongorder
index 2444e74..569d142 100755
--- a/tests/_test_wrongorder
+++ b/tests/_test_wrongorder
@@ -37,15 +37,13 @@
display_processes_by_name "$SWTPM"
-kill_quiet -0 "${SWTPM_PID}"
-if [ $? -ne 0 ]; then
+if ! kill_quiet -0 "${SWTPM_PID}"; then
echo "Error: ${SWTPM_INTERFACE} TPM did not start."
exit 1
fi
if [ "${SWTPM_INTERFACE}" != "cuse" ]; then
- run_swtpm_ioctl "${SWTPM_INTERFACE}" --stop
- if [ $? -ne 0 ]; then
+ if ! run_swtpm_ioctl "${SWTPM_INTERFACE}" --stop; then
echo "Error: Could not stop the ${SWTPM_INTERFACE} TPM"
exit 1
fi
@@ -54,14 +52,12 @@
# Get the established bit before the TPM has been initialized
# This should not work
-run_swtpm_ioctl "${SWTPM_INTERFACE}" -e
-if [ $? -eq 0 ]; then
+if run_swtpm_ioctl "${SWTPM_INTERFACE}" -e; then
echo "Error: Could get established bit from ${SWTPM_INTERFACE} TPM before init."
exit 1
fi
-kill_quiet -0 "${SWTPM_PID}"
-if [ $? -ne 0 ]; then
+if ! kill_quiet -0 "${SWTPM_PID}"; then
echo "Error: ${SWTPM_INTERFACE} TPM must have crashed."
exit 1
fi
@@ -76,27 +72,23 @@
exit 1
fi
-kill_quiet -0 "${SWTPM_PID}"
-if [ $? -ne 0 ]; then
+if ! kill_quiet -0 "${SWTPM_PID}"; then
echo "Error: ${SWTPM_INTERFACE} TPM must have crashed."
exit 1
fi
# Init the TPM
-run_swtpm_ioctl "${SWTPM_INTERFACE}" -i
-if [ $? -ne 0 ]; then
+if ! run_swtpm_ioctl "${SWTPM_INTERFACE}" -i; then
echo "Error: Could not initialize the ${SWTPM_INTERFACE} TPM."
exit 1
fi
-kill_quiet -0 "${SWTPM_PID}" 2>/dev/null
-if [ $? -ne 0 ]; then
+if ! kill_quiet -0 "${SWTPM_PID}" 2>/dev/null; then
echo "Error: ${SWTPM_INTERFACE} TPM not running anymore after INIT."
exit 1
fi
-run_swtpm_ioctl "${SWTPM_INTERFACE}" -s
-if [ $? -ne 0 ]; then
+if ! run_swtpm_ioctl "${SWTPM_INTERFACE}" -s; then
echo "Error: Could not shut down the ${SWTPM_INTERFACE} TPM."
exit 1
fi
diff --git a/tests/common b/tests/common
index a7c857c..5917466 100644
--- a/tests/common
+++ b/tests/common
@@ -171,8 +171,9 @@
local loops=$((timeout * 10)) loop
for ((loop=0; loop<loops; loop++)); do
- (exec 127<>"/dev/tcp/${host}/${port}") &>/dev/null
- [ $? -eq 0 ] && return 1
+ if (exec 127<>"/dev/tcp/${host}/${port}") &>/dev/null; then
+ return 1
+ fi
sleep 0.1
done
return 0
@@ -192,8 +193,9 @@
local loops=$((timeout * 10)) loop
for ((loop=0; loop<loops; loop++)); do
- (exec 127<>"/dev/tcp/${host}/${port}") &>/dev/null
- [ $? -eq 0 ] || return 1
+ if ! (exec 127<>"/dev/tcp/${host}/${port}") &>/dev/null; then
+ return 1
+ fi
sleep 0.1
done
return 0
diff --git a/tests/load_vtpm_proxy b/tests/load_vtpm_proxy
index 29d4e43..d192b69 100644
--- a/tests/load_vtpm_proxy
+++ b/tests/load_vtpm_proxy
@@ -3,8 +3,7 @@
# Some distros may not have the device
if [ ! -c /dev/vtpmx ]; then
- modprobe tpm_vtpm_proxy
- if [ $? -ne 0 ]; then
+ if ! modprobe tpm_vtpm_proxy; then
echo "Skipping test using vtpm proxy module: module not available"
exit 77
fi
diff --git a/tests/test_commandline b/tests/test_commandline
index f3c9f6c..12940fd 100755
--- a/tests/test_commandline
+++ b/tests/test_commandline
@@ -58,8 +58,7 @@
exit 1
fi
-kill_quiet -0 $PID
-if [ $? -ne 0 ]; then
+if ! kill_quiet -0 $PID; then
echo "Test 1 failed: TPM process not running"
exit 1
fi
@@ -71,8 +70,7 @@
validate_pidfile "$PID" "$PID_FILE"
-${SWTPM_BIOS} &>/dev/null
-if [ $? -ne 0 ]; then
+if ! ${SWTPM_BIOS} &>/dev/null; then
echo "Test 1 failed: ${SWTPM_BIOS} did not work"
exit 1
fi
@@ -132,8 +130,7 @@
exit 1
fi
-exec 100<>/dev/tcp/localhost/$PORT
-if [ $? -ne 0 ]; then
+if ! exec 100<>/dev/tcp/localhost/$PORT; then
echo "Test 2 failed: Could not connect to TPM"
exit 1
fi
@@ -196,8 +193,7 @@
exit 1
fi
-kill_quiet -0 "$PID"
-if [ $? -ne 0 ]; then
+if ! kill_quiet -0 "$PID"; then
echo "Test 4 failed: TPM process not running"
exit 1
fi
@@ -209,8 +205,7 @@
validate_pidfile "$PID" "$PID_FILE"
-${SWTPM_BIOS} &>/dev/null
-if [ $? -ne 0 ]; then
+if ! ${SWTPM_BIOS} &>/dev/null; then
echo "Test 4 failed: ${SWTPM_BIOS} did not work"
exit 1
fi
diff --git a/tests/test_ctrlchannel b/tests/test_ctrlchannel
index 1906b47..ec6d0c4 100755
--- a/tests/test_ctrlchannel
+++ b/tests/test_ctrlchannel
@@ -39,8 +39,7 @@
FOWNER=",uid=nobody,gid=$(id -Gn nobody | cut -d" " -f1)"
FILEOWNER="$(id -u nobody) $(id -G nobody | cut -d" " -f1)"
RUNAS="--runas nobody"
- chown nobody "$TPMDIR"
- if [ $? -ne 0 ]; then
+ if ! chown nobody "$TPMDIR"; then
echo "Error: Could not change ownership of $TPMDIR"
exit 1
fi
diff --git a/tests/test_ctrlchannel2 b/tests/test_ctrlchannel2
index 2a84720..bfc0b82 100755
--- a/tests/test_ctrlchannel2
+++ b/tests/test_ctrlchannel2
@@ -47,8 +47,7 @@
PID=$(cat "$PID_FILE")
# Get the capability bits: CMD_GET_CAPABILITY = 0x00 00 00 01
-act=$($SWTPM_IOCTL --unix "$SOCK_PATH" -c 2>&1)
-if [ $? -ne 0 ]; then
+if ! act=$($SWTPM_IOCTL --unix "$SOCK_PATH" -c 2>&1); then
echo "Error: $SWTPM_IOCTL CMD_GET_CAPABILITY failed: $act"
exit 1
fi
@@ -60,15 +59,13 @@
fi
# Send TPM_Init to the TPM: CMD_INIT = 0x00 00 00 02 + flags
-act=$($SWTPM_IOCTL --unix "$SOCK_PATH" -i 2>&1)
-if [ $? -ne 0 ]; then
+if ! act=$($SWTPM_IOCTL --unix "$SOCK_PATH" -i 2>&1); then
echo "Error: $SWTPM_IOCTL CMD_INIT failed: $act"
exit 1
fi
# Save the volatile state: CMD_STORE_VOLATILE = 0x00 00 00 0a
-act=$($SWTPM_IOCTL --unix "$SOCK_PATH" -v 2>&1)
-if [ $? -ne 0 ]; then
+if ! act=$($SWTPM_IOCTL --unix "$SOCK_PATH" -v 2>&1); then
echo "Error: $SWTPM_IOCTL CMD_STORE_VOLATILE failed: $act"
exit 1
fi
@@ -79,15 +76,13 @@
fi
# Send stop command to the TPM: CMD_STOP = 00 00 00 0e
-act=$($SWTPM_IOCTL --unix "$SOCK_PATH" --stop 2>&1)
-if [ $? -ne 0 ]; then
+if ! act=$($SWTPM_IOCTL --unix "$SOCK_PATH" --stop 2>&1); then
echo "Error: $SWTPM_IOCTL CMD_STOP failed: $act"
exit 1
fi
# Send get config command to the TPM: CMD_GET_CONFIG = 00 00 00 0f
-act=$($SWTPM_IOCTL --unix "$SOCK_PATH" -g 2>&1)
-if [ $? -ne 0 ]; then
+if ! act=$($SWTPM_IOCTL --unix "$SOCK_PATH" -g 2>&1); then
echo "Error: $SWTPM_IOCTL CMD_GET_CONFIG failed: $act"
exit 1
fi
@@ -99,8 +94,7 @@
fi
# Send shutdown command to the TPM: CMD_SHUTDOWN = 00 00 00 03
-act=$($SWTPM_IOCTL --unix "$SOCK_PATH" -s 2>&1)
-if [ $? -ne 0 ]; then
+if ! act=$($SWTPM_IOCTL --unix "$SOCK_PATH" -s 2>&1); then
echo "Error: $SWTPM_IOCTL CMD_SHUTDOWN failed: $act"
exit 1
fi
@@ -146,8 +140,7 @@
validate_pidfile "$PID" "$PID_FILE"
# Get the capability bits: CMD_GET_CAPABILITY = 0x00 00 00 01
-act=$($SWTPM_IOCTL --unix "$SOCK_PATH" -c 2>&1)
-if [ $? -ne 0 ]; then
+if ! act=$($SWTPM_IOCTL --unix "$SOCK_PATH" -c 2>&1); then
echo "Error: $SWTPM_IOCTL CMD_GET_CAPABILITY failed: $act"
exit 1
fi
@@ -159,22 +152,19 @@
fi
# Send TPM_Init to the TPM: CMD_INIT = 0x00 00 00 02 + flags
-act=$($SWTPM_IOCTL --unix "$SOCK_PATH" -i 2>&1)
-if [ $? -ne 0 ]; then
+if ! act=$($SWTPM_IOCTL --unix "$SOCK_PATH" -i 2>&1); then
echo "Error: $SWTPM_IOCTL CMD_INIT failed: $act"
exit 1
fi
# Startup the TPM
-msg=$($SWTPM_BIOS --tcp ${BINDADDR}:65431 -o 2>&1)
-if [ $? -ne 0 ]; then
+if ! msg=$($SWTPM_BIOS --tcp ${BINDADDR}:65431 -o 2>&1); then
echo "Error: Failed to startup TPM: $msg"
exit 1
fi
# Save the volatile state: CMD_STORE_VOLATILE = 0x00 00 00 0a
-act=$($SWTPM_IOCTL --unix "$SOCK_PATH" -v 2>&1)
-if [ $? -ne 0 ]; then
+if ! act=$($SWTPM_IOCTL --unix "$SOCK_PATH" -v 2>&1); then
echo "Error: $SWTPM_IOCTL CMD_STORE_VOLATILE failed: $act"
exit 1
fi
@@ -185,8 +175,7 @@
fi
# 1. Send command to get TPM established flag: CMD_GET_TPMESTABLISHED = 00 00 00 04
-act=$($SWTPM_IOCTL --unix "$SOCK_PATH" -e 2>&1)
-if [ $? -ne 0 ]; then
+if ! act=$($SWTPM_IOCTL --unix "$SOCK_PATH" -e 2>&1); then
echo "Error: $SWTPM_IOCTL CMD_GET_TPMESTABLISHED failed: $act"
exit 1
fi
@@ -202,15 +191,13 @@
while [ ${#data} -lt $((0x2000)) ]; do
data="${data}${data}"
done
-act=$($SWTPM_IOCTL --unix "$SOCK_PATH" -h $data 2>&1)
-if [ $? -ne 0 ]; then
+if ! act=$($SWTPM_IOCTL --unix "$SOCK_PATH" -h $data 2>&1); then
echo "Error: $SWTPM_IOCTL data hashing failed: $act"
exit 1
fi
# 3. Send command to get TPM established flag: CMD_GET_TPMESTABLISHED = 00 00 00 04
-act=$($SWTPM_IOCTL --unix "$SOCK_PATH" -e 2>&1)
-if [ $? -ne 0 ]; then
+if ! act=$($SWTPM_IOCTL --unix "$SOCK_PATH" -e 2>&1); then
echo "Error: $SWTPM_IOCTL CMD_GET_TPMESTABLISHED failed: $act"
exit 1
fi
@@ -222,15 +209,13 @@
fi
# 4. Send command to reset TPM established flag: CMD_RESET_TPMESTABLISHED = 00 00 00 0b 03
-act=$($SWTPM_IOCTL --unix "$SOCK_PATH" -r 3 2>&1)
-if [ $? -ne 0 ]; then
+if ! act=$($SWTPM_IOCTL --unix "$SOCK_PATH" -r 3 2>&1); then
echo "Error: $SWTPM_IOCTL CMD_RESET_TPMESTABLISHED failed: $act"
exit 1
fi
# 5. Send command to get TPM established flag: CMD_GET_TPMESTABLISHED = 00 00 00 04
-act=$($SWTPM_IOCTL --unix "$SOCK_PATH" -e 2>&1)
-if [ $? -ne 0 ]; then
+if ! act=$($SWTPM_IOCTL --unix "$SOCK_PATH" -e 2>&1); then
echo "Error: $SWTPM_IOCTL CMD_GET_TPMESTABLISHED failed: $act"
exit 1
fi
@@ -254,15 +239,13 @@
fi
# Get the volatile state of the TPM: CMD_GET_STATEBLOB = 00 00 00 0c
-act=$($SWTPM_IOCTL --unix "$SOCK_PATH" --save volatile "$VOLATILESTATE" 2>&1)
-if [ $? -ne 0 ]; then
+if ! act=$($SWTPM_IOCTL --unix "$SOCK_PATH" --save volatile "$VOLATILESTATE" 2>&1); then
echo "Error: $SWTPM_IOCTL CMD_GET_STATEBLOB failed: $act"
exit 1
fi
# Send stop command to the TPM: CMD_STOP = 00 00 00 0e
-act=$($SWTPM_IOCTL --unix "$SOCK_PATH" --stop 2>&1)
-if [ $? -ne 0 ]; then
+if ! act=$($SWTPM_IOCTL --unix "$SOCK_PATH" --stop 2>&1); then
echo "Error: $SWTPM_IOCTL CMD_STOP failed: $act"
exit 1
fi
@@ -280,8 +263,7 @@
fi
# Send get config command to the TPM: CMD_GET_CONFIG = 00 00 00 0f
-act=$($SWTPM_IOCTL --unix "$SOCK_PATH" -g 2>&1)
-if [ $? -ne 0 ]; then
+if ! act=$($SWTPM_IOCTL --unix "$SOCK_PATH" -g 2>&1); then
echo "Error: $SWTPM_IOCTL CMD_GET_CONFIG failed: $act"
exit 1
fi
@@ -293,8 +275,7 @@
fi
# Send shutdown command to the TPM: CMD_SHUTDOWN = 00 00 00 03
-act=$($SWTPM_IOCTL --unix "$SOCK_PATH" -s 2>&1)
-if [ $? -ne 0 ]; then
+if ! act=$($SWTPM_IOCTL --unix "$SOCK_PATH" -s 2>&1); then
echo "Error: $SWTPM_IOCTL CMD_SHUTDOWN failed: $act"
exit 1
fi
@@ -347,15 +328,13 @@
# Get the volatile state of the TPM: CMD_GET_STATEBLOB = 00 00 00 0c
rm -f "$VOLATILESTATE"
-act=$($SWTPM_IOCTL --unix "$SOCK_PATH" --save volatile "$VOLATILESTATE" 2>&1)
-if [ $? -ne 0 ]; then
+if ! act=$($SWTPM_IOCTL --unix "$SOCK_PATH" --save volatile "$VOLATILESTATE" 2>&1); then
echo "Error: $SWTPM_IOCTL CMD_GET_STATEBLOB failed: $act"
exit 1
fi
# Send shutdown command to the TPM: CMD_SHUTDOWN = 00 00 00 03
-act=$($SWTPM_IOCTL --unix "$SOCK_PATH" -s 2>&1)
-if [ $? -ne 0 ]; then
+if ! act=$($SWTPM_IOCTL --unix "$SOCK_PATH" -s 2>&1); then
echo "Error: $SWTPM_IOCTL CMD_SHUTDOWN failed: $act"
exit 1
fi
@@ -403,23 +382,19 @@
fi
# Send stop command to the TPM: CMD_STOP = 00 00 00 0e
-act=$($SWTPM_IOCTL --unix "$SOCK_PATH" --stop 2>&1)
-if [ $? -ne 0 ]; then
+if ! act=$($SWTPM_IOCTL --unix "$SOCK_PATH" --stop 2>&1); then
echo "Error: $SWTPM_IOCTL CMD_STOP failed: $act"
exit 1
fi
# Send the volatile state to the TPM (while it is stopped)
-$SWTPM_IOCTL --unix "$SOCK_PATH" --load volatile "$VOLATILESTATE"
-#act=$($SWTPM_IOCTL --unix "$SOCK_PATH" --load volatile "$VOLATILESTATE" 2>&1)
-if [ $? -ne 0 ]; then
+if ! act=$($SWTPM_IOCTL --unix "$SOCK_PATH" --load volatile "$VOLATILESTATE" 2>&1); then
echo "Error: $SWTPM_IOCTL CMD_SET_STATEBLOB failed: $act"
exit 1
fi
# Send init command to the TPM: CMD_INIT = 00 00 00 02
-act=$($SWTPM_IOCTL --unix "$SOCK_PATH" -i 2>&1)
-if [ $? -ne 0 ]; then
+if ! act=$($SWTPM_IOCTL --unix "$SOCK_PATH" -i 2>&1); then
echo "Error: $SWTPM_IOCTL CMD_INIT failed: $act"
exit 1
fi
@@ -451,8 +426,7 @@
# In locality 2 we can reset PCR 20
# Set the locality on the TPM: CMD_SET_LOCALITY = 00 00 00 05 <locality>
-act=$($SWTPM_IOCTL --unix "$SOCK_PATH" -l 2 2>&1)
-if [ $? -ne 0 ]; then
+if ! act=$($SWTPM_IOCTL --unix "$SOCK_PATH" -l 2 2>&1); then
echo "Error: $SWTPM_IOCTL CMD_SET_LOCALITY failed: $act"
exit 1
fi
@@ -470,8 +444,7 @@
fi
# Send shutdown command to the TPM: CMD_SHUTDOWN = 00 00 00 03
-act=$($SWTPM_IOCTL --unix "$SOCK_PATH" -s 2>&1)
-if [ $? -ne 0 ]; then
+if ! act=$($SWTPM_IOCTL --unix "$SOCK_PATH" -s 2>&1); then
echo "Error: $SWTPM_IOCTL CMD_SHUTDOWN failed: $act"
exit 1
fi
diff --git a/tests/test_cuse b/tests/test_cuse
index d4af576..95f0fcc 100644
--- a/tests/test_cuse
+++ b/tests/test_cuse
@@ -18,8 +18,7 @@
fi
if [ ! -c /dev/cuse ]; then
- modprobe cuse
- if [ $? -ne 0 ]; then
+ if ! modprobe cuse; then
echo "Skipping test using CUSE module: module not availabe"
exit 77
fi
diff --git a/tests/test_parameters b/tests/test_parameters
index 4619d58..453dffb 100755
--- a/tests/test_parameters
+++ b/tests/test_parameters
@@ -89,12 +89,11 @@
rm -rf "$TPMDIR"/*
echo -n "Test $i: "
params=${PARAMETERS[$i]}
- $TPMAUTHORING \
+ if ! $TPMAUTHORING \
--tpm-state "$TPMDIR" \
--tpm "$SWTPM_EXE socket ${SWTPM_TEST_SECCOMP_OPT}" \
- ${params:+${params}} &>/dev/null
-
- if [ $? -ne 0 ]; then
+ ${params:+${params}} &>/dev/null;
+ then
echo "ERROR: Test with parameters '${params}' failed."
exit 1
elif [ ! -f "$TPMDIR/tpm-00.permall" ]; then
diff --git a/tests/test_samples_create_tpmca b/tests/test_samples_create_tpmca
index d649a91..abe2854 100755
--- a/tests/test_samples_create_tpmca
+++ b/tests/test_samples_create_tpmca
@@ -109,16 +109,14 @@
params="${params} --srkpass ${srk_password}"
# First setup the TPM and take ownership of it and set SRK password
- $SWTPM_SETUP \
+ if ! $SWTPM_SETUP \
--runas root \
--tpm-state "${workdir}" \
--logfile "${workdir}/logfile" \
--config "${workdir}/swtpm_setup.conf" \
--tpm "${SWTPM_EXE} socket ${SWTPM_TEST_SECCOMP_OPT}" \
--take-ownership \
- ${params:+${params}} >/dev/null
-
- if [ $? -ne 0 ]; then
+ ${params:+${params}} >/dev/null; then
echo "Error: Could not run $SWTPM_SETUP."
echo "Setup Logfile:"
cat "${workdir}/logfile"
@@ -174,8 +172,7 @@
# wait for PID to be written
sleep 0.5
TCSD_PID=$(cat "${TCSD_PIDFILE}")
- kill_quiet -0 "${TCSD_PID}"
- if [ $? -ne 0 ]; then
+ if ! kill_quiet -0 "${TCSD_PID}"; then
# Try again with root unless we already tried
if [ "$TSS_USER" != "root" ]; then
TSS_USER="root"
@@ -187,15 +184,13 @@
break
done
- ${SWTPM_CREATE_TPMCA} \
+ if ! ${SWTPM_CREATE_TPMCA} \
--dir "${SWTPM_LOCALCA_DIR}" \
--srk-password "${srk_password}" \
--register \
--group "${TSS_GROUP}" \
--tss-tcsd-port "${TCSD_LISTEN_PORT}" \
- --outfile "${SWTPM_LOCALCA_CONF}" &>/dev/null
-
- if [ $? -ne 0 ]; then
+ --outfile "${SWTPM_LOCALCA_CONF}" &>/dev/null; then
echo "Error: Could not create TPM CA"
exit 1
fi
@@ -241,7 +236,7 @@
fi
# make sure we can actually sign with this new certificate
- ${SWTPM_LOCALCA} \
+ if ! ${SWTPM_LOCALCA} \
--type ek \
--ek x=739192d8f1004283957a7b1568d610b41c637ccc114aadcac4908c20456468fa,y=59f63ac06f8011f6fdd1460c6bc8e3e0a2d090d4fc188c7e04870e06795ce8ae \
--dir "${workdir}" --vmid test \
@@ -249,8 +244,7 @@
--tpm-spec-family 2.0 --tpm-spec-revision 146 --tpm-spec-level 00 \
--tpm-model swtpm --tpm-version 20170101 --tpm-manufacturer IBM \
--configfile "${SWTPM_LOCALCA_CONF}" \
- --optsfile /dev/null
- if [ $? -ne 0 ]; then
+ --optsfile /dev/null; then
echo "Error: The CA could not sign with the new certificate"
exit 1
fi
@@ -297,8 +291,7 @@
kill_quiet -15 "${TCSD_PID}"
# Shut down TPM
- run_swtpm_ioctl "${SWTPM_INTERFACE}" -s
- if [ $? -ne 0 ]; then
+ if ! run_swtpm_ioctl "${SWTPM_INTERFACE}" -s; then
echo "Error: Could not shut down the ${SWTPM_INTERFACE} TPM."
exit 1
fi
diff --git a/tests/test_swtpm_cert b/tests/test_swtpm_cert
index 5d1f38b..e719868 100755
--- a/tests/test_swtpm_cert
+++ b/tests/test_swtpm_cert
@@ -35,7 +35,7 @@
fi
}
-VARNAME=password ${SWTPM_CERT} \
+if ! VARNAME=password ${SWTPM_CERT} \
--signkey "${TESTDIR}/data/signkey-encrypted.pem" \
--signkey-pwd env:VARNAME \
--issuercert "${TESTDIR}/data/issuercert.pem" \
@@ -44,9 +44,7 @@
--days 3650 \
--pem \
--tpm-manufacturer IBM --tpm-model swtpm-libtpms --tpm-version 1.2 \
- --tpm-spec-family 1.2 --tpm-spec-revision 123 --tpm-spec-level 321
-
-if [ $? -ne 0 ]; then
+ --tpm-spec-family 1.2 --tpm-spec-revision 123 --tpm-spec-level 321; then
echo "Error: ${SWTPM_CERT} returned error code."
exit 1
fi
@@ -58,7 +56,7 @@
echo -n > "${cert}"
echo "Test 1: OK"
-${SWTPM_CERT} \
+if ! ${SWTPM_CERT} \
--signkey "${TESTDIR}/data/signkey-encrypted.pem" \
--signkey-pwd file:<(echo -en "password") \
--issuercert "${TESTDIR}/data/issuercert.pem" \
@@ -68,9 +66,7 @@
--subject "OU=foo,L=NewYork,ST=NY,C=US" \
--pem \
--tpm-manufacturer IBM --tpm-model swtpm-libtpms --tpm-version 1.2 \
- --tpm-spec-family 1.2 --tpm-spec-revision 123 --tpm-spec-level 321
-
-if [ $? -ne 0 ]; then
+ --tpm-spec-family 1.2 --tpm-spec-revision 123 --tpm-spec-level 321; then
echo "Error: ${SWTPM_CERT} returned error code."
exit 1
fi
@@ -82,7 +78,7 @@
echo -n > "${cert}"
echo "Test 2: OK"
-${SWTPM_CERT} \
+if ! ${SWTPM_CERT} \
--signkey "${TESTDIR}/data/signkey-encrypted.pem" \
--signkey-pwd pass:password \
--issuercert "${TESTDIR}/data/issuercert.pem" \
@@ -92,9 +88,7 @@
--subject "OU=foo,L=NewYork,ST=NY,C=US" \
--pem \
--tpm-manufacturer IBM --tpm-model swtpm-libtpms --tpm-version 1.2 \
- --tpm-spec-family 1.2 --tpm-spec-revision 123 --tpm-spec-level 321
-
-if [ $? -ne 0 ]; then
+ --tpm-spec-family 1.2 --tpm-spec-revision 123 --tpm-spec-level 321; then
echo "Error: ${SWTPM_CERT} returned error code."
exit 1
fi
@@ -112,7 +106,7 @@
echo -en "password" > "${pwdfile}"
exec 100<"${pwdfile}"
-${SWTPM_CERT} \
+if ! ${SWTPM_CERT} \
--type platform \
--signkey "${TESTDIR}/data/signkey-encrypted.pem" \
--signkey-pwd fd:100 \
@@ -125,9 +119,7 @@
--tpm-manufacturer IBM --tpm-model swtpm-libtpms --tpm-version 1.2 \
--platform-manufacturer Fedora \
--platform-model QEMU \
- --platform-version 2.1
-
-if [ $? -ne 0 ]; then
+ --platform-version 2.1; then
echo "Error: ${SWTPM_CERT} returned error code."
exit 1
fi
diff --git a/tests/test_swtpm_setup_create_cert b/tests/test_swtpm_setup_create_cert
index 48be3b6..1abb525 100755
--- a/tests/test_swtpm_setup_create_cert
+++ b/tests/test_swtpm_setup_create_cert
@@ -59,16 +59,14 @@
export SWTPM_ROOTCA_PASSWORD=password
# we need to create at least one cert: --create-ek-cert
-WORKDIR=${workdir} \
- $SWTPM_SETUP \
+if ! WORKDIR=${workdir} $SWTPM_SETUP \
--tpm-state "${workdir}" \
--create-ek-cert \
--config "${workdir}/swtpm_setup.conf" \
--logfile "${workdir}/logfile" \
--tpm "${SWTPM_EXE} socket ${SWTPM_TEST_SECCOMP_OPT}" \
- --write-ek-cert-files "${workdir}"
-
-if [ $? -ne 0 ]; then
+ --write-ek-cert-files "${workdir}";
+then
echo "Error: Could not run $SWTPM_SETUP."
echo "Setup Logfile:"
cat "${workdir}/logfile"
diff --git a/tests/test_swtpm_setup_file_backend b/tests/test_swtpm_setup_file_backend
index bc46b8f..35f82da 100755
--- a/tests/test_swtpm_setup_file_backend
+++ b/tests/test_swtpm_setup_file_backend
@@ -26,14 +26,13 @@
workdir="$(mktemp -d)" || exit 1
statefile="${workdir}/swtpm-test.state"
-$SWTPM_SETUP \
+if ! $SWTPM_SETUP \
--not-overwrite \
--tpm-state "file://${statefile}" \
--config "${SWTPM_SETUP_CONF}" \
--logfile "${workdir}/logfile" \
- --tpm "${SWTPM_EXE} socket ${SWTPM_TEST_SECCOMP_OPT}"
-
-if [ $? -ne 0 ]; then
+ --tpm "${SWTPM_EXE} socket ${SWTPM_TEST_SECCOMP_OPT}";
+then
echo "Test 1 failed: Error: Could not run $SWTPM_SETUP."
echo "Setup Logfile:"
cat "${workdir}/logfile"
@@ -56,14 +55,13 @@
statefile="${workdir}/swtpm-test.state"
cp "${state_save}" "${statefile}"
-$SWTPM_SETUP \
+if ! $SWTPM_SETUP \
--overwrite \
--tpm-state "file://${statefile}" \
--config "${SWTPM_SETUP_CONF}" \
--logfile "${workdir}/logfile" \
- --tpm "${SWTPM_EXE} socket ${SWTPM_TEST_SECCOMP_OPT}"
-
-if [ $? -ne 0 ]; then
+ --tpm "${SWTPM_EXE} socket ${SWTPM_TEST_SECCOMP_OPT}";
+then
echo "Test 2 failed: Error: Could not run $SWTPM_SETUP."
echo "Setup Logfile:"
cat "${workdir}/logfile"
diff --git a/tests/test_swtpm_setup_misc b/tests/test_swtpm_setup_misc
index 31d1762..bba4c27 100755
--- a/tests/test_swtpm_setup_misc
+++ b/tests/test_swtpm_setup_misc
@@ -23,10 +23,9 @@
FILES="swtpm-localca.conf swtpm-localca.options swtpm_setup.conf"
-XDG_CONFIG_HOME="${workdir}" ${SWTPM_SETUP} \
- --create-config-files 1>/dev/null
-
-if [ $? -ne 0 ]; then
+if ! XDG_CONFIG_HOME="${workdir}" ${SWTPM_SETUP} \
+ --create-config-files 1>/dev/null;
+then
echo "Error: Could not created config files (without parameters)"
exit 1
fi
@@ -41,10 +40,9 @@
exit 1
fi
-XDG_CONFIG_HOME="${workdir}" ${SWTPM_SETUP} \
- --create-config-files skip-if-exist 1>/dev/null
-
-if [ $? -ne 0 ]; then
+if ! XDG_CONFIG_HOME="${workdir}" ${SWTPM_SETUP} \
+ --create-config-files skip-if-exist 1>/dev/null;
+then
echo "Error: skip-if-exists should have exit'ed with 0."
exit 1
fi
@@ -54,10 +52,9 @@
workdir="$(mktemp -d)" || exit 1
-XDG_CONFIG_HOME="${workdir}" ${SWTPM_SETUP} \
- --create-config-files skip-if-exist 1>/dev/null
-
-if [ $? -ne 0 ]; then
+if ! XDG_CONFIG_HOME="${workdir}" ${SWTPM_SETUP} \
+ --create-config-files skip-if-exist 1>/dev/null;
+then
echo "Error: skip-if-exists should have exit'ed with 0."
exit 1
fi
diff --git a/tests/test_swtpm_setup_overwrite b/tests/test_swtpm_setup_overwrite
index 009ae4e..f311b16 100755
--- a/tests/test_swtpm_setup_overwrite
+++ b/tests/test_swtpm_setup_overwrite
@@ -26,14 +26,13 @@
dummydata="DUMMY"
echo "$dummydata" > "${statefile}"
-$SWTPM_SETUP \
+if ! $SWTPM_SETUP \
--not-overwrite \
--tpm-state "${workdir}" \
--config "${SWTPM_SETUP_CONF}" \
--logfile "${workdir}/logfile" \
- --tpm "${SWTPM_EXE} socket ${SWTPM_TEST_SECCOMP_OPT}"
-
-if [ $? -ne 0 ]; then
+ --tpm "${SWTPM_EXE} socket ${SWTPM_TEST_SECCOMP_OPT}";
+then
echo "Test 1 failed: Error: Could not run $SWTPM_SETUP."
echo "Setup Logfile:"
cat "${workdir}/logfile"
@@ -57,14 +56,13 @@
dummydata="DUMMY"
echo "$dummydata" > "${statefile}"
-$SWTPM_SETUP \
+if ! $SWTPM_SETUP \
--overwrite \
--tpm-state "${workdir}" \
--config "${SWTPM_SETUP_CONF}" \
--logfile "${workdir}/logfile" \
- --tpm "${SWTPM_EXE} socket ${SWTPM_TEST_SECCOMP_OPT}"
-
-if [ $? -ne 0 ]; then
+ --tpm "${SWTPM_EXE} socket ${SWTPM_TEST_SECCOMP_OPT}";
+then
echo "Test 2 failed: Error: Could not run $SWTPM_SETUP."
echo "Setup Logfile:"
cat "${workdir}/logfile"
diff --git a/tests/test_tpm12 b/tests/test_tpm12
index ea48647..4affb02 100755
--- a/tests/test_tpm12
+++ b/tests/test_tpm12
@@ -61,8 +61,7 @@
pushd "${WORKDIR}" &>/dev/null || exit 1
for ((i = 0; i < 3; i++)); do
- curl -sJOL https://sourceforge.net/projects/ibmswtpm/files/tpm4769tar.gz/download
- if [ $? -eq 0 ]; then
+ if curl -sJOL https://sourceforge.net/projects/ibmswtpm/files/tpm4769tar.gz/download; then
break
fi
# wait 3..10 seconds for a retry
@@ -78,8 +77,7 @@
pushd libtpm &>/dev/null || exit 1
-patch -p0 < "${TESTDIR}/patches/libtpm.patch"
-if [ $? -ne 0 ]; then
+if ! patch -p0 < "${TESTDIR}/patches/libtpm.patch"; then
echo "Error: Patching failed."
exit 1
fi
diff --git a/tests/test_tpm2_ctrlchannel2 b/tests/test_tpm2_ctrlchannel2
index f6e75c9..1e63065 100755
--- a/tests/test_tpm2_ctrlchannel2
+++ b/tests/test_tpm2_ctrlchannel2
@@ -36,8 +36,7 @@
fi
# make sure --print-capabiities exits with '0'
-msg=$($SWTPM_EXE chardev --print-capabilities 2>&1)
-if [ $? -ne 0 ]; then
+if ! msg=$($SWTPM_EXE chardev --print-capabilities 2>&1); then
echo "Error: swtpm chardev --print-capabilities failed"
echo "$msg"
exit 1
@@ -63,8 +62,7 @@
validate_pidfile "$PID" "$PID_FILE"
# Get the capability bits: CMD_GET_CAPABILITY = 0x00 00 00 01
-act=$($SWTPM_IOCTL --unix "$SOCK_PATH" -c 2>&1)
-if [ $? -ne 0 ]; then
+if ! act=$($SWTPM_IOCTL --unix "$SOCK_PATH" -c 2>&1); then
echo "Error: $SWTPM_IOCTL CMD_GET_CAPABILITY failed: $act"
exit 1
fi
@@ -92,15 +90,13 @@
fi
# Send TPM_Init to the TPM: CMD_INIT = 0x00 00 00 02 + flags
-act=$($SWTPM_IOCTL --unix "$SOCK_PATH" -i 2>&1)
-if [ $? -ne 0 ]; then
+if ! act=$($SWTPM_IOCTL --unix "$SOCK_PATH" -i 2>&1); then
echo "Error: $SWTPM_IOCTL CMD_INIT failed: $act"
exit 1
fi
# Save the volatile state: CMD_STORE_VOLATILE = 0x00 00 00 0a
-act=$($SWTPM_IOCTL --unix "$SOCK_PATH" -v 2>&1)
-if [ $? -ne 0 ]; then
+if ! act=$($SWTPM_IOCTL --unix "$SOCK_PATH" -v 2>&1); then
echo "Error: $SWTPM_IOCTL CMD_STORE_VOLATILE failed: $act"
exit 1
fi
@@ -111,15 +107,13 @@
fi
# Send stop command to the TPM: CMD_STOP = 00 00 00 0e
-act=$($SWTPM_IOCTL --unix "$SOCK_PATH" --stop 2>&1)
-if [ $? -ne 0 ]; then
+if ! act=$($SWTPM_IOCTL --unix "$SOCK_PATH" --stop 2>&1); then
echo "Error: $SWTPM_IOCTL CMD_STOP failed: $act"
exit 1
fi
# Send get config command to the TPM: CMD_GET_CONFIG = 00 00 00 0f
-act=$($SWTPM_IOCTL --unix "$SOCK_PATH" -g 2>&1)
-if [ $? -ne 0 ]; then
+if ! act=$($SWTPM_IOCTL --unix "$SOCK_PATH" -g 2>&1); then
echo "Error: $SWTPM_IOCTL CMD_GET_CONFIG failed: $act"
exit 1
fi
@@ -131,8 +125,7 @@
fi
# Send shutdown command to the TPM: CMD_SHUTDOWN = 00 00 00 03
-act=$($SWTPM_IOCTL --unix "$SOCK_PATH" -s 2>&1)
-if [ $? -ne 0 ]; then
+if ! act=$($SWTPM_IOCTL --unix "$SOCK_PATH" -s 2>&1); then
echo "Error: $SWTPM_IOCTL CMD_SHUTDOWN failed: $act"
exit 1
fi
@@ -175,8 +168,7 @@
exec 100<>/dev/tcp/localhost/65532
# Get the capability bits: CMD_GET_CAPABILITY = 0x00 00 00 01
-act=$($SWTPM_IOCTL --unix "$SOCK_PATH" -c 2>&1)
-if [ $? -ne 0 ]; then
+if ! act=$($SWTPM_IOCTL --unix "$SOCK_PATH" -c 2>&1); then
echo "Error: $SWTPM_IOCTL CMD_GET_CAPABILITY failed: $act"
exit 1
fi
@@ -199,8 +191,7 @@
fi
# Save the volatile state: CMD_STORE_VOLATILE = 0x00 00 00 0a
-act=$($SWTPM_IOCTL --unix "$SOCK_PATH" -v 2>&1)
-if [ $? -ne 0 ]; then
+if ! act=$($SWTPM_IOCTL --unix "$SOCK_PATH" -v 2>&1); then
echo "Error: $SWTPM_IOCTL CMD_STORE_VOLATILE failed: $act"
exit 1
fi
@@ -211,8 +202,7 @@
fi
# 1. Send command to get TPM established flag: CMD_GET_TPMESTABLISHED = 00 00 00 04
-act=$($SWTPM_IOCTL --unix "$SOCK_PATH" -e 2>&1)
-if [ $? -ne 0 ]; then
+if ! act=$($SWTPM_IOCTL --unix "$SOCK_PATH" -e 2>&1); then
echo "Error: $SWTPM_IOCTL CMD_GET_TPMESTABLISHED failed: $act"
exit 1
fi
@@ -228,15 +218,13 @@
while [ ${#data} -lt $((0x2000)) ]; do
data="${data}${data}"
done
-act=$($SWTPM_IOCTL --unix "$SOCK_PATH" -h $data 2>&1)
-if [ $? -ne 0 ]; then
+if ! act=$($SWTPM_IOCTL --unix "$SOCK_PATH" -h $data 2>&1); then
echo "Error: $SWTPM_IOCTL data hashing failed: $act"
exit 1
fi
# 3. Send command to get TPM established flag: CMD_GET_TPMESTABLISHED = 00 00 00 04
-act=$($SWTPM_IOCTL --unix "$SOCK_PATH" -e 2>&1)
-if [ $? -ne 0 ]; then
+if ! act=$($SWTPM_IOCTL --unix "$SOCK_PATH" -e 2>&1); then
echo "Error: $SWTPM_IOCTL CMD_GET_TPMESTABLISHED failed: $act"
exit 1
fi
@@ -248,15 +236,13 @@
fi
# 4. Send command to reset TPM established flag: CMD_RESET_TPMESTABLISHED = 00 00 00 0b 03
-act=$($SWTPM_IOCTL --unix "$SOCK_PATH" -r 3 2>&1)
-if [ $? -ne 0 ]; then
+if ! act=$($SWTPM_IOCTL --unix "$SOCK_PATH" -r 3 2>&1); then
echo "Error: $SWTPM_IOCTL CMD_RESET_TPMESTABLISHED failed: $act"
exit 1
fi
# 5. Send command to get TPM established flag: CMD_GET_TPMESTABLISHED = 00 00 00 04
-act=$($SWTPM_IOCTL --unix "$SOCK_PATH" -e 2>&1)
-if [ $? -ne 0 ]; then
+if ! act=$($SWTPM_IOCTL --unix "$SOCK_PATH" -e 2>&1); then
echo "Error: $SWTPM_IOCTL CMD_GET_TPMESTABLISHED failed: $act"
exit 1
fi
@@ -281,15 +267,13 @@
fi
# Get the volatile state of the TPM: CMD_GET_STATEBLOB = 00 00 00 0c
-act=$($SWTPM_IOCTL --unix "$SOCK_PATH" --save volatile "$VOLATILESTATE" 2>&1)
-if [ $? -ne 0 ]; then
+if ! act=$($SWTPM_IOCTL --unix "$SOCK_PATH" --save volatile "$VOLATILESTATE" 2>&1); then
echo "Error: $SWTPM_IOCTL CMD_GET_STATEBLOB failed: $act"
exit 1
fi
# Send stop command to the TPM: CMD_STOP = 00 00 00 0e
-act=$($SWTPM_IOCTL --unix "$SOCK_PATH" --stop 2>&1)
-if [ $? -ne 0 ]; then
+if ! act=$($SWTPM_IOCTL --unix "$SOCK_PATH" --stop 2>&1); then
echo "Error: $SWTPM_IOCTL CMD_STOP failed: $act"
exit 1
fi
@@ -308,8 +292,7 @@
fi
# Send get config command to the TPM: CMD_GET_CONFIG = 00 00 00 0f
-act=$($SWTPM_IOCTL --unix "$SOCK_PATH" -g 2>&1)
-if [ $? -ne 0 ]; then
+if ! act=$($SWTPM_IOCTL --unix "$SOCK_PATH" -g 2>&1); then
echo "Error: $SWTPM_IOCTL CMD_GET_CONFIG failed: $act"
exit 1
fi
@@ -321,8 +304,7 @@
fi
# Send shutdown command to the TPM: CMD_SHUTDOWN = 00 00 00 03
-act=$($SWTPM_IOCTL --unix "$SOCK_PATH" -s 2>&1)
-if [ $? -ne 0 ]; then
+if ! act=$($SWTPM_IOCTL --unix "$SOCK_PATH" -s 2>&1); then
echo "Error: $SWTPM_IOCTL CMD_SHUTDOWN failed: $act"
exit 1
fi
@@ -377,15 +359,13 @@
# Get the volatile state of the TPM: CMD_GET_STATEBLOB = 00 00 00 0c
rm -f "$VOLATILESTATE"
-act=$($SWTPM_IOCTL --unix "$SOCK_PATH" --save volatile "$VOLATILESTATE" 2>&1)
-if [ $? -ne 0 ]; then
+if ! act=$($SWTPM_IOCTL --unix "$SOCK_PATH" --save volatile "$VOLATILESTATE" 2>&1); then
echo "Error: $SWTPM_IOCTL CMD_GET_STATEBLOB failed: $act"
exit 1
fi
# Send shutdown command to the TPM: CMD_SHUTDOWN = 00 00 00 03
-act=$($SWTPM_IOCTL --unix "$SOCK_PATH" -s 2>&1)
-if [ $? -ne 0 ]; then
+if ! act=$($SWTPM_IOCTL --unix "$SOCK_PATH" -s 2>&1); then
echo "Error: $SWTPM_IOCTL CMD_SHUTDOWN failed: $act"
exit 1
fi
@@ -435,22 +415,19 @@
fi
# Send stop command to the TPM: CMD_STOP = 00 00 00 0e
-act=$($SWTPM_IOCTL --unix "$SOCK_PATH" --stop 2>&1)
-if [ $? -ne 0 ]; then
+if ! act=$($SWTPM_IOCTL --unix "$SOCK_PATH" --stop 2>&1); then
echo "Error: $SWTPM_IOCTL CMD_STOP failed: $act"
exit 1
fi
# Send the volatile state to the TPM (while it is stopped)
-act=$($SWTPM_IOCTL --unix "$SOCK_PATH" --load volatile "$VOLATILESTATE" 2>&1)
-if [ $? -ne 0 ]; then
+if ! act=$($SWTPM_IOCTL --unix "$SOCK_PATH" --load volatile "$VOLATILESTATE" 2>&1); then
echo "Error: $SWTPM_IOCTL CMD_SET_STATEBLOB failed: $act"
exit 1
fi
# Send init command to the TPM: CMD_INIT = 00 00 00 02
-act=$($SWTPM_IOCTL --unix "$SOCK_PATH" -i 2>&1)
-if [ $? -ne 0 ]; then
+if ! act=$($SWTPM_IOCTL --unix "$SOCK_PATH" -i 2>&1); then
echo "Error: $SWTPM_IOCTL CMD_INIT failed: $act"
exit 1
fi
@@ -482,8 +459,7 @@
# In locality 2 we can reset PCR 20
# Set the locality on the TPM: CMD_SET_LOCALITY = 00 00 00 05 <locality>
-act=$($SWTPM_IOCTL --unix "$SOCK_PATH" -l 2 2>&1)
-if [ $? -ne 0 ]; then
+if ! act=$($SWTPM_IOCTL --unix "$SOCK_PATH" -l 2 2>&1); then
echo "Error: $SWTPM_IOCTL CMD_SET_LOCALITY failed: $act"
exit 1
fi
@@ -501,8 +477,7 @@
fi
# Send shutdown command to the TPM: CMD_SHUTDOWN = 00 00 00 03
-act=$($SWTPM_IOCTL --unix "$SOCK_PATH" -s 2>&1)
-if [ $? -ne 0 ]; then
+if ! act=$($SWTPM_IOCTL --unix "$SOCK_PATH" -s 2>&1); then
echo "Error: $SWTPM_IOCTL CMD_SHUTDOWN failed: $act"
exit 1
fi
diff --git a/tests/test_tpm2_ibmtss2 b/tests/test_tpm2_ibmtss2
index 569c3b1..d4b4393 100755
--- a/tests/test_tpm2_ibmtss2
+++ b/tests/test_tpm2_ibmtss2
@@ -50,8 +50,7 @@
pushd ibmtpm20tss-tss &>/dev/null || exit 1
-git checkout tags/v1.6.0
-if [ $? -ne 0 ]; then
+if ! git checkout tags/v1.6.0; then
echo "'Git checkout' failed."
exit 1
fi
@@ -117,8 +116,7 @@
export SWTPM_IOCTL
-./startup
-if [ $? -ne 0 ]; then
+if ! ./startup; then
echo "Startup of TPM2 failed"
exit 1
fi
@@ -134,8 +132,7 @@
fi
# Shut down
-run_swtpm_ioctl "${SWTPM_INTERFACE}" -s
-if [ $? -ne 0 ]; then
+if ! run_swtpm_ioctl "${SWTPM_INTERFACE}" -s; then
echo "Error: Could not shut down the ${SWTPM_INTERFACE} TPM."
ret=1
fi
diff --git a/tests/test_tpm2_parameters b/tests/test_tpm2_parameters
index 0d3da9b..afbfb85 100755
--- a/tests/test_tpm2_parameters
+++ b/tests/test_tpm2_parameters
@@ -94,12 +94,11 @@
rm -rf "$TPMDIR"/*
echo -n "Test $i: "
params=${PARAMETERS[$i]}
- $TPMAUTHORING \
+ if ! $TPMAUTHORING \
--tpm-state "$TPMDIR" \
--tpm "$SWTPM_EXE socket ${SWTPM_TEST_SECCOMP_OPT}" \
- ${params:+${params}} &>/dev/null
-
- if [ $? -ne 0 ]; then
+ ${params:+${params}} &>/dev/null;
+ then
echo "ERROR: Test with parameters '${params}' failed."
exit 1
elif [ ! -f "$TPMDIR/tpm2-00.permall" ]; then
diff --git a/tests/test_tpm2_partial_reads b/tests/test_tpm2_partial_reads
index 2fb2bfe..b0ed3e8 100755
--- a/tests/test_tpm2_partial_reads
+++ b/tests/test_tpm2_partial_reads
@@ -39,21 +39,18 @@
TPM_PATH=$TPM_PATH run_swtpm "${SWTPM_INTERFACE}" --tpm2
-kill_quiet -0 "${SWTPM_PID}"
-if [ $? -ne 0 ]; then
+if ! kill_quiet -0 "${SWTPM_PID}"; then
echo "Error: ${SWTPM_INTERFACE} TPM did not start."
exit 1
fi
# Init the TPM
-run_swtpm_ioctl "${SWTPM_INTERFACE}" -i
-if [ $? -ne 0 ]; then
+if ! run_swtpm_ioctl "${SWTPM_INTERFACE}" -i; then
echo "Error: Could not initialize the ${SWTPM_INTERFACE} TPM."
exit 1
fi
-kill_quiet -0 "${SWTPM_PID}" 2>/dev/null
-if [ $? -ne 0 ]; then
+if ! kill_quiet -0 "${SWTPM_PID}" 2>/dev/null; then
echo "Error: ${SWTPM_INTERFACE} TPM not running anymore after INIT."
exit 1
fi
@@ -130,8 +127,7 @@
fi
exec 100>&-
-run_swtpm_ioctl "${SWTPM_INTERFACE}" -s
-if [ $? -ne 0 ]; then
+if ! run_swtpm_ioctl "${SWTPM_INTERFACE}" -s; then
echo "Error: Could not shut down the ${SWTPM_INTERFACE} TPM."
exit 1
fi
diff --git a/tests/test_tpm2_samples_create_tpmca.test b/tests/test_tpm2_samples_create_tpmca.test
index 27bd4c8..9797a0b 100755
--- a/tests/test_tpm2_samples_create_tpmca.test
+++ b/tests/test_tpm2_samples_create_tpmca.test
@@ -123,6 +123,7 @@
ncat -l ${SWTPM_FAKE_CTRL_PORT} \
-k -c "xargs --null -n1 printf '\x00\x00\x00\x00' 2>/dev/null" &
+ # shellcheck disable=SC2181
if [ $? -ne 0 ]; then
echo "Could not start ncat"
exit 1
diff --git a/tests/test_tpm2_save_load_state_2 b/tests/test_tpm2_save_load_state_2
index 6263f7d..29a9568 100755
--- a/tests/test_tpm2_save_load_state_2
+++ b/tests/test_tpm2_save_load_state_2
@@ -8,14 +8,12 @@
exit 77
fi
-type -p nvdefinespace startup &>/dev/null
-if [ $? -ne 0 ]; then
- PREFIX=tss
- type -p ${PREFIX}nvdefinespace ${PREFIX}startup
-fi
-if [ $? -ne 0 ]; then
- echo "Could not find TPM2 tools (e.g., (tss)startup, (tss)nvdefinespace) in PATH."
- exit 77
+if ! type -p nvdefinespace startup &>/dev/null; then
+ PREFIX=tss
+ if ! type -p ${PREFIX}nvdefinespace ${PREFIX}startup; then
+ echo "Could not find TPM2 tools (e.g., (tss)startup, (tss)nvdefinespace) in PATH."
+ exit 77
+ fi
fi
TOOLSPATH=$(dirname "$(type -P "${PREFIX}startup")")
@@ -72,8 +70,7 @@
if [ "$create" -eq 1 ]; then
# Fill up the NVRAM space with RSA 2048 keys;
# exactly 65 have to fit
- "${TOOLSPATH}/${PREFIX}createprimary" -hi o -si > "$TMPFILE"
- if [ $? -ne 0 ]; then
+ if ! "${TOOLSPATH}/${PREFIX}createprimary" -hi o -si > "$TMPFILE"; then
echo "Error: createprimary failed."
exit 1
fi
@@ -90,8 +87,7 @@
"${TOOLSPATH}/${PREFIX}getcapability" -cap 1 -pr 81000000 -pc 80 > "$TMPFILE"
# We need know we need to see '65 Handles' for state created with
# libtpms-0.6.0 and 128kb NVRAM size
- grep -i "65 Handles" "$TMPFILE"
- if [ $? -ne 0 ]; then
+ if ! grep -i "65 Handles" "$TMPFILE"; then
echo "Error: Did not find '65 Handles' keyword in output"
cat "$TMPFILE"
exit 1
@@ -114,11 +110,11 @@
if [ "$sz" -gt 0 ]; then
sz=$((sz - 1))
echo "Creating final space of size ${sz}"
- "${TOOLSPATH}/${PREFIX}nvdefinespace" \
+ if ! "${TOOLSPATH}/${PREFIX}nvdefinespace" \
-hi o \
-ha 01000000 \
- -sz ${sz} > "${TMPFILE}"
- if [ $? -ne 0 ]; then
+ -sz ${sz} > "${TMPFILE}";
+ then
echo "Error: Could not create final NVRAM space."
cat "${TMPFILE}"
exit 1
@@ -138,11 +134,11 @@
fi
echo -n "123" > "$BINFILE"
- "${TOOLSPATH}/${PREFIX}sign" \
+ if ! "${TOOLSPATH}/${PREFIX}sign" \
-hk 81000000 \
-if "${BINFILE}" \
- -os "${SIGFILE}" > "$TMPFILE"
- if [ $? -ne 0 ]; then
+ -os "${SIGFILE}" > "$TMPFILE";
+ then
echo "Error: Could not create signature."
cat "$TMPFILE"
exit 1
@@ -153,8 +149,7 @@
"${TOOLSPATH}/${PREFIX}getcapability" -cap 1 -pr 81000000 -pc 80 > "$TMPFILE"
# We need know we need to see '65 Handles' for state created with
# libtpms-0.6.0 and 128kb NVRAM size
- grep -i "65 Handles" "$TMPFILE"
- if [ $? -ne 0 ]; then
+ if ! grep -i "65 Handles" "$TMPFILE"; then
echo "Error: Did not find '65 Handles' keyword in output"
cat "$TMPFILE"
exit 1
@@ -163,11 +158,11 @@
printf "Verifying signature with all the persisted keys\n"
echo -n "123" > "$BINFILE"
for ((i = 0x81000000; i < 0x81000040; i++)); do
- "${TOOLSPATH}/${PREFIX}verifysignature" \
+ if ! "${TOOLSPATH}/${PREFIX}verifysignature" \
-hk "$(printf "%x" "$i")" \
-is "${SIGFILE}" \
- -if "${BINFILE}" > "$TMPFILE"
- if [ $? -ne 0 ]; then
+ -if "${BINFILE}" > "$TMPFILE";
+ then
echo "Verifying signature failed for handle $(printf "%x" "$i")."
exit 1
fi
@@ -199,14 +194,12 @@
PID="$(cat "$PID_FILE")"
# Send TPM_Init
-act=$($SWTPM_IOCTL --unix "$SOCK_PATH" -i 2>&1)
-if [ $? -ne 0 ]; then
+if ! act=$($SWTPM_IOCTL --unix "$SOCK_PATH" -i 2>&1); then
echo "Error: $SWTPM_IOCTL CMD_INIT failed: $act"
exit 1
fi
-"${TOOLSPATH}/${PREFIX}startup" -c
-if [ $? -ne 0 ]; then
+if ! "${TOOLSPATH}/${PREFIX}startup" -c; then
echo "Error: tpm_startup clear failed."
exit 1
fi
@@ -214,8 +207,7 @@
fillup_nvram 1 1
# Send Shutdown
-act=$($SWTPM_IOCTL --unix "$SOCK_PATH" -s 2>&1)
-if [ $? -ne 0 ]; then
+if ! act=$($SWTPM_IOCTL --unix "$SOCK_PATH" -s 2>&1); then
echo "Error: $SWTPM_IOCTL CMD_SHUTDOWN failed: $act"
exit 1
fi
@@ -255,15 +247,13 @@
PID="$(cat "$PID_FILE")"
# Send TPM_Init
-act=$($SWTPM_IOCTL --unix "$SOCK_PATH" -i 2>&1)
-if [ $? -ne 0 ]; then
+if ! act=$($SWTPM_IOCTL --unix "$SOCK_PATH" -i 2>&1); then
echo "Error: $SWTPM_IOCTL CMD_INIT failed: $act"
cat "$LOGFILE"
exit 1
fi
-"${TOOLSPATH}/${PREFIX}startup" -c
-if [ $? -ne 0 ]; then
+if ! "${TOOLSPATH}/${PREFIX}startup" -c; then
echo "Error: tpm_startup clear failed."
cat "$LOGFILE"
exit 1
@@ -271,16 +261,14 @@
fillup_nvram 0 1
-"${TOOLSPATH}/${PREFIX}shutdown" -c
-if [ $? -ne 0 ]; then
+if ! "${TOOLSPATH}/${PREFIX}shutdown" -c; then
echo "Error: tpm_shutdown clear failed."
cat "$LOGFILE"
exit 1
fi
# Send Shutdown
-act=$($SWTPM_IOCTL --unix "$SOCK_PATH" -s 2>&1)
-if [ $? -ne 0 ]; then
+if ! act=$($SWTPM_IOCTL --unix "$SOCK_PATH" -s 2>&1); then
echo "Error: $SWTPM_IOCTL CMD_SHUTDOWN failed: $act"
exit 1
fi
@@ -320,14 +308,12 @@
PID="$(cat "$PID_FILE")"
# Send TPM_Init
-act=$($SWTPM_IOCTL --unix "$SOCK_PATH" -i 2>&1)
-if [ $? -ne 0 ]; then
+if ! act=$($SWTPM_IOCTL --unix "$SOCK_PATH" -i 2>&1); then
echo "Error: $SWTPM_IOCTL CMD_INIT failed: $act"
exit 1
fi
-"${TOOLSPATH}/${PREFIX}startup" -c
-if [ $? -ne 0 ]; then
+if ! "${TOOLSPATH}/${PREFIX}startup" -c; then
echo "Error: tpm_startup clear failed."
cat "$LOGFILE"
exit 1
@@ -335,16 +321,14 @@
fillup_nvram 0 1
-"${TOOLSPATH}/${PREFIX}shutdown" -c
-if [ $? -ne 0 ]; then
+if ! "${TOOLSPATH}/${PREFIX}shutdown" -c; then
echo "Error: tpm_shutdown clear failed."
cat "$LOGFILE"
exit 1
fi
# Send Shutdown
-act=$($SWTPM_IOCTL --unix "$SOCK_PATH" -s 2>&1)
-if [ $? -ne 0 ]; then
+if ! act=$($SWTPM_IOCTL --unix "$SOCK_PATH" -s 2>&1); then
echo "Error: $SWTPM_IOCTL CMD_SHUTDOWN failed: $act"
exit 1
fi
diff --git a/tests/test_tpm2_save_load_state_3 b/tests/test_tpm2_save_load_state_3
index aa5c005..d7b91f5 100755
--- a/tests/test_tpm2_save_load_state_3
+++ b/tests/test_tpm2_save_load_state_3
@@ -8,14 +8,12 @@
exit 77
fi
-type -p nvdefinespace startup &>/dev/null
-if [ $? -ne 0 ]; then
- PREFIX=tss
- type -p ${PREFIX}nvdefinespace ${PREFIX}startup
-fi
-if [ $? -ne 0 ]; then
- echo "Could not find TPM2 tools (e.g., (tss)startup, (tss)nvdefinespace) in PATH."
- exit 77
+if ! type -p nvdefinespace startup &>/dev/null; then
+ PREFIX=tss
+ if ! type -p ${PREFIX}nvdefinespace ${PREFIX}startup; then
+ echo "Could not find TPM2 tools (e.g., (tss)startup, (tss)nvdefinespace) in PATH."
+ exit 77
+ fi
fi
TOOLSPATH=$(dirname "$(type -P ${PREFIX}startup)")
@@ -71,15 +69,15 @@
for ((i=0; i < 10; i++)); do
printf "Creating NVRAM location 01%06x\n" "$i"
# the '+at wd' allows us to only write once
- "${TOOLSPATH}/${PREFIX}nvdefinespace" \
+ if ! "${TOOLSPATH}/${PREFIX}nvdefinespace" \
-ha "$(printf "01%06x" "$i")" \
-sz $((100 + i * 10)) \
-pwdn nnn \
+at wst \
+at wd \
${ody:+${ody}} \
- -hi o >/dev/null
- if [ $? -ne 0 ]; then
+ -hi o >/dev/null;
+ then
echo "Error: nvdefinespace failed for i = $i."
exit 1
fi
@@ -88,19 +86,19 @@
ody=""
fi
- "${TOOLSPATH}/${PREFIX}nvwrite" \
+ if ! "${TOOLSPATH}/${PREFIX}nvwrite" \
-ha "$(printf "01%06x" "$i")" \
-ic "Hello TPM2" \
- -pwdn nnn
- if [ $? -ne 0 ]; then
+ -pwdn nnn;
+ then
echo "Error: nwrite failed for i = $i."
exit 1
fi
- "${TOOLSPATH}/${PREFIX}nvwritelock" \
+ if ! "${TOOLSPATH}/${PREFIX}nvwritelock" \
-ha "$(printf "01%06x" "$i")" \
- -pwdn nnn
- if [ $? -ne 0 ]; then
+ -pwdn nnn;
+ then
echo "Error: nwritelock failed for i = $i."
exit 1
fi
@@ -108,21 +106,21 @@
# Create a counter space
echo "Creating NVRAM location 01000010 for counter"
- "${TOOLSPATH}/${PREFIX}nvdefinespace" \
+ if ! "${TOOLSPATH}/${PREFIX}nvdefinespace" \
-hi o \
-ha 01000010 \
-pwdn nnn \
- -ty c >/dev/null
- if [ $? -ne 0 ]; then
+ -ty c >/dev/null;
+ then
echo "Error: nvdefinespace for counter failed."
exit 1
fi
echo "Incrementing the counter at location 01000010"
- "${TOOLSPATH}/${PREFIX}nvincrement" \
+ if ! "${TOOLSPATH}/${PREFIX}nvincrement" \
-ha 01000010 \
- -pwdn nnn >/dev/null
- if [ $? -ne 0 ]; then
+ -pwdn nnn >/dev/null;
+ then
echo "Error: nvincrement failed."
exit 1
fi
@@ -139,11 +137,11 @@
# created. In the latter case we skip this first loop here.
for ((i=0; i < last; i++)); do
printf "Checking orderly NVRAM location 01%06x after reset\n" "$i"
- "${TOOLSPATH}/${PREFIX}nvread" \
+ if "${TOOLSPATH}/${PREFIX}nvread" \
-ha "$(printf "01%06x" "$i")" \
-pwdn nnn \
- -sz 10 > "$TMPFILE"
- if [ $? -eq 0 ]; then
+ -sz 10 > "$TMPFILE";
+ then
echo "Error: nvread succeeded for orderly NVRAM index; i = $i"
cat "$TMPFILE"
exit 1
@@ -153,11 +151,11 @@
# test the non-orderly indices OR orderly we just created above
for ((i=last; i < 10; i++)); do
printf "Checking NVRAM location 01%06x\n" "$i"
- "${TOOLSPATH}/${PREFIX}nvread" \
+ if ! "${TOOLSPATH}/${PREFIX}nvread" \
-ha "$(printf "01%06x" "$i")" \
-pwdn nnn \
- -sz 10 > "$TMPFILE"
- if [ $? -ne 0 ]; then
+ -sz 10 > "$TMPFILE";
+ then
echo "Error: nvread failed for i = $i"
cat "$TMPFILE"
exit 1
@@ -170,12 +168,11 @@
cat "$TMPFILE"
fi
- "${TOOLSPATH}/${PREFIX}nvwrite" \
+ if "${TOOLSPATH}/${PREFIX}nvwrite" \
-ha "$(printf "01%06x" "$i")" \
-ic "Hello TPM2" \
- -pwdn nnn > "$TMPFILE"
- rc=$?
- if [ "$rc" -eq 0 ]; then
+ -pwdn nnn > "$TMPFILE";
+ then
echo "Error: nwrite succeeded for i = $i."
exit 1
fi
@@ -183,12 +180,12 @@
# Read the counter
echo "Checking counter value at location 01000010"
- "${TOOLSPATH}/${PREFIX}nvread" \
+ if ! "${TOOLSPATH}/${PREFIX}nvread" \
-ha 01000010 \
-pwdn nnn \
-sz 8 \
- -of "$BINFILE" > "$TMPFILE"
- if [ $? -ne 0 ]; then
+ -of "$BINFILE" > "$TMPFILE";
+ then
echo "Error: nvread of counter failed."
cat "$TMPFILE"
exit 1
@@ -216,8 +213,7 @@
if [ "$create" -eq 1 ]; then
# Create a permanent primary key that we expecte
# to again see after the TPM has been restarted
- "${TOOLSPATH}/${PREFIX}createprimary" -hi o -si > "$TMPFILE"
- if [ $? -ne 0 ]; then
+ if ! "${TOOLSPATH}/${PREFIX}createprimary" -hi o -si > "$TMPFILE"; then
echo "Error: createprimary failed."
exit 1
fi
@@ -225,16 +221,14 @@
echo "Error: createprimary did not result in expected handle 80000000"
exit 1
fi
- "${TOOLSPATH}/${PREFIX}evictcontrol" -ho 80000000 -hp 81000000 -hi o
- if [ $? -ne 0 ]; then
+ if ! "${TOOLSPATH}/${PREFIX}evictcontrol" -ho 80000000 -hp 81000000 -hi o; then
echo "Error: evictcontrol did not work"
exit 1
fi
"${TOOLSPATH}/${PREFIX}flushcontext" -ha 80000000
echo -n "123" > "$BINFILE"
- "${TOOLSPATH}/${PREFIX}sign" -hk 81000000 -if "${BINFILE}" -os "${SIGFILE}" > "$TMPFILE"
- if [ $? -ne 0 ]; then
+ if ! "${TOOLSPATH}/${PREFIX}sign" -hk 81000000 -if "${BINFILE}" -os "${SIGFILE}" > "$TMPFILE"; then
echo "Error: Could not create signature."
cat "$TMPFILE"
exit 1
@@ -254,12 +248,14 @@
"${TOOLSPATH}/${PREFIX}verifysignature" -hk 81000000 \
-is "${SIGFILE}" \
-if "${BINFILE}" > "$TMPFILE"
+ rc=$?
else
"${TOOLSPATH}/${PREFIX}verifysignature" -hk 81000000 \
-is "${TESTDIR}/data/tpm2state3/signature.bin" \
-if "${BINFILE}" > "$TMPFILE"
+ rc=$?
fi
- if [ $? -ne 0 ]; then
+ if [ $rc -ne 0 ]; then
echo "Verifying signature failed."
exit 1
fi
@@ -333,10 +329,10 @@
# no effect on permanent RAM, so we won't test that
for hi in "l" "e" "o"; do
pwdn="${hi}${hi}${hi}"
- "${TOOLSPATH}/${PREFIX}hierarchychangeauth" \
+ if ! "${TOOLSPATH}/${PREFIX}hierarchychangeauth" \
-hi "${hi}" \
- -pwdn "${pwdn}" > "$TMPFILE"
- if [ $? -ne 0 ]; then
+ -pwdn "${pwdn}" > "$TMPFILE";
+ then
echo "Error: hierarchychangeauth failed to set password."
cat "$TMPFILE"
exit 1
@@ -350,22 +346,22 @@
pwda="${hi}${hi}${hi}"
pwdn="new-${pwda}"
- "${TOOLSPATH}/${PREFIX}hierarchychangeauth" \
+ if ! "${TOOLSPATH}/${PREFIX}hierarchychangeauth" \
-hi "${hi}" \
-pwda "${pwda}" \
- -pwdn "${pwdn}" > "$TMPFILE"
- if [ $? -ne 0 ]; then
+ -pwdn "${pwdn}" > "$TMPFILE";
+ then
echo "Error: hierarchychangeauth failed to change password."
cat "$TMPFILE"
exit 1
fi
# change back
- "${TOOLSPATH}/${PREFIX}hierarchychangeauth" \
+ if ! "${TOOLSPATH}/${PREFIX}hierarchychangeauth" \
-hi "${hi}" \
-pwda "${pwdn}" \
- -pwdn "${pwda}" > "$TMPFILE"
- if [ $? -ne 0 ]; then
+ -pwdn "${pwda}" > "$TMPFILE";
+ then
echo "Error: hierarchychangeauth failed to change back password."
cat "$TMPFILE"
exit 1
@@ -385,54 +381,51 @@
echo -n "123" > "${TMP2FILE}"
echo "Starting a sha1 sequence"
- res="$("${TOOLSPATH}/${PREFIX}hashsequencestart" -halg sha1)"
- if [ $? -ne 0 ]; then
+ if ! res="$("${TOOLSPATH}/${PREFIX}hashsequencestart" -halg sha1)"; then
echo "Error: Could not start hash sequence."
exit 1
fi
SHA1_SEQUENCE_HANDLE="$(echo "$res" | cut -d " " -f3)"
echo "sha1 sequence handle: $SHA1_SEQUENCE_HANDLE"
- "${TOOLSPATH}/${PREFIX}sequenceupdate" \
+ if ! "${TOOLSPATH}/${PREFIX}sequenceupdate" \
-hs "${SHA1_SEQUENCE_HANDLE}" \
- -if "${TMP2FILE}"
- if [ $? -ne 0 ]; then
+ -if "${TMP2FILE}";
+ then
echo "Error: Could not updated the sha1 sequence."
exit 1
fi
echo "Updated sha1 sequence."
echo "Starting a sha256 sequence"
- res="$("${TOOLSPATH}/${PREFIX}hashsequencestart" -halg sha256)"
- if [ $? -ne 0 ]; then
+ if ! res="$("${TOOLSPATH}/${PREFIX}hashsequencestart" -halg sha256)"; then
echo "Error: Could not start sha256 sequence."
exit 1
fi
SHA256_SEQUENCE_HANDLE="$(echo "$res" | cut -d " " -f3)"
echo "sha256 sequence handle: $SHA256_SEQUENCE_HANDLE"
- "${TOOLSPATH}/${PREFIX}sequenceupdate" \
+ if ! "${TOOLSPATH}/${PREFIX}sequenceupdate" \
-hs "${SHA256_SEQUENCE_HANDLE}" \
- -if "${TMP2FILE}"
- if [ $? -ne 0 ]; then
+ -if "${TMP2FILE}";
+ then
echo "Error: Could not updated the hash sequence."
exit 1
fi
echo "Updated sha256 sequence."
echo "Starting a sha384 sequence"
- res="$("${TOOLSPATH}/${PREFIX}hashsequencestart" -halg sha384)"
- if [ $? -ne 0 ]; then
+ if ! res="$("${TOOLSPATH}/${PREFIX}hashsequencestart" -halg sha384)"; then
echo "Error: Could not start sha384 sequence."
exit 1
fi
SHA384_SEQUENCE_HANDLE="$(echo "$res" | cut -d " " -f3)"
echo "sha384 sequence handle: $SHA384_SEQUENCE_HANDLE"
- "${TOOLSPATH}/${PREFIX}sequenceupdate" \
+ if ! "${TOOLSPATH}/${PREFIX}sequenceupdate" \
-hs "${SHA384_SEQUENCE_HANDLE}" \
- -if "${TMP2FILE}"
- if [ $? -ne 0 ]; then
+ -if "${TMP2FILE}";
+ then
echo "Error: Could not updated the hash sequence."
exit 1
fi
@@ -493,8 +486,7 @@
if [ "$create" -eq 1 ]; then
# Create a permanent primary key that we expecte
# to again see after the TPM has been restarted
- "${TOOLSPATH}/${PREFIX}createprimary" -hi o -st > "$TMPFILE"
- if [ $? -ne 0 ]; then
+ if ! "${TOOLSPATH}/${PREFIX}createprimary" -hi o -st > "$TMPFILE"; then
echo "Error: createprimary for creating storage key failed."
exit 1
fi
@@ -503,15 +495,13 @@
cat "$TMPFILE"
exit 1
fi
- "${TOOLSPATH}/${PREFIX}evictcontrol" -ho 80000000 -hp 81000000 -hi o
- if [ $? -ne 0 ]; then
+ if ! "${TOOLSPATH}/${PREFIX}evictcontrol" -ho 80000000 -hp 81000000 -hi o; then
echo "Error: evictcontrol did not work"
exit 1
fi
"${TOOLSPATH}/${PREFIX}flushcontext" -ha 80000000
- "${TOOLSPATH}/${PREFIX}startauthsession" -se h -bi 81000000 > "$TMPFILE"
- if [ $? -ne 0 ]; then
+ if ! "${TOOLSPATH}/${PREFIX}startauthsession" -se h -bi 81000000 > "$TMPFILE"; then
echo "Error: Could not start an auth session."
cat "$TMPFILE"
exit 1
@@ -525,11 +515,10 @@
if [ "$check" -eq 1 ]; then
echo "Using auth session ${AUTHSESSION_HANDLE} to create a key."
- "${TOOLSPATH}/${PREFIX}create" \
+ if ! "${TOOLSPATH}/${PREFIX}create" \
-hp 81000000 \
-st \
- -se0 "${AUTHSESSION_HANDLE}" 1
- if [ $? -ne 0 ]; then
+ -se0 "${AUTHSESSION_HANDLE}" 1; then
echo "Error: Could not create key using authsession"
exit 1
fi
@@ -548,8 +537,7 @@
local i res rc
if [ "$create" -eq 1 ]; then
- "${TOOLSPATH}/${PREFIX}createprimary" -hi o -st > "$TMPFILE"
- if [ $? -ne 0 ]; then
+ if ! "${TOOLSPATH}/${PREFIX}createprimary" -hi o -st > "$TMPFILE"; then
echo "Error: createprimary failed."
exit 1
fi
@@ -558,16 +546,16 @@
exit 1
fi
- "${TOOLSPATH}/${PREFIX}create" -hp 80000000 -kh \
- -opr "${HKEYPRIV}" -opu "${HKEYPUB}" > "$TMPFILE"
- if [ $? -ne 0 ]; then
+ if ! "${TOOLSPATH}/${PREFIX}create" -hp 80000000 -kh \
+ -opr "${HKEYPRIV}" -opu "${HKEYPUB}" > "$TMPFILE";
+ then
echo "Error: could not create key for HMAC"
exit 1
fi
- "${TOOLSPATH}/${PREFIX}load" -hp 80000000 \
- -ipr "${HKEYPRIV}" -ipu "${HKEYPUB}" -v > "$TMPFILE"
- if [ $? -ne 0 ]; then
+ if ! "${TOOLSPATH}/${PREFIX}load" -hp 80000000 \
+ -ipr "${HKEYPRIV}" -ipu "${HKEYPUB}" -v > "$TMPFILE";
+ then
echo "Error: could not load key for HMAC"
cat "$TMPFILE"
exit 1
@@ -577,8 +565,7 @@
exit 1
fi
- "${TOOLSPATH}/${PREFIX}hmacstart" -hk 80000001 > "$TMPFILE"
- if [ $? -ne 0 ]; then
+ if ! "${TOOLSPATH}/${PREFIX}hmacstart" -hk 80000001 > "$TMPFILE"; then
echo "Error: could not start HMAC sequence"
exit 1
fi
@@ -588,10 +575,10 @@
fi
echo -n "123" > "${TMP2FILE}"
- "${TOOLSPATH}/${PREFIX}sequenceupdate" \
+ if ! "${TOOLSPATH}/${PREFIX}sequenceupdate" \
-hs 80000002 \
- -if "${TMP2FILE}"
- if [ $? -ne 0 ]; then
+ -if "${TMP2FILE}";
+ then
echo "Error: Could not updated the HMAC sequence."
exit 1
fi
@@ -628,8 +615,7 @@
if [ "$create" -eq 1 ]; then
# Create a permanent primary key that we expecte
# to again see after the TPM has been restarted
- "${TOOLSPATH}/${PREFIX}createprimary" -hi o -si > "$TMPFILE"
- if [ $? -ne 0 ]; then
+ if ! "${TOOLSPATH}/${PREFIX}createprimary" -hi o -si > "$TMPFILE"; then
echo "Error: createprimary failed."
exit 1
fi
@@ -639,18 +625,17 @@
fi
echo -n "123" > "$BINFILE"
- "${TOOLSPATH}/${PREFIX}sign" -hk 80000000 -if "${BINFILE}" -os "${SIGFILE}" > "$TMPFILE"
- if [ $? -ne 0 ]; then
+ if ! "${TOOLSPATH}/${PREFIX}sign" -hk 80000000 -if "${BINFILE}" -os "${SIGFILE}" > "$TMPFILE"; then
echo "Error: Could not create signature."
cat "$TMPFILE"
exit 1
fi
printf "Verifying signature with this key (create phase)\n"
- "${TOOLSPATH}/${PREFIX}verifysignature" -hk 80000000 \
+ if ! "${TOOLSPATH}/${PREFIX}verifysignature" -hk 80000000 \
-is "${SIGFILE}" \
- -if "${BINFILE}" > "$TMPFILE"
- if [ $? -ne 0 ]; then
+ -if "${BINFILE}" > "$TMPFILE";
+ then
echo "Verifying signature failed."
exit 1
fi
@@ -672,17 +657,16 @@
printf "Verifying signature with this key (check phase)\n"
echo -n "123" > "$BINFILE"
- "${TOOLSPATH}/${PREFIX}verifysignature" -hk 80000000 \
+ if ! "${TOOLSPATH}/${PREFIX}verifysignature" -hk 80000000 \
-is "${sigfile}" \
- -if "${BINFILE}" > "$TMPFILE"
- if [ $? -ne 0 ]; then
+ -if "${BINFILE}" > "$TMPFILE";
+ then
echo "Verifying signature failed."
exit 1
fi
if [ "$previousstate" -eq 0 ]; then
- "${TOOLSPATH}/${PREFIX}sign" -hk 80000000 -if "${BINFILE}" -os "${SIGFILE2}" > "$TMPFILE"
- if [ $? -ne 0 ]; then
+ if ! "${TOOLSPATH}/${PREFIX}sign" -hk 80000000 -if "${BINFILE}" -os "${SIGFILE2}" > "$TMPFILE"; then
echo "Error: Could not create signature."
cat "$TMPFILE"
exit 1
@@ -707,8 +691,7 @@
if [ "$create" -eq 1 ]; then
${CERTTOOL} --generate-privkey --bits 2048 --outfile "${PRIVKEY}" &>/dev/null
${CERTTOOL} --pubkey-info --load-privkey "${PRIVKEY}" > "${PUBKEY}"
- "$TOOLSPATH/${PREFIX}loadexternal" -hi o -ipem "${PUBKEY}" > "$TMPFILE"
- if [ $? -ne 0 ]; then
+ if ! "$TOOLSPATH/${PREFIX}loadexternal" -hi o -ipem "${PUBKEY}" > "$TMPFILE"; then
echo "Error: loadexternal failed."
exit 1
fi
@@ -719,14 +702,12 @@
fi
if [ "$check" -eq 1 ]; then
- "$TOOLSPATH/${PREFIX}contextsave" -ha 80000001 -of "${PUBKEYCONTEXT}"
- if [ $? -ne 0 ]; then
+ if ! "$TOOLSPATH/${PREFIX}contextsave" -ha 80000001 -of "${PUBKEYCONTEXT}"; then
echo "Error: contextsave on loaded public key failed."
exit 1
fi
"$TOOLSPATH/${PREFIX}flushcontext" -ha 80000001
- "$TOOLSPATH/${PREFIX}contextload" -if "${PUBKEYCONTEXT}" > "$TMPFILE"
- if [ $? -ne 0 ]; then
+ if ! "$TOOLSPATH/${PREFIX}contextload" -if "${PUBKEYCONTEXT}" > "$TMPFILE"; then
echo "Error: contextload on context of public key failed."
exit 1
fi
@@ -761,14 +742,12 @@
PID="$(cat "$PID_FILE")"
# Send TPM_Init
-act=$($SWTPM_IOCTL --unix "$SOCK_PATH" -i 2>&1)
-if [ $? -ne 0 ]; then
+if ! act=$($SWTPM_IOCTL --unix "$SOCK_PATH" -i 2>&1); then
echo "Error: $SWTPM_IOCTL CMD_INIT failed: $act"
exit 1
fi
-"${TOOLSPATH}/${PREFIX}startup" -c
-if [ $? -ne 0 ]; then
+if ! "${TOOLSPATH}/${PREFIX}startup" -c; then
echo "Error: tpm_startup clear failed."
exit 1
fi
@@ -778,16 +757,14 @@
test_pcr_allocation 1 0 # can only check after reboot
test_hierarchy 1 1
-"${TOOLSPATH}/${PREFIX}shutdown" -c
-if [ $? -ne 0 ]; then
+if ! "${TOOLSPATH}/${PREFIX}shutdown" -c; then
echo "Error: tpm_shutdown clear failed."
cat "$LOGFILE"
exit 1
fi
# Send Shutdown
-act=$($SWTPM_IOCTL --unix "$SOCK_PATH" -s 2>&1)
-if [ $? -ne 0 ]; then
+if ! act=$($SWTPM_IOCTL --unix "$SOCK_PATH" -s 2>&1); then
echo "Error: $SWTPM_IOCTL CMD_SHUTDOWN failed: $act"
exit 1
fi
@@ -822,14 +799,12 @@
PID="$(cat "$PID_FILE")"
# Send TPM_Init
-act=$($SWTPM_IOCTL --unix "$SOCK_PATH" -i 2>&1)
-if [ $? -ne 0 ]; then
+if ! act=$($SWTPM_IOCTL --unix "$SOCK_PATH" -i 2>&1); then
echo "Error: $SWTPM_IOCTL CMD_INIT failed: $act"
exit 1
fi
-"${TOOLSPATH}/${PREFIX}startup" -c
-if [ $? -ne 0 ]; then
+if ! "${TOOLSPATH}/${PREFIX}startup" -c; then
echo "Error: tpm_startup clear failed."
cat "$LOGFILE"
exit 1
@@ -840,16 +815,14 @@
test_pcr_allocation 0 1
test_hierarchy 0 1
-"${TOOLSPATH}/${PREFIX}shutdown" -c
-if [ $? -ne 0 ]; then
+if ! "${TOOLSPATH}/${PREFIX}shutdown" -c; then
echo "Error: tpm_shutdown clear failed."
cat "$LOGFILE"
exit 1
fi
# Send Shutdown
-act=$($SWTPM_IOCTL --unix "$SOCK_PATH" -s 2>&1)
-if [ $? -ne 0 ]; then
+if ! act=$($SWTPM_IOCTL --unix "$SOCK_PATH" -s 2>&1); then
echo "Error: $SWTPM_IOCTL CMD_SHUTDOWN failed: $act"
exit 1
fi
@@ -883,14 +856,12 @@
PID="$(cat "$PID_FILE")"
# Send TPM_Init
-act=$($SWTPM_IOCTL --unix "$SOCK_PATH" -i 2>&1)
-if [ $? -ne 0 ]; then
+if ! act=$($SWTPM_IOCTL --unix "$SOCK_PATH" -i 2>&1); then
echo "Error: $SWTPM_IOCTL CMD_INIT failed: $act"
exit 1
fi
-"${TOOLSPATH}/${PREFIX}startup" -c
-if [ $? -ne 0 ]; then
+if ! "${TOOLSPATH}/${PREFIX}startup" -c; then
echo "Error: tpm_startup clear failed."
cat "$LOGFILE"
exit 1
@@ -901,16 +872,14 @@
test_pcr_allocation 0 1
test_hierarchy 0 1
-"${TOOLSPATH}/${PREFIX}shutdown" -c
-if [ $? -ne 0 ]; then
+if ! "${TOOLSPATH}/${PREFIX}shutdown" -c; then
echo "Error: tpm_shutdown clear failed."
cat "$LOGFILE"
exit 1
fi
# Send Shutdown
-act=$($SWTPM_IOCTL --unix "$SOCK_PATH" -s 2>&1)
-if [ $? -ne 0 ]; then
+if ! act=$($SWTPM_IOCTL --unix "$SOCK_PATH" -s 2>&1); then
echo "Error: $SWTPM_IOCTL CMD_SHUTDOWN failed: $act"
exit 1
fi
@@ -942,14 +911,12 @@
PID="$(cat "$PID_FILE")"
# Send TPM_Init
-act=$($SWTPM_IOCTL --unix "$SOCK_PATH" -i 2>&1)
-if [ $? -ne 0 ]; then
+if ! act=$($SWTPM_IOCTL --unix "$SOCK_PATH" -i 2>&1); then
echo "Error: $SWTPM_IOCTL CMD_INIT failed: $act"
exit 1
fi
-"${TOOLSPATH}/${PREFIX}startup" -c
-if [ $? -ne 0 ]; then
+if ! "${TOOLSPATH}/${PREFIX}startup" -c; then
echo "Error: tpm_startup clear failed."
cat "$LOGFILE"
exit 1
@@ -958,22 +925,19 @@
test_session 1 1
test_hash_context 1 0
-act=$($SWTPM_IOCTL --unix "$SOCK_PATH" -v 2>&1)
-if [ $? -ne 0 ]; then
+if ! act=$($SWTPM_IOCTL --unix "$SOCK_PATH" -v 2>&1); then
echo "Error: $SWTPM_IOCTL CMD_STORE_VOLATILE failed: $act"
exit 1
fi
-"${TOOLSPATH}/${PREFIX}shutdown" -c
-if [ $? -ne 0 ]; then
+if ! "${TOOLSPATH}/${PREFIX}shutdown" -c; then
echo "Error: tpm_shutdown clear failed."
cat "$LOGFILE"
exit 1
fi
# Send Shutdown
-act=$($SWTPM_IOCTL --unix "$SOCK_PATH" -s 2>&1)
-if [ $? -ne 0 ]; then
+if ! act=$($SWTPM_IOCTL --unix "$SOCK_PATH" -s 2>&1); then
echo "Error: $SWTPM_IOCTL CMD_SHUTDOWN failed: $act"
exit 1
fi
@@ -1004,8 +968,7 @@
PID="$(cat "$PID_FILE")"
# Send TPM_Init
-act=$($SWTPM_IOCTL --unix "$SOCK_PATH" -i 2>&1)
-if [ $? -ne 0 ]; then
+if ! act=$($SWTPM_IOCTL --unix "$SOCK_PATH" -i 2>&1); then
cat "$LOGFILE"
echo "Error: $SWTPM_IOCTL CMD_INIT failed: $act"
exit 1
@@ -1014,16 +977,14 @@
test_hash_context 0 1
test_session 0 1
-"${TOOLSPATH}/${PREFIX}shutdown" -c
-if [ $? -ne 0 ]; then
+if ! "${TOOLSPATH}/${PREFIX}shutdown" -c; then
echo "Error: tpm_shutdown clear failed."
cat "$LOGFILE"
exit 1
fi
# Send Shutdown
-act=$($SWTPM_IOCTL --unix "$SOCK_PATH" -s 2>&1)
-if [ $? -ne 0 ]; then
+if ! act=$($SWTPM_IOCTL --unix "$SOCK_PATH" -s 2>&1); then
echo "Error: $SWTPM_IOCTL CMD_SHUTDOWN failed: $act"
exit 1
fi
@@ -1056,8 +1017,7 @@
PID="$(cat "$PID_FILE")"
# Send TPM_Init
-act=$($SWTPM_IOCTL --unix "$SOCK_PATH" -i 2>&1)
-if [ $? -ne 0 ]; then
+if ! act=$($SWTPM_IOCTL --unix "$SOCK_PATH" -i 2>&1); then
echo "Error: $SWTPM_IOCTL CMD_INIT failed: $act"
tail -n 10 "$LOGFILE"
exit 1
@@ -1067,8 +1027,7 @@
test_session 0 1
# Send Shutdown
-act=$($SWTPM_IOCTL --unix "$SOCK_PATH" -s 2>&1)
-if [ $? -ne 0 ]; then
+if ! act=$($SWTPM_IOCTL --unix "$SOCK_PATH" -s 2>&1); then
echo "Error: $SWTPM_IOCTL CMD_SHUTDOWN failed: $act"
exit 1
fi
@@ -1100,14 +1059,12 @@
PID="$(cat "$PID_FILE")"
# Send TPM_Init
-act=$($SWTPM_IOCTL --unix "$SOCK_PATH" -i 2>&1)
-if [ $? -ne 0 ]; then
+if ! act=$($SWTPM_IOCTL --unix "$SOCK_PATH" -i 2>&1); then
echo "Error: $SWTPM_IOCTL CMD_INIT failed: $act"
exit 1
fi
-"${TOOLSPATH}/${PREFIX}startup" -c
-if [ $? -ne 0 ]; then
+if ! "${TOOLSPATH}/${PREFIX}startup" -c; then
echo "Error: tpm_startup clear failed."
cat "$LOGFILE"
exit 1
@@ -1116,22 +1073,19 @@
# we only run this to generate the AES key which is different every time...
# test_hmac_context 1 0
-act=$($SWTPM_IOCTL --unix "$SOCK_PATH" -v 2>&1)
-if [ $? -ne 0 ]; then
+if ! act=$($SWTPM_IOCTL --unix "$SOCK_PATH" -v 2>&1); then
echo "Error: $SWTPM_IOCTL CMD_STORE_VOLATILE failed: $act"
exit 1
fi
-"${TOOLSPATH}/${PREFIX}shutdown" -c
-if [ $? -ne 0 ]; then
+if ! "${TOOLSPATH}/${PREFIX}shutdown" -c; then
echo "Error: tpm_shutdown clear failed."
cat "$LOGFILE"
exit 1
fi
# Send Shutdown
-act=$($SWTPM_IOCTL --unix "$SOCK_PATH" -s 2>&1)
-if [ $? -ne 0 ]; then
+if ! act=$($SWTPM_IOCTL --unix "$SOCK_PATH" -s 2>&1); then
echo "Error: $SWTPM_IOCTL CMD_SHUTDOWN failed: $act"
exit 1
fi
@@ -1162,8 +1116,7 @@
PID="$(cat "$PID_FILE")"
# Send TPM_Init
-act=$($SWTPM_IOCTL --unix "$SOCK_PATH" -i 2>&1)
-if [ $? -ne 0 ]; then
+if ! act=$($SWTPM_IOCTL --unix "$SOCK_PATH" -i 2>&1); then
cat "$LOGFILE"
echo "Error: $SWTPM_IOCTL CMD_INIT failed: $act"
exit 1
@@ -1174,16 +1127,14 @@
# be different every time
# test_hmac_context 0 1
-"${TOOLSPATH}/${PREFIX}shutdown" -c
-if [ $? -ne 0 ]; then
+if ! "${TOOLSPATH}/${PREFIX}shutdown" -c; then
echo "Error: tpm_shutdown clear failed."
cat "$LOGFILE"
exit 1
fi
# Send Shutdown
-act=$($SWTPM_IOCTL --unix "$SOCK_PATH" -s 2>&1)
-if [ $? -ne 0 ]; then
+if ! act=$($SWTPM_IOCTL --unix "$SOCK_PATH" -s 2>&1); then
echo "Error: $SWTPM_IOCTL CMD_SHUTDOWN failed: $act"
exit 1
fi
@@ -1214,8 +1165,7 @@
PID="$(cat "$PID_FILE")"
# Send TPM_Init
-act=$($SWTPM_IOCTL --unix "$SOCK_PATH" -i 2>&1)
-if [ $? -ne 0 ]; then
+if ! act=$($SWTPM_IOCTL --unix "$SOCK_PATH" -i 2>&1); then
echo "Error: $SWTPM_IOCTL CMD_INIT failed: $act"
exit 1
fi
@@ -1223,8 +1173,7 @@
test_hmac_context 0 1
# Send Shutdown
-act=$($SWTPM_IOCTL --unix "$SOCK_PATH" -s 2>&1)
-if [ $? -ne 0 ]; then
+if ! act=$($SWTPM_IOCTL --unix "$SOCK_PATH" -s 2>&1); then
echo "Error: $SWTPM_IOCTL CMD_SHUTDOWN failed: $act"
exit 1
fi
@@ -1257,14 +1206,12 @@
PID="$(cat "$PID_FILE")"
# Send TPM_Init
-act=$($SWTPM_IOCTL --unix "$SOCK_PATH" -i 2>&1)
-if [ $? -ne 0 ]; then
+if ! act=$($SWTPM_IOCTL --unix "$SOCK_PATH" -i 2>&1); then
echo "Error: $SWTPM_IOCTL CMD_INIT failed: $act"
exit 1
fi
-"${TOOLSPATH}/${PREFIX}startup" -c
-if [ $? -ne 0 ]; then
+if ! "${TOOLSPATH}/${PREFIX}startup" -c; then
echo "Error: tpm_startup clear failed."
cat "$LOGFILE"
exit 1
@@ -1273,22 +1220,19 @@
test_primary_volatile_load 1 0 0
test_external_key 1 1
-act=$($SWTPM_IOCTL --unix "$SOCK_PATH" -v 2>&1)
-if [ $? -ne 0 ]; then
+if ! act=$($SWTPM_IOCTL --unix "$SOCK_PATH" -v 2>&1); then
echo "Error: $SWTPM_IOCTL CMD_STORE_VOLATILE failed: $act"
exit 1
fi
-"${TOOLSPATH}/${PREFIX}shutdown" -c
-if [ $? -ne 0 ]; then
+if ! "${TOOLSPATH}/${PREFIX}shutdown" -c; then
echo "Error: tpm_shutdown clear failed."
cat "$LOGFILE"
exit 1
fi
# Send Shutdown
-act=$($SWTPM_IOCTL --unix "$SOCK_PATH" -s 2>&1)
-if [ $? -ne 0 ]; then
+if ! act=$($SWTPM_IOCTL --unix "$SOCK_PATH" -s 2>&1); then
echo "Error: $SWTPM_IOCTL CMD_SHUTDOWN failed: $act"
exit 1
fi
@@ -1320,8 +1264,7 @@
PID="$(cat "$PID_FILE")"
# Send TPM_Init
-act=$($SWTPM_IOCTL --unix "$SOCK_PATH" -i 2>&1)
-if [ $? -ne 0 ]; then
+if ! act=$($SWTPM_IOCTL --unix "$SOCK_PATH" -i 2>&1); then
cat "$LOGFILE"
echo "Error: $SWTPM_IOCTL CMD_INIT failed: $act"
exit 1
@@ -1330,16 +1273,14 @@
test_primary_volatile_load 0 1 0
test_external_key 0 1
-"${TOOLSPATH}/${PREFIX}shutdown" -c
-if [ $? -ne 0 ]; then
+if ! "${TOOLSPATH}/${PREFIX}shutdown" -c; then
echo "Error: tpm_shutdown clear failed."
cat "$LOGFILE"
exit 1
fi
# Send Shutdown
-act=$($SWTPM_IOCTL --unix "$SOCK_PATH" -s 2>&1)
-if [ $? -ne 0 ]; then
+if ! act=$($SWTPM_IOCTL --unix "$SOCK_PATH" -s 2>&1); then
echo "Error: $SWTPM_IOCTL CMD_SHUTDOWN failed: $act"
exit 1
fi
@@ -1370,8 +1311,7 @@
PID="$(cat "$PID_FILE")"
# Send TPM_Init
-act=$($SWTPM_IOCTL --unix "$SOCK_PATH" -i 2>&1)
-if [ $? -ne 0 ]; then
+if ! act=$($SWTPM_IOCTL --unix "$SOCK_PATH" -i 2>&1); then
echo "Error: $SWTPM_IOCTL CMD_INIT failed: $act"
exit 1
fi
@@ -1381,16 +1321,14 @@
# Create the orderly nv indices and have them cleared (for coverage)
test_nvram_state 1 1
-"${TOOLSPATH}/${PREFIX}clear" -hi p
-if [ $? -ne 0 ]; then
+if ! "${TOOLSPATH}/${PREFIX}clear" -hi p; then
echo "Error: clear failed."
cat "$LOGFILE"
exit 1
fi
# Send Shutdown
-act=$($SWTPM_IOCTL --unix "$SOCK_PATH" -s 2>&1)
-if [ $? -ne 0 ]; then
+if ! act=$($SWTPM_IOCTL --unix "$SOCK_PATH" -s 2>&1); then
echo "Error: $SWTPM_IOCTL CMD_SHUTDOWN failed: $act"
exit 1
fi
diff --git a/tests/test_tpm2_swtpm_cert b/tests/test_tpm2_swtpm_cert
index 5e4aacc..0e5c639 100755
--- a/tests/test_tpm2_swtpm_cert
+++ b/tests/test_tpm2_swtpm_cert
@@ -35,7 +35,7 @@
fi
}
-${SWTPM_CERT} \
+if ! ${SWTPM_CERT} \
--tpm2 \
--allow-signing \
--signkey "${TESTDIR}/data/signkey.pem" \
@@ -45,9 +45,7 @@
--days 3650 \
--pem \
--tpm-manufacturer IBM --tpm-model swtpm-libtpms --tpm-version 1.2 \
- --tpm-spec-family 2.0 --tpm-spec-revision 146 --tpm-spec-level 0
-
-if [ $? -ne 0 ]; then
+ --tpm-spec-family 2.0 --tpm-spec-revision 146 --tpm-spec-level 0; then
echo "Error: ${SWTPM_CERT} returned error code."
exit 1
fi
@@ -59,7 +57,7 @@
echo -n > "${cert}"
echo "Test 1: OK"
-${SWTPM_CERT} \
+if ! ${SWTPM_CERT} \
--tpm2 \
--signkey "${TESTDIR}/data/signkey.pem" \
--issuercert "${TESTDIR}/data/issuercert.pem" \
@@ -69,9 +67,7 @@
--subject "OU=foo,L=NewYork,ST=NY,C=US" \
--pem \
--tpm-manufacturer IBM --tpm-model swtpm-libtpms --tpm-version 1.2 \
- --tpm-spec-family 2.0 --tpm-spec-revision 146 --tpm-spec-level 0
-
-if [ $? -ne 0 ]; then
+ --tpm-spec-family 2.0 --tpm-spec-revision 146 --tpm-spec-level 0; then
echo "Error: ${SWTPM_CERT} returned error code."
exit 1
fi
@@ -83,7 +79,7 @@
echo -n > "${cert}"
echo "Test 2: OK"
-${SWTPM_CERT} \
+if ! ${SWTPM_CERT} \
--tpm2 \
--signkey "${TESTDIR}/data/signkey.pem" \
--issuercert "${TESTDIR}/data/issuercert.pem" \
@@ -93,9 +89,7 @@
--subject "OU=foo,L=NewYork,ST=NY,C=US" \
--pem \
--tpm-manufacturer IBM --tpm-model swtpm-libtpms --tpm-version 1.2 \
- --tpm-spec-family 2.0 --tpm-spec-revision 146 --tpm-spec-level 0
-
-if [ $? -ne 0 ]; then
+ --tpm-spec-family 2.0 --tpm-spec-revision 146 --tpm-spec-level 0; then
echo "Error: ${SWTPM_CERT} returned error code."
exit 1
fi
@@ -111,7 +105,7 @@
###################### Platform Certificate #####################
-${SWTPM_CERT} \
+if ! ${SWTPM_CERT} \
--tpm2 \
--type platform \
--signkey "${TESTDIR}/data/signkey.pem" \
@@ -124,9 +118,7 @@
--tpm-manufacturer IBM --tpm-model swtpm-libtpms --tpm-version 1.2 \
--platform-manufacturer Fedora \
--platform-model QEMU \
- --platform-version 2.1
-
-if [ $? -ne 0 ]; then
+ --platform-version 2.1; then
echo "Error: ${SWTPM_CERT} returned error code."
exit 1
fi
diff --git a/tests/test_tpm2_swtpm_cert_ecc b/tests/test_tpm2_swtpm_cert_ecc
index c74cebf..a1e547a 100755
--- a/tests/test_tpm2_swtpm_cert_ecc
+++ b/tests/test_tpm2_swtpm_cert_ecc
@@ -35,7 +35,7 @@
fi
}
-${SWTPM_CERT} \
+if ! ${SWTPM_CERT} \
--tpm2 \
--signkey "${TESTDIR}/data/signkey.pem" \
--issuercert "${TESTDIR}/data/issuercert.pem" \
@@ -45,9 +45,7 @@
--days 3650 \
--pem \
--tpm-manufacturer IBM --tpm-model swtpm-libtpms --tpm-version 2.0 \
- --tpm-spec-family 2.0 --tpm-spec-revision 146 --tpm-spec-level 0
-
-if [ $? -ne 0 ]; then
+ --tpm-spec-family 2.0 --tpm-spec-revision 146 --tpm-spec-level 0; then
echo "Error: ${SWTPM_CERT} returned error code."
exit 1
fi
@@ -62,7 +60,7 @@
echo -n > "${cert}"
echo "Test 1: OK"
-${SWTPM_CERT} \
+if ! ${SWTPM_CERT} \
--tpm2 \
--signkey "${TESTDIR}/data/signkey.pem" \
--issuercert "${TESTDIR}/data/issuercert.pem" \
@@ -73,9 +71,7 @@
--subject "OU=foo,L=NewYork,ST=NY,C=US" \
--pem \
--tpm-manufacturer IBM --tpm-model swtpm-libtpms --tpm-version 1.2 \
- --tpm-spec-family 2.0 --tpm-spec-revision 146 --tpm-spec-level 0
-
-if [ $? -ne 0 ]; then
+ --tpm-spec-family 2.0 --tpm-spec-revision 146 --tpm-spec-level 0; then
echo "Error: ${SWTPM_CERT} returned error code."
exit 1
fi
@@ -87,7 +83,7 @@
echo -n > "${cert}"
echo "Test 2: OK"
-${SWTPM_CERT} \
+if ! ${SWTPM_CERT} \
--tpm2 \
--signkey "${TESTDIR}/data/signkey.pem" \
--issuercert "${TESTDIR}/data/issuercert.pem" \
@@ -97,9 +93,7 @@
--subject "OU=foo,L=NewYork,ST=NY,C=US" \
--pem \
--tpm-manufacturer IBM --tpm-model swtpm-libtpms --tpm-version 1.2 \
- --tpm-spec-family 2.0 --tpm-spec-revision 146 --tpm-spec-level 0
-
-if [ $? -ne 0 ]; then
+ --tpm-spec-family 2.0 --tpm-spec-revision 146 --tpm-spec-level 0; then
echo "Error: ${SWTPM_CERT} returned error code."
exit 1
fi
@@ -115,7 +109,7 @@
###################### Platform Certificate #####################
-${SWTPM_CERT} \
+if ! ${SWTPM_CERT} \
--tpm2 \
--type platform \
--signkey "${TESTDIR}/data/signkey.pem" \
@@ -128,9 +122,7 @@
--tpm-manufacturer IBM --tpm-model swtpm-libtpms --tpm-version 1.2 \
--platform-manufacturer Fedora \
--platform-model QEMU \
- --platform-version 2.1
-
-if [ $? -ne 0 ]; then
+ --platform-version 2.1; then
echo "Error: ${SWTPM_CERT} returned error code."
exit 1
fi
diff --git a/tests/test_tpm2_swtpm_localca b/tests/test_tpm2_swtpm_localca
index efad7bb..c71dd3b 100755
--- a/tests/test_tpm2_swtpm_localca
+++ b/tests/test_tpm2_swtpm_localca
@@ -62,7 +62,7 @@
params=$(echo "${testparams}" | cut -d"|" -f1)
usage=$(echo "${testparams}" | cut -d"|" -f2)
- ${SWTPM_LOCALCA} \
+ if ! ${SWTPM_LOCALCA} \
--type ek \
--ek "${ek}" \
--dir "${workdir}" \
@@ -71,8 +71,7 @@
--configfile "${workdir}/swtpm-localca.conf" \
--optsfile "${workdir}/swtpm-localca.options" \
--tpm-spec-family 2.0 --tpm-spec-revision 146 --tpm-spec-level 0 \
- ${params:+${params}}
- if [ $? -ne 0 ]; then
+ ${params:+${params}}; then
echo "Error: Test with parameters '$params' failed."
exit 1
fi
@@ -126,12 +125,11 @@
--inder --infile "${workdir}/ek.cert" \
--outfile "${workdir}/ek.pem"
- ${CERTTOOL} \
+ if ! ${CERTTOOL} \
--verify \
${verify_profile} \
--load-ca-certificate "${ISSUERCERT}" \
- --infile "${workdir}/ek.pem"
- if [ $? -ne 0 ]; then
+ --infile "${workdir}/ek.pem"; then
echo "Error: Could not verify certificate chain."
exit 1
fi
@@ -157,7 +155,7 @@
in=$(echo "$vmid" | cut -d"|" -f1)
exp=$(echo "$vmid" | cut -d"|" -f2)
- ${SWTPM_LOCALCA} \
+ if ! ${SWTPM_LOCALCA} \
--type ek \
--ek "${ek}" \
--dir "${workdir}" \
@@ -166,8 +164,7 @@
--configfile "${workdir}/swtpm-localca.conf" \
--optsfile "${workdir}/swtpm-localca.options" \
--tpm-spec-family 2.0 --tpm-spec-revision 146 --tpm-spec-level 0 \
- ${params:+${params}} &>/dev/null
- if [ $? -ne 0 ]; then
+ ${params:+${params}} &>/dev/null; then
echo "Error: Test with parameters '$params' failed."
exit 1
fi
diff --git a/tests/test_tpm2_swtpm_localca_pkcs11.test b/tests/test_tpm2_swtpm_localca_pkcs11.test
index 67c37d3..4c154a6 100755
--- a/tests/test_tpm2_swtpm_localca_pkcs11.test
+++ b/tests/test_tpm2_swtpm_localca_pkcs11.test
@@ -9,9 +9,6 @@
SWTPM_LOCALCA=${TOPBUILD}/src/swtpm_localca/swtpm_localca
workdir="$(mktemp -d)" || exit 1
-if [ $? -ne 0 ]; then
- exit 1
-fi
# Have softhsm_setup use 'workdir'.
export SOFTHSM_SETUP_CONFIGDIR="${workdir}"
@@ -51,8 +48,7 @@
export PIN="abcdef"
# Generate the PKCS11 token and key; it uses env. variable 'PIN'
-msg=$("${TESTDIR}/softhsm_setup" setup 2>&1)
-if [ $? -ne 0 ]; then
+if ! msg=$("${TESTDIR}/softhsm_setup" setup 2>&1); then
echo -e "Could not setup softhsm:\n${msg}"
echo "softhsm needs to be v2.3.0 or greater and pkcs11 correctly configured"
exit 77
@@ -66,11 +62,10 @@
cacert="${workdir}/swtpm-localca-rootca-cert.pem"
# first the private key
-msg=$(${CERTTOOL} \
+if ! msg=$(${CERTTOOL} \
--generate-privkey \
--outfile "${cakey}" \
- 2>&1)
-if [ $? -ne 0 ]; then
+ 2>&1); then
echo "Could not create root-CA key ${cakey}."
echo "${msg}"
exit 1
@@ -85,13 +80,12 @@
expiration_days = 3650
_EOF_
-msg=$(${CERTTOOL} \
+if ! msg=$(${CERTTOOL} \
--generate-self-signed \
--template "${template}" \
--outfile "${cacert}" \
--load-privkey "${cakey}" \
- 2>&1)
-if [ $? -ne 0 ]; then
+ 2>&1); then
echo "Could not create root CA."
echo "${msg}"
exit 1
@@ -101,11 +95,10 @@
pubkey="${workdir}/swtpm-localca-interm-pubkey.pem"
-msg=$(GNUTLS_PIN=${PIN} ${CERTTOOL} \
+if ! msg=$(GNUTLS_PIN=${PIN} ${CERTTOOL} \
--load-privkey "${pkcs11uri}" \
--pubkey-info \
- --outfile "${pubkey}")
-if [ $? -ne 0 ]; then
+ --outfile "${pubkey}"); then
echo "Could not get public key for pkcs11 uri key ($pkcs11uri}."
echo "${msg}"
exit 1
@@ -118,7 +111,7 @@
expiration_days = 3650
_EOF_
-msg=$(GNUTLS_PIN=${PIN} ${CERTTOOL} \
+if ! msg=$(GNUTLS_PIN=${PIN} ${CERTTOOL} \
--generate-certificate \
--template "${template}" \
--outfile "${ISSUERCERT}" \
@@ -126,8 +119,7 @@
--load-ca-certificate "${cacert}" \
--load-privkey "${pkcs11uri}" \
--load-pubkey "${pubkey}" \
- 2>&1)
-if [ $? -ne 0 ]; then
+ 2>&1); then
echo "Could not create intermediate CA"
echo "${msg}"
exit 1
@@ -164,7 +156,7 @@
params=$(echo "${testparams}" | cut -d"|" -f1)
usage=$(echo "${testparams}" | cut -d"|" -f2)
- msg=$(${SWTPM_LOCALCA} \
+ if ! msg=$(${SWTPM_LOCALCA} \
--type ek \
--ek "${ek}" \
--dir "${workdir}" \
@@ -173,8 +165,7 @@
--configfile "${workdir}/swtpm-localca.conf" \
--optsfile "${workdir}/swtpm-localca.options" \
--tpm-spec-family 2.0 --tpm-spec-revision 146 --tpm-spec-level 0 \
- ${params:+${params}} 2>&1)
- if [ $? -ne 0 ]; then
+ ${params:+${params}} 2>&1); then
echo "Error: Test with parameters '$params' failed."
echo "${msg}"
if [[ "${msg}" =~ The\ requested\ PKCS\ #11\ object\ is\ not\ available ]]; then
@@ -213,12 +204,11 @@
--inder --infile "${workdir}/ek.cert" \
--outfile "${workdir}/ek.pem"
- GNUTLS_PIN=${PIN} ${CERTTOOL} \
+ if ! GNUTLS_PIN=${PIN} ${CERTTOOL} \
--verify \
${verify_profile} \
--load-ca-certificate "${ISSUERCERT}" \
- --infile "${workdir}/ek.pem"
- if [ $? -ne 0 ]; then
+ --infile "${workdir}/ek.pem"; then
echo "Error: Could not verify certificate chain."
exit 1
fi
diff --git a/tests/test_tpm2_swtpm_setup_overwrite b/tests/test_tpm2_swtpm_setup_overwrite
index 930039c..f507ac9 100755
--- a/tests/test_tpm2_swtpm_setup_overwrite
+++ b/tests/test_tpm2_swtpm_setup_overwrite
@@ -26,15 +26,14 @@
dummydata="DUMMY"
echo "$dummydata" > "${statefile}"
-$SWTPM_SETUP \
+if ! $SWTPM_SETUP \
--tpm2 \
--not-overwrite \
--tpm-state "${workdir}" \
--config "${SWTPM_SETUP_CONF}" \
--logfile "${workdir}/logfile" \
- --tpm "${SWTPM_EXE} socket ${SWTPM_TEST_SECCOMP_OPT}"
-
-if [ $? -ne 0 ]; then
+ --tpm "${SWTPM_EXE} socket ${SWTPM_TEST_SECCOMP_OPT}";
+then
echo "Test 1 failed: Error: Could not run $SWTPM_SETUP."
echo "Setup Logfile:"
cat "${workdir}/logfile"
@@ -58,15 +57,14 @@
dummydata="DUMMY"
echo "$dummydata" > "${statefile}"
-$SWTPM_SETUP \
+if ! $SWTPM_SETUP \
--tpm2 \
--overwrite \
--tpm-state "${workdir}" \
--config "${SWTPM_SETUP_CONF}" \
--logfile "${workdir}/logfile" \
- --tpm "${SWTPM_EXE} socket ${SWTPM_TEST_SECCOMP_OPT}"
-
-if [ $? -ne 0 ]; then
+ --tpm "${SWTPM_EXE} socket ${SWTPM_TEST_SECCOMP_OPT}";
+then
echo "Test 2 failed: Error: Could not run $SWTPM_SETUP."
echo "Setup Logfile:"
cat "${workdir}/logfile"
@@ -96,7 +94,6 @@
--config "${SWTPM_SETUP_CONF}" \
--logfile "${workdir}/logfile" \
--tpm "${SWTPM_EXE} socket ${SWTPM_TEST_SECCOMP_OPT}"
-
if [ $? -ne 1 ]; then
echo "Test 3 failed: Error: $SWTPM_SETUP did not exit with exit code 1."
echo "Setup Logfile:"
diff --git a/tests/test_tpm2_vtpm_proxy b/tests/test_tpm2_vtpm_proxy
index 40256fe..87539ce 100755
--- a/tests/test_tpm2_vtpm_proxy
+++ b/tests/test_tpm2_vtpm_proxy
@@ -53,8 +53,7 @@
display_processes_by_name "$SWTPM"
-kill_quiet -0 "$PID"
-if [ $? -ne 0 ]; then
+if ! kill_quiet -0 "$PID"; then
echo "Error: Chardev TPM did not start."
exit 1
fi
@@ -72,8 +71,7 @@
fi
# Open access to the TPM
-exec 100<>"$TPM_DEVICE"
-if [ $? -ne 0 ]; then
+if ! exec 100<>"$TPM_DEVICE"; then
echo "Error: Could not open $TPM_DEVICE"
exit 1
fi
@@ -92,8 +90,7 @@
exec 100>&-
-kill_quiet -0 "$PID"
-if [ $? -ne 0 ]; then
+if ! kill_quiet -0 "$PID"; then
echo "Error: Chardev TPM must have crashed."
exit 1
fi
diff --git a/tests/test_vtpm_proxy b/tests/test_vtpm_proxy
index dfdc297..734ed5f 100755
--- a/tests/test_vtpm_proxy
+++ b/tests/test_vtpm_proxy
@@ -50,8 +50,7 @@
display_processes_by_name "$SWTPM"
-kill_quiet -0 "$PID"
-if [ $? -ne 0 ]; then
+if ! kill_quiet -0 "$PID"; then
echo "Error: Chardev TPM did not start."
exit 1
fi
@@ -81,8 +80,7 @@
fi
# Open access to the TPM
-exec 100<>"$TPM_DEVICE"
-if [ $? -ne 0 ]; then
+if ! exec 100<>"$TPM_DEVICE"; then
echo "Error: Could not open $TPM_DEVICE"
exit 1
fi
@@ -101,8 +99,7 @@
exec 100>&-
-kill_quiet -0 "$PID"
-if [ $? -ne 0 ]; then
+if ! kill_quiet -0 "$PID"; then
echo "Error: Chardev TPM must have crashed."
exit 1
fi