[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PULL 04/28] acpi-test: basic acpi unit-test
From: |
Michael S. Tsirkin |
Subject: |
[Qemu-devel] [PULL 04/28] acpi-test: basic acpi unit-test |
Date: |
Wed, 11 Dec 2013 20:30:18 +0200 |
We run bios, and boot a minimal boot sector that immediately halts.
Then poke at memory to find ACPI tables.
This only checks that RSDP is there.
More will be added later.
Cc: Andreas Färber <address@hidden>
Cc: Markus Armbruster <address@hidden>
Cc: Paolo Bonzini <address@hidden>
Signed-off-by: Michael S. Tsirkin <address@hidden>
---
tests/acpi-test.c | 135 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
tests/Makefile | 2 +
2 files changed, 137 insertions(+)
create mode 100644 tests/acpi-test.c
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 <address@hidden>,
+ *
+ * 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 <string.h>
+#include <stdio.h>
+#include <glib.h>
+#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] = {
+ /* 7c00: mov $0xdead,%ax */
+ [0x00] = 0xb8,
+ [0x01] = LOW(SIGNATURE),
+ [0x02] = HIGH(SIGNATURE),
+ /* 7c03: mov %ax,0x7c10 */
+ [0x03] = 0xa3,
+ [0x04] = LOW(BOOT_SECTOR_ADDRESS + SIGNATURE_OFFSET),
+ [0x05] = HIGH(BOOT_SECTOR_ADDRESS + SIGNATURE_OFFSET),
+ /* 7c06: cli */
+ [0x06] = 0xfa,
+ /* 7c07: hlt */
+ [0x07] = 0xf4,
+ /* 7c08: jmp 0x7c07=0x7c0a-3 */
+ [0x08] = 0xeb,
+ [0x09] = LOW(-3),
+ /* We mov 0xdead here: set value to make debugging easier */
+ [SIGNATURE_OFFSET] = LOW(0xface),
+ [SIGNATURE_OFFSET + 1] = HIGH(0xface),
+ /* End of boot sector marker */
+ [0x1FE] = 0x55,
+ [0x1FF] = 0xAA,
+};
+
+static const char *disk = "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 = 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 know BIOS
+ * initialization is done. TODO: check that IP reached the halt
+ * instruction.
+ */
+ for (i = 0; i < TEST_CYCLES; ++i) {
+ signature_low = readb(BOOT_SECTOR_ADDRESS + SIGNATURE_OFFSET);
+ signature_high = readb(BOOT_SECTOR_ADDRESS + SIGNATURE_OFFSET + 1);
+ signature = (signature_high << 8) | signature_low;
+ if (signature == SIGNATURE) {
+ break;
+ }
+ g_usleep(TEST_DELAY);
+ }
+ g_assert_cmphex(signature, ==, SIGNATURE);
+
+ /* OK, now find RSDP */
+ for (off = 0xf0000; off < 0x100000; off += 0x10)
+ {
+ uint8_t sig[] = "RSD PTR ";
+ int i;
+
+ for (i = 0; i < sizeof sig - 1; ++i) {
+ sig[i] = 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=tcg");
+}
+
+int main(int argc, char *argv[])
+{
+ const char *arch = qtest_get_arch();
+ FILE *f = fopen(disk, "w");
+ fwrite(boot_sector, 1, sizeof boot_sector, f);
+ fclose(f);
+
+ g_test_init(&argc, &argv, NULL);
+
+ if (strcmp(arch, "i386") == 0 || strcmp(arch, "x86_64") == 0) {
+ qtest_add_func("acpi/tcg", test_acpi_tcg);
+ }
+ return g_test_run();
+}
diff --git a/tests/Makefile b/tests/Makefile
index 379cdd9..8d25878 100644
--- a/tests/Makefile
+++ b/tests/Makefile
@@ -64,6 +64,7 @@ check-qtest-i386-y += tests/ide-test$(EXESUF)
check-qtest-i386-y += tests/hd-geo-test$(EXESUF)
gcov-files-i386-y += hw/hd-geometry.c
check-qtest-i386-y += tests/boot-order-test$(EXESUF)
+check-qtest-i386-y += tests/acpi-test$(EXESUF)
check-qtest-i386-y += tests/rtc-test$(EXESUF)
check-qtest-i386-y += tests/i440fx-test$(EXESUF)
check-qtest-i386-y += tests/fw_cfg-test$(EXESUF)
@@ -198,6 +199,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)
--
MST
- [Qemu-devel] [PULL 00/28] acpi.pci,pc,memory core fixes, Michael S. Tsirkin, 2013/12/11
- [Qemu-devel] [PULL 01/28] hw: Pass QEMUMachine to its init() method, Michael S. Tsirkin, 2013/12/11
- [Qemu-devel] [PULL 03/28] qtest: split configuration of qtest accelerator and chardev, Michael S. Tsirkin, 2013/12/11
- [Qemu-devel] [PULL 02/28] pc: map PCI address space as catchall region for not mapped addresses, Michael S. Tsirkin, 2013/12/11
- [Qemu-devel] [PULL 04/28] acpi-test: basic acpi unit-test,
Michael S. Tsirkin <=
- [Qemu-devel] [PULL 05/28] MAINTAINERS: update X86 machine entry, Michael S. Tsirkin, 2013/12/11
- [Qemu-devel] [PULL 06/28] pci: fix address space size for bridge, Michael S. Tsirkin, 2013/12/11
- [Qemu-devel] [PULL 08/28] spapr_pci: s/INT64_MAX/UINT64_MAX/, Michael S. Tsirkin, 2013/12/11
- [Qemu-devel] [PULL 07/28] pc: s/INT64_MAX/UINT64_MAX/, Michael S. Tsirkin, 2013/12/11
- [Qemu-devel] [PULL 09/28] split definitions for exec.c and translate-all.c radix trees, Michael S. Tsirkin, 2013/12/11
- [Qemu-devel] [PULL 10/28] exec: replace leaf with skip, Michael S. Tsirkin, 2013/12/11
- [Qemu-devel] [PULL 11/28] exec: extend skip field to 6 bit, page entry to 32 bit, Michael S. Tsirkin, 2013/12/11
- [Qemu-devel] [PULL 12/28] exec: pass hw address to phys_page_find, Michael S. Tsirkin, 2013/12/11
- [Qemu-devel] [PULL 13/28] exec: memory radix tree page level compression, Michael S. Tsirkin, 2013/12/11
- [Qemu-devel] [PULL 14/28] exec: make address spaces 64-bit wide, Michael S. Tsirkin, 2013/12/11