const uint8_t *policy = arg;
QEMUBH *bh = qemu_bh_new(ptimer_trigger, NULL);
ptimer_state *ptimer = ptimer_init(bh, *policy);
+ bool no_round_down = (*policy & PTIMER_POLICY_NO_COUNTER_ROUND_DOWN);
triggered = false;
qemu_clock_step(2000000 * 2 + 100000);
- g_assert_cmpuint(ptimer_get_count(ptimer), ==, 7);
+ g_assert_cmpuint(ptimer_get_count(ptimer), ==, no_round_down ? 8 : 7);
g_assert_false(triggered);
ptimer_stop(ptimer);
- g_assert_cmpuint(ptimer_get_count(ptimer), ==, 7);
+ g_assert_cmpuint(ptimer_get_count(ptimer), ==, no_round_down ? 8 : 7);
g_assert_false(triggered);
qemu_clock_step(2000000 * 11);
- g_assert_cmpuint(ptimer_get_count(ptimer), ==, 7);
+ g_assert_cmpuint(ptimer_get_count(ptimer), ==, no_round_down ? 8 : 7);
g_assert_false(triggered);
ptimer_run(ptimer, 1);
qemu_clock_step(2000000 * 7 + 100000);
- g_assert_cmpuint(ptimer_get_count(ptimer), ==, 0);
- g_assert_true(triggered);
+ g_assert_cmpuint(ptimer_get_count(ptimer), ==, no_round_down ? 1 : 0);
- triggered = false;
+ if (no_round_down) {
+ g_assert_false(triggered);
+ } else {
+ g_assert_true(triggered);
+
+ triggered = false;
+ }
qemu_clock_step(2000000);
g_assert_cmpuint(ptimer_get_count(ptimer), ==, 0);
- g_assert_false(triggered);
+
+ if (no_round_down) {
+ g_assert_true(triggered);
+
+ triggered = false;
+ } else {
+ g_assert_false(triggered);
+ }
qemu_clock_step(4000000);
qemu_clock_step(2000000 + 100000);
- g_assert_cmpuint(ptimer_get_count(ptimer), ==, 7);
+ g_assert_cmpuint(ptimer_get_count(ptimer), ==, no_round_down ? 8 : 7);
g_assert_false(triggered);
ptimer_set_count(ptimer, 20);
qemu_clock_step(2000000 * 19 + 100000);
- g_assert_cmpuint(ptimer_get_count(ptimer), ==, 0);
+ g_assert_cmpuint(ptimer_get_count(ptimer), ==, no_round_down ? 1 : 0);
g_assert_false(triggered);
qemu_clock_step(2000000);
bool wrap_policy = (*policy & PTIMER_POLICY_WRAP_AFTER_ONE_PERIOD);
bool no_immediate_trigger = (*policy & PTIMER_POLICY_NO_IMMEDIATE_TRIGGER);
bool no_immediate_reload = (*policy & PTIMER_POLICY_NO_IMMEDIATE_RELOAD);
+ bool no_round_down = (*policy & PTIMER_POLICY_NO_COUNTER_ROUND_DOWN);
triggered = false;
qemu_clock_step(100000);
- g_assert_cmpuint(ptimer_get_count(ptimer), ==, 9);
+ g_assert_cmpuint(ptimer_get_count(ptimer), ==, no_round_down ? 10 : 9);
g_assert_false(triggered);
qemu_clock_step(2000000 * 10 - 100000);
qemu_clock_step(100000);
- g_assert_cmpuint(ptimer_get_count(ptimer), ==, wrap_policy ? 0 : 9);
+ g_assert_cmpuint(ptimer_get_count(ptimer), ==,
+ wrap_policy ? 0 : (no_round_down ? 10 : 9));
g_assert_true(triggered);
triggered = false;
qemu_clock_step(2000000);
- g_assert_cmpuint(ptimer_get_count(ptimer), ==, 8 + (wrap_policy ? 1 : 0));
+ g_assert_cmpuint(ptimer_get_count(ptimer), ==,
+ (no_round_down ? 9 : 8) + (wrap_policy ? 1 : 0));
g_assert_false(triggered);
ptimer_set_count(ptimer, 20);
qemu_clock_step(100000);
- g_assert_cmpuint(ptimer_get_count(ptimer), ==, 19);
+ g_assert_cmpuint(ptimer_get_count(ptimer), ==, no_round_down ? 20 : 19);
g_assert_false(triggered);
qemu_clock_step(2000000 * 11 + 100000);
- g_assert_cmpuint(ptimer_get_count(ptimer), ==, 8);
+ g_assert_cmpuint(ptimer_get_count(ptimer), ==, no_round_down ? 9 : 8);
g_assert_false(triggered);
qemu_clock_step(2000000 * 10);
- g_assert_cmpuint(ptimer_get_count(ptimer), ==, 8 + (wrap_policy ? 1 : 0));
+ g_assert_cmpuint(ptimer_get_count(ptimer), ==,
+ (no_round_down ? 9 : 8) + (wrap_policy ? 1 : 0));
g_assert_true(triggered);
triggered = false;
qemu_clock_step(100000);
- g_assert_cmpuint(ptimer_get_count(ptimer), ==, 2);
+ g_assert_cmpuint(ptimer_get_count(ptimer), ==, no_round_down ? 3 : 2);
g_assert_false(triggered);
qemu_clock_step(2000000 * 4);
- g_assert_cmpuint(ptimer_get_count(ptimer), ==, 8 + (wrap_policy ? 1 : 0));
+ g_assert_cmpuint(ptimer_get_count(ptimer), ==,
+ (no_round_down ? 9 : 8) + (wrap_policy ? 1 : 0));
g_assert_true(triggered);
ptimer_stop(ptimer);
qemu_clock_step(2000000);
- g_assert_cmpuint(ptimer_get_count(ptimer), ==, 8 + (wrap_policy ? 1 : 0));
+ g_assert_cmpuint(ptimer_get_count(ptimer), ==,
+ (no_round_down ? 9 : 8) + (wrap_policy ? 1 : 0));
g_assert_false(triggered);
ptimer_set_count(ptimer, 3);
qemu_clock_step(2000000 * 3 + 100000);
- g_assert_cmpuint(ptimer_get_count(ptimer), ==, wrap_policy ? 0 : 9);
+ g_assert_cmpuint(ptimer_get_count(ptimer), ==,
+ wrap_policy ? 0 : (no_round_down ? 10 : 9));
g_assert_true(triggered);
triggered = false;
qemu_clock_step(2000000);
- g_assert_cmpuint(ptimer_get_count(ptimer), ==, 8 + (wrap_policy ? 1 : 0));
+ g_assert_cmpuint(ptimer_get_count(ptimer), ==,
+ (no_round_down ? 9 : 8) + (wrap_policy ? 1 : 0));
g_assert_false(triggered);
ptimer_set_count(ptimer, 0);
triggered = false;
}
- g_assert_cmpuint(ptimer_get_count(ptimer), ==, 9);
+ g_assert_cmpuint(ptimer_get_count(ptimer), ==, no_round_down ? 10 : 9);
g_assert_false(triggered);
qemu_clock_step(2000000 * 12);
- g_assert_cmpuint(ptimer_get_count(ptimer), ==, 7 + (wrap_policy ? 1 : 0));
+ g_assert_cmpuint(ptimer_get_count(ptimer), ==,
+ (no_round_down ? 8 : 7) + (wrap_policy ? 1 : 0));
g_assert_true(triggered);
ptimer_stop(ptimer);
qemu_clock_step(2000000 * 10);
- g_assert_cmpuint(ptimer_get_count(ptimer), ==, 7 + (wrap_policy ? 1 : 0));
+ g_assert_cmpuint(ptimer_get_count(ptimer), ==,
+ (no_round_down ? 8 : 7) + (wrap_policy ? 1 : 0));
g_assert_false(triggered);
ptimer_run(ptimer, 0);
qemu_clock_step(2000000 + 100000);
- g_assert_cmpuint(ptimer_get_count(ptimer), ==, 7 + (wrap_policy ? 1 : 0));
+ g_assert_cmpuint(ptimer_get_count(ptimer), ==,
+ (no_round_down ? 8 : 7) + (wrap_policy ? 1 : 0));
g_assert_false(triggered);
}
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);
+ bool no_round_down = (*policy & PTIMER_POLICY_NO_COUNTER_ROUND_DOWN);
triggered = false;
qemu_clock_step(2000000 * 9 + 100000);
- g_assert_cmpuint(ptimer_get_count(ptimer), ==, 0);
+ g_assert_cmpuint(ptimer_get_count(ptimer), ==, no_round_down ? 1 : 0);
g_assert_false(triggered);
ptimer_run(ptimer, 0);
- g_assert_cmpuint(ptimer_get_count(ptimer), ==, 0);
+ g_assert_cmpuint(ptimer_get_count(ptimer), ==, no_round_down ? 1 : 0);
g_assert_false(triggered);
qemu_clock_step(2000000);
- g_assert_cmpuint(ptimer_get_count(ptimer), ==, wrap_policy ? 0 : 9);
+ g_assert_cmpuint(ptimer_get_count(ptimer), ==,
+ wrap_policy ? 0 : (no_round_down ? 10 : 9));
g_assert_true(triggered);
triggered = false;
ptimer_run(ptimer, 1);
- g_assert_cmpuint(ptimer_get_count(ptimer), ==, wrap_policy ? 1 : 0);
+ g_assert_cmpuint(ptimer_get_count(ptimer), ==,
+ (no_round_down ? 1 : 0) + (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 no_round_down = (*policy & PTIMER_POLICY_NO_COUNTER_ROUND_DOWN);
triggered = false;
qemu_clock_step(2000000 * 4 + 100000);
- g_assert_cmpuint(ptimer_get_count(ptimer), ==, 3);
+ g_assert_cmpuint(ptimer_get_count(ptimer), ==, no_round_down ? 4 : 3);
g_assert_false(triggered);
ptimer_set_period(ptimer, 4000000);
- g_assert_cmpuint(ptimer_get_count(ptimer), ==, 3);
+ g_assert_cmpuint(ptimer_get_count(ptimer), ==, no_round_down ? 4 : 3);
qemu_clock_step(4000000 * 2 + 100000);
- g_assert_cmpuint(ptimer_get_count(ptimer), ==, 0);
+ g_assert_cmpuint(ptimer_get_count(ptimer), ==, no_round_down ? 2 : 0);
g_assert_false(triggered);
qemu_clock_step(4000000 * 2);
const uint8_t *policy = arg;
QEMUBH *bh = qemu_bh_new(ptimer_trigger, NULL);
ptimer_state *ptimer = ptimer_init(bh, *policy);
+ bool no_round_down = (*policy & PTIMER_POLICY_NO_COUNTER_ROUND_DOWN);
triggered = false;
qemu_clock_step(2000000 * 4 + 100000);
- g_assert_cmpuint(ptimer_get_count(ptimer), ==, 3);
+ g_assert_cmpuint(ptimer_get_count(ptimer), ==, no_round_down ? 4 : 3);
g_assert_false(triggered);
ptimer_set_freq(ptimer, 250);
- g_assert_cmpuint(ptimer_get_count(ptimer), ==, 3);
+ g_assert_cmpuint(ptimer_get_count(ptimer), ==, no_round_down ? 4 : 3);
qemu_clock_step(2000000 * 4 + 100000);
- g_assert_cmpuint(ptimer_get_count(ptimer), ==, 0);
+ g_assert_cmpuint(ptimer_get_count(ptimer), ==, no_round_down ? 2 : 0);
g_assert_false(triggered);
qemu_clock_step(2000000 * 4);
bool wrap_policy = (*policy & PTIMER_POLICY_WRAP_AFTER_ONE_PERIOD);
bool no_immediate_trigger = (*policy & PTIMER_POLICY_NO_IMMEDIATE_TRIGGER);
bool no_immediate_reload = (*policy & PTIMER_POLICY_NO_IMMEDIATE_RELOAD);
+ bool no_round_down = (*policy & PTIMER_POLICY_NO_COUNTER_ROUND_DOWN);
triggered = false;
qemu_clock_step(2000000 + 100000);
g_assert_cmpuint(ptimer_get_count(ptimer), ==,
- no_immediate_reload ? 0 : 97);
+ no_immediate_reload ? 0 : (no_round_down ? 98 : 97));
if (no_immediate_trigger && no_immediate_reload) {
g_assert_true(triggered);
qemu_clock_step(2000000 + 100000);
- g_assert_cmpuint(ptimer_get_count(ptimer), ==, 97);
+ g_assert_cmpuint(ptimer_get_count(ptimer), ==, no_round_down ? 98 : 97);
g_assert_false(triggered);
qemu_clock_step(2000000 * 97);
- g_assert_cmpuint(ptimer_get_count(ptimer), ==, 0);
+ g_assert_cmpuint(ptimer_get_count(ptimer), ==, no_round_down ? 1 : 0);
g_assert_false(triggered);
qemu_clock_step(2000000 * 2);
qemu_clock_step(2000000);
}
- g_assert_cmpuint(ptimer_get_count(ptimer), ==, 98);
+ g_assert_cmpuint(ptimer_get_count(ptimer), ==, no_round_down ? 99 : 98);
if (no_immediate_reload && no_immediate_trigger) {
g_assert_true(triggered);
qemu_clock_step(2000000);
- g_assert_cmpuint(ptimer_get_count(ptimer), ==, 97);
+ g_assert_cmpuint(ptimer_get_count(ptimer), ==, no_round_down ? 98 : 97);
g_assert_false(triggered);
qemu_clock_step(2000000 * 98);
- g_assert_cmpuint(ptimer_get_count(ptimer), ==, wrap_policy ? 0 : 98);
+ g_assert_cmpuint(ptimer_get_count(ptimer), ==,
+ wrap_policy ? 0 : (no_round_down ? 99 : 98));
g_assert_true(triggered);
ptimer_stop(ptimer);
g_strlcat(policy_name, "no_immediate_reload,", 256);
}
+ if (policy & PTIMER_POLICY_NO_COUNTER_ROUND_DOWN) {
+ g_strlcat(policy_name, "no_counter_rounddown,", 256);
+ }
+
g_test_add_data_func(
g_strdup_printf("/ptimer/set_count policy=%s", policy_name),
ppolicy, check_set_count);
static void add_all_ptimer_policies_comb_tests(void)
{
- int last_policy = PTIMER_POLICY_NO_IMMEDIATE_RELOAD;
+ int last_policy = PTIMER_POLICY_NO_COUNTER_ROUND_DOWN;
int policy = PTIMER_POLICY_DEFAULT;
for (; policy < (last_policy << 1); policy++) {