* [PATCH 2/3] tests/qtest: Move mkimg() and have_qemu_img() from libqos to libqtest
2023-07-04 7:16 [PATCH 0/3] Test the docs/config/q35-*.cfg config files Thomas Huth
2023-07-04 7:16 ` [PATCH 1/3] tests/qtest/readconfig-test: Allow testing for arbitrary memory sizes Thomas Huth
@ 2023-07-04 7:16 ` Thomas Huth
2023-07-04 7:16 ` [PATCH 3/3] tests/qtest/readconfig: Test the docs/config/q35-*.cfg files Thomas Huth
2 siblings, 0 replies; 4+ messages in thread
From: Thomas Huth @ 2023-07-04 7:16 UTC (permalink / raw)
To: qemu-devel; +Cc: Paolo Bonzini, Laurent Vivier, Daniel P . Berrangé
These two functions can be useful for other qtests beside the
qos-test, too, so move them to libqtest instead.
Signed-off-by: Thomas Huth <thuth@redhat.com>
---
tests/qtest/libqos/libqos.h | 2 --
tests/qtest/libqtest.h | 20 ++++++++++++++
tests/qtest/libqos/libqos.c | 49 +---------------------------------
tests/qtest/libqtest.c | 52 +++++++++++++++++++++++++++++++++++++
4 files changed, 73 insertions(+), 50 deletions(-)
diff --git a/tests/qtest/libqos/libqos.h b/tests/qtest/libqos/libqos.h
index 12d05b2365..c04950e2b1 100644
--- a/tests/qtest/libqos/libqos.h
+++ b/tests/qtest/libqos/libqos.h
@@ -27,8 +27,6 @@ QOSState *qtest_boot(QOSOps *ops, const char *cmdline_fmt, ...)
G_GNUC_PRINTF(2, 3);
void qtest_common_shutdown(QOSState *qs);
void qtest_shutdown(QOSState *qs);
-bool have_qemu_img(void);
-void mkimg(const char *file, const char *fmt, unsigned size_mb);
void mkqcow2(const char *file, unsigned size_mb);
void migrate(QOSState *from, QOSState *to, const char *uri);
void prepare_blkdebug_script(const char *debug_fn, const char *event);
diff --git a/tests/qtest/libqtest.h b/tests/qtest/libqtest.h
index 913acc3d5c..3a71bc45fc 100644
--- a/tests/qtest/libqtest.h
+++ b/tests/qtest/libqtest.h
@@ -994,4 +994,24 @@ bool qtest_qom_get_bool(QTestState *s, const char *path, const char *property);
*/
pid_t qtest_pid(QTestState *s);
+/**
+ * have_qemu_img:
+ *
+ * Returns: true if "qemu-img" is available.
+ */
+bool have_qemu_img(void);
+
+/**
+ * mkimg:
+ * @file: File name of the image that should be created
+ * @fmt: Format, e.g. "qcow2" or "raw"
+ * @size_mb: Size of the image in megabytes
+ *
+ * Create a disk image with qemu-img. Note that the QTEST_QEMU_IMG
+ * environment variable must point to the qemu-img file.
+ *
+ * Returns: true if the image has been created successfully.
+ */
+bool mkimg(const char *file, const char *fmt, unsigned size_mb);
+
#endif
diff --git a/tests/qtest/libqos/libqos.c b/tests/qtest/libqos/libqos.c
index 5ffda080ec..5c0fa1f7c5 100644
--- a/tests/qtest/libqos/libqos.c
+++ b/tests/qtest/libqos/libqos.c
@@ -137,56 +137,9 @@ void migrate(QOSState *from, QOSState *to, const char *uri)
migrate_allocator(&from->alloc, &to->alloc);
}
-bool have_qemu_img(void)
-{
- char *rpath;
- const char *path = getenv("QTEST_QEMU_IMG");
- if (!path) {
- return false;
- }
-
- rpath = realpath(path, NULL);
- if (!rpath) {
- return false;
- } else {
- free(rpath);
- return true;
- }
-}
-
-void mkimg(const char *file, const char *fmt, unsigned size_mb)
-{
- gchar *cli;
- bool ret;
- int rc;
- GError *err = NULL;
- char *qemu_img_path;
- gchar *out, *out2;
- char *qemu_img_abs_path;
-
- qemu_img_path = getenv("QTEST_QEMU_IMG");
- g_assert(qemu_img_path);
- qemu_img_abs_path = realpath(qemu_img_path, NULL);
- g_assert(qemu_img_abs_path);
-
- cli = g_strdup_printf("%s create -f %s %s %uM", qemu_img_abs_path,
- fmt, file, size_mb);
- ret = g_spawn_command_line_sync(cli, &out, &out2, &rc, &err);
- if (err || !g_spawn_check_exit_status(rc, &err)) {
- fprintf(stderr, "%s\n", err->message);
- g_error_free(err);
- }
- g_assert(ret && !err);
-
- g_free(out);
- g_free(out2);
- g_free(cli);
- free(qemu_img_abs_path);
-}
-
void mkqcow2(const char *file, unsigned size_mb)
{
- return mkimg(file, "qcow2", size_mb);
+ g_assert_true(mkimg(file, "qcow2", size_mb));
}
void prepare_blkdebug_script(const char *debug_fn, const char *event)
diff --git a/tests/qtest/libqtest.c b/tests/qtest/libqtest.c
index 79152f0ec3..c22dfc30d3 100644
--- a/tests/qtest/libqtest.c
+++ b/tests/qtest/libqtest.c
@@ -1742,3 +1742,55 @@ bool qtest_qom_get_bool(QTestState *s, const char *path, const char *property)
return b;
}
+
+bool have_qemu_img(void)
+{
+ char *rpath;
+ const char *path = getenv("QTEST_QEMU_IMG");
+ if (!path) {
+ return false;
+ }
+
+ rpath = realpath(path, NULL);
+ if (!rpath) {
+ return false;
+ } else {
+ free(rpath);
+ return true;
+ }
+}
+
+bool mkimg(const char *file, const char *fmt, unsigned size_mb)
+{
+ gchar *cli;
+ bool ret;
+ int rc;
+ GError *err = NULL;
+ char *qemu_img_path;
+ gchar *out, *out2;
+ char *qemu_img_abs_path;
+
+ qemu_img_path = getenv("QTEST_QEMU_IMG");
+ if (!qemu_img_path) {
+ return false;
+ }
+ qemu_img_abs_path = realpath(qemu_img_path, NULL);
+ if (!qemu_img_abs_path) {
+ return false;
+ }
+
+ cli = g_strdup_printf("%s create -f %s %s %uM", qemu_img_abs_path,
+ fmt, file, size_mb);
+ ret = g_spawn_command_line_sync(cli, &out, &out2, &rc, &err);
+ if (err || !g_spawn_check_exit_status(rc, &err)) {
+ fprintf(stderr, "%s\n", err->message);
+ g_error_free(err);
+ }
+
+ g_free(out);
+ g_free(out2);
+ g_free(cli);
+ free(qemu_img_abs_path);
+
+ return ret && !err;
+}
--
2.39.3
^ permalink raw reply related [flat|nested] 4+ messages in thread* [PATCH 3/3] tests/qtest/readconfig: Test the docs/config/q35-*.cfg files
2023-07-04 7:16 [PATCH 0/3] Test the docs/config/q35-*.cfg config files Thomas Huth
2023-07-04 7:16 ` [PATCH 1/3] tests/qtest/readconfig-test: Allow testing for arbitrary memory sizes Thomas Huth
2023-07-04 7:16 ` [PATCH 2/3] tests/qtest: Move mkimg() and have_qemu_img() from libqos to libqtest Thomas Huth
@ 2023-07-04 7:16 ` Thomas Huth
2 siblings, 0 replies; 4+ messages in thread
From: Thomas Huth @ 2023-07-04 7:16 UTC (permalink / raw)
To: qemu-devel; +Cc: Paolo Bonzini, Laurent Vivier, Daniel P . Berrangé
Test that we can successfully parse the docs/config/q35-emulated.cfg,
docs/config/q35-virtio-graphical.cfg and docs/config/q35-virtio-serial.cfg
config files (the "...-serial.cfg" file is a subset of the graphical
config file, so we skip that in quick mode).
These config files use two hard-coded image names which we have to
replace with unique temporary files to avoid race conditions in case
the tests are run in parallel. So after creating the temporary image
files, we also have to create a copy of the config file where we
replaced the hard-coded image names.
If KVM is not available, we also have to disable the "accel" lines.
Once everything is in place, we can start QEMU with the modified
config file and check that everything is available in QEMU.
Signed-off-by: Thomas Huth <thuth@redhat.com>
---
tests/qtest/readconfig-test.c | 196 ++++++++++++++++++++++++++++++++++
1 file changed, 196 insertions(+)
diff --git a/tests/qtest/readconfig-test.c b/tests/qtest/readconfig-test.c
index 74526f3af2..760f974e63 100644
--- a/tests/qtest/readconfig-test.c
+++ b/tests/qtest/readconfig-test.c
@@ -197,6 +197,189 @@ static void test_docs_config_ich9(void)
qtest_quit(qts);
}
+#if defined(CONFIG_POSIX) && defined(CONFIG_SLIRP)
+
+static char *make_temp_img(const char *template, const char *format, int size)
+{
+ GError *error = NULL;
+ char *temp_name;
+ int fd;
+
+ /* Create a temporary image names */
+ fd = g_file_open_tmp(template, &temp_name, &error);
+ if (fd == -1) {
+ fprintf(stderr, "unable to create file: %s\n", error->message);
+ g_error_free(error);
+ return NULL;
+ }
+ close(fd);
+
+ if (!mkimg(temp_name, format, size)) {
+ fprintf(stderr, "qemu-img failed to create %s\n", temp_name);
+ g_free(temp_name);
+ return NULL;
+ }
+
+ return temp_name;
+}
+
+struct device {
+ const char *name;
+ const char *type;
+};
+
+static void test_docs_q35(const char *input_file, struct device *devices)
+{
+ QTestState *qts;
+ QDict *resp;
+ QObject *qobj;
+ int ret, i;
+ g_autofree char *cfg_file = NULL, *sedcmd = NULL;
+ g_autofree char *hd_file = NULL, *cd_file = NULL;
+
+ /* Check that all the devices are available in the QEMU binary */
+ for (i = 0; devices[i].name; i++) {
+ if (!qtest_has_device(devices[i].type)) {
+ g_test_skip("one of the required devices is not available");
+ return;
+ }
+ }
+
+ hd_file = make_temp_img("qtest_disk_XXXXXX.qcow2", "qcow2", 1);
+ cd_file = make_temp_img("qtest_cdrom_XXXXXX.iso", "raw", 1);
+ if (!hd_file || !cd_file) {
+ g_test_skip("could not create disk images");
+ goto cleanup;
+ }
+
+ /* Create a temporary config file where we replace the disk image names */
+ ret = g_file_open_tmp("q35-emulated-XXXXXX.cfg", &cfg_file, NULL);
+ if (ret == -1) {
+ g_test_skip("could not create temporary config file");
+ goto cleanup;
+ }
+ close(ret);
+
+ sedcmd = g_strdup_printf("sed -e 's,guest.qcow2,%s,' -e 's,install.iso,%s,'"
+ " %s %s > '%s'",
+ hd_file, cd_file,
+ !qtest_has_accel("kvm") ? "-e '/accel/d'" : "",
+ input_file, cfg_file);
+ ret = system(sedcmd);
+ if (ret) {
+ g_test_skip("could not modify temporary config file");
+ goto cleanup;
+ }
+
+ qts = qtest_initf("-machine none -nodefaults -readconfig %s", cfg_file);
+
+ /* Check memory size */
+ resp = qtest_qmp(qts, "{ 'execute': 'query-memdev' }");
+ test_x86_memdev_resp(qdict_get(resp, "return"), "pc.ram", 1024);
+ qobject_unref(resp);
+
+ resp = qtest_qmp(qts, "{ 'execute': 'qom-list',"
+ " 'arguments': {'path': '/machine/peripheral' }}");
+ qobj = qdict_get(resp, "return");
+
+ /* Check that all the devices have been created */
+ for (i = 0; devices[i].name; i++) {
+ test_object_available(qobj, devices[i].name, devices[i].type);
+ }
+
+ qobject_unref(resp);
+
+ qtest_quit(qts);
+
+cleanup:
+ if (hd_file) {
+ unlink(hd_file);
+ }
+ if (cd_file) {
+ unlink(cd_file);
+ }
+ if (cfg_file) {
+ unlink(cfg_file);
+ }
+}
+
+static void test_docs_q35_emulated(void)
+{
+ struct device devices[] = {
+ { "ich9-pcie-port-1", "ioh3420" },
+ { "ich9-pcie-port-2", "ioh3420" },
+ { "ich9-pcie-port-3", "ioh3420" },
+ { "ich9-pcie-port-4", "ioh3420" },
+ { "ich9-pci-bridge", "i82801b11-bridge" },
+ { "ich9-ehci-1", "ich9-usb-ehci1" },
+ { "ich9-ehci-2", "ich9-usb-ehci2" },
+ { "ich9-uhci-1", "ich9-usb-uhci1" },
+ { "ich9-uhci-2", "ich9-usb-uhci2" },
+ { "ich9-uhci-3", "ich9-usb-uhci3" },
+ { "ich9-uhci-4", "ich9-usb-uhci4" },
+ { "ich9-uhci-5", "ich9-usb-uhci5" },
+ { "ich9-uhci-6", "ich9-usb-uhci6" },
+ { "sata-disk", "ide-hd" },
+ { "sata-optical-disk", "ide-cd" },
+ { "net", "e1000" },
+ { "video", "VGA" },
+ { "ich9-hda-audio", "ich9-intel-hda" },
+ { "ich9-hda-duplex", "hda-duplex" },
+ { NULL, NULL }
+ };
+
+ test_docs_q35("docs/config/q35-emulated.cfg", devices);
+}
+
+static void test_docs_q35_virtio_graphical(void)
+{
+ struct device devices[] = {
+ { "pcie.1", "pcie-root-port" },
+ { "pcie.2", "pcie-root-port" },
+ { "pcie.3", "pcie-root-port" },
+ { "pcie.4", "pcie-root-port" },
+ { "pcie.5", "pcie-root-port" },
+ { "pcie.6", "pcie-root-port" },
+ { "pcie.7", "pcie-root-port" },
+ { "pcie.8", "pcie-root-port" },
+ { "scsi", "virtio-scsi-pci" },
+ { "scsi-disk", "scsi-hd" },
+ { "scsi-optical-disk", "scsi-cd" },
+ { "net", "virtio-net-pci" },
+ { "usb", "nec-usb-xhci" },
+ { "tablet", "usb-tablet" },
+ { "video", "qxl-vga" },
+ { "sound", "ich9-intel-hda" },
+ { "duplex", "hda-duplex" },
+ { NULL, NULL }
+ };
+
+ test_docs_q35("docs/config/q35-virtio-graphical.cfg", devices);
+}
+
+static void test_docs_q35_virtio_serial(void)
+{
+ struct device devices[] = {
+ { "pcie.1", "pcie-root-port" },
+ { "pcie.2", "pcie-root-port" },
+ { "pcie.3", "pcie-root-port" },
+ { "pcie.4", "pcie-root-port" },
+ { "pcie.5", "pcie-root-port" },
+ { "pcie.6", "pcie-root-port" },
+ { "pcie.7", "pcie-root-port" },
+ { "pcie.8", "pcie-root-port" },
+ { "scsi", "virtio-scsi-pci" },
+ { "scsi-disk", "scsi-hd" },
+ { "scsi-optical-disk", "scsi-cd" },
+ { "net", "virtio-net-pci" },
+ { NULL, NULL }
+ };
+
+ test_docs_q35("docs/config/q35-virtio-serial.cfg", devices);
+}
+
+#endif /* CONFIG_LINUX */
+
int main(int argc, char *argv[])
{
const char *arch;
@@ -211,6 +394,19 @@ int main(int argc, char *argv[])
qtest_has_device("ich9-usb-uhci1")) {
qtest_add_func("readconfig/x86/ich9-ehci-uhci", test_docs_config_ich9);
}
+#if defined(CONFIG_POSIX) && defined(CONFIG_SLIRP)
+ qtest_add_func("readconfig/x86/q35-emulated", test_docs_q35_emulated);
+ qtest_add_func("readconfig/x86/q35-virtio-graphical",
+ test_docs_q35_virtio_graphical);
+ if (g_test_slow()) {
+ /*
+ * q35-virtio-serial.cfg is a subset of q35-virtio-graphical.cfg,
+ * so we can skip the test in quick mode
+ */
+ qtest_add_func("readconfig/x86/q35-virtio-serial",
+ test_docs_q35_virtio_serial);
+ }
+#endif
}
#if defined(CONFIG_SPICE) && !defined(__FreeBSD__)
qtest_add_func("readconfig/spice", test_spice);
--
2.39.3
^ permalink raw reply related [flat|nested] 4+ messages in thread