-
Notifications
You must be signed in to change notification settings - Fork 26
/
Copy pathtest.h
214 lines (177 loc) · 6.26 KB
/
test.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
/*
Copyright (C) 2010, 2013 William Hart
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS''
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef BSDNT_TEST_H
#define BSDNT_TEST_H
#include "nn.h"
#include "zz.h"
#include "config.h"
#ifdef __cplusplus
extern "C" {
#endif
#if WANT_REDZONES
#define REDZONE_WORDS 4 /* number of words of redzone */
#else
#define REDZONE_WORDS 0
#endif
#define REDZONE_BYTE 0xA /* byte of data to use in a redzone */
#define checkpoint_rand(s) \
do { \
printf(s); \
bsdnt_printf("%wx\n", randword(state)); \
} while (0)
#define TEST_START(XXX, YYY) \
do { \
long __count; \
const char * __test_name = #XXX; \
for (__count = 0; __count < YYY && result == 1; __count++)
#define TEST_END \
if (!result && __count) printf("Test %s, iteration %ld...", __test_name, __count); \
gc_cleanup(); \
} while (0)
#define test_zz_aliasing(xxx, yyy, s, t, tz) \
do { \
int __resa; \
xxx; \
zz_set(tz, t); \
yyy; \
__resa = zz_equal(s, tz); \
if (!__resa) printf("Aliasing of " #s " and " #t " failed\n"); \
result &= __resa; \
} while (0)
#define test_zz_aliasing_12(xxx, a, b, c) \
do { \
zz_t __tzz; \
zz_init(__tzz); \
test_zz_aliasing(xxx(a, b, c), xxx(__tzz, __tzz, c), a, b, __tzz); \
test_zz_aliasing(xxx(a, b, c), xxx(__tzz, b, __tzz), a, c, __tzz); \
zz_clear(__tzz); \
} while (0)
#define test_zz_aliasing_22(xxx, a, b, c, d) \
do { \
zz_t __tzz; \
zz_init(__tzz); \
test_zz_aliasing(xxx(a, b, c, d), xxx(__tzz, b, __tzz, d), a, c, __tzz); \
test_zz_aliasing(xxx(a, b, c, d), xxx(__tzz, b, c, __tzz), a, d, __tzz); \
test_zz_aliasing(xxx(a, b, c, d), xxx(a, __tzz, __tzz, d), b, c, __tzz); \
test_zz_aliasing(xxx(a, b, c, d), xxx(a, __tzz, c, __tzz), b, d, __tzz); \
zz_clear(__tzz); \
} while (0)
#define test_zz_aliasing_32(xxx, a, b, c, d, e) \
do { \
zz_t __tzz; \
zz_init(__tzz); \
test_zz_aliasing(xxx(a, b, c, d, e), xxx(__tzz, b, c, d, __tzz), a, e, __tzz); \
test_zz_aliasing(xxx(a, b, c, d, e), xxx(__tzz, b, c, __tzz, e), a, d, __tzz); \
test_zz_aliasing(xxx(a, b, c, d, e), xxx(a, __tzz, c, d, __tzz), b, e, __tzz); \
test_zz_aliasing(xxx(a, b, c, d, e), xxx(a, __tzz, c, __tzz, e), b, d, __tzz); \
test_zz_aliasing(xxx(a, b, c, d, e), xxx(a, b, __tzz, d, __tzz), c, e, __tzz); \
test_zz_aliasing(xxx(a, b, c, d, e), xxx(a, b, __tzz, __tzz, e), c, d, __tzz); \
zz_clear(__tzz); \
} while (0)
#define test_zz_aliasing_12i(xxx, a, b, c) \
do { \
zz_t __tzz; \
zz_init(__tzz); \
test_zz_aliasing(xxx(a, b, c), xxx(__tzz, __tzz, c), a, b, __tzz); \
zz_clear(__tzz); \
} while (0)
#define RUN(xxx) \
do { \
if (xxx()) \
{ \
printf("PASS\n"); \
pass++; \
} else \
{ \
printf("FAIL\n"); \
fail++; \
} \
} while (0)
#define print_debug(a, m) \
do { \
bsdnt_printf(#a "(%m) = ", m); \
nn_printx_short(a, BSDNT_ABS(m)); printf("\n"); \
} while (0)
#define print_debug_diff(a, b, m) \
do { \
bsdnt_printf(#a " vs " #b "(%m) ", m); nn_printx_diff(a, b, BSDNT_ABS(m)); printf("\n"); \
} while (0)
#define zz_print_debug(a) \
do { \
bsdnt_printf(#a "(%m) = ", a->size); \
zz_print(a); printf("\n"); \
} while (0)
typedef enum
{
NN, ZZ
} type_t;
typedef enum
{
ANY, NONZERO, ODD, FULL, NORMALISED, POSITIVE
} flag_t;
typedef struct node_t
{
type_t type;
void * ptr;
len_t length;
struct node_t * next;
} node_t;
/*
Given a NULL terminated list of *pointers* to words, generate
random words which have the property specified by the flag.
randoms(NONZERO, state, &w1, &w2, NULL);
*/
void randoms(flag_t flag, rand_t state, ...);
/*
Given a NULL terminated list of *pointers* to words, generate
random words which have the property specified by the flag and
which are below the given limit.
randoms_upto(100, ANY, state, &w1, &w2, NULL);
*/
void randoms_upto(word_t limit, flag_t flag, rand_t state, ...);
/*
Given a NULL terminated list of *pointers* to nn_t's, generate
random integers which have the property specified by the flag and
which have the specified number of words. These can only be
cleaned up by calling gc_cleanup() (see below).
randoms_of_len(100, FULL, state, &a, &b, NULL);
*/
void randoms_of_len(len_t n, flag_t flag, rand_t state, ...);
/*
Given a NULL terminated list of zz_t's, generate random signed integers
which have the property specified by the flag and which have the
specified number of words. These can only be cleaned up by calling
gc_cleanup() (see below).
randoms_signed(100, FULL, state, &a, &b, NULL);
*/
void randoms_signed(len_t n, flag_t flag, rand_t state, ...);
/*
Clean up any objects allocated by the random functions above.
Note *all* objects are cleaned up. We have no way of knowing
which are still in use, so it is assumed none of them are still
in use.
*/
void gc_cleanup(void);
#ifdef __cplusplus
}
#endif
#endif