]> git.proxmox.com Git - swtpm.git/commitdiff
tests: Add test case for chardev for swtpm --print-states option
authorStefan Berger <stefanb@linux.ibm.com>
Wed, 27 Oct 2021 01:38:00 +0000 (21:38 -0400)
committerStefan Berger <stefanb@us.ibm.com>
Wed, 27 Oct 2021 22:58:25 +0000 (18:58 -0400)
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
tests/common
tests/test_tpm2_print_states

index 8e85448a8f64628280fde607c91f8abdd78c8496..22d89bc744e24bf711be3ba32ac3b514bc5481d8 100644 (file)
@@ -869,14 +869,25 @@ function skip_test_no_tpm20()
        fi
 }
 
-# Check whether swtpm supports chardev interface
-function skip_test_no_chardev()
+# Test whether swtpm has a chardev interface; Returns 0 if true, 1 otherwise
+function test_swtpm_has_chardev()
 {
        local swtpm_exe="$1"
 
        local res=$(${swtpm_exe} chardev --help 2>&1 |
                    grep "Unsupported TPM interface")
-       if [ -n "${res}" ]; then
+       if [ -z "${res}" ]; then
+               return 0
+       fi
+       return 1
+}
+
+# Skip test if swtpm does not support chardev interface
+function skip_test_no_chardev()
+{
+       local swtpm_exe="$1"
+
+       if ! test_swtpm_has_chardev "${swtpm_exe}"; then
                echo "${swtpm_exe} does not support chardev interface"
                exit 77
        fi
index 57b208f78822807e2497aa331a6b565134b79a38..398fe779c301c3949fbb3b005696a72c6ff52487 100755 (executable)
@@ -17,4 +17,13 @@ bash _test_tpm2_print_states
 ret=$?
 [ $ret -ne 0 ] && [ $ret -ne 77 ] && exit $ret
 
+if test_swtpm_has_chardev "${SWTPM_EXE}"; then
+       export SWTPM_IFACE=chardev
+       bash _test_tpm2_print_states
+       ret=$?
+       [ $ret -ne 0 ] && [ $ret -ne 77 ] && exit $ret
+else
+       echo "Skip: No chardev available"
+fi
+
 exit 0