sysemu: support up to 1024 vCPUs
[qemu/ar7.git] / tests / ptimer-test.c
blobb36a4764839e7012e78982ecd6cf12f7388ce1a9
1 /*
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.
9 */
11 #include <glib/gprintf.h>
13 #include "qemu/osdep.h"
14 #include "qemu/main-loop.h"
15 #include "hw/ptimer.h"
17 #include "libqtest.h"
18 #include "ptimer-test.h"
20 static bool triggered;
22 static void ptimer_trigger(void *opaque)
24 triggered = true;
27 static void ptimer_test_expire_qemu_timers(int64_t expire_time,
28 QEMUClockType type)
30 QEMUTimerList *timer_list = main_loop_tlg.tl[type];
31 QEMUTimer *t = timer_list->active_timers.next;
33 while (t != NULL) {
34 if (t->expire_time == expire_time) {
35 timer_del(t);
37 if (t->cb != NULL) {
38 t->cb(t->opaque);
42 t = t->next;
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);
54 int64_t advanced_time = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL) + ns;
56 while (deadline != -1 && deadline <= advanced_time) {
57 ptimer_test_set_qemu_time_ns(deadline);
58 ptimer_test_expire_qemu_timers(deadline, QEMU_CLOCK_VIRTUAL);
59 deadline = qemu_clock_deadline_ns_all(QEMU_CLOCK_VIRTUAL);
62 ptimer_test_set_qemu_time_ns(advanced_time);
65 static void check_set_count(gconstpointer arg)
67 const uint8_t *policy = arg;
68 QEMUBH *bh = qemu_bh_new(ptimer_trigger, NULL);
69 ptimer_state *ptimer = ptimer_init(bh, *policy);
71 triggered = false;
73 ptimer_set_count(ptimer, 1000);
74 g_assert_cmpuint(ptimer_get_count(ptimer), ==, 1000);
75 g_assert_false(triggered);
78 static void check_set_limit(gconstpointer arg)
80 const uint8_t *policy = arg;
81 QEMUBH *bh = qemu_bh_new(ptimer_trigger, NULL);
82 ptimer_state *ptimer = ptimer_init(bh, *policy);
84 triggered = false;
86 ptimer_set_limit(ptimer, 1000, 0);
87 g_assert_cmpuint(ptimer_get_count(ptimer), ==, 0);
88 g_assert_cmpuint(ptimer_get_limit(ptimer), ==, 1000);
89 g_assert_false(triggered);
91 ptimer_set_limit(ptimer, 2000, 1);
92 g_assert_cmpuint(ptimer_get_count(ptimer), ==, 2000);
93 g_assert_cmpuint(ptimer_get_limit(ptimer), ==, 2000);
94 g_assert_false(triggered);
97 static void check_oneshot(gconstpointer arg)
99 const uint8_t *policy = arg;
100 QEMUBH *bh = qemu_bh_new(ptimer_trigger, NULL);
101 ptimer_state *ptimer = ptimer_init(bh, *policy);
102 bool no_round_down = (*policy & PTIMER_POLICY_NO_COUNTER_ROUND_DOWN);
104 triggered = false;
106 ptimer_set_period(ptimer, 2000000);
107 ptimer_set_count(ptimer, 10);
108 ptimer_run(ptimer, 1);
110 qemu_clock_step(2000000 * 2 + 1);
112 g_assert_cmpuint(ptimer_get_count(ptimer), ==, no_round_down ? 8 : 7);
113 g_assert_false(triggered);
115 ptimer_stop(ptimer);
117 g_assert_cmpuint(ptimer_get_count(ptimer), ==, no_round_down ? 8 : 7);
118 g_assert_false(triggered);
120 qemu_clock_step(2000000 * 11);
122 g_assert_cmpuint(ptimer_get_count(ptimer), ==, no_round_down ? 8 : 7);
123 g_assert_false(triggered);
125 ptimer_run(ptimer, 1);
127 qemu_clock_step(2000000 * 7 + 1);
129 g_assert_cmpuint(ptimer_get_count(ptimer), ==, no_round_down ? 1 : 0);
131 if (no_round_down) {
132 g_assert_false(triggered);
133 } else {
134 g_assert_true(triggered);
136 triggered = false;
139 qemu_clock_step(2000000);
141 g_assert_cmpuint(ptimer_get_count(ptimer), ==, 0);
143 if (no_round_down) {
144 g_assert_true(triggered);
146 triggered = false;
147 } else {
148 g_assert_false(triggered);
151 qemu_clock_step(4000000);
153 g_assert_cmpuint(ptimer_get_count(ptimer), ==, 0);
154 g_assert_false(triggered);
156 ptimer_set_count(ptimer, 10);
158 qemu_clock_step(20000000 + 1);
160 g_assert_cmpuint(ptimer_get_count(ptimer), ==, 10);
161 g_assert_false(triggered);
163 ptimer_set_limit(ptimer, 9, 1);
165 qemu_clock_step(20000000 + 1);
167 g_assert_cmpuint(ptimer_get_count(ptimer), ==, 9);
168 g_assert_false(triggered);
170 ptimer_run(ptimer, 1);
172 qemu_clock_step(2000000 + 1);
174 g_assert_cmpuint(ptimer_get_count(ptimer), ==, no_round_down ? 8 : 7);
175 g_assert_false(triggered);
177 ptimer_set_count(ptimer, 20);
179 qemu_clock_step(2000000 * 19 + 1);
181 g_assert_cmpuint(ptimer_get_count(ptimer), ==, no_round_down ? 1 : 0);
182 g_assert_false(triggered);
184 qemu_clock_step(2000000);
186 g_assert_cmpuint(ptimer_get_count(ptimer), ==, 0);
187 g_assert_true(triggered);
189 ptimer_stop(ptimer);
191 triggered = false;
193 qemu_clock_step(2000000 * 12 + 1);
195 g_assert_cmpuint(ptimer_get_count(ptimer), ==, 0);
196 g_assert_false(triggered);
199 static void check_periodic(gconstpointer arg)
201 const uint8_t *policy = arg;
202 QEMUBH *bh = qemu_bh_new(ptimer_trigger, NULL);
203 ptimer_state *ptimer = ptimer_init(bh, *policy);
204 bool wrap_policy = (*policy & PTIMER_POLICY_WRAP_AFTER_ONE_PERIOD);
205 bool no_immediate_trigger = (*policy & PTIMER_POLICY_NO_IMMEDIATE_TRIGGER);
206 bool no_immediate_reload = (*policy & PTIMER_POLICY_NO_IMMEDIATE_RELOAD);
207 bool no_round_down = (*policy & PTIMER_POLICY_NO_COUNTER_ROUND_DOWN);
209 triggered = false;
211 ptimer_set_period(ptimer, 2000000);
212 ptimer_set_limit(ptimer, 10, 1);
213 ptimer_run(ptimer, 0);
215 g_assert_cmpuint(ptimer_get_count(ptimer), ==, 10);
216 g_assert_false(triggered);
218 qemu_clock_step(1);
220 g_assert_cmpuint(ptimer_get_count(ptimer), ==, no_round_down ? 10 : 9);
221 g_assert_false(triggered);
223 qemu_clock_step(2000000 * 10 - 1);
225 g_assert_cmpuint(ptimer_get_count(ptimer), ==, wrap_policy ? 0 : 10);
226 g_assert_true(triggered);
228 qemu_clock_step(1);
230 g_assert_cmpuint(ptimer_get_count(ptimer), ==,
231 wrap_policy ? 0 : (no_round_down ? 10 : 9));
232 g_assert_true(triggered);
234 triggered = false;
236 qemu_clock_step(2000000);
238 g_assert_cmpuint(ptimer_get_count(ptimer), ==,
239 (no_round_down ? 9 : 8) + (wrap_policy ? 1 : 0));
240 g_assert_false(triggered);
242 ptimer_set_count(ptimer, 20);
244 g_assert_cmpuint(ptimer_get_count(ptimer), ==, 20);
245 g_assert_false(triggered);
247 qemu_clock_step(1);
249 g_assert_cmpuint(ptimer_get_count(ptimer), ==, no_round_down ? 20 : 19);
250 g_assert_false(triggered);
252 qemu_clock_step(2000000 * 11 + 1);
254 g_assert_cmpuint(ptimer_get_count(ptimer), ==, no_round_down ? 9 : 8);
255 g_assert_false(triggered);
257 qemu_clock_step(2000000 * 10);
259 g_assert_cmpuint(ptimer_get_count(ptimer), ==,
260 (no_round_down ? 9 : 8) + (wrap_policy ? 1 : 0));
261 g_assert_true(triggered);
263 triggered = false;
265 ptimer_set_count(ptimer, 3);
267 g_assert_cmpuint(ptimer_get_count(ptimer), ==, 3);
268 g_assert_false(triggered);
270 qemu_clock_step(1);
272 g_assert_cmpuint(ptimer_get_count(ptimer), ==, no_round_down ? 3 : 2);
273 g_assert_false(triggered);
275 qemu_clock_step(2000000 * 4);
277 g_assert_cmpuint(ptimer_get_count(ptimer), ==,
278 (no_round_down ? 9 : 8) + (wrap_policy ? 1 : 0));
279 g_assert_true(triggered);
281 ptimer_stop(ptimer);
282 triggered = false;
284 qemu_clock_step(2000000);
286 g_assert_cmpuint(ptimer_get_count(ptimer), ==,
287 (no_round_down ? 9 : 8) + (wrap_policy ? 1 : 0));
288 g_assert_false(triggered);
290 ptimer_set_count(ptimer, 3);
291 ptimer_run(ptimer, 0);
293 qemu_clock_step(2000000 * 3 + 1);
295 g_assert_cmpuint(ptimer_get_count(ptimer), ==,
296 wrap_policy ? 0 : (no_round_down ? 10 : 9));
297 g_assert_true(triggered);
299 triggered = false;
301 qemu_clock_step(2000000);
303 g_assert_cmpuint(ptimer_get_count(ptimer), ==,
304 (no_round_down ? 9 : 8) + (wrap_policy ? 1 : 0));
305 g_assert_false(triggered);
307 ptimer_set_count(ptimer, 0);
308 g_assert_cmpuint(ptimer_get_count(ptimer), ==,
309 no_immediate_reload ? 0 : 10);
311 if (no_immediate_trigger) {
312 g_assert_false(triggered);
313 } else {
314 g_assert_true(triggered);
317 triggered = false;
319 qemu_clock_step(1);
321 if (no_immediate_reload) {
322 g_assert_cmpuint(ptimer_get_count(ptimer), ==, 0);
323 g_assert_false(triggered);
325 qemu_clock_step(2000000);
327 if (no_immediate_trigger) {
328 g_assert_true(triggered);
329 } else {
330 g_assert_false(triggered);
333 triggered = false;
336 g_assert_cmpuint(ptimer_get_count(ptimer), ==, no_round_down ? 10 : 9);
337 g_assert_false(triggered);
339 qemu_clock_step(2000000 * 12);
341 g_assert_cmpuint(ptimer_get_count(ptimer), ==,
342 (no_round_down ? 8 : 7) + (wrap_policy ? 1 : 0));
343 g_assert_true(triggered);
345 ptimer_stop(ptimer);
347 triggered = false;
349 qemu_clock_step(2000000 * 10);
351 g_assert_cmpuint(ptimer_get_count(ptimer), ==,
352 (no_round_down ? 8 : 7) + (wrap_policy ? 1 : 0));
353 g_assert_false(triggered);
355 ptimer_run(ptimer, 0);
356 ptimer_set_period(ptimer, 0);
358 qemu_clock_step(2000000 + 1);
360 g_assert_cmpuint(ptimer_get_count(ptimer), ==,
361 (no_round_down ? 8 : 7) + (wrap_policy ? 1 : 0));
362 g_assert_false(triggered);
365 static void check_on_the_fly_mode_change(gconstpointer arg)
367 const uint8_t *policy = arg;
368 QEMUBH *bh = qemu_bh_new(ptimer_trigger, NULL);
369 ptimer_state *ptimer = ptimer_init(bh, *policy);
370 bool wrap_policy = (*policy & PTIMER_POLICY_WRAP_AFTER_ONE_PERIOD);
371 bool no_round_down = (*policy & PTIMER_POLICY_NO_COUNTER_ROUND_DOWN);
373 triggered = false;
375 ptimer_set_period(ptimer, 2000000);
376 ptimer_set_limit(ptimer, 10, 1);
377 ptimer_run(ptimer, 1);
379 qemu_clock_step(2000000 * 9 + 1);
381 g_assert_cmpuint(ptimer_get_count(ptimer), ==, no_round_down ? 1 : 0);
382 g_assert_false(triggered);
384 ptimer_run(ptimer, 0);
386 g_assert_cmpuint(ptimer_get_count(ptimer), ==, no_round_down ? 1 : 0);
387 g_assert_false(triggered);
389 qemu_clock_step(2000000);
391 g_assert_cmpuint(ptimer_get_count(ptimer), ==,
392 wrap_policy ? 0 : (no_round_down ? 10 : 9));
393 g_assert_true(triggered);
395 triggered = false;
397 qemu_clock_step(2000000 * 9);
399 ptimer_run(ptimer, 1);
401 g_assert_cmpuint(ptimer_get_count(ptimer), ==,
402 (no_round_down ? 1 : 0) + (wrap_policy ? 1 : 0));
403 g_assert_false(triggered);
405 qemu_clock_step(2000000 * 3);
407 g_assert_cmpuint(ptimer_get_count(ptimer), ==, 0);
408 g_assert_true(triggered);
411 static void check_on_the_fly_period_change(gconstpointer arg)
413 const uint8_t *policy = arg;
414 QEMUBH *bh = qemu_bh_new(ptimer_trigger, NULL);
415 ptimer_state *ptimer = ptimer_init(bh, *policy);
416 bool no_round_down = (*policy & PTIMER_POLICY_NO_COUNTER_ROUND_DOWN);
418 triggered = false;
420 ptimer_set_period(ptimer, 2000000);
421 ptimer_set_limit(ptimer, 8, 1);
422 ptimer_run(ptimer, 1);
424 qemu_clock_step(2000000 * 4 + 1);
426 g_assert_cmpuint(ptimer_get_count(ptimer), ==, no_round_down ? 4 : 3);
427 g_assert_false(triggered);
429 ptimer_set_period(ptimer, 4000000);
430 g_assert_cmpuint(ptimer_get_count(ptimer), ==, no_round_down ? 4 : 3);
432 qemu_clock_step(4000000 * 2 + 1);
434 g_assert_cmpuint(ptimer_get_count(ptimer), ==, no_round_down ? 2 : 0);
435 g_assert_false(triggered);
437 qemu_clock_step(4000000 * 2);
439 g_assert_cmpuint(ptimer_get_count(ptimer), ==, 0);
440 g_assert_true(triggered);
443 static void check_on_the_fly_freq_change(gconstpointer arg)
445 const uint8_t *policy = arg;
446 QEMUBH *bh = qemu_bh_new(ptimer_trigger, NULL);
447 ptimer_state *ptimer = ptimer_init(bh, *policy);
448 bool no_round_down = (*policy & PTIMER_POLICY_NO_COUNTER_ROUND_DOWN);
450 triggered = false;
452 ptimer_set_freq(ptimer, 500);
453 ptimer_set_limit(ptimer, 8, 1);
454 ptimer_run(ptimer, 1);
456 qemu_clock_step(2000000 * 4 + 1);
458 g_assert_cmpuint(ptimer_get_count(ptimer), ==, no_round_down ? 4 : 3);
459 g_assert_false(triggered);
461 ptimer_set_freq(ptimer, 250);
462 g_assert_cmpuint(ptimer_get_count(ptimer), ==, no_round_down ? 4 : 3);
464 qemu_clock_step(2000000 * 4 + 1);
466 g_assert_cmpuint(ptimer_get_count(ptimer), ==, no_round_down ? 2 : 0);
467 g_assert_false(triggered);
469 qemu_clock_step(2000000 * 4);
471 g_assert_cmpuint(ptimer_get_count(ptimer), ==, 0);
472 g_assert_true(triggered);
475 static void check_run_with_period_0(gconstpointer arg)
477 const uint8_t *policy = arg;
478 QEMUBH *bh = qemu_bh_new(ptimer_trigger, NULL);
479 ptimer_state *ptimer = ptimer_init(bh, *policy);
481 triggered = false;
483 ptimer_set_count(ptimer, 99);
484 ptimer_run(ptimer, 1);
486 qemu_clock_step(10 * NANOSECONDS_PER_SECOND);
488 g_assert_cmpuint(ptimer_get_count(ptimer), ==, 99);
489 g_assert_false(triggered);
492 static void check_run_with_delta_0(gconstpointer arg)
494 const uint8_t *policy = arg;
495 QEMUBH *bh = qemu_bh_new(ptimer_trigger, NULL);
496 ptimer_state *ptimer = ptimer_init(bh, *policy);
497 bool wrap_policy = (*policy & PTIMER_POLICY_WRAP_AFTER_ONE_PERIOD);
498 bool no_immediate_trigger = (*policy & PTIMER_POLICY_NO_IMMEDIATE_TRIGGER);
499 bool no_immediate_reload = (*policy & PTIMER_POLICY_NO_IMMEDIATE_RELOAD);
500 bool no_round_down = (*policy & PTIMER_POLICY_NO_COUNTER_ROUND_DOWN);
502 triggered = false;
504 ptimer_set_period(ptimer, 2000000);
505 ptimer_set_limit(ptimer, 99, 0);
506 ptimer_run(ptimer, 1);
507 g_assert_cmpuint(ptimer_get_count(ptimer), ==,
508 no_immediate_reload ? 0 : 99);
510 if (no_immediate_trigger) {
511 g_assert_false(triggered);
512 } else {
513 g_assert_true(triggered);
516 triggered = false;
518 if (no_immediate_trigger || no_immediate_reload) {
519 qemu_clock_step(2000000 + 1);
521 g_assert_cmpuint(ptimer_get_count(ptimer), ==,
522 no_immediate_reload ? 0 : (no_round_down ? 98 : 97));
524 if (no_immediate_trigger && no_immediate_reload) {
525 g_assert_true(triggered);
527 triggered = false;
528 } else {
529 g_assert_false(triggered);
532 ptimer_set_count(ptimer, 99);
533 ptimer_run(ptimer, 1);
536 qemu_clock_step(2000000 + 1);
538 g_assert_cmpuint(ptimer_get_count(ptimer), ==, no_round_down ? 98 : 97);
539 g_assert_false(triggered);
541 qemu_clock_step(2000000 * 97);
543 g_assert_cmpuint(ptimer_get_count(ptimer), ==, no_round_down ? 1 : 0);
544 g_assert_false(triggered);
546 qemu_clock_step(2000000 * 2);
548 g_assert_cmpuint(ptimer_get_count(ptimer), ==, 0);
549 g_assert_true(triggered);
551 triggered = false;
553 ptimer_set_count(ptimer, 0);
554 ptimer_run(ptimer, 0);
555 g_assert_cmpuint(ptimer_get_count(ptimer), ==,
556 no_immediate_reload ? 0 : 99);
558 if (no_immediate_trigger) {
559 g_assert_false(triggered);
560 } else {
561 g_assert_true(triggered);
564 triggered = false;
566 qemu_clock_step(1);
568 if (no_immediate_reload) {
569 qemu_clock_step(2000000);
572 g_assert_cmpuint(ptimer_get_count(ptimer), ==, no_round_down ? 99 : 98);
574 if (no_immediate_reload && no_immediate_trigger) {
575 g_assert_true(triggered);
576 } else {
577 g_assert_false(triggered);
580 triggered = false;
582 qemu_clock_step(2000000);
584 g_assert_cmpuint(ptimer_get_count(ptimer), ==, no_round_down ? 98 : 97);
585 g_assert_false(triggered);
587 qemu_clock_step(2000000 * 98);
589 g_assert_cmpuint(ptimer_get_count(ptimer), ==,
590 wrap_policy ? 0 : (no_round_down ? 99 : 98));
591 g_assert_true(triggered);
593 ptimer_stop(ptimer);
596 static void check_periodic_with_load_0(gconstpointer arg)
598 const uint8_t *policy = arg;
599 QEMUBH *bh = qemu_bh_new(ptimer_trigger, NULL);
600 ptimer_state *ptimer = ptimer_init(bh, *policy);
601 bool continuous_trigger = (*policy & PTIMER_POLICY_CONTINUOUS_TRIGGER);
602 bool no_immediate_trigger = (*policy & PTIMER_POLICY_NO_IMMEDIATE_TRIGGER);
604 triggered = false;
606 ptimer_set_period(ptimer, 2000000);
607 ptimer_run(ptimer, 0);
609 g_assert_cmpuint(ptimer_get_count(ptimer), ==, 0);
611 if (no_immediate_trigger) {
612 g_assert_false(triggered);
613 } else {
614 g_assert_true(triggered);
617 triggered = false;
619 qemu_clock_step(2000000 + 1);
621 g_assert_cmpuint(ptimer_get_count(ptimer), ==, 0);
623 if (continuous_trigger || no_immediate_trigger) {
624 g_assert_true(triggered);
625 } else {
626 g_assert_false(triggered);
629 triggered = false;
631 ptimer_set_count(ptimer, 10);
632 ptimer_run(ptimer, 0);
634 qemu_clock_step(2000000 * 10 + 1);
636 g_assert_cmpuint(ptimer_get_count(ptimer), ==, 0);
637 g_assert_true(triggered);
639 triggered = false;
641 qemu_clock_step(2000000 + 1);
643 g_assert_cmpuint(ptimer_get_count(ptimer), ==, 0);
645 if (continuous_trigger) {
646 g_assert_true(triggered);
647 } else {
648 g_assert_false(triggered);
651 ptimer_stop(ptimer);
654 static void check_oneshot_with_load_0(gconstpointer arg)
656 const uint8_t *policy = arg;
657 QEMUBH *bh = qemu_bh_new(ptimer_trigger, NULL);
658 ptimer_state *ptimer = ptimer_init(bh, *policy);
659 bool no_immediate_trigger = (*policy & PTIMER_POLICY_NO_IMMEDIATE_TRIGGER);
661 triggered = false;
663 ptimer_set_period(ptimer, 2000000);
664 ptimer_run(ptimer, 1);
666 g_assert_cmpuint(ptimer_get_count(ptimer), ==, 0);
668 if (no_immediate_trigger) {
669 g_assert_false(triggered);
670 } else {
671 g_assert_true(triggered);
674 triggered = false;
676 qemu_clock_step(2000000 + 1);
678 g_assert_cmpuint(ptimer_get_count(ptimer), ==, 0);
680 if (no_immediate_trigger) {
681 g_assert_true(triggered);
682 } else {
683 g_assert_false(triggered);
687 static void add_ptimer_tests(uint8_t policy)
689 uint8_t *ppolicy = g_malloc(1);
690 char *policy_name = g_malloc0(256);
692 *ppolicy = policy;
694 if (policy == PTIMER_POLICY_DEFAULT) {
695 g_sprintf(policy_name, "default");
698 if (policy & PTIMER_POLICY_WRAP_AFTER_ONE_PERIOD) {
699 g_strlcat(policy_name, "wrap_after_one_period,", 256);
702 if (policy & PTIMER_POLICY_CONTINUOUS_TRIGGER) {
703 g_strlcat(policy_name, "continuous_trigger,", 256);
706 if (policy & PTIMER_POLICY_NO_IMMEDIATE_TRIGGER) {
707 g_strlcat(policy_name, "no_immediate_trigger,", 256);
710 if (policy & PTIMER_POLICY_NO_IMMEDIATE_RELOAD) {
711 g_strlcat(policy_name, "no_immediate_reload,", 256);
714 if (policy & PTIMER_POLICY_NO_COUNTER_ROUND_DOWN) {
715 g_strlcat(policy_name, "no_counter_rounddown,", 256);
718 g_test_add_data_func(
719 g_strdup_printf("/ptimer/set_count policy=%s", policy_name),
720 ppolicy, check_set_count);
722 g_test_add_data_func(
723 g_strdup_printf("/ptimer/set_limit policy=%s", policy_name),
724 ppolicy, check_set_limit);
726 g_test_add_data_func(
727 g_strdup_printf("/ptimer/oneshot policy=%s", policy_name),
728 ppolicy, check_oneshot);
730 g_test_add_data_func(
731 g_strdup_printf("/ptimer/periodic policy=%s", policy_name),
732 ppolicy, check_periodic);
734 g_test_add_data_func(
735 g_strdup_printf("/ptimer/on_the_fly_mode_change policy=%s", policy_name),
736 ppolicy, check_on_the_fly_mode_change);
738 g_test_add_data_func(
739 g_strdup_printf("/ptimer/on_the_fly_period_change policy=%s", policy_name),
740 ppolicy, check_on_the_fly_period_change);
742 g_test_add_data_func(
743 g_strdup_printf("/ptimer/on_the_fly_freq_change policy=%s", policy_name),
744 ppolicy, check_on_the_fly_freq_change);
746 g_test_add_data_func(
747 g_strdup_printf("/ptimer/run_with_period_0 policy=%s", policy_name),
748 ppolicy, check_run_with_period_0);
750 g_test_add_data_func(
751 g_strdup_printf("/ptimer/run_with_delta_0 policy=%s", policy_name),
752 ppolicy, check_run_with_delta_0);
754 g_test_add_data_func(
755 g_strdup_printf("/ptimer/periodic_with_load_0 policy=%s", policy_name),
756 ppolicy, check_periodic_with_load_0);
758 g_test_add_data_func(
759 g_strdup_printf("/ptimer/oneshot_with_load_0 policy=%s", policy_name),
760 ppolicy, check_oneshot_with_load_0);
763 static void add_all_ptimer_policies_comb_tests(void)
765 int last_policy = PTIMER_POLICY_NO_COUNTER_ROUND_DOWN;
766 int policy = PTIMER_POLICY_DEFAULT;
768 for (; policy < (last_policy << 1); policy++) {
769 add_ptimer_tests(policy);
773 int main(int argc, char **argv)
775 int i;
777 g_test_init(&argc, &argv, NULL);
779 for (i = 0; i < QEMU_CLOCK_MAX; i++) {
780 main_loop_tlg.tl[i] = g_new0(QEMUTimerList, 1);
783 add_all_ptimer_policies_comb_tests();
785 qtest_allowed = true;
787 return g_test_run();