From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:39924) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bQF1b-00033i-Mw for qemu-devel@nongnu.org; Thu, 21 Jul 2016 10:32:32 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bQF1a-0003lk-09 for qemu-devel@nongnu.org; Thu, 21 Jul 2016 10:32:31 -0400 From: Dmitry Osipenko Date: Thu, 21 Jul 2016 17:31:20 +0300 Message-Id: <638cddbcb65b0e5e4bcedacbd991cba12779fafc.1469110137.git.digetx@gmail.com> In-Reply-To: References: In-Reply-To: References: Subject: [Qemu-devel] [PATCH v15 09/15] tests: ptimer: Add tests for "continuous trigger" policy List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: QEMU Developers , qemu-arm@nongnu.org Cc: Peter Crosthwaite , Peter Maydell PTIMER_POLICY_CONTINUOUS_TRIGGER makes periodic ptimer to re-trigger every period in case of load = delta = 0. Signed-off-by: Dmitry Osipenko --- tests/ptimer-test.c | 66 ++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 65 insertions(+), 1 deletion(-) diff --git a/tests/ptimer-test.c b/tests/ptimer-test.c index 981414d..cdf8d28 100644 --- a/tests/ptimer-test.c +++ b/tests/ptimer-test.c @@ -437,6 +437,58 @@ static void check_run_with_delta_0(gconstpointer arg) ptimer_stop(ptimer); } +static void check_periodic_with_load_0(gconstpointer arg) +{ + const uint8_t *policy = arg; + QEMUBH *bh = qemu_bh_new(ptimer_trigger, NULL); + ptimer_state *ptimer = ptimer_init(bh, *policy); + bool continuous_trigger = (*policy & PTIMER_POLICY_CONTINUOUS_TRIGGER); + + triggered = false; + + ptimer_set_period(ptimer, 2000000); + ptimer_run(ptimer, 0); + + g_assert_cmpuint(ptimer_get_count(ptimer), ==, 0); + g_assert_true(triggered); + + triggered = false; + + qemu_clock_step(2000000 + 100000); + + g_assert_cmpuint(ptimer_get_count(ptimer), ==, 0); + + if (continuous_trigger) { + g_assert_true(triggered); + } else { + g_assert_false(triggered); + } + + ptimer_stop(ptimer); +} + +static void check_oneshot_with_load_0(gconstpointer arg) +{ + const uint8_t *policy = arg; + QEMUBH *bh = qemu_bh_new(ptimer_trigger, NULL); + ptimer_state *ptimer = ptimer_init(bh, *policy); + + triggered = false; + + ptimer_set_period(ptimer, 2000000); + ptimer_run(ptimer, 1); + + g_assert_cmpuint(ptimer_get_count(ptimer), ==, 0); + g_assert_true(triggered); + + triggered = false; + + qemu_clock_step(2000000 + 100000); + + g_assert_cmpuint(ptimer_get_count(ptimer), ==, 0); + g_assert_false(triggered); +} + static void add_ptimer_tests(uint8_t policy) { uint8_t *ppolicy = g_malloc(1); @@ -452,6 +504,10 @@ static void add_ptimer_tests(uint8_t policy) g_strlcat(policy_name, "wrap_after_one_period,", 256); } + if (policy & PTIMER_POLICY_CONTINUOUS_TRIGGER) { + g_strlcat(policy_name, "continuous_trigger,", 256); + } + qtest_add_data_func( g_strdup_printf("/ptimer/set_count policy=%s", policy_name), ppolicy, check_set_count); @@ -487,11 +543,19 @@ static void add_ptimer_tests(uint8_t policy) qtest_add_data_func( g_strdup_printf("/ptimer/run_with_delta_0 policy=%s", policy_name), ppolicy, check_run_with_delta_0); + + qtest_add_data_func( + g_strdup_printf("/ptimer/periodic_with_load_0 policy=%s", policy_name), + ppolicy, check_periodic_with_load_0); + + qtest_add_data_func( + g_strdup_printf("/ptimer/oneshot_with_load_0 policy=%s", policy_name), + ppolicy, check_oneshot_with_load_0); } static void add_all_ptimer_policies_comb_tests(void) { - int last_policy = PTIMER_POLICY_WRAP_AFTER_ONE_PERIOD; + int last_policy = PTIMER_POLICY_CONTINUOUS_TRIGGER; int policy = PTIMER_POLICY_DEFAULT; for (; policy < (last_policy << 1); policy++) { -- 2.9.2