[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH 05/10] qtest: Add IDE test case
From: |
Kevin Wolf |
Subject: |
[Qemu-devel] [PATCH 05/10] qtest: Add IDE test case |
Date: |
Wed, 8 May 2013 16:28:59 +0200 |
This adds a simple IDE test case and starts by verifying that IDENTIFY
can be successfully used and return the correct serial number, version
and the WCE flag is set for cache=writeback.
Signed-off-by: Kevin Wolf <address@hidden>
---
tests/Makefile | 2 +
tests/ide-test.c | 165 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 167 insertions(+)
create mode 100644 tests/ide-test.c
diff --git a/tests/Makefile b/tests/Makefile
index bf41d10..a307d5a 100644
--- a/tests/Makefile
+++ b/tests/Makefile
@@ -51,6 +51,7 @@ check-block-$(CONFIG_POSIX) += tests/qemu-iotests-quick.sh
# really in libqtest, not in the testcases themselves.
check-qtest-i386-y = tests/fdc-test$(EXESUF)
gcov-files-i386-y = hw/fdc.c
+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/rtc-test$(EXESUF)
@@ -127,6 +128,7 @@ libqos-omap-obj-y = $(libqos-obj-y) tests/libqos/i2c-omap.o
tests/rtc-test$(EXESUF): tests/rtc-test.o
tests/m48t59-test$(EXESUF): tests/m48t59-test.o
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/tmp105-test$(EXESUF): tests/tmp105-test.o $(libqos-omap-obj-y)
tests/i440fx-test$(EXESUF): tests/i440fx-test.o $(libqos-pc-obj-y)
diff --git a/tests/ide-test.c b/tests/ide-test.c
new file mode 100644
index 0000000..45036e3
--- /dev/null
+++ b/tests/ide-test.c
@@ -0,0 +1,165 @@
+/*
+ * IDE test cases
+ *
+ * Copyright (c) 2013 Kevin Wolf <address@hidden>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to
deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+#include <stdint.h>
+#include <string.h>
+#include <stdio.h>
+
+#include <glib.h>
+
+#include "libqtest.h"
+
+#include "qemu-common.h"
+
+#define TEST_IMAGE_SIZE 64 * 1024 * 1024
+
+#define IDE_PCI_DEV 1
+#define IDE_PCI_FUNC 1
+
+#define IDE_BASE 0x1f0
+#define IDE_PRIMARY_IRQ 14
+
+enum {
+ reg_data = 0x0,
+ reg_nsectors = 0x2,
+ reg_lba_low = 0x3,
+ reg_lba_middle = 0x4,
+ reg_lba_high = 0x5,
+ reg_device = 0x6,
+ reg_status = 0x7,
+ reg_command = 0x7,
+};
+
+enum {
+ BSY = 0x80,
+ DRDY = 0x40,
+ DF = 0x20,
+ DRQ = 0x08,
+ ERR = 0x01,
+};
+
+enum {
+ CMD_IDENTIFY = 0xec,
+};
+
+#define assert_bit_set(data, mask) g_assert_cmphex((data) & (mask), ==, (mask))
+#define assert_bit_clear(data, mask) g_assert_cmphex((data) & (mask), ==, 0)
+
+static char tmp_path[] = "/tmp/qtest.XXXXXX";
+
+static void ide_test_start(const char *cmdline_fmt, ...)
+{
+ va_list ap;
+ char *cmdline;
+
+ va_start(ap, cmdline_fmt);
+ cmdline = g_strdup_vprintf(cmdline_fmt, ap);
+ va_end(ap);
+
+ qtest_start(cmdline);
+ qtest_irq_intercept_in(global_qtest, "ioapic");
+}
+
+static void ide_test_quit(void)
+{
+ qtest_quit(global_qtest);
+}
+
+static void test_identify(void)
+{
+ uint8_t data;
+ uint16_t buf[256];
+ int i;
+ int ret;
+
+ ide_test_start(
+ "-vnc none "
+ "-drive file=%s,if=ide,serial=%s,cache=writeback "
+ "-global ide-hd.ver=%s",
+ tmp_path, "testdisk", "version");
+
+ /* IDENTIFY command on device 0*/
+ outb(IDE_BASE + reg_device, 0);
+ outb(IDE_BASE + reg_command, CMD_IDENTIFY);
+
+ /* Read in the IDENTIFY buffer and check registers */
+ data = inb(IDE_BASE + reg_device);
+ g_assert_cmpint(data & 0x10, ==, 0);
+
+ for (i = 0; i < 256; i++) {
+ data = inb(IDE_BASE + reg_status);
+ assert_bit_set(data, DRDY | DRQ);
+ assert_bit_clear(data, BSY | DF | ERR);
+
+ ((uint16_t*) buf)[i] = inw(IDE_BASE + reg_data);
+ }
+
+ data = inb(IDE_BASE + reg_status);
+ assert_bit_set(data, DRDY);
+ assert_bit_clear(data, BSY | DF | ERR | DRQ);
+
+ /* Check serial number/version in the buffer */
+ ret = memcmp(&buf[10], "ettsidks ", 20);
+ g_assert(ret == 0);
+
+ ret = memcmp(&buf[23], "evsroi n", 8);
+ g_assert(ret == 0);
+
+ /* Write cache enabled bit */
+ assert_bit_set(buf[85], 0x20);
+
+ ide_test_quit();
+}
+
+int main(int argc, char **argv)
+{
+ const char *arch = qtest_get_arch();
+ int fd;
+ int ret;
+
+ /* Check architecture */
+ if (strcmp(arch, "i386") && strcmp(arch, "x86_64")) {
+ g_test_message("Skipping test for non-x86\n");
+ return 0;
+ }
+
+ /* Create a temporary raw image */
+ fd = mkstemp(tmp_path);
+ g_assert(fd >= 0);
+ ret = ftruncate(fd, TEST_IMAGE_SIZE);
+ g_assert(ret == 0);
+ close(fd);
+
+ /* Run the tests */
+ g_test_init(&argc, &argv, NULL);
+
+ qtest_add_func("/ide/identify", test_identify);
+
+ ret = g_test_run();
+
+ /* Cleanup */
+ unlink(tmp_path);
+
+ return ret;
+}
--
1.8.1.4
- [Qemu-devel] [PULL 1.5 00/10] Block patches for 1.5.0-rc1, Kevin Wolf, 2013/05/08
- [Qemu-devel] [PATCH 08/10] qemu-iotests: exclude vmdk for test 042, Kevin Wolf, 2013/05/08
- [Qemu-devel] [PATCH 07/10] qtest/ide-test: Test short and long PRDTs, Kevin Wolf, 2013/05/08
- [Qemu-devel] [PATCH 09/10] qemu-iotests: exclude vmdk and qcow from 043, Kevin Wolf, 2013/05/08
- [Qemu-devel] [PATCH 05/10] qtest: Add IDE test case,
Kevin Wolf <=
- [Qemu-devel] [PATCH 10/10] qemu-iotests: fix 017 018 for vmdk, Kevin Wolf, 2013/05/08
- [Qemu-devel] [PATCH 03/10] ide: Reset BMIDEA bit when the bus master is stopped, Kevin Wolf, 2013/05/08
- [Qemu-devel] [PATCH 06/10] qtest/ide-test: Add simple DMA read/write test case, Kevin Wolf, 2013/05/08
- [Qemu-devel] [PATCH 01/10] ahci: Don't allow creating slave drives, Kevin Wolf, 2013/05/08
- [Qemu-devel] [PATCH 04/10] libqos/pci: Enable bus mastering, Kevin Wolf, 2013/05/08
- [Qemu-devel] [PATCH 02/10] de_DE.po: Add missing leading spaces, Kevin Wolf, 2013/05/08