Received: from eggs.gnu.org ([2001:4830:134:3::10]:42120) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VapvD-0007PI-02 for qemu-devel@nongnu.org; Mon, 28 Oct 2013 12:44:15 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Vapv4-0000Mk-FH for qemu-devel@nongnu.org; Mon, 28 Oct 2013 12:44:06 -0400 Received: from mail-qa0-x22a.google.com ([2607:f8b0:400d:c00::22a]:46200) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Vapv4-0000Mg-9I for qemu-devel@nongnu.org; Mon, 28 Oct 2013 12:43:58 -0400 Received: by mail-qa0-f42.google.com with SMTP id w8so2237224qac.1 for ; Mon, 28 Oct 2013 09:43:57 -0700 (PDT) Sender: Paolo Bonzini From: Paolo Bonzini Date: Mon, 28 Oct 2013 17:43:20 +0100 Message-Id: <1382978620-16641-5-git-send-email-pbonzini@redhat.com> In-Reply-To: <1382978620-16641-1-git-send-email-pbonzini@redhat.com> References: <1382978620-16641-1-git-send-email-pbonzini@redhat.com> Subject: [Qemu-devel] [PATCH 04/24] ide-test: add test for werror=stop List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: mst@redhat.com Signed-off-by: Paolo Bonzini --- tests/ide-test.c | 74 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 74 insertions(+) diff --git a/tests/ide-test.c b/tests/ide-test.c index 7307f1d..560dd2c 100644 --- a/tests/ide-test.c +++ b/tests/ide-test.c @@ -105,6 +105,7 @@ static QPCIBus *pcibus = NULL; static QGuestAllocator *guest_malloc; static char tmp_path[] = "/tmp/qtest.XXXXXX"; +static char debug_path[] = "/tmp/qtest-blkdebug.XXXXXX"; static void ide_test_start(const char *cmdline_fmt, ...) { @@ -465,6 +466,72 @@ static void test_flush(void) ide_test_quit(); } +static void prepare_blkdebug_script(const char *debug_path, const char *event) +{ + FILE *debug_file = fopen(debug_path, "w"); + int ret; + + fprintf(debug_file, "[inject-error]\n"); + fprintf(debug_file, "event = \"%s\"\n", event); + fprintf(debug_file, "errno = \"5\"\n"); + fprintf(debug_file, "state = \"1\"\n"); + fprintf(debug_file, "immediately = \"off\"\n"); + fprintf(debug_file, "once = \"on\"\n"); + + fprintf(debug_file, "[set-state]\n"); + fprintf(debug_file, "event = \"%s\"\n", event); + fprintf(debug_file, "new_state = \"2\"\n"); + fflush(debug_file); + g_assert(!ferror(debug_file)); + + ret = fclose(debug_file); + g_assert(ret == 0); +} + +static void test_retry_flush(void) +{ + uint8_t data; + const char *s; + + prepare_blkdebug_script(debug_path, "flush_to_disk"); + + ide_test_start( + "-vnc none " + "-drive file=blkdebug:%s:%s,if=ide,cache=writeback,rerror=stop,werror=stop", + debug_path, tmp_path); + + /* FLUSH CACHE command on device 0*/ + outb(IDE_BASE + reg_device, 0); + outb(IDE_BASE + reg_command, CMD_FLUSH_CACHE); + + /* Check status while request is in flight*/ + data = inb(IDE_BASE + reg_status); + assert_bit_set(data, BSY | DRDY); + assert_bit_clear(data, DF | ERR | DRQ); + + sleep(1); /* HACK: wait for event */ + + /* Complete the command */ + s = "{'execute':'cont' }"; + while (!qmp(s)) { + s = ""; + sleep(1); + } + + /* Check registers */ + data = inb(IDE_BASE + reg_device); + g_assert_cmpint(data & DEV, ==, 0); + + do { + data = inb(IDE_BASE + reg_status); + } while (data & BSY); + + assert_bit_set(data, DRDY); + assert_bit_clear(data, BSY | DF | ERR | DRQ); + + ide_test_quit(); +} + int main(int argc, char **argv) { const char *arch = qtest_get_arch(); @@ -477,6 +544,11 @@ int main(int argc, char **argv) return 0; } + /* Create temporary blkdebug instructions */ + fd = mkstemp(debug_path); + g_assert(fd >= 0); + close(fd); + /* Create a temporary raw image */ fd = mkstemp(tmp_path); g_assert(fd >= 0); @@ -497,6 +569,8 @@ int main(int argc, char **argv) qtest_add_func("/ide/flush", test_flush); + qtest_add_func("/ide/retry/flush", test_retry_flush); + ret = g_test_run(); /* Cleanup */ -- 1.8.3.1