mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-12-22 13:45:38 +00:00
qemufirmwaretest: Test qemuFirmwareFetchConfigs()
Signed-off-by: Michal Privoznik <mprivozn@redhat.com> Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
This commit is contained in:
parent
3c876d2428
commit
31eb3093c0
@ -705,6 +705,7 @@ qemusecuritytest_LDADD = $(qemu_LDADDS) $(LDADDS)
|
|||||||
qemufirmwaretest_SOURCES = \
|
qemufirmwaretest_SOURCES = \
|
||||||
qemufirmwaretest.c \
|
qemufirmwaretest.c \
|
||||||
testutils.h testutils.c \
|
testutils.h testutils.c \
|
||||||
|
virfilewrapper.c virfilewrapper.h \
|
||||||
$(NULL)
|
$(NULL)
|
||||||
qemufirmwaretest_LDADD = $(qemu_LDADDS) $(LDADDS)
|
qemufirmwaretest_LDADD = $(qemu_LDADDS) $(LDADDS)
|
||||||
|
|
||||||
|
1
tests/qemufirmwaredata/etc/qemu/firmware/40-ovmf-sb-keys.json
Symbolic link
1
tests/qemufirmwaredata/etc/qemu/firmware/40-ovmf-sb-keys.json
Symbolic link
@ -0,0 +1 @@
|
|||||||
|
../../../usr/share/qemu/firmware/50-ovmf-sb-keys.json
|
@ -1,7 +1,9 @@
|
|||||||
#include <config.h>
|
#include <config.h>
|
||||||
|
|
||||||
#include "testutils.h"
|
#include "testutils.h"
|
||||||
|
#include "virfilewrapper.h"
|
||||||
#include "qemu/qemu_firmware.h"
|
#include "qemu/qemu_firmware.h"
|
||||||
|
#include "configmake.h"
|
||||||
|
|
||||||
#define VIR_FROM_THIS VIR_FROM_QEMU
|
#define VIR_FROM_THIS VIR_FROM_QEMU
|
||||||
|
|
||||||
@ -50,11 +52,66 @@ testParseFormatFW(const void *opaque)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static int
|
||||||
|
testFWPrecedence(const void *opaque ATTRIBUTE_UNUSED)
|
||||||
|
{
|
||||||
|
VIR_AUTOFREE(char *) fakehome = NULL;
|
||||||
|
VIR_AUTOSTRINGLIST fwList = NULL;
|
||||||
|
size_t nfwList;
|
||||||
|
size_t i;
|
||||||
|
const char *expected[] = {
|
||||||
|
PREFIX "/share/qemu/firmware/40-bios.json",
|
||||||
|
SYSCONFDIR "/qemu/firmware/40-ovmf-sb-keys.json",
|
||||||
|
PREFIX "/share/qemu/firmware/50-ovmf-sb-keys.json",
|
||||||
|
PREFIX "/share/qemu/firmware/61-ovmf.json",
|
||||||
|
PREFIX "/share/qemu/firmware/70-aavmf.json",
|
||||||
|
};
|
||||||
|
|
||||||
|
if (VIR_STRDUP(fakehome, abs_srcdir "/qemufirmwaredata/home/user/.config") < 0)
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
setenv("XDG_CONFIG_HOME", fakehome, 1);
|
||||||
|
|
||||||
|
if (qemuFirmwareFetchConfigs(&fwList, false) < 0)
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
if (!fwList) {
|
||||||
|
fprintf(stderr, "Expected a non-NULL result, but got a NULL result\n");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
nfwList = virStringListLength((const char **)fwList);
|
||||||
|
if (nfwList != ARRAY_CARDINALITY(expected)) {
|
||||||
|
fprintf(stderr, "Expected %zu paths, got %zu\n",
|
||||||
|
ARRAY_CARDINALITY(expected), nfwList);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (i = 0; i < ARRAY_CARDINALITY(expected); i++) {
|
||||||
|
if (STRNEQ_NULLABLE(expected[i], fwList[i])) {
|
||||||
|
fprintf(stderr,
|
||||||
|
"Unexpected path (i=%zu). Expected %s got %s \n",
|
||||||
|
i, expected[i], NULLSTR(fwList[i]));
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
static int
|
static int
|
||||||
mymain(void)
|
mymain(void)
|
||||||
{
|
{
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
|
|
||||||
|
virFileWrapperAddPrefix(SYSCONFDIR "/qemu/firmware",
|
||||||
|
abs_srcdir "/qemufirmwaredata/etc/qemu/firmware");
|
||||||
|
virFileWrapperAddPrefix(PREFIX "/share/qemu/firmware",
|
||||||
|
abs_srcdir "/qemufirmwaredata/usr/share/qemu/firmware");
|
||||||
|
virFileWrapperAddPrefix("/home/user/.config/qemu/firmware",
|
||||||
|
abs_srcdir "/qemufirmwaredata/home/user/.config/qemu/firmware");
|
||||||
|
|
||||||
#define DO_PARSE_TEST(filename) \
|
#define DO_PARSE_TEST(filename) \
|
||||||
do { \
|
do { \
|
||||||
if (virTestRun("QEMU FW " filename, \
|
if (virTestRun("QEMU FW " filename, \
|
||||||
@ -62,11 +119,14 @@ mymain(void)
|
|||||||
ret = -1; \
|
ret = -1; \
|
||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
DO_PARSE_TEST("bios.json");
|
DO_PARSE_TEST("usr/share/qemu/firmware/40-bios.json");
|
||||||
DO_PARSE_TEST("ovmf-sb-keys.json");
|
DO_PARSE_TEST("usr/share/qemu/firmware/50-ovmf-sb-keys.json");
|
||||||
DO_PARSE_TEST("ovmf-sb.json");
|
DO_PARSE_TEST("usr/share/qemu/firmware/60-ovmf-sb.json");
|
||||||
DO_PARSE_TEST("ovmf.json");
|
DO_PARSE_TEST("usr/share/qemu/firmware/61-ovmf.json");
|
||||||
DO_PARSE_TEST("aavmf.json");
|
DO_PARSE_TEST("usr/share/qemu/firmware/70-aavmf.json");
|
||||||
|
|
||||||
|
if (virTestRun("QEMU FW precedence test", testFWPrecedence, NULL) < 0)
|
||||||
|
ret = -1;
|
||||||
|
|
||||||
return ret == 0 ? EXIT_SUCCESS : EXIT_FAILURE;
|
return ret == 0 ? EXIT_SUCCESS : EXIT_FAILURE;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user