From nobody Sat Oct 25 21:45:33 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1521178965923777.1408175705621; Thu, 15 Mar 2018 22:42:45 -0700 (PDT) Received: from localhost ([::1]:55096 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ewi8a-00079x-UC for importer@patchew.org; Fri, 16 Mar 2018 01:42:45 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:55419) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ewi6D-0005d9-UX for qemu-devel@nongnu.org; Fri, 16 Mar 2018 01:40:19 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ewi6C-0003CB-Eo for qemu-devel@nongnu.org; Fri, 16 Mar 2018 01:40:17 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:52140 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1ewi67-000362-Km; Fri, 16 Mar 2018 01:40:11 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id F1C964068053; Fri, 16 Mar 2018 05:40:10 +0000 (UTC) Received: from thh440s.redhat.com (ovpn-116-92.ams2.redhat.com [10.36.116.92]) by smtp.corp.redhat.com (Postfix) with ESMTP id 48D35215CDAF; Fri, 16 Mar 2018 05:40:08 +0000 (UTC) From: Thomas Huth To: qemu-devel@nongnu.org Date: Fri, 16 Mar 2018 06:39:54 +0100 Message-Id: <1521178795-21894-3-git-send-email-thuth@redhat.com> In-Reply-To: <1521178795-21894-1-git-send-email-thuth@redhat.com> References: <1521178795-21894-1-git-send-email-thuth@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.5]); Fri, 16 Mar 2018 05:40:11 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.5]); Fri, 16 Mar 2018 05:40:11 +0000 (UTC) for IP:'10.11.54.6' DOMAIN:'int-mx06.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'thuth@redhat.com' RCPT:'' X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [PATCH v2 2/3] tests/cdrom-test: Test booting from CD-ROM ISO image file X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , Victor Kaplansky , qemu-block@nongnu.org, "Michael S. Tsirkin" , Mark Cave-Ayland , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , qemu-s390x@nongnu.org, =?UTF-8?q?Herv=C3=A9=20Poussineau?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" 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. Signed-off-by: Thomas Huth Reviewed-by: Philippe Mathieu-Daud=C3=A9 --- 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 ef9b88c..37ca258 100644 --- a/tests/Makefile.include +++ b/tests/Makefile.include @@ -178,6 +178,7 @@ check-qtest-generic-y =3D tests/qmp-test$(EXESUF) gcov-files-generic-y =3D monitor.c qapi/qmp-dispatch.c check-qtest-generic-y +=3D tests/device-introspect-test$(EXESUF) gcov-files-generic-y =3D qdev-monitor.c qmp.c +check-qtest-generic-y +=3D tests/cdrom-test$(EXESUF) =20 gcov-files-ipack-y +=3D hw/ipack/ipack.c check-qtest-ipack-y +=3D tests/ipoctal232-test$(EXESUF) @@ -829,6 +830,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 test= s/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) =20 tests/migration/stress$(EXESUF): tests/migration/stress.o $(call quiet-command, $(LINKPROG) -static -O3 $(PTHREAD_LIB) -o $@ $< ,"L= INK","$(TARGET_DIR)$@") diff --git a/tests/cdrom-test.c b/tests/cdrom-test.c new file mode 100644 index 0000000..5bbf322 --- /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 + * + * 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[] =3D "cdrom-boot-iso-XXXXXX"; + +static int exec_genisoimg(const char **args) +{ + gchar *out_err =3D NULL; + gint exit_status =3D -1; + bool success; + + success =3D g_spawn_sync(NULL, (gchar **)args, NULL, + G_SPAWN_SEARCH_PATH | G_SPAWN_STDOUT_TO_DEV_NUL= L, + 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[] =3D "cdrom-test-dir-XXXXXX"; + char *codefile =3D NULL; + int ifh, ret =3D -1; + const char *args[] =3D { + "genisoimage", "-quiet", "-l", "-no-emul-boot", + "-b", NULL, "-o", isoimage, srcdir, NULL + }; + + ifh =3D 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 =3D g_strdup_printf("%s/bootcode-XXXXXX", srcdir); + ret =3D boot_sector_init(codefile); + if (ret) { + goto cleanup; + } + } else { + /* Just create a dummy file */ + char txt[] =3D "empty disc"; + codefile =3D 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] =3D strchr(codefile, '/') + 1; + ret =3D 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 =3D 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=3Dcdr " + "-blockdev file,node-name=3Dcdr,filename=3D", test= _cdboot); + qtest_add_data_func("cdrom/boot/isapc", "-M isapc " + "-drive if=3Dide,media=3Dcdrom,file=3D", test_cdbo= ot); + qtest_add_data_func("cdrom/boot/am53c974", + "-device am53c974 -device scsi-cd,drive=3Dcd1 " + "-drive if=3Dnone,id=3Dcd1,format=3Draw,file=3D", = test_cdboot); + qtest_add_data_func("cdrom/boot/dc390", + "-device dc390 -device scsi-cd,drive=3Dcd1 " + "-blockdev file,node-name=3Dcd1,filename=3D", test= _cdboot); + qtest_add_data_func("cdrom/boot/lsi53c895a", + "-device lsi53c895a -device scsi-cd,drive=3Dcd1 " + "-blockdev file,node-name=3Dcd1,filename=3D", test= _cdboot); + qtest_add_data_func("cdrom/boot/megasas", "-M q35 " + "-device megasas -device scsi-cd,drive=3Dcd1 " + "-blockdev file,node-name=3Dcd1,filename=3D", test= _cdboot); + qtest_add_data_func("cdrom/boot/megasas-gen2", "-M q35 " + "-device megasas-gen2 -device scsi-cd,drive=3Dcd1 " + "-blockdev file,node-name=3Dcd1,filename=3D", 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=3Dcdr " + "-blockdev file,node-name=3Dcdr,filename=3D", test= _cdboot); +} + +int main(int argc, char **argv) +{ + int ret; + const char *arch =3D qtest_get_arch(); + const char *genisocheck[] =3D { "genisoimage", "-version", NULL }; + + g_test_init(&argc, &argv, NULL); + + if (exec_genisoimg(genisocheck)) { + /* genisoimage not available - so can't run tests */ + return 0; + } + + ret =3D 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 =3D g_test_run(); + + unlink(isoimage); + + return ret; +} --=20 1.8.3.1