]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
1 | /********************************************************************** |
2 | Copyright(c) 2011-2016 Intel Corporation All rights reserved. | |
3 | ||
4 | Redistribution and use in source and binary forms, with or without | |
1e59de90 | 5 | modification, are permitted provided that the following conditions |
7c673cae FG |
6 | are met: |
7 | * Redistributions of source code must retain the above copyright | |
8 | notice, this list of conditions and the following disclaimer. | |
9 | * Redistributions in binary form must reproduce the above copyright | |
10 | notice, this list of conditions and the following disclaimer in | |
11 | the documentation and/or other materials provided with the | |
12 | distribution. | |
13 | * Neither the name of Intel Corporation nor the names of its | |
14 | contributors may be used to endorse or promote products derived | |
15 | from this software without specific prior written permission. | |
16 | ||
17 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | |
18 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | |
19 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | |
20 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | |
21 | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |
22 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | |
23 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | |
24 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | |
25 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
26 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | |
27 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
28 | **********************************************************************/ | |
29 | ||
30 | #include <stdio.h> | |
31 | #include <stdlib.h> | |
32 | #include <openssl/md5.h> | |
33 | #include "md5_mb.h" | |
34 | #include "test.h" | |
35 | ||
36 | // Set number of outstanding jobs | |
37 | #define TEST_BUFS 32 | |
38 | ||
39 | #ifdef CACHED_TEST | |
40 | // Loop many times over same data | |
41 | # define TEST_LEN 4*1024 | |
42 | # define TEST_LOOPS 10000 | |
43 | # define TEST_TYPE_STR "_warm" | |
44 | #else | |
45 | // Uncached test. Pull from large mem base. | |
46 | # define GT_L3_CACHE 32*1024*1024 /* some number > last level cache */ | |
47 | # define TEST_LEN (GT_L3_CACHE / TEST_BUFS) | |
48 | # define TEST_LOOPS 100 | |
49 | # define TEST_TYPE_STR "_cold" | |
50 | #endif | |
51 | ||
52 | #define TEST_MEM TEST_LEN * TEST_BUFS * TEST_LOOPS | |
53 | ||
54 | /* Reference digest global to reduce stack usage */ | |
55 | static uint8_t digest_ssl[TEST_BUFS][4 * MD5_DIGEST_NWORDS]; | |
56 | ||
57 | int main(void) | |
58 | { | |
1e59de90 | 59 | int ret; |
7c673cae FG |
60 | MD5_HASH_CTX_MGR *mgr = NULL; |
61 | MD5_HASH_CTX ctxpool[TEST_BUFS]; | |
62 | unsigned char *bufs[TEST_BUFS]; | |
63 | uint32_t i, j, t, fail = 0; | |
64 | struct perf start, stop; | |
65 | ||
66 | for (i = 0; i < TEST_BUFS; i++) { | |
1e59de90 | 67 | bufs[i] = (unsigned char *)calloc((size_t)TEST_LEN, 1); |
7c673cae FG |
68 | if (bufs[i] == NULL) { |
69 | printf("calloc failed test aborted\n"); | |
70 | return 1; | |
71 | } | |
72 | // Init ctx contents | |
73 | hash_ctx_init(&ctxpool[i]); | |
74 | ctxpool[i].user_data = (void *)((uint64_t) i); | |
75 | } | |
76 | ||
1e59de90 TL |
77 | ret = posix_memalign((void *)&mgr, 16, sizeof(MD5_HASH_CTX_MGR)); |
78 | if (ret) { | |
79 | printf("alloc error: Fail"); | |
80 | return -1; | |
81 | } | |
7c673cae FG |
82 | md5_ctx_mgr_init(mgr); |
83 | ||
84 | // Start OpenSSL tests | |
85 | perf_start(&start); | |
86 | for (t = 0; t < TEST_LOOPS; t++) { | |
87 | for (i = 0; i < TEST_BUFS; i++) | |
88 | MD5(bufs[i], TEST_LEN, digest_ssl[i]); | |
89 | } | |
90 | perf_stop(&stop); | |
91 | ||
92 | printf("md5_openssl" TEST_TYPE_STR ": "); | |
93 | perf_print(stop, start, (long long)TEST_LEN * i * t); | |
94 | ||
95 | // Start mb tests | |
96 | perf_start(&start); | |
97 | for (t = 0; t < TEST_LOOPS; t++) { | |
98 | for (i = 0; i < TEST_BUFS; i++) | |
99 | md5_ctx_mgr_submit(mgr, &ctxpool[i], bufs[i], TEST_LEN, HASH_ENTIRE); | |
100 | ||
101 | while (md5_ctx_mgr_flush(mgr)) ; | |
102 | } | |
103 | perf_stop(&stop); | |
104 | ||
105 | printf("multibinary_md5" TEST_TYPE_STR ": "); | |
106 | perf_print(stop, start, (long long)TEST_LEN * i * t); | |
107 | ||
108 | for (i = 0; i < TEST_BUFS; i++) { | |
109 | for (j = 0; j < MD5_DIGEST_NWORDS; j++) { | |
1e59de90 TL |
110 | if (ctxpool[i].job.result_digest[j] != |
111 | to_le32(((uint32_t *) digest_ssl[i])[j])) { | |
7c673cae FG |
112 | fail++; |
113 | printf("Test%d, digest%d fail %08X <=> %08X\n", | |
114 | i, j, ctxpool[i].job.result_digest[j], | |
1e59de90 | 115 | to_le32(((uint32_t *) digest_ssl[i])[j])); |
7c673cae FG |
116 | } |
117 | } | |
118 | } | |
119 | ||
120 | printf("Multi-buffer md5 test complete %d buffers of %d B with " | |
121 | "%d iterations\n", TEST_BUFS, TEST_LEN, TEST_LOOPS); | |
122 | ||
123 | if (fail) | |
124 | printf("Test failed function check %d\n", fail); | |
125 | else | |
126 | printf(" multibinary_md5_ossl_perf: Pass\n"); | |
127 | ||
128 | return fail; | |
129 | } |