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