2016-09-22 17:13:07 +00:00
|
|
|
/*
|
|
|
|
* QTest testcase for the ptimer
|
|
|
|
*
|
2016-10-24 15:26:53 +00:00
|
|
|
* Copyright (c) 2016 Dmitry Osipenko <digetx@gmail.com>
|
2016-09-22 17:13:07 +00:00
|
|
|
*
|
|
|
|
* This work is licensed under the terms of the GNU GPL, version 2 or later.
|
|
|
|
* See the COPYING file in the top-level directory.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2018-02-01 11:18:29 +00:00
|
|
|
#include "qemu/osdep.h"
|
2016-09-22 17:13:07 +00:00
|
|
|
#include <glib/gprintf.h>
|
|
|
|
|
|
|
|
#include "qemu/main-loop.h"
|
|
|
|
#include "hw/ptimer.h"
|
|
|
|
|
|
|
|
#include "libqtest.h"
|
|
|
|
#include "ptimer-test.h"
|
|
|
|
|
|
|
|
static bool triggered;
|
|
|
|
|
|
|
|
static void ptimer_trigger(void *opaque)
|
|
|
|
{
|
|
|
|
triggered = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void ptimer_test_expire_qemu_timers(int64_t expire_time,
|
|
|
|
QEMUClockType type)
|
|
|
|
{
|
|
|
|
QEMUTimerList *timer_list = main_loop_tlg.tl[type];
|
|
|
|
QEMUTimer *t = timer_list->active_timers.next;
|
|
|
|
|
|
|
|
while (t != NULL) {
|
|
|
|
if (t->expire_time == expire_time) {
|
|
|
|
timer_del(t);
|
|
|
|
|
|
|
|
if (t->cb != NULL) {
|
|
|
|
t->cb(t->opaque);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
t = t->next;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void ptimer_test_set_qemu_time_ns(int64_t ns)
|
|
|
|
{
|
|
|
|
ptimer_test_time_ns = ns;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void qemu_clock_step(uint64_t ns)
|
|
|
|
{
|
|
|
|
int64_t deadline = qemu_clock_deadline_ns_all(QEMU_CLOCK_VIRTUAL);
|
|
|
|
int64_t advanced_time = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL) + ns;
|
|
|
|
|
|
|
|
while (deadline != -1 && deadline <= advanced_time) {
|
|
|
|
ptimer_test_set_qemu_time_ns(deadline);
|
|
|
|
ptimer_test_expire_qemu_timers(deadline, QEMU_CLOCK_VIRTUAL);
|
|
|
|
deadline = qemu_clock_deadline_ns_all(QEMU_CLOCK_VIRTUAL);
|
|
|
|
}
|
|
|
|
|
|
|
|
ptimer_test_set_qemu_time_ns(advanced_time);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void check_set_count(gconstpointer arg)
|
|
|
|
{
|
|
|
|
const uint8_t *policy = arg;
|
|
|
|
QEMUBH *bh = qemu_bh_new(ptimer_trigger, NULL);
|
|
|
|
ptimer_state *ptimer = ptimer_init(bh, *policy);
|
|
|
|
|
|
|
|
triggered = false;
|
|
|
|
|
|
|
|
ptimer_set_count(ptimer, 1000);
|
|
|
|
g_assert_cmpuint(ptimer_get_count(ptimer), ==, 1000);
|
|
|
|
g_assert_false(triggered);
|
2017-01-27 08:55:51 +00:00
|
|
|
ptimer_free(ptimer);
|
2016-09-22 17:13:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void check_set_limit(gconstpointer arg)
|
|
|
|
{
|
|
|
|
const uint8_t *policy = arg;
|
|
|
|
QEMUBH *bh = qemu_bh_new(ptimer_trigger, NULL);
|
|
|
|
ptimer_state *ptimer = ptimer_init(bh, *policy);
|
|
|
|
|
|
|
|
triggered = false;
|
|
|
|
|
|
|
|
ptimer_set_limit(ptimer, 1000, 0);
|
|
|
|
g_assert_cmpuint(ptimer_get_count(ptimer), ==, 0);
|
|
|
|
g_assert_cmpuint(ptimer_get_limit(ptimer), ==, 1000);
|
|
|
|
g_assert_false(triggered);
|
|
|
|
|
|
|
|
ptimer_set_limit(ptimer, 2000, 1);
|
|
|
|
g_assert_cmpuint(ptimer_get_count(ptimer), ==, 2000);
|
|
|
|
g_assert_cmpuint(ptimer_get_limit(ptimer), ==, 2000);
|
|
|
|
g_assert_false(triggered);
|
2017-01-27 08:55:51 +00:00
|
|
|
ptimer_free(ptimer);
|
2016-09-22 17:13:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void check_oneshot(gconstpointer arg)
|
|
|
|
{
|
|
|
|
const uint8_t *policy = arg;
|
|
|
|
QEMUBH *bh = qemu_bh_new(ptimer_trigger, NULL);
|
|
|
|
ptimer_state *ptimer = ptimer_init(bh, *policy);
|
2016-10-24 15:26:53 +00:00
|
|
|
bool no_round_down = (*policy & PTIMER_POLICY_NO_COUNTER_ROUND_DOWN);
|
2016-09-22 17:13:07 +00:00
|
|
|
|
|
|
|
triggered = false;
|
|
|
|
|
|
|
|
ptimer_set_period(ptimer, 2000000);
|
|
|
|
ptimer_set_count(ptimer, 10);
|
|
|
|
ptimer_run(ptimer, 1);
|
|
|
|
|
2016-10-24 15:26:53 +00:00
|
|
|
qemu_clock_step(2000000 * 2 + 1);
|
2016-09-22 17:13:07 +00:00
|
|
|
|
2016-10-24 15:26:53 +00:00
|
|
|
g_assert_cmpuint(ptimer_get_count(ptimer), ==, no_round_down ? 8 : 7);
|
2016-09-22 17:13:07 +00:00
|
|
|
g_assert_false(triggered);
|
|
|
|
|
|
|
|
ptimer_stop(ptimer);
|
|
|
|
|
2016-10-24 15:26:53 +00:00
|
|
|
g_assert_cmpuint(ptimer_get_count(ptimer), ==, no_round_down ? 8 : 7);
|
2016-09-22 17:13:07 +00:00
|
|
|
g_assert_false(triggered);
|
|
|
|
|
|
|
|
qemu_clock_step(2000000 * 11);
|
|
|
|
|
2016-10-24 15:26:53 +00:00
|
|
|
g_assert_cmpuint(ptimer_get_count(ptimer), ==, no_round_down ? 8 : 7);
|
2016-09-22 17:13:07 +00:00
|
|
|
g_assert_false(triggered);
|
|
|
|
|
|
|
|
ptimer_run(ptimer, 1);
|
|
|
|
|
2016-10-24 15:26:53 +00:00
|
|
|
qemu_clock_step(2000000 * 7 + 1);
|
2016-09-22 17:13:07 +00:00
|
|
|
|
2016-10-24 15:26:53 +00:00
|
|
|
g_assert_cmpuint(ptimer_get_count(ptimer), ==, no_round_down ? 1 : 0);
|
2016-09-22 17:13:07 +00:00
|
|
|
|
2016-10-24 15:26:53 +00:00
|
|
|
if (no_round_down) {
|
|
|
|
g_assert_false(triggered);
|
|
|
|
} else {
|
|
|
|
g_assert_true(triggered);
|
|
|
|
|
|
|
|
triggered = false;
|
|
|
|
}
|
2016-09-22 17:13:07 +00:00
|
|
|
|
|
|
|
qemu_clock_step(2000000);
|
|
|
|
|
|
|
|
g_assert_cmpuint(ptimer_get_count(ptimer), ==, 0);
|
2016-10-24 15:26:53 +00:00
|
|
|
|
|
|
|
if (no_round_down) {
|
|
|
|
g_assert_true(triggered);
|
|
|
|
|
|
|
|
triggered = false;
|
|
|
|
} else {
|
|
|
|
g_assert_false(triggered);
|
|
|
|
}
|
2016-09-22 17:13:07 +00:00
|
|
|
|
|
|
|
qemu_clock_step(4000000);
|
|
|
|
|
|
|
|
g_assert_cmpuint(ptimer_get_count(ptimer), ==, 0);
|
|
|
|
g_assert_false(triggered);
|
|
|
|
|
|
|
|
ptimer_set_count(ptimer, 10);
|
|
|
|
|
2016-10-24 15:26:53 +00:00
|
|
|
qemu_clock_step(20000000 + 1);
|
2016-09-22 17:13:07 +00:00
|
|
|
|
|
|
|
g_assert_cmpuint(ptimer_get_count(ptimer), ==, 10);
|
|
|
|
g_assert_false(triggered);
|
|
|
|
|
|
|
|
ptimer_set_limit(ptimer, 9, 1);
|
|
|
|
|
2016-10-24 15:26:53 +00:00
|
|
|
qemu_clock_step(20000000 + 1);
|
2016-09-22 17:13:07 +00:00
|
|
|
|
|
|
|
g_assert_cmpuint(ptimer_get_count(ptimer), ==, 9);
|
|
|
|
g_assert_false(triggered);
|
|
|
|
|
|
|
|
ptimer_run(ptimer, 1);
|
|
|
|
|
2016-10-24 15:26:53 +00:00
|
|
|
qemu_clock_step(2000000 + 1);
|
2016-09-22 17:13:07 +00:00
|
|
|
|
2016-10-24 15:26:53 +00:00
|
|
|
g_assert_cmpuint(ptimer_get_count(ptimer), ==, no_round_down ? 8 : 7);
|
2016-09-22 17:13:07 +00:00
|
|
|
g_assert_false(triggered);
|
|
|
|
|
|
|
|
ptimer_set_count(ptimer, 20);
|
|
|
|
|
2016-10-24 15:26:53 +00:00
|
|
|
qemu_clock_step(2000000 * 19 + 1);
|
2016-09-22 17:13:07 +00:00
|
|
|
|
2016-10-24 15:26:53 +00:00
|
|
|
g_assert_cmpuint(ptimer_get_count(ptimer), ==, no_round_down ? 1 : 0);
|
2016-09-22 17:13:07 +00:00
|
|
|
g_assert_false(triggered);
|
|
|
|
|
|
|
|
qemu_clock_step(2000000);
|
|
|
|
|
|
|
|
g_assert_cmpuint(ptimer_get_count(ptimer), ==, 0);
|
|
|
|
g_assert_true(triggered);
|
|
|
|
|
|
|
|
ptimer_stop(ptimer);
|
|
|
|
|
|
|
|
triggered = false;
|
|
|
|
|
2016-10-24 15:26:53 +00:00
|
|
|
qemu_clock_step(2000000 * 12 + 1);
|
2016-09-22 17:13:07 +00:00
|
|
|
|
|
|
|
g_assert_cmpuint(ptimer_get_count(ptimer), ==, 0);
|
|
|
|
g_assert_false(triggered);
|
2017-01-27 08:55:51 +00:00
|
|
|
ptimer_free(ptimer);
|
2016-09-22 17:13:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void check_periodic(gconstpointer arg)
|
|
|
|
{
|
|
|
|
const uint8_t *policy = arg;
|
|
|
|
QEMUBH *bh = qemu_bh_new(ptimer_trigger, NULL);
|
|
|
|
ptimer_state *ptimer = ptimer_init(bh, *policy);
|
2016-10-24 15:26:51 +00:00
|
|
|
bool wrap_policy = (*policy & PTIMER_POLICY_WRAP_AFTER_ONE_PERIOD);
|
2016-10-24 15:26:52 +00:00
|
|
|
bool no_immediate_trigger = (*policy & PTIMER_POLICY_NO_IMMEDIATE_TRIGGER);
|
2016-10-24 15:26:52 +00:00
|
|
|
bool no_immediate_reload = (*policy & PTIMER_POLICY_NO_IMMEDIATE_RELOAD);
|
2016-10-24 15:26:53 +00:00
|
|
|
bool no_round_down = (*policy & PTIMER_POLICY_NO_COUNTER_ROUND_DOWN);
|
2018-07-09 13:51:34 +00:00
|
|
|
bool trig_only_on_dec = (*policy & PTIMER_POLICY_TRIGGER_ONLY_ON_DECREMENT);
|
2016-09-22 17:13:07 +00:00
|
|
|
|
|
|
|
triggered = false;
|
|
|
|
|
|
|
|
ptimer_set_period(ptimer, 2000000);
|
|
|
|
ptimer_set_limit(ptimer, 10, 1);
|
|
|
|
ptimer_run(ptimer, 0);
|
|
|
|
|
2016-10-24 15:26:51 +00:00
|
|
|
g_assert_cmpuint(ptimer_get_count(ptimer), ==, 10);
|
|
|
|
g_assert_false(triggered);
|
|
|
|
|
2016-10-24 15:26:53 +00:00
|
|
|
qemu_clock_step(1);
|
2016-09-22 17:13:07 +00:00
|
|
|
|
2016-10-24 15:26:53 +00:00
|
|
|
g_assert_cmpuint(ptimer_get_count(ptimer), ==, no_round_down ? 10 : 9);
|
2016-10-24 15:26:51 +00:00
|
|
|
g_assert_false(triggered);
|
|
|
|
|
2016-10-24 15:26:53 +00:00
|
|
|
qemu_clock_step(2000000 * 10 - 1);
|
2016-10-24 15:26:51 +00:00
|
|
|
|
|
|
|
g_assert_cmpuint(ptimer_get_count(ptimer), ==, wrap_policy ? 0 : 10);
|
|
|
|
g_assert_true(triggered);
|
|
|
|
|
2016-10-24 15:26:53 +00:00
|
|
|
qemu_clock_step(1);
|
2016-10-24 15:26:51 +00:00
|
|
|
|
2016-10-24 15:26:53 +00:00
|
|
|
g_assert_cmpuint(ptimer_get_count(ptimer), ==,
|
|
|
|
wrap_policy ? 0 : (no_round_down ? 10 : 9));
|
2016-09-22 17:13:07 +00:00
|
|
|
g_assert_true(triggered);
|
|
|
|
|
|
|
|
triggered = false;
|
|
|
|
|
|
|
|
qemu_clock_step(2000000);
|
|
|
|
|
2016-10-24 15:26:53 +00:00
|
|
|
g_assert_cmpuint(ptimer_get_count(ptimer), ==,
|
|
|
|
(no_round_down ? 9 : 8) + (wrap_policy ? 1 : 0));
|
2016-09-22 17:13:07 +00:00
|
|
|
g_assert_false(triggered);
|
|
|
|
|
|
|
|
ptimer_set_count(ptimer, 20);
|
|
|
|
|
2016-10-24 15:26:51 +00:00
|
|
|
g_assert_cmpuint(ptimer_get_count(ptimer), ==, 20);
|
|
|
|
g_assert_false(triggered);
|
|
|
|
|
2016-10-24 15:26:53 +00:00
|
|
|
qemu_clock_step(1);
|
2016-10-24 15:26:51 +00:00
|
|
|
|
2016-10-24 15:26:53 +00:00
|
|
|
g_assert_cmpuint(ptimer_get_count(ptimer), ==, no_round_down ? 20 : 19);
|
2016-10-24 15:26:51 +00:00
|
|
|
g_assert_false(triggered);
|
|
|
|
|
2016-10-24 15:26:53 +00:00
|
|
|
qemu_clock_step(2000000 * 11 + 1);
|
2016-09-22 17:13:07 +00:00
|
|
|
|
2016-10-24 15:26:53 +00:00
|
|
|
g_assert_cmpuint(ptimer_get_count(ptimer), ==, no_round_down ? 9 : 8);
|
2016-09-22 17:13:07 +00:00
|
|
|
g_assert_false(triggered);
|
|
|
|
|
|
|
|
qemu_clock_step(2000000 * 10);
|
|
|
|
|
2016-10-24 15:26:53 +00:00
|
|
|
g_assert_cmpuint(ptimer_get_count(ptimer), ==,
|
|
|
|
(no_round_down ? 9 : 8) + (wrap_policy ? 1 : 0));
|
2016-10-24 15:26:51 +00:00
|
|
|
g_assert_true(triggered);
|
|
|
|
|
|
|
|
triggered = false;
|
|
|
|
|
|
|
|
ptimer_set_count(ptimer, 3);
|
|
|
|
|
|
|
|
g_assert_cmpuint(ptimer_get_count(ptimer), ==, 3);
|
|
|
|
g_assert_false(triggered);
|
|
|
|
|
2016-10-24 15:26:53 +00:00
|
|
|
qemu_clock_step(1);
|
2016-10-24 15:26:51 +00:00
|
|
|
|
2016-10-24 15:26:53 +00:00
|
|
|
g_assert_cmpuint(ptimer_get_count(ptimer), ==, no_round_down ? 3 : 2);
|
2016-10-24 15:26:51 +00:00
|
|
|
g_assert_false(triggered);
|
|
|
|
|
|
|
|
qemu_clock_step(2000000 * 4);
|
|
|
|
|
2016-10-24 15:26:53 +00:00
|
|
|
g_assert_cmpuint(ptimer_get_count(ptimer), ==,
|
|
|
|
(no_round_down ? 9 : 8) + (wrap_policy ? 1 : 0));
|
2016-09-22 17:13:07 +00:00
|
|
|
g_assert_true(triggered);
|
|
|
|
|
|
|
|
ptimer_stop(ptimer);
|
|
|
|
triggered = false;
|
|
|
|
|
|
|
|
qemu_clock_step(2000000);
|
|
|
|
|
2016-10-24 15:26:53 +00:00
|
|
|
g_assert_cmpuint(ptimer_get_count(ptimer), ==,
|
|
|
|
(no_round_down ? 9 : 8) + (wrap_policy ? 1 : 0));
|
2016-09-22 17:13:07 +00:00
|
|
|
g_assert_false(triggered);
|
|
|
|
|
|
|
|
ptimer_set_count(ptimer, 3);
|
|
|
|
ptimer_run(ptimer, 0);
|
|
|
|
|
2016-10-24 15:26:53 +00:00
|
|
|
qemu_clock_step(2000000 * 3 + 1);
|
2016-09-22 17:13:07 +00:00
|
|
|
|
2016-10-24 15:26:53 +00:00
|
|
|
g_assert_cmpuint(ptimer_get_count(ptimer), ==,
|
|
|
|
wrap_policy ? 0 : (no_round_down ? 10 : 9));
|
2016-09-22 17:13:07 +00:00
|
|
|
g_assert_true(triggered);
|
|
|
|
|
|
|
|
triggered = false;
|
|
|
|
|
|
|
|
qemu_clock_step(2000000);
|
|
|
|
|
2016-10-24 15:26:53 +00:00
|
|
|
g_assert_cmpuint(ptimer_get_count(ptimer), ==,
|
|
|
|
(no_round_down ? 9 : 8) + (wrap_policy ? 1 : 0));
|
2016-09-22 17:13:07 +00:00
|
|
|
g_assert_false(triggered);
|
|
|
|
|
|
|
|
ptimer_set_count(ptimer, 0);
|
2016-10-24 15:26:52 +00:00
|
|
|
g_assert_cmpuint(ptimer_get_count(ptimer), ==,
|
|
|
|
no_immediate_reload ? 0 : 10);
|
2016-10-24 15:26:52 +00:00
|
|
|
|
2018-07-09 13:51:34 +00:00
|
|
|
if (no_immediate_trigger || trig_only_on_dec) {
|
2016-10-24 15:26:52 +00:00
|
|
|
g_assert_false(triggered);
|
|
|
|
} else {
|
|
|
|
g_assert_true(triggered);
|
|
|
|
}
|
2016-09-22 17:13:07 +00:00
|
|
|
|
|
|
|
triggered = false;
|
|
|
|
|
2016-10-24 15:26:53 +00:00
|
|
|
qemu_clock_step(1);
|
2016-09-22 17:13:07 +00:00
|
|
|
|
2016-10-24 15:26:52 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2016-10-24 15:26:53 +00:00
|
|
|
g_assert_cmpuint(ptimer_get_count(ptimer), ==, no_round_down ? 10 : 9);
|
2016-10-24 15:26:51 +00:00
|
|
|
g_assert_false(triggered);
|
|
|
|
|
|
|
|
qemu_clock_step(2000000 * 12);
|
|
|
|
|
2016-10-24 15:26:53 +00:00
|
|
|
g_assert_cmpuint(ptimer_get_count(ptimer), ==,
|
|
|
|
(no_round_down ? 8 : 7) + (wrap_policy ? 1 : 0));
|
2016-09-22 17:13:07 +00:00
|
|
|
g_assert_true(triggered);
|
|
|
|
|
|
|
|
ptimer_stop(ptimer);
|
|
|
|
|
|
|
|
triggered = false;
|
|
|
|
|
2016-10-24 15:26:51 +00:00
|
|
|
qemu_clock_step(2000000 * 10);
|
2016-09-22 17:13:07 +00:00
|
|
|
|
2016-10-24 15:26:53 +00:00
|
|
|
g_assert_cmpuint(ptimer_get_count(ptimer), ==,
|
|
|
|
(no_round_down ? 8 : 7) + (wrap_policy ? 1 : 0));
|
2016-09-22 17:13:07 +00:00
|
|
|
g_assert_false(triggered);
|
|
|
|
|
|
|
|
ptimer_run(ptimer, 0);
|
|
|
|
ptimer_set_period(ptimer, 0);
|
|
|
|
|
2016-10-24 15:26:53 +00:00
|
|
|
qemu_clock_step(2000000 + 1);
|
2016-09-22 17:13:07 +00:00
|
|
|
|
2016-10-24 15:26:53 +00:00
|
|
|
g_assert_cmpuint(ptimer_get_count(ptimer), ==,
|
|
|
|
(no_round_down ? 8 : 7) + (wrap_policy ? 1 : 0));
|
2016-09-22 17:13:07 +00:00
|
|
|
g_assert_false(triggered);
|
2017-01-27 08:55:51 +00:00
|
|
|
ptimer_free(ptimer);
|
2016-09-22 17:13:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void check_on_the_fly_mode_change(gconstpointer arg)
|
|
|
|
{
|
|
|
|
const uint8_t *policy = arg;
|
|
|
|
QEMUBH *bh = qemu_bh_new(ptimer_trigger, NULL);
|
|
|
|
ptimer_state *ptimer = ptimer_init(bh, *policy);
|
2016-10-24 15:26:51 +00:00
|
|
|
bool wrap_policy = (*policy & PTIMER_POLICY_WRAP_AFTER_ONE_PERIOD);
|
2016-10-24 15:26:53 +00:00
|
|
|
bool no_round_down = (*policy & PTIMER_POLICY_NO_COUNTER_ROUND_DOWN);
|
2016-09-22 17:13:07 +00:00
|
|
|
|
|
|
|
triggered = false;
|
|
|
|
|
|
|
|
ptimer_set_period(ptimer, 2000000);
|
|
|
|
ptimer_set_limit(ptimer, 10, 1);
|
|
|
|
ptimer_run(ptimer, 1);
|
|
|
|
|
2016-10-24 15:26:53 +00:00
|
|
|
qemu_clock_step(2000000 * 9 + 1);
|
2016-09-22 17:13:07 +00:00
|
|
|
|
2016-10-24 15:26:53 +00:00
|
|
|
g_assert_cmpuint(ptimer_get_count(ptimer), ==, no_round_down ? 1 : 0);
|
2016-10-24 15:26:51 +00:00
|
|
|
g_assert_false(triggered);
|
|
|
|
|
2016-09-22 17:13:07 +00:00
|
|
|
ptimer_run(ptimer, 0);
|
|
|
|
|
2016-10-24 15:26:53 +00:00
|
|
|
g_assert_cmpuint(ptimer_get_count(ptimer), ==, no_round_down ? 1 : 0);
|
2016-09-22 17:13:07 +00:00
|
|
|
g_assert_false(triggered);
|
|
|
|
|
|
|
|
qemu_clock_step(2000000);
|
|
|
|
|
2016-10-24 15:26:53 +00:00
|
|
|
g_assert_cmpuint(ptimer_get_count(ptimer), ==,
|
|
|
|
wrap_policy ? 0 : (no_round_down ? 10 : 9));
|
2016-09-22 17:13:07 +00:00
|
|
|
g_assert_true(triggered);
|
|
|
|
|
|
|
|
triggered = false;
|
|
|
|
|
|
|
|
qemu_clock_step(2000000 * 9);
|
|
|
|
|
|
|
|
ptimer_run(ptimer, 1);
|
|
|
|
|
2016-10-24 15:26:53 +00:00
|
|
|
g_assert_cmpuint(ptimer_get_count(ptimer), ==,
|
|
|
|
(no_round_down ? 1 : 0) + (wrap_policy ? 1 : 0));
|
2016-09-22 17:13:07 +00:00
|
|
|
g_assert_false(triggered);
|
|
|
|
|
|
|
|
qemu_clock_step(2000000 * 3);
|
|
|
|
|
|
|
|
g_assert_cmpuint(ptimer_get_count(ptimer), ==, 0);
|
|
|
|
g_assert_true(triggered);
|
2017-01-27 08:55:51 +00:00
|
|
|
ptimer_free(ptimer);
|
2016-09-22 17:13:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void check_on_the_fly_period_change(gconstpointer arg)
|
|
|
|
{
|
|
|
|
const uint8_t *policy = arg;
|
|
|
|
QEMUBH *bh = qemu_bh_new(ptimer_trigger, NULL);
|
|
|
|
ptimer_state *ptimer = ptimer_init(bh, *policy);
|
2016-10-24 15:26:53 +00:00
|
|
|
bool no_round_down = (*policy & PTIMER_POLICY_NO_COUNTER_ROUND_DOWN);
|
2016-09-22 17:13:07 +00:00
|
|
|
|
|
|
|
triggered = false;
|
|
|
|
|
|
|
|
ptimer_set_period(ptimer, 2000000);
|
|
|
|
ptimer_set_limit(ptimer, 8, 1);
|
|
|
|
ptimer_run(ptimer, 1);
|
|
|
|
|
2016-10-24 15:26:53 +00:00
|
|
|
qemu_clock_step(2000000 * 4 + 1);
|
2016-09-22 17:13:07 +00:00
|
|
|
|
2016-10-24 15:26:53 +00:00
|
|
|
g_assert_cmpuint(ptimer_get_count(ptimer), ==, no_round_down ? 4 : 3);
|
2016-09-22 17:13:07 +00:00
|
|
|
g_assert_false(triggered);
|
|
|
|
|
|
|
|
ptimer_set_period(ptimer, 4000000);
|
2016-10-24 15:26:53 +00:00
|
|
|
g_assert_cmpuint(ptimer_get_count(ptimer), ==, no_round_down ? 4 : 3);
|
2016-09-22 17:13:07 +00:00
|
|
|
|
2016-10-24 15:26:53 +00:00
|
|
|
qemu_clock_step(4000000 * 2 + 1);
|
2016-09-22 17:13:07 +00:00
|
|
|
|
2016-10-24 15:26:53 +00:00
|
|
|
g_assert_cmpuint(ptimer_get_count(ptimer), ==, no_round_down ? 2 : 0);
|
2016-09-22 17:13:07 +00:00
|
|
|
g_assert_false(triggered);
|
|
|
|
|
|
|
|
qemu_clock_step(4000000 * 2);
|
|
|
|
|
|
|
|
g_assert_cmpuint(ptimer_get_count(ptimer), ==, 0);
|
|
|
|
g_assert_true(triggered);
|
2017-01-27 08:55:51 +00:00
|
|
|
ptimer_free(ptimer);
|
2016-09-22 17:13:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void check_on_the_fly_freq_change(gconstpointer arg)
|
|
|
|
{
|
|
|
|
const uint8_t *policy = arg;
|
|
|
|
QEMUBH *bh = qemu_bh_new(ptimer_trigger, NULL);
|
|
|
|
ptimer_state *ptimer = ptimer_init(bh, *policy);
|
2016-10-24 15:26:53 +00:00
|
|
|
bool no_round_down = (*policy & PTIMER_POLICY_NO_COUNTER_ROUND_DOWN);
|
2016-09-22 17:13:07 +00:00
|
|
|
|
|
|
|
triggered = false;
|
|
|
|
|
|
|
|
ptimer_set_freq(ptimer, 500);
|
|
|
|
ptimer_set_limit(ptimer, 8, 1);
|
|
|
|
ptimer_run(ptimer, 1);
|
|
|
|
|
2016-10-24 15:26:53 +00:00
|
|
|
qemu_clock_step(2000000 * 4 + 1);
|
2016-09-22 17:13:07 +00:00
|
|
|
|
2016-10-24 15:26:53 +00:00
|
|
|
g_assert_cmpuint(ptimer_get_count(ptimer), ==, no_round_down ? 4 : 3);
|
2016-09-22 17:13:07 +00:00
|
|
|
g_assert_false(triggered);
|
|
|
|
|
|
|
|
ptimer_set_freq(ptimer, 250);
|
2016-10-24 15:26:53 +00:00
|
|
|
g_assert_cmpuint(ptimer_get_count(ptimer), ==, no_round_down ? 4 : 3);
|
2016-09-22 17:13:07 +00:00
|
|
|
|
2016-10-24 15:26:53 +00:00
|
|
|
qemu_clock_step(2000000 * 4 + 1);
|
2016-09-22 17:13:07 +00:00
|
|
|
|
2016-10-24 15:26:53 +00:00
|
|
|
g_assert_cmpuint(ptimer_get_count(ptimer), ==, no_round_down ? 2 : 0);
|
2016-09-22 17:13:07 +00:00
|
|
|
g_assert_false(triggered);
|
|
|
|
|
|
|
|
qemu_clock_step(2000000 * 4);
|
|
|
|
|
|
|
|
g_assert_cmpuint(ptimer_get_count(ptimer), ==, 0);
|
|
|
|
g_assert_true(triggered);
|
2017-01-27 08:55:51 +00:00
|
|
|
ptimer_free(ptimer);
|
2016-09-22 17:13:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void check_run_with_period_0(gconstpointer arg)
|
|
|
|
{
|
|
|
|
const uint8_t *policy = arg;
|
|
|
|
QEMUBH *bh = qemu_bh_new(ptimer_trigger, NULL);
|
|
|
|
ptimer_state *ptimer = ptimer_init(bh, *policy);
|
|
|
|
|
|
|
|
triggered = false;
|
|
|
|
|
|
|
|
ptimer_set_count(ptimer, 99);
|
|
|
|
ptimer_run(ptimer, 1);
|
|
|
|
|
|
|
|
qemu_clock_step(10 * NANOSECONDS_PER_SECOND);
|
|
|
|
|
|
|
|
g_assert_cmpuint(ptimer_get_count(ptimer), ==, 99);
|
|
|
|
g_assert_false(triggered);
|
2017-01-27 08:55:51 +00:00
|
|
|
ptimer_free(ptimer);
|
2016-09-22 17:13:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void check_run_with_delta_0(gconstpointer arg)
|
|
|
|
{
|
|
|
|
const uint8_t *policy = arg;
|
|
|
|
QEMUBH *bh = qemu_bh_new(ptimer_trigger, NULL);
|
|
|
|
ptimer_state *ptimer = ptimer_init(bh, *policy);
|
2016-10-24 15:26:51 +00:00
|
|
|
bool wrap_policy = (*policy & PTIMER_POLICY_WRAP_AFTER_ONE_PERIOD);
|
2016-10-24 15:26:52 +00:00
|
|
|
bool no_immediate_trigger = (*policy & PTIMER_POLICY_NO_IMMEDIATE_TRIGGER);
|
2016-10-24 15:26:52 +00:00
|
|
|
bool no_immediate_reload = (*policy & PTIMER_POLICY_NO_IMMEDIATE_RELOAD);
|
2016-10-24 15:26:53 +00:00
|
|
|
bool no_round_down = (*policy & PTIMER_POLICY_NO_COUNTER_ROUND_DOWN);
|
2018-07-09 13:51:34 +00:00
|
|
|
bool trig_only_on_dec = (*policy & PTIMER_POLICY_TRIGGER_ONLY_ON_DECREMENT);
|
2016-09-22 17:13:07 +00:00
|
|
|
|
|
|
|
triggered = false;
|
|
|
|
|
|
|
|
ptimer_set_period(ptimer, 2000000);
|
|
|
|
ptimer_set_limit(ptimer, 99, 0);
|
|
|
|
ptimer_run(ptimer, 1);
|
2016-10-24 15:26:52 +00:00
|
|
|
g_assert_cmpuint(ptimer_get_count(ptimer), ==,
|
|
|
|
no_immediate_reload ? 0 : 99);
|
2016-10-24 15:26:52 +00:00
|
|
|
|
2018-07-09 13:51:34 +00:00
|
|
|
if (no_immediate_trigger || trig_only_on_dec) {
|
2016-10-24 15:26:52 +00:00
|
|
|
g_assert_false(triggered);
|
|
|
|
} else {
|
|
|
|
g_assert_true(triggered);
|
|
|
|
}
|
2016-09-22 17:13:07 +00:00
|
|
|
|
|
|
|
triggered = false;
|
|
|
|
|
2016-10-24 15:26:52 +00:00
|
|
|
if (no_immediate_trigger || no_immediate_reload) {
|
2016-10-24 15:26:53 +00:00
|
|
|
qemu_clock_step(2000000 + 1);
|
2016-10-24 15:26:52 +00:00
|
|
|
|
2016-10-24 15:26:52 +00:00
|
|
|
g_assert_cmpuint(ptimer_get_count(ptimer), ==,
|
2016-10-24 15:26:53 +00:00
|
|
|
no_immediate_reload ? 0 : (no_round_down ? 98 : 97));
|
2016-10-24 15:26:52 +00:00
|
|
|
|
|
|
|
if (no_immediate_trigger && no_immediate_reload) {
|
|
|
|
g_assert_true(triggered);
|
|
|
|
|
|
|
|
triggered = false;
|
|
|
|
} else {
|
|
|
|
g_assert_false(triggered);
|
|
|
|
}
|
2016-10-24 15:26:52 +00:00
|
|
|
|
|
|
|
ptimer_set_count(ptimer, 99);
|
|
|
|
ptimer_run(ptimer, 1);
|
|
|
|
}
|
|
|
|
|
2016-10-24 15:26:53 +00:00
|
|
|
qemu_clock_step(2000000 + 1);
|
2016-09-22 17:13:07 +00:00
|
|
|
|
2016-10-24 15:26:53 +00:00
|
|
|
g_assert_cmpuint(ptimer_get_count(ptimer), ==, no_round_down ? 98 : 97);
|
2016-09-22 17:13:07 +00:00
|
|
|
g_assert_false(triggered);
|
|
|
|
|
|
|
|
qemu_clock_step(2000000 * 97);
|
|
|
|
|
2016-10-24 15:26:53 +00:00
|
|
|
g_assert_cmpuint(ptimer_get_count(ptimer), ==, no_round_down ? 1 : 0);
|
2016-09-22 17:13:07 +00:00
|
|
|
g_assert_false(triggered);
|
|
|
|
|
|
|
|
qemu_clock_step(2000000 * 2);
|
|
|
|
|
|
|
|
g_assert_cmpuint(ptimer_get_count(ptimer), ==, 0);
|
|
|
|
g_assert_true(triggered);
|
|
|
|
|
|
|
|
triggered = false;
|
|
|
|
|
|
|
|
ptimer_set_count(ptimer, 0);
|
|
|
|
ptimer_run(ptimer, 0);
|
2016-10-24 15:26:52 +00:00
|
|
|
g_assert_cmpuint(ptimer_get_count(ptimer), ==,
|
|
|
|
no_immediate_reload ? 0 : 99);
|
2016-10-24 15:26:52 +00:00
|
|
|
|
2018-07-09 13:51:34 +00:00
|
|
|
if (no_immediate_trigger || trig_only_on_dec) {
|
2016-10-24 15:26:52 +00:00
|
|
|
g_assert_false(triggered);
|
|
|
|
} else {
|
|
|
|
g_assert_true(triggered);
|
|
|
|
}
|
2016-09-22 17:13:07 +00:00
|
|
|
|
|
|
|
triggered = false;
|
|
|
|
|
2016-10-24 15:26:53 +00:00
|
|
|
qemu_clock_step(1);
|
2016-10-24 15:26:51 +00:00
|
|
|
|
2016-10-24 15:26:52 +00:00
|
|
|
if (no_immediate_reload) {
|
|
|
|
qemu_clock_step(2000000);
|
|
|
|
}
|
|
|
|
|
2016-10-24 15:26:53 +00:00
|
|
|
g_assert_cmpuint(ptimer_get_count(ptimer), ==, no_round_down ? 99 : 98);
|
2016-10-24 15:26:52 +00:00
|
|
|
|
|
|
|
if (no_immediate_reload && no_immediate_trigger) {
|
|
|
|
g_assert_true(triggered);
|
|
|
|
} else {
|
|
|
|
g_assert_false(triggered);
|
|
|
|
}
|
2016-10-24 15:26:51 +00:00
|
|
|
|
|
|
|
triggered = false;
|
|
|
|
|
|
|
|
qemu_clock_step(2000000);
|
2016-09-22 17:13:07 +00:00
|
|
|
|
2016-10-24 15:26:53 +00:00
|
|
|
g_assert_cmpuint(ptimer_get_count(ptimer), ==, no_round_down ? 98 : 97);
|
2016-09-22 17:13:07 +00:00
|
|
|
g_assert_false(triggered);
|
|
|
|
|
|
|
|
qemu_clock_step(2000000 * 98);
|
|
|
|
|
2016-10-24 15:26:53 +00:00
|
|
|
g_assert_cmpuint(ptimer_get_count(ptimer), ==,
|
|
|
|
wrap_policy ? 0 : (no_round_down ? 99 : 98));
|
2016-09-22 17:13:07 +00:00
|
|
|
g_assert_true(triggered);
|
|
|
|
|
|
|
|
ptimer_stop(ptimer);
|
2017-01-27 08:55:51 +00:00
|
|
|
ptimer_free(ptimer);
|
2016-09-22 17:13:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void check_periodic_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);
|
2016-10-24 15:26:51 +00:00
|
|
|
bool continuous_trigger = (*policy & PTIMER_POLICY_CONTINUOUS_TRIGGER);
|
2016-10-24 15:26:52 +00:00
|
|
|
bool no_immediate_trigger = (*policy & PTIMER_POLICY_NO_IMMEDIATE_TRIGGER);
|
2018-07-09 13:51:34 +00:00
|
|
|
bool trig_only_on_dec = (*policy & PTIMER_POLICY_TRIGGER_ONLY_ON_DECREMENT);
|
2016-09-22 17:13:07 +00:00
|
|
|
|
|
|
|
triggered = false;
|
|
|
|
|
|
|
|
ptimer_set_period(ptimer, 2000000);
|
|
|
|
ptimer_run(ptimer, 0);
|
|
|
|
|
|
|
|
g_assert_cmpuint(ptimer_get_count(ptimer), ==, 0);
|
2016-10-24 15:26:52 +00:00
|
|
|
|
2018-07-09 13:51:34 +00:00
|
|
|
if (no_immediate_trigger || trig_only_on_dec) {
|
2016-10-24 15:26:52 +00:00
|
|
|
g_assert_false(triggered);
|
|
|
|
} else {
|
|
|
|
g_assert_true(triggered);
|
|
|
|
}
|
2016-09-22 17:13:07 +00:00
|
|
|
|
|
|
|
triggered = false;
|
|
|
|
|
2016-10-24 15:26:53 +00:00
|
|
|
qemu_clock_step(2000000 + 1);
|
2016-09-22 17:13:07 +00:00
|
|
|
|
|
|
|
g_assert_cmpuint(ptimer_get_count(ptimer), ==, 0);
|
2016-10-24 15:26:51 +00:00
|
|
|
|
2016-10-24 15:26:52 +00:00
|
|
|
if (continuous_trigger || no_immediate_trigger) {
|
2016-10-24 15:26:51 +00:00
|
|
|
g_assert_true(triggered);
|
|
|
|
} else {
|
|
|
|
g_assert_false(triggered);
|
|
|
|
}
|
2016-09-22 17:13:07 +00:00
|
|
|
|
2016-10-24 15:26:51 +00:00
|
|
|
triggered = false;
|
|
|
|
|
|
|
|
ptimer_set_count(ptimer, 10);
|
|
|
|
ptimer_run(ptimer, 0);
|
|
|
|
|
2016-10-24 15:26:53 +00:00
|
|
|
qemu_clock_step(2000000 * 10 + 1);
|
2016-10-24 15:26:51 +00:00
|
|
|
|
|
|
|
g_assert_cmpuint(ptimer_get_count(ptimer), ==, 0);
|
|
|
|
g_assert_true(triggered);
|
|
|
|
|
|
|
|
triggered = false;
|
|
|
|
|
2016-10-24 15:26:53 +00:00
|
|
|
qemu_clock_step(2000000 + 1);
|
2016-10-24 15:26:51 +00:00
|
|
|
|
|
|
|
g_assert_cmpuint(ptimer_get_count(ptimer), ==, 0);
|
2016-10-24 15:26:51 +00:00
|
|
|
|
|
|
|
if (continuous_trigger) {
|
|
|
|
g_assert_true(triggered);
|
|
|
|
} else {
|
|
|
|
g_assert_false(triggered);
|
|
|
|
}
|
2016-10-24 15:26:51 +00:00
|
|
|
|
2016-09-22 17:13:07 +00:00
|
|
|
ptimer_stop(ptimer);
|
2017-01-27 08:55:51 +00:00
|
|
|
ptimer_free(ptimer);
|
2016-09-22 17:13:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
2016-10-24 15:26:52 +00:00
|
|
|
bool no_immediate_trigger = (*policy & PTIMER_POLICY_NO_IMMEDIATE_TRIGGER);
|
2018-07-09 13:51:34 +00:00
|
|
|
bool trig_only_on_dec = (*policy & PTIMER_POLICY_TRIGGER_ONLY_ON_DECREMENT);
|
2016-09-22 17:13:07 +00:00
|
|
|
|
|
|
|
triggered = false;
|
|
|
|
|
|
|
|
ptimer_set_period(ptimer, 2000000);
|
|
|
|
ptimer_run(ptimer, 1);
|
|
|
|
|
|
|
|
g_assert_cmpuint(ptimer_get_count(ptimer), ==, 0);
|
2016-10-24 15:26:52 +00:00
|
|
|
|
2018-07-09 13:51:34 +00:00
|
|
|
if (no_immediate_trigger || trig_only_on_dec) {
|
2016-10-24 15:26:52 +00:00
|
|
|
g_assert_false(triggered);
|
|
|
|
} else {
|
|
|
|
g_assert_true(triggered);
|
|
|
|
}
|
2016-09-22 17:13:07 +00:00
|
|
|
|
|
|
|
triggered = false;
|
|
|
|
|
2016-10-24 15:26:53 +00:00
|
|
|
qemu_clock_step(2000000 + 1);
|
2016-09-22 17:13:07 +00:00
|
|
|
|
|
|
|
g_assert_cmpuint(ptimer_get_count(ptimer), ==, 0);
|
2016-10-24 15:26:52 +00:00
|
|
|
|
|
|
|
if (no_immediate_trigger) {
|
|
|
|
g_assert_true(triggered);
|
|
|
|
} else {
|
|
|
|
g_assert_false(triggered);
|
|
|
|
}
|
2017-01-27 08:55:51 +00:00
|
|
|
|
|
|
|
ptimer_free(ptimer);
|
2016-09-22 17:13:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void add_ptimer_tests(uint8_t policy)
|
|
|
|
{
|
2017-01-27 08:55:51 +00:00
|
|
|
char policy_name[256] = "";
|
|
|
|
char *tmp;
|
2016-09-22 17:13:07 +00:00
|
|
|
|
|
|
|
if (policy == PTIMER_POLICY_DEFAULT) {
|
|
|
|
g_sprintf(policy_name, "default");
|
|
|
|
}
|
|
|
|
|
2016-10-24 15:26:51 +00:00
|
|
|
if (policy & PTIMER_POLICY_WRAP_AFTER_ONE_PERIOD) {
|
|
|
|
g_strlcat(policy_name, "wrap_after_one_period,", 256);
|
|
|
|
}
|
|
|
|
|
2016-10-24 15:26:51 +00:00
|
|
|
if (policy & PTIMER_POLICY_CONTINUOUS_TRIGGER) {
|
|
|
|
g_strlcat(policy_name, "continuous_trigger,", 256);
|
|
|
|
}
|
|
|
|
|
2016-10-24 15:26:52 +00:00
|
|
|
if (policy & PTIMER_POLICY_NO_IMMEDIATE_TRIGGER) {
|
|
|
|
g_strlcat(policy_name, "no_immediate_trigger,", 256);
|
|
|
|
}
|
|
|
|
|
2016-10-24 15:26:52 +00:00
|
|
|
if (policy & PTIMER_POLICY_NO_IMMEDIATE_RELOAD) {
|
|
|
|
g_strlcat(policy_name, "no_immediate_reload,", 256);
|
|
|
|
}
|
|
|
|
|
2016-10-24 15:26:53 +00:00
|
|
|
if (policy & PTIMER_POLICY_NO_COUNTER_ROUND_DOWN) {
|
|
|
|
g_strlcat(policy_name, "no_counter_rounddown,", 256);
|
|
|
|
}
|
|
|
|
|
2018-07-09 13:51:34 +00:00
|
|
|
if (policy & PTIMER_POLICY_TRIGGER_ONLY_ON_DECREMENT) {
|
|
|
|
g_strlcat(policy_name, "trigger_only_on_decrement,", 256);
|
|
|
|
}
|
|
|
|
|
2017-01-27 08:55:51 +00:00
|
|
|
g_test_add_data_func_full(
|
|
|
|
tmp = g_strdup_printf("/ptimer/set_count policy=%s", policy_name),
|
|
|
|
g_memdup(&policy, 1), check_set_count, g_free);
|
|
|
|
g_free(tmp);
|
|
|
|
|
|
|
|
g_test_add_data_func_full(
|
|
|
|
tmp = g_strdup_printf("/ptimer/set_limit policy=%s", policy_name),
|
|
|
|
g_memdup(&policy, 1), check_set_limit, g_free);
|
|
|
|
g_free(tmp);
|
|
|
|
|
|
|
|
g_test_add_data_func_full(
|
|
|
|
tmp = g_strdup_printf("/ptimer/oneshot policy=%s", policy_name),
|
|
|
|
g_memdup(&policy, 1), check_oneshot, g_free);
|
|
|
|
g_free(tmp);
|
|
|
|
|
|
|
|
g_test_add_data_func_full(
|
|
|
|
tmp = g_strdup_printf("/ptimer/periodic policy=%s", policy_name),
|
|
|
|
g_memdup(&policy, 1), check_periodic, g_free);
|
|
|
|
g_free(tmp);
|
|
|
|
|
|
|
|
g_test_add_data_func_full(
|
|
|
|
tmp = g_strdup_printf("/ptimer/on_the_fly_mode_change policy=%s",
|
|
|
|
policy_name),
|
|
|
|
g_memdup(&policy, 1), check_on_the_fly_mode_change, g_free);
|
|
|
|
g_free(tmp);
|
|
|
|
|
|
|
|
g_test_add_data_func_full(
|
|
|
|
tmp = g_strdup_printf("/ptimer/on_the_fly_period_change policy=%s",
|
|
|
|
policy_name),
|
|
|
|
g_memdup(&policy, 1), check_on_the_fly_period_change, g_free);
|
|
|
|
g_free(tmp);
|
|
|
|
|
|
|
|
g_test_add_data_func_full(
|
|
|
|
tmp = g_strdup_printf("/ptimer/on_the_fly_freq_change policy=%s",
|
|
|
|
policy_name),
|
|
|
|
g_memdup(&policy, 1), check_on_the_fly_freq_change, g_free);
|
|
|
|
g_free(tmp);
|
|
|
|
|
|
|
|
g_test_add_data_func_full(
|
|
|
|
tmp = g_strdup_printf("/ptimer/run_with_period_0 policy=%s",
|
|
|
|
policy_name),
|
|
|
|
g_memdup(&policy, 1), check_run_with_period_0, g_free);
|
|
|
|
g_free(tmp);
|
|
|
|
|
|
|
|
g_test_add_data_func_full(
|
|
|
|
tmp = g_strdup_printf("/ptimer/run_with_delta_0 policy=%s",
|
|
|
|
policy_name),
|
|
|
|
g_memdup(&policy, 1), check_run_with_delta_0, g_free);
|
|
|
|
g_free(tmp);
|
|
|
|
|
|
|
|
g_test_add_data_func_full(
|
|
|
|
tmp = g_strdup_printf("/ptimer/periodic_with_load_0 policy=%s",
|
|
|
|
policy_name),
|
|
|
|
g_memdup(&policy, 1), check_periodic_with_load_0, g_free);
|
|
|
|
g_free(tmp);
|
|
|
|
|
|
|
|
g_test_add_data_func_full(
|
|
|
|
tmp = g_strdup_printf("/ptimer/oneshot_with_load_0 policy=%s",
|
|
|
|
policy_name),
|
|
|
|
g_memdup(&policy, 1), check_oneshot_with_load_0, g_free);
|
|
|
|
g_free(tmp);
|
2016-09-22 17:13:07 +00:00
|
|
|
}
|
|
|
|
|
2016-10-24 15:26:51 +00:00
|
|
|
static void add_all_ptimer_policies_comb_tests(void)
|
|
|
|
{
|
2018-07-09 13:51:34 +00:00
|
|
|
int last_policy = PTIMER_POLICY_TRIGGER_ONLY_ON_DECREMENT;
|
2016-10-24 15:26:51 +00:00
|
|
|
int policy = PTIMER_POLICY_DEFAULT;
|
|
|
|
|
|
|
|
for (; policy < (last_policy << 1); policy++) {
|
2018-07-09 13:51:34 +00:00
|
|
|
if ((policy & PTIMER_POLICY_TRIGGER_ONLY_ON_DECREMENT) &&
|
|
|
|
(policy & PTIMER_POLICY_NO_IMMEDIATE_TRIGGER)) {
|
|
|
|
/* Incompatible policy flag settings -- don't try to test them */
|
|
|
|
continue;
|
|
|
|
}
|
2016-10-24 15:26:51 +00:00
|
|
|
add_ptimer_tests(policy);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-09-22 17:13:07 +00:00
|
|
|
int main(int argc, char **argv)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
g_test_init(&argc, &argv, NULL);
|
|
|
|
|
|
|
|
for (i = 0; i < QEMU_CLOCK_MAX; i++) {
|
|
|
|
main_loop_tlg.tl[i] = g_new0(QEMUTimerList, 1);
|
|
|
|
}
|
|
|
|
|
2016-10-24 15:26:51 +00:00
|
|
|
add_all_ptimer_policies_comb_tests();
|
2016-09-22 17:13:07 +00:00
|
|
|
|
|
|
|
qtest_allowed = true;
|
|
|
|
|
|
|
|
return g_test_run();
|
|
|
|
}
|