From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:52078) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VXaH6-0006hf-5c for qemu-devel@nongnu.org; Sat, 19 Oct 2013 13:25:22 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1VXaGv-0003dR-Jk for qemu-devel@nongnu.org; Sat, 19 Oct 2013 13:25:16 -0400 Received: from mx1.redhat.com ([209.132.183.28]:64561) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VXaGv-0003YV-8M for qemu-devel@nongnu.org; Sat, 19 Oct 2013 13:25:05 -0400 Date: Sat, 19 Oct 2013 20:27:30 +0300 From: "Michael S. Tsirkin" Message-ID: <20131019172730.GB29768@redhat.com> References: <1382046646-20263-1-git-send-email-mst@redhat.com> <1382046646-20263-2-git-send-email-mst@redhat.com> <5261CEB8.1050108@suse.de> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline In-Reply-To: <5261CEB8.1050108@suse.de> Content-Transfer-Encoding: quoted-printable Subject: Re: [Qemu-devel] [PATCH 2/2] acpi-test: basic acpi unit-test List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Andreas =?iso-8859-1?Q?F=E4rber?= Cc: pbonzini@redhat.com, qemu-devel@nongnu.org, Anthony Liguori , Markus Armbruster On Sat, Oct 19, 2013 at 02:13:44AM +0200, Andreas F=E4rber wrote: > Am 17.10.2013 23:52, schrieb Michael S. Tsirkin: > > diff --git a/tests/acpi-test.c b/tests/acpi-test.c > > new file mode 100644 > > index 0000000..42de248 > > --- /dev/null > > +++ b/tests/acpi-test.c > [...] > > +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 (60 * G_USEC_PER_SEC / TEST_DELAY) > > + > > + for (i =3D 0; i < TEST_CYCLES; ++i) { > > + signature_low =3D readb(BOOT_SECTOR_ADDRESS + SIGNATURE_OFFS= ET); > > + signature_high =3D readb(BOOT_SECTOR_ADDRESS + SIGNATURE_OFF= SET + 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); >=20 > Might be a good safety precaution to use QEMU_BUG_ON() or MIN(..., 1) > for TEST_CYCLES to assure signature gets initialized before comparison. You mean check that TEST_CYCLES > 0? > > + > > + /* 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) > > +{ > > + test_acpi_one("-machine accel=3Dtcg"); > > +} > > + > > +static void test_acpi_kvm(void) > > +{ > > + test_acpi_one("-enable-kvm -machine accel=3Dkvm"); > > +} > > + > > +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); > > + qtest_add_func("acpi/kvm", test_acpi_kvm); >=20 > Sorry, while the intention is good, this is a no-go. Not only will make > check fail on KVM-incompatible x86 hosts (including insufficient > permissions for /dev/kvm), it will also fail on ppc or arm hosts since > we are testing the target architecture here. >=20 > Regards, > Andreas I'll limit this to tcg for now. > > + } > > + return g_test_run(); > > +} > [snip] >=20 > --=20 > SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 N=FCrnberg, Germany > GF: Jeff Hawn, Jennifer Guild, Felix Imend=F6rffer; HRB 16746 AG N=FCrn= berg