contrib/vhost-user-blk: fix the compilation issue
[qemu/ar7.git] / tests / ptimer-test.c
blobb30aad0737239f840335b4b973fc0c376b48fe04
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 "qemu/osdep.h"
12 #include <glib/gprintf.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);
76 ptimer_free(ptimer);
79 static void check_set_limit(gconstpointer arg)
81 const uint8_t *policy = arg;
82 QEMUBH *bh = qemu_bh_new(ptimer_trigger, NULL);
83 ptimer_state *ptimer = ptimer_init(bh, *policy);
85 triggered = false;
87 ptimer_set_limit(ptimer, 1000, 0);
88 g_assert_cmpuint(ptimer_get_count(ptimer), ==, 0);
89 g_assert_cmpuint(ptimer_get_limit(ptimer), ==, 1000);
90 g_assert_false(triggered);
92 ptimer_set_limit(ptimer, 2000, 1);
93 g_assert_cmpuint(ptimer_get_count(ptimer), ==, 2000);
94 g_assert_cmpuint(ptimer_get_limit(ptimer), ==, 2000);
95 g_assert_false(triggered);
96 ptimer_free(ptimer);
99 static void check_oneshot(gconstpointer arg)
101 const uint8_t *policy = arg;
102 QEMUBH *bh = qemu_bh_new(ptimer_trigger, NULL);
103 ptimer_state *ptimer = ptimer_init(bh, *policy);
104 bool no_round_down = (*policy & PTIMER_POLICY_NO_COUNTER_ROUND_DOWN);
106 triggered = false;
108 ptimer_set_period(ptimer, 2000000);
109 ptimer_set_count(ptimer, 10);
110 ptimer_run(ptimer, 1);
112 qemu_clock_step(2000000 * 2 + 1);
114 g_assert_cmpuint(ptimer_get_count(ptimer), ==, no_round_down ? 8 : 7);
115 g_assert_false(triggered);
117 ptimer_stop(ptimer);
119 g_assert_cmpuint(ptimer_get_count(ptimer), ==, no_round_down ? 8 : 7);
120 g_assert_false(triggered);
122 qemu_clock_step(2000000 * 11);
124 g_assert_cmpuint(ptimer_get_count(ptimer), ==, no_round_down ? 8 : 7);
125 g_assert_false(triggered);
127 ptimer_run(ptimer, 1);
129 qemu_clock_step(2000000 * 7 + 1);
131 g_assert_cmpuint(ptimer_get_count(ptimer), ==, no_round_down ? 1 : 0);
133 if (no_round_down) {
134 g_assert_false(triggered);
135 } else {
136 g_assert_true(triggered);
138 triggered = false;
141 qemu_clock_step(2000000);
143 g_assert_cmpuint(ptimer_get_count(ptimer), ==, 0);
145 if (no_round_down) {
146 g_assert_true(triggered);
148 triggered = false;
149 } else {
150 g_assert_false(triggered);
153 qemu_clock_step(4000000);
155 g_assert_cmpuint(ptimer_get_count(ptimer), ==, 0);
156 g_assert_false(triggered);
158 ptimer_set_count(ptimer, 10);
160 qemu_clock_step(20000000 + 1);
162 g_assert_cmpuint(ptimer_get_count(ptimer), ==, 10);
163 g_assert_false(triggered);
165 ptimer_set_limit(ptimer, 9, 1);
167 qemu_clock_step(20000000 + 1);
169 g_assert_cmpuint(ptimer_get_count(ptimer), ==, 9);
170 g_assert_false(triggered);
172 ptimer_run(ptimer, 1);
174 qemu_clock_step(2000000 + 1);
176 g_assert_cmpuint(ptimer_get_count(ptimer), ==, no_round_down ? 8 : 7);
177 g_assert_false(triggered);
179 ptimer_set_count(ptimer, 20);
181 qemu_clock_step(2000000 * 19 + 1);
183 g_assert_cmpuint(ptimer_get_count(ptimer), ==, no_round_down ? 1 : 0);
184 g_assert_false(triggered);
186 qemu_clock_step(2000000);
188 g_assert_cmpuint(ptimer_get_count(ptimer), ==, 0);
189 g_assert_true(triggered);
191 ptimer_stop(ptimer);
193 triggered = false;
195 qemu_clock_step(2000000 * 12 + 1);
197 g_assert_cmpuint(ptimer_get_count(ptimer), ==, 0);
198 g_assert_false(triggered);
199 ptimer_free(ptimer);
202 static void check_periodic(gconstpointer arg)
204 const uint8_t *policy = arg;
205 QEMUBH *bh = qemu_bh_new(ptimer_trigger, NULL);
206 ptimer_state *ptimer = ptimer_init(bh, *policy);
207 bool wrap_policy = (*policy & PTIMER_POLICY_WRAP_AFTER_ONE_PERIOD);
208 bool no_immediate_trigger = (*policy & PTIMER_POLICY_NO_IMMEDIATE_TRIGGER);
209 bool no_immediate_reload = (*policy & PTIMER_POLICY_NO_IMMEDIATE_RELOAD);
210 bool no_round_down = (*policy & PTIMER_POLICY_NO_COUNTER_ROUND_DOWN);
211 bool trig_only_on_dec = (*policy & PTIMER_POLICY_TRIGGER_ONLY_ON_DECREMENT);
213 triggered = false;
215 ptimer_set_period(ptimer, 2000000);
216 ptimer_set_limit(ptimer, 10, 1);
217 ptimer_run(ptimer, 0);
219 g_assert_cmpuint(ptimer_get_count(ptimer), ==, 10);
220 g_assert_false(triggered);
222 qemu_clock_step(1);
224 g_assert_cmpuint(ptimer_get_count(ptimer), ==, no_round_down ? 10 : 9);
225 g_assert_false(triggered);
227 qemu_clock_step(2000000 * 10 - 1);
229 g_assert_cmpuint(ptimer_get_count(ptimer), ==, wrap_policy ? 0 : 10);
230 g_assert_true(triggered);
232 qemu_clock_step(1);
234 g_assert_cmpuint(ptimer_get_count(ptimer), ==,
235 wrap_policy ? 0 : (no_round_down ? 10 : 9));
236 g_assert_true(triggered);
238 triggered = false;
240 qemu_clock_step(2000000);
242 g_assert_cmpuint(ptimer_get_count(ptimer), ==,
243 (no_round_down ? 9 : 8) + (wrap_policy ? 1 : 0));
244 g_assert_false(triggered);
246 ptimer_set_count(ptimer, 20);
248 g_assert_cmpuint(ptimer_get_count(ptimer), ==, 20);
249 g_assert_false(triggered);
251 qemu_clock_step(1);
253 g_assert_cmpuint(ptimer_get_count(ptimer), ==, no_round_down ? 20 : 19);
254 g_assert_false(triggered);
256 qemu_clock_step(2000000 * 11 + 1);
258 g_assert_cmpuint(ptimer_get_count(ptimer), ==, no_round_down ? 9 : 8);
259 g_assert_false(triggered);
261 qemu_clock_step(2000000 * 10);
263 g_assert_cmpuint(ptimer_get_count(ptimer), ==,
264 (no_round_down ? 9 : 8) + (wrap_policy ? 1 : 0));
265 g_assert_true(triggered);
267 triggered = false;
269 ptimer_set_count(ptimer, 3);
271 g_assert_cmpuint(ptimer_get_count(ptimer), ==, 3);
272 g_assert_false(triggered);
274 qemu_clock_step(1);
276 g_assert_cmpuint(ptimer_get_count(ptimer), ==, no_round_down ? 3 : 2);
277 g_assert_false(triggered);
279 qemu_clock_step(2000000 * 4);
281 g_assert_cmpuint(ptimer_get_count(ptimer), ==,
282 (no_round_down ? 9 : 8) + (wrap_policy ? 1 : 0));
283 g_assert_true(triggered);
285 ptimer_stop(ptimer);
286 triggered = false;
288 qemu_clock_step(2000000);
290 g_assert_cmpuint(ptimer_get_count(ptimer), ==,
291 (no_round_down ? 9 : 8) + (wrap_policy ? 1 : 0));
292 g_assert_false(triggered);
294 ptimer_set_count(ptimer, 3);
295 ptimer_run(ptimer, 0);
297 qemu_clock_step(2000000 * 3 + 1);
299 g_assert_cmpuint(ptimer_get_count(ptimer), ==,
300 wrap_policy ? 0 : (no_round_down ? 10 : 9));
301 g_assert_true(triggered);
303 triggered = false;
305 qemu_clock_step(2000000);
307 g_assert_cmpuint(ptimer_get_count(ptimer), ==,
308 (no_round_down ? 9 : 8) + (wrap_policy ? 1 : 0));
309 g_assert_false(triggered);
311 ptimer_set_count(ptimer, 0);
312 g_assert_cmpuint(ptimer_get_count(ptimer), ==,
313 no_immediate_reload ? 0 : 10);
315 if (no_immediate_trigger || trig_only_on_dec) {
316 g_assert_false(triggered);
317 } else {
318 g_assert_true(triggered);
321 triggered = false;
323 qemu_clock_step(1);
325 if (no_immediate_reload) {
326 g_assert_cmpuint(ptimer_get_count(ptimer), ==, 0);
327 g_assert_false(triggered);
329 qemu_clock_step(2000000);
331 if (no_immediate_trigger) {
332 g_assert_true(triggered);
333 } else {
334 g_assert_false(triggered);
337 triggered = false;
340 g_assert_cmpuint(ptimer_get_count(ptimer), ==, no_round_down ? 10 : 9);
341 g_assert_false(triggered);
343 qemu_clock_step(2000000 * 12);
345 g_assert_cmpuint(ptimer_get_count(ptimer), ==,
346 (no_round_down ? 8 : 7) + (wrap_policy ? 1 : 0));
347 g_assert_true(triggered);
349 ptimer_stop(ptimer);
351 triggered = false;
353 qemu_clock_step(2000000 * 10);
355 g_assert_cmpuint(ptimer_get_count(ptimer), ==,
356 (no_round_down ? 8 : 7) + (wrap_policy ? 1 : 0));
357 g_assert_false(triggered);
359 ptimer_run(ptimer, 0);
360 ptimer_set_period(ptimer, 0);
362 qemu_clock_step(2000000 + 1);
364 g_assert_cmpuint(ptimer_get_count(ptimer), ==,
365 (no_round_down ? 8 : 7) + (wrap_policy ? 1 : 0));
366 g_assert_false(triggered);
367 ptimer_free(ptimer);
370 static void check_on_the_fly_mode_change(gconstpointer arg)
372 const uint8_t *policy = arg;
373 QEMUBH *bh = qemu_bh_new(ptimer_trigger, NULL);
374 ptimer_state *ptimer = ptimer_init(bh, *policy);
375 bool wrap_policy = (*policy & PTIMER_POLICY_WRAP_AFTER_ONE_PERIOD);
376 bool no_round_down = (*policy & PTIMER_POLICY_NO_COUNTER_ROUND_DOWN);
378 triggered = false;
380 ptimer_set_period(ptimer, 2000000);
381 ptimer_set_limit(ptimer, 10, 1);
382 ptimer_run(ptimer, 1);
384 qemu_clock_step(2000000 * 9 + 1);
386 g_assert_cmpuint(ptimer_get_count(ptimer), ==, no_round_down ? 1 : 0);
387 g_assert_false(triggered);
389 ptimer_run(ptimer, 0);
391 g_assert_cmpuint(ptimer_get_count(ptimer), ==, no_round_down ? 1 : 0);
392 g_assert_false(triggered);
394 qemu_clock_step(2000000);
396 g_assert_cmpuint(ptimer_get_count(ptimer), ==,
397 wrap_policy ? 0 : (no_round_down ? 10 : 9));
398 g_assert_true(triggered);
400 triggered = false;
402 qemu_clock_step(2000000 * 9);
404 ptimer_run(ptimer, 1);
406 g_assert_cmpuint(ptimer_get_count(ptimer), ==,
407 (no_round_down ? 1 : 0) + (wrap_policy ? 1 : 0));
408 g_assert_false(triggered);
410 qemu_clock_step(2000000 * 3);
412 g_assert_cmpuint(ptimer_get_count(ptimer), ==, 0);
413 g_assert_true(triggered);
414 ptimer_free(ptimer);
417 static void check_on_the_fly_period_change(gconstpointer arg)
419 const uint8_t *policy = arg;
420 QEMUBH *bh = qemu_bh_new(ptimer_trigger, NULL);
421 ptimer_state *ptimer = ptimer_init(bh, *policy);
422 bool no_round_down = (*policy & PTIMER_POLICY_NO_COUNTER_ROUND_DOWN);
424 triggered = false;
426 ptimer_set_period(ptimer, 2000000);
427 ptimer_set_limit(ptimer, 8, 1);
428 ptimer_run(ptimer, 1);
430 qemu_clock_step(2000000 * 4 + 1);
432 g_assert_cmpuint(ptimer_get_count(ptimer), ==, no_round_down ? 4 : 3);
433 g_assert_false(triggered);
435 ptimer_set_period(ptimer, 4000000);
436 g_assert_cmpuint(ptimer_get_count(ptimer), ==, no_round_down ? 4 : 3);
438 qemu_clock_step(4000000 * 2 + 1);
440 g_assert_cmpuint(ptimer_get_count(ptimer), ==, no_round_down ? 2 : 0);
441 g_assert_false(triggered);
443 qemu_clock_step(4000000 * 2);
445 g_assert_cmpuint(ptimer_get_count(ptimer), ==, 0);
446 g_assert_true(triggered);
447 ptimer_free(ptimer);
450 static void check_on_the_fly_freq_change(gconstpointer arg)
452 const uint8_t *policy = arg;
453 QEMUBH *bh = qemu_bh_new(ptimer_trigger, NULL);
454 ptimer_state *ptimer = ptimer_init(bh, *policy);
455 bool no_round_down = (*policy & PTIMER_POLICY_NO_COUNTER_ROUND_DOWN);
457 triggered = false;
459 ptimer_set_freq(ptimer, 500);
460 ptimer_set_limit(ptimer, 8, 1);
461 ptimer_run(ptimer, 1);
463 qemu_clock_step(2000000 * 4 + 1);
465 g_assert_cmpuint(ptimer_get_count(ptimer), ==, no_round_down ? 4 : 3);
466 g_assert_false(triggered);
468 ptimer_set_freq(ptimer, 250);
469 g_assert_cmpuint(ptimer_get_count(ptimer), ==, no_round_down ? 4 : 3);
471 qemu_clock_step(2000000 * 4 + 1);
473 g_assert_cmpuint(ptimer_get_count(ptimer), ==, no_round_down ? 2 : 0);
474 g_assert_false(triggered);
476 qemu_clock_step(2000000 * 4);
478 g_assert_cmpuint(ptimer_get_count(ptimer), ==, 0);
479 g_assert_true(triggered);
480 ptimer_free(ptimer);
483 static void check_run_with_period_0(gconstpointer arg)
485 const uint8_t *policy = arg;
486 QEMUBH *bh = qemu_bh_new(ptimer_trigger, NULL);
487 ptimer_state *ptimer = ptimer_init(bh, *policy);
489 triggered = false;
491 ptimer_set_count(ptimer, 99);
492 ptimer_run(ptimer, 1);
494 qemu_clock_step(10 * NANOSECONDS_PER_SECOND);
496 g_assert_cmpuint(ptimer_get_count(ptimer), ==, 99);
497 g_assert_false(triggered);
498 ptimer_free(ptimer);
501 static void check_run_with_delta_0(gconstpointer arg)
503 const uint8_t *policy = arg;
504 QEMUBH *bh = qemu_bh_new(ptimer_trigger, NULL);
505 ptimer_state *ptimer = ptimer_init(bh, *policy);
506 bool wrap_policy = (*policy & PTIMER_POLICY_WRAP_AFTER_ONE_PERIOD);
507 bool no_immediate_trigger = (*policy & PTIMER_POLICY_NO_IMMEDIATE_TRIGGER);
508 bool no_immediate_reload = (*policy & PTIMER_POLICY_NO_IMMEDIATE_RELOAD);
509 bool no_round_down = (*policy & PTIMER_POLICY_NO_COUNTER_ROUND_DOWN);
510 bool trig_only_on_dec = (*policy & PTIMER_POLICY_TRIGGER_ONLY_ON_DECREMENT);
512 triggered = false;
514 ptimer_set_period(ptimer, 2000000);
515 ptimer_set_limit(ptimer, 99, 0);
516 ptimer_run(ptimer, 1);
517 g_assert_cmpuint(ptimer_get_count(ptimer), ==,
518 no_immediate_reload ? 0 : 99);
520 if (no_immediate_trigger || trig_only_on_dec) {
521 g_assert_false(triggered);
522 } else {
523 g_assert_true(triggered);
526 triggered = false;
528 if (no_immediate_trigger || no_immediate_reload) {
529 qemu_clock_step(2000000 + 1);
531 g_assert_cmpuint(ptimer_get_count(ptimer), ==,
532 no_immediate_reload ? 0 : (no_round_down ? 98 : 97));
534 if (no_immediate_trigger && no_immediate_reload) {
535 g_assert_true(triggered);
537 triggered = false;
538 } else {
539 g_assert_false(triggered);
542 ptimer_set_count(ptimer, 99);
543 ptimer_run(ptimer, 1);
546 qemu_clock_step(2000000 + 1);
548 g_assert_cmpuint(ptimer_get_count(ptimer), ==, no_round_down ? 98 : 97);
549 g_assert_false(triggered);
551 qemu_clock_step(2000000 * 97);
553 g_assert_cmpuint(ptimer_get_count(ptimer), ==, no_round_down ? 1 : 0);
554 g_assert_false(triggered);
556 qemu_clock_step(2000000 * 2);
558 g_assert_cmpuint(ptimer_get_count(ptimer), ==, 0);
559 g_assert_true(triggered);
561 triggered = false;
563 ptimer_set_count(ptimer, 0);
564 ptimer_run(ptimer, 0);
565 g_assert_cmpuint(ptimer_get_count(ptimer), ==,
566 no_immediate_reload ? 0 : 99);
568 if (no_immediate_trigger || trig_only_on_dec) {
569 g_assert_false(triggered);
570 } else {
571 g_assert_true(triggered);
574 triggered = false;
576 qemu_clock_step(1);
578 if (no_immediate_reload) {
579 qemu_clock_step(2000000);
582 g_assert_cmpuint(ptimer_get_count(ptimer), ==, no_round_down ? 99 : 98);
584 if (no_immediate_reload && no_immediate_trigger) {
585 g_assert_true(triggered);
586 } else {
587 g_assert_false(triggered);
590 triggered = false;
592 qemu_clock_step(2000000);
594 g_assert_cmpuint(ptimer_get_count(ptimer), ==, no_round_down ? 98 : 97);
595 g_assert_false(triggered);
597 qemu_clock_step(2000000 * 98);
599 g_assert_cmpuint(ptimer_get_count(ptimer), ==,
600 wrap_policy ? 0 : (no_round_down ? 99 : 98));
601 g_assert_true(triggered);
603 ptimer_stop(ptimer);
604 ptimer_free(ptimer);
607 static void check_periodic_with_load_0(gconstpointer arg)
609 const uint8_t *policy = arg;
610 QEMUBH *bh = qemu_bh_new(ptimer_trigger, NULL);
611 ptimer_state *ptimer = ptimer_init(bh, *policy);
612 bool continuous_trigger = (*policy & PTIMER_POLICY_CONTINUOUS_TRIGGER);
613 bool no_immediate_trigger = (*policy & PTIMER_POLICY_NO_IMMEDIATE_TRIGGER);
614 bool trig_only_on_dec = (*policy & PTIMER_POLICY_TRIGGER_ONLY_ON_DECREMENT);
616 triggered = false;
618 ptimer_set_period(ptimer, 2000000);
619 ptimer_run(ptimer, 0);
621 g_assert_cmpuint(ptimer_get_count(ptimer), ==, 0);
623 if (no_immediate_trigger || trig_only_on_dec) {
624 g_assert_false(triggered);
625 } else {
626 g_assert_true(triggered);
629 triggered = false;
631 qemu_clock_step(2000000 + 1);
633 g_assert_cmpuint(ptimer_get_count(ptimer), ==, 0);
635 if (continuous_trigger || no_immediate_trigger) {
636 g_assert_true(triggered);
637 } else {
638 g_assert_false(triggered);
641 triggered = false;
643 ptimer_set_count(ptimer, 10);
644 ptimer_run(ptimer, 0);
646 qemu_clock_step(2000000 * 10 + 1);
648 g_assert_cmpuint(ptimer_get_count(ptimer), ==, 0);
649 g_assert_true(triggered);
651 triggered = false;
653 qemu_clock_step(2000000 + 1);
655 g_assert_cmpuint(ptimer_get_count(ptimer), ==, 0);
657 if (continuous_trigger) {
658 g_assert_true(triggered);
659 } else {
660 g_assert_false(triggered);
663 ptimer_stop(ptimer);
664 ptimer_free(ptimer);
667 static void check_oneshot_with_load_0(gconstpointer arg)
669 const uint8_t *policy = arg;
670 QEMUBH *bh = qemu_bh_new(ptimer_trigger, NULL);
671 ptimer_state *ptimer = ptimer_init(bh, *policy);
672 bool no_immediate_trigger = (*policy & PTIMER_POLICY_NO_IMMEDIATE_TRIGGER);
673 bool trig_only_on_dec = (*policy & PTIMER_POLICY_TRIGGER_ONLY_ON_DECREMENT);
675 triggered = false;
677 ptimer_set_period(ptimer, 2000000);
678 ptimer_run(ptimer, 1);
680 g_assert_cmpuint(ptimer_get_count(ptimer), ==, 0);
682 if (no_immediate_trigger || trig_only_on_dec) {
683 g_assert_false(triggered);
684 } else {
685 g_assert_true(triggered);
688 triggered = false;
690 qemu_clock_step(2000000 + 1);
692 g_assert_cmpuint(ptimer_get_count(ptimer), ==, 0);
694 if (no_immediate_trigger) {
695 g_assert_true(triggered);
696 } else {
697 g_assert_false(triggered);
700 ptimer_free(ptimer);
703 static void add_ptimer_tests(uint8_t policy)
705 char policy_name[256] = "";
706 char *tmp;
708 if (policy == PTIMER_POLICY_DEFAULT) {
709 g_sprintf(policy_name, "default");
712 if (policy & PTIMER_POLICY_WRAP_AFTER_ONE_PERIOD) {
713 g_strlcat(policy_name, "wrap_after_one_period,", 256);
716 if (policy & PTIMER_POLICY_CONTINUOUS_TRIGGER) {
717 g_strlcat(policy_name, "continuous_trigger,", 256);
720 if (policy & PTIMER_POLICY_NO_IMMEDIATE_TRIGGER) {
721 g_strlcat(policy_name, "no_immediate_trigger,", 256);
724 if (policy & PTIMER_POLICY_NO_IMMEDIATE_RELOAD) {
725 g_strlcat(policy_name, "no_immediate_reload,", 256);
728 if (policy & PTIMER_POLICY_NO_COUNTER_ROUND_DOWN) {
729 g_strlcat(policy_name, "no_counter_rounddown,", 256);
732 if (policy & PTIMER_POLICY_TRIGGER_ONLY_ON_DECREMENT) {
733 g_strlcat(policy_name, "trigger_only_on_decrement,", 256);
736 g_test_add_data_func_full(
737 tmp = g_strdup_printf("/ptimer/set_count policy=%s", policy_name),
738 g_memdup(&policy, 1), check_set_count, g_free);
739 g_free(tmp);
741 g_test_add_data_func_full(
742 tmp = g_strdup_printf("/ptimer/set_limit policy=%s", policy_name),
743 g_memdup(&policy, 1), check_set_limit, g_free);
744 g_free(tmp);
746 g_test_add_data_func_full(
747 tmp = g_strdup_printf("/ptimer/oneshot policy=%s", policy_name),
748 g_memdup(&policy, 1), check_oneshot, g_free);
749 g_free(tmp);
751 g_test_add_data_func_full(
752 tmp = g_strdup_printf("/ptimer/periodic policy=%s", policy_name),
753 g_memdup(&policy, 1), check_periodic, g_free);
754 g_free(tmp);
756 g_test_add_data_func_full(
757 tmp = g_strdup_printf("/ptimer/on_the_fly_mode_change policy=%s",
758 policy_name),
759 g_memdup(&policy, 1), check_on_the_fly_mode_change, g_free);
760 g_free(tmp);
762 g_test_add_data_func_full(
763 tmp = g_strdup_printf("/ptimer/on_the_fly_period_change policy=%s",
764 policy_name),
765 g_memdup(&policy, 1), check_on_the_fly_period_change, g_free);
766 g_free(tmp);
768 g_test_add_data_func_full(
769 tmp = g_strdup_printf("/ptimer/on_the_fly_freq_change policy=%s",
770 policy_name),
771 g_memdup(&policy, 1), check_on_the_fly_freq_change, g_free);
772 g_free(tmp);
774 g_test_add_data_func_full(
775 tmp = g_strdup_printf("/ptimer/run_with_period_0 policy=%s",
776 policy_name),
777 g_memdup(&policy, 1), check_run_with_period_0, g_free);
778 g_free(tmp);
780 g_test_add_data_func_full(
781 tmp = g_strdup_printf("/ptimer/run_with_delta_0 policy=%s",
782 policy_name),
783 g_memdup(&policy, 1), check_run_with_delta_0, g_free);
784 g_free(tmp);
786 g_test_add_data_func_full(
787 tmp = g_strdup_printf("/ptimer/periodic_with_load_0 policy=%s",
788 policy_name),
789 g_memdup(&policy, 1), check_periodic_with_load_0, g_free);
790 g_free(tmp);
792 g_test_add_data_func_full(
793 tmp = g_strdup_printf("/ptimer/oneshot_with_load_0 policy=%s",
794 policy_name),
795 g_memdup(&policy, 1), check_oneshot_with_load_0, g_free);
796 g_free(tmp);
799 static void add_all_ptimer_policies_comb_tests(void)
801 int last_policy = PTIMER_POLICY_TRIGGER_ONLY_ON_DECREMENT;
802 int policy = PTIMER_POLICY_DEFAULT;
804 for (; policy < (last_policy << 1); policy++) {
805 if ((policy & PTIMER_POLICY_TRIGGER_ONLY_ON_DECREMENT) &&
806 (policy & PTIMER_POLICY_NO_IMMEDIATE_TRIGGER)) {
807 /* Incompatible policy flag settings -- don't try to test them */
808 continue;
810 add_ptimer_tests(policy);
814 int main(int argc, char **argv)
816 int i;
818 g_test_init(&argc, &argv, NULL);
820 for (i = 0; i < QEMU_CLOCK_MAX; i++) {
821 main_loop_tlg.tl[i] = g_new0(QEMUTimerList, 1);
824 add_all_ptimer_policies_comb_tests();
826 qtest_allowed = true;
828 return g_test_run();