Debian Codegraph @

regressions/ck_pr/validate/ck_pr_fax.c

raw
1 /*
2 * Copyright 2011 David Joseph.
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 *
14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24 * SUCH DAMAGE.
25 */
26
27 #include <stdio.h>
28 #include <stdlib.h>
29 #include <unistd.h>
30 #include <ck_pr.h>
31
32 #include "../../common.h"
33 #define REPEAT 2000000
34
35 #define TEST_FAX_FN(S, T, M) \
36 static T \
37 test_faa_##S(M *target, T delta) \
38 { \
39 T previous = (T)*target; \
40 *target = (T)*target + delta; \
41 \
42 return (previous); \
43 } \
44 static T \
45 test_fas_##S(M *target, T update) \
46 { \
47 T previous = *target; \
48 *target = update; \
49 \
50 return (previous); \
51 }
52
53 #define TEST_FAX_FN_S(S, T) TEST_FAX_FN(S, T, T)
54
55 TEST_FAX_FN_S(int, int)
56 TEST_FAX_FN_S(uint, unsigned int)
57
58 #undef TEST_FAX_FN_S
59 #undef TEST_FAX_FN
60
61 #define TEST_FAX(K, S, T, D) \
62 static void \
63 run_test_##K##_##S(void) \
64 { \
65 int i, r; \
66 T x = 0, y = 0, x_b, y_b; \
67 \
68 puts("***TESTING ck_pr_"#K"_"#S"***"); \
69 common_srand((unsigned int)getpid()); \
70 for (i = 0; i < REPEAT; ++i) { \
71 r = common_rand(); \
72 x_b = test_##K##_##S(&x, r); \
73 y_b = ck_pr_##K##_##S(&y, r); \
74 \
75 if (x_b != y_b) { \
76 printf("Serial fetch does not match ck_pr fetch.\n" \
77 "\tSerial: %"#D"\n" \
78 "\tck_pr: %"#D"\n", \
79 x_b, y_b); \
80 \
81 return; \
82 } \
83 } \
84 \
85 printf("Final result:\n" \
86 "\tSerial: %"#D"\n" \
87 "\tck_pr: %"#D"\n", \
88 x, y); \
89 (x == y) ? puts("SUCCESS.") \
90 : puts("FAILURE."); \
91 \
92 return; \
93 } \
94
95
96 #define GENERATE_TEST(K) \
97 TEST_FAX(K, int, int, d) \
98 TEST_FAX(K, uint, unsigned int, u) \
99 static void \
100 run_test_##K(void) \
101 { \
102 run_test_##K##_int(); \
103 run_test_##K##_uint(); \
104 }
105
106 GENERATE_TEST(faa)
107 GENERATE_TEST(fas)
108
109 #undef GENERATE_TEST
110 #undef TEST_FAX
111
112 int
113 main(void)
114 {
115 run_test_faa();
116 run_test_fas();
117
118 return (0);
119 }
120
121