os/ossrv/genericopenlibs/liboil/tsrc/testsuite/introspect/src/introspect.c
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
     1 /*
     2  * LIBOIL - Library of Optimized Inner Loops
     3  * Copyright (c) 2004 David A. Schleef <ds@schleef.org>
     4  * All rights reserved.
     5  *
     6  * Redistribution and use in source and binary forms, with or without
     7  * modification, are permitted provided that the following conditions
     8  * are met:
     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.
    14  * 
    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.
    26  */
    27 
    28 
    29 #include <stdio.h>
    30 #include <liboil/liboil.h>
    31 #include <liboil/liboilfunction.h>
    32 #include <ctype.h>
    33 #include <stdlib.h>
    34 #include <string.h>
    35 
    36 #define LOG_FILE "c:\\logs\\testsuite_introspect_log.txt"
    37 #include "std_log_result.h"
    38 #define LOG_FILENAME_LINE __FILE__, __LINE__
    39 
    40 void create_xml(int result)
    41 {
    42     if(result)
    43         assert_failed = 1;
    44     
    45     testResultXml("testsuite_introspect");
    46     close_log_file();
    47 }
    48 
    49 void parse_prototype (const char *s);
    50 
    51 int main (int argc, char *argv[])
    52 {
    53   OilFunctionClass *klass;
    54   OilFunctionImpl *impl;
    55   int i;
    56   int n;
    57   int errors = 0;
    58 
    59   std_log(LOG_FILENAME_LINE,"Test started testsuite_introspect");
    60   oil_init ();
    61 
    62   n = oil_class_get_n_classes ();
    63   for (i=0;i<n; i++ ){
    64     int ref=0;
    65 
    66     klass = oil_class_get_by_index (i);
    67 
    68     std_log(LOG_FILENAME_LINE,"class: %s\n", klass->name);
    69     for(impl = klass->first_impl; impl; impl=impl->next) {
    70     std_log(LOG_FILENAME_LINE,"  %s %s %s\n", impl->name,
    71           (impl->flags&OIL_IMPL_FLAG_REF)?"(ref)":"",
    72           (impl->flags&OIL_IMPL_FLAG_OPT)?"(opt)":"");
    73       if (impl->flags & OIL_IMPL_FLAG_REF) {
    74         ref++;
    75       }
    76     }
    77     if (ref < 1) {
    78     std_log(LOG_FILENAME_LINE,"ERROR: no reference function\n");
    79       errors++;
    80     }
    81     if (ref > 1) {
    82     std_log(LOG_FILENAME_LINE,"ERROR: more than one reference function\n");
    83       errors++;
    84     }
    85     if (klass->prototype == NULL) {
    86     std_log(LOG_FILENAME_LINE,"ERROR: prototype is NULL\n");
    87       errors++;
    88     }
    89 #if 0
    90     printf ("#define %s ((void (*)(%s)) \\\n\t_oil_function_%s_class.func)\n",
    91         klass->name, klass->prototype, klass->name);
    92     //printf("void %s (%s);\n", klass->name, klass->prototype);
    93     parse_prototype(klass->prototype);
    94 #endif
    95   }
    96 
    97   assert_failed = (errors == 0) ? assert_failed : 1;
    98   if(assert_failed)
    99           std_log(LOG_FILENAME_LINE,"Test Fail");
   100   else
   101           std_log(LOG_FILENAME_LINE,"Test Successful");
   102   create_xml(0);
   103   return 0;
   104 }
   105 
   106 #ifdef unused
   107 static char *typenames[] = {
   108   "type_s8",
   109   "type_u8",
   110   "type_s16",
   111   "type_u16",
   112   "type_s32",
   113   "type_u32",
   114   "type_f32",
   115   "type_f64",
   116   "int8_t",
   117   "uint8_t",
   118   "int16_t",
   119   "uint16_t",
   120   "int32_t",
   121   "uint32_t",
   122   "float",
   123   "double",
   124   "int",
   125 };
   126 
   127 static int parse_type (char *s, char **endptr)
   128 {
   129   int i;
   130 
   131   while(isspace((int)*s))s++;
   132 
   133   for(i=0;i<8;i++){
   134     if(strncmp(typenames[i],s,strlen(typenames[i]))==0){
   135       *endptr = s + strlen(typenames[i]);
   136       return OIL_TYPE_s8 + i;
   137     }
   138   }
   139 
   140   return OIL_TYPE_UNKNOWN;
   141 }
   142 
   143 static int parse_size (const char *s, char **endptr)
   144 {
   145   while(isspace((int)*s))s++;
   146 
   147   if(s[0] == 'n'){
   148     *endptr = (char *)(s + 1);
   149     return 0;
   150   }
   151   if(isdigit((int)s[0])){
   152     return strtol(s,endptr,0);
   153   }
   154 
   155   return -1;
   156 }
   157 #endif
   158 
   159 char *
   160 xstrndup (const char *s, int n)
   161 {
   162   char *r;
   163 
   164   if (strlen(s) < n) {
   165     n = strlen(s);
   166   }
   167   r = malloc(n+1);
   168   memcpy(r,s,n);
   169   r[n] = 0;
   170 
   171   return r;
   172 }
   173 
   174 static char * parse_string (const char *s, const char **endptr)
   175 {
   176   const char *s0;
   177 
   178   s0 = s;
   179   while(isalnum((int)*s) || *s=='_') {
   180     s++;
   181   }
   182   *endptr = s;
   183 
   184   return xstrndup(s0, s - s0);
   185 }
   186 
   187 void parse_prototype (const char *s)
   188 {
   189   char *type;
   190   char *name;
   191   int ptr = 0;
   192 
   193   while (isspace((int)*s))s++;
   194   while (*s) {
   195     type = parse_string (s, &s);
   196 
   197     while (isspace((int)*s))s++;
   198 
   199     if(s[0] == '*'){
   200       ptr = 1;
   201       s++;
   202     }
   203     while (isspace((int)*s))s++;
   204     name = parse_string (s, &s);
   205 
   206     while (isspace((int)*s))s++;
   207 
   208     if(s[0] == ','){
   209       s++;
   210     }
   211     while (isspace((int)*s))s++;
   212 
   213     std_log(LOG_FILENAME_LINE,"%s %s\n", type, name);
   214   }
   215 }
   216