From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:51560) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Ve6Sl-0003Kt-Su for qemu-devel@nongnu.org; Wed, 06 Nov 2013 12:00:22 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Ve6Sc-0004sY-WC for qemu-devel@nongnu.org; Wed, 06 Nov 2013 12:00:15 -0500 Received: from cantor2.suse.de ([195.135.220.15]:39288 helo=mx2.suse.de) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Ve6Sc-0004rg-JM for qemu-devel@nongnu.org; Wed, 06 Nov 2013 12:00:06 -0500 Message-ID: <527A7593.6050603@suse.de> Date: Wed, 06 Nov 2013 18:00:03 +0100 From: =?ISO-8859-1?Q?Andreas_F=E4rber?= MIME-Version: 1.0 References: <1383749487-4823-1-git-send-email-mst@redhat.com> <1383749487-4823-2-git-send-email-mst@redhat.com> In-Reply-To: <1383749487-4823-2-git-send-email-mst@redhat.com> Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Subject: Re: [Qemu-devel] [PATCH v2 2/2] acpi-test: basic acpi unit-test List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: "Michael S. Tsirkin" , qemu-devel@nongnu.org Cc: Paolo Bonzini , Markus Armbruster , Stefan Hajnoczi Am 06.11.2013 15:53, schrieb Michael S. Tsirkin: > We run bios, and boot a minimal boot sector that immediately halts. > Then poke at memory to find ACPI tables. >=20 > This only checks that RSDP is there. > More will be added later. >=20 > Cc: Andreas F=E4rber > Cc: Markus Armbruster > Cc: Paolo Bonzini > Signed-off-by: Michael S. Tsirkin > --- >=20 > changes from v1: > address style comments by Markus, Andreas > add cli to disable interrupts as suggested by Paolo >=20 > tests/acpi-test.c | 135 ++++++++++++++++++++++++++++++++++++++++++++++= ++++++++ > tests/Makefile | 2 + > 2 files changed, 137 insertions(+) > create mode 100644 tests/acpi-test.c >=20 > diff --git a/tests/acpi-test.c b/tests/acpi-test.c > new file mode 100644 > index 0000000..468c4f5 > --- /dev/null > +++ b/tests/acpi-test.c > @@ -0,0 +1,135 @@ > +/* > + * Boot order test cases. > + * > + * Copyright (c) 2013 Red Hat Inc. > + * > + * Authors: > + * Michael S. Tsirkin , > + * > + * 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 > +#include > +#include > +#include "libqtest.h" > + > +typedef struct { > + const char *args; > + uint64_t expected_boot; > + uint64_t expected_reboot; > +} boot_order_test; > + > +#define LOW(x) ((x) & 0xff) > +#define HIGH(x) ((x) >> 8) > + > +#define SIGNATURE 0xdead > +#define SIGNATURE_OFFSET 0x10 > +#define BOOT_SECTOR_ADDRESS 0x7c00 > + > +/* Boot sector code: write SIGNATURE into memory, > + * then halt. > + */ > +static uint8_t boot_sector[0x200] =3D { > + /* 7c00: mov $0xdead,%ax */ > + [0x00] =3D 0xb8, > + [0x01] =3D LOW(SIGNATURE), > + [0x02] =3D HIGH(SIGNATURE), > + /* 7c03: mov %ax,0x7c10 */ > + [0x03] =3D 0xa3, > + [0x04] =3D LOW(BOOT_SECTOR_ADDRESS + SIGNATURE_OFFSET), > + [0x05] =3D HIGH(BOOT_SECTOR_ADDRESS + SIGNATURE_OFFSET), > + /* 7c06: cli */ > + [0x06] =3D 0xfa, > + /* 7c07: hlt */ > + [0x07] =3D 0xf4, > + /* 7c08: jmp 0x7c07=3D0x7c0a-3 */ > + [0x08] =3D 0xeb, > + [0x09] =3D LOW(-3), > + /* We mov 0xdead here: set value to make debugging easier */ > + [SIGNATURE_OFFSET] =3D LOW(0xface), > + [SIGNATURE_OFFSET + 1] =3D HIGH(0xface), > + /* End of boot sector marker */ > + [0x1FE] =3D 0x55, > + [0x1FF] =3D 0xAA, > +}; > + > +static const char *disk =3D "tests/acpi-test-disk.raw"; > + > +static void test_acpi_one(const char *params) > +{ > + char *args; > + uint8_t signature_low; > + uint8_t signature_high; > + uint16_t signature; > + int i; > + uint32_t off; > + > + > + args =3D g_strdup_printf("-net none -display none %s %s", > + params ? params : "", disk); > + qtest_start(args); > + > + /* Wait at most 1 minute */ > +#define TEST_DELAY (1 * G_USEC_PER_SEC / 10) > +#define TEST_CYCLES MAX((60 * G_USEC_PER_SEC / TEST_DELAY), 1) > + > + /* Poll until code has run and modified memory. Once it has we kn= ow BIOS > + * initialization is done. TODO: check that IP reached the halt > + * instruction. > + */ > + for (i =3D 0; i < TEST_CYCLES; ++i) { > + signature_low =3D readb(BOOT_SECTOR_ADDRESS + SIGNATURE_OFFSET= ); > + signature_high =3D readb(BOOT_SECTOR_ADDRESS + SIGNATURE_OFFSE= T + 1); > + signature =3D (signature_high << 8) | signature_low; > + if (signature =3D=3D SIGNATURE) { > + break; > + } > + g_usleep(TEST_DELAY); > + } > + g_assert_cmphex(signature, =3D=3D, SIGNATURE); > + > + /* OK, now find RSDP */ > + for (off =3D 0xf0000; off < 0x100000; off +=3D 0x10) > + { > + uint8_t sig[] =3D "RSD PTR "; > + int i; > + > + for (i =3D 0; i < sizeof sig - 1; ++i) { > + sig[i] =3D readb(off + i); > + } > + > + if (!memcmp(sig, "RSD PTR ", sizeof sig)) { > + break; > + } > + } > + > + g_assert_cmphex(off, <, 0x100000); > + > + qtest_quit(global_qtest); > + g_free(args); > +} > + > +static void test_acpi_tcg(void) > +{ > + /* Supplying -machine accel argument overrides the default (qtest)= . > + * This is to make guest actually run. > + */ > + test_acpi_one("-machine accel=3Dtcg"); > +} > + > +int main(int argc, char *argv[]) > +{ > + const char *arch =3D qtest_get_arch(); > + FILE *f =3D fopen(disk, "w"); > + fwrite(boot_sector, 1, sizeof boot_sector, f); > + fclose(f); > + > + g_test_init(&argc, &argv, NULL); > + > + if (strcmp(arch, "i386") =3D=3D 0 || strcmp(arch, "x86_64") =3D=3D= 0) { > + qtest_add_func("acpi/tcg", test_acpi_tcg); Minor observation: Stefan's patch had "/qdev/..." whereas this is "acpi/..." - please compare the in-tree qtests and/or make check V=3D1. Other than that looks okay, although I have mixed feelings about executing TCG code inside qtest - pro gives it some more testing, con requires it to work on the host platform. Andreas > + } > + return g_test_run(); > +} > diff --git a/tests/Makefile b/tests/Makefile > index fa4c9f0..62a0a5d 100644 > --- a/tests/Makefile > +++ b/tests/Makefile > @@ -64,6 +64,7 @@ check-qtest-i386-y +=3D tests/ide-test$(EXESUF) > check-qtest-i386-y +=3D tests/hd-geo-test$(EXESUF) > gcov-files-i386-y +=3D hw/hd-geometry.c > check-qtest-i386-y +=3D tests/boot-order-test$(EXESUF) > +check-qtest-i386-y +=3D tests/acpi-test$(EXESUF) > check-qtest-i386-y +=3D tests/rtc-test$(EXESUF) > check-qtest-i386-y +=3D tests/i440fx-test$(EXESUF) > check-qtest-i386-y +=3D tests/fw_cfg-test$(EXESUF) > @@ -171,6 +172,7 @@ tests/fdc-test$(EXESUF): tests/fdc-test.o > tests/ide-test$(EXESUF): tests/ide-test.o $(libqos-pc-obj-y) > tests/hd-geo-test$(EXESUF): tests/hd-geo-test.o > tests/boot-order-test$(EXESUF): tests/boot-order-test.o $(libqos-obj-y= ) > +tests/acpi-test$(EXESUF): tests/acpi-test.o $(libqos-obj-y) > tests/tmp105-test$(EXESUF): tests/tmp105-test.o $(libqos-omap-obj-y) > tests/i440fx-test$(EXESUF): tests/i440fx-test.o $(libqos-pc-obj-y) > tests/fw_cfg-test$(EXESUF): tests/fw_cfg-test.o $(libqos-pc-obj-y) >=20 --=20 SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 N=FCrnberg, Germany GF: Jeff Hawn, Jennifer Guild, Felix Imend=F6rffer; HRB 16746 AG N=FCrnbe= rg