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