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;
ptimer_set_limit(ptimer, 10, 1);
ptimer_run(ptimer, 0);
- qemu_clock_step(2000000 * 10 + 100000);
+ g_assert_cmpuint(ptimer_get_count(ptimer), ==, 10);
+ g_assert_false(triggered);
+
+ qemu_clock_step(100000);
g_assert_cmpuint(ptimer_get_count(ptimer), ==, 9);
+ g_assert_false(triggered);
+
+ qemu_clock_step(2000000 * 10 - 100000);
+
+ g_assert_cmpuint(ptimer_get_count(ptimer), ==, wrap_policy ? 0 : 10);
+ g_assert_true(triggered);
+
+ qemu_clock_step(100000);
+
+ g_assert_cmpuint(ptimer_get_count(ptimer), ==, wrap_policy ? 0 : 9);
g_assert_true(triggered);
triggered = false;
qemu_clock_step(2000000);
- g_assert_cmpuint(ptimer_get_count(ptimer), ==, 8);
+ g_assert_cmpuint(ptimer_get_count(ptimer), ==, wrap_policy ? 9 : 8);
g_assert_false(triggered);
ptimer_set_count(ptimer, 20);
+ g_assert_cmpuint(ptimer_get_count(ptimer), ==, 20);
+ g_assert_false(triggered);
+
+ qemu_clock_step(100000);
+
+ g_assert_cmpuint(ptimer_get_count(ptimer), ==, 19);
+ g_assert_false(triggered);
+
qemu_clock_step(2000000 * 11 + 100000);
g_assert_cmpuint(ptimer_get_count(ptimer), ==, 8);
qemu_clock_step(2000000 * 10);
- g_assert_cmpuint(ptimer_get_count(ptimer), ==, 8);
+ g_assert_cmpuint(ptimer_get_count(ptimer), ==, wrap_policy ? 9 : 8);
+ g_assert_true(triggered);
+
+ triggered = false;
+
+ ptimer_set_count(ptimer, 3);
+
+ g_assert_cmpuint(ptimer_get_count(ptimer), ==, 3);
+ g_assert_false(triggered);
+
+ qemu_clock_step(100000);
+
+ g_assert_cmpuint(ptimer_get_count(ptimer), ==, 2);
+ g_assert_false(triggered);
+
+ qemu_clock_step(2000000 * 4);
+
+ g_assert_cmpuint(ptimer_get_count(ptimer), ==, wrap_policy ? 9 : 8);
g_assert_true(triggered);
ptimer_stop(ptimer);
qemu_clock_step(2000000);
- g_assert_cmpuint(ptimer_get_count(ptimer), ==, 8);
+ g_assert_cmpuint(ptimer_get_count(ptimer), ==, wrap_policy ? 9 : 8);
g_assert_false(triggered);
ptimer_set_count(ptimer, 3);
qemu_clock_step(2000000 * 3 + 100000);
- g_assert_cmpuint(ptimer_get_count(ptimer), ==, 9);
+ g_assert_cmpuint(ptimer_get_count(ptimer), ==, wrap_policy ? 0 : 9);
g_assert_true(triggered);
triggered = false;
qemu_clock_step(2000000);
- g_assert_cmpuint(ptimer_get_count(ptimer), ==, 8);
+ g_assert_cmpuint(ptimer_get_count(ptimer), ==, wrap_policy ? 9 : 8);
g_assert_false(triggered);
ptimer_set_count(ptimer, 0);
triggered = false;
- qemu_clock_step(2000000 * 12 + 100000);
+ qemu_clock_step(100000);
- g_assert_cmpuint(ptimer_get_count(ptimer), ==, 7);
+ g_assert_cmpuint(ptimer_get_count(ptimer), ==, 9);
+ g_assert_false(triggered);
+
+ qemu_clock_step(2000000 * 12);
+
+ g_assert_cmpuint(ptimer_get_count(ptimer), ==, wrap_policy ? 8 : 7);
g_assert_true(triggered);
ptimer_stop(ptimer);
triggered = false;
- qemu_clock_step(2000000 * 12 + 100000);
+ qemu_clock_step(2000000 * 10);
- g_assert_cmpuint(ptimer_get_count(ptimer), ==, 7);
+ g_assert_cmpuint(ptimer_get_count(ptimer), ==, wrap_policy ? 8 : 7);
g_assert_false(triggered);
ptimer_run(ptimer, 0);
qemu_clock_step(2000000 + 100000);
- g_assert_cmpuint(ptimer_get_count(ptimer), ==, 7);
+ g_assert_cmpuint(ptimer_get_count(ptimer), ==, wrap_policy ? 8 : 7);
g_assert_false(triggered);
}
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;
qemu_clock_step(2000000 * 9 + 100000);
+ g_assert_cmpuint(ptimer_get_count(ptimer), ==, 0);
+ g_assert_false(triggered);
+
ptimer_run(ptimer, 0);
g_assert_cmpuint(ptimer_get_count(ptimer), ==, 0);
qemu_clock_step(2000000);
- g_assert_cmpuint(ptimer_get_count(ptimer), ==, 9);
+ g_assert_cmpuint(ptimer_get_count(ptimer), ==, wrap_policy ? 0 : 9);
g_assert_true(triggered);
triggered = false;
ptimer_run(ptimer, 1);
- g_assert_cmpuint(ptimer_get_count(ptimer), ==, 0);
+ g_assert_cmpuint(ptimer_get_count(ptimer), ==, wrap_policy ? 1 : 0);
g_assert_false(triggered);
qemu_clock_step(2000000 * 3);
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;
triggered = false;
- qemu_clock_step(2000000 + 100000);
+ qemu_clock_step(100000);
+
+ g_assert_cmpuint(ptimer_get_count(ptimer), ==, 98);
+ g_assert_false(triggered);
+
+ triggered = false;
+
+ qemu_clock_step(2000000);
g_assert_cmpuint(ptimer_get_count(ptimer), ==, 97);
g_assert_false(triggered);
qemu_clock_step(2000000 * 98);
- g_assert_cmpuint(ptimer_get_count(ptimer), ==, 98);
+ g_assert_cmpuint(ptimer_get_count(ptimer), ==, wrap_policy ? 0 : 98);
g_assert_true(triggered);
ptimer_stop(ptimer);
g_assert_cmpuint(ptimer_get_count(ptimer), ==, 0);
g_assert_false(triggered);
+ triggered = false;
+
+ ptimer_set_count(ptimer, 10);
+ ptimer_run(ptimer, 0);
+
+ qemu_clock_step(2000000 * 10 + 100000);
+
+ 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);
+
ptimer_stop(ptimer);
}
g_assert_cmpuint(ptimer_get_count(ptimer), ==, 0);
g_assert_false(triggered);
-
- triggered = false;
-
- qemu_clock_step(2000000 + 100000);
-
- g_assert_false(triggered);
}
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;
g_sprintf(policy_name, "default");
}
+ if (policy & PTIMER_POLICY_WRAP_AFTER_ONE_PERIOD) {
+ g_strlcat(policy_name, "wrap_after_one_period,", 256);
+ }
+
g_test_add_data_func(
g_strdup_printf("/ptimer/set_count policy=%s", policy_name),
ppolicy, check_set_count);
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 policy = PTIMER_POLICY_DEFAULT;
+
+ for (; policy < (last_policy << 1); policy++) {
+ add_ptimer_tests(policy);
+ }
+}
+
int main(int argc, char **argv)
{
int i;
main_loop_tlg.tl[i] = g_new0(QEMUTimerList, 1);
}
- add_ptimer_tests(PTIMER_POLICY_DEFAULT);
+ add_all_ptimer_policies_comb_tests();
qtest_allowed = true;