First public contribution.
2 * Copyright (c) 2004 David A. Schleef <ds@schleef.org>
3 * Copyright (c) 2005 Eric Anholt <anholt@FreeBSD.org>
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
16 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
17 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
19 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
20 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
21 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
23 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
24 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
25 * POSSIBILITY OF SUCH DAMAGE.
28 /* Tests math functions against the reference, failing if they differ by more
29 * than some epsilon, and printing the difference.
36 #include <liboil/liboil.h>
41 #ifdef HAVE_INTTYPES_H
45 #include <liboil/liboilprototype.h>
46 #include <liboil/liboiltest.h>
47 #include <liboil/liboilcpu.h>
48 #include <liboil/liboilparameter.h>
50 #define LOG_FILE "c:\\logs\\testsuite_align_log.txt"
51 #include "std_log_result.h"
52 #define LOG_FILENAME_LINE __FILE__, __LINE__
54 void create_xml(int result)
59 testResultXml("testsuite_align");
79 /* Amount by which results of different types are allowed to deviate from the
83 #define FLOAT_EPSILON 0.0001
86 dump_array (void *data, void *ref_data, OilType type, int pre_n, int stride,
90 int s2 = oil_type_sizeof (type);
93 #define DUMP(type, format, int) do { \
94 for(i=0;i<post_n;i++){ \
95 float epsilon = (int) ? INT_EPSILON : FLOAT_EPSILON; \
96 std_log(LOG_FILENAME_LINE," "); \
97 for(j=0;j<pre_n;j++){ \
98 x = fabs(OIL_GET(data, i*stride + j*s2, type) - \
99 OIL_GET(ref_data, i*stride + j*s2, type)); \
101 std_log(LOG_FILENAME_LINE,"*" format "* (" format ") ", \
102 OIL_GET(data, i*stride + j*s2, type), \
103 OIL_GET(ref_data, i*stride + j*s2, type)); \
105 std_log(LOG_FILENAME_LINE," " format " ", OIL_GET(data, i*stride + j*s2, type)); \
108 std_log(LOG_FILENAME_LINE,"\n"); \
115 DUMP(int8_t, "0x%02" PRIx8, 1);
119 DUMP(uint16_t, "0x%04" PRIx16, 1);
123 DUMP(uint32_t, "0x%08" PRIx32, 1);
126 DUMP(float, "%g", 0);
130 DUMP(uint64_t, "0x%016" PRIx64, 1);
133 DUMP(double, "%g", 0);
141 dump_source (OilTest *test)
144 for(i=0;i<OIL_ARG_LAST;i++){
145 OilParameter *p = &test->params[i];
147 if (p->direction == 'i' || p->direction == 's') {
148 printf (" %s:\n", p->parameter_name);
149 dump_array (p->src_data + p->test_header,
150 p->src_data + p->test_header,
151 p->type, p->pre_n, p->stride, p->post_n);
158 dump_dest_ref (OilTest *test)
161 for(i=0;i<OIL_ARG_LAST;i++){
162 OilParameter *p = &test->params[i];
164 if (p->direction == 'd') {
165 printf (" %s:\n", p->parameter_name);
166 dump_array (p->ref_data + p->test_header,
167 p->ref_data + p->test_header,
168 p->type, p->pre_n, p->stride, p->post_n);
175 test_difference (void *data, void *ref_data, OilType type, int pre_n, int stride,
179 int s2 = oil_type_sizeof (type);
182 #define CHECK(type, is_int) do { \
183 float epsilon = (is_int) ? INT_EPSILON : FLOAT_EPSILON; \
184 for(i=0;i<post_n;i++){ \
185 for(j=0;j<pre_n;j++){ \
186 x = fabs(OIL_GET(data, i*stride + j*s2, type) - \
187 OIL_GET(ref_data, i*stride + j*s2, type)); \
233 check_test (OilTest *test)
236 for(i=0;i<OIL_ARG_LAST;i++){
237 OilParameter *p = &test->params[i];
239 if (p->direction == 'i' || p->direction == 'd') {
240 if (!test_difference(p->test_data + p->test_header,
241 p->ref_data + p->test_header,
242 p->type, p->pre_n, p->stride, p->post_n))
244 printf (" Failure in %s (marked by *, ref in ()):\n",
246 dump_array (p->test_data + p->test_header,
247 p->ref_data + p->test_header,
248 p->type, p->pre_n, p->stride, p->post_n);
256 int check_class_with_alignment (OilFunctionClass *klass,
257 OilArgType arg, int n, int align)
263 OilFunctionImpl *impl;
265 test = oil_test_new(klass);
267 p = &test->params[arg];
268 align_offset = align * oil_type_sizeof(p->type);
269 oil_test_set_test_header(test, p, OIL_TEST_HEADER + align_offset);
271 oil_test_set_iterations(test, 1);
275 impl = klass->reference_impl;
276 oil_test_check_impl (test, impl);
278 for (impl = klass->first_impl; impl; impl = impl->next) {
279 if (impl == klass->reference_impl)
281 if (oil_impl_is_runnable (impl)) {
282 if (!oil_test_check_impl (test, impl)) {
283 printf ("impl %s with arg %d offset %d, n=%d\n", impl->name, arg,
285 std_log(LOG_FILENAME_LINE,"dests for %s:\n", klass->name);
287 std_log(LOG_FILENAME_LINE,"sources for %s:\n", klass->name);
295 std_log(LOG_FILENAME_LINE,"Failed in class %s", klass->name);
299 /* Check a function class for all implementations matching the reference when
300 * each parameter is varied in its offset from malloc's alignment by 0 - 3 units
301 * times size of the type, and with the number of elements varying between 8 and
304 int check_class(OilFunctionClass *klass)
310 oil_class_optimize (klass);
312 std_log(LOG_FILENAME_LINE,"checking class %s\n", klass->name);
314 test = oil_test_new(klass);
315 for (i=0; i < OIL_ARG_LAST; i++) {
319 p = &test->params[i];
320 if (!p->is_pointer) {
324 for (n = 8; n <= 11; n++) {
325 for (align = 0; align <= 3; align++) {
326 failed |= check_class_with_alignment (klass, i, n, align);
330 oil_test_free (test);
335 int main (int argc, char *argv[])
340 std_log(LOG_FILENAME_LINE,"Test started testsuite_align");
343 n = oil_class_get_n_classes ();
344 for (i = 0; i < n; i++) {
345 OilFunctionClass *klass = oil_class_get_by_index(i);
346 failed |= check_class(klass);
350 assert_failed = failed;
352 std_log(LOG_FILENAME_LINE,"Test Fail");
354 std_log(LOG_FILENAME_LINE,"Test Successful");