提交 91b37aea 编写于 作者: P Peter Maydell

tests/ptimer-test: Switch to transaction-based ptimer API

Convert the ptimer test cases to the transaction-based ptimer API,
by changing to ptimer_init(), dropping the now-unused QEMUBH
variables, and surrounding each set of changes to the ptimer
state in ptimer_transaction_begin/commit calls.
Signed-off-by: NPeter Maydell <peter.maydell@linaro.org>
Reviewed-by: NRichard Henderson <richard.henderson@linaro.org>
Message-id: 20191008171740.9679-4-peter.maydell@linaro.org
上级 78b6eaa6
...@@ -67,12 +67,13 @@ static void qemu_clock_step(uint64_t ns) ...@@ -67,12 +67,13 @@ static void qemu_clock_step(uint64_t ns)
static void check_set_count(gconstpointer arg) static void check_set_count(gconstpointer arg)
{ {
const uint8_t *policy = arg; const uint8_t *policy = arg;
QEMUBH *bh = qemu_bh_new(ptimer_trigger, NULL); ptimer_state *ptimer = ptimer_init(ptimer_trigger, NULL, *policy);
ptimer_state *ptimer = ptimer_init_with_bh(bh, *policy);
triggered = false; triggered = false;
ptimer_transaction_begin(ptimer);
ptimer_set_count(ptimer, 1000); ptimer_set_count(ptimer, 1000);
ptimer_transaction_commit(ptimer);
g_assert_cmpuint(ptimer_get_count(ptimer), ==, 1000); g_assert_cmpuint(ptimer_get_count(ptimer), ==, 1000);
g_assert_false(triggered); g_assert_false(triggered);
ptimer_free(ptimer); ptimer_free(ptimer);
...@@ -81,17 +82,20 @@ static void check_set_count(gconstpointer arg) ...@@ -81,17 +82,20 @@ static void check_set_count(gconstpointer arg)
static void check_set_limit(gconstpointer arg) static void check_set_limit(gconstpointer arg)
{ {
const uint8_t *policy = arg; const uint8_t *policy = arg;
QEMUBH *bh = qemu_bh_new(ptimer_trigger, NULL); ptimer_state *ptimer = ptimer_init(ptimer_trigger, NULL, *policy);
ptimer_state *ptimer = ptimer_init_with_bh(bh, *policy);
triggered = false; triggered = false;
ptimer_transaction_begin(ptimer);
ptimer_set_limit(ptimer, 1000, 0); ptimer_set_limit(ptimer, 1000, 0);
ptimer_transaction_commit(ptimer);
g_assert_cmpuint(ptimer_get_count(ptimer), ==, 0); g_assert_cmpuint(ptimer_get_count(ptimer), ==, 0);
g_assert_cmpuint(ptimer_get_limit(ptimer), ==, 1000); g_assert_cmpuint(ptimer_get_limit(ptimer), ==, 1000);
g_assert_false(triggered); g_assert_false(triggered);
ptimer_transaction_begin(ptimer);
ptimer_set_limit(ptimer, 2000, 1); ptimer_set_limit(ptimer, 2000, 1);
ptimer_transaction_commit(ptimer);
g_assert_cmpuint(ptimer_get_count(ptimer), ==, 2000); g_assert_cmpuint(ptimer_get_count(ptimer), ==, 2000);
g_assert_cmpuint(ptimer_get_limit(ptimer), ==, 2000); g_assert_cmpuint(ptimer_get_limit(ptimer), ==, 2000);
g_assert_false(triggered); g_assert_false(triggered);
...@@ -101,22 +105,25 @@ static void check_set_limit(gconstpointer arg) ...@@ -101,22 +105,25 @@ static void check_set_limit(gconstpointer arg)
static void check_oneshot(gconstpointer arg) static void check_oneshot(gconstpointer arg)
{ {
const uint8_t *policy = arg; const uint8_t *policy = arg;
QEMUBH *bh = qemu_bh_new(ptimer_trigger, NULL); ptimer_state *ptimer = ptimer_init(ptimer_trigger, NULL, *policy);
ptimer_state *ptimer = ptimer_init_with_bh(bh, *policy);
bool no_round_down = (*policy & PTIMER_POLICY_NO_COUNTER_ROUND_DOWN); bool no_round_down = (*policy & PTIMER_POLICY_NO_COUNTER_ROUND_DOWN);
triggered = false; triggered = false;
ptimer_transaction_begin(ptimer);
ptimer_set_period(ptimer, 2000000); ptimer_set_period(ptimer, 2000000);
ptimer_set_count(ptimer, 10); ptimer_set_count(ptimer, 10);
ptimer_run(ptimer, 1); ptimer_run(ptimer, 1);
ptimer_transaction_commit(ptimer);
qemu_clock_step(2000000 * 2 + 1); qemu_clock_step(2000000 * 2 + 1);
g_assert_cmpuint(ptimer_get_count(ptimer), ==, no_round_down ? 8 : 7); g_assert_cmpuint(ptimer_get_count(ptimer), ==, no_round_down ? 8 : 7);
g_assert_false(triggered); g_assert_false(triggered);
ptimer_transaction_begin(ptimer);
ptimer_stop(ptimer); ptimer_stop(ptimer);
ptimer_transaction_commit(ptimer);
g_assert_cmpuint(ptimer_get_count(ptimer), ==, no_round_down ? 8 : 7); g_assert_cmpuint(ptimer_get_count(ptimer), ==, no_round_down ? 8 : 7);
g_assert_false(triggered); g_assert_false(triggered);
...@@ -126,7 +133,9 @@ static void check_oneshot(gconstpointer arg) ...@@ -126,7 +133,9 @@ static void check_oneshot(gconstpointer arg)
g_assert_cmpuint(ptimer_get_count(ptimer), ==, no_round_down ? 8 : 7); g_assert_cmpuint(ptimer_get_count(ptimer), ==, no_round_down ? 8 : 7);
g_assert_false(triggered); g_assert_false(triggered);
ptimer_transaction_begin(ptimer);
ptimer_run(ptimer, 1); ptimer_run(ptimer, 1);
ptimer_transaction_commit(ptimer);
qemu_clock_step(2000000 * 7 + 1); qemu_clock_step(2000000 * 7 + 1);
...@@ -157,28 +166,36 @@ static void check_oneshot(gconstpointer arg) ...@@ -157,28 +166,36 @@ static void check_oneshot(gconstpointer arg)
g_assert_cmpuint(ptimer_get_count(ptimer), ==, 0); g_assert_cmpuint(ptimer_get_count(ptimer), ==, 0);
g_assert_false(triggered); g_assert_false(triggered);
ptimer_transaction_begin(ptimer);
ptimer_set_count(ptimer, 10); ptimer_set_count(ptimer, 10);
ptimer_transaction_commit(ptimer);
qemu_clock_step(20000000 + 1); qemu_clock_step(20000000 + 1);
g_assert_cmpuint(ptimer_get_count(ptimer), ==, 10); g_assert_cmpuint(ptimer_get_count(ptimer), ==, 10);
g_assert_false(triggered); g_assert_false(triggered);
ptimer_transaction_begin(ptimer);
ptimer_set_limit(ptimer, 9, 1); ptimer_set_limit(ptimer, 9, 1);
ptimer_transaction_commit(ptimer);
qemu_clock_step(20000000 + 1); qemu_clock_step(20000000 + 1);
g_assert_cmpuint(ptimer_get_count(ptimer), ==, 9); g_assert_cmpuint(ptimer_get_count(ptimer), ==, 9);
g_assert_false(triggered); g_assert_false(triggered);
ptimer_transaction_begin(ptimer);
ptimer_run(ptimer, 1); ptimer_run(ptimer, 1);
ptimer_transaction_commit(ptimer);
qemu_clock_step(2000000 + 1); qemu_clock_step(2000000 + 1);
g_assert_cmpuint(ptimer_get_count(ptimer), ==, no_round_down ? 8 : 7); g_assert_cmpuint(ptimer_get_count(ptimer), ==, no_round_down ? 8 : 7);
g_assert_false(triggered); g_assert_false(triggered);
ptimer_transaction_begin(ptimer);
ptimer_set_count(ptimer, 20); ptimer_set_count(ptimer, 20);
ptimer_transaction_commit(ptimer);
qemu_clock_step(2000000 * 19 + 1); qemu_clock_step(2000000 * 19 + 1);
...@@ -190,7 +207,9 @@ static void check_oneshot(gconstpointer arg) ...@@ -190,7 +207,9 @@ static void check_oneshot(gconstpointer arg)
g_assert_cmpuint(ptimer_get_count(ptimer), ==, 0); g_assert_cmpuint(ptimer_get_count(ptimer), ==, 0);
g_assert_true(triggered); g_assert_true(triggered);
ptimer_transaction_begin(ptimer);
ptimer_stop(ptimer); ptimer_stop(ptimer);
ptimer_transaction_commit(ptimer);
triggered = false; triggered = false;
...@@ -204,8 +223,7 @@ static void check_oneshot(gconstpointer arg) ...@@ -204,8 +223,7 @@ static void check_oneshot(gconstpointer arg)
static void check_periodic(gconstpointer arg) static void check_periodic(gconstpointer arg)
{ {
const uint8_t *policy = arg; const uint8_t *policy = arg;
QEMUBH *bh = qemu_bh_new(ptimer_trigger, NULL); ptimer_state *ptimer = ptimer_init(ptimer_trigger, NULL, *policy);
ptimer_state *ptimer = ptimer_init_with_bh(bh, *policy);
bool wrap_policy = (*policy & PTIMER_POLICY_WRAP_AFTER_ONE_PERIOD); bool wrap_policy = (*policy & PTIMER_POLICY_WRAP_AFTER_ONE_PERIOD);
bool no_immediate_trigger = (*policy & PTIMER_POLICY_NO_IMMEDIATE_TRIGGER); bool no_immediate_trigger = (*policy & PTIMER_POLICY_NO_IMMEDIATE_TRIGGER);
bool no_immediate_reload = (*policy & PTIMER_POLICY_NO_IMMEDIATE_RELOAD); bool no_immediate_reload = (*policy & PTIMER_POLICY_NO_IMMEDIATE_RELOAD);
...@@ -214,9 +232,11 @@ static void check_periodic(gconstpointer arg) ...@@ -214,9 +232,11 @@ static void check_periodic(gconstpointer arg)
triggered = false; triggered = false;
ptimer_transaction_begin(ptimer);
ptimer_set_period(ptimer, 2000000); ptimer_set_period(ptimer, 2000000);
ptimer_set_limit(ptimer, 10, 1); ptimer_set_limit(ptimer, 10, 1);
ptimer_run(ptimer, 0); ptimer_run(ptimer, 0);
ptimer_transaction_commit(ptimer);
g_assert_cmpuint(ptimer_get_count(ptimer), ==, 10); g_assert_cmpuint(ptimer_get_count(ptimer), ==, 10);
g_assert_false(triggered); g_assert_false(triggered);
...@@ -245,7 +265,9 @@ static void check_periodic(gconstpointer arg) ...@@ -245,7 +265,9 @@ static void check_periodic(gconstpointer arg)
(no_round_down ? 9 : 8) + (wrap_policy ? 1 : 0)); (no_round_down ? 9 : 8) + (wrap_policy ? 1 : 0));
g_assert_false(triggered); g_assert_false(triggered);
ptimer_transaction_begin(ptimer);
ptimer_set_count(ptimer, 20); ptimer_set_count(ptimer, 20);
ptimer_transaction_commit(ptimer);
g_assert_cmpuint(ptimer_get_count(ptimer), ==, 20); g_assert_cmpuint(ptimer_get_count(ptimer), ==, 20);
g_assert_false(triggered); g_assert_false(triggered);
...@@ -268,7 +290,9 @@ static void check_periodic(gconstpointer arg) ...@@ -268,7 +290,9 @@ static void check_periodic(gconstpointer arg)
triggered = false; triggered = false;
ptimer_transaction_begin(ptimer);
ptimer_set_count(ptimer, 3); ptimer_set_count(ptimer, 3);
ptimer_transaction_commit(ptimer);
g_assert_cmpuint(ptimer_get_count(ptimer), ==, 3); g_assert_cmpuint(ptimer_get_count(ptimer), ==, 3);
g_assert_false(triggered); g_assert_false(triggered);
...@@ -284,7 +308,9 @@ static void check_periodic(gconstpointer arg) ...@@ -284,7 +308,9 @@ static void check_periodic(gconstpointer arg)
(no_round_down ? 9 : 8) + (wrap_policy ? 1 : 0)); (no_round_down ? 9 : 8) + (wrap_policy ? 1 : 0));
g_assert_true(triggered); g_assert_true(triggered);
ptimer_transaction_begin(ptimer);
ptimer_stop(ptimer); ptimer_stop(ptimer);
ptimer_transaction_commit(ptimer);
triggered = false; triggered = false;
qemu_clock_step(2000000); qemu_clock_step(2000000);
...@@ -293,8 +319,10 @@ static void check_periodic(gconstpointer arg) ...@@ -293,8 +319,10 @@ static void check_periodic(gconstpointer arg)
(no_round_down ? 9 : 8) + (wrap_policy ? 1 : 0)); (no_round_down ? 9 : 8) + (wrap_policy ? 1 : 0));
g_assert_false(triggered); g_assert_false(triggered);
ptimer_transaction_begin(ptimer);
ptimer_set_count(ptimer, 3); ptimer_set_count(ptimer, 3);
ptimer_run(ptimer, 0); ptimer_run(ptimer, 0);
ptimer_transaction_commit(ptimer);
qemu_clock_step(2000000 * 3 + 1); qemu_clock_step(2000000 * 3 + 1);
...@@ -310,7 +338,9 @@ static void check_periodic(gconstpointer arg) ...@@ -310,7 +338,9 @@ static void check_periodic(gconstpointer arg)
(no_round_down ? 9 : 8) + (wrap_policy ? 1 : 0)); (no_round_down ? 9 : 8) + (wrap_policy ? 1 : 0));
g_assert_false(triggered); g_assert_false(triggered);
ptimer_transaction_begin(ptimer);
ptimer_set_count(ptimer, 0); ptimer_set_count(ptimer, 0);
ptimer_transaction_commit(ptimer);
g_assert_cmpuint(ptimer_get_count(ptimer), ==, g_assert_cmpuint(ptimer_get_count(ptimer), ==,
no_immediate_reload ? 0 : 10); no_immediate_reload ? 0 : 10);
...@@ -348,7 +378,9 @@ static void check_periodic(gconstpointer arg) ...@@ -348,7 +378,9 @@ static void check_periodic(gconstpointer arg)
(no_round_down ? 8 : 7) + (wrap_policy ? 1 : 0)); (no_round_down ? 8 : 7) + (wrap_policy ? 1 : 0));
g_assert_true(triggered); g_assert_true(triggered);
ptimer_transaction_begin(ptimer);
ptimer_stop(ptimer); ptimer_stop(ptimer);
ptimer_transaction_commit(ptimer);
triggered = false; triggered = false;
...@@ -358,8 +390,13 @@ static void check_periodic(gconstpointer arg) ...@@ -358,8 +390,13 @@ static void check_periodic(gconstpointer arg)
(no_round_down ? 8 : 7) + (wrap_policy ? 1 : 0)); (no_round_down ? 8 : 7) + (wrap_policy ? 1 : 0));
g_assert_false(triggered); g_assert_false(triggered);
ptimer_transaction_begin(ptimer);
ptimer_run(ptimer, 0); ptimer_run(ptimer, 0);
ptimer_transaction_commit(ptimer);
ptimer_transaction_begin(ptimer);
ptimer_set_period(ptimer, 0); ptimer_set_period(ptimer, 0);
ptimer_transaction_commit(ptimer);
qemu_clock_step(2000000 + 1); qemu_clock_step(2000000 + 1);
...@@ -372,23 +409,26 @@ static void check_periodic(gconstpointer arg) ...@@ -372,23 +409,26 @@ static void check_periodic(gconstpointer arg)
static void check_on_the_fly_mode_change(gconstpointer arg) static void check_on_the_fly_mode_change(gconstpointer arg)
{ {
const uint8_t *policy = arg; const uint8_t *policy = arg;
QEMUBH *bh = qemu_bh_new(ptimer_trigger, NULL); ptimer_state *ptimer = ptimer_init(ptimer_trigger, NULL, *policy);
ptimer_state *ptimer = ptimer_init_with_bh(bh, *policy);
bool wrap_policy = (*policy & PTIMER_POLICY_WRAP_AFTER_ONE_PERIOD); bool wrap_policy = (*policy & PTIMER_POLICY_WRAP_AFTER_ONE_PERIOD);
bool no_round_down = (*policy & PTIMER_POLICY_NO_COUNTER_ROUND_DOWN); bool no_round_down = (*policy & PTIMER_POLICY_NO_COUNTER_ROUND_DOWN);
triggered = false; triggered = false;
ptimer_transaction_begin(ptimer);
ptimer_set_period(ptimer, 2000000); ptimer_set_period(ptimer, 2000000);
ptimer_set_limit(ptimer, 10, 1); ptimer_set_limit(ptimer, 10, 1);
ptimer_run(ptimer, 1); ptimer_run(ptimer, 1);
ptimer_transaction_commit(ptimer);
qemu_clock_step(2000000 * 9 + 1); qemu_clock_step(2000000 * 9 + 1);
g_assert_cmpuint(ptimer_get_count(ptimer), ==, no_round_down ? 1 : 0); g_assert_cmpuint(ptimer_get_count(ptimer), ==, no_round_down ? 1 : 0);
g_assert_false(triggered); g_assert_false(triggered);
ptimer_transaction_begin(ptimer);
ptimer_run(ptimer, 0); ptimer_run(ptimer, 0);
ptimer_transaction_commit(ptimer);
g_assert_cmpuint(ptimer_get_count(ptimer), ==, no_round_down ? 1 : 0); g_assert_cmpuint(ptimer_get_count(ptimer), ==, no_round_down ? 1 : 0);
g_assert_false(triggered); g_assert_false(triggered);
...@@ -403,7 +443,9 @@ static void check_on_the_fly_mode_change(gconstpointer arg) ...@@ -403,7 +443,9 @@ static void check_on_the_fly_mode_change(gconstpointer arg)
qemu_clock_step(2000000 * 9); qemu_clock_step(2000000 * 9);
ptimer_transaction_begin(ptimer);
ptimer_run(ptimer, 1); ptimer_run(ptimer, 1);
ptimer_transaction_commit(ptimer);
g_assert_cmpuint(ptimer_get_count(ptimer), ==, g_assert_cmpuint(ptimer_get_count(ptimer), ==,
(no_round_down ? 1 : 0) + (wrap_policy ? 1 : 0)); (no_round_down ? 1 : 0) + (wrap_policy ? 1 : 0));
...@@ -419,22 +461,25 @@ static void check_on_the_fly_mode_change(gconstpointer arg) ...@@ -419,22 +461,25 @@ static void check_on_the_fly_mode_change(gconstpointer arg)
static void check_on_the_fly_period_change(gconstpointer arg) static void check_on_the_fly_period_change(gconstpointer arg)
{ {
const uint8_t *policy = arg; const uint8_t *policy = arg;
QEMUBH *bh = qemu_bh_new(ptimer_trigger, NULL); ptimer_state *ptimer = ptimer_init(ptimer_trigger, NULL, *policy);
ptimer_state *ptimer = ptimer_init_with_bh(bh, *policy);
bool no_round_down = (*policy & PTIMER_POLICY_NO_COUNTER_ROUND_DOWN); bool no_round_down = (*policy & PTIMER_POLICY_NO_COUNTER_ROUND_DOWN);
triggered = false; triggered = false;
ptimer_transaction_begin(ptimer);
ptimer_set_period(ptimer, 2000000); ptimer_set_period(ptimer, 2000000);
ptimer_set_limit(ptimer, 8, 1); ptimer_set_limit(ptimer, 8, 1);
ptimer_run(ptimer, 1); ptimer_run(ptimer, 1);
ptimer_transaction_commit(ptimer);
qemu_clock_step(2000000 * 4 + 1); qemu_clock_step(2000000 * 4 + 1);
g_assert_cmpuint(ptimer_get_count(ptimer), ==, no_round_down ? 4 : 3); g_assert_cmpuint(ptimer_get_count(ptimer), ==, no_round_down ? 4 : 3);
g_assert_false(triggered); g_assert_false(triggered);
ptimer_transaction_begin(ptimer);
ptimer_set_period(ptimer, 4000000); ptimer_set_period(ptimer, 4000000);
ptimer_transaction_commit(ptimer);
g_assert_cmpuint(ptimer_get_count(ptimer), ==, no_round_down ? 4 : 3); g_assert_cmpuint(ptimer_get_count(ptimer), ==, no_round_down ? 4 : 3);
qemu_clock_step(4000000 * 2 + 1); qemu_clock_step(4000000 * 2 + 1);
...@@ -452,22 +497,25 @@ static void check_on_the_fly_period_change(gconstpointer arg) ...@@ -452,22 +497,25 @@ static void check_on_the_fly_period_change(gconstpointer arg)
static void check_on_the_fly_freq_change(gconstpointer arg) static void check_on_the_fly_freq_change(gconstpointer arg)
{ {
const uint8_t *policy = arg; const uint8_t *policy = arg;
QEMUBH *bh = qemu_bh_new(ptimer_trigger, NULL); ptimer_state *ptimer = ptimer_init(ptimer_trigger, NULL, *policy);
ptimer_state *ptimer = ptimer_init_with_bh(bh, *policy);
bool no_round_down = (*policy & PTIMER_POLICY_NO_COUNTER_ROUND_DOWN); bool no_round_down = (*policy & PTIMER_POLICY_NO_COUNTER_ROUND_DOWN);
triggered = false; triggered = false;
ptimer_transaction_begin(ptimer);
ptimer_set_freq(ptimer, 500); ptimer_set_freq(ptimer, 500);
ptimer_set_limit(ptimer, 8, 1); ptimer_set_limit(ptimer, 8, 1);
ptimer_run(ptimer, 1); ptimer_run(ptimer, 1);
ptimer_transaction_commit(ptimer);
qemu_clock_step(2000000 * 4 + 1); qemu_clock_step(2000000 * 4 + 1);
g_assert_cmpuint(ptimer_get_count(ptimer), ==, no_round_down ? 4 : 3); g_assert_cmpuint(ptimer_get_count(ptimer), ==, no_round_down ? 4 : 3);
g_assert_false(triggered); g_assert_false(triggered);
ptimer_transaction_begin(ptimer);
ptimer_set_freq(ptimer, 250); ptimer_set_freq(ptimer, 250);
ptimer_transaction_commit(ptimer);
g_assert_cmpuint(ptimer_get_count(ptimer), ==, no_round_down ? 4 : 3); g_assert_cmpuint(ptimer_get_count(ptimer), ==, no_round_down ? 4 : 3);
qemu_clock_step(2000000 * 4 + 1); qemu_clock_step(2000000 * 4 + 1);
...@@ -485,13 +533,14 @@ static void check_on_the_fly_freq_change(gconstpointer arg) ...@@ -485,13 +533,14 @@ static void check_on_the_fly_freq_change(gconstpointer arg)
static void check_run_with_period_0(gconstpointer arg) static void check_run_with_period_0(gconstpointer arg)
{ {
const uint8_t *policy = arg; const uint8_t *policy = arg;
QEMUBH *bh = qemu_bh_new(ptimer_trigger, NULL); ptimer_state *ptimer = ptimer_init(ptimer_trigger, NULL, *policy);
ptimer_state *ptimer = ptimer_init_with_bh(bh, *policy);
triggered = false; triggered = false;
ptimer_transaction_begin(ptimer);
ptimer_set_count(ptimer, 99); ptimer_set_count(ptimer, 99);
ptimer_run(ptimer, 1); ptimer_run(ptimer, 1);
ptimer_transaction_commit(ptimer);
qemu_clock_step(10 * NANOSECONDS_PER_SECOND); qemu_clock_step(10 * NANOSECONDS_PER_SECOND);
...@@ -503,8 +552,7 @@ static void check_run_with_period_0(gconstpointer arg) ...@@ -503,8 +552,7 @@ static void check_run_with_period_0(gconstpointer arg)
static void check_run_with_delta_0(gconstpointer arg) static void check_run_with_delta_0(gconstpointer arg)
{ {
const uint8_t *policy = arg; const uint8_t *policy = arg;
QEMUBH *bh = qemu_bh_new(ptimer_trigger, NULL); ptimer_state *ptimer = ptimer_init(ptimer_trigger, NULL, *policy);
ptimer_state *ptimer = ptimer_init_with_bh(bh, *policy);
bool wrap_policy = (*policy & PTIMER_POLICY_WRAP_AFTER_ONE_PERIOD); bool wrap_policy = (*policy & PTIMER_POLICY_WRAP_AFTER_ONE_PERIOD);
bool no_immediate_trigger = (*policy & PTIMER_POLICY_NO_IMMEDIATE_TRIGGER); bool no_immediate_trigger = (*policy & PTIMER_POLICY_NO_IMMEDIATE_TRIGGER);
bool no_immediate_reload = (*policy & PTIMER_POLICY_NO_IMMEDIATE_RELOAD); bool no_immediate_reload = (*policy & PTIMER_POLICY_NO_IMMEDIATE_RELOAD);
...@@ -513,9 +561,11 @@ static void check_run_with_delta_0(gconstpointer arg) ...@@ -513,9 +561,11 @@ static void check_run_with_delta_0(gconstpointer arg)
triggered = false; triggered = false;
ptimer_transaction_begin(ptimer);
ptimer_set_period(ptimer, 2000000); ptimer_set_period(ptimer, 2000000);
ptimer_set_limit(ptimer, 99, 0); ptimer_set_limit(ptimer, 99, 0);
ptimer_run(ptimer, 1); ptimer_run(ptimer, 1);
ptimer_transaction_commit(ptimer);
g_assert_cmpuint(ptimer_get_count(ptimer), ==, g_assert_cmpuint(ptimer_get_count(ptimer), ==,
no_immediate_reload ? 0 : 99); no_immediate_reload ? 0 : 99);
...@@ -541,8 +591,10 @@ static void check_run_with_delta_0(gconstpointer arg) ...@@ -541,8 +591,10 @@ static void check_run_with_delta_0(gconstpointer arg)
g_assert_false(triggered); g_assert_false(triggered);
} }
ptimer_transaction_begin(ptimer);
ptimer_set_count(ptimer, 99); ptimer_set_count(ptimer, 99);
ptimer_run(ptimer, 1); ptimer_run(ptimer, 1);
ptimer_transaction_commit(ptimer);
} }
qemu_clock_step(2000000 + 1); qemu_clock_step(2000000 + 1);
...@@ -562,8 +614,10 @@ static void check_run_with_delta_0(gconstpointer arg) ...@@ -562,8 +614,10 @@ static void check_run_with_delta_0(gconstpointer arg)
triggered = false; triggered = false;
ptimer_transaction_begin(ptimer);
ptimer_set_count(ptimer, 0); ptimer_set_count(ptimer, 0);
ptimer_run(ptimer, 0); ptimer_run(ptimer, 0);
ptimer_transaction_commit(ptimer);
g_assert_cmpuint(ptimer_get_count(ptimer), ==, g_assert_cmpuint(ptimer_get_count(ptimer), ==,
no_immediate_reload ? 0 : 99); no_immediate_reload ? 0 : 99);
...@@ -602,23 +656,26 @@ static void check_run_with_delta_0(gconstpointer arg) ...@@ -602,23 +656,26 @@ static void check_run_with_delta_0(gconstpointer arg)
wrap_policy ? 0 : (no_round_down ? 99 : 98)); wrap_policy ? 0 : (no_round_down ? 99 : 98));
g_assert_true(triggered); g_assert_true(triggered);
ptimer_transaction_begin(ptimer);
ptimer_stop(ptimer); ptimer_stop(ptimer);
ptimer_transaction_commit(ptimer);
ptimer_free(ptimer); ptimer_free(ptimer);
} }
static void check_periodic_with_load_0(gconstpointer arg) static void check_periodic_with_load_0(gconstpointer arg)
{ {
const uint8_t *policy = arg; const uint8_t *policy = arg;
QEMUBH *bh = qemu_bh_new(ptimer_trigger, NULL); ptimer_state *ptimer = ptimer_init(ptimer_trigger, NULL, *policy);
ptimer_state *ptimer = ptimer_init_with_bh(bh, *policy);
bool continuous_trigger = (*policy & PTIMER_POLICY_CONTINUOUS_TRIGGER); bool continuous_trigger = (*policy & PTIMER_POLICY_CONTINUOUS_TRIGGER);
bool no_immediate_trigger = (*policy & PTIMER_POLICY_NO_IMMEDIATE_TRIGGER); bool no_immediate_trigger = (*policy & PTIMER_POLICY_NO_IMMEDIATE_TRIGGER);
bool trig_only_on_dec = (*policy & PTIMER_POLICY_TRIGGER_ONLY_ON_DECREMENT); bool trig_only_on_dec = (*policy & PTIMER_POLICY_TRIGGER_ONLY_ON_DECREMENT);
triggered = false; triggered = false;
ptimer_transaction_begin(ptimer);
ptimer_set_period(ptimer, 2000000); ptimer_set_period(ptimer, 2000000);
ptimer_run(ptimer, 0); ptimer_run(ptimer, 0);
ptimer_transaction_commit(ptimer);
g_assert_cmpuint(ptimer_get_count(ptimer), ==, 0); g_assert_cmpuint(ptimer_get_count(ptimer), ==, 0);
...@@ -642,8 +699,10 @@ static void check_periodic_with_load_0(gconstpointer arg) ...@@ -642,8 +699,10 @@ static void check_periodic_with_load_0(gconstpointer arg)
triggered = false; triggered = false;
ptimer_transaction_begin(ptimer);
ptimer_set_count(ptimer, 10); ptimer_set_count(ptimer, 10);
ptimer_run(ptimer, 0); ptimer_run(ptimer, 0);
ptimer_transaction_commit(ptimer);
qemu_clock_step(2000000 * 10 + 1); qemu_clock_step(2000000 * 10 + 1);
...@@ -662,22 +721,25 @@ static void check_periodic_with_load_0(gconstpointer arg) ...@@ -662,22 +721,25 @@ static void check_periodic_with_load_0(gconstpointer arg)
g_assert_false(triggered); g_assert_false(triggered);
} }
ptimer_transaction_begin(ptimer);
ptimer_stop(ptimer); ptimer_stop(ptimer);
ptimer_transaction_commit(ptimer);
ptimer_free(ptimer); ptimer_free(ptimer);
} }
static void check_oneshot_with_load_0(gconstpointer arg) static void check_oneshot_with_load_0(gconstpointer arg)
{ {
const uint8_t *policy = arg; const uint8_t *policy = arg;
QEMUBH *bh = qemu_bh_new(ptimer_trigger, NULL); ptimer_state *ptimer = ptimer_init(ptimer_trigger, NULL, *policy);
ptimer_state *ptimer = ptimer_init_with_bh(bh, *policy);
bool no_immediate_trigger = (*policy & PTIMER_POLICY_NO_IMMEDIATE_TRIGGER); bool no_immediate_trigger = (*policy & PTIMER_POLICY_NO_IMMEDIATE_TRIGGER);
bool trig_only_on_dec = (*policy & PTIMER_POLICY_TRIGGER_ONLY_ON_DECREMENT); bool trig_only_on_dec = (*policy & PTIMER_POLICY_TRIGGER_ONLY_ON_DECREMENT);
triggered = false; triggered = false;
ptimer_transaction_begin(ptimer);
ptimer_set_period(ptimer, 2000000); ptimer_set_period(ptimer, 2000000);
ptimer_run(ptimer, 1); ptimer_run(ptimer, 1);
ptimer_transaction_commit(ptimer);
g_assert_cmpuint(ptimer_get_count(ptimer), ==, 0); g_assert_cmpuint(ptimer_get_count(ptimer), ==, 0);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册