From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:49840) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Wswni-0005Xv-Vt for qemu-devel@nongnu.org; Fri, 06 Jun 2014 12:15:35 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Wswnd-0004qB-Mg for qemu-devel@nongnu.org; Fri, 06 Jun 2014 12:15:30 -0400 Received: from mx1.redhat.com ([209.132.183.28]:15189) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Wswnd-0004q7-Df for qemu-devel@nongnu.org; Fri, 06 Jun 2014 12:15:25 -0400 From: Stefan Hajnoczi Date: Fri, 6 Jun 2014 18:13:53 +0200 Message-Id: <1402071243-16702-33-git-send-email-stefanha@redhat.com> In-Reply-To: <1402071243-16702-1-git-send-email-stefanha@redhat.com> References: <1402071243-16702-1-git-send-email-stefanha@redhat.com> Subject: [Qemu-devel] [PULL 32/42] throttle: add detach/attach test case List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Peter Maydell , Stefan Hajnoczi Add a test case that checks the timer is really removed/added by the detach/attach functions. Signed-off-by: Stefan Hajnoczi Reviewed-by: Benoit Canet --- tests/test-throttle.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/tests/test-throttle.c b/tests/test-throttle.c index 5fa5000..3de6ab8 100644 --- a/tests/test-throttle.c +++ b/tests/test-throttle.c @@ -338,6 +338,29 @@ static void test_have_timer(void) throttle_destroy(&ts); } +static void test_detach_attach(void) +{ + /* zero the structure */ + memset(&ts, 0, sizeof(ts)); + + /* init the structure */ + throttle_init(&ts, ctx, QEMU_CLOCK_VIRTUAL, + read_timer_cb, write_timer_cb, &ts); + + /* timer set by init should return true */ + g_assert(throttle_have_timer(&ts)); + + /* timer should no longer exist after detaching */ + throttle_detach_aio_context(&ts); + g_assert(!throttle_have_timer(&ts)); + + /* timer should exist again after attaching */ + throttle_attach_aio_context(&ts, ctx); + g_assert(throttle_have_timer(&ts)); + + throttle_destroy(&ts); +} + static bool do_test_accounting(bool is_ops, /* are we testing bps or ops */ int size, /* size of the operation to do */ double avg, /* io limit */ @@ -486,6 +509,7 @@ int main(int argc, char **argv) g_test_add_func("/throttle/init", test_init); g_test_add_func("/throttle/destroy", test_destroy); g_test_add_func("/throttle/have_timer", test_have_timer); + g_test_add_func("/throttle/detach_attach", test_detach_attach); g_test_add_func("/throttle/config/enabled", test_enabled); g_test_add_func("/throttle/config/conflicting", test_conflicting_config); g_test_add_func("/throttle/config/is_valid", test_is_valid); -- 1.9.3