[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH v15 07/15] tests: ptimer: Add tests for "wraparound
From: |
Dmitry Osipenko |
Subject: |
[Qemu-devel] [PATCH v15 07/15] tests: ptimer: Add tests for "wraparound after one period" policy |
Date: |
Thu, 21 Jul 2016 17:31:18 +0300 |
PTIMER_POLICY_WRAP_AFTER_ONE_PERIOD changes ptimer behaviour in a such way,
that it would wrap around after one period instead of doing it immediately.
Signed-off-by: Dmitry Osipenko <address@hidden>
---
tests/ptimer-test.c | 45 +++++++++++++++++++++++++++++++--------------
1 file changed, 31 insertions(+), 14 deletions(-)
diff --git a/tests/ptimer-test.c b/tests/ptimer-test.c
index 5c87828..981414d 100644
--- a/tests/ptimer-test.c
+++ b/tests/ptimer-test.c
@@ -188,6 +188,7 @@ static void check_periodic(gconstpointer arg)
const uint8_t *policy = arg;
QEMUBH *bh = qemu_bh_new(ptimer_trigger, NULL);
ptimer_state *ptimer = ptimer_init(bh, *policy);
+ bool wrap_policy = (*policy & PTIMER_POLICY_WRAP_AFTER_ONE_PERIOD);
triggered = false;
@@ -197,14 +198,14 @@ static void check_periodic(gconstpointer arg)
qemu_clock_step(2000000 * 10 + 100000);
- g_assert_cmpuint(ptimer_get_count(ptimer), ==, 10);
+ g_assert_cmpuint(ptimer_get_count(ptimer), ==, wrap_policy ? 0 : 10);
g_assert_true(triggered);
triggered = false;
qemu_clock_step(2000000);
- g_assert_cmpuint(ptimer_get_count(ptimer), ==, 9);
+ g_assert_cmpuint(ptimer_get_count(ptimer), ==, wrap_policy ? 10 : 9);
g_assert_false(triggered);
ptimer_set_count(ptimer, 20);
@@ -216,7 +217,7 @@ static void check_periodic(gconstpointer arg)
qemu_clock_step(2000000 * 10);
- g_assert_cmpuint(ptimer_get_count(ptimer), ==, 9);
+ g_assert_cmpuint(ptimer_get_count(ptimer), ==, wrap_policy ? 10 : 9);
g_assert_true(triggered);
ptimer_stop(ptimer);
@@ -224,7 +225,7 @@ static void check_periodic(gconstpointer arg)
qemu_clock_step(2000000);
- g_assert_cmpuint(ptimer_get_count(ptimer), ==, 9);
+ g_assert_cmpuint(ptimer_get_count(ptimer), ==, wrap_policy ? 10 : 9);
g_assert_false(triggered);
ptimer_set_count(ptimer, 3);
@@ -232,14 +233,14 @@ static void check_periodic(gconstpointer arg)
qemu_clock_step(2000000 * 3 + 100000);
- g_assert_cmpuint(ptimer_get_count(ptimer), ==, 10);
+ g_assert_cmpuint(ptimer_get_count(ptimer), ==, wrap_policy ? 0 : 10);
g_assert_true(triggered);
triggered = false;
qemu_clock_step(2000000);
- g_assert_cmpuint(ptimer_get_count(ptimer), ==, 9);
+ g_assert_cmpuint(ptimer_get_count(ptimer), ==, wrap_policy ? 10 : 9);
g_assert_false(triggered);
ptimer_set_count(ptimer, 0);
@@ -250,7 +251,7 @@ static void check_periodic(gconstpointer arg)
qemu_clock_step(2000000 * 12 + 100000);
- g_assert_cmpuint(ptimer_get_count(ptimer), ==, 8);
+ g_assert_cmpuint(ptimer_get_count(ptimer), ==, wrap_policy ? 9 : 8);
g_assert_true(triggered);
ptimer_stop(ptimer);
@@ -259,7 +260,7 @@ static void check_periodic(gconstpointer arg)
qemu_clock_step(2000000 * 12 + 100000);
- g_assert_cmpuint(ptimer_get_count(ptimer), ==, 8);
+ g_assert_cmpuint(ptimer_get_count(ptimer), ==, wrap_policy ? 9 : 8);
g_assert_false(triggered);
}
@@ -268,6 +269,7 @@ static void check_on_the_fly_mode_change(gconstpointer arg)
const uint8_t *policy = arg;
QEMUBH *bh = qemu_bh_new(ptimer_trigger, NULL);
ptimer_state *ptimer = ptimer_init(bh, *policy);
+ bool wrap_policy = (*policy & PTIMER_POLICY_WRAP_AFTER_ONE_PERIOD);
triggered = false;
@@ -284,7 +286,7 @@ static void check_on_the_fly_mode_change(gconstpointer arg)
qemu_clock_step(2000000);
- g_assert_cmpuint(ptimer_get_count(ptimer), ==, 10);
+ g_assert_cmpuint(ptimer_get_count(ptimer), ==, wrap_policy ? 0 : 10);
g_assert_true(triggered);
triggered = false;
@@ -293,10 +295,10 @@ static void check_on_the_fly_mode_change(gconstpointer
arg)
ptimer_run(ptimer, 1);
- g_assert_cmpuint(ptimer_get_count(ptimer), ==, 1);
+ g_assert_cmpuint(ptimer_get_count(ptimer), ==, wrap_policy ? 2 : 1);
g_assert_false(triggered);
- qemu_clock_step(2000000);
+ qemu_clock_step(2000000 * 3);
g_assert_cmpuint(ptimer_get_count(ptimer), ==, 0);
g_assert_true(triggered);
@@ -386,6 +388,7 @@ static void check_run_with_delta_0(gconstpointer arg)
const uint8_t *policy = arg;
QEMUBH *bh = qemu_bh_new(ptimer_trigger, NULL);
ptimer_state *ptimer = ptimer_init(bh, *policy);
+ bool wrap_policy = (*policy & PTIMER_POLICY_WRAP_AFTER_ONE_PERIOD);
triggered = false;
@@ -428,7 +431,7 @@ static void check_run_with_delta_0(gconstpointer arg)
qemu_clock_step(2000000 * 98);
- g_assert_cmpuint(ptimer_get_count(ptimer), ==, 99);
+ g_assert_cmpuint(ptimer_get_count(ptimer), ==, wrap_policy ? 0 : 99);
g_assert_true(triggered);
ptimer_stop(ptimer);
@@ -437,7 +440,7 @@ static void check_run_with_delta_0(gconstpointer arg)
static void add_ptimer_tests(uint8_t policy)
{
uint8_t *ppolicy = g_malloc(1);
- char *policy_name = g_malloc(64);
+ char *policy_name = g_malloc0(256);
*ppolicy = policy;
@@ -445,6 +448,10 @@ static void add_ptimer_tests(uint8_t policy)
g_sprintf(policy_name, "default");
}
+ if (policy & PTIMER_POLICY_WRAP_AFTER_ONE_PERIOD) {
+ g_strlcat(policy_name, "wrap_after_one_period,", 256);
+ }
+
qtest_add_data_func(
g_strdup_printf("/ptimer/set_count policy=%s", policy_name),
ppolicy, check_set_count);
@@ -482,6 +489,16 @@ static void add_ptimer_tests(uint8_t policy)
ppolicy, check_run_with_delta_0);
}
+static void add_all_ptimer_policies_comb_tests(void)
+{
+ int last_policy = PTIMER_POLICY_WRAP_AFTER_ONE_PERIOD;
+ int policy = PTIMER_POLICY_DEFAULT;
+
+ for (; policy < (last_policy << 1); policy++) {
+ add_ptimer_tests(policy);
+ }
+}
+
int main(int argc, char **argv)
{
int i;
@@ -492,7 +509,7 @@ int main(int argc, char **argv)
main_loop_tlg.tl[i] = g_new0(QEMUTimerList, 1);
}
- add_ptimer_tests(PTIMER_POLICY_DEFAULT);
+ add_all_ptimer_policies_comb_tests();
return g_test_run();
}
--
2.9.2
- [Qemu-devel] [PATCH v15 01/15] hw/ptimer: Change ptimer_get_count to return "1" for the expired timer, (continued)
- [Qemu-devel] [PATCH v15 01/15] hw/ptimer: Change ptimer_get_count to return "1" for the expired timer, Dmitry Osipenko, 2016/07/21
- [Qemu-devel] [PATCH v15 03/15] hw/ptimer: Actually stop timer in case of error, Dmitry Osipenko, 2016/07/21
- [Qemu-devel] [PATCH v15 02/15] hw/ptimer: Fix counter - 1 returned by ptimer_get_count for the active timer, Dmitry Osipenko, 2016/07/21
- [Qemu-devel] [PATCH v15 08/15] hw/ptimer: Add "continuous trigger" policy, Dmitry Osipenko, 2016/07/21
- [Qemu-devel] [PATCH v15 05/15] tests: Add ptimer tests, Dmitry Osipenko, 2016/07/21
- [Qemu-devel] [PATCH v15 09/15] tests: ptimer: Add tests for "continuous trigger" policy, Dmitry Osipenko, 2016/07/21
- [Qemu-devel] [PATCH v15 06/15] hw/ptimer: Add "wraparound after one period" policy, Dmitry Osipenko, 2016/07/21
- [Qemu-devel] [PATCH v15 04/15] hw/ptimer: Introduce timer policy feature, Dmitry Osipenko, 2016/07/21
- [Qemu-devel] [PATCH v15 12/15] hw/ptimer: Add "no immediate reload" policy, Dmitry Osipenko, 2016/07/21
- [Qemu-devel] [PATCH v15 13/15] tests: ptimer: Add tests for "no immediate reload" policy, Dmitry Osipenko, 2016/07/21
- [Qemu-devel] [PATCH v15 07/15] tests: ptimer: Add tests for "wraparound after one period" policy,
Dmitry Osipenko <=
- [Qemu-devel] [PATCH v15 10/15] hw/ptimer: Add "no immediate trigger" policy, Dmitry Osipenko, 2016/07/21
- [Qemu-devel] [PATCH v15 11/15] tests: ptimer: Add tests for "no immediate trigger" policy, Dmitry Osipenko, 2016/07/21
- [Qemu-devel] [PATCH v15 14/15] arm_mptimer: Convert to use ptimer, Dmitry Osipenko, 2016/07/21
- [Qemu-devel] [PATCH v15 15/15] tests: Add tests for the ARM MPTimer, Dmitry Osipenko, 2016/07/21