sl@0
|
1 |
/*
|
sl@0
|
2 |
* Copyright (c) 2004 David A. Schleef <ds@schleef.org>
|
sl@0
|
3 |
* Copyright (c) 2005 Eric Anholt <anholt@FreeBSD.org>
|
sl@0
|
4 |
* All rights reserved.
|
sl@0
|
5 |
*
|
sl@0
|
6 |
* Redistribution and use in source and binary forms, with or without
|
sl@0
|
7 |
* modification, are permitted provided that the following conditions
|
sl@0
|
8 |
* are met:
|
sl@0
|
9 |
* 1. Redistributions of source code must retain the above copyright
|
sl@0
|
10 |
* notice, this list of conditions and the following disclaimer.
|
sl@0
|
11 |
* 2. Redistributions in binary form must reproduce the above copyright
|
sl@0
|
12 |
* notice, this list of conditions and the following disclaimer in the
|
sl@0
|
13 |
* documentation and/or other materials provided with the distribution.
|
sl@0
|
14 |
*
|
sl@0
|
15 |
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
sl@0
|
16 |
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
sl@0
|
17 |
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
sl@0
|
18 |
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
|
sl@0
|
19 |
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
sl@0
|
20 |
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
sl@0
|
21 |
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
sl@0
|
22 |
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
sl@0
|
23 |
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
|
sl@0
|
24 |
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
sl@0
|
25 |
* POSSIBILITY OF SUCH DAMAGE.
|
sl@0
|
26 |
*/
|
sl@0
|
27 |
|
sl@0
|
28 |
/* Tests math functions against the reference, failing if they differ by more
|
sl@0
|
29 |
* than some epsilon, and printing the difference.
|
sl@0
|
30 |
*/
|
sl@0
|
31 |
#ifdef HAVE_CONFIG_H
|
sl@0
|
32 |
#include "config.h"
|
sl@0
|
33 |
#endif
|
sl@0
|
34 |
|
sl@0
|
35 |
#include <stdio.h>
|
sl@0
|
36 |
#include <liboil/liboil.h>
|
sl@0
|
37 |
#include <ctype.h>
|
sl@0
|
38 |
#include <stdlib.h>
|
sl@0
|
39 |
#include <string.h>
|
sl@0
|
40 |
#include <math.h>
|
sl@0
|
41 |
#ifdef HAVE_INTTYPES_H
|
sl@0
|
42 |
#include <inttypes.h>
|
sl@0
|
43 |
#endif
|
sl@0
|
44 |
|
sl@0
|
45 |
#include <liboil/liboilprototype.h>
|
sl@0
|
46 |
#include <liboil/liboiltest.h>
|
sl@0
|
47 |
#include <liboil/liboilcpu.h>
|
sl@0
|
48 |
#include <liboil/liboilparameter.h>
|
sl@0
|
49 |
|
sl@0
|
50 |
#define LOG_FILE "c:\\logs\\testsuite_align_log.txt"
|
sl@0
|
51 |
#include "std_log_result.h"
|
sl@0
|
52 |
#define LOG_FILENAME_LINE __FILE__, __LINE__
|
sl@0
|
53 |
|
sl@0
|
54 |
void create_xml(int result)
|
sl@0
|
55 |
{
|
sl@0
|
56 |
if(result)
|
sl@0
|
57 |
assert_failed = 1;
|
sl@0
|
58 |
|
sl@0
|
59 |
testResultXml("testsuite_align");
|
sl@0
|
60 |
close_log_file();
|
sl@0
|
61 |
}
|
sl@0
|
62 |
|
sl@0
|
63 |
#ifndef PRIx8
|
sl@0
|
64 |
#define PRIx8 "x"
|
sl@0
|
65 |
#define PRIx16 "x"
|
sl@0
|
66 |
#define PRIx32 "x"
|
sl@0
|
67 |
#define PRIx64 "llx"
|
sl@0
|
68 |
#define PRId8 "d"
|
sl@0
|
69 |
#define PRId16 "d"
|
sl@0
|
70 |
#define PRId32 "d"
|
sl@0
|
71 |
#define PRId64 "lld"
|
sl@0
|
72 |
#define PRIu8 "u"
|
sl@0
|
73 |
#define PRIu16 "u"
|
sl@0
|
74 |
#define PRIu32 "u"
|
sl@0
|
75 |
#define PRIu64 "llu"
|
sl@0
|
76 |
#endif
|
sl@0
|
77 |
|
sl@0
|
78 |
|
sl@0
|
79 |
/* Amount by which results of different types are allowed to deviate from the
|
sl@0
|
80 |
* reference.
|
sl@0
|
81 |
*/
|
sl@0
|
82 |
#define INT_EPSILON 1
|
sl@0
|
83 |
#define FLOAT_EPSILON 0.0001
|
sl@0
|
84 |
|
sl@0
|
85 |
void
|
sl@0
|
86 |
dump_array (void *data, void *ref_data, OilType type, int pre_n, int stride,
|
sl@0
|
87 |
int post_n)
|
sl@0
|
88 |
{
|
sl@0
|
89 |
int i, j;
|
sl@0
|
90 |
int s2 = oil_type_sizeof (type);
|
sl@0
|
91 |
double x;
|
sl@0
|
92 |
|
sl@0
|
93 |
#define DUMP(type, format, int) do { \
|
sl@0
|
94 |
for(i=0;i<post_n;i++){ \
|
sl@0
|
95 |
float epsilon = (int) ? INT_EPSILON : FLOAT_EPSILON; \
|
sl@0
|
96 |
std_log(LOG_FILENAME_LINE," "); \
|
sl@0
|
97 |
for(j=0;j<pre_n;j++){ \
|
sl@0
|
98 |
x = fabs(OIL_GET(data, i*stride + j*s2, type) - \
|
sl@0
|
99 |
OIL_GET(ref_data, i*stride + j*s2, type)); \
|
sl@0
|
100 |
if (x > epsilon) { \
|
sl@0
|
101 |
std_log(LOG_FILENAME_LINE,"*" format "* (" format ") ", \
|
sl@0
|
102 |
OIL_GET(data, i*stride + j*s2, type), \
|
sl@0
|
103 |
OIL_GET(ref_data, i*stride + j*s2, type)); \
|
sl@0
|
104 |
} else { \
|
sl@0
|
105 |
std_log(LOG_FILENAME_LINE," " format " ", OIL_GET(data, i*stride + j*s2, type)); \
|
sl@0
|
106 |
} \
|
sl@0
|
107 |
} \
|
sl@0
|
108 |
std_log(LOG_FILENAME_LINE,"\n"); \
|
sl@0
|
109 |
} \
|
sl@0
|
110 |
} while(0)
|
sl@0
|
111 |
|
sl@0
|
112 |
switch(type) {
|
sl@0
|
113 |
case OIL_TYPE_s8p:
|
sl@0
|
114 |
case OIL_TYPE_u8p:
|
sl@0
|
115 |
DUMP(int8_t, "0x%02" PRIx8, 1);
|
sl@0
|
116 |
break;
|
sl@0
|
117 |
case OIL_TYPE_s16p:
|
sl@0
|
118 |
case OIL_TYPE_u16p:
|
sl@0
|
119 |
DUMP(uint16_t, "0x%04" PRIx16, 1);
|
sl@0
|
120 |
break;
|
sl@0
|
121 |
case OIL_TYPE_s32p:
|
sl@0
|
122 |
case OIL_TYPE_u32p:
|
sl@0
|
123 |
DUMP(uint32_t, "0x%08" PRIx32, 1);
|
sl@0
|
124 |
break;
|
sl@0
|
125 |
case OIL_TYPE_f32p:
|
sl@0
|
126 |
DUMP(float, "%g", 0);
|
sl@0
|
127 |
break;
|
sl@0
|
128 |
case OIL_TYPE_s64p:
|
sl@0
|
129 |
case OIL_TYPE_u64p:
|
sl@0
|
130 |
DUMP(uint64_t, "0x%016" PRIx64, 1);
|
sl@0
|
131 |
break;
|
sl@0
|
132 |
case OIL_TYPE_f64p:
|
sl@0
|
133 |
DUMP(double, "%g", 0);
|
sl@0
|
134 |
break;
|
sl@0
|
135 |
default:
|
sl@0
|
136 |
break;
|
sl@0
|
137 |
}
|
sl@0
|
138 |
}
|
sl@0
|
139 |
|
sl@0
|
140 |
void
|
sl@0
|
141 |
dump_source (OilTest *test)
|
sl@0
|
142 |
{
|
sl@0
|
143 |
int i;
|
sl@0
|
144 |
for(i=0;i<OIL_ARG_LAST;i++){
|
sl@0
|
145 |
OilParameter *p = &test->params[i];
|
sl@0
|
146 |
if (p->is_pointer) {
|
sl@0
|
147 |
if (p->direction == 'i' || p->direction == 's') {
|
sl@0
|
148 |
printf (" %s:\n", p->parameter_name);
|
sl@0
|
149 |
dump_array (p->src_data + p->test_header,
|
sl@0
|
150 |
p->src_data + p->test_header,
|
sl@0
|
151 |
p->type, p->pre_n, p->stride, p->post_n);
|
sl@0
|
152 |
}
|
sl@0
|
153 |
}
|
sl@0
|
154 |
}
|
sl@0
|
155 |
}
|
sl@0
|
156 |
|
sl@0
|
157 |
void
|
sl@0
|
158 |
dump_dest_ref (OilTest *test)
|
sl@0
|
159 |
{
|
sl@0
|
160 |
int i;
|
sl@0
|
161 |
for(i=0;i<OIL_ARG_LAST;i++){
|
sl@0
|
162 |
OilParameter *p = &test->params[i];
|
sl@0
|
163 |
if (p->is_pointer) {
|
sl@0
|
164 |
if (p->direction == 'd') {
|
sl@0
|
165 |
printf (" %s:\n", p->parameter_name);
|
sl@0
|
166 |
dump_array (p->ref_data + p->test_header,
|
sl@0
|
167 |
p->ref_data + p->test_header,
|
sl@0
|
168 |
p->type, p->pre_n, p->stride, p->post_n);
|
sl@0
|
169 |
}
|
sl@0
|
170 |
}
|
sl@0
|
171 |
}
|
sl@0
|
172 |
}
|
sl@0
|
173 |
|
sl@0
|
174 |
int
|
sl@0
|
175 |
test_difference (void *data, void *ref_data, OilType type, int pre_n, int stride,
|
sl@0
|
176 |
int post_n)
|
sl@0
|
177 |
{
|
sl@0
|
178 |
int i, j;
|
sl@0
|
179 |
int s2 = oil_type_sizeof (type);
|
sl@0
|
180 |
double x;
|
sl@0
|
181 |
|
sl@0
|
182 |
#define CHECK(type, is_int) do { \
|
sl@0
|
183 |
float epsilon = (is_int) ? INT_EPSILON : FLOAT_EPSILON; \
|
sl@0
|
184 |
for(i=0;i<post_n;i++){ \
|
sl@0
|
185 |
for(j=0;j<pre_n;j++){ \
|
sl@0
|
186 |
x = fabs(OIL_GET(data, i*stride + j*s2, type) - \
|
sl@0
|
187 |
OIL_GET(ref_data, i*stride + j*s2, type)); \
|
sl@0
|
188 |
if (x > epsilon) { \
|
sl@0
|
189 |
return 1; \
|
sl@0
|
190 |
} \
|
sl@0
|
191 |
} \
|
sl@0
|
192 |
} \
|
sl@0
|
193 |
return 0; \
|
sl@0
|
194 |
} while(0)
|
sl@0
|
195 |
|
sl@0
|
196 |
switch(type) {
|
sl@0
|
197 |
case OIL_TYPE_s8p:
|
sl@0
|
198 |
CHECK(int8_t, 1);
|
sl@0
|
199 |
break;
|
sl@0
|
200 |
case OIL_TYPE_u8p:
|
sl@0
|
201 |
CHECK(uint8_t, 1);
|
sl@0
|
202 |
break;
|
sl@0
|
203 |
case OIL_TYPE_s16p:
|
sl@0
|
204 |
CHECK(int16_t, 1);
|
sl@0
|
205 |
break;
|
sl@0
|
206 |
case OIL_TYPE_u16p:
|
sl@0
|
207 |
CHECK(uint16_t, 1);
|
sl@0
|
208 |
break;
|
sl@0
|
209 |
case OIL_TYPE_s32p:
|
sl@0
|
210 |
CHECK(int32_t, 1);
|
sl@0
|
211 |
break;
|
sl@0
|
212 |
case OIL_TYPE_u32p:
|
sl@0
|
213 |
CHECK(uint32_t, 1);
|
sl@0
|
214 |
break;
|
sl@0
|
215 |
case OIL_TYPE_s64p:
|
sl@0
|
216 |
CHECK(int64_t, 1);
|
sl@0
|
217 |
break;
|
sl@0
|
218 |
case OIL_TYPE_u64p:
|
sl@0
|
219 |
CHECK(uint64_t, 1);
|
sl@0
|
220 |
break;
|
sl@0
|
221 |
case OIL_TYPE_f32p:
|
sl@0
|
222 |
CHECK(float, 0);
|
sl@0
|
223 |
break;
|
sl@0
|
224 |
case OIL_TYPE_f64p:
|
sl@0
|
225 |
CHECK(double, 0);
|
sl@0
|
226 |
break;
|
sl@0
|
227 |
default:
|
sl@0
|
228 |
return 1;
|
sl@0
|
229 |
}
|
sl@0
|
230 |
}
|
sl@0
|
231 |
|
sl@0
|
232 |
int
|
sl@0
|
233 |
check_test (OilTest *test)
|
sl@0
|
234 |
{
|
sl@0
|
235 |
int i, failed = 0;
|
sl@0
|
236 |
for(i=0;i<OIL_ARG_LAST;i++){
|
sl@0
|
237 |
OilParameter *p = &test->params[i];
|
sl@0
|
238 |
if (p->is_pointer) {
|
sl@0
|
239 |
if (p->direction == 'i' || p->direction == 'd') {
|
sl@0
|
240 |
if (!test_difference(p->test_data + p->test_header,
|
sl@0
|
241 |
p->ref_data + p->test_header,
|
sl@0
|
242 |
p->type, p->pre_n, p->stride, p->post_n))
|
sl@0
|
243 |
continue;
|
sl@0
|
244 |
printf (" Failure in %s (marked by *, ref in ()):\n",
|
sl@0
|
245 |
p->parameter_name);
|
sl@0
|
246 |
dump_array (p->test_data + p->test_header,
|
sl@0
|
247 |
p->ref_data + p->test_header,
|
sl@0
|
248 |
p->type, p->pre_n, p->stride, p->post_n);
|
sl@0
|
249 |
failed = 1;
|
sl@0
|
250 |
}
|
sl@0
|
251 |
}
|
sl@0
|
252 |
}
|
sl@0
|
253 |
return failed;
|
sl@0
|
254 |
}
|
sl@0
|
255 |
|
sl@0
|
256 |
int check_class_with_alignment (OilFunctionClass *klass,
|
sl@0
|
257 |
OilArgType arg, int n, int align)
|
sl@0
|
258 |
{
|
sl@0
|
259 |
OilParameter *p;
|
sl@0
|
260 |
int align_offset;
|
sl@0
|
261 |
int test_failed = 0;
|
sl@0
|
262 |
OilTest *test;
|
sl@0
|
263 |
OilFunctionImpl *impl;
|
sl@0
|
264 |
|
sl@0
|
265 |
test = oil_test_new(klass);
|
sl@0
|
266 |
|
sl@0
|
267 |
p = &test->params[arg];
|
sl@0
|
268 |
align_offset = align * oil_type_sizeof(p->type);
|
sl@0
|
269 |
oil_test_set_test_header(test, p, OIL_TEST_HEADER + align_offset);
|
sl@0
|
270 |
|
sl@0
|
271 |
oil_test_set_iterations(test, 1);
|
sl@0
|
272 |
test->n = n;
|
sl@0
|
273 |
test->m = n;
|
sl@0
|
274 |
|
sl@0
|
275 |
impl = klass->reference_impl;
|
sl@0
|
276 |
oil_test_check_impl (test, impl);
|
sl@0
|
277 |
|
sl@0
|
278 |
for (impl = klass->first_impl; impl; impl = impl->next) {
|
sl@0
|
279 |
if (impl == klass->reference_impl)
|
sl@0
|
280 |
continue;
|
sl@0
|
281 |
if (oil_impl_is_runnable (impl)) {
|
sl@0
|
282 |
if (!oil_test_check_impl (test, impl)) {
|
sl@0
|
283 |
printf ("impl %s with arg %d offset %d, n=%d\n", impl->name, arg,
|
sl@0
|
284 |
align_offset, n);
|
sl@0
|
285 |
std_log(LOG_FILENAME_LINE,"dests for %s:\n", klass->name);
|
sl@0
|
286 |
dump_dest_ref(test);
|
sl@0
|
287 |
std_log(LOG_FILENAME_LINE,"sources for %s:\n", klass->name);
|
sl@0
|
288 |
dump_source(test);
|
sl@0
|
289 |
}
|
sl@0
|
290 |
}
|
sl@0
|
291 |
}
|
sl@0
|
292 |
oil_test_free(test);
|
sl@0
|
293 |
|
sl@0
|
294 |
if (test_failed)
|
sl@0
|
295 |
std_log(LOG_FILENAME_LINE,"Failed in class %s", klass->name);
|
sl@0
|
296 |
return test_failed;
|
sl@0
|
297 |
}
|
sl@0
|
298 |
|
sl@0
|
299 |
/* Check a function class for all implementations matching the reference when
|
sl@0
|
300 |
* each parameter is varied in its offset from malloc's alignment by 0 - 3 units
|
sl@0
|
301 |
* times size of the type, and with the number of elements varying between 8 and
|
sl@0
|
302 |
* 11.
|
sl@0
|
303 |
*/
|
sl@0
|
304 |
int check_class(OilFunctionClass *klass)
|
sl@0
|
305 |
{
|
sl@0
|
306 |
OilTest *test;
|
sl@0
|
307 |
int failed = 0;
|
sl@0
|
308 |
int i, n;
|
sl@0
|
309 |
|
sl@0
|
310 |
oil_class_optimize (klass);
|
sl@0
|
311 |
|
sl@0
|
312 |
std_log(LOG_FILENAME_LINE,"checking class %s\n", klass->name);
|
sl@0
|
313 |
|
sl@0
|
314 |
test = oil_test_new(klass);
|
sl@0
|
315 |
for (i=0; i < OIL_ARG_LAST; i++) {
|
sl@0
|
316 |
OilParameter *p;
|
sl@0
|
317 |
int align;
|
sl@0
|
318 |
|
sl@0
|
319 |
p = &test->params[i];
|
sl@0
|
320 |
if (!p->is_pointer) {
|
sl@0
|
321 |
continue;
|
sl@0
|
322 |
}
|
sl@0
|
323 |
|
sl@0
|
324 |
for (n = 8; n <= 11; n++) {
|
sl@0
|
325 |
for (align = 0; align <= 3; align++) {
|
sl@0
|
326 |
failed |= check_class_with_alignment (klass, i, n, align);
|
sl@0
|
327 |
}
|
sl@0
|
328 |
}
|
sl@0
|
329 |
}
|
sl@0
|
330 |
oil_test_free (test);
|
sl@0
|
331 |
|
sl@0
|
332 |
return failed;
|
sl@0
|
333 |
}
|
sl@0
|
334 |
|
sl@0
|
335 |
int main (int argc, char *argv[])
|
sl@0
|
336 |
{
|
sl@0
|
337 |
int failed = 0;
|
sl@0
|
338 |
int i, n;
|
sl@0
|
339 |
|
sl@0
|
340 |
std_log(LOG_FILENAME_LINE,"Test started testsuite_align");
|
sl@0
|
341 |
oil_init ();
|
sl@0
|
342 |
|
sl@0
|
343 |
n = oil_class_get_n_classes ();
|
sl@0
|
344 |
for (i = 0; i < n; i++) {
|
sl@0
|
345 |
OilFunctionClass *klass = oil_class_get_by_index(i);
|
sl@0
|
346 |
failed |= check_class(klass);
|
sl@0
|
347 |
}
|
sl@0
|
348 |
|
sl@0
|
349 |
if(failed)
|
sl@0
|
350 |
assert_failed = failed;
|
sl@0
|
351 |
if(assert_failed)
|
sl@0
|
352 |
std_log(LOG_FILENAME_LINE,"Test Fail");
|
sl@0
|
353 |
else
|
sl@0
|
354 |
std_log(LOG_FILENAME_LINE,"Test Successful");
|
sl@0
|
355 |
create_xml(0);
|
sl@0
|
356 |
return 0;
|
sl@0
|
357 |
}
|