From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:48051) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bhHMy-0006eH-3j for qemu-devel@nongnu.org; Tue, 06 Sep 2016 10:29:04 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bhHMt-0006OX-Sd for qemu-devel@nongnu.org; Tue, 06 Sep 2016 10:28:59 -0400 Received: from szxga01-in.huawei.com ([58.251.152.64]:1425) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bhHMt-0006N6-1A for qemu-devel@nongnu.org; Tue, 06 Sep 2016 10:28:55 -0400 References: <1473165001-8333-1-git-send-email-wangjie88@huawei.com> From: "WangJie (Captain)" Message-ID: <57CED256.4080600@huawei.com> Date: Tue, 6 Sep 2016 22:27:34 +0800 MIME-Version: 1.0 In-Reply-To: <1473165001-8333-1-git-send-email-wangjie88@huawei.com> Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Subject: Re: [Qemu-devel] [PATCH] tests: add drive-mirror qtest List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: jcody@redhat.com Cc: kwolf@redhat.com, mreitz@redhat.com, qemu-devel@nongnu.org, wu.wubin@huawei.com, subo7@huawei.com, eric.fangyi@huawei.com Please ignore this messages, I will send a new one. Thank you On 2016/9/6 20:30, Jie Wang wrote: > Signed-off-by: Jie Wang > --- > 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 > + * > + * 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 > +#include > +#include > +#include > +#include > +#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; > +}