sl@0: /* sl@0: * LIBOIL - Library of Optimized Inner Loops sl@0: * Copyright (c) 2004 David A. Schleef sl@0: * All rights reserved. sl@0: * sl@0: * Redistribution and use in source and binary forms, with or without sl@0: * modification, are permitted provided that the following conditions sl@0: * are met: sl@0: * 1. Redistributions of source code must retain the above copyright sl@0: * notice, this list of conditions and the following disclaimer. sl@0: * 2. Redistributions in binary form must reproduce the above copyright sl@0: * notice, this list of conditions and the following disclaimer in the sl@0: * documentation and/or other materials provided with the distribution. sl@0: * sl@0: * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR sl@0: * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED sl@0: * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE sl@0: * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, sl@0: * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES sl@0: * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR sl@0: * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) sl@0: * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, sl@0: * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING sl@0: * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE sl@0: * POSSIBILITY OF SUCH DAMAGE. sl@0: */ sl@0: sl@0: sl@0: #ifdef HAVE_CONFIG_H sl@0: #include "config.h" sl@0: #endif sl@0: sl@0: #include sl@0: #include sl@0: #include sl@0: #include sl@0: #include sl@0: sl@0: #define LOG_FILE "c:\\logs\\testsuite_md5_log.txt" sl@0: #include "std_log_result.h" sl@0: #define LOG_FILENAME_LINE __FILE__, __LINE__ sl@0: sl@0: void create_xml(int result) sl@0: { sl@0: if(result) sl@0: assert_failed = 1; sl@0: sl@0: testResultXml("testsuite_md5"); sl@0: close_log_file(); sl@0: } sl@0: sl@0: char *message = "liboil md5 test"; sl@0: //char *message = ""; sl@0: sl@0: #ifdef WORDS_BIGENDIAN sl@0: #define uint32_from_host(a) \ sl@0: ((((a)&0xff)<<24)|(((a)&0xff00)<<8)|(((a)&0xff0000)>>8)|(((a)>>24)&0xff)) sl@0: #else sl@0: #define uint32_from_host(a) (a) sl@0: #endif sl@0: sl@0: void test(void) sl@0: { sl@0: uint32_t state[4]; sl@0: uint32_t src[16]; sl@0: int len; sl@0: char buf[33]; sl@0: sl@0: state[0] = 0x67452301; sl@0: state[1] = 0xefcdab89; sl@0: state[2] = 0x98badcfe; sl@0: state[3] = 0x10325476; sl@0: sl@0: memset (src, 0, 64); sl@0: len = strlen (message); sl@0: memcpy (src, message, len); sl@0: ((uint8_t *)src)[len] = 0x80; sl@0: src[14] = uint32_from_host(len << 3); sl@0: src[15] = 0; sl@0: sl@0: oil_md5 (state, src); sl@0: sl@0: std_log(LOG_FILENAME_LINE,"%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x\n", sl@0: state[0]&0xff, (state[0]>>8)&0xff, (state[0]>>16)&0xff, sl@0: (state[0]>>24)&0xff, sl@0: state[1]&0xff, (state[1]>>8)&0xff, (state[1]>>16)&0xff, sl@0: (state[1]>>24)&0xff, sl@0: state[2]&0xff, (state[2]>>8)&0xff, (state[2]>>16)&0xff, sl@0: (state[2]>>24)&0xff, sl@0: state[3]&0xff, (state[3]>>8)&0xff, (state[3]>>16)&0xff, sl@0: (state[3]>>24)&0xff); sl@0: sprintf(buf,"%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x", sl@0: state[0]&0xff, (state[0]>>8)&0xff, (state[0]>>16)&0xff, sl@0: (state[0]>>24)&0xff, sl@0: state[1]&0xff, (state[1]>>8)&0xff, (state[1]>>16)&0xff, sl@0: (state[1]>>24)&0xff, sl@0: state[2]&0xff, (state[2]>>8)&0xff, (state[2]>>16)&0xff, sl@0: (state[2]>>24)&0xff, sl@0: state[3]&0xff, (state[3]>>8)&0xff, (state[3]>>16)&0xff, sl@0: (state[3]>>24)&0xff); sl@0: if(strcasecmp(buf, "4311e9ad205ad575539c1d7e208ee53a")){ sl@0: std_log(LOG_FILENAME_LINE,"buf = %s\n", buf); sl@0: assert_failed = 1; sl@0: } sl@0: } sl@0: sl@0: int main (int argc, char *argv[]) sl@0: { sl@0: OilFunctionClass *klass; sl@0: OilFunctionImpl *impl; sl@0: sl@0: std_log(LOG_FILENAME_LINE,"Test started testsuite_md5"); sl@0: oil_init (); sl@0: sl@0: klass = oil_class_get ("md5"); sl@0: oil_class_optimize(klass); sl@0: sl@0: std_log(LOG_FILENAME_LINE,"class=%s\n", klass->name); sl@0: for (impl = klass->first_impl; impl; impl=impl->next) { sl@0: std_log(LOG_FILENAME_LINE,"impl=%p\n", impl); sl@0: std_log(LOG_FILENAME_LINE," func=%p\n", impl->func); sl@0: std_log(LOG_FILENAME_LINE," name=%s\n", impl->name); sl@0: std_log(LOG_FILENAME_LINE," flags=%08x\n", impl->flags); sl@0: } sl@0: sl@0: oil_class_choose_by_name (klass, "md5_c"); sl@0: impl = klass->chosen_impl; sl@0: std_log(LOG_FILENAME_LINE,"chosen=%p\n", impl); sl@0: impl = klass->reference_impl; sl@0: std_log(LOG_FILENAME_LINE,"ref=%p\n", impl); sl@0: test(); sl@0: sl@0: oil_class_choose_by_name (klass, "md5_asm1"); sl@0: impl = klass->chosen_impl; sl@0: std_log(LOG_FILENAME_LINE,"chosen=%p\n", impl); sl@0: impl = klass->reference_impl; sl@0: std_log(LOG_FILENAME_LINE,"ref=%p\n", impl); sl@0: test(); sl@0: sl@0: oil_class_choose_by_name (klass, "md5_asm2"); sl@0: impl = klass->chosen_impl; sl@0: std_log(LOG_FILENAME_LINE,"chosen=%p\n", impl); sl@0: impl = klass->reference_impl; sl@0: std_log(LOG_FILENAME_LINE,"ref=%p\n", impl); sl@0: test(); sl@0: sl@0: if(assert_failed) sl@0: std_log(LOG_FILENAME_LINE,"Test Fail"); sl@0: else sl@0: std_log(LOG_FILENAME_LINE,"Test Successful"); sl@0: create_xml(0); sl@0: return 0; sl@0: } sl@0: