os/ossrv/genericopenlibs/liboil/tsrc/testsuite/test1/src/test1.c
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200
changeset 0 bde4ae8d615e
permissions -rw-r--r--
First public contribution.
sl@0
     1
/*
sl@0
     2
 * LIBOIL - Library of Optimized Inner Loops
sl@0
     3
 * Copyright (c) 2004 David A. Schleef <ds@schleef.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
sl@0
    29
#include <stdio.h>
sl@0
    30
#include <liboil/liboil.h>
sl@0
    31
#include <ctype.h>
sl@0
    32
#include <stdlib.h>
sl@0
    33
#include <string.h>
sl@0
    34
#include <math.h>
sl@0
    35
sl@0
    36
#include <liboil/liboilprototype.h>
sl@0
    37
#include <liboil/liboiltest.h>
sl@0
    38
#include <liboil/liboilcpu.h>
sl@0
    39
#define LOG_FILE "c:\\logs\\testsuite_test1_log1.txt"
sl@0
    40
#include "std_log_result.h"
sl@0
    41
#define LOG_FILENAME_LINE __FILE__, __LINE__
sl@0
    42
sl@0
    43
void create_xml(int result)
sl@0
    44
{
sl@0
    45
    if(result)
sl@0
    46
        assert_failed = 1;
sl@0
    47
    
sl@0
    48
    testResultXml("testsuite_test1");
sl@0
    49
    close_log_file();
sl@0
    50
}
sl@0
    51
sl@0
    52
void hist(OilTest *Test);
sl@0
    53
sl@0
    54
int main (int argc, char *argv[])
sl@0
    55
{
sl@0
    56
  OilFunctionClass *klass;
sl@0
    57
  OilFunctionImpl *impl;
sl@0
    58
  OilTest *test;
sl@0
    59
  int i;
sl@0
    60
  int n;
sl@0
    61
  //int j;
sl@0
    62
  int ret;
sl@0
    63
  unsigned int cpu_flags;
sl@0
    64
  //xmlfile = "test1";
sl@0
    65
  std_log(LOG_FILENAME_LINE, "Test Started testsuite_test1");
sl@0
    66
  
sl@0
    67
  oil_init ();
sl@0
    68
sl@0
    69
  cpu_flags = oil_cpu_get_flags ();     //Returns a bitmask containing the available CPU features
sl@0
    70
  n = oil_class_get_n_classes ();       
sl@0
    71
  for (i=0;i<n; i++ ){
sl@0
    72
    klass = oil_class_get_by_index(i);
sl@0
    73
sl@0
    74
    printf("%s\n", klass->name);
sl@0
    75
    std_log(LOG_FILENAME_LINE, "class name = %s\n",klass->name);
sl@0
    76
sl@0
    77
    test = oil_test_new (klass);        //Creates a new OilTest(structure describing how to test an OilFunctionImpl for an OilFunctionClass) for the OilFunctionClass represented by klass
sl@0
    78
    if (test == NULL) {
sl@0
    79
      std_log(LOG_FILENAME_LINE, "bad prototype");
sl@0
    80
      printf("  bad prototype\n");
sl@0
    81
      continue;
sl@0
    82
    }
sl@0
    83
sl@0
    84
    for (impl = klass->first_impl; impl; impl = impl->next) 
sl@0
    85
    {
sl@0
    86
        printf("  %s\n", impl->name);
sl@0
    87
        if ((impl->flags & OIL_CPU_FLAG_MASK) & ~cpu_flags) 
sl@0
    88
        {
sl@0
    89
            std_log(LOG_FILENAME_LINE, "not supported");
sl@0
    90
            printf("not supported\n");
sl@0
    91
        } 
sl@0
    92
        else 
sl@0
    93
        {
sl@0
    94
            test->n = 1600;
sl@0
    95
            ret = oil_test_check_impl (test, impl);     //Runs the testing procedure described by test on the implementation impl
sl@0
    96
            if (ret) 
sl@0
    97
            {
sl@0
    98
                #if 0
sl@0
    99
                printf("    %lu %g\n",test->prof.min,
sl@0
   100
                (double)test->prof.total/test->prof.n);
sl@0
   101
                for(j=0;j<test->prof.hist_n;j++){
sl@0
   102
                printf("    %lu %d\n",test->prof.hist_time[j],test->prof.hist_count[j]);
sl@0
   103
                }
sl@0
   104
                #endif
sl@0
   105
                printf("    ave=%g std=%g\n", impl->profile_ave, impl->profile_std);
sl@0
   106
                //hist(test);
sl@0
   107
            } 
sl@0
   108
            else 
sl@0
   109
            {
sl@0
   110
                printf("  not tested\n");
sl@0
   111
                oil_test_free (test);
sl@0
   112
                std_log(LOG_FILENAME_LINE, "Test Failed");
sl@0
   113
                create_xml(1);
sl@0
   114
                return 1;
sl@0
   115
            }
sl@0
   116
        }
sl@0
   117
    }//for loop
sl@0
   118
sl@0
   119
    oil_test_free (test);   //Frees memory associated with test(OilTest)
sl@0
   120
  }
sl@0
   121
  std_log(LOG_FILENAME_LINE, "Test Successful");
sl@0
   122
  create_xml(0);
sl@0
   123
  return 0;
sl@0
   124
}
sl@0
   125
sl@0
   126
sl@0
   127
void
sl@0
   128
hist(OilTest *test)
sl@0
   129
{
sl@0
   130
  double ave;
sl@0
   131
  double std;
sl@0
   132
  int max_i;
sl@0
   133
  double off;
sl@0
   134
  double s;
sl@0
   135
  double s2;
sl@0
   136
  int i;
sl@0
   137
  int n;
sl@0
   138
  double x;
sl@0
   139
sl@0
   140
  do {
sl@0
   141
    s = s2 = 0;
sl@0
   142
    n = 0;
sl@0
   143
    max_i = -1;
sl@0
   144
    for(i=0;i<10;i++){
sl@0
   145
      x = test->prof.hist_time[i];
sl@0
   146
      s2 += x * x * test->prof.hist_count[i];
sl@0
   147
      s += x * test->prof.hist_count[i];
sl@0
   148
      n += test->prof.hist_count[i];
sl@0
   149
      if (test->prof.hist_count[i] > 0) {
sl@0
   150
        if (max_i == -1 || test->prof.hist_time[i] > test->prof.hist_time[max_i]) {
sl@0
   151
          max_i = i;
sl@0
   152
        }
sl@0
   153
      }
sl@0
   154
    }
sl@0
   155
sl@0
   156
    ave = s / n;
sl@0
   157
    std = sqrt (s2 - s * s / n + n*n) / (n-1);
sl@0
   158
    off = (test->prof.hist_time[max_i] - ave)/std;
sl@0
   159
sl@0
   160
    printf("    ave=%g std=%g max=%ld off=%g %s\n",
sl@0
   161
        ave, std, test->prof.hist_time[max_i], off, (off>4.0)?"yes":"no");
sl@0
   162
sl@0
   163
    if (off > 4.0) {
sl@0
   164
      test->prof.hist_count[max_i] = 0;
sl@0
   165
    }
sl@0
   166
  } while (off > 4.0);
sl@0
   167
  printf("    ave=%g std=%g\n", ave, std);
sl@0
   168
}
sl@0
   169
sl@0
   170