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 1521100391874410.97346582077523; Thu, 15 Mar 2018 00:53:11 -0700 (PDT) Received: from localhost ([::1]:50148 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ewNhH-0001fP-4l for importer@patchew.org; Thu, 15 Mar 2018 03:53:11 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:38698) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ewNdh-0007Up-6D for qemu-devel@nongnu.org; Thu, 15 Mar 2018 03:49:30 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ewNdf-0004dd-T0 for qemu-devel@nongnu.org; Thu, 15 Mar 2018 03:49:29 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:43660 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 1ewNda-0004Pt-8n; Thu, 15 Mar 2018 03:49:22 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id B85ABD1426; Thu, 15 Mar 2018 07:49:21 +0000 (UTC) Received: from thh440s.redhat.com (ovpn-116-56.ams2.redhat.com [10.36.116.56]) by smtp.corp.redhat.com (Postfix) with ESMTP id 740B21208F71; Thu, 15 Mar 2018 07:49:19 +0000 (UTC) From: Thomas Huth To: qemu-devel@nongnu.org Date: Thu, 15 Mar 2018 08:49:04 +0100 Message-Id: <1521100145-15304-3-git-send-email-thuth@redhat.com> In-Reply-To: <1521100145-15304-1-git-send-email-thuth@redhat.com> References: <1521100145-15304-1-git-send-email-thuth@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.3 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.2]); Thu, 15 Mar 2018 07:49:21 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.2]); Thu, 15 Mar 2018 07:49:21 +0000 (UTC) for IP:'10.11.54.3' DOMAIN:'int-mx03.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 2/3] tests/cdboot: 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 , 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 --- tests/Makefile.include | 3 + tests/cdrom-test.c | 155 +++++++++++++++++++++++++++++++++++++++++++++= ++++ 2 files changed, 158 insertions(+) create mode 100644 tests/cdrom-test.c diff --git a/tests/Makefile.include b/tests/Makefile.include index ef9b88c..a104222 100644 --- a/tests/Makefile.include +++ b/tests/Makefile.include @@ -304,6 +304,7 @@ check-qtest-i386-$(CONFIG_POSIX) +=3D tests/test-filter= -redirector$(EXESUF) check-qtest-i386-y +=3D tests/migration-test$(EXESUF) check-qtest-i386-y +=3D tests/test-x86-cpuid-compat$(EXESUF) check-qtest-i386-y +=3D tests/numa-test$(EXESUF) +check-qtest-i386-y +=3D tests/cdrom-test$(EXESUF) check-qtest-x86_64-y +=3D $(check-qtest-i386-y) check-qtest-x86_64-y +=3D tests/sdhci-test$(EXESUF) gcov-files-i386-y +=3D i386-softmmu/hw/timer/mc146818rtc.c @@ -398,6 +399,7 @@ check-qtest-s390x-y +=3D tests/virtio-balloon-test$(EXE= SUF) check-qtest-s390x-y +=3D tests/virtio-console-test$(EXESUF) check-qtest-s390x-y +=3D tests/virtio-serial-test$(EXESUF) check-qtest-s390x-y +=3D tests/cpu-plug-test$(EXESUF) +check-qtest-s390x-y +=3D tests/cdrom-test$(EXESUF) =20 check-qtest-generic-y +=3D tests/qom-test$(EXESUF) check-qtest-generic-y +=3D tests/test-hmp$(EXESUF) @@ -829,6 +831,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..1fc5230 --- /dev/null +++ b/tests/cdrom-test.c @@ -0,0 +1,155 @@ +/* + * 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 gen_iso(const char *fmt, ...) +{ + char *params, *command; + va_list args; + pid_t pid; + int status; + + pid =3D fork(); + if (pid =3D=3D 0) { + va_start(args, fmt); + params =3D g_strdup_vprintf(fmt, args); + va_end(args); + command =3D g_strdup_printf("exec genisoimage %s", params); + g_free(params); + execlp("/bin/sh", "sh", "-c", command, NULL); + exit(1); + } + wait(&status); + + return WEXITSTATUS(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; + + 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 { + g_assert_not_reached(); + } + + ret =3D gen_iso("-quiet -l -no-emul-boot -b %s -o %s %s", + strrchr(codefile, '/') + 1, isoimage, srcdir); + 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("cdboot/default", "-cdrom ", test_cdboot); + qtest_add_data_func("cdboot/virtio-scsi", + "-device virtio-scsi -device scsi-cd,drive=3Dcdr " + "-blockdev file,node-name=3Dcdr,filename=3D", test= _cdboot); + qtest_add_data_func("cdboot/isapc", "-M isapc " + "-drive if=3Dide,media=3Dcdrom,file=3D", test_cdbo= ot); + qtest_add_data_func("cdboot/am53c974", + "-device am53c974 -device scsi-cd,drive=3Dcd1 " + "-drive if=3Dnone,id=3Dcd1,format=3Draw,file=3D", = test_cdboot); + qtest_add_data_func("cdboot/dc390", + "-device dc390 -device scsi-cd,drive=3Dcd1 " + "-blockdev file,node-name=3Dcd1,filename=3D", test= _cdboot); + qtest_add_data_func("cdboot/lsi53c895a", + "-device lsi53c895a -device scsi-cd,drive=3Dcd1 " + "-blockdev file,node-name=3Dcd1,filename=3D", test= _cdboot); + qtest_add_data_func("cdboot/megasas", "-M q35 " + "-device megasas -device scsi-cd,drive=3Dcd1 " + "-blockdev file,node-name=3Dcd1,filename=3D", test= _cdboot); + qtest_add_data_func("cdboot/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("cdboot/default", "-cdrom ", test_cdboot); + qtest_add_data_func("cdboot/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(); + + g_test_init(&argc, &argv, NULL); + + if (gen_iso("--version > /dev/null")) { + /* 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