All of lore.kernel.org
 help / color / mirror / Atom feed
From: John Snow <jsnow@redhat.com>
To: qemu-devel@nongnu.org
Cc: jsnow@redhat.com, peter.maydell@linaro.org,
	Thomas Huth <thuth@redhat.com>
Subject: [Qemu-devel] [PULL 21/30] tests/cdrom-test: Test booting from CD-ROM ISO image file
Date: Fri,  8 Jun 2018 13:47:24 -0400	[thread overview]
Message-ID: <20180608174733.4936-22-jsnow@redhat.com> (raw)
In-Reply-To: <20180608174733.4936-1-jsnow@redhat.com>

From: Thomas Huth <thuth@redhat.com>

We already have the code for a boot file in tests/boot-sector.c,
so if the genisoimage program is available, we can easily create
a bootable CD ISO image that we can use for testing whether our
CD-ROM emulation and the BIOS CD-ROM boot works correctly.

Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Reviewed-by: Hervé Poussineau <hpoussin@reactos.org>
Acked-By: Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>
Signed-off-by: Thomas Huth <thuth@redhat.com>
Signed-off-by: John Snow <jsnow@redhat.com>
---
 tests/Makefile.include |   2 +
 tests/cdrom-test.c     | 164 +++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 166 insertions(+)
 create mode 100644 tests/cdrom-test.c

diff --git a/tests/Makefile.include b/tests/Makefile.include
index 400d8890e7..d098a104bb 100644
--- a/tests/Makefile.include
+++ b/tests/Makefile.include
@@ -179,6 +179,7 @@ check-qtest-generic-y = tests/qmp-test$(EXESUF)
 gcov-files-generic-y = monitor.c qapi/qmp-dispatch.c
 check-qtest-generic-y += tests/device-introspect-test$(EXESUF)
 gcov-files-generic-y = qdev-monitor.c qmp.c
+check-qtest-generic-y += tests/cdrom-test$(EXESUF)
 
 gcov-files-ipack-y += hw/ipack/ipack.c
 check-qtest-ipack-y += tests/ipoctal232-test$(EXESUF)
@@ -844,6 +845,7 @@ tests/test-qapi-util$(EXESUF): tests/test-qapi-util.o $(test-util-obj-y)
 tests/numa-test$(EXESUF): tests/numa-test.o
 tests/vmgenid-test$(EXESUF): tests/vmgenid-test.o tests/boot-sector.o tests/acpi-utils.o
 tests/sdhci-test$(EXESUF): tests/sdhci-test.o $(libqos-pc-obj-y)
+tests/cdrom-test$(EXESUF): tests/cdrom-test.o tests/boot-sector.o $(libqos-obj-y)
 
 tests/migration/stress$(EXESUF): tests/migration/stress.o
 	$(call quiet-command, $(LINKPROG) -static -O3 $(PTHREAD_LIB) -o $@ $< ,"LINK","$(TARGET_DIR)$@")
diff --git a/tests/cdrom-test.c b/tests/cdrom-test.c
new file mode 100644
index 0000000000..5bbf322789
--- /dev/null
+++ b/tests/cdrom-test.c
@@ -0,0 +1,164 @@
+/*
+ * Various tests for emulated CD-ROM drives.
+ *
+ * Copyright (c) 2018 Red Hat Inc.
+ *
+ * Author:
+ *    Thomas Huth <thuth@redhat.com>
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2
+ * or later. See the COPYING file in the top-level directory.
+ */
+
+#include "qemu/osdep.h"
+#include "libqtest.h"
+#include "boot-sector.h"
+
+static char isoimage[] = "cdrom-boot-iso-XXXXXX";
+
+static int exec_genisoimg(const char **args)
+{
+    gchar *out_err = NULL;
+    gint exit_status = -1;
+    bool success;
+
+    success = g_spawn_sync(NULL, (gchar **)args, NULL,
+                           G_SPAWN_SEARCH_PATH | G_SPAWN_STDOUT_TO_DEV_NULL,
+                           NULL, NULL, NULL, &out_err, &exit_status, NULL);
+    if (!success) {
+        return -ENOENT;
+    }
+    if (out_err) {
+        fputs(out_err, stderr);
+        g_free(out_err);
+    }
+
+    return exit_status;
+}
+
+static int prepare_image(const char *arch, char *isoimage)
+{
+    char srcdir[] = "cdrom-test-dir-XXXXXX";
+    char *codefile = NULL;
+    int ifh, ret = -1;
+    const char *args[] = {
+        "genisoimage", "-quiet", "-l", "-no-emul-boot",
+        "-b", NULL, "-o", isoimage, srcdir, NULL
+    };
+
+    ifh = mkstemp(isoimage);
+    if (ifh < 0) {
+        perror("Error creating temporary iso image file");
+        return -1;
+    }
+    if (!mkdtemp(srcdir)) {
+        perror("Error creating temporary directory");
+        goto cleanup;
+    }
+
+    if (g_str_equal(arch, "i386") || g_str_equal(arch, "x86_64") ||
+        g_str_equal(arch, "s390x")) {
+        codefile = g_strdup_printf("%s/bootcode-XXXXXX", srcdir);
+        ret = boot_sector_init(codefile);
+        if (ret) {
+            goto cleanup;
+        }
+    } else {
+        /* Just create a dummy file */
+        char txt[] = "empty disc";
+        codefile = g_strdup_printf("%s/readme.txt", srcdir);
+        if (!g_file_set_contents(codefile, txt, sizeof(txt) - 1, NULL)) {
+            fprintf(stderr, "Failed to create '%s'\n", codefile);
+            goto cleanup;
+        }
+    }
+
+    args[5] = strchr(codefile, '/') + 1;
+    ret = exec_genisoimg(args);
+    if (ret) {
+        fprintf(stderr, "genisoimage failed: %i\n", ret);
+    }
+
+    unlink(codefile);
+
+cleanup:
+    g_free(codefile);
+    rmdir(srcdir);
+    close(ifh);
+
+    return ret;
+}
+
+static void test_cdboot(gconstpointer data)
+{
+    QTestState *qts;
+
+    qts = qtest_startf("-accel kvm:tcg -no-shutdown %s%s", (const char *)data,
+                       isoimage);
+    boot_sector_test(qts);
+    qtest_quit(qts);
+}
+
+static void add_x86_tests(void)
+{
+    qtest_add_data_func("cdrom/boot/default", "-cdrom ", test_cdboot);
+    qtest_add_data_func("cdrom/boot/virtio-scsi",
+                        "-device virtio-scsi -device scsi-cd,drive=cdr "
+                        "-blockdev file,node-name=cdr,filename=", test_cdboot);
+    qtest_add_data_func("cdrom/boot/isapc", "-M isapc "
+                        "-drive if=ide,media=cdrom,file=", test_cdboot);
+    qtest_add_data_func("cdrom/boot/am53c974",
+                        "-device am53c974 -device scsi-cd,drive=cd1 "
+                        "-drive if=none,id=cd1,format=raw,file=", test_cdboot);
+    qtest_add_data_func("cdrom/boot/dc390",
+                        "-device dc390 -device scsi-cd,drive=cd1 "
+                        "-blockdev file,node-name=cd1,filename=", test_cdboot);
+    qtest_add_data_func("cdrom/boot/lsi53c895a",
+                        "-device lsi53c895a -device scsi-cd,drive=cd1 "
+                        "-blockdev file,node-name=cd1,filename=", test_cdboot);
+    qtest_add_data_func("cdrom/boot/megasas", "-M q35 "
+                        "-device megasas -device scsi-cd,drive=cd1 "
+                        "-blockdev file,node-name=cd1,filename=", test_cdboot);
+    qtest_add_data_func("cdrom/boot/megasas-gen2", "-M q35 "
+                        "-device megasas-gen2 -device scsi-cd,drive=cd1 "
+                        "-blockdev file,node-name=cd1,filename=", test_cdboot);
+}
+
+static void add_s390x_tests(void)
+{
+    qtest_add_data_func("cdrom/boot/default", "-cdrom ", test_cdboot);
+    qtest_add_data_func("cdrom/boot/virtio-scsi",
+                        "-device virtio-scsi -device scsi-cd,drive=cdr "
+                        "-blockdev file,node-name=cdr,filename=", test_cdboot);
+}
+
+int main(int argc, char **argv)
+{
+    int ret;
+    const char *arch = qtest_get_arch();
+    const char *genisocheck[] = { "genisoimage", "-version", NULL };
+
+    g_test_init(&argc, &argv, NULL);
+
+    if (exec_genisoimg(genisocheck)) {
+        /* genisoimage not available - so can't run tests */
+        return 0;
+    }
+
+    ret = prepare_image(arch, isoimage);
+    if (ret) {
+        return ret;
+    }
+
+    if (g_str_equal(arch, "i386") || g_str_equal(arch, "x86_64")) {
+        add_x86_tests();
+    } else if (g_str_equal(arch, "s390x")) {
+        add_s390x_tests();
+    }
+
+    ret = g_test_run();
+
+    unlink(isoimage);
+
+    return ret;
+}
-- 
2.14.3

  parent reply	other threads:[~2018-06-08 17:47 UTC|newest]

Thread overview: 32+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-06-08 17:47 [Qemu-devel] [PULL 00/30] Ide patches John Snow
2018-06-08 17:47 ` [Qemu-devel] [PULL 01/30] ahci: trim signatures on raise/lower John Snow
2018-06-08 17:47 ` [Qemu-devel] [PULL 02/30] ahci: fix PxCI register race John Snow
2018-06-08 17:47 ` [Qemu-devel] [PULL 03/30] ahci: don't schedule unnecessary BH John Snow
2018-06-08 17:47 ` [Qemu-devel] [PULL 04/30] ahci: add port register enumeration John Snow
2018-06-08 17:47 ` [Qemu-devel] [PULL 05/30] ahci: modify ahci_port_read to use register numbers John Snow
2018-06-08 17:47 ` [Qemu-devel] [PULL 06/30] ahci: make port read traces more descriptive John Snow
2018-06-08 17:47 ` [Qemu-devel] [PULL 07/30] ahci: fix spacing damage on ahci_port_write John Snow
2018-06-08 17:47 ` [Qemu-devel] [PULL 08/30] ahci: combine identical clauses in port write John Snow
2018-06-08 17:47 ` [Qemu-devel] [PULL 09/30] ahci: modify ahci_port_write to use register numbers John Snow
2018-06-08 17:47 ` [Qemu-devel] [PULL 10/30] ahci: make port write traces more descriptive John Snow
2018-06-08 17:47 ` [Qemu-devel] [PULL 11/30] ahci: delete old port register address definitions John Snow
2018-06-08 17:47 ` [Qemu-devel] [PULL 12/30] ahci: add host register enumeration John Snow
2018-06-08 17:47 ` [Qemu-devel] [PULL 13/30] ahci: fix host register max address John Snow
2018-06-08 17:47 ` [Qemu-devel] [PULL 14/30] ahci: modify ahci_mem_read_32 to work on register numbers John Snow
2018-06-08 17:47 ` [Qemu-devel] [PULL 15/30] ahci: make mem_read_32 traces more descriptive John Snow
2018-06-08 17:47 ` [Qemu-devel] [PULL 16/30] ahci: fix spacing damage on ahci_mem_write John Snow
2018-06-08 17:47 ` [Qemu-devel] [PULL 17/30] ahci: adjust ahci_mem_write to work on registers John Snow
2018-06-08 17:47 ` [Qemu-devel] [PULL 18/30] ahci: delete old host register address definitions John Snow
2018-06-08 17:47 ` [Qemu-devel] [PULL 19/30] ahci: make ahci_mem_write traces more descriptive John Snow
2018-06-08 17:47 ` [Qemu-devel] [PULL 20/30] tests/boot-sector: Add magic bytes to s390x boot code header John Snow
2018-06-08 17:47 ` John Snow [this message]
2018-06-08 17:47 ` [Qemu-devel] [PULL 22/30] tests/cdrom-test: Test that -cdrom parameter is working John Snow
2018-06-08 17:47 ` [Qemu-devel] [PULL 23/30] MAINTAINERS: Add the cdrom-test to John's section John Snow
2018-06-08 17:47 ` [Qemu-devel] [PULL 24/30] libqos/ahci: track sector size John Snow
2018-06-08 17:47 ` [Qemu-devel] [PULL 25/30] ahci: move PIO Setup FIS before transfer, fix it for ATAPI commands John Snow
2018-06-08 17:47 ` [Qemu-devel] [PULL 26/30] ide: push end_transfer_func out of start_transfer callback, rename callback John Snow
2018-06-08 17:47 ` [Qemu-devel] [PULL 27/30] ide: call ide_cmd_done from ide_transfer_stop John Snow
2018-06-08 17:47 ` [Qemu-devel] [PULL 28/30] ide: make ide_transfer_stop idempotent John Snow
2018-06-08 17:47 ` [Qemu-devel] [PULL 29/30] atapi: call ide_set_irq before ide_transfer_start John Snow
2018-06-08 17:47 ` [Qemu-devel] [PULL 30/30] ide: introduce ide_transfer_start_norecurse John Snow
2018-06-11 11:46 ` [Qemu-devel] [PULL 00/30] Ide patches Peter Maydell

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=20180608174733.4936-22-jsnow@redhat.com \
    --to=jsnow@redhat.com \
    --cc=peter.maydell@linaro.org \
    --cc=qemu-devel@nongnu.org \
    --cc=thuth@redhat.com \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.