os/ossrv/genericopenlibs/liboil/tsrc/testsuite/stride/src/stride.c
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/ossrv/genericopenlibs/liboil/tsrc/testsuite/stride/src/stride.c	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,187 @@
     1.4 +/*
     1.5 + * LIBOIL - Library of Optimized Inner Loops
     1.6 + * Copyright (c) 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 +
    1.31 +
    1.32 +#include <stdio.h>
    1.33 +#include <liboil/liboilprototype.h>
    1.34 +#include <liboil/liboiltest.h>
    1.35 +#include <liboil/liboilcpu.h>
    1.36 +#include <liboil/liboilrandom.h>
    1.37 +#include <liboil/liboil.h>
    1.38 +#include <ctype.h>
    1.39 +#include <stdlib.h>
    1.40 +#include <string.h>
    1.41 +#include <math.h>
    1.42 +
    1.43 +
    1.44 +#define LOG_FILE "c:\\logs\\testsuite_stride_log1.txt"
    1.45 +#include "std_log_result.h"
    1.46 +#define LOG_FILENAME_LINE __FILE__, __LINE__
    1.47 +
    1.48 +void create_xml(int result)
    1.49 +{
    1.50 +    if(result)
    1.51 +        assert_failed = 1;
    1.52 +    
    1.53 +    testResultXml("testsuite_stride");
    1.54 +    close_log_file();
    1.55 +}
    1.56 +
    1.57 +void hist(OilTest *Test);
    1.58 +
    1.59 +int verbose = 0;
    1.60 +int fail = 0;
    1.61 +
    1.62 +int main (int argc, char *argv[])
    1.63 +{
    1.64 +  OilFunctionClass *klass;
    1.65 +  OilFunctionImpl *impl;
    1.66 +  OilTest *test;
    1.67 +  int i;
    1.68 +  int n;
    1.69 +  int j;
    1.70 +  int ret;
    1.71 +  unsigned int cpu_flags;
    1.72 +  //xmlfile = "stride";
    1.73 +  std_log(LOG_FILENAME_LINE, "Test Started testsuite_stride");
    1.74 +
    1.75 +  if (argc > 1 && strcmp(argv[1],"-v") == 0) {
    1.76 +    verbose = 1;
    1.77 +  }
    1.78 +  oil_init ();
    1.79 +
    1.80 +  cpu_flags = oil_cpu_get_flags ();
    1.81 +  n = oil_class_get_n_classes ();
    1.82 +  
    1.83 +  for (i=0;i<n; i++ )
    1.84 +  {
    1.85 +      klass = oil_class_get_by_index(i);
    1.86 +      std_log(LOG_FILENAME_LINE,"Class Name %s %d\n",klass->name, i);
    1.87 +
    1.88 +      test = oil_test_new (klass);
    1.89 +
    1.90 +      if (test == NULL) 
    1.91 +      {
    1.92 +          std_log(LOG_FILENAME_LINE,"class \"%s\" has  bad prototype\n", klass->name);
    1.93 +          assert_failed = fail = 1; 
    1.94 +          continue;
    1.95 +      }
    1.96 +      oil_test_set_iterations (test, 1);
    1.97 +      test->n = 1 + oil_rand_u8();
    1.98 +      test->m = 1 + oil_rand_u8();
    1.99 +
   1.100 +      std_log(LOG_FILENAME_LINE, "ref impl %s",klass->reference_impl->name);
   1.101 +      oil_test_check_impl (test, klass->reference_impl);        //Testing whether an appropriate implementation is suitable or not
   1.102 +                                                                //Runs the testing procedure described by test on the implementation impl
   1.103 +      
   1.104 +      for(j=0;j<OIL_ARG_LAST;j++)
   1.105 +      {
   1.106 +          if (test->params[j].is_stride) 
   1.107 +          {
   1.108 +              test->params[j].value += oil_type_sizeof(test->params[j].type) *
   1.109 +              (oil_rand_u8()&0xf);
   1.110 +          }
   1.111 +      }
   1.112 +      test->inited = 0;
   1.113 +
   1.114 +      for (impl = klass->first_impl; impl; impl = impl->next) 
   1.115 +      {
   1.116 +          std_log(LOG_FILENAME_LINE,"  %s\n", impl->name);
   1.117 +          if ((impl->flags & OIL_CPU_FLAG_MASK) & ~cpu_flags){
   1.118 +              std_log(LOG_FILENAME_LINE, "Not supported");
   1.119 +          } 
   1.120 +          else 
   1.121 +          {
   1.122 +              ret = oil_test_check_impl (test, impl);
   1.123 +              if (!ret) 
   1.124 +              {
   1.125 +                  assert_failed = fail = 1;
   1.126 +                  oil_test_free (test);
   1.127 +                  std_log(LOG_FILENAME_LINE, "Test Failed");
   1.128 +                  create_xml(1);
   1.129 +                  return fail;
   1.130 +              }
   1.131 +              
   1.132 +          }
   1.133 +          
   1.134 +      }
   1.135 +
   1.136 +      oil_test_free (test);
   1.137 +  }
   1.138 +  
   1.139 +  if(assert_failed)
   1.140 +      std_log(LOG_FILENAME_LINE,"Test Fail");
   1.141 +  else
   1.142 +      std_log(LOG_FILENAME_LINE,"Test Successful");
   1.143 +  create_xml(0);
   1.144 +  return fail;
   1.145 +}
   1.146 +
   1.147 +void
   1.148 +hist(OilTest *test)
   1.149 +{
   1.150 +  double ave;
   1.151 +  double std;
   1.152 +  int max_i;
   1.153 +  double off;
   1.154 +  double s;
   1.155 +  double s2;
   1.156 +  int i;
   1.157 +  int n;
   1.158 +  double x;
   1.159 +
   1.160 +  do {
   1.161 +    s = s2 = 0;
   1.162 +    n = 0;
   1.163 +    max_i = -1;
   1.164 +    for(i=0;i<10;i++){
   1.165 +      x = test->prof.hist_time[i];
   1.166 +      s2 += x * x * test->prof.hist_count[i];
   1.167 +      s += x * test->prof.hist_count[i];
   1.168 +      n += test->prof.hist_count[i];
   1.169 +      if (test->prof.hist_count[i] > 0) {
   1.170 +        if (max_i == -1 || test->prof.hist_time[i] > test->prof.hist_time[max_i]) {
   1.171 +          max_i = i;
   1.172 +        }
   1.173 +      }
   1.174 +    }
   1.175 +
   1.176 +    ave = s / n;
   1.177 +    std = sqrt (s2 - s * s / n + n*n) / (n-1);
   1.178 +    off = (test->prof.hist_time[max_i] - ave)/std;
   1.179 +
   1.180 +    printf("    ave=%g std=%g max=%ld off=%g %s\n",
   1.181 +        ave, std, test->prof.hist_time[max_i], off, (off>4.0)?"yes":"no");
   1.182 +
   1.183 +    if (off > 4.0) {
   1.184 +      test->prof.hist_count[max_i] = 0;
   1.185 +    }
   1.186 +  } while (off > 4.0);
   1.187 +  printf("    ave=%g std=%g\n", ave, std);
   1.188 +}
   1.189 +
   1.190 +