tests: Fix shellcheck issue SC2143 by using grep -q
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
diff --git a/tests/Makefile.am b/tests/Makefile.am
index e28e1bf..a7e19b0 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -241,10 +241,9 @@
# SC2009: Consider using pgrep instead of grepping ps output.
# 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 /*.
-# SC2143: Use grep -q instead of comparing output with [ -n .. ].
# 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,SC2143,SC2148,SC2181 \
+ shellcheck -e SC2001,SC2009,SC2010,SC2115,SC2148,SC2181 \
$(TESTS) $(TEST_UTILS) $(filter _test_%,$(EXTRA_DIST))
check: check-am check-display
diff --git a/tests/_test_setbuffersize b/tests/_test_setbuffersize
index c786ae5..3709c99 100755
--- a/tests/_test_setbuffersize
+++ b/tests/_test_setbuffersize
@@ -48,7 +48,7 @@
fi
cat "${OUTFILE}"
-if [ -z "$(grep "TPM buffersize" "${OUTFILE}" | grep 4096)" ]; then
+if ! grep "TPM buffersize" "${OUTFILE}" | grep -q 4096; then
echo "Error: The TPM buffersize of the ${SWTPM_INTERFACE} TPM is not 4096."
exit 1
fi
@@ -61,7 +61,7 @@
fi
cat "${OUTFILE}"
-if [ -z "$(grep "TPM buffersize" "${OUTFILE}" | grep 4000)" ]; then
+if ! grep "TPM buffersize" "${OUTFILE}" | grep -q 4000; then
echo "Error: The TPM buffersize of the ${SWTPM_INTERFACE} TPM is not 4000."
exit 1
fi
diff --git a/tests/_test_tpm2_derived_keys b/tests/_test_tpm2_derived_keys
index 6811fd6..371e83b 100755
--- a/tests/_test_tpm2_derived_keys
+++ b/tests/_test_tpm2_derived_keys
@@ -249,8 +249,8 @@
case "$(uname -s)" in
Linux)
# Only 64bit apps will link with libs in /lib64/ dirs
- if [ -n "$(grep -E "\/lib64\/" "/proc/${SWTPM_PID}/maps")" ] && \
- [ -n "$(lscpu | grep "Little Endian")" ]; then
+ if grep -q -E "\/lib64\/" "/proc/${SWTPM_PID}/maps" && \
+ lscpu | grep -q "Little Endian"; then
tx_cmd 1 0 "$test1_cmd" "$test1_exp" "" || exit 1 && echo "Test 1: OK"
tx_cmd 1 1 "$test2_cmd" "$test2_exp" "" || exit 1 && echo "Test 2: OK"
tx_cmd 1 1 "$test3_cmd" "$test3_exp" "" || exit 1 && echo "Test 3: OK"
diff --git a/tests/_test_tpm2_file_permissions b/tests/_test_tpm2_file_permissions
index 2b96c0d..ddc9fd9 100644
--- a/tests/_test_tpm2_file_permissions
+++ b/tests/_test_tpm2_file_permissions
@@ -38,7 +38,7 @@
# We need to copy swtpm and libswtpm_libtpms.so to the workdir
# so that swtpm_setup can access it as TESTUSER
-if [ -z "$(file "${SWTPM_EXE}" | grep ELF)" ]; then
+if ! file "${SWTPM_EXE}" | grep -q ELF; then
directory="$(dirname "${SWTPM_EXE}")/.libs"
if [ -d "${directory}" ]; then
cp "${directory}/swtpm" "${TPM_PATH}"
@@ -122,7 +122,7 @@
fi
# The log file must have grown
-if [ -z "$(grep "TestTest" "${LOGFILE}")" ]; then
+if ! grep -q "TestTest" "${LOGFILE}"; then
echo "Error: First line 'TestTest' missing in logfile."
exit 1
fi
@@ -206,7 +206,7 @@
echo "Error: State file was not changed."
exit 1
fi
-if [ -z "$(grep "TestTest" "${LOGFILE}")" ]; then
+if ! grep -q "TestTest" "${LOGFILE}"; then
echo "Error: First line 'TestTest' missing in logfile."
exit 1
fi
diff --git a/tests/_test_tpm2_setbuffersize b/tests/_test_tpm2_setbuffersize
index 85a2aef..98e69b8 100755
--- a/tests/_test_tpm2_setbuffersize
+++ b/tests/_test_tpm2_setbuffersize
@@ -48,7 +48,7 @@
fi
cat "${OUTFILE}"
-if [ -z "$(grep "TPM buffersize" "${OUTFILE}" | grep 4096)" ]; then
+if ! grep "TPM buffersize" "${OUTFILE}" | grep -q 4096; then
echo "Error: The TPM buffersize of the ${SWTPM_INTERFACE} TPM is not 4096."
exit 1
fi
@@ -61,7 +61,7 @@
fi
cat "${OUTFILE}"
-if [ -z "$(grep "TPM buffersize" "${OUTFILE}" | grep 4000)" ]; then
+if ! grep "TPM buffersize" "${OUTFILE}" | grep -q 4000; then
echo "Error: Could not set the buffersize of the ${SWTPM_INTERFACE} TPM to 4000."
exit 1
fi
diff --git a/tests/common b/tests/common
index 7b93eed..a7c857c 100644
--- a/tests/common
+++ b/tests/common
@@ -216,16 +216,16 @@
for ((loop = 0; loop < loops; loop++)); do
if [ -n "$NETSTAT" ]; then
- if [ -n "$(netstat -naptl 2>/dev/null |
- grep "LISTEN" |
- grep " $pid/" |
- grep ":$port ")" ]; then
+ if netstat -naptl 2>/dev/null |
+ grep "LISTEN" |
+ grep " $pid/" |
+ grep -q ":$port "; then
return 1
fi
else
- if [ -n "$(ss -nptl |
- grep ",pid=${pid}," |
- grep ":$port ")" ]; then
+ if ss -nptl | \
+ grep ",pid=${pid}," | \
+ grep -q ":$port "; then
return 1
fi
fi
@@ -250,16 +250,16 @@
for ((loop = 0; loop < loops; loop++)); do
if [ -n "$NETSTAT" ]; then
- if [ -z "$(netstat -naptl 2>/dev/null |
- grep "LISTEN" |
- grep " $pid/" |
- grep ":$port ")" ]; then
+ if ! netstat -naptl 2>/dev/null | \
+ grep "LISTEN" | \
+ grep " $pid/" | \
+ grep -q ":$port "; then
return 1
fi
else
- if [ -z "$(ss -nptl |
- grep ",pid=${pid}," |
- grep ":$port ")" ]; then
+ if ! ss -nptl | \
+ grep ",pid=${pid}," | \
+ grep -q ":$port "; then
return 1
fi
fi
@@ -920,12 +920,12 @@
local act_exe
if [[ "$(uname -s)" =~ Linux ]]; then
- if [ -z "$(file "${swtpm_exe}" | grep ELF)" ]; then
+ if ! file "${swtpm_exe}" | grep -q ELF; then
act_exe="$(dirname "${swtpm_exe}")"/.libs/"$(basename "${swtpm_exe}")"
else
act_exe="${swtpm_exe}"
fi
- if [ -n "$(nm "${act_exe}" | grep __asan_)" ]; then
+ if nm "${act_exe}" | grep -q "__asan_"; then
echo "${act_exe} is built with ASAN"
exit 77
fi
@@ -952,13 +952,13 @@
local pid="$1"
if [ -d "/proc/${pid}/fd" ]; then
- if [ -n "$(ls -l "/proc/${pid}/fd" | grep -E "\.lock\$")" ]; then
+ if ls -l "/proc/${pid}/fd" | grep -q -E "\.lock\$"; then
echo "Error: swtpm must not have storage locked"
ls -l "/proc/${pid}/fd"
exit 1
fi
elif [ -n "$(type -P lsof)" ]; then
- if [ -n "$(lsof -p "${pid}" | grep -e "\.lock\$")" ]; then
+ if lsof -p "${pid}" | grep -q -e "\.lock\$"; then
echo "Error: swtpm must not have storage locked"
lsof -p "${pid}"
exit 1
@@ -975,13 +975,13 @@
local pid="$1"
if [ -d "/proc/${pid}/fd" ]; then
- if [ -z "$(ls -l "/proc/${pid}/fd" | grep -E "\.lock\$")" ]; then
+ if ! ls -l "/proc/${pid}/fd" | grep -q -E "\.lock\$"; then
echo "Error: swtpm must have storage locked"
ls -l "/proc/${pid}/fd"
exit 1
fi
elif [ -n "$(type -P lsof)" ]; then
- if [ -z "$(lsof -p "${pid}" | grep -e "\.lock\$")" ]; then
+ if ! lsof -p "${pid}" | grep -q -e "\.lock\$"; then
echo "Error: swtpm must have storage locked"
lsof -p "${pid}"
exit 1
diff --git a/tests/test_cuse b/tests/test_cuse
index daadd5e..d4af576 100644
--- a/tests/test_cuse
+++ b/tests/test_cuse
@@ -11,8 +11,8 @@
exit 77
fi
-if [ -z "$(grep -E '#[[:blank:]]*define[[:blank:]]+WITH_CUSE[[:blank:]]+1[[:blank:]]*$' \
- "${PWD}/../config.h")" ]; then
+if ! grep -q -E '#[[:blank:]]*define[[:blank:]]+WITH_CUSE[[:blank:]]+1[[:blank:]]*$' \
+ "${PWD}/../config.h"; then
echo "Skipping test: swtpm was not compiled with CUSE interface"
exit 77
fi
diff --git a/tests/test_samples_create_tpmca b/tests/test_samples_create_tpmca
index 04bcb44..d649a91 100755
--- a/tests/test_samples_create_tpmca
+++ b/tests/test_samples_create_tpmca
@@ -225,7 +225,7 @@
"^TSS_TCSD_PORT = " \
${params}; do
if [ -n "${regex}" ] && \
- [ -z "$(grep -E "${regex}" "${SWTPM_LOCALCA_CONF}")" ]; then
+ ! grep -q -E "${regex}" "${SWTPM_LOCALCA_CONF}"; then
echo "Error: Could not find regex '${regex}' in CA config file."
cat "${SWTPM_LOCALCA_CONF}"
exit 1
@@ -286,7 +286,7 @@
for ((i=0; i < ${#regexs}; i++)); do \
if [ -n "${regexs[$i]}" ] && \
- [ -z "$(echo "${certinfo}" | grep -E "${regexs[$i]}")" ]; then
+ ! echo "${certinfo}" | grep -q -E "${regexs[$i]}"; then
echo "Error: Could not match regex '${regexs[$i]}' with certificate info:"
echo "${certinfo}"
exit 1
diff --git a/tests/test_swtpm_setup_create_cert b/tests/test_swtpm_setup_create_cert
index c48b0e2..48be3b6 100755
--- a/tests/test_swtpm_setup_create_cert
+++ b/tests/test_swtpm_setup_create_cert
@@ -96,7 +96,7 @@
exit 1
fi
-if [ -z "$(grep "ENCRYPTED PRIVATE KEY" "${workdir}/swtpm-localca-rootca-privkey.pem")" ]; then
+if ! grep -q "ENCRYPTED PRIVATE KEY" "${workdir}/swtpm-localca-rootca-privkey.pem"; then
echo "Error: Root CA's private key should be encrypted"
cat "${workdir}/swtpm-localca-rootca-privkey.pem"
exit 1
@@ -109,7 +109,7 @@
exit 1
fi
-if [ -z "$($CERTTOOL --inder --infile "${certfile}" -i | grep "2048 bits")" ]; then
+if ! $CERTTOOL --inder --infile "${certfile}" -i | grep -q "2048 bits"; then
echo "Error: EK file '${certfile}' is not an RSA 2048 bit key."
$CERTTOOL --inder --infile "${certfile}" -i
exit 1
@@ -119,8 +119,8 @@
expected1="Not After: Fri Dec 31 23:59:59 UTC 9999"
# 32bit machines
expected2="Not After: Thu Dec 31 23:23:23 UTC 2037"
-if [ -z "$(echo "${expiration}" | grep "${expected1}")" ] && \
- [ -z "$(echo "${expiration}" | grep "${expected2}")" ]; then
+if ! echo "${expiration}" | grep -q "${expected1}" && \
+ ! echo "${expiration}" | grep -q "${expected2}"; then
echo "Error: EK file '${certfile}' does not expire in 9999 or 2037"
echo "actual : ${expiration}"
echo "expected1: ${expected1}"
diff --git a/tests/test_swtpm_setup_overwrite b/tests/test_swtpm_setup_overwrite
index a9f47fc..009ae4e 100755
--- a/tests/test_swtpm_setup_overwrite
+++ b/tests/test_swtpm_setup_overwrite
@@ -40,7 +40,7 @@
exit 1
fi
-if [ -z "$(grep "${dummydata}" "${statefile}")" ]; then
+if ! grep -q "${dummydata}" "${statefile}"; then
echo "Test 1 failed: Error: The state file was unexpectedly overwritten."
echo "Setup Logfile:"
cat "${workdir}/logfile"
@@ -71,7 +71,7 @@
exit 1
fi
-if [ -n "$(grep "${dummydata}" "${statefile}")" ]; then
+if grep -q "${dummydata}" "${statefile}"; then
echo "Test 2 failed: Error: The state file was not overwritten."
echo "Setup Logfile:"
cat "${workdir}/logfile"
@@ -101,7 +101,7 @@
exit 1
fi
-if [ -z "$(grep "${dummydata}" "${statefile}")" ]; then
+if ! grep -q "${dummydata}" "${statefile}"; then
echo "Test 3 failed: Error: The state file was unexpectedly overwritten."
echo "Setup Logfile:"
cat "${workdir}/logfile"
diff --git a/tests/test_tpm12 b/tests/test_tpm12
index f298bd6..ea48647 100755
--- a/tests/test_tpm12
+++ b/tests/test_tpm12
@@ -130,7 +130,7 @@
TPM_AUDITING=${TPM_AUDITING} TPM_TRANSPORT=${TPM_TRANSPORT} timeout 40 ./test_console.sh \
--non-interactive "${tst}" >> "${TESTLOG}" </dev/null
# Ignore all errors that occurred in test 1
- if [ $tst != "1" ] && [ -n "$(grep "ERROR" "${TESTLOG}")" ]; then
+ if [ $tst != "1" ] && grep -q "ERROR" "${TESTLOG}"; then
echo "Error occurred!"
cat "${TESTLOG}"
exit 1
diff --git a/tests/test_tpm2_ibmtss2 b/tests/test_tpm2_ibmtss2
index 1dd4f52..569c3b1 100755
--- a/tests/test_tpm2_ibmtss2
+++ b/tests/test_tpm2_ibmtss2
@@ -99,7 +99,7 @@
git am < "${PATCHESDIR}/0009-Disable-getcapability-TPM_CAP_ACT.patch"
fi
-if [ -n "$(openssl version | grep -E "^OpenSSL 3")" ]; then
+if openssl version | grep -q -E "^OpenSSL 3"; then
git am < "${PATCHESDIR}/0010-Adjust-test-cases-for-OpenSSL-3.patch"
fi
@@ -127,7 +127,7 @@
ret=0
-if [ -n "$(grep -E "^ ERROR:" "${REGLOG}")" ]; then
+if grep -q -E "^ ERROR:" "${REGLOG}"; then
echo "There were test failures running the IBM TSS 2 tests"
grep -E "^ ERROR:" "${REGLOG}" -B2 -A2
ret=1
diff --git a/tests/test_tpm2_parameters b/tests/test_tpm2_parameters
index f6aa10c..0d3da9b 100755
--- a/tests/test_tpm2_parameters
+++ b/tests/test_tpm2_parameters
@@ -81,7 +81,7 @@
fi
}
-if [ -n "$($TPMAUTHORING --tpm2 --print-capabilities | grep tpm2-rsa-keysize-3072 )" ]; then
+if $TPMAUTHORING --tpm2 --print-capabilities | grep -q tpm2-rsa-keysize-3072; then
PARAMETERS+=( "${PARAMETERS_3072[@]}" )
fi
diff --git a/tests/test_tpm2_samples_create_tpmca.test b/tests/test_tpm2_samples_create_tpmca.test
index 8dd58cf..27bd4c8 100755
--- a/tests/test_tpm2_samples_create_tpmca.test
+++ b/tests/test_tpm2_samples_create_tpmca.test
@@ -20,7 +20,7 @@
exit 77
fi
-if [ -z "$(tpm2_ptool | grep ",config,")" ]; then
+if ! tpm2_ptool | grep -q ",config,"; then
echo "tpm2_ptool does not support the config command"
exit 77
fi
@@ -189,7 +189,7 @@
"^certserial = " \
"^SWTPM_PKCS11_PIN = mypin 123"; do
if [ -n "${regex}" ] && \
- [ -z "$(grep -E "${regex}" "${SWTPM_LOCALCA_CONF}")" ]; then
+ ! grep -q -E "${regex}" "${SWTPM_LOCALCA_CONF}"; then
echo "Error: Could not find regex '${regex}' in CA config file."
cat "${SWTPM_LOCALCA_CONF}"
exit 1
@@ -249,7 +249,7 @@
for ((i=0; i < ${#regexs}; i++)); do \
if [ -n "${regexs[$i]}" ] && \
- [ -z "$(echo "${certinfo}" | grep -E "${regexs[$i]}")" ]; then
+ ! echo "${certinfo}" | grep -q -E "${regexs[$i]}"; then
echo "Error: Could not match regex '${regexs[$i]}' with certificate info:"
echo "${certinfo}"
exit 1
diff --git a/tests/test_tpm2_save_load_state_2 b/tests/test_tpm2_save_load_state_2
index 0eecab8..6263f7d 100755
--- a/tests/test_tpm2_save_load_state_2
+++ b/tests/test_tpm2_save_load_state_2
@@ -77,7 +77,7 @@
echo "Error: createprimary failed."
exit 1
fi
- if [ -z "$(grep 80000000 "$TMPFILE")" ]; then
+ if ! grep -q 80000000 "$TMPFILE"; then
echo "Error: createprimary did not result in expected handle 80000000"
exit 1
fi
diff --git a/tests/test_tpm2_save_load_state_2_block b/tests/test_tpm2_save_load_state_2_block
index b596c85..39723e0 100755
--- a/tests/test_tpm2_save_load_state_2_block
+++ b/tests/test_tpm2_save_load_state_2_block
@@ -28,7 +28,7 @@
exit 77
fi
-if [ -z "$(fallocate --help 2>&1 | grep -E "\-\-posix")" ]; then
+if ! fallocate --help 2>&1 | grep -q -E "\-\-posix"; then
echo "This test requires fallocate to support --posix."
exit 77
fi
diff --git a/tests/test_tpm2_save_load_state_3 b/tests/test_tpm2_save_load_state_3
index f0d357b..aa5c005 100755
--- a/tests/test_tpm2_save_load_state_3
+++ b/tests/test_tpm2_save_load_state_3
@@ -221,7 +221,7 @@
echo "Error: createprimary failed."
exit 1
fi
- if [ -z "$(grep 80000000 "$TMPFILE")" ]; then
+ if ! grep -q 80000000 "$TMPFILE"; then
echo "Error: createprimary did not result in expected handle 80000000"
exit 1
fi
@@ -244,7 +244,7 @@
if [ "$check" -eq 1 ]; then
printf "Checking availability of key with perm. handle 0x81000000\n"
"${TOOLSPATH}/${PREFIX}getcapability" -cap 1 -pr 0x81000000 >"$TMPFILE"
- if [ -z "$(grep 81000000 "$TMPFILE")" ]; then
+ if ! grep -q 81000000 "$TMPFILE"; then
echo "Could not find key with permanent handle 0x81000000"
exit 1
fi
@@ -275,7 +275,7 @@
local i res rc ha
- if [ -z "$("$TOOLSPATH/${PREFIX}pcrallocate" | grep sha512)" ]; then
+ if ! "$TOOLSPATH/${PREFIX}pcrallocate" | grep -q sha512; then
echo " Skipping PCR Allocate test since it does not support sha512"
return 0
fi
@@ -286,13 +286,13 @@
for ((ha = 0; ha < 24; ha++)); do
"${TOOLSPATH}/${PREFIX}pcrread" -ha "${ha}" -halg sha512 > "$TMPFILE"
- if [ -z "$(grep "^count 1.*$" "$TMPFILE")" ]; then
+ if ! grep -q "^count 1.*$" "$TMPFILE"; then
echo "Error: PCR ${ha} in SHA512 bank should be available for read before reboot"
cat "$TMPFILE"
exit 1
fi
"${TOOLSPATH}/${PREFIX}pcrread" -ha "${ha}" -halg sha256 > "$TMPFILE"
- if [ -z "$(grep "^count 1.*$" "$TMPFILE")" ]; then
+ if ! grep -q "^count 1.*$" "$TMPFILE"; then
echo "Error: PCR ${ha} in SHA256 bank should be available for read before reboot"
cat "$TMPFILE"
exit 1
@@ -305,14 +305,14 @@
for ((ha = 0; ha < 24; ha++)); do
"${TOOLSPATH}/${PREFIX}pcrread" -ha "${ha}" -halg sha512 > "$TMPFILE"
- if [ -z "$(grep "^count 0.*$" "$TMPFILE")" ]; then
+ if ! grep -q "^count 0.*$" "$TMPFILE"; then
echo "Error: PCR ${ha} in SHA512 bank should be unavailable for read after reboot"
cat "$TMPFILE"
exit 1
fi
"${TOOLSPATH}/${PREFIX}pcrread" -ha "${ha}" -halg sha256 > "$TMPFILE"
- if [ -z "$(grep "^count 1.*$" "$TMPFILE")" ]; then
+ if ! grep -q "^count 1.*$" "$TMPFILE"; then
echo "Error: PCR ${ha} in SHA256 bank should be available for read after reboot"
exit 1
fi
@@ -498,7 +498,7 @@
echo "Error: createprimary for creating storage key failed."
exit 1
fi
- if [ -z "$(grep 80000000 "$TMPFILE")" ]; then
+ if ! grep -q 80000000 "$TMPFILE"; then
echo "Error: createprimary did not result in expected handle 80000000"
cat "$TMPFILE"
exit 1
@@ -553,7 +553,7 @@
echo "Error: createprimary failed."
exit 1
fi
- if [ -z "$(grep 80000000 "$TMPFILE")" ]; then
+ if ! grep -q 80000000 "$TMPFILE"; then
echo "Error: createprimary did not result in expected handle 80000000"
exit 1
fi
@@ -572,7 +572,7 @@
cat "$TMPFILE"
exit 1
fi
- if [ -z "$(grep 80000001 "$TMPFILE")" ]; then
+ if ! grep -q 80000001 "$TMPFILE"; then
echo "Error: load did not result in expected handle 80000001"
exit 1
fi
@@ -582,7 +582,7 @@
echo "Error: could not start HMAC sequence"
exit 1
fi
- if [ -z "$(grep 80000002 "$TMPFILE")" ]; then
+ if ! grep -q 80000002 "$TMPFILE"; then
echo "Error: load did not result in expected handle 80000002"
exit 1
fi
@@ -607,7 +607,7 @@
-hs 80000002 \
-if "${TMP2FILE}" -v |
tail -n 4 > "${TMPFILE}"
- if [ -z "$(grep " 6e 40 33 1a " "${TMPFILE}")" ]; then
+ if ! grep -q " 6e 40 33 1a " "${TMPFILE}"; then
echo "Error: Did not get expected result from completing HMAC sequence."
cat "$TMPFILE"
exit 1
@@ -633,7 +633,7 @@
echo "Error: createprimary failed."
exit 1
fi
- if [ -z "$(grep 80000000 "$TMPFILE")" ]; then
+ if ! grep -q 80000000 "$TMPFILE"; then
echo "Error: createprimary did not result in expected handle 80000000"
exit 1
fi
@@ -665,7 +665,7 @@
printf "Checking availability of key with handle 0x80000000\n"
"${TOOLSPATH}/${PREFIX}getcapability" -cap 1 -pr 0x80000000 > "$TMPFILE"
- if [ -z "$(grep 80000000 "$TMPFILE")" ]; then
+ if ! grep -q 80000000 "$TMPFILE"; then
echo "Could not find key with handle 0x80000000"
exit 1
fi
@@ -712,7 +712,7 @@
echo "Error: loadexternal failed."
exit 1
fi
- if [ -z "$(grep 80000001 "$TMPFILE")" ]; then
+ if ! grep -q 80000001 "$TMPFILE"; then
echo "Error: loadexternal did not result in expected handle 80000001"
exit 1
fi
@@ -730,7 +730,7 @@
echo "Error: contextload on context of public key failed."
exit 1
fi
- if [ -z "$(grep 80000001 "$TMPFILE")" ]; then
+ if ! grep -q 80000001 "$TMPFILE"; then
echo "Error: contextload did not result in expected handle 80000001"
exit 1
fi
diff --git a/tests/test_tpm2_swtpm_localca b/tests/test_tpm2_swtpm_localca
index 506cd76..efad7bb 100755
--- a/tests/test_tpm2_swtpm_localca
+++ b/tests/test_tpm2_swtpm_localca
@@ -23,7 +23,7 @@
source "${TESTDIR}/common"
-if [ -n "$(${CERTTOOL} --help | grep -E "\-\-verify-profile")" ]; then
+if ${CERTTOOL} --help | grep -q -E "\-\-verify-profile"; then
verify_profile="--verify-profile=medium"
fi
@@ -78,20 +78,20 @@
fi
# Signing key should always be password protected
- if [ -z "$(grep "ENCRYPTED PRIVATE KEY" "${SIGNINGKEY}")" ]; then
+ if ! grep -q "ENCRYPTED PRIVATE KEY" "${SIGNINGKEY}"; then
echo "Error: Signing key is not password protected."
exit 1
fi
# For the root CA's key we flip the password protection
if [ -n "${SWTPM_ROOTCA_PASSWORD}" ] ;then
- if [ -z "$(grep "ENCRYPTED PRIVATE KEY" "${workdir}/swtpm-localca-rootca-privkey.pem")" ]; then
+ if ! grep -q "ENCRYPTED PRIVATE KEY" "${workdir}/swtpm-localca-rootca-privkey.pem"; then
echo "Error: Root CA's private key is not password protected."
exit 1
fi
unset SWTPM_ROOTCA_PASSWORD
else
- if [ -n "$(grep "ENCRYPTED PRIVATE KEY" "${workdir}/swtpm-localca-rootca-privkey.pem")" ]; then
+ if grep -q "ENCRYPTED PRIVATE KEY" "${workdir}/swtpm-localca-rootca-privkey.pem"; then
echo "Error: Root CA's private key is password protected but should not be."
exit 1
fi
@@ -108,10 +108,10 @@
for u in $usage; do
echo "$u"
- if [ -z "$(${CERTTOOL} -i \
- --inder --infile "${workdir}/ek.cert" | \
- grep "Key Usage" -A2 | \
- grep "$u")" ]; then
+ if ! ${CERTTOOL} -i \
+ --inder --infile "${workdir}/ek.cert" | \
+ grep "Key Usage" -A2 | \
+ grep -q "$u"; then
echo "Error: Could not find key usage $u in key created " \
"with $params."
else
diff --git a/tests/test_tpm2_swtpm_localca_pkcs11.test b/tests/test_tpm2_swtpm_localca_pkcs11.test
index 17b6955..67c37d3 100755
--- a/tests/test_tpm2_swtpm_localca_pkcs11.test
+++ b/tests/test_tpm2_swtpm_localca_pkcs11.test
@@ -33,7 +33,7 @@
source "${TESTDIR}/common"
-if [ -n "$(${CERTTOOL} --help | grep -E "\-\-verify-profile")" ]; then
+if ${CERTTOOL} --help | grep -q -E "\-\-verify-profile"; then
verify_profile="--verify-profile=medium"
fi
@@ -195,10 +195,10 @@
IFS=","
for u in $usage; do
- if [ -z "$(${CERTTOOL} -i \
- --inder --infile "${workdir}/ek.cert" | \
- grep "Key Usage" -A2 | \
- grep "$u")" ]; then
+ if ! ${CERTTOOL} -i \
+ --inder --infile "${workdir}/ek.cert" | \
+ grep "Key Usage" -A2 | \
+ grep -q "$u"; then
echo "Error: Could not find key usage $u in key created " \
"with $params."
else
diff --git a/tests/test_tpm2_swtpm_setup_create_cert b/tests/test_tpm2_swtpm_setup_create_cert
index 898bd4e..a0abe72 100755
--- a/tests/test_tpm2_swtpm_setup_create_cert
+++ b/tests/test_tpm2_swtpm_setup_create_cert
@@ -60,8 +60,11 @@
export PATH=${TOPBUILD}/src/swtpm_cert:${PATH}
keysizes="2048"
-if [ -n "$($SWTPM_SETUP --tpm2 --print-capabilities |
- grep tpm2-rsa-keysize-3072 )" ]; then
+if ${SWTPM_SETUP} \
+ --tpm2 \
+ --tpm "${SWTPM_EXE} socket ${SWTPM_TEST_SECCOMP_OPT}" \
+ --print-capabilities |
+ grep -q tpm2-rsa-keysize-3072; then
keysizes+=" 3072"
fi
@@ -109,7 +112,7 @@
exit 1
fi
- if [ -z "$($CERTTOOL --inder --infile "${certfile}" -i | grep "${keysize} bits")" ]; then
+ if ! $CERTTOOL --inder --infile "${certfile}" -i | grep -q "${keysize} bits"; then
echo "Error: EK file '${certfile}' is not an RSA ${keysize} bit key."
$CERTTOOL --inder --infile "${certfile}" -i
exit 1
@@ -216,7 +219,7 @@
exit 1
fi
- if [ -z "$($CERTTOOL --inder --infile "${certfile}" -i | grep "384 bits")" ]; then
+ if ! $CERTTOOL --inder --infile "${certfile}" -i | grep -q "384 bits"; then
echo "Error: EK file '${certfile}' is not an ECC 384 bit key."
$CERTTOOL --inder --infile "${certfile}" -i
exit 1
diff --git a/tests/test_tpm2_swtpm_setup_overwrite b/tests/test_tpm2_swtpm_setup_overwrite
index 0efd649..930039c 100755
--- a/tests/test_tpm2_swtpm_setup_overwrite
+++ b/tests/test_tpm2_swtpm_setup_overwrite
@@ -41,7 +41,7 @@
exit 1
fi
-if [ -z "$(grep "${dummydata}" "${statefile}")" ]; then
+if ! grep -q "${dummydata}" "${statefile}"; then
echo "Test 1 failed: Error: The state file was unexpectedly overwritten."
echo "Setup Logfile:"
cat "${workdir}/logfile"
@@ -73,7 +73,7 @@
exit 1
fi
-if [ -n "$(grep "${dummydata}" "${statefile}")" ]; then
+if grep -q "${dummydata}" "${statefile}"; then
echo "Test 2 failed: Error: The state file was not overwritten."
echo "Setup Logfile:"
cat "${workdir}/logfile"
@@ -104,7 +104,7 @@
exit 1
fi
-if [ -z "$(grep "${dummydata}" "${statefile}")" ]; then
+if ! grep -q "${dummydata}" "${statefile}"; then
echo "Test 3 failed: Error: The state file was unexpectedly overwritten."
echo "Setup Logfile:"
cat "${workdir}/logfile"