]> git.proxmox.com Git - ceph.git/blob - ceph/src/isa-l/erasure_code/gf_vect_mul_test.c
add subtree-ish sources for 12.0.3
[ceph.git] / ceph / src / isa-l / erasure_code / gf_vect_mul_test.c
1 /**********************************************************************
2 Copyright(c) 2011-2015 Intel Corporation All rights reserved.
3
4 Redistribution and use in source and binary forms, with or without
5 modification, are permitted provided that the following conditions
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 <string.h> // for memset
33 #include "erasure_code.h"
34
35 #define TEST_SIZE 8192
36 #define TEST_MEM TEST_SIZE
37 #define TEST_LOOPS 100000
38 #define TEST_TYPE_STR ""
39
40 typedef unsigned char u8;
41
42 int main(int argc, char *argv[])
43 {
44 int i;
45 u8 *buff1, *buff2, *buff3, gf_const_tbl[64], a = 2;
46 int align, size;
47 unsigned char *efence_buff1;
48 unsigned char *efence_buff2;
49 unsigned char *efence_buff3;
50
51 printf("gf_vect_mul_test:\n");
52
53 gf_vect_mul_init(a, gf_const_tbl);
54
55 buff1 = (u8 *) malloc(TEST_SIZE);
56 buff2 = (u8 *) malloc(TEST_SIZE);
57 buff3 = (u8 *) malloc(TEST_SIZE);
58
59 if (NULL == buff1 || NULL == buff2 || NULL == buff3) {
60 printf("buffer alloc error\n");
61 return -1;
62 }
63 // Fill with rand data
64 for (i = 0; i < TEST_SIZE; i++)
65 buff1[i] = rand();
66
67 gf_vect_mul(TEST_SIZE, gf_const_tbl, buff1, buff2);
68
69 for (i = 0; i < TEST_SIZE; i++)
70 if (gf_mul(a, buff1[i]) != buff2[i]) {
71 printf("fail at %d, 0x%x x 2 = 0x%x (0x%x)\n", i, buff1[i], buff2[i],
72 gf_mul(2, buff1[i]));
73 return 1;
74 }
75
76 gf_vect_mul_base(TEST_SIZE, gf_const_tbl, buff1, buff3);
77
78 // Check reference function
79 for (i = 0; i < TEST_SIZE; i++)
80 if (buff2[i] != buff3[i]) {
81 printf("fail at %d, 0x%x x 0x%d = 0x%x (0x%x)\n",
82 i, a, buff1[i], buff2[i], gf_mul(a, buff1[i]));
83 return 1;
84 }
85
86 for (i = 0; i < TEST_SIZE; i++)
87 buff1[i] = rand();
88
89 // Check each possible constant
90 printf("Random tests ");
91 for (a = 0; a != 255; a++) {
92 gf_vect_mul_init(a, gf_const_tbl);
93 gf_vect_mul(TEST_SIZE, gf_const_tbl, buff1, buff2);
94
95 for (i = 0; i < TEST_SIZE; i++) {
96 if (gf_mul(a, buff1[i]) != buff2[i]) {
97 printf("fail at %d, 0x%x x %d = 0x%x (0x%x)\n",
98 i, a, buff1[i], buff2[i], gf_mul(2, buff1[i]));
99 return 1;
100 }
101 }
102 putchar('.');
103 }
104
105 // Run tests at end of buffer for Electric Fence
106 align = 32;
107 a = 2;
108
109 gf_vect_mul_init(a, gf_const_tbl);
110 for (size = 0; size < TEST_SIZE; size += align) {
111 // Line up TEST_SIZE from end
112 efence_buff1 = buff1 + size;
113 efence_buff2 = buff2 + size;
114 efence_buff3 = buff3 + size;
115
116 gf_vect_mul(TEST_SIZE - size, gf_const_tbl, efence_buff1, efence_buff2);
117
118 for (i = 0; i < TEST_SIZE - size; i++)
119 if (gf_mul(a, efence_buff1[i]) != efence_buff2[i]) {
120 printf("fail at %d, 0x%x x 2 = 0x%x (0x%x)\n",
121 i, efence_buff1[i], efence_buff2[i],
122 gf_mul(2, efence_buff1[i]));
123 return 1;
124 }
125
126 gf_vect_mul_base(TEST_SIZE - size, gf_const_tbl, efence_buff1, efence_buff3);
127
128 // Check reference function
129 for (i = 0; i < TEST_SIZE - size; i++)
130 if (efence_buff2[i] != efence_buff3[i]) {
131 printf("fail at %d, 0x%x x 0x%d = 0x%x (0x%x)\n",
132 i, a, efence_buff2[i], efence_buff3[i],
133 gf_mul(2, efence_buff1[i]));
134 return 1;
135 }
136
137 putchar('.');
138 }
139
140 printf(" done: Pass\n");
141 return 0;
142 }