]>
git.proxmox.com Git - ceph.git/blob - ceph/src/isa-l/raid/xor_gen_test.c
1 /**********************************************************************
2 Copyright(c) 2011-2015 Intel Corporation All rights reserved.
4 Redistribution and use in source and binary forms, with or without
5 modification, are permitted provided that the following conditions
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
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.
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 **********************************************************************/
37 #define TEST_SOURCES 16
39 #define TEST_MEM ((TEST_SOURCES + 1)*(TEST_LEN))
41 # define TEST_SEED 0x1234
44 // Generates pseudo-random data
46 void rand_buffer(unsigned char *buf
, long buffer_size
)
49 for (i
= 0; i
< buffer_size
; i
++)
53 int main(int argc
, char *argv
[])
55 int i
, j
, k
, ret
, fail
= 0;
56 void *buffs
[TEST_SOURCES
+ 1];
57 char *tmp_buf
[TEST_SOURCES
+ 1];
59 printf("Test xor_gen_test ");
63 // Allocate the arrays
64 for (i
= 0; i
< TEST_SOURCES
+ 1; i
++) {
66 ret
= posix_memalign(&buf
, 32, TEST_LEN
);
68 printf("alloc error: Fail");
75 for (i
= 0; i
< TEST_SOURCES
+ 1; i
++)
76 memset(buffs
[i
], 0, TEST_LEN
);
78 xor_gen(TEST_SOURCES
+ 1, TEST_LEN
, buffs
);
80 for (i
= 0; i
< TEST_LEN
; i
++) {
81 if (((char *)buffs
[TEST_SOURCES
])[i
] != 0)
86 printf("fail zero test");
92 for (i
= 0; i
< TEST_SOURCES
+ 1; i
++)
93 rand_buffer(buffs
[i
], TEST_LEN
);
95 xor_gen(TEST_SOURCES
+ 1, TEST_LEN
, buffs
);
97 fail
|= xor_check_base(TEST_SOURCES
+ 1, TEST_LEN
, buffs
);
100 printf("fail rand test %d\n", fail
);
105 // Test various number of sources
106 for (j
= 3; j
<= TEST_SOURCES
+ 1; j
++) {
107 for (i
= 0; i
< j
; i
++)
108 rand_buffer(buffs
[i
], TEST_LEN
);
110 xor_gen(j
, TEST_LEN
, buffs
);
111 fail
|= xor_check_base(j
, TEST_LEN
, buffs
);
114 printf("fail rand test %d sources\n", j
);
122 // Test various number of sources and len
124 while (k
<= TEST_LEN
) {
125 for (j
= 3; j
<= TEST_SOURCES
+ 1; j
++) {
126 for (i
= 0; i
< j
; i
++)
127 rand_buffer(buffs
[i
], k
);
129 xor_gen(j
, k
, buffs
);
130 fail
|= xor_check_base(j
, k
, buffs
);
133 printf("fail rand test %d sources, len=%d, ret=%d\n", j
, k
,
142 // Test at the end of buffer
143 for (i
= 0; i
< TEST_LEN
; i
+= 32) {
144 for (j
= 0; j
< TEST_SOURCES
+ 1; j
++) {
145 rand_buffer((unsigned char *)buffs
[j
] + i
, TEST_LEN
- i
);
146 tmp_buf
[j
] = (char *)buffs
[j
] + i
;
149 xor_gen(TEST_SOURCES
+ 1, TEST_LEN
- i
, (void *)tmp_buf
);
150 fail
|= xor_check_base(TEST_SOURCES
+ 1, TEST_LEN
- i
, (void *)tmp_buf
);
153 printf("fail end test - offset: %d, len: %d\n", i
, TEST_LEN
- i
);
162 printf(" done: Pass\n");