target/sparc: Handle bus errors in mmu_probe()
[qemu/ar7.git] / tests / ptimer-test.c
blob5b20e91599e54f7f3f464af710316b7bb3b3ce87
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 QEMU_TIMER_ATTR_ALL);
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,
61 QEMU_TIMER_ATTR_ALL);
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);
73 triggered = false;
75 ptimer_set_count(ptimer, 1000);
76 g_assert_cmpuint(ptimer_get_count(ptimer), ==, 1000);
77 g_assert_false(triggered);
78 ptimer_free(ptimer);
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);
87 triggered = false;
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);
98 ptimer_free(ptimer);
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);
108 triggered = false;
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);
119 ptimer_stop(ptimer);
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);
135 if (no_round_down) {
136 g_assert_false(triggered);
137 } else {
138 g_assert_true(triggered);
140 triggered = false;
143 qemu_clock_step(2000000);
145 g_assert_cmpuint(ptimer_get_count(ptimer), ==, 0);
147 if (no_round_down) {
148 g_assert_true(triggered);
150 triggered = false;
151 } else {
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);
193 ptimer_stop(ptimer);
195 triggered = false;
197 qemu_clock_step(2000000 * 12 + 1);
199 g_assert_cmpuint(ptimer_get_count(ptimer), ==, 0);
200 g_assert_false(triggered);
201 ptimer_free(ptimer);
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);
215 triggered = false;
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);
224 qemu_clock_step(1);
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);
234 qemu_clock_step(1);
236 g_assert_cmpuint(ptimer_get_count(ptimer), ==,
237 wrap_policy ? 0 : (no_round_down ? 10 : 9));
238 g_assert_true(triggered);
240 triggered = false;
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);
253 qemu_clock_step(1);
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);
269 triggered = false;
271 ptimer_set_count(ptimer, 3);
273 g_assert_cmpuint(ptimer_get_count(ptimer), ==, 3);
274 g_assert_false(triggered);
276 qemu_clock_step(1);
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);
287 ptimer_stop(ptimer);
288 triggered = false;
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);
305 triggered = false;
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);
319 } else {
320 g_assert_true(triggered);
323 triggered = false;
325 qemu_clock_step(1);
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);
335 } else {
336 g_assert_false(triggered);
339 triggered = false;
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);
351 ptimer_stop(ptimer);
353 triggered = false;
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);
369 ptimer_free(ptimer);
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);
380 triggered = false;
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);
402 triggered = false;
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);
416 ptimer_free(ptimer);
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);
426 triggered = false;
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);
449 ptimer_free(ptimer);
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);
459 triggered = false;
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);
482 ptimer_free(ptimer);
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);
491 triggered = false;
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);
500 ptimer_free(ptimer);
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);
514 triggered = false;
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);
524 } else {
525 g_assert_true(triggered);
528 triggered = false;
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);
539 triggered = false;
540 } else {
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);
563 triggered = false;
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);
572 } else {
573 g_assert_true(triggered);
576 triggered = false;
578 qemu_clock_step(1);
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);
588 } else {
589 g_assert_false(triggered);
592 triggered = false;
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);
605 ptimer_stop(ptimer);
606 ptimer_free(ptimer);
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);
618 triggered = false;
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);
627 } else {
628 g_assert_true(triggered);
631 triggered = false;
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);
639 } else {
640 g_assert_false(triggered);
643 triggered = false;
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);
653 triggered = false;
655 qemu_clock_step(2000000 + 1);
657 g_assert_cmpuint(ptimer_get_count(ptimer), ==, 0);
659 if (continuous_trigger) {
660 g_assert_true(triggered);
661 } else {
662 g_assert_false(triggered);
665 ptimer_stop(ptimer);
666 ptimer_free(ptimer);
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);
677 triggered = false;
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);
686 } else {
687 g_assert_true(triggered);
690 triggered = false;
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);
698 } else {
699 g_assert_false(triggered);
702 ptimer_free(ptimer);
705 static void add_ptimer_tests(uint8_t policy)
707 char policy_name[256] = "";
708 char *tmp;
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);
741 g_free(tmp);
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);
746 g_free(tmp);
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);
751 g_free(tmp);
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);
756 g_free(tmp);
758 g_test_add_data_func_full(
759 tmp = g_strdup_printf("/ptimer/on_the_fly_mode_change policy=%s",
760 policy_name),
761 g_memdup(&policy, 1), check_on_the_fly_mode_change, g_free);
762 g_free(tmp);
764 g_test_add_data_func_full(
765 tmp = g_strdup_printf("/ptimer/on_the_fly_period_change policy=%s",
766 policy_name),
767 g_memdup(&policy, 1), check_on_the_fly_period_change, g_free);
768 g_free(tmp);
770 g_test_add_data_func_full(
771 tmp = g_strdup_printf("/ptimer/on_the_fly_freq_change policy=%s",
772 policy_name),
773 g_memdup(&policy, 1), check_on_the_fly_freq_change, g_free);
774 g_free(tmp);
776 g_test_add_data_func_full(
777 tmp = g_strdup_printf("/ptimer/run_with_period_0 policy=%s",
778 policy_name),
779 g_memdup(&policy, 1), check_run_with_period_0, g_free);
780 g_free(tmp);
782 g_test_add_data_func_full(
783 tmp = g_strdup_printf("/ptimer/run_with_delta_0 policy=%s",
784 policy_name),
785 g_memdup(&policy, 1), check_run_with_delta_0, g_free);
786 g_free(tmp);
788 g_test_add_data_func_full(
789 tmp = g_strdup_printf("/ptimer/periodic_with_load_0 policy=%s",
790 policy_name),
791 g_memdup(&policy, 1), check_periodic_with_load_0, g_free);
792 g_free(tmp);
794 g_test_add_data_func_full(
795 tmp = g_strdup_printf("/ptimer/oneshot_with_load_0 policy=%s",
796 policy_name),
797 g_memdup(&policy, 1), check_oneshot_with_load_0, g_free);
798 g_free(tmp);
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 */
810 continue;
812 add_ptimer_tests(policy);
816 int main(int argc, char **argv)
818 int i;
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;
830 return g_test_run();