qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Thomas Huth <thuth@redhat.com>
To: qemu-devel@nongnu.org, Peter Maydell <peter.maydell@linaro.org>
Subject: [PULL 14/16] tests/qtest/readconfig: Test docs/config/q35-emulated.cfg
Date: Mon,  6 Mar 2023 14:30:00 +0100	[thread overview]
Message-ID: <20230306133002.418421-15-thuth@redhat.com> (raw)
In-Reply-To: <20230306133002.418421-1-thuth@redhat.com>

This config file uses accel = "kvm", so it can only work on Linux.
It also uses two hard-coded image names which we have to replace
with unique temporary files to avoid race conditions. 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.
Once everything is in place, we can start QEMU with this config
file and check that everything is available in QEMU.

Message-Id: <20230228211533.201837-7-thuth@redhat.com>
Signed-off-by: Thomas Huth <thuth@redhat.com>
---
 tests/qtest/readconfig-test.c | 131 ++++++++++++++++++++++++++++++++++
 1 file changed, 131 insertions(+)

diff --git a/tests/qtest/readconfig-test.c b/tests/qtest/readconfig-test.c
index 533623f638..fe64376e85 100644
--- a/tests/qtest/readconfig-test.c
+++ b/tests/qtest/readconfig-test.c
@@ -197,6 +197,132 @@ static void test_docs_config_ich9(void)
     qtest_quit(qts);
 }
 
+#ifdef CONFIG_LINUX
+
+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;
+}
+
+static void test_docs_q35_emulated(void)
+{
+    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;
+
+    struct {
+        const char *name;
+        const char *type;
+    } 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" },
+    };
+
+    /* Check that all the devices are available in the QEMU binary */
+    for (i = 0; i < ARRAY_SIZE(devices); 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,'"
+                             " docs/config/q35-emulated.cfg > '%s'",
+                             hd_file, cd_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; i < ARRAY_SIZE(devices); 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);
+    }
+}
+
+#endif /* CONFIG_LINUX */
+
 int main(int argc, char *argv[])
 {
     const char *arch;
@@ -208,6 +334,11 @@ int main(int argc, char *argv[])
         g_str_equal(arch, "x86_64")) {
         qtest_add_func("readconfig/x86/memdev", test_x86_memdev);
         qtest_add_func("readconfig/x86/ich9-ehci-uhci", test_docs_config_ich9);
+#ifdef CONFIG_LINUX
+        if (qtest_has_accel("kvm")) {
+            qtest_add_func("readconfig/x86/q35-emulated", test_docs_q35_emulated);
+        }
+#endif
     }
 #ifdef CONFIG_SPICE
     qtest_add_func("readconfig/spice", test_spice);
-- 
2.31.1



  parent reply	other threads:[~2023-03-06 13:32 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-03-06 13:29 [PULL 00/16] Final tests, s390x and misc updates before the soft freeze Thomas Huth
2023-03-06 13:29 ` [PULL 01/16] docs/about/build-platforms: Refine the distro support policy Thomas Huth
2023-03-06 13:29 ` [PULL 02/16] Hexagon (meson.build): define min bison version Thomas Huth
2023-03-06 13:29 ` [PULL 03/16] test: Check vnc enable before compiling vnc test Thomas Huth
2023-03-06 13:29 ` [PULL 04/16] include/hw/i386: Clean up includes in x86.h Thomas Huth
2023-03-06 13:29 ` [PULL 05/16] docs/about/deprecated: Deprecate 32-bit x86 hosts for system emulation Thomas Huth
2023-03-06 13:29 ` [PULL 06/16] gitlab-ci.d/crossbuilds: Drop the i386 system emulation job Thomas Huth
2023-03-06 13:29 ` [PULL 07/16] docs/about/deprecated: Deprecate 32-bit arm hosts for system emulation Thomas Huth
2023-03-06 13:29 ` [PULL 08/16] gitlab-ci.d/crossbuilds: Drop the 32-bit arm system emulation jobs Thomas Huth
2023-03-06 13:29 ` [PULL 09/16] tests/qtest/readconfig: Rework test_object_rng_resp into a generic function Thomas Huth
2023-03-06 13:29 ` [PULL 10/16] tests/qtest/readconfig: Test docs/config/ich9-ehci-uhci.cfg Thomas Huth
2023-03-06 13:29 ` [PULL 11/16] docs/config: Set the "kvm" accelerator via "[accel]" section Thomas Huth
2023-03-06 13:29 ` [PULL 12/16] tests/qtest/readconfig-test: Allow testing for arbitrary memory sizes Thomas Huth
2023-03-06 13:29 ` [PULL 13/16] tests/qtest: Move mkimg() and have_qemu_img() from libqos to libqtest Thomas Huth
2023-03-06 13:30 ` Thomas Huth [this message]
2023-03-06 13:30 ` [PULL 15/16] pc-bios: Add support for List-Directed IPL from ECKD DASD Thomas Huth
2023-03-06 13:30 ` [PULL 16/16] pc-bios/s390-ccw: Update s390-ccw.img with the list-directed IPL fix Thomas Huth
2023-03-07  9:57 ` [PULL 00/16] Final tests, s390x and misc updates before the soft freeze Peter Maydell
2023-03-07 11:50   ` Thomas Huth

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230306133002.418421-15-thuth@redhat.com \
    --to=thuth@redhat.com \
    --cc=peter.maydell@linaro.org \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).