[PATCH 2/3] testutilsqemu: Mock virTPMSwtpmSetupCapsGet()

Michal Privoznik mprivozn at redhat.com
Fri Jul 29 07:42:12 UTC 2022


In a recent commit of v8.5.0-85-g430ab88ab1 I've made domaincaps
XML report supported TPM versions. This was done by calling
virTPMSwtpmSetupCapsGet(). But this function isn't mocked and
thus domaincapstest calls the real implementation, which tries to
execute swtpm_setup binary. This fails, because
virFindFileInPath() is mocked in such way that it returns NULL
for anything else than qemu-*.

Anyway, while the real binary is not executed after all, we
should mock the function which tries to execute it so that
predictable result is returned.

Signed-off-by: Michal Privoznik <mprivozn at redhat.com>
---
 tests/testutilsqemu.c | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)

diff --git a/tests/testutilsqemu.c b/tests/testutilsqemu.c
index 6dabbaf36a..00dd9871d1 100644
--- a/tests/testutilsqemu.c
+++ b/tests/testutilsqemu.c
@@ -146,6 +146,24 @@ bool virTPMHasSwtpm(void)
 }
 
 
+bool
+virTPMSwtpmSetupCapsGet(virTPMSwtpmSetupFeature cap)
+{
+    switch (cap) {
+    case VIR_TPM_SWTPM_SETUP_FEATURE_CMDARG_PWDFILE_FD:
+    case VIR_TPM_SWTPM_SETUP_FEATURE_CMDARG_CREATE_CONFIG_FILES:
+    case VIR_TPM_SWTPM_SETUP_FEATURE_TPM12_NOT_NEED_ROOT:
+    case VIR_TPM_SWTPM_SETUP_FEATURE_CMDARG_RECONFIGURE_PCR_BANKS:
+    case VIR_TPM_SWTPM_SETUP_FEATURE_TPM_1_2:
+    case VIR_TPM_SWTPM_SETUP_FEATURE_TPM_2_0:
+    case VIR_TPM_SWTPM_SETUP_FEATURE_LAST:
+        break;
+    }
+
+    return false;
+}
+
+
 virCapsHostNUMA *
 virCapabilitiesHostNUMANewHost(void)
 {
-- 
2.35.1



More information about the libvir-list mailing list