提交 04406d87 编写于 作者: M Michal Privoznik

test: Introduce qemufirmwaretest

Test firmware description parsing so far.

The test files come from three locations:
1) ovmf-sb-keys.json and ovmf-sb.json come from OVMF
package from RHEL-7 (with slight name change to reflect their
features in filename too),

2) bios.json and aavmf.json come from example JSON documents from
firmware.json from qemu's git (3a0adfc9bf),

3) ovmf.json is then copied from ovmf-sb.json and stripped
of SECURE_BOOT and REQUIRES_SMM flags, OVMF path change,
description update and machine type expanded for both pc and q35
machine types.
Signed-off-by: NMichal Privoznik <mprivozn@redhat.com>
Reviewed-by: NDaniel P. Berrangé <berrange@redhat.com>
Acked-by: NLaszlo Ersek <lersek@redhat.com>
上级 8b5b80f4
...@@ -132,6 +132,7 @@ EXTRA_DIST = \ ...@@ -132,6 +132,7 @@ EXTRA_DIST = \
qemuxml2xmloutdata \ qemuxml2xmloutdata \
qemustatusxml2xmldata \ qemustatusxml2xmldata \
qemumemlockdata \ qemumemlockdata \
qemufirmwaredata \
secretxml2xmlin \ secretxml2xmlin \
securityselinuxhelperdata \ securityselinuxhelperdata \
securityselinuxlabeldata \ securityselinuxlabeldata \
...@@ -292,6 +293,7 @@ test_programs += qemuxml2argvtest qemuxml2xmltest \ ...@@ -292,6 +293,7 @@ test_programs += qemuxml2argvtest qemuxml2xmltest \
qemublocktest \ qemublocktest \
qemumigparamstest \ qemumigparamstest \
qemusecuritytest \ qemusecuritytest \
qemufirmwaretest \
$(NULL) $(NULL)
test_helpers += qemucapsprobe test_helpers += qemucapsprobe
test_libraries += libqemumonitortestutils.la \ test_libraries += libqemumonitortestutils.la \
...@@ -700,6 +702,12 @@ qemusecuritytest_SOURCES = \ ...@@ -700,6 +702,12 @@ qemusecuritytest_SOURCES = \
testutilsqemu.h testutilsqemu.c testutilsqemu.h testutilsqemu.c
qemusecuritytest_LDADD = $(qemu_LDADDS) $(LDADDS) qemusecuritytest_LDADD = $(qemu_LDADDS) $(LDADDS)
qemufirmwaretest_SOURCES = \
qemufirmwaretest.c \
testutils.h testutils.c \
$(NULL)
qemufirmwaretest_LDADD = $(qemu_LDADDS) $(LDADDS)
else ! WITH_QEMU else ! WITH_QEMU
EXTRA_DIST += qemuxml2argvtest.c qemuxml2xmltest.c qemuargv2xmltest.c \ EXTRA_DIST += qemuxml2argvtest.c qemuxml2xmltest.c qemuargv2xmltest.c \
domainsnapshotxml2xmltest.c \ domainsnapshotxml2xmltest.c \
...@@ -713,6 +721,7 @@ EXTRA_DIST += qemuxml2argvtest.c qemuxml2xmltest.c qemuargv2xmltest.c \ ...@@ -713,6 +721,7 @@ EXTRA_DIST += qemuxml2argvtest.c qemuxml2xmltest.c qemuargv2xmltest.c \
qemumigparamstest.c \ qemumigparamstest.c \
qemusecuritytest.c qemusecuritytest.h \ qemusecuritytest.c qemusecuritytest.h \
qemusecuritymock.c \ qemusecuritymock.c \
qemufirmwaretest.c \
$(QEMUMONITORTESTUTILS_SOURCES) $(QEMUMONITORTESTUTILS_SOURCES)
endif ! WITH_QEMU endif ! WITH_QEMU
......
{
"description": "UEFI firmware for ARM64 virtual machines",
"interface-types": [
"uefi"
],
"mapping": {
"device": "flash",
"executable": {
"filename": "/usr/share/AAVMF/AAVMF_CODE.fd",
"format": "raw"
},
"nvram-template": {
"filename": "/usr/share/AAVMF/AAVMF_VARS.fd",
"format": "raw"
}
},
"targets": [
{
"architecture": "aarch64",
"machines": [
"virt-*"
]
}
],
"features": [
],
"tags": [
"-a AARCH64",
"-p ArmVirtPkg/ArmVirtQemu.dsc",
"-t GCC48",
"-b DEBUG",
"-D DEBUG_PRINT_ERROR_LEVEL=0x80000000"
]
}
{
"description": "SeaBIOS",
"interface-types": [
"bios"
],
"mapping": {
"device": "memory",
"filename": "/usr/share/seabios/bios-256k.bin"
},
"targets": [
{
"architecture": "i386",
"machines": [
"pc-i440fx-*",
"pc-q35-*"
]
},
{
"architecture": "x86_64",
"machines": [
"pc-i440fx-*",
"pc-q35-*"
]
}
],
"features": [
"acpi-s3",
"acpi-s4"
],
"tags": [
"CONFIG_BOOTSPLASH=n",
"CONFIG_ROM_SIZE=256",
"CONFIG_USE_SMM=n"
]
}
{
"description": "OVMF with SB+SMM, SB enabled, MS certs enrolled",
"interface-types": [
"uefi"
],
"mapping": {
"device": "flash",
"executable": {
"filename": "/usr/share/OVMF/OVMF_CODE.secboot.fd",
"format": "raw"
},
"nvram-template": {
"filename": "/usr/share/OVMF/OVMF_VARS.secboot.fd",
"format": "raw"
}
},
"targets": [
{
"architecture": "x86_64",
"machines": [
"pc-q35-*"
]
}
],
"features": [
"acpi-s3",
"amd-sev",
"enrolled-keys",
"requires-smm",
"secure-boot",
"verbose-dynamic"
],
"tags": [
]
}
{
"description": "OVMF with SB+SMM, empty varstore",
"interface-types": [
"uefi"
],
"mapping": {
"device": "flash",
"executable": {
"filename": "/usr/share/OVMF/OVMF_CODE.secboot.fd",
"format": "raw"
},
"nvram-template": {
"filename": "/usr/share/OVMF/OVMF_VARS.fd",
"format": "raw"
}
},
"targets": [
{
"architecture": "x86_64",
"machines": [
"pc-q35-*"
]
}
],
"features": [
"acpi-s3",
"amd-sev",
"requires-smm",
"secure-boot",
"verbose-dynamic"
],
"tags": [
]
}
{
"description": "UEFI firmware for x86_64 virtual machines",
"interface-types": [
"uefi"
],
"mapping": {
"device": "flash",
"executable": {
"filename": "/usr/share/OVMF/OVMF_CODE.fd",
"format": "raw"
},
"nvram-template": {
"filename": "/usr/share/OVMF/OVMF_VARS.fd",
"format": "raw"
}
},
"targets": [
{
"architecture": "x86_64",
"machines": [
"pc-i440fx-*",
"pc-q35-*"
]
}
],
"features": [
"acpi-s3",
"amd-sev",
"verbose-dynamic"
],
"tags": [
]
}
#include <config.h>
#include "testutils.h"
#include "qemu/qemu_firmware.h"
#define VIR_FROM_THIS VIR_FROM_QEMU
/* A very basic test. Parse given JSON firmware description into
* an internal structure, format it back and compare with the
* contents of the file (minus some keys that are not parsed).
*/
static int
testParseFormatFW(const void *opaque)
{
const char *filename = opaque;
VIR_AUTOFREE(char *) path = NULL;
VIR_AUTOPTR(qemuFirmware) fw = NULL;
VIR_AUTOFREE(char *) buf = NULL;
VIR_AUTOPTR(virJSONValue) json = NULL;
VIR_AUTOFREE(char *) expected = NULL;
VIR_AUTOFREE(char *) actual = NULL;
if (virAsprintf(&path, "%s/qemufirmwaredata/%s",
abs_srcdir, filename) < 0)
return -1;
if (!(fw = qemuFirmwareParse(path)))
return -1;
if (virFileReadAll(path,
1024 * 1024, /* 1MiB */
&buf) < 0)
return -1;
if (!(json = virJSONValueFromString(buf)))
return -1;
/* Description and tags are not parsed. */
if (virJSONValueObjectRemoveKey(json, "description", NULL) < 0 ||
virJSONValueObjectRemoveKey(json, "tags", NULL) < 0)
return -1;
if (!(expected = virJSONValueToString(json, true)))
return -1;
if (!(actual = qemuFirmwareFormat(fw)))
return -1;
return virTestCompareToString(expected, actual);
}
static int
mymain(void)
{
int ret = 0;
#define DO_PARSE_TEST(filename) \
do { \
if (virTestRun("QEMU FW " filename, \
testParseFormatFW, filename) < 0) \
ret = -1; \
} while (0)
DO_PARSE_TEST("bios.json");
DO_PARSE_TEST("ovmf-sb-keys.json");
DO_PARSE_TEST("ovmf-sb.json");
DO_PARSE_TEST("ovmf.json");
DO_PARSE_TEST("aavmf.json");
return ret == 0 ? EXIT_SUCCESS : EXIT_FAILURE;
}
VIR_TEST_MAIN(mymain)
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册