os/ossrv/genericopenlibs/liboil/tsrc/testsuite/md5/src/md5.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.
     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 #ifdef HAVE_CONFIG_H
    30 #include "config.h"
    31 #endif
    32 
    33 #include <liboil/liboil.h>
    34 #include <liboil/liboilfunction.h>
    35 #include <stdio.h>
    36 #include <string.h>
    37 #include <liboil/globals.h>
    38 
    39 #define LOG_FILE "c:\\logs\\testsuite_md5_log.txt"
    40 #include "std_log_result.h"
    41 #define LOG_FILENAME_LINE __FILE__, __LINE__
    42 
    43 void create_xml(int result)
    44 {
    45     if(result)
    46         assert_failed = 1;
    47     
    48     testResultXml("testsuite_md5");
    49     close_log_file();
    50 }
    51 
    52 char *message = "liboil md5 test";
    53 //char *message = "";
    54 
    55 #ifdef WORDS_BIGENDIAN
    56 #define uint32_from_host(a) \
    57   ((((a)&0xff)<<24)|(((a)&0xff00)<<8)|(((a)&0xff0000)>>8)|(((a)>>24)&0xff))
    58 #else
    59 #define uint32_from_host(a) (a)
    60 #endif
    61 
    62 void test(void)
    63 {
    64   uint32_t state[4];
    65   uint32_t src[16];
    66   int len;
    67   char buf[33];
    68 
    69   state[0] = 0x67452301;
    70   state[1] = 0xefcdab89;
    71   state[2] = 0x98badcfe;
    72   state[3] = 0x10325476;
    73 
    74   memset (src, 0, 64);
    75   len = strlen (message);
    76   memcpy (src, message, len);
    77   ((uint8_t *)src)[len] = 0x80;
    78   src[14] = uint32_from_host(len << 3);
    79   src[15] = 0;
    80 
    81   oil_md5 (state, src);
    82 
    83   std_log(LOG_FILENAME_LINE,"%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x\n",
    84       state[0]&0xff, (state[0]>>8)&0xff, (state[0]>>16)&0xff,
    85       (state[0]>>24)&0xff,
    86       state[1]&0xff, (state[1]>>8)&0xff, (state[1]>>16)&0xff,
    87       (state[1]>>24)&0xff,
    88       state[2]&0xff, (state[2]>>8)&0xff, (state[2]>>16)&0xff,
    89       (state[2]>>24)&0xff,
    90       state[3]&0xff, (state[3]>>8)&0xff, (state[3]>>16)&0xff,
    91       (state[3]>>24)&0xff);
    92   sprintf(buf,"%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x",
    93         state[0]&0xff, (state[0]>>8)&0xff, (state[0]>>16)&0xff,
    94         (state[0]>>24)&0xff,
    95         state[1]&0xff, (state[1]>>8)&0xff, (state[1]>>16)&0xff,
    96         (state[1]>>24)&0xff,
    97         state[2]&0xff, (state[2]>>8)&0xff, (state[2]>>16)&0xff,
    98         (state[2]>>24)&0xff,
    99         state[3]&0xff, (state[3]>>8)&0xff, (state[3]>>16)&0xff,
   100         (state[3]>>24)&0xff);
   101   if(strcasecmp(buf, "4311e9ad205ad575539c1d7e208ee53a")){
   102       std_log(LOG_FILENAME_LINE,"buf = %s\n", buf);
   103       assert_failed = 1; 
   104   }
   105 }
   106 
   107 int main (int argc, char *argv[])
   108 {
   109   OilFunctionClass *klass;
   110   OilFunctionImpl *impl;
   111   
   112   std_log(LOG_FILENAME_LINE,"Test started testsuite_md5");
   113   oil_init ();
   114 
   115   klass = oil_class_get ("md5");
   116   oil_class_optimize(klass);
   117 
   118   std_log(LOG_FILENAME_LINE,"class=%s\n", klass->name);
   119   for (impl = klass->first_impl; impl; impl=impl->next) {
   120     std_log(LOG_FILENAME_LINE,"impl=%p\n", impl);
   121     std_log(LOG_FILENAME_LINE,"  func=%p\n", impl->func);
   122     std_log(LOG_FILENAME_LINE,"  name=%s\n", impl->name);
   123     std_log(LOG_FILENAME_LINE,"  flags=%08x\n", impl->flags);
   124   }
   125 
   126   oil_class_choose_by_name (klass, "md5_c");
   127   impl = klass->chosen_impl;
   128   std_log(LOG_FILENAME_LINE,"chosen=%p\n", impl);
   129   impl = klass->reference_impl;
   130   std_log(LOG_FILENAME_LINE,"ref=%p\n", impl);
   131   test();
   132 
   133   oil_class_choose_by_name (klass, "md5_asm1");
   134   impl = klass->chosen_impl;
   135   std_log(LOG_FILENAME_LINE,"chosen=%p\n", impl);
   136   impl = klass->reference_impl;
   137   std_log(LOG_FILENAME_LINE,"ref=%p\n", impl);
   138   test();
   139 
   140   oil_class_choose_by_name (klass, "md5_asm2");
   141   impl = klass->chosen_impl;
   142   std_log(LOG_FILENAME_LINE,"chosen=%p\n", impl);
   143   impl = klass->reference_impl;
   144   std_log(LOG_FILENAME_LINE,"ref=%p\n", impl);
   145   test();
   146 
   147   if(assert_failed)
   148       std_log(LOG_FILENAME_LINE,"Test Fail");
   149   else
   150       std_log(LOG_FILENAME_LINE,"Test Successful");
   151   create_xml(0);
   152   return 0;
   153 }
   154