Debian Codegraph @

regressions/ck_pr/validate/ck_pr_store.c

raw
1 /*
2 * Copyright 2009 Samy Al Bahra.
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 "../../common.h"
28 #include <ck_pr.h>
29
30 #include <inttypes.h>
31 #include <stdbool.h>
32 #include <stdio.h>
33 #include <stdint.h>
34 #include <stdlib.h>
35 #include <unistd.h>
36
37 #ifndef R_REPEAT
38 #define R_REPEAT 200000
39 #endif
40
41 #define CK_PR_STORE_B(w) \
42 { \
43 uint##w##_t t = (uint##w##_t)-1, a = 0, b; \
44 ck_pr_store_##w(&b, 1ULL << (w - 1)); \
45 unsigned int i; \
46 printf("ck_pr_store_" #w ": "); \
47 if (w < 10) \
48 printf(" "); \
49 ck_pr_store_##w(&a, t); \
50 if (a != t) { \
51 printf("FAIL [%#" PRIx##w " != %#" PRIx##w "]\n", a, t); \
52 exit(EXIT_FAILURE); \
53 } \
54 for (i = 0; i < R_REPEAT; i++) { \
55 t = (uint##w##_t)common_rand(); \
56 ck_pr_store_##w(&a, t); \
57 if (a != t) { \
58 printf("FAIL [%#" PRIx##w " != %#" PRIx##w "]\n", a, t);\
59 exit(EXIT_FAILURE); \
60 } \
61 } \
62 rg_width(w); \
63 printf("SUCCESS\n"); \
64 }
65
66 #define CK_PR_STORE_W(m, w) \
67 { \
68 uint##m##_t f = 0; \
69 uint##w##_t j = (uint##w##_t)-1; \
70 ck_pr_store_##w((uint##w##_t *)(void *)&f, j); \
71 if (f != j) { \
72 printf("FAIL [%#" PRIx##m " != %#" PRIx##w "]\n", f, j);\
73 exit(EXIT_FAILURE); \
74 } \
75 }
76
77 static void
78 rg_width(int m)
79 {
80
81 /* Other architectures are bi-endian. */
82 #if !defined(__x86__) && !defined(__x86_64__)
83 return;
84 #endif
85
86 #ifdef CK_F_PR_STORE_64
87 if (m == 64) {
88 #if defined(CK_F_PR_STORE_32)
89 CK_PR_STORE_W(64, 32);
90 #endif
91 #if defined(CK_PR_STORE_16)
92 CK_PR_STORE_W(64, 16);
93 #endif
94 #if defined(CK_PR_STORE_8)
95 CK_PR_STORE_W(64, 8);
96 #endif
97 }
98 #endif /* CK_PR_STORE_64 */
99
100 #ifdef CK_F_PR_STORE_32
101 if (m == 32) {
102 #if defined(CK_F_PR_STORE_16)
103 CK_PR_STORE_W(32, 16);
104 #endif
105 #if defined(CK_PR_STORE_8)
106 CK_PR_STORE_W(32, 8);
107 #endif
108 }
109 #endif /* CK_PR_STORE_32 */
110
111 #if defined(CK_F_PR_STORE_16) && defined(CK_PR_STORE_8)
112 if (m == 16)
113 CK_PR_STORE_W(16, 8);
114 #endif /* CK_PR_STORE_16 && CK_PR_STORE_8 */
115
116 return;
117 }
118
119 int
120 main(void)
121 {
122 void *ptr;
123
124 #if defined(CK_F_PR_STORE_DOUBLE) && defined(CK_F_PR_LOAD_DOUBLE)
125 double d;
126
127 ck_pr_store_double(&d, 0.0);
128 if (ck_pr_load_double(&d) != 0.0) {
129 ck_error("Stored 0 in double, did not find 0.\n");
130 }
131 #endif
132
133 common_srand((unsigned int)getpid());
134
135 #ifdef CK_F_PR_STORE_64
136 CK_PR_STORE_B(64);
137 #endif
138
139 #ifdef CK_F_PR_STORE_32
140 CK_PR_STORE_B(32);
141 #endif
142
143 #ifdef CK_F_PR_STORE_16
144 CK_PR_STORE_B(16);
145 #endif
146
147 #ifdef CK_F_PR_STORE_8
148 CK_PR_STORE_B(8);
149 #endif
150 printf("ck_pr_store_ptr: ");
151 ck_pr_store_ptr(&ptr, (void *)(intptr_t)-1);
152 if (ptr != (void *)(intptr_t)(-1))
153 printf("Failed : %p != %p\n", ptr, (void *)(intptr_t)-1);
154 else
155 printf("SUCCESS\n");
156
157 return (0);
158 }