9ae3a8
From d1c34ff41de0ece966991adb6aef6f2bce2ccfc4 Mon Sep 17 00:00:00 2001
9ae3a8
From: Kevin Wolf <kwolf@redhat.com>
9ae3a8
Date: Wed, 10 Sep 2014 11:06:08 +0200
9ae3a8
Subject: [PATCH 09/12] ide-test: Add FLUSH CACHE test case
9ae3a8
9ae3a8
Message-id: <1410347169-4368-3-git-send-email-kwolf@redhat.com>
9ae3a8
Patchwork-id: 60954
9ae3a8
O-Subject: [RHEL-7.1 qemu-kvm PATCH 2/3] ide-test: Add FLUSH CACHE test case
9ae3a8
Bugzilla: 1123372
9ae3a8
RH-Acked-by: Max Reitz <mreitz@redhat.com>
9ae3a8
RH-Acked-by: Fam Zheng <famz@redhat.com>
9ae3a8
RH-Acked-by: Stefan Hajnoczi <stefanha@redhat.com>
9ae3a8
9ae3a8
This checks in particular that BSY is set while the flush request is in
9ae3a8
flight.
9ae3a8
9ae3a8
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
9ae3a8
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
9ae3a8
(cherry picked from commit bd07684aacfb61668ae2c25b7dd00b64f3d7c7f3)
9ae3a8
9ae3a8
RHEL: Whitelist the blkdebug driver so that the new qtest can succeed.
9ae3a8
9ae3a8
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
9ae3a8
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
9ae3a8
---
9ae3a8
 redhat/qemu-kvm.spec.template |    4 ++--
9ae3a8
 tests/ide-test.c              |   40 ++++++++++++++++++++++++++++++++++++++++
9ae3a8
 2 files changed, 42 insertions(+), 2 deletions(-)
9ae3a8
9ae3a8
diff --git a/tests/ide-test.c b/tests/ide-test.c
9ae3a8
index ac59259..739d2bf 100644
9ae3a8
--- a/tests/ide-test.c
9ae3a8
+++ b/tests/ide-test.c
9ae3a8
@@ -77,6 +77,7 @@ enum {
9ae3a8
 enum {
9ae3a8
     CMD_READ_DMA    = 0xc8,
9ae3a8
     CMD_WRITE_DMA   = 0xca,
9ae3a8
+    CMD_FLUSH_CACHE = 0xe7,
9ae3a8
     CMD_IDENTIFY    = 0xec,
9ae3a8
 
9ae3a8
     CMDF_ABORT      = 0x100,
9ae3a8
@@ -424,6 +425,43 @@ static void test_identify(void)
9ae3a8
     ide_test_quit();
9ae3a8
 }
9ae3a8
 
9ae3a8
+static void test_flush(void)
9ae3a8
+{
9ae3a8
+    uint8_t data;
9ae3a8
+
9ae3a8
+    ide_test_start(
9ae3a8
+        "-vnc none "
9ae3a8
+        "-drive file=blkdebug::%s,if=ide,cache=writeback",
9ae3a8
+        tmp_path);
9ae3a8
+
9ae3a8
+    /* Delay the completion of the flush request until we explicitly do it */
9ae3a8
+    qmp("{'execute':'human-monitor-command', 'arguments': { "
9ae3a8
+        "'command-line': 'qemu-io ide0-hd0 \"break flush_to_os A\"'} }");
9ae3a8
+
9ae3a8
+    /* FLUSH CACHE command on device 0*/
9ae3a8
+    outb(IDE_BASE + reg_device, 0);
9ae3a8
+    outb(IDE_BASE + reg_command, CMD_FLUSH_CACHE);
9ae3a8
+
9ae3a8
+    /* Check status while request is in flight*/
9ae3a8
+    data = inb(IDE_BASE + reg_status);
9ae3a8
+    assert_bit_set(data, BSY | DRDY);
9ae3a8
+    assert_bit_clear(data, DF | ERR | DRQ);
9ae3a8
+
9ae3a8
+    /* Complete the command */
9ae3a8
+    qmp("{'execute':'human-monitor-command', 'arguments': { "
9ae3a8
+        "'command-line': 'qemu-io ide0-hd0 \"resume A\"'} }");
9ae3a8
+
9ae3a8
+    /* Check registers */
9ae3a8
+    data = inb(IDE_BASE + reg_device);
9ae3a8
+    g_assert_cmpint(data & DEV, ==, 0);
9ae3a8
+
9ae3a8
+    data = inb(IDE_BASE + reg_status);
9ae3a8
+    assert_bit_set(data, DRDY);
9ae3a8
+    assert_bit_clear(data, BSY | DF | ERR | DRQ);
9ae3a8
+
9ae3a8
+    ide_test_quit();
9ae3a8
+}
9ae3a8
+
9ae3a8
 int main(int argc, char **argv)
9ae3a8
 {
9ae3a8
     const char *arch = qtest_get_arch();
9ae3a8
@@ -454,6 +492,8 @@ int main(int argc, char **argv)
9ae3a8
     qtest_add_func("/ide/bmdma/long_prdt", test_bmdma_long_prdt);
9ae3a8
     qtest_add_func("/ide/bmdma/teardown", test_bmdma_teardown);
9ae3a8
 
9ae3a8
+    qtest_add_func("/ide/flush", test_flush);
9ae3a8
+
9ae3a8
     ret = g_test_run();
9ae3a8
 
9ae3a8
     /* Cleanup */
9ae3a8
-- 
9ae3a8
1.7.1
9ae3a8