]>
git.proxmox.com Git - ceph.git/blob - ceph/src/isa-l/raid/pq_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 **********************************************************************/
38 #define TEST_SOURCES 16
40 #define TEST_MEM ((TEST_SOURCES + 2)*(TEST_LEN))
42 # define TEST_SEED 0x1234
45 // Generates pseudo-random data
47 void rand_buffer(unsigned char *buf
, long buffer_size
)
50 for (i
= 0; i
< buffer_size
; i
++)
54 int dump(unsigned char *buf
, int len
)
57 for (i
= 0; i
< len
;) {
58 printf(" %2x", buf
[i
++]);
66 int main(int argc
, char *argv
[])
68 int i
, j
, k
, ret
, fail
= 0;
69 void *buffs
[TEST_SOURCES
+ 2]; // Pointers to src and dest
70 char *tmp_buf
[TEST_SOURCES
+ 2];
72 printf("Test pq_gen_test ");
76 // Allocate the arrays
77 for (i
= 0; i
< TEST_SOURCES
+ 2; i
++) {
79 ret
= posix_memalign(&buf
, 32, TEST_LEN
);
81 printf("alloc error: Fail");
88 for (i
= 0; i
< TEST_SOURCES
+ 2; i
++)
89 memset(buffs
[i
], 0, TEST_LEN
);
91 pq_gen(TEST_SOURCES
+ 2, TEST_LEN
, buffs
);
93 for (i
= 0; i
< TEST_LEN
; i
++) {
94 if (((char *)buffs
[TEST_SOURCES
])[i
] != 0)
98 for (i
= 0; i
< TEST_LEN
; i
++) {
99 if (((char *)buffs
[TEST_SOURCES
+ 1])[i
] != 0)
104 printf("fail zero test %d\n", fail
);
110 for (i
= 0; i
< TEST_SOURCES
+ 2; i
++)
111 rand_buffer(buffs
[i
], TEST_LEN
);
113 ret
= pq_gen(TEST_SOURCES
+ 2, TEST_LEN
, buffs
);
114 fail
|= pq_check_base(TEST_SOURCES
+ 2, TEST_LEN
, buffs
);
118 printf(" Fail rand test1 fail=%d, ret=%d\n", fail
, ret
);
119 for (t
= 0; t
< TEST_SOURCES
+ 2; t
++)
122 printf(" reference function p,q\n");
123 pq_gen_base(TEST_SOURCES
+ 2, TEST_LEN
, buffs
);
124 for (t
= TEST_SOURCES
; t
< TEST_SOURCES
+ 2; t
++)
131 // Test various number of sources
132 for (j
= 4; j
<= TEST_SOURCES
+ 2; j
++) {
133 for (i
= 0; i
< j
; i
++)
134 rand_buffer(buffs
[i
], TEST_LEN
);
136 pq_gen(j
, TEST_LEN
, buffs
);
137 fail
|= pq_check_base(j
, TEST_LEN
, buffs
);
140 printf("fail rand test %d sources\n", j
);
148 // Test various number of sources and len
150 while (k
<= TEST_LEN
) {
151 for (j
= 4; j
<= TEST_SOURCES
+ 2; j
++) {
152 for (i
= 0; i
< j
; i
++)
153 rand_buffer(buffs
[i
], k
);
155 ret
= pq_gen(j
, k
, buffs
);
156 fail
|= pq_check_base(j
, k
, buffs
);
159 printf("fail rand test %d sources, len=%d, fail="
160 "%d, ret=%d\n", j
, k
, fail
, ret
);
168 // Test at the end of buffer
170 while (k
<= TEST_LEN
) {
171 for (j
= 0; j
< (TEST_SOURCES
+ 2); j
++) {
172 rand_buffer(buffs
[j
], TEST_LEN
- k
);
173 tmp_buf
[j
] = (char *)buffs
[j
] + k
;
176 ret
= pq_gen(TEST_SOURCES
+ 2, TEST_LEN
- k
, (void *)tmp_buf
);
177 fail
|= pq_check_base(TEST_SOURCES
+ 2, TEST_LEN
- k
, (void *)tmp_buf
);
180 printf("fail end test - offset: %d, len: %d, fail: %d, "
181 "ret: %d\n", k
, TEST_LEN
- k
, fail
, ret
);
191 printf(" done: Pass\n");