[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-block] [PATCH] test: add drive-mirror qtest
From: |
Jie Wang |
Subject: |
[Qemu-block] [PATCH] test: add drive-mirror qtest |
Date: |
Tue, 6 Sep 2016 14:01:59 +0000 |
Signed-off-by: Jie Wang <address@hidden>
---
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..d1353bd 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 += 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 <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 <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
- [Qemu-block] [PATCH] test: add drive-mirror qtest,
Jie Wang <=