Skip to content

Commit

Permalink
tests: Derive support for CUSE from SWTPM_EXE help screen
Browse files Browse the repository at this point in the history
Use 'swtpm --help | grep cuse' to determine whether CUSE interface
is supported and CUSE related tests need to run. Make sure that
SWTPM_EXE is available when test_cuse is sourced.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
  • Loading branch information
stefanberger committed Aug 26, 2024
1 parent 54e2aef commit 7f8aa8b
Show file tree
Hide file tree
Showing 43 changed files with 48 additions and 44 deletions.
2 changes: 1 addition & 1 deletion tests/_test_encrypted_state
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ function cleanup()

trap "cleanup" EXIT

[ "${SWTPM_INTERFACE}" == cuse ] && source "${TESTDIR}/test_cuse"
source "${TESTDIR}/common"
[ "${SWTPM_INTERFACE}" == cuse ] && source "${TESTDIR}/test_cuse"

rm -f "$STATE_FILE" "$VOLATILE_STATE_FILE" 2>/dev/null

Expand Down
2 changes: 1 addition & 1 deletion tests/_test_getcap
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ function cleanup()

trap "cleanup" EXIT

[ "${SWTPM_INTERFACE}" == cuse ] && source "${TESTDIR}/test_cuse"
source "${TESTDIR}/common"
[ "${SWTPM_INTERFACE}" == cuse ] && source "${TESTDIR}/test_cuse"

rm -f "$STATE_FILE" "$VOLATILE_STATE_FILE" 2>/dev/null

Expand Down
2 changes: 1 addition & 1 deletion tests/_test_hashing
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ function cleanup()

trap "cleanup" EXIT

[ "${SWTPM_INTERFACE}" == cuse ] && source "${TESTDIR}/test_cuse"
source "${TESTDIR}/common"
[ "${SWTPM_INTERFACE}" == cuse ] && source "${TESTDIR}/test_cuse"

rm -f "$STATE_FILE" "$VOLATILE_STATE_FILE" 2>/dev/null

Expand Down
2 changes: 1 addition & 1 deletion tests/_test_hashing2
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ function cleanup()

trap "cleanup" EXIT

[ "${SWTPM_INTERFACE}" == cuse ] && source "${TESTDIR}/test_cuse"
source "${TESTDIR}/common"
[ "${SWTPM_INTERFACE}" == cuse ] && source "${TESTDIR}/test_cuse"

rm -f "$STATE_FILE" "$VOLATILE_STATE_FILE" 2>/dev/null

Expand Down
2 changes: 1 addition & 1 deletion tests/_test_init
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ function cleanup()

trap "cleanup" EXIT

[ "${SWTPM_INTERFACE}" == cuse ] && source "${TESTDIR}/test_cuse"
source "${TESTDIR}/common"
[ "${SWTPM_INTERFACE}" == cuse ] && source "${TESTDIR}/test_cuse"

rm -f "$STATE_FILE" "$VOLATILE_STATE_FILE" 2>/dev/null

Expand Down
2 changes: 1 addition & 1 deletion tests/_test_locality
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ function cleanup()

trap "cleanup" EXIT

[ "${SWTPM_INTERFACE}" == cuse ] && source "${TESTDIR}/test_cuse"
source "${TESTDIR}/common"
[ "${SWTPM_INTERFACE}" == cuse ] && source "${TESTDIR}/test_cuse"

rm -f "$STATE_FILE" "$VOLATILE_STATE_FILE" 2>/dev/null

Expand Down
2 changes: 1 addition & 1 deletion tests/_test_migration_key
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ function cleanup()

trap "cleanup" EXIT

[ "${SWTPM_INTERFACE}" == cuse ] && source "${TESTDIR}/test_cuse"
source "${TESTDIR}/common"
[ "${SWTPM_INTERFACE}" == cuse ] && source "${TESTDIR}/test_cuse"

# make a backup of the volatile state
TPM_PATH=$tpmstatedir
Expand Down
2 changes: 1 addition & 1 deletion tests/_test_print_capabilities
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ TESTDIR=${abs_top_testdir:-$(dirname "$0")}

PATH=$ROOT/src/swtpm:$PATH

[ "${SWTPM_IFACE}" == "cuse" ] && source "${TESTDIR}/test_cuse"
source "${TESTDIR}/common"
[ "${SWTPM_IFACE}" == "cuse" ] && source "${TESTDIR}/test_cuse"

if ! msg="$(${SWTPM_EXE} "${SWTPM_IFACE}" --print-capabilities 2>&1)"; then
echo "Error: Could not pass --print-capabilities"
Expand Down
2 changes: 1 addition & 1 deletion tests/_test_print_states
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ TESTDIR=${abs_top_testdir:-$(dirname "$0")}

PATH=$ROOT/src/swtpm:$PATH

[ "${SWTPM_IFACE}" == "cuse" ] && source "${TESTDIR}/test_cuse"
source "${TESTDIR}/common"
[ "${SWTPM_IFACE}" == "cuse" ] && source "${TESTDIR}/test_cuse"

trap "cleanup" SIGTERM EXIT

Expand Down
2 changes: 1 addition & 1 deletion tests/_test_resume_volatile
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ function cleanup()

trap "cleanup" EXIT

[ "${SWTPM_INTERFACE}" == cuse ] && source "${TESTDIR}/test_cuse"
source "${TESTDIR}/common"
[ "${SWTPM_INTERFACE}" == cuse ] && source "${TESTDIR}/test_cuse"

TPM_PATH=$tpmstatedir
VOLATILE_STATE_FILE="$TPM_PATH/tpm-00.volatilestate"
Expand Down
2 changes: 1 addition & 1 deletion tests/_test_save_load_encrypted_state
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ function cleanup()

trap "cleanup" EXIT

[ "${SWTPM_INTERFACE}" == cuse ] && source "${TESTDIR}/test_cuse"
source "${TESTDIR}/common"
[ "${SWTPM_INTERFACE}" == cuse ] && source "${TESTDIR}/test_cuse"

rm -f "$STATE_FILE" "$VOLATILE_STATE_FILE" 2>/dev/null

Expand Down
2 changes: 1 addition & 1 deletion tests/_test_save_load_state
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ function cleanup()

trap "cleanup" EXIT

[ "${SWTPM_INTERFACE}" == cuse ] && source "${TESTDIR}/test_cuse"
source "${TESTDIR}/common"
[ "${SWTPM_INTERFACE}" == cuse ] && source "${TESTDIR}/test_cuse"

rm -f "$STATE_FILE" "$VOLATILE_STATE_FILE" 2>/dev/null

Expand Down
2 changes: 1 addition & 1 deletion tests/_test_setbuffersize
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ function cleanup()

trap "cleanup" EXIT

[ "${SWTPM_INTERFACE}" == cuse ] && source "${TESTDIR}/test_cuse"
source "${TESTDIR}/common"
[ "${SWTPM_INTERFACE}" == cuse ] && source "${TESTDIR}/test_cuse"

rm -f "$STATE_FILE" "$VOLATILE_STATE_FILE" 2>/dev/null

Expand Down
2 changes: 1 addition & 1 deletion tests/_test_swtpm_bios
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ function cleanup()

trap "cleanup" EXIT

[ "${SWTPM_INTERFACE}" == cuse ] && source "${TESTDIR}/test_cuse"
source "${TESTDIR}/common"
[ "${SWTPM_INTERFACE}" == cuse ] && source "${TESTDIR}/test_cuse"

rm -f "$STATE_FILE" "$VOLATILE_STATE_FILE" 2>/dev/null

Expand Down
2 changes: 1 addition & 1 deletion tests/_test_tpm2_avoid_da_lockout
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ function cleanup()

trap "cleanup" EXIT

[ "${SWTPM_INTERFACE}" == "cuse" ] && source "${TESTDIR}/test_cuse"
source "${TESTDIR}/common"
source "${TESTDIR}/test_common"
[ "${SWTPM_INTERFACE}" == "cuse" ] && source "${TESTDIR}/test_cuse"

TPM_PATH=$TPM_PATH run_swtpm "${SWTPM_INTERFACE}" \
--tpm2 \
Expand Down
2 changes: 1 addition & 1 deletion tests/_test_tpm2_derived_keys
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ function cleanup()

trap "cleanup" EXIT

[ "${SWTPM_INTERFACE}" == "cuse" ] && source "${TESTDIR}/test_cuse"
source "${TESTDIR}/common"
[ "${SWTPM_INTERFACE}" == "cuse" ] && source "${TESTDIR}/test_cuse"

TPM_PATH=$tpmstatedir

Expand Down
2 changes: 1 addition & 1 deletion tests/_test_tpm2_encrypted_state
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ function cleanup()

trap "cleanup" EXIT

[ "${SWTPM_INTERFACE}" == "cuse" ] && source "${TESTDIR}/test_cuse"
source "${TESTDIR}/common"
[ "${SWTPM_INTERFACE}" == "cuse" ] && source "${TESTDIR}/test_cuse"

rm -f "$STATE_FILE" "$VOLATILE_STATE_FILE" 2>/dev/null

Expand Down
2 changes: 1 addition & 1 deletion tests/_test_tpm2_file_permissions
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ function cleanup()

trap "cleanup" EXIT

[ "${SWTPM_INTERFACE}" == cuse ] && source "${TESTDIR}/test_cuse"
source "${TESTDIR}/common"
[ "${SWTPM_INTERFACE}" == cuse ] && source "${TESTDIR}/test_cuse"
SWTPM_SETUP_CONF=${TPM_PATH}/swtpm_setup.conf

cat <<_EOF_ > "${SWTPM_SETUP_CONF}"
Expand Down
2 changes: 1 addition & 1 deletion tests/_test_tpm2_getcap
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ function cleanup()

trap "cleanup" EXIT

[ "${SWTPM_INTERFACE}" == "cuse" ] && source "${TESTDIR}/test_cuse"
source "${TESTDIR}/common"
[ "${SWTPM_INTERFACE}" == "cuse" ] && source "${TESTDIR}/test_cuse"

rm -f "$STATE_FILE" "$VOLATILE_STATE_FILE" 2>/dev/null

Expand Down
2 changes: 1 addition & 1 deletion tests/_test_tpm2_hashing
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ function cleanup()

trap "cleanup" EXIT

[ "${SWTPM_INTERFACE}" == "cuse" ] && source "${TESTDIR}/test_cuse"
source "${TESTDIR}/common"
[ "${SWTPM_INTERFACE}" == "cuse" ] && source "${TESTDIR}/test_cuse"

rm -f "$STATE_FILE" "$VOLATILE_STATE_FILE" 2>/dev/null

Expand Down
2 changes: 1 addition & 1 deletion tests/_test_tpm2_hashing2
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ function cleanup()

trap "cleanup" EXIT

[ "${SWTPM_INTERFACE}" == "cuse" ] && source "${TESTDIR}/test_cuse"
source "${TESTDIR}/common"
[ "${SWTPM_INTERFACE}" == "cuse" ] && source "${TESTDIR}/test_cuse"

rm -f "$STATE_FILE" "$VOLATILE_STATE_FILE" 2>/dev/null

Expand Down
2 changes: 1 addition & 1 deletion tests/_test_tpm2_hashing3
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ function cleanup()

trap "cleanup" EXIT

[ "${SWTPM_INTERFACE}" == "cuse" ] && source "${TESTDIR}/test_cuse"
source "${TESTDIR}/common"
[ "${SWTPM_INTERFACE}" == "cuse" ] && source "${TESTDIR}/test_cuse"

rm -f "$STATE_FILE" "$VOLATILE_STATE_FILE" 2>/dev/null

Expand Down
2 changes: 1 addition & 1 deletion tests/_test_tpm2_init
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ function cleanup()

trap "cleanup" EXIT

[ "${SWTPM_INTERFACE}" == "cuse" ] && source "${TESTDIR}/test_cuse"
source "${TESTDIR}/common"
[ "${SWTPM_INTERFACE}" == "cuse" ] && source "${TESTDIR}/test_cuse"

rm -f "$STATE_FILE" "$VOLATILE_STATE_FILE" 2>/dev/null

Expand Down
2 changes: 1 addition & 1 deletion tests/_test_tpm2_locality
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ function cleanup()

trap "cleanup" EXIT

[ "${SWTPM_INTERFACE}" == "cuse" ] && source "${TESTDIR}/test_cuse"
source "${TESTDIR}/common"
[ "${SWTPM_INTERFACE}" == "cuse" ] && source "${TESTDIR}/test_cuse"

rm -f "$STATE_FILE" "$VOLATILE_STATE_FILE" 2>/dev/null

Expand Down
2 changes: 1 addition & 1 deletion tests/_test_tpm2_migration_key
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ logfile="$(mktemp)" || exit 1
SWTPM_CMD_UNIX_PATH=${tpmstatedir}/unix-cmd.sock
SWTPM_CTRL_UNIX_PATH=${tpmstatedir}/unix-ctrl.sock

[ "${SWTPM_INTERFACE}" == "cuse" ] && source "${TESTDIR}/test_cuse"
source "${TESTDIR}/common"
[ "${SWTPM_INTERFACE}" == "cuse" ] && source "${TESTDIR}/test_cuse"

# make a backup of the volatile state
TPM_PATH=$tpmstatedir
Expand Down
2 changes: 1 addition & 1 deletion tests/_test_tpm2_print_capabilities
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ TESTDIR=${abs_top_testdir:-$(dirname "$0")}

PATH=$ROOT/src/swtpm:$PATH

[ "${SWTPM_IFACE}" == "cuse" ] && source "${TESTDIR}/test_cuse"
source "${TESTDIR}/common"
[ "${SWTPM_IFACE}" == "cuse" ] && source "${TESTDIR}/test_cuse"

if ! msg="$(${SWTPM_EXE} "${SWTPM_IFACE}" --tpm2 --print-capabilities 2>&1)"; then
echo "Error: Could not pass --print-capabilities"
Expand Down
2 changes: 1 addition & 1 deletion tests/_test_tpm2_print_states
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ TESTDIR=${abs_top_testdir:-$(dirname "$0")}

PATH=$ROOT/src/swtpm:$PATH

[ "${SWTPM_IFACE}" == "cuse" ] && source "${TESTDIR}/test_cuse"
source "${TESTDIR}/common"
[ "${SWTPM_IFACE}" == "cuse" ] && source "${TESTDIR}/test_cuse"

trap "cleanup" SIGTERM EXIT

Expand Down
2 changes: 1 addition & 1 deletion tests/_test_tpm2_probe
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ function cleanup()

trap "cleanup" EXIT

[ "${SWTPM_INTERFACE}" == "cuse" ] && source "${TESTDIR}/test_cuse"
source "${TESTDIR}/common"
[ "${SWTPM_INTERFACE}" == "cuse" ] && source "${TESTDIR}/test_cuse"

rm -f "$STATE_FILE" "$VOLATILE_STATE_FILE" 2>/dev/null

Expand Down
2 changes: 1 addition & 1 deletion tests/_test_tpm2_resume_volatile
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ function cleanup()

trap "cleanup" EXIT

[ "${SWTPM_INTERFACE}" == "cuse" ] && source "${TESTDIR}/test_cuse"
source "${TESTDIR}/common"
[ "${SWTPM_INTERFACE}" == "cuse" ] && source "${TESTDIR}/test_cuse"

TPM_PATH=$tpmstatedir
VOLATILE_STATE_FILE="$TPM_PATH/tpm2-00.volatilestate"
Expand Down
2 changes: 1 addition & 1 deletion tests/_test_tpm2_save_load_encrypted_state
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ function cleanup()

trap "cleanup" EXIT

[ "${SWTPM_INTERFACE}" == "cuse" ] && source "${TESTDIR}/test_cuse"
source "${TESTDIR}/common"
[ "${SWTPM_INTERFACE}" == "cuse" ] && source "${TESTDIR}/test_cuse"

rm -f "$STATE_FILE" "$VOLATILE_STATE_FILE" 2>/dev/null

Expand Down
2 changes: 1 addition & 1 deletion tests/_test_tpm2_save_load_state
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ function cleanup()

trap "cleanup" EXIT

[ "${SWTPM_INTERFACE}" == "cuse" ] && source "${TESTDIR}/test_cuse"
source "${TESTDIR}/common"
[ "${SWTPM_INTERFACE}" == "cuse" ] && source "${TESTDIR}/test_cuse"

rm -f "$STATE_FILE" "$VOLATILE_STATE_FILE" 2>/dev/null

Expand Down
2 changes: 1 addition & 1 deletion tests/_test_tpm2_save_load_state_da_timeout
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ function cleanup()

trap "cleanup" EXIT

[ "${SWTPM_INTERFACE}" == "cuse" ] && source "${TESTDIR}/test_cuse"
source "${TESTDIR}/common"
[ "${SWTPM_INTERFACE}" == "cuse" ] && source "${TESTDIR}/test_cuse"

rm -f "$STATE_FILE" "$VOLATILE_STATE_FILE" 2>/dev/null

Expand Down
2 changes: 1 addition & 1 deletion tests/_test_tpm2_save_load_state_locking
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ function cleanup()

trap "cleanup" EXIT

[ "${SWTPM_INTERFACE}" == "cuse" ] && source "${TESTDIR}/test_cuse"
source "${TESTDIR}/common"
[ "${SWTPM_INTERFACE}" == "cuse" ] && source "${TESTDIR}/test_cuse"

TPM_PATH=$TPM_PATH run_swtpm "${SWTPM_INTERFACE}" \
--migration release-lock-outgoing \
Expand Down
2 changes: 1 addition & 1 deletion tests/_test_tpm2_savestate
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ function cleanup()

trap "cleanup" EXIT

[ "${SWTPM_INTERFACE}" == "cuse" ] && source "${TESTDIR}/test_cuse"
source "${TESTDIR}/common"
[ "${SWTPM_INTERFACE}" == "cuse" ] && source "${TESTDIR}/test_cuse"

rm -f "$STATE_FILE" "$VOLATILE_STATE_FILE" 2>/dev/null

Expand Down
2 changes: 1 addition & 1 deletion tests/_test_tpm2_setbuffersize
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ function cleanup()

trap "cleanup" EXIT

[ "${SWTPM_INTERFACE}" == cuse ] && source "${TESTDIR}/test_cuse"
source "${TESTDIR}/common"
[ "${SWTPM_INTERFACE}" == cuse ] && source "${TESTDIR}/test_cuse"

rm -f "$STATE_FILE" "$VOLATILE_STATE_FILE" 2>/dev/null

Expand Down
2 changes: 1 addition & 1 deletion tests/_test_tpm2_swtpm_bios
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ function cleanup()

trap "cleanup" EXIT

[ "${SWTPM_INTERFACE}" == "cuse" ] && source "${TESTDIR}/test_cuse"
source "${TESTDIR}/common"
[ "${SWTPM_INTERFACE}" == "cuse" ] && source "${TESTDIR}/test_cuse"

rm -f "$STATE_FILE" "$VOLATILE_STATE_FILE" 2>/dev/null

Expand Down
2 changes: 1 addition & 1 deletion tests/_test_tpm2_volatilestate
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ function cleanup()

trap "cleanup" EXIT

[ "${SWTPM_INTERFACE}" == "cuse" ] && source "${TESTDIR}/test_cuse"
source "${TESTDIR}/common"
[ "${SWTPM_INTERFACE}" == "cuse" ] && source "${TESTDIR}/test_cuse"

rm -f "$STATE_FILE" "$VOLATILE_STATE_FILE" 2>/dev/null

Expand Down
2 changes: 1 addition & 1 deletion tests/_test_tpm2_wrongorder
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ function cleanup()

trap "cleanup" EXIT

[ "${SWTPM_INTERFACE}" == "cuse" ] && source "${TESTDIR}/test_cuse"
source "${TESTDIR}/common"
[ "${SWTPM_INTERFACE}" == "cuse" ] && source "${TESTDIR}/test_cuse"

rm -f "$STATE_FILE" "$VOLATILE_STATE_FILE" 2>/dev/null

Expand Down
2 changes: 1 addition & 1 deletion tests/_test_tpm_probe
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ function cleanup()

trap "cleanup" EXIT

[ "${SWTPM_INTERFACE}" == "cuse" ] && source "${TESTDIR}/test_cuse"
source "${TESTDIR}/common"
[ "${SWTPM_INTERFACE}" == "cuse" ] && source "${TESTDIR}/test_cuse"

rm -f "$STATE_FILE" "$VOLATILE_STATE_FILE" 2>/dev/null

Expand Down
Loading

0 comments on commit 7f8aa8b

Please sign in to comment.