From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:58909) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Z3QPO-00088X-Fu for qemu-devel@nongnu.org; Fri, 12 Jun 2015 10:58:15 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Z3QPN-0004uw-B6 for qemu-devel@nongnu.org; Fri, 12 Jun 2015 10:58:14 -0400 Received: from mx1.redhat.com ([209.132.183.28]:47341) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Z3QPN-0004uo-4R for qemu-devel@nongnu.org; Fri, 12 Jun 2015 10:58:13 -0400 From: Stefan Hajnoczi Date: Fri, 12 Jun 2015 15:57:53 +0100 Message-Id: <1434121078-15776-6-git-send-email-stefanha@redhat.com> In-Reply-To: <1434121078-15776-1-git-send-email-stefanha@redhat.com> References: <1434121078-15776-1-git-send-email-stefanha@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Subject: [Qemu-devel] [PULL 05/10] throttle: Add throttle group infrastructure tests List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Kevin Wolf , Peter Maydell , Alberto Garcia , Stefan Hajnoczi From: Alberto Garcia Signed-off-by: Alberto Garcia Message-id: ba7b9dc7fca43efbb31d5f3aad91a8dbdbea635b.1433779731.git.berto= @igalia.com Cc: Stefan Hajnoczi Signed-off-by: Stefan Hajnoczi --- tests/test-throttle.c | 81 ++++++++++++++++++++++++++++++++++++++++++++-= ------ 1 file changed, 71 insertions(+), 10 deletions(-) diff --git a/tests/test-throttle.c b/tests/test-throttle.c index 458f577..0168445 100644 --- a/tests/test-throttle.c +++ b/tests/test-throttle.c @@ -1,10 +1,12 @@ /* * Throttle infrastructure tests * - * Copyright Nodalink, SARL. 2013 + * Copyright Nodalink, EURL. 2013-2014 + * Copyright Igalia, S.L. 2015 * * Authors: - * Beno=C3=AEt Canet + * Beno=C3=AEt Canet + * Alberto Garcia * * This work is licensed under the terms of the GNU LGPL, version 2 or l= ater. * See the COPYING.LIB file in the top-level directory. @@ -15,6 +17,7 @@ #include "block/aio.h" #include "qemu/throttle.h" #include "qemu/error-report.h" +#include "block/throttle-groups.h" =20 static AioContext *ctx; static LeakyBucket bkt; @@ -500,23 +503,80 @@ static void test_accounting(void) (64.0 / 13))); } =20 +static void test_groups(void) +{ + ThrottleConfig cfg1, cfg2; + BlockDriverState *bdrv1, *bdrv2, *bdrv3; + + bdrv1 =3D bdrv_new(); + bdrv2 =3D bdrv_new(); + bdrv3 =3D bdrv_new(); + + g_assert(bdrv1->throttle_state =3D=3D NULL); + g_assert(bdrv2->throttle_state =3D=3D NULL); + g_assert(bdrv3->throttle_state =3D=3D NULL); + + throttle_group_register_bs(bdrv1, "bar"); + throttle_group_register_bs(bdrv2, "foo"); + throttle_group_register_bs(bdrv3, "bar"); + + g_assert(bdrv1->throttle_state !=3D NULL); + g_assert(bdrv2->throttle_state !=3D NULL); + g_assert(bdrv3->throttle_state !=3D NULL); + + g_assert(!strcmp(throttle_group_get_name(bdrv1), "bar")); + g_assert(!strcmp(throttle_group_get_name(bdrv2), "foo")); + g_assert(bdrv1->throttle_state =3D=3D bdrv3->throttle_state); + + /* Setting the config of a group member affects the whole group */ + memset(&cfg1, 0, sizeof(cfg1)); + cfg1.buckets[THROTTLE_BPS_READ].avg =3D 500000; + cfg1.buckets[THROTTLE_BPS_WRITE].avg =3D 285000; + cfg1.buckets[THROTTLE_OPS_READ].avg =3D 20000; + cfg1.buckets[THROTTLE_OPS_WRITE].avg =3D 12000; + throttle_group_config(bdrv1, &cfg1); + + throttle_group_get_config(bdrv1, &cfg1); + throttle_group_get_config(bdrv3, &cfg2); + g_assert(!memcmp(&cfg1, &cfg2, sizeof(cfg1))); + + cfg2.buckets[THROTTLE_BPS_READ].avg =3D 4547; + cfg2.buckets[THROTTLE_BPS_WRITE].avg =3D 1349; + cfg2.buckets[THROTTLE_OPS_READ].avg =3D 123; + cfg2.buckets[THROTTLE_OPS_WRITE].avg =3D 86; + throttle_group_config(bdrv3, &cfg1); + + throttle_group_get_config(bdrv1, &cfg1); + throttle_group_get_config(bdrv3, &cfg2); + g_assert(!memcmp(&cfg1, &cfg2, sizeof(cfg1))); + + throttle_group_unregister_bs(bdrv1); + throttle_group_unregister_bs(bdrv2); + throttle_group_unregister_bs(bdrv3); + + g_assert(bdrv1->throttle_state =3D=3D NULL); + g_assert(bdrv2->throttle_state =3D=3D NULL); + g_assert(bdrv3->throttle_state =3D=3D NULL); +} + int main(int argc, char **argv) { - GSource *src; Error *local_error =3D NULL; =20 - init_clocks(); + qemu_init_main_loop(&local_error); + ctx =3D qemu_get_aio_context(); =20 - ctx =3D aio_context_new(&local_error); if (!ctx) { error_report("Failed to create AIO Context: '%s'", - error_get_pretty(local_error)); - error_free(local_error); + local_error ? error_get_pretty(local_error) : + "Failed to initialize the QEMU main loop"); + if (local_error) { + error_free(local_error); + } exit(1); } - src =3D aio_get_g_source(ctx); - g_source_attach(src, NULL); - g_source_unref(src); + + bdrv_init(); =20 do {} while (g_main_context_iteration(NULL, false)); =20 @@ -533,6 +593,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_function= s); g_test_add_func("/throttle/accounting", test_accounting); + g_test_add_func("/throttle/groups", test_groups); return g_test_run(); } =20 --=20 2.4.2