summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorManos Pitsidianakis <el13635@mail.ntua.gr>2017-08-25 16:20:24 +0300
committerKevin Wolf <kwolf@redhat.com>2017-09-05 16:47:52 +0200
commitc61791fc23ecd96e6a1e038c379c4033ffd5f40c (patch)
tree54226255fb34d61ce0dcfe2cf05724f3e2594c02 /tests
parent022cdc9f407434ad6eb7ace80362a1218a009bcc (diff)
block: add aio_context field in ThrottleGroupMember
timer_cb() needs to know about the current Aio context of the throttle request that is woken up. In order to make ThrottleGroupMember backend agnostic, this information is stored in an aio_context field instead of accessing it from BlockBackend. Reviewed-by: Alberto Garcia <berto@igalia.com> Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com> Signed-off-by: Manos Pitsidianakis <el13635@mail.ntua.gr> Signed-off-by: Kevin Wolf <kwolf@redhat.com>
Diffstat (limited to 'tests')
-rw-r--r--tests/test-throttle.c63
1 files changed, 33 insertions, 30 deletions
diff --git a/tests/test-throttle.c b/tests/test-throttle.c
index 69cc8b18e4..e3a45cc605 100644
--- a/tests/test-throttle.c
+++ b/tests/test-throttle.c
@@ -24,8 +24,9 @@
static AioContext *ctx;
static LeakyBucket bkt;
static ThrottleConfig cfg;
+static ThrottleGroupMember tgm;
static ThrottleState ts;
-static ThrottleTimers tt;
+static ThrottleTimers *tt;
/* useful function */
static bool double_cmp(double x, double y)
@@ -153,19 +154,21 @@ static void test_init(void)
{
int i;
+ tt = &tgm.throttle_timers;
+
/* fill the structures with crap */
memset(&ts, 1, sizeof(ts));
- memset(&tt, 1, sizeof(tt));
+ memset(tt, 1, sizeof(*tt));
/* init structures */
throttle_init(&ts);
- throttle_timers_init(&tt, ctx, QEMU_CLOCK_VIRTUAL,
+ throttle_timers_init(tt, ctx, QEMU_CLOCK_VIRTUAL,
read_timer_cb, write_timer_cb, &ts);
/* check initialized fields */
- g_assert(tt.clock_type == QEMU_CLOCK_VIRTUAL);
- g_assert(tt.timers[0]);
- g_assert(tt.timers[1]);
+ g_assert(tt->clock_type == QEMU_CLOCK_VIRTUAL);
+ g_assert(tt->timers[0]);
+ g_assert(tt->timers[1]);
/* check other fields where cleared */
g_assert(!ts.previous_leak);
@@ -176,18 +179,18 @@ static void test_init(void)
g_assert(!ts.cfg.buckets[i].level);
}
- throttle_timers_destroy(&tt);
+ throttle_timers_destroy(tt);
}
static void test_destroy(void)
{
int i;
throttle_init(&ts);
- throttle_timers_init(&tt, ctx, QEMU_CLOCK_VIRTUAL,
+ throttle_timers_init(tt, ctx, QEMU_CLOCK_VIRTUAL,
read_timer_cb, write_timer_cb, &ts);
- throttle_timers_destroy(&tt);
+ throttle_timers_destroy(tt);
for (i = 0; i < 2; i++) {
- g_assert(!tt.timers[i]);
+ g_assert(!tt->timers[i]);
}
}
@@ -224,7 +227,7 @@ static void test_config_functions(void)
orig_cfg.op_size = 1;
throttle_init(&ts);
- throttle_timers_init(&tt, ctx, QEMU_CLOCK_VIRTUAL,
+ throttle_timers_init(tt, ctx, QEMU_CLOCK_VIRTUAL,
read_timer_cb, write_timer_cb, &ts);
/* structure reset by throttle_init previous_leak should be null */
g_assert(!ts.previous_leak);
@@ -236,7 +239,7 @@ static void test_config_functions(void)
/* get back the fixed configuration */
throttle_get_config(&ts, &final_cfg);
- throttle_timers_destroy(&tt);
+ throttle_timers_destroy(tt);
g_assert(final_cfg.buckets[THROTTLE_BPS_TOTAL].avg == 153);
g_assert(final_cfg.buckets[THROTTLE_BPS_READ].avg == 56);
@@ -494,45 +497,45 @@ static void test_have_timer(void)
{
/* zero structures */
memset(&ts, 0, sizeof(ts));
- memset(&tt, 0, sizeof(tt));
+ memset(tt, 0, sizeof(*tt));
/* no timer set should return false */
- g_assert(!throttle_timers_are_initialized(&tt));
+ g_assert(!throttle_timers_are_initialized(tt));
/* init structures */
throttle_init(&ts);
- throttle_timers_init(&tt, ctx, QEMU_CLOCK_VIRTUAL,
+ throttle_timers_init(tt, ctx, QEMU_CLOCK_VIRTUAL,
read_timer_cb, write_timer_cb, &ts);
/* timer set by init should return true */
- g_assert(throttle_timers_are_initialized(&tt));
+ g_assert(throttle_timers_are_initialized(tt));
- throttle_timers_destroy(&tt);
+ throttle_timers_destroy(tt);
}
static void test_detach_attach(void)
{
/* zero structures */
memset(&ts, 0, sizeof(ts));
- memset(&tt, 0, sizeof(tt));
+ memset(tt, 0, sizeof(*tt));
/* init the structure */
throttle_init(&ts);
- throttle_timers_init(&tt, ctx, QEMU_CLOCK_VIRTUAL,
+ throttle_timers_init(tt, ctx, QEMU_CLOCK_VIRTUAL,
read_timer_cb, write_timer_cb, &ts);
/* timer set by init should return true */
- g_assert(throttle_timers_are_initialized(&tt));
+ g_assert(throttle_timers_are_initialized(tt));
/* timer should no longer exist after detaching */
- throttle_timers_detach_aio_context(&tt);
- g_assert(!throttle_timers_are_initialized(&tt));
+ throttle_timers_detach_aio_context(tt);
+ g_assert(!throttle_timers_are_initialized(tt));
/* timer should exist again after attaching */
- throttle_timers_attach_aio_context(&tt, ctx);
- g_assert(throttle_timers_are_initialized(&tt));
+ throttle_timers_attach_aio_context(tt, ctx);
+ g_assert(throttle_timers_are_initialized(tt));
- throttle_timers_destroy(&tt);
+ throttle_timers_destroy(tt);
}
static bool do_test_accounting(bool is_ops, /* are we testing bps or ops */
@@ -561,7 +564,7 @@ static bool do_test_accounting(bool is_ops, /* are we testing bps or ops */
cfg.op_size = op_size;
throttle_init(&ts);
- throttle_timers_init(&tt, ctx, QEMU_CLOCK_VIRTUAL,
+ throttle_timers_init(tt, ctx, QEMU_CLOCK_VIRTUAL,
read_timer_cb, write_timer_cb, &ts);
throttle_config(&ts, QEMU_CLOCK_VIRTUAL, &cfg);
@@ -588,7 +591,7 @@ static bool do_test_accounting(bool is_ops, /* are we testing bps or ops */
return false;
}
- throttle_timers_destroy(&tt);
+ throttle_timers_destroy(tt);
return true;
}
@@ -688,9 +691,9 @@ static void test_groups(void)
g_assert(tgm2->throttle_state == NULL);
g_assert(tgm3->throttle_state == NULL);
- throttle_group_register_tgm(tgm1, "bar");
- throttle_group_register_tgm(tgm2, "foo");
- throttle_group_register_tgm(tgm3, "bar");
+ throttle_group_register_tgm(tgm1, "bar", blk_get_aio_context(blk1));
+ throttle_group_register_tgm(tgm2, "foo", blk_get_aio_context(blk2));
+ throttle_group_register_tgm(tgm3, "bar", blk_get_aio_context(blk3));
g_assert(tgm1->throttle_state != NULL);
g_assert(tgm2->throttle_state != NULL);