]> git.proxmox.com Git - ceph.git/blob - ceph/src/isa-l/erasure_code/gf_vect_mul_base_test.c
add subtree-ish sources for 12.0.3
[ceph.git] / ceph / src / isa-l / erasure_code / gf_vect_mul_base_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
50 printf("gf_vect_mul_base_test:\n");
51
52 gf_vect_mul_init(a, gf_const_tbl);
53
54 buff1 = (u8 *) malloc(TEST_SIZE);
55 buff2 = (u8 *) malloc(TEST_SIZE);
56 buff3 = (u8 *) malloc(TEST_SIZE);
57
58 if (NULL == buff1 || NULL == buff2 || NULL == buff3) {
59 printf("buffer alloc error\n");
60 return -1;
61 }
62 // Fill with rand data
63 for (i = 0; i < TEST_SIZE; i++)
64 buff1[i] = rand();
65
66 gf_vect_mul_base(TEST_SIZE, gf_const_tbl, buff1, buff2);
67
68 for (i = 0; i < TEST_SIZE; i++)
69 if (gf_mul(a, buff1[i]) != buff2[i]) {
70 printf("fail at %d, 0x%x x 2 = 0x%x (0x%x)\n", i, buff1[i], buff2[i],
71 gf_mul(2, buff1[i]));
72 return 1;
73 }
74
75 gf_vect_mul_base(TEST_SIZE, gf_const_tbl, buff1, buff3);
76
77 // Check reference function
78 for (i = 0; i < TEST_SIZE; i++)
79 if (buff2[i] != buff3[i]) {
80 printf("fail at %d, 0x%x x 0x%d = 0x%x (0x%x)\n",
81 i, a, buff1[i], buff2[i], gf_mul(a, buff1[i]));
82 return 1;
83 }
84
85 for (i = 0; i < TEST_SIZE; i++)
86 buff1[i] = rand();
87
88 // Check each possible constant
89 printf("Random tests ");
90 for (a = 0; a != 255; a++) {
91 gf_vect_mul_init(a, gf_const_tbl);
92 gf_vect_mul_base(TEST_SIZE, gf_const_tbl, buff1, buff2);
93
94 for (i = 0; i < TEST_SIZE; i++)
95 if (gf_mul(a, buff1[i]) != buff2[i]) {
96 printf("fail at %d, 0x%x x %d = 0x%x (0x%x)\n",
97 i, a, buff1[i], buff2[i], gf_mul(2, buff1[i]));
98 return 1;
99 }
100 putchar('.');
101 }
102
103 // Run tests at end of buffer for Electric Fence
104 align = 32;
105 a = 2;
106
107 gf_vect_mul_init(a, gf_const_tbl);
108 for (size = 0; size < TEST_SIZE; size += align) {
109 // Line up TEST_SIZE from end
110 efence_buff1 = buff1 + size;
111 efence_buff2 = buff2 + size;
112
113 gf_vect_mul_base(TEST_SIZE - size, gf_const_tbl, efence_buff1, efence_buff2);
114
115 for (i = 0; i < TEST_SIZE - size; i++)
116 if (gf_mul(a, efence_buff1[i]) != efence_buff2[i]) {
117 printf("fail at %d, 0x%x x 2 = 0x%x (0x%x)\n",
118 i, efence_buff1[i], efence_buff2[i], gf_mul(2,
119 efence_buff1
120 [i]));
121 return 1;
122 }
123
124 putchar('.');
125 }
126
127 printf(" done: Pass\n");
128 return 0;
129 }