2 * QTest testcase for the ptimer
4 * Copyright (c) 2016 Dmitry Osipenko <digetx@gmail.com>
6 * This work is licensed under the terms of the GNU GPL, version 2 or later.
7 * See the COPYING file in the top-level directory.
11 #include "qemu/osdep.h"
12 #include <glib/gprintf.h>
14 #include "qemu/main-loop.h"
15 #include "hw/ptimer.h"
18 #include "ptimer-test.h"
20 static bool triggered
;
22 static void ptimer_trigger(void *opaque
)
27 static void ptimer_test_expire_qemu_timers(int64_t expire_time
,
30 QEMUTimerList
*timer_list
= main_loop_tlg
.tl
[type
];
31 QEMUTimer
*t
= timer_list
->active_timers
.next
;
34 if (t
->expire_time
== expire_time
) {
46 static void ptimer_test_set_qemu_time_ns(int64_t ns
)
48 ptimer_test_time_ns
= ns
;
51 static void qemu_clock_step(uint64_t ns
)
53 int64_t deadline
= qemu_clock_deadline_ns_all(QEMU_CLOCK_VIRTUAL
,
55 int64_t advanced_time
= qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL
) + ns
;
57 while (deadline
!= -1 && deadline
<= advanced_time
) {
58 ptimer_test_set_qemu_time_ns(deadline
);
59 ptimer_test_expire_qemu_timers(deadline
, QEMU_CLOCK_VIRTUAL
);
60 deadline
= qemu_clock_deadline_ns_all(QEMU_CLOCK_VIRTUAL
,
64 ptimer_test_set_qemu_time_ns(advanced_time
);
67 static void check_set_count(gconstpointer arg
)
69 const uint8_t *policy
= arg
;
70 QEMUBH
*bh
= qemu_bh_new(ptimer_trigger
, NULL
);
71 ptimer_state
*ptimer
= ptimer_init(bh
, *policy
);
75 ptimer_set_count(ptimer
, 1000);
76 g_assert_cmpuint(ptimer_get_count(ptimer
), ==, 1000);
77 g_assert_false(triggered
);
81 static void check_set_limit(gconstpointer arg
)
83 const uint8_t *policy
= arg
;
84 QEMUBH
*bh
= qemu_bh_new(ptimer_trigger
, NULL
);
85 ptimer_state
*ptimer
= ptimer_init(bh
, *policy
);
89 ptimer_set_limit(ptimer
, 1000, 0);
90 g_assert_cmpuint(ptimer_get_count(ptimer
), ==, 0);
91 g_assert_cmpuint(ptimer_get_limit(ptimer
), ==, 1000);
92 g_assert_false(triggered
);
94 ptimer_set_limit(ptimer
, 2000, 1);
95 g_assert_cmpuint(ptimer_get_count(ptimer
), ==, 2000);
96 g_assert_cmpuint(ptimer_get_limit(ptimer
), ==, 2000);
97 g_assert_false(triggered
);
101 static void check_oneshot(gconstpointer arg
)
103 const uint8_t *policy
= arg
;
104 QEMUBH
*bh
= qemu_bh_new(ptimer_trigger
, NULL
);
105 ptimer_state
*ptimer
= ptimer_init(bh
, *policy
);
106 bool no_round_down
= (*policy
& PTIMER_POLICY_NO_COUNTER_ROUND_DOWN
);
110 ptimer_set_period(ptimer
, 2000000);
111 ptimer_set_count(ptimer
, 10);
112 ptimer_run(ptimer
, 1);
114 qemu_clock_step(2000000 * 2 + 1);
116 g_assert_cmpuint(ptimer_get_count(ptimer
), ==, no_round_down
? 8 : 7);
117 g_assert_false(triggered
);
121 g_assert_cmpuint(ptimer_get_count(ptimer
), ==, no_round_down
? 8 : 7);
122 g_assert_false(triggered
);
124 qemu_clock_step(2000000 * 11);
126 g_assert_cmpuint(ptimer_get_count(ptimer
), ==, no_round_down
? 8 : 7);
127 g_assert_false(triggered
);
129 ptimer_run(ptimer
, 1);
131 qemu_clock_step(2000000 * 7 + 1);
133 g_assert_cmpuint(ptimer_get_count(ptimer
), ==, no_round_down
? 1 : 0);
136 g_assert_false(triggered
);
138 g_assert_true(triggered
);
143 qemu_clock_step(2000000);
145 g_assert_cmpuint(ptimer_get_count(ptimer
), ==, 0);
148 g_assert_true(triggered
);
152 g_assert_false(triggered
);
155 qemu_clock_step(4000000);
157 g_assert_cmpuint(ptimer_get_count(ptimer
), ==, 0);
158 g_assert_false(triggered
);
160 ptimer_set_count(ptimer
, 10);
162 qemu_clock_step(20000000 + 1);
164 g_assert_cmpuint(ptimer_get_count(ptimer
), ==, 10);
165 g_assert_false(triggered
);
167 ptimer_set_limit(ptimer
, 9, 1);
169 qemu_clock_step(20000000 + 1);
171 g_assert_cmpuint(ptimer_get_count(ptimer
), ==, 9);
172 g_assert_false(triggered
);
174 ptimer_run(ptimer
, 1);
176 qemu_clock_step(2000000 + 1);
178 g_assert_cmpuint(ptimer_get_count(ptimer
), ==, no_round_down
? 8 : 7);
179 g_assert_false(triggered
);
181 ptimer_set_count(ptimer
, 20);
183 qemu_clock_step(2000000 * 19 + 1);
185 g_assert_cmpuint(ptimer_get_count(ptimer
), ==, no_round_down
? 1 : 0);
186 g_assert_false(triggered
);
188 qemu_clock_step(2000000);
190 g_assert_cmpuint(ptimer_get_count(ptimer
), ==, 0);
191 g_assert_true(triggered
);
197 qemu_clock_step(2000000 * 12 + 1);
199 g_assert_cmpuint(ptimer_get_count(ptimer
), ==, 0);
200 g_assert_false(triggered
);
204 static void check_periodic(gconstpointer arg
)
206 const uint8_t *policy
= arg
;
207 QEMUBH
*bh
= qemu_bh_new(ptimer_trigger
, NULL
);
208 ptimer_state
*ptimer
= ptimer_init(bh
, *policy
);
209 bool wrap_policy
= (*policy
& PTIMER_POLICY_WRAP_AFTER_ONE_PERIOD
);
210 bool no_immediate_trigger
= (*policy
& PTIMER_POLICY_NO_IMMEDIATE_TRIGGER
);
211 bool no_immediate_reload
= (*policy
& PTIMER_POLICY_NO_IMMEDIATE_RELOAD
);
212 bool no_round_down
= (*policy
& PTIMER_POLICY_NO_COUNTER_ROUND_DOWN
);
213 bool trig_only_on_dec
= (*policy
& PTIMER_POLICY_TRIGGER_ONLY_ON_DECREMENT
);
217 ptimer_set_period(ptimer
, 2000000);
218 ptimer_set_limit(ptimer
, 10, 1);
219 ptimer_run(ptimer
, 0);
221 g_assert_cmpuint(ptimer_get_count(ptimer
), ==, 10);
222 g_assert_false(triggered
);
226 g_assert_cmpuint(ptimer_get_count(ptimer
), ==, no_round_down
? 10 : 9);
227 g_assert_false(triggered
);
229 qemu_clock_step(2000000 * 10 - 1);
231 g_assert_cmpuint(ptimer_get_count(ptimer
), ==, wrap_policy
? 0 : 10);
232 g_assert_true(triggered
);
236 g_assert_cmpuint(ptimer_get_count(ptimer
), ==,
237 wrap_policy
? 0 : (no_round_down
? 10 : 9));
238 g_assert_true(triggered
);
242 qemu_clock_step(2000000);
244 g_assert_cmpuint(ptimer_get_count(ptimer
), ==,
245 (no_round_down
? 9 : 8) + (wrap_policy
? 1 : 0));
246 g_assert_false(triggered
);
248 ptimer_set_count(ptimer
, 20);
250 g_assert_cmpuint(ptimer_get_count(ptimer
), ==, 20);
251 g_assert_false(triggered
);
255 g_assert_cmpuint(ptimer_get_count(ptimer
), ==, no_round_down
? 20 : 19);
256 g_assert_false(triggered
);
258 qemu_clock_step(2000000 * 11 + 1);
260 g_assert_cmpuint(ptimer_get_count(ptimer
), ==, no_round_down
? 9 : 8);
261 g_assert_false(triggered
);
263 qemu_clock_step(2000000 * 10);
265 g_assert_cmpuint(ptimer_get_count(ptimer
), ==,
266 (no_round_down
? 9 : 8) + (wrap_policy
? 1 : 0));
267 g_assert_true(triggered
);
271 ptimer_set_count(ptimer
, 3);
273 g_assert_cmpuint(ptimer_get_count(ptimer
), ==, 3);
274 g_assert_false(triggered
);
278 g_assert_cmpuint(ptimer_get_count(ptimer
), ==, no_round_down
? 3 : 2);
279 g_assert_false(triggered
);
281 qemu_clock_step(2000000 * 4);
283 g_assert_cmpuint(ptimer_get_count(ptimer
), ==,
284 (no_round_down
? 9 : 8) + (wrap_policy
? 1 : 0));
285 g_assert_true(triggered
);
290 qemu_clock_step(2000000);
292 g_assert_cmpuint(ptimer_get_count(ptimer
), ==,
293 (no_round_down
? 9 : 8) + (wrap_policy
? 1 : 0));
294 g_assert_false(triggered
);
296 ptimer_set_count(ptimer
, 3);
297 ptimer_run(ptimer
, 0);
299 qemu_clock_step(2000000 * 3 + 1);
301 g_assert_cmpuint(ptimer_get_count(ptimer
), ==,
302 wrap_policy
? 0 : (no_round_down
? 10 : 9));
303 g_assert_true(triggered
);
307 qemu_clock_step(2000000);
309 g_assert_cmpuint(ptimer_get_count(ptimer
), ==,
310 (no_round_down
? 9 : 8) + (wrap_policy
? 1 : 0));
311 g_assert_false(triggered
);
313 ptimer_set_count(ptimer
, 0);
314 g_assert_cmpuint(ptimer_get_count(ptimer
), ==,
315 no_immediate_reload
? 0 : 10);
317 if (no_immediate_trigger
|| trig_only_on_dec
) {
318 g_assert_false(triggered
);
320 g_assert_true(triggered
);
327 if (no_immediate_reload
) {
328 g_assert_cmpuint(ptimer_get_count(ptimer
), ==, 0);
329 g_assert_false(triggered
);
331 qemu_clock_step(2000000);
333 if (no_immediate_trigger
) {
334 g_assert_true(triggered
);
336 g_assert_false(triggered
);
342 g_assert_cmpuint(ptimer_get_count(ptimer
), ==, no_round_down
? 10 : 9);
343 g_assert_false(triggered
);
345 qemu_clock_step(2000000 * 12);
347 g_assert_cmpuint(ptimer_get_count(ptimer
), ==,
348 (no_round_down
? 8 : 7) + (wrap_policy
? 1 : 0));
349 g_assert_true(triggered
);
355 qemu_clock_step(2000000 * 10);
357 g_assert_cmpuint(ptimer_get_count(ptimer
), ==,
358 (no_round_down
? 8 : 7) + (wrap_policy
? 1 : 0));
359 g_assert_false(triggered
);
361 ptimer_run(ptimer
, 0);
362 ptimer_set_period(ptimer
, 0);
364 qemu_clock_step(2000000 + 1);
366 g_assert_cmpuint(ptimer_get_count(ptimer
), ==,
367 (no_round_down
? 8 : 7) + (wrap_policy
? 1 : 0));
368 g_assert_false(triggered
);
372 static void check_on_the_fly_mode_change(gconstpointer arg
)
374 const uint8_t *policy
= arg
;
375 QEMUBH
*bh
= qemu_bh_new(ptimer_trigger
, NULL
);
376 ptimer_state
*ptimer
= ptimer_init(bh
, *policy
);
377 bool wrap_policy
= (*policy
& PTIMER_POLICY_WRAP_AFTER_ONE_PERIOD
);
378 bool no_round_down
= (*policy
& PTIMER_POLICY_NO_COUNTER_ROUND_DOWN
);
382 ptimer_set_period(ptimer
, 2000000);
383 ptimer_set_limit(ptimer
, 10, 1);
384 ptimer_run(ptimer
, 1);
386 qemu_clock_step(2000000 * 9 + 1);
388 g_assert_cmpuint(ptimer_get_count(ptimer
), ==, no_round_down
? 1 : 0);
389 g_assert_false(triggered
);
391 ptimer_run(ptimer
, 0);
393 g_assert_cmpuint(ptimer_get_count(ptimer
), ==, no_round_down
? 1 : 0);
394 g_assert_false(triggered
);
396 qemu_clock_step(2000000);
398 g_assert_cmpuint(ptimer_get_count(ptimer
), ==,
399 wrap_policy
? 0 : (no_round_down
? 10 : 9));
400 g_assert_true(triggered
);
404 qemu_clock_step(2000000 * 9);
406 ptimer_run(ptimer
, 1);
408 g_assert_cmpuint(ptimer_get_count(ptimer
), ==,
409 (no_round_down
? 1 : 0) + (wrap_policy
? 1 : 0));
410 g_assert_false(triggered
);
412 qemu_clock_step(2000000 * 3);
414 g_assert_cmpuint(ptimer_get_count(ptimer
), ==, 0);
415 g_assert_true(triggered
);
419 static void check_on_the_fly_period_change(gconstpointer arg
)
421 const uint8_t *policy
= arg
;
422 QEMUBH
*bh
= qemu_bh_new(ptimer_trigger
, NULL
);
423 ptimer_state
*ptimer
= ptimer_init(bh
, *policy
);
424 bool no_round_down
= (*policy
& PTIMER_POLICY_NO_COUNTER_ROUND_DOWN
);
428 ptimer_set_period(ptimer
, 2000000);
429 ptimer_set_limit(ptimer
, 8, 1);
430 ptimer_run(ptimer
, 1);
432 qemu_clock_step(2000000 * 4 + 1);
434 g_assert_cmpuint(ptimer_get_count(ptimer
), ==, no_round_down
? 4 : 3);
435 g_assert_false(triggered
);
437 ptimer_set_period(ptimer
, 4000000);
438 g_assert_cmpuint(ptimer_get_count(ptimer
), ==, no_round_down
? 4 : 3);
440 qemu_clock_step(4000000 * 2 + 1);
442 g_assert_cmpuint(ptimer_get_count(ptimer
), ==, no_round_down
? 2 : 0);
443 g_assert_false(triggered
);
445 qemu_clock_step(4000000 * 2);
447 g_assert_cmpuint(ptimer_get_count(ptimer
), ==, 0);
448 g_assert_true(triggered
);
452 static void check_on_the_fly_freq_change(gconstpointer arg
)
454 const uint8_t *policy
= arg
;
455 QEMUBH
*bh
= qemu_bh_new(ptimer_trigger
, NULL
);
456 ptimer_state
*ptimer
= ptimer_init(bh
, *policy
);
457 bool no_round_down
= (*policy
& PTIMER_POLICY_NO_COUNTER_ROUND_DOWN
);
461 ptimer_set_freq(ptimer
, 500);
462 ptimer_set_limit(ptimer
, 8, 1);
463 ptimer_run(ptimer
, 1);
465 qemu_clock_step(2000000 * 4 + 1);
467 g_assert_cmpuint(ptimer_get_count(ptimer
), ==, no_round_down
? 4 : 3);
468 g_assert_false(triggered
);
470 ptimer_set_freq(ptimer
, 250);
471 g_assert_cmpuint(ptimer_get_count(ptimer
), ==, no_round_down
? 4 : 3);
473 qemu_clock_step(2000000 * 4 + 1);
475 g_assert_cmpuint(ptimer_get_count(ptimer
), ==, no_round_down
? 2 : 0);
476 g_assert_false(triggered
);
478 qemu_clock_step(2000000 * 4);
480 g_assert_cmpuint(ptimer_get_count(ptimer
), ==, 0);
481 g_assert_true(triggered
);
485 static void check_run_with_period_0(gconstpointer arg
)
487 const uint8_t *policy
= arg
;
488 QEMUBH
*bh
= qemu_bh_new(ptimer_trigger
, NULL
);
489 ptimer_state
*ptimer
= ptimer_init(bh
, *policy
);
493 ptimer_set_count(ptimer
, 99);
494 ptimer_run(ptimer
, 1);
496 qemu_clock_step(10 * NANOSECONDS_PER_SECOND
);
498 g_assert_cmpuint(ptimer_get_count(ptimer
), ==, 99);
499 g_assert_false(triggered
);
503 static void check_run_with_delta_0(gconstpointer arg
)
505 const uint8_t *policy
= arg
;
506 QEMUBH
*bh
= qemu_bh_new(ptimer_trigger
, NULL
);
507 ptimer_state
*ptimer
= ptimer_init(bh
, *policy
);
508 bool wrap_policy
= (*policy
& PTIMER_POLICY_WRAP_AFTER_ONE_PERIOD
);
509 bool no_immediate_trigger
= (*policy
& PTIMER_POLICY_NO_IMMEDIATE_TRIGGER
);
510 bool no_immediate_reload
= (*policy
& PTIMER_POLICY_NO_IMMEDIATE_RELOAD
);
511 bool no_round_down
= (*policy
& PTIMER_POLICY_NO_COUNTER_ROUND_DOWN
);
512 bool trig_only_on_dec
= (*policy
& PTIMER_POLICY_TRIGGER_ONLY_ON_DECREMENT
);
516 ptimer_set_period(ptimer
, 2000000);
517 ptimer_set_limit(ptimer
, 99, 0);
518 ptimer_run(ptimer
, 1);
519 g_assert_cmpuint(ptimer_get_count(ptimer
), ==,
520 no_immediate_reload
? 0 : 99);
522 if (no_immediate_trigger
|| trig_only_on_dec
) {
523 g_assert_false(triggered
);
525 g_assert_true(triggered
);
530 if (no_immediate_trigger
|| no_immediate_reload
) {
531 qemu_clock_step(2000000 + 1);
533 g_assert_cmpuint(ptimer_get_count(ptimer
), ==,
534 no_immediate_reload
? 0 : (no_round_down
? 98 : 97));
536 if (no_immediate_trigger
&& no_immediate_reload
) {
537 g_assert_true(triggered
);
541 g_assert_false(triggered
);
544 ptimer_set_count(ptimer
, 99);
545 ptimer_run(ptimer
, 1);
548 qemu_clock_step(2000000 + 1);
550 g_assert_cmpuint(ptimer_get_count(ptimer
), ==, no_round_down
? 98 : 97);
551 g_assert_false(triggered
);
553 qemu_clock_step(2000000 * 97);
555 g_assert_cmpuint(ptimer_get_count(ptimer
), ==, no_round_down
? 1 : 0);
556 g_assert_false(triggered
);
558 qemu_clock_step(2000000 * 2);
560 g_assert_cmpuint(ptimer_get_count(ptimer
), ==, 0);
561 g_assert_true(triggered
);
565 ptimer_set_count(ptimer
, 0);
566 ptimer_run(ptimer
, 0);
567 g_assert_cmpuint(ptimer_get_count(ptimer
), ==,
568 no_immediate_reload
? 0 : 99);
570 if (no_immediate_trigger
|| trig_only_on_dec
) {
571 g_assert_false(triggered
);
573 g_assert_true(triggered
);
580 if (no_immediate_reload
) {
581 qemu_clock_step(2000000);
584 g_assert_cmpuint(ptimer_get_count(ptimer
), ==, no_round_down
? 99 : 98);
586 if (no_immediate_reload
&& no_immediate_trigger
) {
587 g_assert_true(triggered
);
589 g_assert_false(triggered
);
594 qemu_clock_step(2000000);
596 g_assert_cmpuint(ptimer_get_count(ptimer
), ==, no_round_down
? 98 : 97);
597 g_assert_false(triggered
);
599 qemu_clock_step(2000000 * 98);
601 g_assert_cmpuint(ptimer_get_count(ptimer
), ==,
602 wrap_policy
? 0 : (no_round_down
? 99 : 98));
603 g_assert_true(triggered
);
609 static void check_periodic_with_load_0(gconstpointer arg
)
611 const uint8_t *policy
= arg
;
612 QEMUBH
*bh
= qemu_bh_new(ptimer_trigger
, NULL
);
613 ptimer_state
*ptimer
= ptimer_init(bh
, *policy
);
614 bool continuous_trigger
= (*policy
& PTIMER_POLICY_CONTINUOUS_TRIGGER
);
615 bool no_immediate_trigger
= (*policy
& PTIMER_POLICY_NO_IMMEDIATE_TRIGGER
);
616 bool trig_only_on_dec
= (*policy
& PTIMER_POLICY_TRIGGER_ONLY_ON_DECREMENT
);
620 ptimer_set_period(ptimer
, 2000000);
621 ptimer_run(ptimer
, 0);
623 g_assert_cmpuint(ptimer_get_count(ptimer
), ==, 0);
625 if (no_immediate_trigger
|| trig_only_on_dec
) {
626 g_assert_false(triggered
);
628 g_assert_true(triggered
);
633 qemu_clock_step(2000000 + 1);
635 g_assert_cmpuint(ptimer_get_count(ptimer
), ==, 0);
637 if (continuous_trigger
|| no_immediate_trigger
) {
638 g_assert_true(triggered
);
640 g_assert_false(triggered
);
645 ptimer_set_count(ptimer
, 10);
646 ptimer_run(ptimer
, 0);
648 qemu_clock_step(2000000 * 10 + 1);
650 g_assert_cmpuint(ptimer_get_count(ptimer
), ==, 0);
651 g_assert_true(triggered
);
655 qemu_clock_step(2000000 + 1);
657 g_assert_cmpuint(ptimer_get_count(ptimer
), ==, 0);
659 if (continuous_trigger
) {
660 g_assert_true(triggered
);
662 g_assert_false(triggered
);
669 static void check_oneshot_with_load_0(gconstpointer arg
)
671 const uint8_t *policy
= arg
;
672 QEMUBH
*bh
= qemu_bh_new(ptimer_trigger
, NULL
);
673 ptimer_state
*ptimer
= ptimer_init(bh
, *policy
);
674 bool no_immediate_trigger
= (*policy
& PTIMER_POLICY_NO_IMMEDIATE_TRIGGER
);
675 bool trig_only_on_dec
= (*policy
& PTIMER_POLICY_TRIGGER_ONLY_ON_DECREMENT
);
679 ptimer_set_period(ptimer
, 2000000);
680 ptimer_run(ptimer
, 1);
682 g_assert_cmpuint(ptimer_get_count(ptimer
), ==, 0);
684 if (no_immediate_trigger
|| trig_only_on_dec
) {
685 g_assert_false(triggered
);
687 g_assert_true(triggered
);
692 qemu_clock_step(2000000 + 1);
694 g_assert_cmpuint(ptimer_get_count(ptimer
), ==, 0);
696 if (no_immediate_trigger
) {
697 g_assert_true(triggered
);
699 g_assert_false(triggered
);
705 static void add_ptimer_tests(uint8_t policy
)
707 char policy_name
[256] = "";
710 if (policy
== PTIMER_POLICY_DEFAULT
) {
711 g_sprintf(policy_name
, "default");
714 if (policy
& PTIMER_POLICY_WRAP_AFTER_ONE_PERIOD
) {
715 g_strlcat(policy_name
, "wrap_after_one_period,", 256);
718 if (policy
& PTIMER_POLICY_CONTINUOUS_TRIGGER
) {
719 g_strlcat(policy_name
, "continuous_trigger,", 256);
722 if (policy
& PTIMER_POLICY_NO_IMMEDIATE_TRIGGER
) {
723 g_strlcat(policy_name
, "no_immediate_trigger,", 256);
726 if (policy
& PTIMER_POLICY_NO_IMMEDIATE_RELOAD
) {
727 g_strlcat(policy_name
, "no_immediate_reload,", 256);
730 if (policy
& PTIMER_POLICY_NO_COUNTER_ROUND_DOWN
) {
731 g_strlcat(policy_name
, "no_counter_rounddown,", 256);
734 if (policy
& PTIMER_POLICY_TRIGGER_ONLY_ON_DECREMENT
) {
735 g_strlcat(policy_name
, "trigger_only_on_decrement,", 256);
738 g_test_add_data_func_full(
739 tmp
= g_strdup_printf("/ptimer/set_count policy=%s", policy_name
),
740 g_memdup(&policy
, 1), check_set_count
, g_free
);
743 g_test_add_data_func_full(
744 tmp
= g_strdup_printf("/ptimer/set_limit policy=%s", policy_name
),
745 g_memdup(&policy
, 1), check_set_limit
, g_free
);
748 g_test_add_data_func_full(
749 tmp
= g_strdup_printf("/ptimer/oneshot policy=%s", policy_name
),
750 g_memdup(&policy
, 1), check_oneshot
, g_free
);
753 g_test_add_data_func_full(
754 tmp
= g_strdup_printf("/ptimer/periodic policy=%s", policy_name
),
755 g_memdup(&policy
, 1), check_periodic
, g_free
);
758 g_test_add_data_func_full(
759 tmp
= g_strdup_printf("/ptimer/on_the_fly_mode_change policy=%s",
761 g_memdup(&policy
, 1), check_on_the_fly_mode_change
, g_free
);
764 g_test_add_data_func_full(
765 tmp
= g_strdup_printf("/ptimer/on_the_fly_period_change policy=%s",
767 g_memdup(&policy
, 1), check_on_the_fly_period_change
, g_free
);
770 g_test_add_data_func_full(
771 tmp
= g_strdup_printf("/ptimer/on_the_fly_freq_change policy=%s",
773 g_memdup(&policy
, 1), check_on_the_fly_freq_change
, g_free
);
776 g_test_add_data_func_full(
777 tmp
= g_strdup_printf("/ptimer/run_with_period_0 policy=%s",
779 g_memdup(&policy
, 1), check_run_with_period_0
, g_free
);
782 g_test_add_data_func_full(
783 tmp
= g_strdup_printf("/ptimer/run_with_delta_0 policy=%s",
785 g_memdup(&policy
, 1), check_run_with_delta_0
, g_free
);
788 g_test_add_data_func_full(
789 tmp
= g_strdup_printf("/ptimer/periodic_with_load_0 policy=%s",
791 g_memdup(&policy
, 1), check_periodic_with_load_0
, g_free
);
794 g_test_add_data_func_full(
795 tmp
= g_strdup_printf("/ptimer/oneshot_with_load_0 policy=%s",
797 g_memdup(&policy
, 1), check_oneshot_with_load_0
, g_free
);
801 static void add_all_ptimer_policies_comb_tests(void)
803 int last_policy
= PTIMER_POLICY_TRIGGER_ONLY_ON_DECREMENT
;
804 int policy
= PTIMER_POLICY_DEFAULT
;
806 for (; policy
< (last_policy
<< 1); policy
++) {
807 if ((policy
& PTIMER_POLICY_TRIGGER_ONLY_ON_DECREMENT
) &&
808 (policy
& PTIMER_POLICY_NO_IMMEDIATE_TRIGGER
)) {
809 /* Incompatible policy flag settings -- don't try to test them */
812 add_ptimer_tests(policy
);
816 int main(int argc
, char **argv
)
820 g_test_init(&argc
, &argv
, NULL
);
822 for (i
= 0; i
< QEMU_CLOCK_MAX
; i
++) {
823 main_loop_tlg
.tl
[i
] = g_new0(QEMUTimerList
, 1);
826 add_all_ptimer_policies_comb_tests();
828 qtest_allowed
= true;