From: Jie Wang <wangjie88@huawei.com>
To: jcody@redhat.com
Cc: kwolf@redhat.com, mreitz@redhat.com, qemu-devel@nongnu.org,
wangjie88@huawei.com, wu.wubin@huawei.com, subo7@huawei.com,
eric.fangyi@huawei.com
Subject: [Qemu-devel] [PATCH] tests: add drive-mirror qtest
Date: Tue, 6 Sep 2016 12:30:01 +0000 [thread overview]
Message-ID: <1473165001-8333-1-git-send-email-wangjie88@huawei.com> (raw)
Signed-off-by: Jie Wang <wangjie88@huawei.com>
---
tests/Makefile.include | 3 ++
tests/drive-mirror-test.c | 96 +++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 99 insertions(+)
create mode 100755 tests/drive-mirror-test.c
diff --git a/tests/Makefile.include b/tests/Makefile.include
index 14be491..73b78c3 100644
--- a/tests/Makefile.include
+++ b/tests/Makefile.include
@@ -164,6 +164,8 @@ check-qtest-pci-y += tests/ne2000-test$(EXESUF)
gcov-files-pci-y += hw/net/ne2000.c
check-qtest-pci-y += tests/nvme-test$(EXESUF)
gcov-files-pci-y += hw/block/nvme.c
+check-qtest-pci-y += tests/drive-mirror-test$(EXESUF)
+gcov-files-pci-y += hw/block/mirror.c
check-qtest-pci-y += tests/ac97-test$(EXESUF)
gcov-files-pci-y += hw/audio/ac97.c
check-qtest-pci-y += tests/es1370-test$(EXESUF)
@@ -610,6 +612,7 @@ tests/qom-test$(EXESUF): tests/qom-test.o
tests/drive_del-test$(EXESUF): tests/drive_del-test.o $(libqos-pc-obj-y)
tests/qdev-monitor-test$(EXESUF): tests/qdev-monitor-test.o $(libqos-pc-obj-y)
tests/nvme-test$(EXESUF): tests/nvme-test.o
+tests/drive-mirror-test$(EXESUF): tests/drive-mirror-test.o
tests/pvpanic-test$(EXESUF): tests/pvpanic-test.o
tests/i82801b11-test$(EXESUF): tests/i82801b11-test.o
tests/ac97-test$(EXESUF): tests/ac97-test.o
diff --git a/tests/drive-mirror-test.c b/tests/drive-mirror-test.c
new file mode 100755
index 0000000..1f86bb1
--- /dev/null
+++ b/tests/drive-mirror-test.c
@@ -0,0 +1,96 @@
+/*
+ * Drive mirror unit-tests.
+ *
+ * Copyright (c) 2014 HUAWEI TECHNOLOGIES CO., LTD.
+ *
+ * Authors:
+ * Jie Wang <wangjie88@huawei.com>
+ *
+ * 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 <glib.h>
+#include <string.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <stdio.h>
+#include "libqtest.h"
+
+#define TEST_IMAGE_SIZE (10 * 1014 * 1024)
+#define PCI_SLOT 0x04
+#define PCI_FN 0x00
+
+static char *drive_create(void)
+{
+ int fd, ret;
+ char *tmp_path = g_strdup("/tmp/qtest-src-mirror.XXXXXX");
+
+ /* Create a temporary raw image */
+ fd = mkstemp(tmp_path);
+ g_assert_cmpint(fd, >=, 0);
+ ret = ftruncate(fd, TEST_IMAGE_SIZE);
+ g_assert_cmpint(ret, ==, 0);
+ close(fd);
+
+ return tmp_path;
+}
+
+static void mirror_test_start(void)
+{
+ char *cmdline;
+ char *tmp_path;
+
+ tmp_path = drive_create();
+
+ cmdline = g_strdup_printf("-drive if=none,id=drive0,file=%s,format=raw "
+ "-device virtio-blk-pci,id=drv0,drive=drive0,"
+ "addr=%x.%x",
+ tmp_path, PCI_SLOT, PCI_FN);
+
+ qtest_start(cmdline);
+ unlink(tmp_path);
+ g_free(tmp_path);
+ g_free(cmdline);
+}
+
+static void test_mirror_base(void)
+{
+ QDict *response;
+
+ mirror_test_start();
+
+ response = qmp("{\"execute\": \"drive-mirror\","
+ " \"arguments\": {"
+ " \"device\": \"drive0\","
+ " \"target\": \"/tmp/qtest-dest-mirror\","
+ " \"sync\": \"full\","
+ " \"mode\": \"absolute-paths\","
+ " \"format\": \"raw\""
+ "}}");
+
+ g_assert(response);
+ g_assert(!qdict_haskey(response, "error"));
+ QDECREF(response);
+
+ qtest_end();
+}
+
+int main(int argc, char **argv)
+{
+ int ret;
+ const char *arch = qtest_get_arch();
+
+ g_test_init(&argc, &argv, NULL);
+
+ if (strcmp(arch, "i386") == 0 || strcmp(arch, "x86_64") == 0) {
+ qtest_add_func("/mirror/mirror_base", test_mirror_base);
+ } else if (strcmp(arch, "arm") == 0) {
+ g_test_message("Skipping test for non-x86\n");
+ return 0;
+ }
+
+ ret = g_test_run();
+
+ return ret;
+}
--
1.7.12.4
next reply other threads:[~2016-09-06 14:08 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-09-06 12:30 Jie Wang [this message]
2016-09-06 14:27 ` [Qemu-devel] [PATCH] tests: add drive-mirror qtest WangJie (Captain)
2016-09-06 14:29 ` no-reply
2016-09-06 14:53 ` no-reply
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1473165001-8333-1-git-send-email-wangjie88@huawei.com \
--to=wangjie88@huawei.com \
--cc=eric.fangyi@huawei.com \
--cc=jcody@redhat.com \
--cc=kwolf@redhat.com \
--cc=mreitz@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=subo7@huawei.com \
--cc=wu.wubin@huawei.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.