From nobody Wed Dec 17 21:51:50 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1520018700712709.4792548770265; Fri, 2 Mar 2018 11:25:00 -0800 (PST) Received: from localhost ([::1]:37050 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1erqId-0002T8-SP for importer@patchew.org; Fri, 02 Mar 2018 14:24:59 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:53111) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1erpqh-0001rx-So for qemu-devel@nongnu.org; Fri, 02 Mar 2018 13:56:09 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1erpqg-0003I1-T9 for qemu-devel@nongnu.org; Fri, 02 Mar 2018 13:56:07 -0500 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:60128 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1erpqd-0003EK-0E; Fri, 02 Mar 2018 13:56:03 -0500 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 8245D4022909; Fri, 2 Mar 2018 18:56:02 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-117-66.ams2.redhat.com [10.36.117.66]) by smtp.corp.redhat.com (Postfix) with ESMTP id 618F59C079; Fri, 2 Mar 2018 18:55:58 +0000 (UTC) From: Kevin Wolf To: qemu-block@nongnu.org Date: Fri, 2 Mar 2018 19:54:40 +0100 Message-Id: <20180302185448.6314-30-kwolf@redhat.com> In-Reply-To: <20180302185448.6314-1-kwolf@redhat.com> References: <20180302185448.6314-1-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.6]); Fri, 02 Mar 2018 18:56:02 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.6]); Fri, 02 Mar 2018 18:56:02 +0000 (UTC) for IP:'10.11.54.5' DOMAIN:'int-mx05.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'kwolf@redhat.com' RCPT:'' X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [PULL 29/37] block: test blk_aio_flush() with blk->root == NULL 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, qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" This patch adds test cases for the scenario where blk_aio_flush() is called on a BlockBackend with no root. Calling drain afterwards should complete the requests with -ENOMEDIUM. Signed-off-by: Kevin Wolf Signed-off-by: Stefan Hajnoczi Reviewed-by: Eric Blake Signed-off-by: Kevin Wolf --- tests/test-block-backend.c | 82 ++++++++++++++++++++++++++++++++++++++++++= ++++ tests/Makefile.include | 2 ++ 2 files changed, 84 insertions(+) create mode 100644 tests/test-block-backend.c diff --git a/tests/test-block-backend.c b/tests/test-block-backend.c new file mode 100644 index 0000000000..fd59f02bd0 --- /dev/null +++ b/tests/test-block-backend.c @@ -0,0 +1,82 @@ +/* + * BlockBackend tests + * + * Copyright (c) 2017 Kevin Wolf + * + * Permission is hereby granted, free of charge, to any person obtaining a= copy + * of this software and associated documentation files (the "Software"), t= o deal + * in the Software without restriction, including without limitation the r= ights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or se= ll + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included= in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS= OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OT= HER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING= FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS = IN + * THE SOFTWARE. + */ + +#include "qemu/osdep.h" +#include "block/block.h" +#include "sysemu/block-backend.h" +#include "qapi/error.h" + +static void test_drain_aio_error_flush_cb(void *opaque, int ret) +{ + bool *completed =3D opaque; + + g_assert(ret =3D=3D -ENOMEDIUM); + *completed =3D true; +} + +static void test_drain_aio_error(void) +{ + BlockBackend *blk =3D blk_new(BLK_PERM_ALL, BLK_PERM_ALL); + BlockAIOCB *acb; + bool completed =3D false; + + acb =3D blk_aio_flush(blk, test_drain_aio_error_flush_cb, &completed); + g_assert(acb !=3D NULL); + g_assert(completed =3D=3D false); + + blk_drain(blk); + g_assert(completed =3D=3D true); + + blk_unref(blk); +} + +static void test_drain_all_aio_error(void) +{ + BlockBackend *blk =3D blk_new(BLK_PERM_ALL, BLK_PERM_ALL); + BlockAIOCB *acb; + bool completed =3D false; + + acb =3D blk_aio_flush(blk, test_drain_aio_error_flush_cb, &completed); + g_assert(acb !=3D NULL); + g_assert(completed =3D=3D false); + + blk_drain_all(); + g_assert(completed =3D=3D true); + + blk_unref(blk); +} + +int main(int argc, char **argv) +{ + bdrv_init(); + qemu_init_main_loop(&error_abort); + + g_test_init(&argc, &argv, NULL); + + g_test_add_func("/block-backend/drain_aio_error", test_drain_aio_error= ); + g_test_add_func("/block-backend/drain_all_aio_error", + test_drain_all_aio_error); + + return g_test_run(); +} diff --git a/tests/Makefile.include b/tests/Makefile.include index 937cbd874a..b5aab848b3 100644 --- a/tests/Makefile.include +++ b/tests/Makefile.include @@ -83,6 +83,7 @@ gcov-files-test-hbitmap-y =3D blockjob.c check-unit-y +=3D tests/test-bdrv-drain$(EXESUF) check-unit-y +=3D tests/test-blockjob$(EXESUF) check-unit-y +=3D tests/test-blockjob-txn$(EXESUF) +check-unit-y +=3D tests/test-block-backend$(EXESUF) check-unit-y +=3D tests/test-x86-cpuid$(EXESUF) # all code tested by test-x86-cpuid is inside topology.h gcov-files-test-x86-cpuid-y =3D @@ -613,6 +614,7 @@ tests/test-throttle$(EXESUF): tests/test-throttle.o $(t= est-block-obj-y) tests/test-bdrv-drain$(EXESUF): tests/test-bdrv-drain.o $(test-block-obj-y= ) $(test-util-obj-y) tests/test-blockjob$(EXESUF): tests/test-blockjob.o $(test-block-obj-y) $(= test-util-obj-y) tests/test-blockjob-txn$(EXESUF): tests/test-blockjob-txn.o $(test-block-o= bj-y) $(test-util-obj-y) +tests/test-block-backend$(EXESUF): tests/test-block-backend.o $(test-block= -obj-y) $(test-util-obj-y) tests/test-thread-pool$(EXESUF): tests/test-thread-pool.o $(test-block-obj= -y) tests/test-iov$(EXESUF): tests/test-iov.o $(test-util-obj-y) tests/test-hbitmap$(EXESUF): tests/test-hbitmap.o $(test-util-obj-y) $(tes= t-crypto-obj-y) --=20 2.13.6