@@ -189,6 +189,7 @@ static void check_periodic(gconstpointer 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);
+ bool no_immediate_trigger = (*policy & PTIMER_POLICY_NO_IMMEDIATE_TRIGGER);
triggered = false;
@@ -245,7 +246,12 @@ static void check_periodic(gconstpointer arg)
ptimer_set_count(ptimer, 0);
g_assert_cmpuint(ptimer_get_count(ptimer), ==, 10);
- g_assert_true(triggered);
+
+ if (no_immediate_trigger) {
+ g_assert_false(triggered);
+ } else {
+ g_assert_true(triggered);
+ }
triggered = false;
@@ -397,6 +403,7 @@ static void check_run_with_delta_0(gconstpointer 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);
+ bool no_immediate_trigger = (*policy & PTIMER_POLICY_NO_IMMEDIATE_TRIGGER);
triggered = false;
@@ -404,7 +411,12 @@ static void check_run_with_delta_0(gconstpointer arg)
ptimer_set_limit(ptimer, 99, 0);
ptimer_run(ptimer, 1);
g_assert_cmpuint(ptimer_get_count(ptimer), ==, 99);
- g_assert_true(triggered);
+
+ if (no_immediate_trigger) {
+ g_assert_false(triggered);
+ } else {
+ g_assert_true(triggered);
+ }
triggered = false;
@@ -428,7 +440,12 @@ 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_true(triggered);
+
+ if (no_immediate_trigger) {
+ g_assert_false(triggered);
+ } else {
+ g_assert_true(triggered);
+ }
triggered = false;
@@ -451,6 +468,7 @@ static void check_periodic_with_load_0(gconstpointer arg)
QEMUBH *bh = qemu_bh_new(ptimer_trigger, NULL);
ptimer_state *ptimer = ptimer_init(bh, *policy);
bool continuous_trigger = (*policy & PTIMER_POLICY_CONTINUOUS_TRIGGER);
+ bool no_immediate_trigger = (*policy & PTIMER_POLICY_NO_IMMEDIATE_TRIGGER);
triggered = false;
@@ -458,7 +476,12 @@ static void check_periodic_with_load_0(gconstpointer arg)
ptimer_run(ptimer, 0);
g_assert_cmpuint(ptimer_get_count(ptimer), ==, 0);
- g_assert_true(triggered);
+
+ if (no_immediate_trigger) {
+ g_assert_false(triggered);
+ } else {
+ g_assert_true(triggered);
+ }
triggered = false;
@@ -466,7 +489,7 @@ static void check_periodic_with_load_0(gconstpointer arg)
g_assert_cmpuint(ptimer_get_count(ptimer), ==, 0);
- if (continuous_trigger) {
+ if (continuous_trigger || no_immediate_trigger) {
g_assert_true(triggered);
} else {
g_assert_false(triggered);
@@ -480,6 +503,7 @@ 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);
+ bool no_immediate_trigger = (*policy & PTIMER_POLICY_NO_IMMEDIATE_TRIGGER);
triggered = false;
@@ -487,13 +511,29 @@ static void check_oneshot_with_load_0(gconstpointer arg)
ptimer_run(ptimer, 1);
g_assert_cmpuint(ptimer_get_count(ptimer), ==, 0);
- g_assert_true(triggered);
+
+ if (no_immediate_trigger) {
+ g_assert_false(triggered);
+ } else {
+ g_assert_true(triggered);
+ }
triggered = false;
qemu_clock_step(2000000 + 100000);
g_assert_cmpuint(ptimer_get_count(ptimer), ==, 0);
+
+ if (no_immediate_trigger) {
+ g_assert_true(triggered);
+ } else {
+ g_assert_false(triggered);
+ }
+
+ triggered = false;
+
+ qemu_clock_step(2000000 + 100000);
+
g_assert_false(triggered);
triggered = false;
@@ -522,6 +562,10 @@ static void add_ptimer_tests(uint8_t policy)
g_strlcat(policy_name, "continuous_trigger,", 256);
}
+ if (policy & PTIMER_POLICY_NO_IMMEDIATE_TRIGGER) {
+ g_strlcat(policy_name, "no_immediate_trigger,", 256);
+ }
+
qtest_add_data_func(
g_strdup_printf("/ptimer/set_count policy=%s", policy_name),
ppolicy, check_set_count);
@@ -569,7 +613,7 @@ static void add_ptimer_tests(uint8_t policy)
static void add_all_ptimer_policies_comb_tests(void)
{
- int last_policy = PTIMER_POLICY_CONTINUOUS_TRIGGER;
+ int last_policy = PTIMER_POLICY_NO_IMMEDIATE_TRIGGER;
int policy = PTIMER_POLICY_DEFAULT;
for (; policy < (last_policy << 1); policy++) {
PTIMER_POLICY_NO_IMMEDIATE_TRIGGER makes ptimer to not to trigger on starting to run with / setting counter to "0". Signed-off-by: Dmitry Osipenko <digetx@gmail.com> --- tests/ptimer-test.c | 58 ++++++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 51 insertions(+), 7 deletions(-)