qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Qemu-devel] [RFC V2 3/8] throttle: Add throttle group infrastructure te


From: Benoît Canet
Subject: [Qemu-devel] [RFC V2 3/8] throttle: Add throttle group infrastructure tests
Date: Wed, 13 Aug 2014 16:23:54 +0200

Signed-off-by: Benoit Canet <address@hidden>
---
 tests/test-throttle.c | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 51 insertions(+)

diff --git a/tests/test-throttle.c b/tests/test-throttle.c
index 66e4982..50e6655 100644
--- a/tests/test-throttle.c
+++ b/tests/test-throttle.c
@@ -14,6 +14,7 @@
 #include <math.h>
 #include "block/aio.h"
 #include "qemu/throttle.h"
+#include "block/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();
 }
 
-- 
2.1.0.rc1




reply via email to

[Prev in Thread] Current Thread [Next in Thread]