From patchwork Tue Aug 12 13:42:25 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Beno=C3=AEt_Canet?= X-Patchwork-Id: 379351 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 35FC6140087 for ; Tue, 12 Aug 2014 23:51:25 +1000 (EST) Received: from localhost ([::1]:42177 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XHCTz-0005ig-CL for incoming@patchwork.ozlabs.org; Tue, 12 Aug 2014 09:51:23 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:41549) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XHCMK-0000hH-Fd for qemu-devel@nongnu.org; Tue, 12 Aug 2014 09:43:33 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XHCMC-0001WG-M2 for qemu-devel@nongnu.org; Tue, 12 Aug 2014 09:43:28 -0400 Received: from lputeaux-656-01-25-125.w80-12.abo.wanadoo.fr ([80.12.84.125]:41990 helo=paradis.irqsave.net) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XHCMC-0001VZ-Fi for qemu-devel@nongnu.org; Tue, 12 Aug 2014 09:43:20 -0400 Received: from localhost.localdomain (laure.irqsave.net [192.168.77.2]) by paradis.irqsave.net (Postfix) with ESMTP id BEA3DCB502; Tue, 12 Aug 2014 15:43:17 +0200 (CEST) From: =?UTF-8?q?Beno=C3=AEt=20Canet?= To: qemu-devel@nongnu.org Date: Tue, 12 Aug 2014 15:42:25 +0200 Message-Id: <1407850947-17625-4-git-send-email-benoit.canet@irqsave.net> X-Mailer: git-send-email 2.1.0.rc1 In-Reply-To: <1407850947-17625-1-git-send-email-benoit.canet@irqsave.net> References: <1407850947-17625-1-git-send-email-benoit.canet@irqsave.net> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [generic] X-Received-From: 80.12.84.125 Cc: kwolf@redhat.com, =?UTF-8?q?Beno=C3=AEt=20Canet?= , Benoit Canet , stefanha@redhat.com Subject: [Qemu-devel] [RFC 3/5] throttle: Add throttle group infrastructure tests X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Signed-off-by: Benoit Canet --- tests/test-throttle.c | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) diff --git a/tests/test-throttle.c b/tests/test-throttle.c index 66e4982..494a806 100644 --- a/tests/test-throttle.c +++ b/tests/test-throttle.c @@ -14,6 +14,7 @@ #include #include "block/aio.h" #include "qemu/throttle.h" +#include "qemu/throttle-groups.h" static AioContext *ctx; static LeakyBucket bkt; @@ -499,6 +500,55 @@ static void test_accounting(void) (64.0 / 13))); } +static void test_groups(void) +{ + bool removed; + + ThrottleState *ts_foo, *ts_bar, *tmp; + + ts_bar = throttle_group_incref("bar"); + throttle_group_set_token(ts_bar, (BlockDriverState *) 0x5, false); + ts_foo = throttle_group_incref("foo"); + + tmp = throttle_group_incref("foo"); + throttle_group_set_token(tmp, (BlockDriverState *) 0x7, true); + g_assert(tmp == ts_foo); + + tmp = throttle_group_incref("bar"); + g_assert(tmp == ts_bar); + + tmp = throttle_group_incref("bar"); + g_assert(tmp == ts_bar); + + g_assert((int64_t) throttle_group_token(ts_bar, false) == 0x5); + g_assert((int64_t) throttle_group_token(ts_foo, true) == 0x7); + + removed = throttle_group_unref(ts_foo); + g_assert(removed); + removed = throttle_group_unref(ts_bar); + g_assert(removed); + + g_assert((int64_t) throttle_group_token(ts_foo, true) == 0x7); + + removed = throttle_group_unref(ts_foo); + g_assert(removed); + removed = throttle_group_unref(ts_bar); + g_assert(removed); + + /* "foo" group should be destroyed when reaching this */ + removed = throttle_group_unref(ts_foo); + g_assert(!removed); + + g_assert((int64_t) throttle_group_token(ts_bar, false) == 0x5); + + removed = throttle_group_unref(ts_bar); + g_assert(removed); + + /* "bar" group should be destroyed when reaching this */ + removed = throttle_group_unref(ts_bar); + g_assert(!removed); +} + int main(int argc, char **argv) { GSource *src; @@ -525,6 +575,7 @@ int main(int argc, char **argv) g_test_add_func("/throttle/config/is_valid", test_is_valid); g_test_add_func("/throttle/config_functions", test_config_functions); g_test_add_func("/throttle/accounting", test_accounting); + g_test_add_func("/throttle/groups", test_groups); return g_test_run(); }