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"
17 #include "ptimer-test.h"
19 static bool triggered;
21 static void ptimer_trigger(void *opaque)
26 static void ptimer_test_expire_qemu_timers(int64_t expire_time,
29 QEMUTimerList *timer_list = main_loop_tlg.tl[type];
30 QEMUTimer *t = timer_list->active_timers.next;
33 if (t->expire_time == expire_time) {
45 static void ptimer_test_set_qemu_time_ns(int64_t ns)
47 ptimer_test_time_ns = ns;
50 static void qemu_clock_step(uint64_t ns)
52 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,
63 ptimer_test_set_qemu_time_ns(advanced_time);
66 static void check_set_count(gconstpointer arg)
68 const uint8_t *policy = arg;
69 ptimer_state *ptimer = ptimer_init(ptimer_trigger, NULL, *policy);
73 ptimer_transaction_begin(ptimer);
74 ptimer_set_count(ptimer, 1000);
75 ptimer_transaction_commit(ptimer);
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 ptimer_state *ptimer = ptimer_init(ptimer_trigger, NULL, *policy);
88 ptimer_transaction_begin(ptimer);
89 ptimer_set_limit(ptimer, 1000, 0);
90 ptimer_transaction_commit(ptimer);
91 g_assert_cmpuint(ptimer_get_count(ptimer), ==, 0);
92 g_assert_cmpuint(ptimer_get_limit(ptimer), ==, 1000);
93 g_assert_false(triggered);
95 ptimer_transaction_begin(ptimer);
96 ptimer_set_limit(ptimer, 2000, 1);
97 ptimer_transaction_commit(ptimer);
98 g_assert_cmpuint(ptimer_get_count(ptimer), ==, 2000);
99 g_assert_cmpuint(ptimer_get_limit(ptimer), ==, 2000);
100 g_assert_false(triggered);
104 static void check_oneshot(gconstpointer arg)
106 const uint8_t *policy = arg;
107 ptimer_state *ptimer = ptimer_init(ptimer_trigger, NULL, *policy);
108 bool no_round_down = (*policy & PTIMER_POLICY_NO_COUNTER_ROUND_DOWN);
112 ptimer_transaction_begin(ptimer);
113 ptimer_set_period(ptimer, 2000000);
114 ptimer_set_count(ptimer, 10);
115 ptimer_run(ptimer, 1);
116 ptimer_transaction_commit(ptimer);
118 qemu_clock_step(2000000 * 2 + 1);
120 g_assert_cmpuint(ptimer_get_count(ptimer), ==, no_round_down ? 8 : 7);
121 g_assert_false(triggered);
123 ptimer_transaction_begin(ptimer);
125 ptimer_transaction_commit(ptimer);
127 g_assert_cmpuint(ptimer_get_count(ptimer), ==, no_round_down ? 8 : 7);
128 g_assert_false(triggered);
130 qemu_clock_step(2000000 * 11);
132 g_assert_cmpuint(ptimer_get_count(ptimer), ==, no_round_down ? 8 : 7);
133 g_assert_false(triggered);
135 ptimer_transaction_begin(ptimer);
136 ptimer_run(ptimer, 1);
137 ptimer_transaction_commit(ptimer);
139 qemu_clock_step(2000000 * 7 + 1);
141 g_assert_cmpuint(ptimer_get_count(ptimer), ==, no_round_down ? 1 : 0);
144 g_assert_false(triggered);
146 g_assert_true(triggered);
151 qemu_clock_step(2000000);
153 g_assert_cmpuint(ptimer_get_count(ptimer), ==, 0);
156 g_assert_true(triggered);
160 g_assert_false(triggered);
163 qemu_clock_step(4000000);
165 g_assert_cmpuint(ptimer_get_count(ptimer), ==, 0);
166 g_assert_false(triggered);
168 ptimer_transaction_begin(ptimer);
169 ptimer_set_count(ptimer, 10);
170 ptimer_transaction_commit(ptimer);
172 qemu_clock_step(20000000 + 1);
174 g_assert_cmpuint(ptimer_get_count(ptimer), ==, 10);
175 g_assert_false(triggered);
177 ptimer_transaction_begin(ptimer);
178 ptimer_set_limit(ptimer, 9, 1);
179 ptimer_transaction_commit(ptimer);
181 qemu_clock_step(20000000 + 1);
183 g_assert_cmpuint(ptimer_get_count(ptimer), ==, 9);
184 g_assert_false(triggered);
186 ptimer_transaction_begin(ptimer);
187 ptimer_run(ptimer, 1);
188 ptimer_transaction_commit(ptimer);
190 qemu_clock_step(2000000 + 1);
192 g_assert_cmpuint(ptimer_get_count(ptimer), ==, no_round_down ? 8 : 7);
193 g_assert_false(triggered);
195 ptimer_transaction_begin(ptimer);
196 ptimer_set_count(ptimer, 20);
197 ptimer_transaction_commit(ptimer);
199 qemu_clock_step(2000000 * 19 + 1);
201 g_assert_cmpuint(ptimer_get_count(ptimer), ==, no_round_down ? 1 : 0);
202 g_assert_false(triggered);
204 qemu_clock_step(2000000);
206 g_assert_cmpuint(ptimer_get_count(ptimer), ==, 0);
207 g_assert_true(triggered);
209 ptimer_transaction_begin(ptimer);
211 ptimer_transaction_commit(ptimer);
215 qemu_clock_step(2000000 * 12 + 1);
217 g_assert_cmpuint(ptimer_get_count(ptimer), ==, 0);
218 g_assert_false(triggered);
222 static void check_periodic(gconstpointer arg)
224 const uint8_t *policy = arg;
225 ptimer_state *ptimer = ptimer_init(ptimer_trigger, NULL, *policy);
226 bool wrap_policy = (*policy & PTIMER_POLICY_WRAP_AFTER_ONE_PERIOD);
227 bool no_immediate_trigger = (*policy & PTIMER_POLICY_NO_IMMEDIATE_TRIGGER);
228 bool no_immediate_reload = (*policy & PTIMER_POLICY_NO_IMMEDIATE_RELOAD);
229 bool no_round_down = (*policy & PTIMER_POLICY_NO_COUNTER_ROUND_DOWN);
230 bool trig_only_on_dec = (*policy & PTIMER_POLICY_TRIGGER_ONLY_ON_DECREMENT);
234 ptimer_transaction_begin(ptimer);
235 ptimer_set_period(ptimer, 2000000);
236 ptimer_set_limit(ptimer, 10, 1);
237 ptimer_run(ptimer, 0);
238 ptimer_transaction_commit(ptimer);
240 g_assert_cmpuint(ptimer_get_count(ptimer), ==, 10);
241 g_assert_false(triggered);
245 g_assert_cmpuint(ptimer_get_count(ptimer), ==, no_round_down ? 10 : 9);
246 g_assert_false(triggered);
248 qemu_clock_step(2000000 * 10 - 1);
250 g_assert_cmpuint(ptimer_get_count(ptimer), ==, wrap_policy ? 0 : 10);
251 g_assert_true(triggered);
255 g_assert_cmpuint(ptimer_get_count(ptimer), ==,
256 wrap_policy ? 0 : (no_round_down ? 10 : 9));
257 g_assert_true(triggered);
261 qemu_clock_step(2000000);
263 g_assert_cmpuint(ptimer_get_count(ptimer), ==,
264 (no_round_down ? 9 : 8) + (wrap_policy ? 1 : 0));
265 g_assert_false(triggered);
267 ptimer_transaction_begin(ptimer);
268 ptimer_set_count(ptimer, 20);
269 ptimer_transaction_commit(ptimer);
271 g_assert_cmpuint(ptimer_get_count(ptimer), ==, 20);
272 g_assert_false(triggered);
276 g_assert_cmpuint(ptimer_get_count(ptimer), ==, no_round_down ? 20 : 19);
277 g_assert_false(triggered);
279 qemu_clock_step(2000000 * 11 + 1);
281 g_assert_cmpuint(ptimer_get_count(ptimer), ==, no_round_down ? 9 : 8);
282 g_assert_false(triggered);
284 qemu_clock_step(2000000 * 10);
286 g_assert_cmpuint(ptimer_get_count(ptimer), ==,
287 (no_round_down ? 9 : 8) + (wrap_policy ? 1 : 0));
288 g_assert_true(triggered);
292 ptimer_transaction_begin(ptimer);
293 ptimer_set_count(ptimer, 3);
294 ptimer_transaction_commit(ptimer);
296 g_assert_cmpuint(ptimer_get_count(ptimer), ==, 3);
297 g_assert_false(triggered);
301 g_assert_cmpuint(ptimer_get_count(ptimer), ==, no_round_down ? 3 : 2);
302 g_assert_false(triggered);
304 qemu_clock_step(2000000 * 4);
306 g_assert_cmpuint(ptimer_get_count(ptimer), ==,
307 (no_round_down ? 9 : 8) + (wrap_policy ? 1 : 0));
308 g_assert_true(triggered);
310 ptimer_transaction_begin(ptimer);
312 ptimer_transaction_commit(ptimer);
315 qemu_clock_step(2000000);
317 g_assert_cmpuint(ptimer_get_count(ptimer), ==,
318 (no_round_down ? 9 : 8) + (wrap_policy ? 1 : 0));
319 g_assert_false(triggered);
321 ptimer_transaction_begin(ptimer);
322 ptimer_set_count(ptimer, 3);
323 ptimer_run(ptimer, 0);
324 ptimer_transaction_commit(ptimer);
326 qemu_clock_step(2000000 * 3 + 1);
328 g_assert_cmpuint(ptimer_get_count(ptimer), ==,
329 wrap_policy ? 0 : (no_round_down ? 10 : 9));
330 g_assert_true(triggered);
334 qemu_clock_step(2000000);
336 g_assert_cmpuint(ptimer_get_count(ptimer), ==,
337 (no_round_down ? 9 : 8) + (wrap_policy ? 1 : 0));
338 g_assert_false(triggered);
340 ptimer_transaction_begin(ptimer);
341 ptimer_set_count(ptimer, 0);
342 ptimer_transaction_commit(ptimer);
343 g_assert_cmpuint(ptimer_get_count(ptimer), ==,
344 no_immediate_reload ? 0 : 10);
346 if (no_immediate_trigger || trig_only_on_dec) {
347 g_assert_false(triggered);
349 g_assert_true(triggered);
356 if (no_immediate_reload) {
357 g_assert_cmpuint(ptimer_get_count(ptimer), ==, 0);
358 g_assert_false(triggered);
360 qemu_clock_step(2000000);
362 if (no_immediate_trigger) {
363 g_assert_true(triggered);
365 g_assert_false(triggered);
371 g_assert_cmpuint(ptimer_get_count(ptimer), ==, no_round_down ? 10 : 9);
372 g_assert_false(triggered);
374 qemu_clock_step(2000000 * 12);
376 g_assert_cmpuint(ptimer_get_count(ptimer), ==,
377 (no_round_down ? 8 : 7) + (wrap_policy ? 1 : 0));
378 g_assert_true(triggered);
380 ptimer_transaction_begin(ptimer);
382 ptimer_transaction_commit(ptimer);
386 qemu_clock_step(2000000 * 10);
388 g_assert_cmpuint(ptimer_get_count(ptimer), ==,
389 (no_round_down ? 8 : 7) + (wrap_policy ? 1 : 0));
390 g_assert_false(triggered);
392 ptimer_transaction_begin(ptimer);
393 ptimer_run(ptimer, 0);
394 ptimer_transaction_commit(ptimer);
396 ptimer_transaction_begin(ptimer);
397 ptimer_set_period(ptimer, 0);
398 ptimer_transaction_commit(ptimer);
400 qemu_clock_step(2000000 + 1);
402 g_assert_cmpuint(ptimer_get_count(ptimer), ==,
403 (no_round_down ? 8 : 7) + (wrap_policy ? 1 : 0));
404 g_assert_false(triggered);
408 static void check_on_the_fly_mode_change(gconstpointer arg)
410 const uint8_t *policy = arg;
411 ptimer_state *ptimer = ptimer_init(ptimer_trigger, NULL, *policy);
412 bool wrap_policy = (*policy & PTIMER_POLICY_WRAP_AFTER_ONE_PERIOD);
413 bool no_round_down = (*policy & PTIMER_POLICY_NO_COUNTER_ROUND_DOWN);
417 ptimer_transaction_begin(ptimer);
418 ptimer_set_period(ptimer, 2000000);
419 ptimer_set_limit(ptimer, 10, 1);
420 ptimer_run(ptimer, 1);
421 ptimer_transaction_commit(ptimer);
423 qemu_clock_step(2000000 * 9 + 1);
425 g_assert_cmpuint(ptimer_get_count(ptimer), ==, no_round_down ? 1 : 0);
426 g_assert_false(triggered);
428 ptimer_transaction_begin(ptimer);
429 ptimer_run(ptimer, 0);
430 ptimer_transaction_commit(ptimer);
432 g_assert_cmpuint(ptimer_get_count(ptimer), ==, no_round_down ? 1 : 0);
433 g_assert_false(triggered);
435 qemu_clock_step(2000000);
437 g_assert_cmpuint(ptimer_get_count(ptimer), ==,
438 wrap_policy ? 0 : (no_round_down ? 10 : 9));
439 g_assert_true(triggered);
443 qemu_clock_step(2000000 * 9);
445 ptimer_transaction_begin(ptimer);
446 ptimer_run(ptimer, 1);
447 ptimer_transaction_commit(ptimer);
449 g_assert_cmpuint(ptimer_get_count(ptimer), ==,
450 (no_round_down ? 1 : 0) + (wrap_policy ? 1 : 0));
451 g_assert_false(triggered);
453 qemu_clock_step(2000000 * 3);
455 g_assert_cmpuint(ptimer_get_count(ptimer), ==, 0);
456 g_assert_true(triggered);
460 static void check_on_the_fly_period_change(gconstpointer arg)
462 const uint8_t *policy = arg;
463 ptimer_state *ptimer = ptimer_init(ptimer_trigger, NULL, *policy);
464 bool no_round_down = (*policy & PTIMER_POLICY_NO_COUNTER_ROUND_DOWN);
468 ptimer_transaction_begin(ptimer);
469 ptimer_set_period(ptimer, 2000000);
470 ptimer_set_limit(ptimer, 8, 1);
471 ptimer_run(ptimer, 1);
472 ptimer_transaction_commit(ptimer);
474 qemu_clock_step(2000000 * 4 + 1);
476 g_assert_cmpuint(ptimer_get_count(ptimer), ==, no_round_down ? 4 : 3);
477 g_assert_false(triggered);
479 ptimer_transaction_begin(ptimer);
480 ptimer_set_period(ptimer, 4000000);
481 ptimer_transaction_commit(ptimer);
482 g_assert_cmpuint(ptimer_get_count(ptimer), ==, no_round_down ? 4 : 3);
484 qemu_clock_step(4000000 * 2 + 1);
486 g_assert_cmpuint(ptimer_get_count(ptimer), ==, no_round_down ? 2 : 0);
487 g_assert_false(triggered);
489 qemu_clock_step(4000000 * 2);
491 g_assert_cmpuint(ptimer_get_count(ptimer), ==, 0);
492 g_assert_true(triggered);
496 static void check_on_the_fly_freq_change(gconstpointer arg)
498 const uint8_t *policy = arg;
499 ptimer_state *ptimer = ptimer_init(ptimer_trigger, NULL, *policy);
500 bool no_round_down = (*policy & PTIMER_POLICY_NO_COUNTER_ROUND_DOWN);
504 ptimer_transaction_begin(ptimer);
505 ptimer_set_freq(ptimer, 500);
506 ptimer_set_limit(ptimer, 8, 1);
507 ptimer_run(ptimer, 1);
508 ptimer_transaction_commit(ptimer);
510 qemu_clock_step(2000000 * 4 + 1);
512 g_assert_cmpuint(ptimer_get_count(ptimer), ==, no_round_down ? 4 : 3);
513 g_assert_false(triggered);
515 ptimer_transaction_begin(ptimer);
516 ptimer_set_freq(ptimer, 250);
517 ptimer_transaction_commit(ptimer);
518 g_assert_cmpuint(ptimer_get_count(ptimer), ==, no_round_down ? 4 : 3);
520 qemu_clock_step(2000000 * 4 + 1);
522 g_assert_cmpuint(ptimer_get_count(ptimer), ==, no_round_down ? 2 : 0);
523 g_assert_false(triggered);
525 qemu_clock_step(2000000 * 4);
527 g_assert_cmpuint(ptimer_get_count(ptimer), ==, 0);
528 g_assert_true(triggered);
532 static void check_run_with_period_0(gconstpointer arg)
534 const uint8_t *policy = arg;
535 ptimer_state *ptimer = ptimer_init(ptimer_trigger, NULL, *policy);
539 ptimer_transaction_begin(ptimer);
540 ptimer_set_count(ptimer, 99);
541 ptimer_run(ptimer, 1);
542 ptimer_transaction_commit(ptimer);
544 qemu_clock_step(10 * NANOSECONDS_PER_SECOND);
546 g_assert_cmpuint(ptimer_get_count(ptimer), ==, 99);
547 g_assert_false(triggered);
551 static void check_run_with_delta_0(gconstpointer arg)
553 const uint8_t *policy = arg;
554 ptimer_state *ptimer = ptimer_init(ptimer_trigger, NULL, *policy);
555 bool wrap_policy = (*policy & PTIMER_POLICY_WRAP_AFTER_ONE_PERIOD);
556 bool no_immediate_trigger = (*policy & PTIMER_POLICY_NO_IMMEDIATE_TRIGGER);
557 bool no_immediate_reload = (*policy & PTIMER_POLICY_NO_IMMEDIATE_RELOAD);
558 bool no_round_down = (*policy & PTIMER_POLICY_NO_COUNTER_ROUND_DOWN);
559 bool trig_only_on_dec = (*policy & PTIMER_POLICY_TRIGGER_ONLY_ON_DECREMENT);
563 ptimer_transaction_begin(ptimer);
564 ptimer_set_period(ptimer, 2000000);
565 ptimer_set_limit(ptimer, 99, 0);
566 ptimer_run(ptimer, 1);
567 ptimer_transaction_commit(ptimer);
568 g_assert_cmpuint(ptimer_get_count(ptimer), ==,
569 no_immediate_reload ? 0 : 99);
571 if (no_immediate_trigger || trig_only_on_dec) {
572 g_assert_false(triggered);
574 g_assert_true(triggered);
579 if (no_immediate_trigger || no_immediate_reload) {
580 qemu_clock_step(2000000 + 1);
582 g_assert_cmpuint(ptimer_get_count(ptimer), ==,
583 no_immediate_reload ? 0 : (no_round_down ? 98 : 97));
585 if (no_immediate_trigger && no_immediate_reload) {
586 g_assert_true(triggered);
590 g_assert_false(triggered);
593 ptimer_transaction_begin(ptimer);
594 ptimer_set_count(ptimer, 99);
595 ptimer_run(ptimer, 1);
596 ptimer_transaction_commit(ptimer);
599 qemu_clock_step(2000000 + 1);
601 g_assert_cmpuint(ptimer_get_count(ptimer), ==, no_round_down ? 98 : 97);
602 g_assert_false(triggered);
604 qemu_clock_step(2000000 * 97);
606 g_assert_cmpuint(ptimer_get_count(ptimer), ==, no_round_down ? 1 : 0);
607 g_assert_false(triggered);
609 qemu_clock_step(2000000 * 2);
611 g_assert_cmpuint(ptimer_get_count(ptimer), ==, 0);
612 g_assert_true(triggered);
616 ptimer_transaction_begin(ptimer);
617 ptimer_set_count(ptimer, 0);
618 ptimer_run(ptimer, 0);
619 ptimer_transaction_commit(ptimer);
620 g_assert_cmpuint(ptimer_get_count(ptimer), ==,
621 no_immediate_reload ? 0 : 99);
623 if (no_immediate_trigger || trig_only_on_dec) {
624 g_assert_false(triggered);
626 g_assert_true(triggered);
633 if (no_immediate_reload) {
634 qemu_clock_step(2000000);
637 g_assert_cmpuint(ptimer_get_count(ptimer), ==, no_round_down ? 99 : 98);
639 if (no_immediate_reload && no_immediate_trigger) {
640 g_assert_true(triggered);
642 g_assert_false(triggered);
647 qemu_clock_step(2000000);
649 g_assert_cmpuint(ptimer_get_count(ptimer), ==, no_round_down ? 98 : 97);
650 g_assert_false(triggered);
652 qemu_clock_step(2000000 * 98);
654 g_assert_cmpuint(ptimer_get_count(ptimer), ==,
655 wrap_policy ? 0 : (no_round_down ? 99 : 98));
656 g_assert_true(triggered);
658 ptimer_transaction_begin(ptimer);
660 ptimer_transaction_commit(ptimer);
664 static void check_periodic_with_load_0(gconstpointer arg)
666 const uint8_t *policy = arg;
667 ptimer_state *ptimer = ptimer_init(ptimer_trigger, NULL, *policy);
668 bool continuous_trigger = (*policy & PTIMER_POLICY_CONTINUOUS_TRIGGER);
669 bool no_immediate_trigger = (*policy & PTIMER_POLICY_NO_IMMEDIATE_TRIGGER);
670 bool trig_only_on_dec = (*policy & PTIMER_POLICY_TRIGGER_ONLY_ON_DECREMENT);
674 ptimer_transaction_begin(ptimer);
675 ptimer_set_period(ptimer, 2000000);
676 ptimer_run(ptimer, 0);
677 ptimer_transaction_commit(ptimer);
679 g_assert_cmpuint(ptimer_get_count(ptimer), ==, 0);
681 if (no_immediate_trigger || trig_only_on_dec) {
682 g_assert_false(triggered);
684 g_assert_true(triggered);
689 qemu_clock_step(2000000 + 1);
691 g_assert_cmpuint(ptimer_get_count(ptimer), ==, 0);
693 if (continuous_trigger || no_immediate_trigger) {
694 g_assert_true(triggered);
696 g_assert_false(triggered);
701 ptimer_transaction_begin(ptimer);
702 ptimer_set_count(ptimer, 10);
703 ptimer_run(ptimer, 0);
704 ptimer_transaction_commit(ptimer);
706 qemu_clock_step(2000000 * 10 + 1);
708 g_assert_cmpuint(ptimer_get_count(ptimer), ==, 0);
709 g_assert_true(triggered);
713 qemu_clock_step(2000000 + 1);
715 g_assert_cmpuint(ptimer_get_count(ptimer), ==, 0);
717 if (continuous_trigger) {
718 g_assert_true(triggered);
720 g_assert_false(triggered);
723 ptimer_transaction_begin(ptimer);
725 ptimer_transaction_commit(ptimer);
729 static void check_oneshot_with_load_0(gconstpointer arg)
731 const uint8_t *policy = arg;
732 ptimer_state *ptimer = ptimer_init(ptimer_trigger, NULL, *policy);
733 bool no_immediate_trigger = (*policy & PTIMER_POLICY_NO_IMMEDIATE_TRIGGER);
734 bool trig_only_on_dec = (*policy & PTIMER_POLICY_TRIGGER_ONLY_ON_DECREMENT);
738 ptimer_transaction_begin(ptimer);
739 ptimer_set_period(ptimer, 2000000);
740 ptimer_run(ptimer, 1);
741 ptimer_transaction_commit(ptimer);
743 g_assert_cmpuint(ptimer_get_count(ptimer), ==, 0);
745 if (no_immediate_trigger || trig_only_on_dec) {
746 g_assert_false(triggered);
748 g_assert_true(triggered);
753 qemu_clock_step(2000000 + 1);
755 g_assert_cmpuint(ptimer_get_count(ptimer), ==, 0);
757 if (no_immediate_trigger) {
758 g_assert_true(triggered);
760 g_assert_false(triggered);
766 static void add_ptimer_tests(uint8_t policy)
768 char policy_name[256] = "";
771 if (policy == PTIMER_POLICY_LEGACY) {
772 g_sprintf(policy_name, "legacy");
775 if (policy & PTIMER_POLICY_WRAP_AFTER_ONE_PERIOD) {
776 g_strlcat(policy_name, "wrap_after_one_period,", 256);
779 if (policy & PTIMER_POLICY_CONTINUOUS_TRIGGER) {
780 g_strlcat(policy_name, "continuous_trigger,", 256);
783 if (policy & PTIMER_POLICY_NO_IMMEDIATE_TRIGGER) {
784 g_strlcat(policy_name, "no_immediate_trigger,", 256);
787 if (policy & PTIMER_POLICY_NO_IMMEDIATE_RELOAD) {
788 g_strlcat(policy_name, "no_immediate_reload,", 256);
791 if (policy & PTIMER_POLICY_NO_COUNTER_ROUND_DOWN) {
792 g_strlcat(policy_name, "no_counter_rounddown,", 256);
795 if (policy & PTIMER_POLICY_TRIGGER_ONLY_ON_DECREMENT) {
796 g_strlcat(policy_name, "trigger_only_on_decrement,", 256);
799 g_test_add_data_func_full(
800 tmp = g_strdup_printf("/ptimer/set_count policy=%s", policy_name),
801 g_memdup2(&policy, 1), check_set_count, g_free);
804 g_test_add_data_func_full(
805 tmp = g_strdup_printf("/ptimer/set_limit policy=%s", policy_name),
806 g_memdup2(&policy, 1), check_set_limit, g_free);
809 g_test_add_data_func_full(
810 tmp = g_strdup_printf("/ptimer/oneshot policy=%s", policy_name),
811 g_memdup2(&policy, 1), check_oneshot, g_free);
814 g_test_add_data_func_full(
815 tmp = g_strdup_printf("/ptimer/periodic policy=%s", policy_name),
816 g_memdup2(&policy, 1), check_periodic, g_free);
819 g_test_add_data_func_full(
820 tmp = g_strdup_printf("/ptimer/on_the_fly_mode_change policy=%s",
822 g_memdup2(&policy, 1), check_on_the_fly_mode_change, g_free);
825 g_test_add_data_func_full(
826 tmp = g_strdup_printf("/ptimer/on_the_fly_period_change policy=%s",
828 g_memdup2(&policy, 1), check_on_the_fly_period_change, g_free);
831 g_test_add_data_func_full(
832 tmp = g_strdup_printf("/ptimer/on_the_fly_freq_change policy=%s",
834 g_memdup2(&policy, 1), check_on_the_fly_freq_change, g_free);
837 g_test_add_data_func_full(
838 tmp = g_strdup_printf("/ptimer/run_with_period_0 policy=%s",
840 g_memdup2(&policy, 1), check_run_with_period_0, g_free);
843 g_test_add_data_func_full(
844 tmp = g_strdup_printf("/ptimer/run_with_delta_0 policy=%s",
846 g_memdup2(&policy, 1), check_run_with_delta_0, g_free);
849 g_test_add_data_func_full(
850 tmp = g_strdup_printf("/ptimer/periodic_with_load_0 policy=%s",
852 g_memdup2(&policy, 1), check_periodic_with_load_0, g_free);
855 g_test_add_data_func_full(
856 tmp = g_strdup_printf("/ptimer/oneshot_with_load_0 policy=%s",
858 g_memdup2(&policy, 1), check_oneshot_with_load_0, g_free);
862 static void add_all_ptimer_policies_comb_tests(void)
864 int last_policy = PTIMER_POLICY_TRIGGER_ONLY_ON_DECREMENT;
865 int policy = PTIMER_POLICY_LEGACY;
867 for (; policy < (last_policy << 1); policy++) {
868 if ((policy & PTIMER_POLICY_TRIGGER_ONLY_ON_DECREMENT) &&
869 (policy & PTIMER_POLICY_NO_IMMEDIATE_TRIGGER)) {
870 /* Incompatible policy flag settings -- don't try to test them */
873 add_ptimer_tests(policy);
877 int main(int argc, char **argv)
881 g_test_init(&argc, &argv, NULL);
883 for (i = 0; i < QEMU_CLOCK_MAX; i++) {
884 main_loop_tlg.tl[i] = g_new0(QEMUTimerList, 1);
887 add_all_ptimer_policies_comb_tests();
889 qtest_allowed = true;