First public contribution.
2 * LIBOIL - Library of Optimized Inner Loops
3 * Copyright (c) 2004 David A. Schleef <ds@schleef.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.
32 #include <liboil/liboil.h>
33 #include <liboil/liboilfunction.h>
34 #include <liboil/liboiltest.h>
35 #include <liboil/liboilrandom.h>
36 #include <liboil/liboilcpu.h>
41 #include "std_log_result.h"
43 #include <liboil/globals.h>
44 #ifdef HAVE_INTTYPES_H
63 #define LOG_FILE "c:\\logs\\examples_oil-test_log.txt"
64 #include "std_log_result.h"
65 #define LOG_FILENAME_LINE __FILE__, __LINE__
66 double new_des[10][10];
69 void create_xml(int result)
74 testResultXml("examples_oil-test");
80 void register_impls(void);
89 src[i] = oil_rand_u8() & 0x7f;
93 oil_utf8_validate (dest, src, 100);
97 printf("%d %d\n",dest[i],src[i]);
100 printf("%d\n", dest[0]);
105 dump_array (void *data, void *ref_data, OilType type, int pre_n, int stride,
109 int s2 = oil_type_sizeof (type);
113 #define DUMP(type, format) do { \
114 for(i=0;i<post_n;i++){ \
116 for(j=0;j<pre_n;j++){ \
117 x = fabs(OIL_GET(data, i*stride + j*s2, type) - \
118 OIL_GET(ref_data, i*stride + j*s2, type)); \
119 if (x >= 0.00001) { \
120 std_log(LOG_FILENAME_LINE,"*" format "* ", OIL_GET(data, i*stride + j*s2, type)); \
121 new_des[ind1][i]=OIL_GET(data, i*stride + j*s2, type);\
123 std_log(LOG_FILENAME_LINE,format " ", OIL_GET(data, i*stride + j*s2, type)); \
124 new_des[ind1][i]=OIL_GET(data, i*stride + j*s2, type);\
135 DUMP(uint8_t, "%02" PRIx8);
139 DUMP(uint16_t, "%04" PRIx16);
144 DUMP(uint32_t, "%08" PRIx32);
149 DUMP(uint64_t, "%016" PRIx64);
157 DUMP(int8_t, "%" PRId8);
160 DUMP(uint8_t, "%" PRIu8);
163 DUMP(int16_t, "%" PRId16);
166 DUMP(uint16_t, "%" PRIu16);
169 DUMP(int32_t, "%" PRId32);
172 DUMP(uint32_t, "%" PRIu32);
175 DUMP(int64_t, "%" PRId64);
178 DUMP(uint64_t, "%" PRIu64);
193 dump_test (OilTest *test)
196 for(i=0;i<OIL_ARG_LAST;i++){
197 OilParameter *p = &test->params[i];
199 if (p->direction == 'i' || p->direction == 'd') {
200 std_log(LOG_FILENAME_LINE," %s:\n", p->parameter_name);
201 dump_array (p->test_data + OIL_TEST_HEADER,
202 p->ref_data + OIL_TEST_HEADER,
203 p->type, p->pre_n, p->stride, p->post_n);
210 dump_source (OilTest *test)
213 for(i=0;i<OIL_ARG_LAST;i++){
214 OilParameter *p = &test->params[i];
216 if (p->direction == 'i' || p->direction == 's') {
217 std_log(LOG_FILENAME_LINE," %s:\n", p->parameter_name);
218 dump_array (p->src_data + OIL_TEST_HEADER,
219 p->src_data + OIL_TEST_HEADER,
220 p->type, p->pre_n, p->stride, p->post_n);
229 std_log(LOG_FILENAME_LINE,"oil-test [-x] <class_name>\n");
233 int main (int argc, char *argv[])
235 OilFunctionClass *klass;
236 OilFunctionImpl *impl;
239 char *class_name = NULL;
246 for (i=1;i<argc;i++){
247 if (!strcmp(argv[i],"-x")) {
249 } else if (!strcmp(argv[i],"-n")) {
251 n = strtol (argv[i+1], NULL, 0);
255 if (class_name != NULL) {
258 class_name = argv[i];
261 if (class_name == NULL) {
265 klass = oil_class_get (class_name);
267 std_log(LOG_FILENAME_LINE,"class not found: %s\n", class_name);
270 oil_class_optimize (klass);
272 test = oil_test_new(klass);
273 oil_test_set_iterations(test, 1);
277 impl = klass->reference_impl;
278 ave = impl->profile_ave;
279 std = impl->profile_std;
280 oil_test_check_impl (test, impl);
281 std_log(LOG_FILENAME_LINE,"source array\n");
283 std_log(LOG_FILENAME_LINE,"reference impl %s\n", impl->name);
284 std_log(LOG_FILENAME_LINE," ave=%g std=%g\n", ave, std);
285 std_log(LOG_FILENAME_LINE," (this test) ave=%g std=%g\n", test->profile_ave, test->profile_std);
288 for (impl = klass->first_impl; impl; impl = impl->next) {
289 if (impl == klass->reference_impl) continue;
290 std_log(LOG_FILENAME_LINE,"impl %s\n", impl->name);
292 if (oil_impl_is_runnable (impl)) {
293 std_log(LOG_FILENAME_LINE," ave=%g std=%g\n", impl->profile_ave, impl->profile_std);
294 oil_test_check_impl (test, impl);
295 std_log(LOG_FILENAME_LINE," (this test) ave=%g std=%g\n", test->profile_ave, test->profile_std);
296 std_log(LOG_FILENAME_LINE," abs diff=%g\n", test->sum_abs_diff);
304 if(new_des[0][i]!=new_des[j][i])
311 std_log(LOG_FILENAME_LINE,"Test Fail");
313 std_log(LOG_FILENAME_LINE,"Test Successful");