Debian Codegraph @

gcc/testsuite/gcc.target/s390/htm-builtins-1.c

raw
1 /* Functional tests of the htm __builtin_... macros. */
2
3 /* { dg-do run } */
4 /* { dg-require-effective-target htm } */
5 /* { dg-options "-O3 -march=zEC12 -mzarch" } */
6
7 /* ---------------------------- included header files ---------------------- */
8
9 #include <stdio.h>
10 #include <string.h>
11 #include <stdint.h>
12 #include <htmintrin.h>
13
14 /* ---------------------------- local definitions -------------------------- */
15
16 #define DEFAULT_MAX_REPETITIONS 7
17 #define DEFAULT_REQUIRED_QUORUM 4
18 #define NUM_WARMUP_RUNS 2
19
20 /* ---------------------------- local macros ------------------------------- */
21
22 #define TEST_DF_REP(name) \
23 { #name, name, DEFAULT_MAX_REPETITIONS, DEFAULT_REQUIRED_QUORUM }
24 #define TEST_NO_REP(name) { #name, name, 1, 1 }
25
26 /* ---------------------------- local types -------------------------------- */
27
28 typedef int (*test_func_t)(void);
29
30 typedef struct
31 {
32 const char *name;
33 test_func_t test_func;
34 int max_repetitions;
35 int required_quorum;
36 } test_table_entry_t;
37
38 /* ---------------------------- local variables ---------------------------- */
39
40 __attribute__ ((aligned(256))) static struct __htm_tdb local_tdb256;
41 static struct __htm_tdb local_tdb;
42 static int do_dump_tdb = 0;
43
44 /* ---------------------------- exported variables (globals) --------------- */
45
46 __attribute__ ((aligned(256))) struct
47 {
48 float float_1;
49 float float_2;
50 float float_3;
51 } global = { 1.0, 2.5, 0.0 };
52
53 __attribute__ ((aligned(256))) struct
54 {
55 volatile uint64_t c1;
56 char pad1[256 - sizeof(uint64_t)];
57 volatile uint64_t c2;
58 char pad2[256 - sizeof(uint64_t)];
59 volatile uint64_t c3;
60 } counters = { 0 };
61
62 /* ---------------------------- local helper functions --------------------- */
63
64 static void dump_tdb (struct __htm_tdb *tdb)
65 {
66 unsigned char *p;
67 int i;
68 int j;
69
70 if (do_dump_tdb == 0)
71 {
72 return;
73 }
74 p = (unsigned char *)tdb;
75 for (i = 0; i < 16; i++)
76 {
77 fprintf (stderr, "0x%02x ", i * 16);
78 for (j = 0; j < 16; j++)
79 {
80 fprintf (stderr, "%02x", (int)p[i * 16 + j]);
81 if (j < 15)
82 {
83 fprintf (stderr, " ");
84 }
85 if (j == 7)
86 {
87 fprintf (stderr, " ");
88 }
89 }
90 fprintf (stderr, "\n");
91 }
92
93 return;
94 }
95
96 /* ---------------------------- local test functions ----------------------- */
97
98 /* Check values of the constants defined in htmintrin.h. */
99 static int test_constants (void)
100 {
101 if (_HTM_TBEGIN_STARTED != 0)
102 {
103 return 100 * _HTM_TBEGIN_STARTED + 1;
104 }
105 if (_HTM_TBEGIN_INDETERMINATE != 1)
106 {
107 return 100 * _HTM_TBEGIN_INDETERMINATE + 2;
108 }
109 if (_HTM_TBEGIN_TRANSIENT != 2)
110 {
111 return 100 * _HTM_TBEGIN_TRANSIENT + 3;
112 }
113 if (_HTM_TBEGIN_PERSISTENT != 3)
114 {
115 return 100 * _HTM_TBEGIN_PERSISTENT + 4;
116 }
117
118 return 0;
119 }
120
121 static int test_tbegin_ntstg_tend (void)
122 {
123 int rc;
124
125 counters.c1 = 0;
126 counters.c2 = 0;
127 if ((rc = __builtin_tbegin ((void *)0)) == 0)
128 {
129 __builtin_non_tx_store ((uint64_t *)&counters.c1, 1);
130 counters.c2 = 2;
131 rc = __builtin_tend ();
132 if (rc != 0)
133 {
134 return 100 * rc + 5;
135 }
136 if (counters.c1 != 1)
137 {
138 return 100 * counters.c1 + 2;
139 }
140 if (counters.c2 != 2)
141 {
142 return 100 * counters.c2 + 3;
143 }
144 }
145 else
146 {
147 return 100 * rc + 4;
148 }
149
150 return 0;
151 }
152
153 static int test_tbegin_ntstg_tabort (void)
154 {
155 float f;
156
157 counters.c1 = 0;
158 counters.c2 = 0;
159 f = 0;
160 if (__builtin_tbegin ((void *)0) == 0)
161 {
162 __builtin_non_tx_store ((uint64_t *)&counters.c1, 1);
163 counters.c2 = 2;
164 f = 1;
165 __builtin_tabort (256);
166 return 1;
167 }
168 if (counters.c1 != 1)
169 {
170 return 100 * counters.c1 + 2;
171 }
172 if (counters.c2 != 0)
173 {
174 return 100 * counters.c2 + 3;
175 }
176 if (f != 0)
177 {
178 return 100 * f + 4;
179 }
180
181 return 0;
182 }
183
184 static int test_tbegin_nofloat (void)
185 {
186 int rc;
187
188 counters.c1 = 0;
189 counters.c2 = 0;
190 if ((rc = __builtin_tbegin_nofloat ((void *)0)) == 0)
191 {
192 __builtin_non_tx_store ((uint64_t *)&counters.c1, 1);
193 counters.c2 = 2;
194 rc = __builtin_tend ();
195 if (rc != 0)
196 {
197 return 100 * rc + 5;
198 }
199 if (counters.c1 != 1)
200 {
201 return 100 * counters.c1 + 2;
202 }
203 if (counters.c2 != 2)
204 {
205 return 100 * counters.c2 + 3;
206 }
207 }
208 else
209 {
210 return 100 * rc + 4;
211 }
212
213 return 0;
214 }
215
216 static int test_tbegin_retry (void)
217 {
218 int rc;
219
220 counters.c1 = 0;
221 counters.c2 = 0;
222 counters.c3 = 0;
223 if ((rc = __builtin_tbegin_retry ((void *)0, 5)) == 0)
224 {
225 int do_abort;
226
227 do_abort = (counters.c1 == 0) ? 1 : 0;
228 __builtin_non_tx_store (
229 (uint64_t *)&counters.c1, counters.c1 + 1);
230 if (do_abort == 1)
231 {
232 __builtin_tabort (256);
233 }
234 counters.c2 = counters.c2 + 10;
235 __builtin_non_tx_store ((uint64_t *)&counters.c3, 3);
236 rc = __builtin_tend ();
237 if (rc != 0)
238 {
239 return 100 * rc + 5;
240 }
241 if (counters.c1 != 2)
242 {
243 return 100 * counters.c1 + 2;
244 }
245 if (counters.c2 != 10)
246 {
247 return 100 * counters.c2 + 3;
248 }
249 if (counters.c3 != 3)
250 {
251 return 100 * counters.c3 + 6;
252 }
253 }
254 else
255 {
256 return 100 * rc + 4;
257 }
258
259 return 0;
260 }
261
262 static int test_tbegin_retry_nofloat (void)
263 {
264 int rc;
265
266 counters.c1 = 0;
267 counters.c2 = 0;
268 counters.c3 = 0;
269 if ((rc = __builtin_tbegin_retry_nofloat ((void *)0, 5)) == 0)
270 {
271 int do_abort;
272
273 do_abort = (counters.c1 == 0) ? 1 : 0;
274 __builtin_non_tx_store (
275 (uint64_t *)&counters.c1, counters.c1 + 1);
276 if (do_abort == 1)
277 {
278 __builtin_tabort (256);
279 }
280 counters.c2 = counters.c2 + 10;
281 __builtin_non_tx_store ((uint64_t *)&counters.c3, 3);
282 rc = __builtin_tend ();
283 if (rc != 0)
284 {
285 return 100 * rc + 5;
286 }
287 if (counters.c1 != 2)
288 {
289 return 100 * counters.c1 + 2;
290 }
291 if (counters.c2 != 10)
292 {
293 return 100 * counters.c2 + 3;
294 }
295 if (counters.c3 != 3)
296 {
297 return 100 * counters.c3 + 6;
298 }
299 }
300 else
301 {
302 return 100 * rc + 4;
303 }
304
305 return 0;
306 }
307
308 static int test_tbegin_aborts (void)
309 {
310 float f;
311 int rc;
312
313 f = 77;
314 if ((rc = __builtin_tbegin ((void *)0)) == 0)
315 {
316 f = 88;
317 __builtin_tabort (256);
318 return 2;
319 }
320 else if (rc != 2)
321 {
322 return 3;
323 }
324 if (f != 77)
325 {
326 return 4;
327 }
328 f = 66;
329 if ((rc = __builtin_tbegin ((void *)0)) == 0)
330 {
331 f = 99;
332 __builtin_tabort (257);
333 return 5;
334 }
335 else if (rc != 3)
336 {
337 return 100 * rc + 6;
338 }
339 if (f != 66)
340 {
341 return 100 * f + 7;
342 }
343 if ((rc = __builtin_tbegin ((void *)0)) == 0)
344 {
345 global.float_3 = global.float_1 + global.float_2;
346 rc = __builtin_tend ();
347 if (rc != 0)
348 {
349 return 100 * rc + 8;
350 }
351 }
352 else
353 {
354 return 100 * rc + 9;
355 }
356 if (global.float_3 != global.float_1 + global.float_2)
357 {
358 return 100 * rc + 10;
359 }
360
361 return 0;
362 }
363
364 static __attribute__((noinline)) void indirect_abort(int abort_code)
365 {
366 __builtin_tabort (abort_code);
367
368 return;
369 }
370
371 static int test_tbegin_indirect_aborts (void)
372 {
373 float f;
374 int rc;
375
376 f = 77;
377 if ((rc = __builtin_tbegin ((void *)0)) == 0)
378 {
379 f = 88;
380 indirect_abort(256);
381 return 2;
382 }
383 else if (rc != 2)
384 {
385 return 100 * rc + 3;
386 }
387 if (f != 77)
388 {
389 return 100 * rc + 4;
390 }
391 f = 66;
392 if ((rc = __builtin_tbegin ((void *)0)) == 0)
393 {
394 f = 99;
395 indirect_abort(257);
396 return 5;
397 }
398 else if (rc != 3)
399 {
400 return 100 * rc + 6;
401 }
402 if (f != 66)
403 {
404 return 100 * f + 7;
405 }
406
407 return 0;
408 }
409
410 static int test_tbegin_nofloat_aborts (void)
411 {
412 int rc;
413
414 if ((rc = __builtin_tbegin_nofloat ((void *)0)) == 0)
415 {
416 __builtin_tabort (256);
417 return 2;
418 }
419 if ((rc = __builtin_tbegin_nofloat ((void *)0)) == 0)
420 {
421 __builtin_tabort (257);
422 return 1005;
423 }
424 else if (rc != 3)
425 {
426 return 1000 * rc + 6;
427 }
428
429 return 0;
430 }
431
432 static int test_tbegin_nofloat_indirect_aborts (void)
433 {
434 int rc;
435
436 if ((rc = __builtin_tbegin_nofloat ((void *)0)) == 0)
437 {
438 indirect_abort (256);
439 return 2;
440 }
441 if ((rc = __builtin_tbegin_nofloat ((void *)0)) == 0)
442 {
443 indirect_abort (257);
444 return 1005;
445 }
446 else if (rc != 3)
447 {
448 return 1000 * rc + 6;
449 }
450
451 return 0;
452 }
453
454 static
455 int _test_tbegin_retry_aborts (int retries, uint64_t abort_code)
456 {
457 int rc;
458
459 counters.c1 = 0;
460 if ((rc = __builtin_tbegin_retry ((void *)0, retries)) == 0)
461 {
462 __builtin_non_tx_store ((uint64_t *)&counters.c1, counters.c1 + 1);
463 __builtin_tabort (abort_code);
464 return 2;
465 }
466 else
467 {
468 if ((abort_code & 1) == 0)
469 {
470 if (rc != 2)
471 {
472 return 100 * rc + 2003;
473 }
474 else if (counters.c1 != (uint64_t)retries + 1)
475 {
476 return 1000 * counters.c1 + 100 * retries + 4;
477 }
478 }
479 else
480 {
481 if (rc != 3)
482 {
483 return 100 * rc + 3005;
484 }
485 else if (counters.c1 != 1)
486 {
487 return 1000 * counters.c1 + 100 * retries + 6;
488 }
489 }
490 }
491
492 return 0;
493 }
494
495 static int test_tbegin_retry_aborts (void)
496 {
497 int rc;
498 int retries;
499
500 for (retries = 1; retries <= 3; retries++)
501 {
502 rc = _test_tbegin_retry_aborts (retries, 256);
503 if (rc != 0)
504 {
505 return 10000 + rc;
506 }
507 }
508 for (retries = 1; retries <= 3; retries++)
509 {
510 rc = _test_tbegin_retry_aborts (retries, 257);
511 if (rc != 0)
512 {
513 return 20000 + rc;
514 }
515 }
516 if ((rc = __builtin_tbegin_retry ((void *)0, 5)) == 0)
517 {
518 global.float_3 = global.float_1 + global.float_2;
519 rc = __builtin_tend ();
520 if (rc != 0)
521 {
522 return 30000 + 100 * rc + 6;
523 }
524 }
525 else
526 {
527 return 30000 + 100 * rc + 7;
528 }
529
530 return 0;
531 }
532
533 static int _test_tbegin_retry_nofloat_aborts (int retries, uint64_t abort_code)
534 {
535 int rc;
536
537 counters.c1 = 0;
538 if ((rc = __builtin_tbegin_retry_nofloat ((void *)0, retries)) == 0)
539 {
540 __builtin_non_tx_store ((uint64_t *)&counters.c1, counters.c1 + 1);
541 __builtin_tabort (abort_code);
542 return 2;
543 }
544 else
545 {
546 if ((abort_code & 1) == 0)
547 {
548 if (rc != 2)
549 {
550 return 100 * rc + 2003;
551 }
552 else if (counters.c1 != (uint64_t)retries + 1)
553 {
554 return 1000 * counters.c1 + 100 * retries + 4;
555 }
556 }
557 else
558 {
559 if (rc != 3)
560 {
561 return 100 * rc + 3005;
562 }
563 else if (counters.c1 != 1)
564 {
565 return 1000 * counters.c1 + 100 * retries + 6;
566 }
567 }
568 }
569
570 return 0;
571 }
572
573 static int test_tbegin_retry_nofloat_aborts (void)
574 {
575 int rc;
576 int retries;
577
578 for (retries = 1; retries <= 3; retries++)
579 {
580 rc = _test_tbegin_retry_nofloat_aborts (retries, 256);
581 if (rc != 0)
582 {
583 return 10 * retries + rc;
584 }
585 }
586 for (retries = 1; retries <= 3; retries++)
587 {
588 rc = _test_tbegin_retry_nofloat_aborts (retries, 257);
589 if (rc != 0)
590 {
591 return 10000 + 10 * retries + rc;
592 }
593 }
594
595 return 0;
596 }
597
598 static int test_tbegin_tdb (void)
599 {
600 int rc;
601
602 local_tdb.format = 0;
603 if ((rc = __builtin_tbegin (&local_tdb)) == 0)
604 {
605 rc = __builtin_tend ();
606 if (rc != 0)
607 {
608 return 100 * rc + 1;
609 }
610 if (local_tdb.format != 0)
611 {
612 dump_tdb (&local_tdb);
613 return 100 * local_tdb.format + 2;
614 }
615 }
616 else
617 {
618 return 100 * rc + 3;
619 }
620 local_tdb.format = 0;
621 if ((rc = __builtin_tbegin (&local_tdb)) == 0)
622 {
623 __builtin_tabort (257);
624 return 4;
625 }
626 else
627 {
628 if (rc != 3)
629 {
630 return 100 * rc + 5;
631 }
632 if (local_tdb.format != 1)
633 {
634 dump_tdb (&local_tdb);
635 return 100 * local_tdb.format + 6;
636 }
637 }
638 local_tdb256.format = 0;
639 if ((rc = __builtin_tbegin (&local_tdb256)) == 0)
640 {
641 rc = __builtin_tend ();
642 if (rc != 0)
643 {
644 return 1100 * rc + 1;
645 }
646 if (local_tdb256.format != 0)
647 {
648 dump_tdb (&local_tdb256);
649 return 1100 * local_tdb256.format + 2;
650 }
651 }
652 else
653 {
654 return 1100 * rc + 3;
655 }
656 local_tdb256.format = 0;
657 if ((rc = __builtin_tbegin (&local_tdb256)) == 0)
658 {
659 __builtin_tabort (257);
660 return 2004;
661 }
662 else
663 {
664 if (rc != 3)
665 {
666 return 2100 * rc + 5;
667 }
668 if (local_tdb256.format != 1)
669 {
670 dump_tdb (&local_tdb256);
671 return 2100 * local_tdb256.format + 6;
672 }
673 }
674
675 return 0;
676 }
677
678 static int test_tbegin_nofloat_tdb (void)
679 {
680 int rc;
681
682 local_tdb.format = 0;
683 if ((rc = __builtin_tbegin_nofloat (&local_tdb)) == 0)
684 {
685 rc = __builtin_tend ();
686 if (rc != 0)
687 {
688 return 100 * rc + 1;
689 }
690 if (local_tdb.format != 0)
691 {
692 dump_tdb (&local_tdb);
693 return 100 * local_tdb.format + 2;
694 }
695 }
696 else
697 {
698 return 3;
699 }
700 local_tdb.format = 0;
701 if ((rc = __builtin_tbegin_nofloat (&local_tdb)) == 0)
702 {
703 __builtin_tabort (257);
704 return 4;
705 }
706 else
707 {
708 if (rc != 3)
709 {
710 return 100 * rc + 5;
711 }
712 if (local_tdb.format != 1)
713 {
714 dump_tdb (&local_tdb);
715 return 100 * local_tdb.format + 6;
716 }
717 }
718 local_tdb256.format = 0;
719 if ((rc = __builtin_tbegin_nofloat (&local_tdb256)) == 0)
720 {
721 rc = __builtin_tend ();
722 if (rc != 0)
723 {
724 return 1100 * rc + 1;
725 }
726 if (local_tdb256.format != 0)
727 {
728 dump_tdb (&local_tdb256);
729 return 1100 * local_tdb256.format + 2;
730 }
731 }
732 else
733 {
734 return 1003;
735 }
736 local_tdb256.format = 0;
737 if ((rc = __builtin_tbegin_nofloat (&local_tdb256)) == 0)
738 {
739 __builtin_tabort (257);
740 return 2004;
741 }
742 else
743 {
744 if (rc != 3)
745 {
746 return 2100 * rc + 5;
747 }
748 if (local_tdb256.format != 1)
749 {
750 dump_tdb (&local_tdb256);
751 return 2100 * local_tdb256.format + 6;
752 }
753 }
754
755 return 0;
756 }
757
758 static int test_tbegin_retry_tdb (void)
759 {
760 int rc;
761
762 local_tdb256.format = 0;
763 if ((rc = __builtin_tbegin_retry (&local_tdb256, 2)) == 0)
764 {
765 rc = __builtin_tend ();
766 if (rc != 0)
767 {
768 return 1100 * rc + 1;
769 }
770 if (local_tdb256.format != 0)
771 {
772 dump_tdb (&local_tdb256);
773 return 1100 * local_tdb256.format + 2;
774 }
775 }
776 else
777 {
778 return 1003;
779 }
780 local_tdb256.format = 0;
781 if ((rc = __builtin_tbegin_retry (&local_tdb256, 2)) == 0)
782 {
783 __builtin_tabort (257);
784 return 2004;
785 }
786 else
787 {
788 if (rc != 3)
789 {
790 return 2100 * rc + 5;
791 }
792 if (local_tdb256.format != 1)
793 {
794 dump_tdb (&local_tdb256);
795 return 2100 * local_tdb256.format + 6;
796 }
797 }
798
799 return 0;
800 }
801
802 static int test_tbegin_retry_nofloat_tdb (void)
803 {
804 int rc;
805
806 local_tdb.format = 0;
807 if ((rc = __builtin_tbegin_retry_nofloat (&local_tdb, 2)) == 0)
808 {
809 rc = __builtin_tend ();
810 if (rc != 0)
811 {
812 return 100 * rc + 1;
813 }
814 if (local_tdb.format != 0)
815 {
816 dump_tdb (&local_tdb);
817 return 100 * local_tdb.format + 2;
818 }
819 }
820 else
821 {
822 return 100 * rc + 3;
823 }
824 local_tdb.format = 0;
825 if ((rc = __builtin_tbegin_retry_nofloat (&local_tdb, 2)) == 0)
826 {
827 __builtin_tabort (257);
828 return 4;
829 }
830 else
831 {
832 if (rc != 3)
833 {
834 return 100 * rc + 5;
835 }
836 if (local_tdb.format != 1)
837 {
838 dump_tdb (&local_tdb);
839 return 100 * local_tdb.format + 6;
840 }
841 }
842 local_tdb256.format = 0;
843 if ((rc = __builtin_tbegin_retry_nofloat (&local_tdb256, 2)) == 0)
844 {
845 rc = __builtin_tend ();
846 if (rc != 0)
847 {
848 return 1100 * rc + 1;
849 }
850 if (local_tdb256.format != 0)
851 {
852 dump_tdb (&local_tdb256);
853 return 1100 * local_tdb256.format + 2;
854 }
855 }
856 else
857 {
858 return 1100 * rc + 3;
859 }
860 local_tdb256.format = 0;
861 if ((rc = __builtin_tbegin_retry_nofloat (&local_tdb256, 2)) == 0)
862 {
863 __builtin_tabort (257);
864 return 2004;
865 }
866 else
867 {
868 if (rc != 3)
869 {
870 return 2100 * rc + 5;
871 }
872 if (local_tdb256.format != 1)
873 {
874 dump_tdb (&local_tdb256);
875 return 2100 * local_tdb256.format + 6;
876 }
877 }
878
879 return 0;
880 }
881
882 static int test_etnd (void)
883 {
884 int rc;
885
886 counters.c1 = 0;
887 counters.c2 = 0;
888 counters.c3 = 0;
889 if ((rc = __builtin_tbegin ((void *)0)) == 0)
890 {
891 counters.c1 = __builtin_tx_nesting_depth ();
892 if (__builtin_tbegin ((void *)0) == 0)
893 {
894 counters.c2 = __builtin_tx_nesting_depth ();
895 if (__builtin_tbegin ((void *)0) == 0)
896 {
897 counters.c3 = __builtin_tx_nesting_depth ();
898 __builtin_tend ();
899 }
900 __builtin_tend ();
901 }
902 __builtin_tend ();
903 }
904 else
905 {
906 return 100 * rc + 1;
907 }
908 if (counters.c1 != 1)
909 {
910 return 100 * counters.c1 + 2;
911 }
912 if (counters.c2 != 2)
913 {
914 return 100 * counters.c2 + 3;
915 }
916 if (counters.c3 != 3)
917 {
918 return 100 * counters.c3 + 4;
919 }
920
921 return 0;
922 }
923
924 static int test_tbeginc (void)
925 {
926 int rc;
927
928 counters.c1 = 0;
929 __builtin_tbeginc ();
930 counters.c1 = 1;
931 rc = __builtin_tend ();
932 if (rc != 0)
933 {
934 return 10000 * rc + 1;
935 }
936 if (counters.c1 != 1)
937 {
938 return 100000 * counters.c1 + 3;
939 }
940
941 return 0;
942 }
943
944 /* ---------------------------- local testing framework functions ---------- */
945
946 static int run_one_test (const test_table_entry_t *test_entry)
947 {
948 int do_print_passes;
949 int succeeded;
950 int rc;
951 int i;
952
953 /* Warmup run to get all necessary data and instruction pages into the page
954 * tables. */
955 {
956 int run;
957
958 do_dump_tdb = 0;
959 for (run = 0; run < NUM_WARMUP_RUNS; run++)
960 {
961 test_entry->test_func ();
962 }
963 do_dump_tdb = 1;
964 }
965 do_print_passes = (
966 test_entry->required_quorum != 1 ||
967 test_entry->max_repetitions != 1);
968 printf ("RRR RUN %s\n", test_entry->name);
969 if (do_print_passes == 1)
970 {
971 printf (
972 " (requires %d successful out of %d runs)\n",
973 test_entry->required_quorum,
974 test_entry->max_repetitions);
975 }
976 succeeded = 0;
977 rc = 0;
978 for (rc = 0, i = 0; i < test_entry->max_repetitions; i++)
979 {
980 if (do_print_passes == 1)
981 {
982 if (i == 0)
983 {
984 printf (" ");
985 }
986 else
987 {
988 printf (",");
989 }
990 }
991 rc = test_entry->test_func ();
992 if (rc == 0)
993 {
994 if (do_print_passes == 1)
995 {
996 printf (" success");
997 }
998 succeeded++;
999 if (succeeded >= test_entry->required_quorum)
1000 {
1001 break;
1002 }
1003 }
1004 else
1005 {
1006 printf (" failed (rc = %d)", rc);
1007 }
1008 }
1009 if (do_print_passes == 1 || rc != 0)
1010 {
1011 printf ("\n");
1012 }
1013 if (succeeded >= test_entry->required_quorum)
1014 {
1015 printf ("+++ OK %s\n", test_entry->name);
1016
1017 return 0;
1018 }
1019 else
1020 {
1021 printf ("--- FAIL %s\n", test_entry->name);
1022
1023 return (rc != 0) ? rc : -1;
1024 }
1025 }
1026
1027 static int run_all_tests (const test_table_entry_t *test_table)
1028 {
1029 const test_table_entry_t *test;
1030 int rc;
1031
1032 for (
1033 rc = 0, test = &test_table[0];
1034 test->test_func != NULL && rc == 0; test++)
1035 {
1036 rc = run_one_test (test);
1037 }
1038
1039 return rc;
1040 }
1041
1042 /* ---------------------------- interface functions ------------------------ */
1043
1044 int main (void)
1045 {
1046 const test_table_entry_t test_table[] = {
1047 TEST_NO_REP (test_constants),
1048 TEST_DF_REP (test_tbegin_ntstg_tend),
1049 TEST_DF_REP (test_tbegin_ntstg_tabort),
1050 TEST_DF_REP (test_tbegin_nofloat),
1051 TEST_NO_REP (test_tbegin_retry),
1052 TEST_NO_REP (test_tbegin_retry_nofloat),
1053 TEST_DF_REP (test_tbegin_aborts),
1054 TEST_DF_REP (test_tbegin_indirect_aborts),
1055 TEST_DF_REP (test_tbegin_nofloat_aborts),
1056 TEST_DF_REP (test_tbegin_nofloat_indirect_aborts),
1057 TEST_NO_REP (test_tbegin_retry_aborts),
1058 TEST_NO_REP (test_tbegin_retry_nofloat_aborts),
1059 TEST_DF_REP (test_tbegin_tdb),
1060 TEST_DF_REP (test_tbegin_nofloat_tdb),
1061 TEST_NO_REP (test_tbegin_retry_tdb),
1062 TEST_NO_REP (test_tbegin_retry_nofloat_tdb),
1063 TEST_DF_REP (test_etnd),
1064 TEST_DF_REP (test_tbeginc),
1065 { (void *)0, 0, 0 }
1066 };
1067
1068 {
1069 int rc;
1070
1071 rc = run_all_tests (test_table);
1072
1073 return rc;
1074 }
1075 }