From patchwork Tue Sep 6 12:30:01 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jie Wang X-Patchwork-Id: 9317073 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 0203860752 for ; Tue, 6 Sep 2016 14:15:38 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0BE4428C8B for ; Tue, 6 Sep 2016 14:15:38 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id F40B328C9E; Tue, 6 Sep 2016 14:15:37 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id C3E5628C8B for ; Tue, 6 Sep 2016 14:15:35 +0000 (UTC) Received: from localhost ([::1]:33771 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bhH9y-0003pB-8f for patchwork-qemu-devel@patchwork.kernel.org; Tue, 06 Sep 2016 10:15:34 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:40975) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bhH2t-0005n8-0i for qemu-devel@nongnu.org; Tue, 06 Sep 2016 10:08:19 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bhH2j-000176-Fg for qemu-devel@nongnu.org; Tue, 06 Sep 2016 10:08:10 -0400 Received: from szxga01-in.huawei.com ([58.251.152.64]:60292) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bhH2i-00016g-MG for qemu-devel@nongnu.org; Tue, 06 Sep 2016 10:08:05 -0400 Received: from 172.24.1.60 (EHLO SZXEML423-HUB.china.huawei.com) ([172.24.1.60]) by szxrg01-dlp.huawei.com (MOS 4.3.7-GA FastPath queued) with ESMTP id DQR44578; Tue, 06 Sep 2016 22:07:58 +0800 (CST) Received: from localhost.localdomain (10.175.101.253) by SZXEML423-HUB.china.huawei.com (10.82.67.154) with Microsoft SMTP Server id 14.3.235.1; Tue, 6 Sep 2016 22:07:48 +0800 From: Jie Wang To: Date: Tue, 6 Sep 2016 12:30:01 +0000 Message-ID: <1473165001-8333-1-git-send-email-wangjie88@huawei.com> X-Mailer: git-send-email 1.8.5 MIME-Version: 1.0 X-Originating-IP: [10.175.101.253] X-CFilter-Loop: Reflected X-Mirapoint-Virus-RAPID-Raw: score=unknown(0), refid=str=0001.0A020202.57CECDBF.03A1, ss=1, re=0.000, recu=0.000, reip=0.000, cl=1, cld=1, fgs=0, ip=0.0.0.0, so=2013-06-18 04:22:30, dmn=2013-03-21 17:37:32 X-Mirapoint-Loop-Id: af8abebaecfb969626d23017ecbc69cd X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.4.x-2.6.x [generic] X-Received-From: 58.251.152.64 Subject: [Qemu-devel] [PATCH] tests: add drive-mirror qtest X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, subo7@huawei.com, eric.fangyi@huawei.com, qemu-devel@nongnu.org, mreitz@redhat.com, wangjie88@huawei.com, wu.wubin@huawei.com Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP 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; +}