os/ossrv/genericopenlibs/liboil/src/liboiltest.c
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/ossrv/genericopenlibs/liboil/src/liboiltest.c	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,778 @@
     1.4 +/*
     1.5 + * LIBOIL - Library of Optimized Inner Loops
     1.6 + * Copyright (c) 2003,2004 David A. Schleef <ds@schleef.org>
     1.7 + * All rights reserved.
     1.8 + *
     1.9 + * Redistribution and use in source and binary forms, with or without
    1.10 + * modification, are permitted provided that the following conditions
    1.11 + * are met:
    1.12 + * 1. Redistributions of source code must retain the above copyright
    1.13 + *    notice, this list of conditions and the following disclaimer.
    1.14 + * 2. Redistributions in binary form must reproduce the above copyright
    1.15 + *    notice, this list of conditions and the following disclaimer in the
    1.16 + *    documentation and/or other materials provided with the distribution.
    1.17 + * 
    1.18 + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
    1.19 + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
    1.20 + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
    1.21 + * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
    1.22 + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
    1.23 + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
    1.24 + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
    1.25 + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
    1.26 + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
    1.27 + * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
    1.28 + * POSSIBILITY OF SUCH DAMAGE.
    1.29 + */
    1.30 +//Portions Copyright (c)  2008-2009 Nokia Corporation and/or its subsidiary(-ies). All rights reserved. 
    1.31 +
    1.32 +#ifdef HAVE_CONFIG_H
    1.33 +#include <config.h>
    1.34 +#endif
    1.35 +
    1.36 +#include <liboil/liboiltest.h>
    1.37 +#include <liboil/liboildebug.h>
    1.38 +#include <liboil/liboilrandom.h>
    1.39 +#include <liboil/liboilprofile.h>
    1.40 +#include <liboil/liboilfault.h>
    1.41 +#include <stdlib.h>
    1.42 +#include <string.h>
    1.43 +#include <stdio.h>
    1.44 +#include <math.h>
    1.45 +
    1.46 +#ifdef __SYMBIAN32__
    1.47 +#ifdef __WINSCW__
    1.48 +#pragma warn_unusedarg off 
    1.49 +#endif//__WINSCW__
    1.50 +#endif//__SYMBIAN32__
    1.51 +
    1.52 +#define MAX_PARAMS 20
    1.53 +
    1.54 +/**
    1.55 + * SECTION:liboiltest
    1.56 + * @title:OilTest
    1.57 + * @short_description: Test and profile function implementations.
    1.58 + *
    1.59 + */
    1.60 +static void oil_test_init_params (OilTest *test);
    1.61 +static void fill_array (void *ptr, OilType type, int pre_n, int stride,
    1.62 +    int post_n);
    1.63 +static double check_array (void *data, void *ref, OilType type, int pre_n,
    1.64 +    int stride, int post_n);
    1.65 +static int check_holes (void *data, OilType type, int pre_n,
    1.66 +    int stride, int post_n, int guard);
    1.67 +
    1.68 +/**
    1.69 + * oil_test_new:
    1.70 + * @klass: an OilFunctionClass
    1.71 + *
    1.72 + * Creates a new OilTest for the OilFunctionClass represented by @klass.
    1.73 + *
    1.74 + * Returns: the new OilTest
    1.75 + */
    1.76 +#ifdef __SYMBIAN32__
    1.77 +EXPORT_C
    1.78 +#endif
    1.79 +OilTest *
    1.80 +oil_test_new (OilFunctionClass *klass)
    1.81 +{
    1.82 +  OilTest *test;
    1.83 +  OilPrototype *proto;
    1.84 +  int i;
    1.85 +
    1.86 +  if (klass == NULL) return NULL;
    1.87 +
    1.88 +  proto = oil_prototype_from_string (klass->prototype);
    1.89 +  if (proto == NULL) return NULL;
    1.90 +
    1.91 +  test = malloc (sizeof (OilTest));
    1.92 +  memset (test, 0, sizeof (OilTest));
    1.93 +
    1.94 +  test->klass = klass;
    1.95 +  test->proto = proto;
    1.96 +  test->impl = klass->reference_impl;
    1.97 +  test->tolerance = 0.0;
    1.98 +
    1.99 +  for (i=0;i<proto->n_params;i++){
   1.100 +    if (proto->params[i].parameter_type == OIL_ARG_UNKNOWN) {
   1.101 +      return NULL;
   1.102 +    }
   1.103 +    if (oil_type_is_floating_point(proto->params[i].type)) {
   1.104 +      test->tolerance = 0.001;
   1.105 +    }
   1.106 +    memcpy (&test->params[proto->params[i].parameter_type], &proto->params[i],
   1.107 +        sizeof(OilParameter));
   1.108 +  }
   1.109 +  for (i=0;i<OIL_ARG_LAST;i++){
   1.110 +    test->params[i].src_data = NULL;
   1.111 +    test->params[i].ref_data = NULL;
   1.112 +    test->params[i].test_data = NULL;
   1.113 +    test->params[i].test_header = OIL_TEST_HEADER;
   1.114 +    test->params[i].test_footer = OIL_TEST_FOOTER;
   1.115 +  }
   1.116 +
   1.117 +  test->iterations = 10;
   1.118 +  test->n = 100;
   1.119 +  test->m = 100;
   1.120 +
   1.121 +  return test;
   1.122 +}
   1.123 +
   1.124 +/**
   1.125 + * oil_test_free:
   1.126 + * @test: the OilTest
   1.127 + *
   1.128 + * Frees memory associated with @test.
   1.129 + */
   1.130 + #ifdef __SYMBIAN32__
   1.131 +EXPORT_C
   1.132 +#endif
   1.133 +void
   1.134 +oil_test_free (OilTest *test)
   1.135 +{
   1.136 +  int i;
   1.137 +
   1.138 +  if (test->proto) {
   1.139 +    oil_prototype_free (test->proto);
   1.140 +  }
   1.141 +
   1.142 +  for(i=0;i<OIL_ARG_LAST;i++){
   1.143 +    if (test->params[i].src_data) {
   1.144 +      free (test->params[i].src_data);
   1.145 +    }
   1.146 +    if (test->params[i].ref_data) {
   1.147 +      free (test->params[i].ref_data);
   1.148 +    }
   1.149 +    if (test->params[i].test_data) {
   1.150 +      free (test->params[i].test_data);
   1.151 +    }
   1.152 +  }
   1.153 +
   1.154 +  free(test);
   1.155 +}
   1.156 +
   1.157 +/**
   1.158 + * oil_test_set_impl:
   1.159 + * @test: the OilTest
   1.160 + * @impl: an OilFunctionImpl to set
   1.161 + *
   1.162 + * Sets the current implementation of @test to @impl.
   1.163 + */
   1.164 + #ifdef __SYMBIAN32__
   1.165 + EXPORT_C
   1.166 +#endif
   1.167 +void
   1.168 +oil_test_set_impl (OilTest *test, OilFunctionImpl *impl)
   1.169 +{
   1.170 +  test->impl = impl;
   1.171 +}
   1.172 +
   1.173 +/**
   1.174 + * oil_test_set_iterations:
   1.175 + * @test: the OilTest
   1.176 + * @iterations: the number of iterations
   1.177 + *
   1.178 + * Sets the number of iterations of @test to @iterations.
   1.179 + */
   1.180 + #ifdef __SYMBIAN32__
   1.181 + EXPORT_C
   1.182 +#endif
   1.183 +void
   1.184 +oil_test_set_iterations (OilTest *test, int iterations)
   1.185 +{
   1.186 +  test->iterations = iterations;
   1.187 +}
   1.188 +
   1.189 +/**
   1.190 + * oil_test_set_test_header:
   1.191 + * @test: the OilTest
   1.192 + * @p: the OilParameter to change the header for
   1.193 + * @test_header: the number of bytes of guard header
   1.194 + *
   1.195 + * Sets the number of bytes of guard header for @p to @test_header.
   1.196 + */
   1.197 + #ifdef __SYMBIAN32__
   1.198 + EXPORT_C
   1.199 +#endif
   1.200 +void
   1.201 +oil_test_set_test_header (OilTest *test, OilParameter *p, int test_header)
   1.202 +{
   1.203 +  p->test_header = test_header;
   1.204 +}
   1.205 +
   1.206 +/**
   1.207 + * oil_test_set_test_footer:
   1.208 + * @test: the OilTest
   1.209 + * @p: the OilParameter to change the footer for
   1.210 + * @test_footer: the number of bytes of guard footer
   1.211 + *
   1.212 + * Sets the number of bytes of guard footer for @p to @test_footer.
   1.213 + */
   1.214 + #ifdef __SYMBIAN32__
   1.215 + EXPORT_C
   1.216 +#endif
   1.217 +void
   1.218 +oil_test_set_test_footer (OilTest *test, OilParameter *p, int test_footer)
   1.219 +{
   1.220 +  p->test_footer = test_footer;
   1.221 +}
   1.222 +
   1.223 +/**
   1.224 + * oil_test_init:
   1.225 + * @test: the OilTest
   1.226 + *
   1.227 + * Intializes @test.
   1.228 + * 
   1.229 + * FIXME: needs work
   1.230 + */
   1.231 + #ifdef __SYMBIAN32__
   1.232 + EXPORT_C
   1.233 +#endif
   1.234 +void
   1.235 +oil_test_init (OilTest *test)
   1.236 +{
   1.237 +  if (test->inited) {
   1.238 +    return;
   1.239 +  }
   1.240 +
   1.241 +  oil_test_init_params(test);
   1.242 +
   1.243 +  test->params[OIL_ARG_N].value = test->n;
   1.244 +  
   1.245 +  test->inited = 1;
   1.246 +
   1.247 +  if (test->klass->test_func) {
   1.248 +    test->klass->test_func (test);
   1.249 +  }
   1.250 +}
   1.251 +
   1.252 +#ifdef __WINSCW__
   1.253 +#pragma suppress_warnings on 
   1.254 +#endif//__WINSCW__
   1.255 +#ifdef __ARMCC__
   1.256 +#pragma diag_remark 188
   1.257 +#endif//__ARMCC__
   1.258 +
   1.259 +static void
   1.260 +oil_test_check_function (void * priv)
   1.261 +{
   1.262 +  OilTest *test = priv;
   1.263 +  int i;
   1.264 +  int j;
   1.265 +  unsigned long args[MAX_PARAMS];
   1.266 +  unsigned int pointer_mask;
   1.267 +
   1.268 +  oil_test_init (test);
   1.269 +
   1.270 +  OIL_LOG("calling function %s", test->impl->name);
   1.271 +
   1.272 +  pointer_mask = 1;
   1.273 +  for(i=0;i<test->proto->n_params;i++){
   1.274 +    OilParameter *p;
   1.275 +    j = test->proto->params[i].parameter_type;
   1.276 +    p = &test->params[j];
   1.277 +
   1.278 +    pointer_mask <<= 1;
   1.279 +    OIL_LOG("  %s: 0x%08lx (%ld)", oil_arg_type_name (j), p->value, p->value);
   1.280 +    if (p->is_pointer) {
   1.281 +      pointer_mask |= 1;
   1.282 +      if (p->direction == 's') {
   1.283 +        args[i] = (unsigned long)p->src_data + p->test_header;
   1.284 +      } else if (p->direction == 'i') {
   1.285 +        memcpy (p->test_data, p->src_data, p->size);
   1.286 +        args[i] = (unsigned long)p->test_data + p->test_header;
   1.287 +      } else if (p->direction == 'd') {
   1.288 +        memset (p->test_data, p->guard, p->size);
   1.289 +        args[i] = (unsigned long)p->test_data + p->test_header;
   1.290 +      } else {
   1.291 +        OIL_ERROR ("not reached");
   1.292 +      }
   1.293 +    } else {
   1.294 +      args[i] = p->value;
   1.295 +    }
   1.296 +  }
   1.297 +#ifdef __WINSCW__
   1.298 +#pragma suppress_warnings off
   1.299 +#endif//__WINSCW__
   1.300 +
   1.301 +  oil_profile_init (&test->prof);
   1.302 +  for(i=0;i<test->iterations;i++){
   1.303 +    int k;
   1.304 +
   1.305 +    for(k=0;k<test->proto->n_params;k++){
   1.306 +      OilParameter *p;
   1.307 +      j = test->proto->params[k].parameter_type;
   1.308 +      p = &test->params[j];
   1.309 +      if (p->direction == 'i') {
   1.310 +        memcpy (p->test_data, p->src_data, p->size);
   1.311 +      }
   1.312 +    }
   1.313 +    _oil_test_marshal_function (test->impl->func, args, test->proto->n_params,
   1.314 +        pointer_mask, &test->prof);
   1.315 +  }
   1.316 +
   1.317 +  oil_profile_get_ave_std (&test->prof, &test->profile_ave,
   1.318 +      &test->profile_std);
   1.319 +}
   1.320 +
   1.321 +/**
   1.322 + * oil_test_check_ref:
   1.323 + * @test: the OilTest
   1.324 + *
   1.325 + * Runs the test specified by @test on the reference function of the
   1.326 + * class being tested.
   1.327 + */
   1.328 + #ifdef __SYMBIAN32__
   1.329 + EXPORT_C
   1.330 +#endif
   1.331 +void
   1.332 +oil_test_check_ref (OilTest *test)
   1.333 +{
   1.334 +  int i;
   1.335 +
   1.336 +  if (test->proto->n_params > MAX_PARAMS) {
   1.337 +    OIL_ERROR ("function class %s has too many parameters",
   1.338 +        test->klass->name);
   1.339 +    return;
   1.340 +  }
   1.341 +  if (test->klass->reference_impl == NULL) {
   1.342 +    OIL_ERROR ("function class %s has no reference implementation",
   1.343 +        test->klass->name);
   1.344 +    return;
   1.345 +  }
   1.346 +
   1.347 +  test->impl = test->klass->reference_impl;
   1.348 +
   1.349 +  oil_test_check_function (test);
   1.350 +
   1.351 +  for(i=0;i<OIL_ARG_LAST;i++){
   1.352 +    OilParameter *p = &test->params[i];
   1.353 +
   1.354 +    if (p->is_pointer) {
   1.355 +      if (p->direction == 'i' || p->direction == 'd') {
   1.356 +        memcpy (p->ref_data, p->test_data, p->size);
   1.357 +      }
   1.358 +    }
   1.359 +  }
   1.360 +
   1.361 +  test->tested_ref = 1;
   1.362 +}
   1.363 +
   1.364 +static int
   1.365 +check_guard (uint8_t *data, int n, int guard)
   1.366 +{
   1.367 +  int i;
   1.368 +  for(i=0;i<n;i++) {
   1.369 +    if (data[i] != guard) return 0;
   1.370 +  }
   1.371 +  return 1;
   1.372 +}
   1.373 +
   1.374 +/**
   1.375 + * oil_test_check_impl:
   1.376 + * @test: the OilTest
   1.377 + * @impl: an OilFunctionImpl
   1.378 + *
   1.379 + * Runs the testing procedure described by @test on the implementation
   1.380 + * @impl.
   1.381 + *
   1.382 + * Returns: 1 if @impl passes the test, 0 if it fails
   1.383 + */
   1.384 + #ifdef __SYMBIAN32__
   1.385 + EXPORT_C
   1.386 +#endif
   1.387 +int
   1.388 +oil_test_check_impl (OilTest *test, OilFunctionImpl *impl)
   1.389 +{
   1.390 +  double x;
   1.391 +  int i;
   1.392 +  int n;
   1.393 +  int fail = 0;
   1.394 +  int ret;
   1.395 +
   1.396 +  if (test->proto->n_params > MAX_PARAMS) {
   1.397 +    OIL_ERROR ("function has too many parameters");
   1.398 +    return 0;
   1.399 +  }
   1.400 +
   1.401 +  if (!test->inited || !test->tested_ref) {
   1.402 +    oil_test_check_ref(test);
   1.403 +  }
   1.404 +
   1.405 +  test->impl = impl;
   1.406 +  ret = oil_fault_check_try (oil_test_check_function, test);
   1.407 +  if (!ret) {
   1.408 +    OIL_ERROR ("illegal instruction in %s", test->impl->name);
   1.409 +    test->profile_ave = 0;
   1.410 +    test->profile_std = 0;
   1.411 +
   1.412 +    return 0;
   1.413 +  }
   1.414 +
   1.415 +  x = 0;
   1.416 +  n = 0;
   1.417 +  for(i=0;i<OIL_ARG_LAST;i++){
   1.418 +    OilParameter *p = &test->params[i];
   1.419 +
   1.420 +    if (p->is_pointer) {
   1.421 +      if (p->direction == 'i' || p->direction == 'd') {
   1.422 +        x += check_array (p->test_data + p->test_header,
   1.423 +            p->ref_data + p->test_header, p->type, p->pre_n, p->stride,
   1.424 +            p->post_n);
   1.425 +        n += p->pre_n * p->post_n;
   1.426 +        if (!check_guard (p->test_data, p->test_header, p->guard)) {
   1.427 +          fail = 1;
   1.428 +          OIL_ERROR("function %s wrote before area for parameter %s",
   1.429 +              test->impl->name, p->parameter_name);
   1.430 +        }
   1.431 +        if (!check_guard ((uint8_t *)p->test_data + p->size - p->test_footer,
   1.432 +              p->test_footer, p->guard)) {
   1.433 +          fail = 1;
   1.434 +          OIL_ERROR("function %s wrote after area for parameter %s",
   1.435 +              test->impl->name, p->parameter_name);
   1.436 +        }
   1.437 +        if (!check_holes (p->test_data, p->type, p->pre_n, p->stride,
   1.438 +              p->post_n, p->guard)) {
   1.439 +          fail = 1;
   1.440 +          OIL_ERROR("function %s wrote in interstitial area for parameter %s",
   1.441 +              test->impl->name, p->parameter_name);
   1.442 +        }
   1.443 +      }
   1.444 +    }
   1.445 +  }
   1.446 +  OIL_DEBUG("sum of absolute differences %g for %d values", x, n);
   1.447 +  test->sum_abs_diff = x;
   1.448 +  test->n_points = n;
   1.449 +
   1.450 +  if (x > test->tolerance * n || fail) {
   1.451 +    OIL_ERROR ("function %s in class %s failed check (%g > %g) || (outside=%d)",
   1.452 +        test->impl->name, test->klass->name, x, test->tolerance * n, fail);
   1.453 +    return 0;
   1.454 +  }
   1.455 +
   1.456 +  return 1;
   1.457 +}
   1.458 +
   1.459 +/**
   1.460 + * oil_test_cleanup
   1.461 + * @test: the OilTest
   1.462 + *
   1.463 + * Cleans up @test.
   1.464 + *
   1.465 + * FIXME: needs work
   1.466 + */
   1.467 + #ifdef __SYMBIAN32__
   1.468 + EXPORT_C
   1.469 +#endif
   1.470 +void
   1.471 +oil_test_cleanup (OilTest *test)
   1.472 +{
   1.473 +  OilParameter *params = test->params;
   1.474 +
   1.475 +  /* src1 */
   1.476 +  if(params[OIL_ARG_SRC1].type) {
   1.477 +    if (!params[OIL_ARG_SSTR1].type) {
   1.478 +      params[OIL_ARG_SSTR1].value = oil_type_sizeof (params[OIL_ARG_SRC1].type);
   1.479 +    }
   1.480 +  }
   1.481 +
   1.482 +  /* src2 */
   1.483 +  if(params[OIL_ARG_SRC2].type) {
   1.484 +    if (!params[OIL_ARG_SSTR2].type) {
   1.485 +      params[OIL_ARG_SSTR2].value = oil_type_sizeof (params[OIL_ARG_SRC2].type);
   1.486 +    }
   1.487 +  }
   1.488 +
   1.489 +  /* src3 */
   1.490 +  if(params[OIL_ARG_SRC3].type) {
   1.491 +    if (!params[OIL_ARG_SSTR3].type) {
   1.492 +      params[OIL_ARG_SSTR3].value = oil_type_sizeof (params[OIL_ARG_SRC3].type);
   1.493 +    }
   1.494 +  }
   1.495 +
   1.496 +  /* dest1 */
   1.497 +  if(params[OIL_ARG_DEST1].type) {
   1.498 +    if (!params[OIL_ARG_DSTR1].type) {
   1.499 +      params[OIL_ARG_DSTR1].value = oil_type_sizeof (params[OIL_ARG_DEST1].type);
   1.500 +    }
   1.501 +  }
   1.502 +
   1.503 +  /* dest2 */
   1.504 +  if(params[OIL_ARG_DEST2].type) {
   1.505 +    if (!params[OIL_ARG_DSTR2].type) {
   1.506 +      params[OIL_ARG_DSTR2].value = oil_type_sizeof (params[OIL_ARG_DEST2].type);
   1.507 +    }
   1.508 +  }
   1.509 +
   1.510 +  /* dest3 */
   1.511 +  if(params[OIL_ARG_DEST3].type) {
   1.512 +    if (!params[OIL_ARG_DSTR3].type) {
   1.513 +      params[OIL_ARG_DSTR3].value = oil_type_sizeof (params[OIL_ARG_DEST3].type);
   1.514 +    }
   1.515 +  }
   1.516 +
   1.517 +}
   1.518 +
   1.519 +
   1.520 +static void
   1.521 +init_parameter (OilTest *test, OilParameter *p, OilParameter *ps)
   1.522 +{
   1.523 +  if (!p->type) return;
   1.524 +
   1.525 +  p->pre_n = p->prestride_length;
   1.526 +  if (p->prestride_var == 1) {
   1.527 +    p->pre_n += test->n;
   1.528 +  }
   1.529 +  if (p->prestride_var == 2) {
   1.530 +    p->pre_n += test->m;
   1.531 +  }
   1.532 +
   1.533 +  if (ps->value) {
   1.534 +    p->stride = ps->value;
   1.535 +  } else {
   1.536 +    p->stride = oil_type_sizeof (p->type) * p->pre_n;
   1.537 +    ps->value = p->stride;
   1.538 +  }
   1.539 +
   1.540 +  p->post_n = p->poststride_length;
   1.541 +  if (p->poststride_var == 1) {
   1.542 +    p->post_n += test->n;
   1.543 +  }
   1.544 +  if (p->poststride_var == 2) {
   1.545 +    p->post_n += test->m;
   1.546 +  }
   1.547 +
   1.548 +  p->size = p->stride * p->post_n + p->test_header + p->test_footer;
   1.549 +  p->guard = oil_rand_u8();
   1.550 +
   1.551 +  if (p->direction == 'i' || p->direction == 's') {
   1.552 +    if (p->src_data) free (p->src_data);
   1.553 +
   1.554 +    OIL_DEBUG("allocating %d bytes for src_data for %s", p->size, p->parameter_name);
   1.555 +    p->src_data = malloc (p->size);
   1.556 +    memset (p->src_data, p->guard, p->size);
   1.557 +    fill_array (p->src_data + p->test_header, p->type, p->pre_n, p->stride, p->post_n);
   1.558 +  }
   1.559 +
   1.560 +  if (p->direction == 'i' || p->direction == 'd') {
   1.561 +    if (p->ref_data) free (p->ref_data);
   1.562 +    p->ref_data = malloc (p->size);
   1.563 +    memset (p->ref_data, p->guard, p->size);
   1.564 +    OIL_DEBUG("allocating %d bytes for ref_data and test_data for %s", p->size, p->parameter_name);
   1.565 +
   1.566 +    if (p->test_data) free (p->test_data);
   1.567 +    p->test_data = malloc (p->size);
   1.568 +    memset (p->test_data, p->guard, p->size);
   1.569 +  }
   1.570 +}
   1.571 +
   1.572 +static void
   1.573 +oil_test_init_params (OilTest *test)
   1.574 +{
   1.575 +  init_parameter (test, &test->params[OIL_ARG_DEST1],
   1.576 +      &test->params[OIL_ARG_DSTR1]);
   1.577 +  init_parameter (test, &test->params[OIL_ARG_DEST2],
   1.578 +      &test->params[OIL_ARG_DSTR2]);
   1.579 +  init_parameter (test, &test->params[OIL_ARG_DEST3],
   1.580 +      &test->params[OIL_ARG_DSTR3]);
   1.581 +
   1.582 +  init_parameter (test, &test->params[OIL_ARG_SRC1],
   1.583 +      &test->params[OIL_ARG_SSTR1]);
   1.584 +  init_parameter (test, &test->params[OIL_ARG_SRC2],
   1.585 +      &test->params[OIL_ARG_SSTR2]);
   1.586 +  init_parameter (test, &test->params[OIL_ARG_SRC3],
   1.587 +      &test->params[OIL_ARG_SSTR3]);
   1.588 +  init_parameter (test, &test->params[OIL_ARG_SRC4],
   1.589 +      &test->params[OIL_ARG_SSTR4]);
   1.590 +  init_parameter (test, &test->params[OIL_ARG_SRC5],
   1.591 +      &test->params[OIL_ARG_SSTR5]);
   1.592 +
   1.593 +  init_parameter (test, &test->params[OIL_ARG_INPLACE1],
   1.594 +      &test->params[OIL_ARG_ISTR1]);
   1.595 +  init_parameter (test, &test->params[OIL_ARG_INPLACE2],
   1.596 +      &test->params[OIL_ARG_ISTR2]);
   1.597 +}
   1.598 +
   1.599 +static void
   1.600 +fill_array (void *data, OilType type, int pre_n, int stride, int post_n)
   1.601 +{
   1.602 +  int i;
   1.603 +
   1.604 +#define FILL(type,func) do {\
   1.605 +  for(i=0;i<post_n;i++){ \
   1.606 +    func (OIL_OFFSET(data, i*stride), pre_n); \
   1.607 +  } \
   1.608 +}while(0)
   1.609 +
   1.610 +  switch (type) {
   1.611 +    case OIL_TYPE_s8p:
   1.612 +      FILL(int8_t,oil_random_s8);
   1.613 +      break;
   1.614 +    case OIL_TYPE_u8p:
   1.615 +      FILL(uint8_t,oil_random_u8);
   1.616 +      break;
   1.617 +    case OIL_TYPE_s16p:
   1.618 +      FILL(int16_t,oil_random_s16);
   1.619 +      break;
   1.620 +    case OIL_TYPE_u16p:
   1.621 +      FILL(uint16_t,oil_random_u16);
   1.622 +      break;
   1.623 +    case OIL_TYPE_s32p:
   1.624 +      FILL(int32_t,oil_random_s32);
   1.625 +      break;
   1.626 +    case OIL_TYPE_u32p:
   1.627 +      FILL(uint32_t,oil_random_u32);
   1.628 +      break;
   1.629 +    case OIL_TYPE_s64p:
   1.630 +      FILL(int64_t,oil_random_s64);
   1.631 +      break;
   1.632 +    case OIL_TYPE_u64p:
   1.633 +      FILL(uint64_t,oil_random_u64);
   1.634 +      break;
   1.635 +    case OIL_TYPE_f32p:
   1.636 +      FILL(float,oil_random_f32);
   1.637 +      break;
   1.638 +    case OIL_TYPE_f64p:
   1.639 +      FILL(double,oil_random_f64);
   1.640 +      break;
   1.641 +    default:
   1.642 +      OIL_ERROR ("should not be reached (type == %d)", type);
   1.643 +      return;
   1.644 +      break;
   1.645 +  }
   1.646 +}
   1.647 +
   1.648 +static double
   1.649 +check_array (void *data, void *ref, OilType type, int pre_n, int stride, int post_n)
   1.650 +{
   1.651 +  int i;
   1.652 +  int j;
   1.653 +  int s2 = oil_type_sizeof (type);
   1.654 +  double x = 0;
   1.655 +
   1.656 +#if 0
   1.657 +  OIL_ERROR ("check array pre_n=%d stride=%d post_n=%d",
   1.658 +      pre_n, stride, post_n);
   1.659 +#endif
   1.660 +
   1.661 +#define CHECK(type) do {\
   1.662 +  for(i=0;i<post_n;i++){ \
   1.663 +    for(j=0;j<pre_n;j++){ \
   1.664 +      x += fabs((double)OIL_GET(data, i*stride + j*s2, type) - \
   1.665 +          (double)OIL_GET(ref, i*stride + j*s2, type)); \
   1.666 +    } \
   1.667 +  } \
   1.668 +}while(0)
   1.669 +
   1.670 +  switch (type) {
   1.671 +    case OIL_TYPE_s8p:
   1.672 +      CHECK(int8_t);
   1.673 +      break;
   1.674 +    case OIL_TYPE_u8p:
   1.675 +      CHECK(uint8_t);
   1.676 +      break;
   1.677 +    case OIL_TYPE_s16p:
   1.678 +      CHECK(int16_t);
   1.679 +      break;
   1.680 +    case OIL_TYPE_u16p:
   1.681 +      CHECK(uint16_t);
   1.682 +      break;
   1.683 +    case OIL_TYPE_s32p:
   1.684 +      CHECK(int32_t);
   1.685 +      break;
   1.686 +    case OIL_TYPE_u32p:
   1.687 +      CHECK(uint32_t);
   1.688 +      break;
   1.689 +    case OIL_TYPE_s64p:
   1.690 +      CHECK(int64_t);
   1.691 +      break;
   1.692 +    case OIL_TYPE_u64p:
   1.693 +      CHECK(uint64_t);
   1.694 +      break;
   1.695 +    case OIL_TYPE_f32p:
   1.696 +      CHECK(float);
   1.697 +      break;
   1.698 +    case OIL_TYPE_f64p:
   1.699 +      CHECK(double);
   1.700 +      break;
   1.701 +    default:
   1.702 +      OIL_ERROR ("should not be reached (type == %d)", type);
   1.703 +      return 1e9;
   1.704 +      break;
   1.705 +  }
   1.706 +  return x;
   1.707 +}
   1.708 +
   1.709 +static int
   1.710 +check_holes (void *data, OilType type, int pre_n, int stride, int post_n,
   1.711 +    int guard)
   1.712 +{
   1.713 +  int i;
   1.714 +  int chunk_size;
   1.715 +  int hole_size;
   1.716 +
   1.717 +  chunk_size = pre_n * oil_type_sizeof (type);
   1.718 +  hole_size = stride - chunk_size;
   1.719 +  if (hole_size == 0) {
   1.720 +    return 1;
   1.721 +  }
   1.722 +
   1.723 +  for(i=0;i<post_n;i++){
   1.724 +    if (!check_guard (OIL_OFFSET(data, stride * i + chunk_size),
   1.725 +        hole_size, guard)) {
   1.726 +      return 0;
   1.727 +    }
   1.728 +  }
   1.729 +
   1.730 +  return 1;
   1.731 +}
   1.732 +
   1.733 +#ifdef __SYMBIAN32__
   1.734 + EXPORT_C
   1.735 +#endif
   1.736 +void *
   1.737 +oil_test_get_source_data (OilTest *test, OilArgType arg_type)
   1.738 +{
   1.739 +  uint8_t *ptr;
   1.740 + 
   1.741 +  ptr = test->params[arg_type].src_data;
   1.742 +  ptr += test->params[arg_type].test_header;
   1.743 +
   1.744 +  return ptr;
   1.745 +}
   1.746 +
   1.747 +#ifdef __SYMBIAN32__
   1.748 + EXPORT_C
   1.749 +#endif
   1.750 +int
   1.751 +oil_test_get_arg_pre_n (OilTest *test, OilArgType arg_type)
   1.752 +{
   1.753 +  return test->params[arg_type].pre_n;
   1.754 +}
   1.755 +
   1.756 +#ifdef __SYMBIAN32__
   1.757 + EXPORT_C
   1.758 +#endif
   1.759 +int
   1.760 +oil_test_get_arg_post_n (OilTest *test, OilArgType arg_type)
   1.761 +{
   1.762 +  return test->params[arg_type].post_n;
   1.763 +}
   1.764 +
   1.765 +#ifdef __SYMBIAN32__
   1.766 + EXPORT_C
   1.767 +#endif
   1.768 +int
   1.769 +oil_test_get_arg_stride (OilTest *test, OilArgType arg_type)
   1.770 +{
   1.771 +  return test->params[arg_type].stride;
   1.772 +}
   1.773 +
   1.774 +#ifdef __SYMBIAN32__
   1.775 + EXPORT_C
   1.776 +#endif
   1.777 +int
   1.778 +oil_test_get_value (OilTest *test, OilArgType arg_type)
   1.779 +{
   1.780 +  return test->params[arg_type].value;
   1.781 +}