@@ -190,6 +190,7 @@ static void check_periodic(gconstpointer arg)
ptimer_state *ptimer = ptimer_init(bh, *policy);
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);
triggered = false;
@@ -219,7 +220,7 @@ static void check_periodic(gconstpointer arg)
qemu_clock_step(2000000);
- g_assert_cmpuint(ptimer_get_count(ptimer), ==, wrap_policy ? 9 : 8);
+ g_assert_cmpuint(ptimer_get_count(ptimer), ==, 8 + (wrap_policy ? 1 : 0));
g_assert_false(triggered);
ptimer_set_count(ptimer, 20);
@@ -239,7 +240,7 @@ static void check_periodic(gconstpointer arg)
qemu_clock_step(2000000 * 10);
- g_assert_cmpuint(ptimer_get_count(ptimer), ==, wrap_policy ? 9 : 8);
+ g_assert_cmpuint(ptimer_get_count(ptimer), ==, 8 + (wrap_policy ? 1 : 0));
g_assert_true(triggered);
triggered = false;
@@ -256,7 +257,7 @@ static void check_periodic(gconstpointer arg)
qemu_clock_step(2000000 * 4);
- g_assert_cmpuint(ptimer_get_count(ptimer), ==, wrap_policy ? 9 : 8);
+ g_assert_cmpuint(ptimer_get_count(ptimer), ==, 8 + (wrap_policy ? 1 : 0));
g_assert_true(triggered);
ptimer_stop(ptimer);
@@ -264,7 +265,7 @@ static void check_periodic(gconstpointer arg)
qemu_clock_step(2000000);
- g_assert_cmpuint(ptimer_get_count(ptimer), ==, wrap_policy ? 9 : 8);
+ g_assert_cmpuint(ptimer_get_count(ptimer), ==, 8 + (wrap_policy ? 1 : 0));
g_assert_false(triggered);
ptimer_set_count(ptimer, 3);
@@ -279,11 +280,12 @@ static void check_periodic(gconstpointer arg)
qemu_clock_step(2000000);
- g_assert_cmpuint(ptimer_get_count(ptimer), ==, wrap_policy ? 9 : 8);
+ g_assert_cmpuint(ptimer_get_count(ptimer), ==, 8 + (wrap_policy ? 1 : 0));
g_assert_false(triggered);
ptimer_set_count(ptimer, 0);
- g_assert_cmpuint(ptimer_get_count(ptimer), ==, 10);
+ g_assert_cmpuint(ptimer_get_count(ptimer), ==,
+ no_immediate_reload ? 0 : 10);
if (no_immediate_trigger) {
g_assert_false(triggered);
@@ -295,12 +297,27 @@ static void check_periodic(gconstpointer arg)
qemu_clock_step(100000);
+ if (no_immediate_reload) {
+ g_assert_cmpuint(ptimer_get_count(ptimer), ==, 0);
+ g_assert_false(triggered);
+
+ qemu_clock_step(2000000);
+
+ if (no_immediate_trigger) {
+ g_assert_true(triggered);
+ } else {
+ g_assert_false(triggered);
+ }
+
+ triggered = false;
+ }
+
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_cmpuint(ptimer_get_count(ptimer), ==, 7 + (wrap_policy ? 1 : 0));
g_assert_true(triggered);
ptimer_stop(ptimer);
@@ -309,7 +326,7 @@ static void check_periodic(gconstpointer arg)
qemu_clock_step(2000000 * 10);
- g_assert_cmpuint(ptimer_get_count(ptimer), ==, wrap_policy ? 8 : 7);
+ g_assert_cmpuint(ptimer_get_count(ptimer), ==, 7 + (wrap_policy ? 1 : 0));
g_assert_false(triggered);
ptimer_run(ptimer, 0);
@@ -317,7 +334,7 @@ static void check_periodic(gconstpointer arg)
qemu_clock_step(2000000 + 100000);
- g_assert_cmpuint(ptimer_get_count(ptimer), ==, wrap_policy ? 8 : 7);
+ g_assert_cmpuint(ptimer_get_count(ptimer), ==, 7 + (wrap_policy ? 1 : 0));
g_assert_false(triggered);
}
@@ -450,13 +467,15 @@ static void check_run_with_delta_0(gconstpointer arg)
ptimer_state *ptimer = ptimer_init(bh, *policy);
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);
triggered = false;
ptimer_set_period(ptimer, 2000000);
ptimer_set_limit(ptimer, 99, 0);
ptimer_run(ptimer, 1);
- g_assert_cmpuint(ptimer_get_count(ptimer), ==, 99);
+ g_assert_cmpuint(ptimer_get_count(ptimer), ==,
+ no_immediate_reload ? 0 : 99);
if (no_immediate_trigger) {
g_assert_false(triggered);
@@ -466,11 +485,19 @@ static void check_run_with_delta_0(gconstpointer arg)
triggered = false;
- if (no_immediate_trigger) {
+ if (no_immediate_trigger || no_immediate_reload) {
qemu_clock_step(2000000 + 100000);
- g_assert_cmpuint(ptimer_get_count(ptimer), ==, 97);
- g_assert_false(triggered);
+ g_assert_cmpuint(ptimer_get_count(ptimer), ==,
+ no_immediate_reload ? 0 : 97);
+
+ if (no_immediate_trigger && no_immediate_reload) {
+ g_assert_true(triggered);
+
+ triggered = false;
+ } else {
+ g_assert_false(triggered);
+ }
ptimer_set_count(ptimer, 99);
ptimer_run(ptimer, 1);
@@ -495,7 +522,8 @@ static void check_run_with_delta_0(gconstpointer arg)
ptimer_set_count(ptimer, 0);
ptimer_run(ptimer, 0);
- g_assert_cmpuint(ptimer_get_count(ptimer), ==, 99);
+ g_assert_cmpuint(ptimer_get_count(ptimer), ==,
+ no_immediate_reload ? 0 : 99);
if (no_immediate_trigger) {
g_assert_false(triggered);
@@ -507,8 +535,17 @@ static void check_run_with_delta_0(gconstpointer arg)
qemu_clock_step(100000);
+ if (no_immediate_reload) {
+ qemu_clock_step(2000000);
+ }
+
g_assert_cmpuint(ptimer_get_count(ptimer), ==, 98);
- g_assert_false(triggered);
+
+ if (no_immediate_reload && no_immediate_trigger) {
+ g_assert_true(triggered);
+ } else {
+ g_assert_false(triggered);
+ }
triggered = false;
@@ -639,6 +676,10 @@ static void add_ptimer_tests(uint8_t policy)
g_strlcat(policy_name, "no_immediate_trigger,", 256);
}
+ if (policy & PTIMER_POLICY_NO_IMMEDIATE_RELOAD) {
+ g_strlcat(policy_name, "no_immediate_reload,", 256);
+ }
+
g_test_add_data_func(
g_strdup_printf("/ptimer/set_count policy=%s", policy_name),
ppolicy, check_set_count);
@@ -686,7 +727,7 @@ static void add_ptimer_tests(uint8_t policy)
static void add_all_ptimer_policies_comb_tests(void)
{
- int last_policy = PTIMER_POLICY_NO_IMMEDIATE_TRIGGER;
+ int last_policy = PTIMER_POLICY_NO_IMMEDIATE_RELOAD;
int policy = PTIMER_POLICY_DEFAULT;
for (; policy < (last_policy << 1); policy++) {
PTIMER_POLICY_NO_IMMEDIATE_RELOAD makes ptimer to not to re-load counter on setting counter value to "0" or starting to run with "0". Signed-off-by: Dmitry Osipenko <digetx@gmail.com> --- tests/ptimer-test.c | 73 +++++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 57 insertions(+), 16 deletions(-)