raid: reformat using new code style

Signed-off-by: Marcel Cornu <marcel.d.cornu@intel.com>
This commit is contained in:
Marcel Cornu 2024-04-19 17:09:54 +01:00 committed by Pablo de Lara
parent cf6105271a
commit ae951677ab
10 changed files with 893 additions and 884 deletions

View File

@ -37,7 +37,6 @@ DEFINE_INTERFACE_DISPATCHER(xor_gen)
return PROVIDER_INFO(xor_gen_neon); return PROVIDER_INFO(xor_gen_neon);
#endif #endif
return PROVIDER_BASIC(xor_gen); return PROVIDER_BASIC(xor_gen);
} }
DEFINE_INTERFACE_DISPATCHER(xor_check) DEFINE_INTERFACE_DISPATCHER(xor_check)
@ -49,7 +48,6 @@ DEFINE_INTERFACE_DISPATCHER(xor_check)
return PROVIDER_INFO(xor_check_neon); return PROVIDER_INFO(xor_check_neon);
#endif #endif
return PROVIDER_BASIC(xor_check); return PROVIDER_BASIC(xor_check);
} }
DEFINE_INTERFACE_DISPATCHER(pq_gen) DEFINE_INTERFACE_DISPATCHER(pq_gen)
@ -61,7 +59,6 @@ DEFINE_INTERFACE_DISPATCHER(pq_gen)
return PROVIDER_INFO(pq_gen_neon); return PROVIDER_INFO(pq_gen_neon);
#endif #endif
return PROVIDER_BASIC(pq_gen); return PROVIDER_BASIC(pq_gen);
} }
DEFINE_INTERFACE_DISPATCHER(pq_check) DEFINE_INTERFACE_DISPATCHER(pq_check)
@ -73,5 +70,4 @@ DEFINE_INTERFACE_DISPATCHER(pq_check)
return PROVIDER_INFO(pq_check_neon); return PROVIDER_INFO(pq_check_neon);
#endif #endif
return PROVIDER_BASIC(pq_check); return PROVIDER_BASIC(pq_check);
} }

View File

@ -27,25 +27,26 @@
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
**********************************************************************/ **********************************************************************/
#include<stdio.h> #include <stdio.h>
#include<stdint.h> #include <stdint.h>
#include<string.h> #include <string.h>
#include<stdlib.h> #include <stdlib.h>
#include "raid.h" #include "raid.h"
#include "test.h" #include "test.h"
#define TEST_SOURCES 16 #define TEST_SOURCES 16
#define TEST_LEN 1024 #define TEST_LEN 1024
#define TEST_MEM ((TEST_SOURCES + 2)*(TEST_LEN)) #define TEST_MEM ((TEST_SOURCES + 2) * (TEST_LEN))
#ifndef TEST_SEED #ifndef TEST_SEED
# define TEST_SEED 0x1234 #define TEST_SEED 0x1234
#endif #endif
int ref_multi_pq(int vects, int len, void **array) int
ref_multi_pq(int vects, int len, void **array)
{ {
int i, j; int i, j;
unsigned char p, q, s; unsigned char p, q, s;
unsigned char **src = (unsigned char **)array; unsigned char **src = (unsigned char **) array;
for (i = 0; i < len; i++) { for (i = 0; i < len; i++) {
q = p = src[vects - 3][i]; q = p = src[vects - 3][i];
@ -63,14 +64,16 @@ int ref_multi_pq(int vects, int len, void **array)
// Generates pseudo-random data // Generates pseudo-random data
void rand_buffer(unsigned char *buf, long buffer_size) void
rand_buffer(unsigned char *buf, long buffer_size)
{ {
long i; long i;
for (i = 0; i < buffer_size; i++) for (i = 0; i < buffer_size; i++)
buf[i] = rand(); buf[i] = rand();
} }
int main(int argc, char *argv[]) int
main(int argc, char *argv[])
{ {
int i, j, k, ret, fail = 0; int i, j, k, ret, fail = 0;
void *buffs[TEST_SOURCES + 2] = { NULL }; void *buffs[TEST_SOURCES + 2] = { NULL };
@ -103,25 +106,25 @@ int main(int argc, char *argv[])
printf("\nfail zero test %d\n", ret); printf("\nfail zero test %d\n", ret);
} }
((char *)(buffs[0]))[TEST_LEN - 2] = 0x7; // corrupt buffer ((char *) (buffs[0]))[TEST_LEN - 2] = 0x7; // corrupt buffer
ret = pq_check(TEST_SOURCES + 2, TEST_LEN, buffs); ret = pq_check(TEST_SOURCES + 2, TEST_LEN, buffs);
if (ret == 0) { if (ret == 0) {
fail++; fail++;
printf("\nfail corrupt buffer test %d\n", ret); printf("\nfail corrupt buffer test %d\n", ret);
} }
((char *)(buffs[0]))[TEST_LEN - 2] = 0; // un-corrupt buffer ((char *) (buffs[0]))[TEST_LEN - 2] = 0; // un-corrupt buffer
// Test corrupted buffer any location on all sources // Test corrupted buffer any location on all sources
for (j = 0; j < TEST_SOURCES + 2; j++) { for (j = 0; j < TEST_SOURCES + 2; j++) {
for (i = TEST_LEN - 1; i >= 0; i--) { for (i = TEST_LEN - 1; i >= 0; i--) {
((char *)buffs[j])[i] = 0x5; // corrupt buffer ((char *) buffs[j])[i] = 0x5; // corrupt buffer
ret = pq_check(TEST_SOURCES + 2, TEST_LEN, buffs); ret = pq_check(TEST_SOURCES + 2, TEST_LEN, buffs);
if (ret == 0) { if (ret == 0) {
fail++; fail++;
printf("\nfail corrupt zero buffer test j=%d, i=%d\n", j, i); printf("\nfail corrupt zero buffer test j=%d, i=%d\n", j, i);
goto exit; goto exit;
} }
((char *)buffs[j])[i] = 0; // un-corrupt buffer ((char *) buffs[j])[i] = 0; // un-corrupt buffer
} }
#ifdef TEST_VERBOSE #ifdef TEST_VERBOSE
putchar('.'); putchar('.');
@ -139,14 +142,14 @@ int main(int argc, char *argv[])
printf("fail first rand test %d\n", ret); printf("fail first rand test %d\n", ret);
} }
c = ((char *)(buffs[0]))[TEST_LEN - 2]; c = ((char *) (buffs[0]))[TEST_LEN - 2];
((char *)(buffs[0]))[TEST_LEN - 2] = c ^ 0x1; ((char *) (buffs[0]))[TEST_LEN - 2] = c ^ 0x1;
ret = pq_check(TEST_SOURCES + 2, TEST_LEN, buffs); ret = pq_check(TEST_SOURCES + 2, TEST_LEN, buffs);
if (ret == 0) { if (ret == 0) {
fail++; fail++;
printf("\nFail corrupt buffer test, passed when should have failed\n"); printf("\nFail corrupt buffer test, passed when should have failed\n");
} }
((char *)(buffs[0]))[TEST_LEN - 2] = c; // un-corrupt buffer ((char *) (buffs[0]))[TEST_LEN - 2] = c; // un-corrupt buffer
// Test corrupted buffer any location on all sources w/ random data // Test corrupted buffer any location on all sources w/ random data
for (j = 0; j < TEST_SOURCES + 2; j++) { for (j = 0; j < TEST_SOURCES + 2; j++) {
@ -155,20 +158,19 @@ int main(int argc, char *argv[])
ret = pq_check(TEST_SOURCES + 2, TEST_LEN, buffs); ret = pq_check(TEST_SOURCES + 2, TEST_LEN, buffs);
if (ret != 0) { // should pass if (ret != 0) { // should pass
fail++; fail++;
printf printf("\nFail rand test with un-corrupted buffer j=%d, i=%d\n", j,
("\nFail rand test with un-corrupted buffer j=%d, i=%d\n", i);
j, i);
goto exit; goto exit;
} }
c = ((char *)buffs[j])[i]; c = ((char *) buffs[j])[i];
((char *)buffs[j])[i] = c ^ 1; // corrupt buffer ((char *) buffs[j])[i] = c ^ 1; // corrupt buffer
ret = pq_check(TEST_SOURCES + 2, TEST_LEN, buffs); ret = pq_check(TEST_SOURCES + 2, TEST_LEN, buffs);
if (ret == 0) { // Check it now fails if (ret == 0) { // Check it now fails
fail++; fail++;
printf("\nfail corrupt buffer test j=%d, i=%d\n", j, i); printf("\nfail corrupt buffer test j=%d, i=%d\n", j, i);
goto exit; goto exit;
} }
((char *)buffs[j])[i] = c; // un-corrupt buffer ((char *) buffs[j])[i] = c; // un-corrupt buffer
} }
#ifdef TEST_VERBOSE #ifdef TEST_VERBOSE
putchar('.'); putchar('.');
@ -195,18 +197,18 @@ int main(int argc, char *argv[])
goto exit; goto exit;
} }
c = ((char *)buffs[i])[k]; c = ((char *) buffs[i])[k];
((char *)buffs[i])[k] = c ^ 1; // corrupt buffer ((char *) buffs[i])[k] = c ^ 1; // corrupt buffer
ret = pq_check(j, TEST_LEN, buffs); ret = pq_check(j, TEST_LEN, buffs);
if (ret == 0) { // Should fail if (ret == 0) { // Should fail
printf printf("\nfail rand fixed len test corrupted buffer %d "
("\nfail rand fixed len test corrupted buffer %d sources\n", "sources\n",
j); j);
fail++; fail++;
goto exit; goto exit;
} }
((char *)buffs[i])[k] = c; // un-corrupt buffer ((char *) buffs[i])[k] = c; // un-corrupt buffer
} }
} }
#ifdef TEST_VERBOSE #ifdef TEST_VERBOSE
@ -233,27 +235,27 @@ int main(int argc, char *argv[])
// See if it still passes // See if it still passes
ret = pq_check(j, k, buffs); ret = pq_check(j, k, buffs);
if (ret != 0) { // Should pass if (ret != 0) { // Should pass
printf printf("\nfail rand var src, len test %d sources, "
("\nfail rand var src, len test %d sources, len=%d\n", "len=%d\n",
j, k); j, k);
fail++; fail++;
goto exit; goto exit;
} }
tmp = (char *)buffs[serr]; tmp = (char *) buffs[serr];
c = tmp[lerr]; c = tmp[lerr];
((char *)buffs[serr])[lerr] = c ^ 1; // corrupt buffer ((char *) buffs[serr])[lerr] = c ^ 1; // corrupt buffer
ret = pq_check(j, k, buffs); ret = pq_check(j, k, buffs);
if (ret == 0) { // Should fail if (ret == 0) { // Should fail
printf printf("\nfail rand var src, len test corrupted "
("\nfail rand var src, len test corrupted buffer " "buffer "
"%d sources, len=%d, ret=%d\n", j, k, "%d sources, len=%d, ret=%d\n",
ret); j, k, ret);
fail++; fail++;
goto exit; goto exit;
} }
((char *)buffs[serr])[lerr] = c; // un-corrupt buffer ((char *) buffs[serr])[lerr] = c; // un-corrupt buffer
} }
} }
#ifdef TEST_VERBOSE #ifdef TEST_VERBOSE
@ -268,13 +270,13 @@ int main(int argc, char *argv[])
for (i = 0; i < TEST_LEN; i += 16) { for (i = 0; i < TEST_LEN; i += 16) {
for (j = 0; j < TEST_SOURCES + 2; j++) { for (j = 0; j < TEST_SOURCES + 2; j++) {
rand_buffer(buffs[j], TEST_LEN - i); rand_buffer(buffs[j], TEST_LEN - i);
tmp_buf[j] = (char *)buffs[j] + i; tmp_buf[j] = (char *) buffs[j] + i;
} }
pq_gen_base(TEST_SOURCES + 2, TEST_LEN - i, (void *)tmp_buf); pq_gen_base(TEST_SOURCES + 2, TEST_LEN - i, (void *) tmp_buf);
// Test good data // Test good data
ret = pq_check(TEST_SOURCES + 2, TEST_LEN - i, (void *)tmp_buf); ret = pq_check(TEST_SOURCES + 2, TEST_LEN - i, (void *) tmp_buf);
if (ret != 0) { if (ret != 0) {
printf("fail end test - offset: %d, len: %d\n", i, TEST_LEN - i); printf("fail end test - offset: %d, len: %d\n", i, TEST_LEN - i);
fail++; fail++;
@ -286,12 +288,11 @@ int main(int argc, char *argv[])
c = tmp_buf[serr][lerr]; c = tmp_buf[serr][lerr];
tmp_buf[serr][lerr] = c ^ 1; tmp_buf[serr][lerr] = c ^ 1;
ret = ret = pq_check(TEST_SOURCES + 2, TEST_LEN - i, (void *) tmp_buf);
pq_check(TEST_SOURCES + 2, TEST_LEN - i, (void *)tmp_buf);
if (ret == 0) { if (ret == 0) {
printf("fail end test corrupted buffer - " printf("fail end test corrupted buffer - "
"offset: %d, len: %d, ret: %d\n", i, "offset: %d, len: %d, ret: %d\n",
TEST_LEN - i, ret); i, TEST_LEN - i, ret);
fail++; fail++;
goto exit; goto exit;
} }
@ -309,9 +310,8 @@ int main(int argc, char *argv[])
if (fail == 0) if (fail == 0)
printf("Pass\n"); printf("Pass\n");
exit: exit:
for (i = 0; i < TEST_SOURCES + 2; i++) for (i = 0; i < TEST_SOURCES + 2; i++)
aligned_free(buffs[i]); aligned_free(buffs[i]);
return fail; return fail;
} }

View File

@ -27,34 +27,35 @@
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
**********************************************************************/ **********************************************************************/
#include<stdio.h> #include <stdio.h>
#include<stdint.h> #include <stdint.h>
#include<string.h> #include <string.h>
#include<stdlib.h> #include <stdlib.h>
#include "raid.h" #include "raid.h"
#include "test.h" #include "test.h"
#ifndef GT_L3_CACHE #ifndef GT_L3_CACHE
# define GT_L3_CACHE 32*1024*1024 /* some number > last level cache */ #define GT_L3_CACHE 32 * 1024 * 1024 /* some number > last level cache */
#endif #endif
#if !defined(COLD_TEST) && !defined(TEST_CUSTOM) #if !defined(COLD_TEST) && !defined(TEST_CUSTOM)
// Cached test, loop many times over small dataset // Cached test, loop many times over small dataset
# define TEST_SOURCES 10 #define TEST_SOURCES 10
# define TEST_LEN 8*1024 #define TEST_LEN 8 * 1024
# define TEST_TYPE_STR "_warm" #define TEST_TYPE_STR "_warm"
#elif defined (COLD_TEST) #elif defined(COLD_TEST)
// Uncached test. Pull from large mem base. // Uncached test. Pull from large mem base.
# define TEST_SOURCES 10 #define TEST_SOURCES 10
# define TEST_LEN ((GT_L3_CACHE / TEST_SOURCES) & ~(64-1)) #define TEST_LEN ((GT_L3_CACHE / TEST_SOURCES) & ~(64 - 1))
# define TEST_TYPE_STR "_cold" #define TEST_TYPE_STR "_cold"
#elif defined (TEST_CUSTOM) #elif defined(TEST_CUSTOM)
# define TEST_TYPE_STR "_cus" #define TEST_TYPE_STR "_cus"
#endif #endif
#define TEST_MEM ((TEST_SOURCES + 2)*(TEST_LEN)) #define TEST_MEM ((TEST_SOURCES + 2) * (TEST_LEN))
int main(int argc, char *argv[]) int
main(int argc, char *argv[])
{ {
int i; int i;
void *buffs[TEST_SOURCES + 2]; void *buffs[TEST_SOURCES + 2];
@ -81,7 +82,7 @@ int main(int argc, char *argv[])
// Warm up // Warm up
BENCHMARK(&start, BENCHMARK_TIME, pq_gen(TEST_SOURCES + 2, TEST_LEN, buffs)); BENCHMARK(&start, BENCHMARK_TIME, pq_gen(TEST_SOURCES + 2, TEST_LEN, buffs));
printf("pq_gen" TEST_TYPE_STR ": "); printf("pq_gen" TEST_TYPE_STR ": ");
perf_print(start, (long long)TEST_MEM); perf_print(start, (long long) TEST_MEM);
return 0; return 0;
} }

View File

@ -27,31 +27,33 @@
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
**********************************************************************/ **********************************************************************/
#include<stdio.h> #include <stdio.h>
#include<stdint.h> #include <stdint.h>
#include<string.h> #include <string.h>
#include<stdlib.h> #include <stdlib.h>
#include<limits.h> #include <limits.h>
#include "raid.h" #include "raid.h"
#include "test.h" #include "test.h"
#define TEST_SOURCES 16 #define TEST_SOURCES 16
#define TEST_LEN 1024 #define TEST_LEN 1024
#define TEST_MEM ((TEST_SOURCES + 2)*(TEST_LEN)) #define TEST_MEM ((TEST_SOURCES + 2) * (TEST_LEN))
#ifndef TEST_SEED #ifndef TEST_SEED
# define TEST_SEED 0x1234 #define TEST_SEED 0x1234
#endif #endif
// Generates pseudo-random data // Generates pseudo-random data
void rand_buffer(unsigned char *buf, long buffer_size) void
rand_buffer(unsigned char *buf, long buffer_size)
{ {
long i; long i;
for (i = 0; i < buffer_size; i++) for (i = 0; i < buffer_size; i++)
buf[i] = rand(); buf[i] = rand();
} }
int dump(unsigned char *buf, int len) int
dump(unsigned char *buf, int len)
{ {
int i; int i;
for (i = 0; i < len;) { for (i = 0; i < len;) {
@ -63,7 +65,8 @@ int dump(unsigned char *buf, int len)
return 0; return 0;
} }
int main(int argc, char *argv[]) int
main(int argc, char *argv[])
{ {
int i, j, k, ret = 0, fail = 0; int i, j, k, ret = 0, fail = 0;
void *buffs[TEST_SOURCES + 2] = { NULL }; // Pointers to src and dest void *buffs[TEST_SOURCES + 2] = { NULL }; // Pointers to src and dest
@ -92,12 +95,12 @@ int main(int argc, char *argv[])
pq_gen(TEST_SOURCES + 2, TEST_LEN, buffs); pq_gen(TEST_SOURCES + 2, TEST_LEN, buffs);
for (i = 0; i < TEST_LEN; i++) { for (i = 0; i < TEST_LEN; i++) {
if (((char *)buffs[TEST_SOURCES])[i] != 0) if (((char *) buffs[TEST_SOURCES])[i] != 0)
fail++; fail++;
} }
for (i = 0; i < TEST_LEN; i++) { for (i = 0; i < TEST_LEN; i++) {
if (((char *)buffs[TEST_SOURCES + 1])[i] != 0) if (((char *) buffs[TEST_SOURCES + 1])[i] != 0)
fail++; fail++;
} }
@ -164,7 +167,8 @@ int main(int argc, char *argv[])
if (fail > 0) { if (fail > 0) {
printf("fail rand test %d sources, len=%d, fail=" printf("fail rand test %d sources, len=%d, fail="
"%d, ret=%d\n", j, k, fail, ret); "%d, ret=%d\n",
j, k, fail, ret);
goto exit; goto exit;
} }
} }
@ -179,15 +183,16 @@ int main(int argc, char *argv[])
while (k <= TEST_LEN) { while (k <= TEST_LEN) {
for (j = 0; j < (TEST_SOURCES + 2); j++) { for (j = 0; j < (TEST_SOURCES + 2); j++) {
rand_buffer(buffs[j], TEST_LEN - k); rand_buffer(buffs[j], TEST_LEN - k);
tmp_buf[j] = (char *)buffs[j] + k; tmp_buf[j] = (char *) buffs[j] + k;
} }
ret = pq_gen(TEST_SOURCES + 2, TEST_LEN - k, (void *)tmp_buf); ret = pq_gen(TEST_SOURCES + 2, TEST_LEN - k, (void *) tmp_buf);
fail |= pq_check_base(TEST_SOURCES + 2, TEST_LEN - k, (void *)tmp_buf); fail |= pq_check_base(TEST_SOURCES + 2, TEST_LEN - k, (void *) tmp_buf);
if (fail > 0) { if (fail > 0) {
printf("fail end test - offset: %d, len: %d, fail: %d, " printf("fail end test - offset: %d, len: %d, fail: %d, "
"ret: %d\n", k, TEST_LEN - k, fail, ret); "ret: %d\n",
k, TEST_LEN - k, fail, ret);
goto exit; goto exit;
} }
#ifdef TEST_VERBOSE #ifdef TEST_VERBOSE
@ -200,7 +205,7 @@ int main(int argc, char *argv[])
if (!fail) if (!fail)
printf(" done: Pass\n"); printf(" done: Pass\n");
exit: exit:
for (i = 0; i < TEST_SOURCES + 2; i++) for (i = 0; i < TEST_SOURCES + 2; i++)
aligned_free(buffs[i]); aligned_free(buffs[i]);
return fail; return fail;

View File

@ -31,20 +31,21 @@
#include <stdint.h> #include <stdint.h>
#if __WORDSIZE == 64 || _WIN64 || __x86_64__ #if __WORDSIZE == 64 || _WIN64 || __x86_64__
# define notbit0 0xfefefefefefefefeULL #define notbit0 0xfefefefefefefefeULL
# define bit7 0x8080808080808080ULL #define bit7 0x8080808080808080ULL
# define gf8poly 0x1d1d1d1d1d1d1d1dULL #define gf8poly 0x1d1d1d1d1d1d1d1dULL
#else #else
# define notbit0 0xfefefefeUL #define notbit0 0xfefefefeUL
# define bit7 0x80808080UL #define bit7 0x80808080UL
# define gf8poly 0x1d1d1d1dUL #define gf8poly 0x1d1d1d1dUL
#endif #endif
int pq_gen_base(int vects, int len, void **array) int
pq_gen_base(int vects, int len, void **array)
{ {
int i, j; int i, j;
unsigned long p, q, s; unsigned long p, q, s;
unsigned long **src = (unsigned long **)array; unsigned long **src = (unsigned long **) array;
int blocks = len / sizeof(long); int blocks = len / sizeof(long);
if (vects < 4) if (vects < 4)
@ -66,11 +67,12 @@ int pq_gen_base(int vects, int len, void **array)
return 0; return 0;
} }
int pq_check_base(int vects, int len, void **array) int
pq_check_base(int vects, int len, void **array)
{ {
int i, j; int i, j;
unsigned char p, q, s; unsigned char p, q, s;
unsigned char **src = (unsigned char **)array; unsigned char **src = (unsigned char **) array;
if (vects < 4) if (vects < 4)
return 1; // Must have at least 2 src and 2 dest return 1; // Must have at least 2 src and 2 dest
@ -94,11 +96,12 @@ int pq_check_base(int vects, int len, void **array)
return 0; return 0;
} }
int xor_gen_base(int vects, int len, void **array) int
xor_gen_base(int vects, int len, void **array)
{ {
int i, j; int i, j;
unsigned char parity; unsigned char parity;
unsigned char **src = (unsigned char **)array; unsigned char **src = (unsigned char **) array;
if (vects < 3) if (vects < 3)
return 1; // Must have at least 2 src and 1 dest return 1; // Must have at least 2 src and 1 dest
@ -109,18 +112,18 @@ int xor_gen_base(int vects, int len, void **array)
parity ^= src[j][i]; parity ^= src[j][i];
src[vects - 1][i] = parity; // last pointer is dest src[vects - 1][i] = parity; // last pointer is dest
} }
return 0; return 0;
} }
int xor_check_base(int vects, int len, void **array) int
xor_check_base(int vects, int len, void **array)
{ {
int i, j, fail = 0; int i, j, fail = 0;
unsigned char parity; unsigned char parity;
unsigned char **src = (unsigned char **)array; unsigned char **src = (unsigned char **) array;
if (vects < 2) if (vects < 2)
return 1; // Must have at least 2 src return 1; // Must have at least 2 src

View File

@ -29,22 +29,26 @@
#include "raid.h" #include "raid.h"
int pq_gen(int vects, int len, void **array) int
pq_gen(int vects, int len, void **array)
{ {
return pq_gen_base(vects, len, array); return pq_gen_base(vects, len, array);
} }
int pq_check(int vects, int len, void **array) int
pq_check(int vects, int len, void **array)
{ {
return pq_check_base(vects, len, array); return pq_check_base(vects, len, array);
} }
int xor_gen(int vects, int len, void **array) int
xor_gen(int vects, int len, void **array)
{ {
return xor_gen_base(vects, len, array); return xor_gen_base(vects, len, array);
} }
int xor_check(int vects, int len, void **array) int
xor_check(int vects, int len, void **array)
{ {
return xor_check_base(vects, len, array); return xor_check_base(vects, len, array);
} }

View File

@ -27,30 +27,32 @@
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
**********************************************************************/ **********************************************************************/
#include<stdio.h> #include <stdio.h>
#include<stdint.h> #include <stdint.h>
#include<string.h> #include <string.h>
#include<stdlib.h> #include <stdlib.h>
#include "raid.h" #include "raid.h"
#include "test.h" #include "test.h"
#define TEST_SOURCES 16 #define TEST_SOURCES 16
#define TEST_LEN 1024 #define TEST_LEN 1024
#define TEST_MEM ((TEST_SOURCES + 1)*(TEST_LEN)) #define TEST_MEM ((TEST_SOURCES + 1) * (TEST_LEN))
#ifndef TEST_SEED #ifndef TEST_SEED
# define TEST_SEED 0x1234 #define TEST_SEED 0x1234
#endif #endif
// Generates pseudo-random data // Generates pseudo-random data
void rand_buffer(unsigned char *buf, long buffer_size) void
rand_buffer(unsigned char *buf, long buffer_size)
{ {
long i; long i;
for (i = 0; i < buffer_size; i++) for (i = 0; i < buffer_size; i++)
buf[i] = rand(); buf[i] = rand();
} }
int main(int argc, char *argv[]) int
main(int argc, char *argv[])
{ {
int i, j, k, ret, fail = 0; int i, j, k, ret, fail = 0;
void *buffs[TEST_SOURCES + 1] = { NULL }; void *buffs[TEST_SOURCES + 1] = { NULL };
@ -84,25 +86,25 @@ int main(int argc, char *argv[])
printf("\nfail zero test %d\n", ret); printf("\nfail zero test %d\n", ret);
} }
((char *)(buffs[0]))[TEST_LEN - 2] = 0x7; // corrupt buffer ((char *) (buffs[0]))[TEST_LEN - 2] = 0x7; // corrupt buffer
ret = xor_check(TEST_SOURCES + 1, TEST_LEN, buffs); ret = xor_check(TEST_SOURCES + 1, TEST_LEN, buffs);
if (ret == 0) { if (ret == 0) {
fail++; fail++;
printf("\nfail corrupt buffer test %d\n", ret); printf("\nfail corrupt buffer test %d\n", ret);
} }
((char *)(buffs[0]))[TEST_LEN - 2] = 0; // un-corrupt buffer ((char *) (buffs[0]))[TEST_LEN - 2] = 0; // un-corrupt buffer
// Test corrupted buffer any location on all sources // Test corrupted buffer any location on all sources
for (j = 0; j < TEST_SOURCES + 1; j++) { for (j = 0; j < TEST_SOURCES + 1; j++) {
for (i = TEST_LEN - 1; i >= 0; i--) { for (i = TEST_LEN - 1; i >= 0; i--) {
((char *)buffs[j])[i] = 0x5; // corrupt buffer ((char *) buffs[j])[i] = 0x5; // corrupt buffer
ret = xor_check(TEST_SOURCES + 1, TEST_LEN, buffs); ret = xor_check(TEST_SOURCES + 1, TEST_LEN, buffs);
if (ret == 0) { if (ret == 0) {
fail++; fail++;
printf("\nfail corrupt buffer test j=%d, i=%d\n", j, i); printf("\nfail corrupt buffer test j=%d, i=%d\n", j, i);
goto exit; goto exit;
} }
((char *)buffs[j])[i] = 0; // un-corrupt buffer ((char *) buffs[j])[i] = 0; // un-corrupt buffer
} }
#ifdef TEST_VERBOSE #ifdef TEST_VERBOSE
putchar('.'); putchar('.');
@ -120,14 +122,14 @@ int main(int argc, char *argv[])
printf("fail first rand test %d\n", ret); printf("fail first rand test %d\n", ret);
} }
c = ((char *)(buffs[0]))[TEST_LEN - 2]; c = ((char *) (buffs[0]))[TEST_LEN - 2];
((char *)(buffs[0]))[TEST_LEN - 2] = c ^ 0x1; ((char *) (buffs[0]))[TEST_LEN - 2] = c ^ 0x1;
ret = xor_check(TEST_SOURCES + 1, TEST_LEN, buffs); ret = xor_check(TEST_SOURCES + 1, TEST_LEN, buffs);
if (ret == 0) { if (ret == 0) {
fail++; fail++;
printf("\nFail corrupt buffer test, passed when should have failed\n"); printf("\nFail corrupt buffer test, passed when should have failed\n");
} }
((char *)(buffs[0]))[TEST_LEN - 2] = c; // un-corrupt buffer ((char *) (buffs[0]))[TEST_LEN - 2] = c; // un-corrupt buffer
// Test corrupted buffer any location on all sources w/ random data // Test corrupted buffer any location on all sources w/ random data
for (j = 0; j < TEST_SOURCES + 1; j++) { for (j = 0; j < TEST_SOURCES + 1; j++) {
@ -136,20 +138,19 @@ int main(int argc, char *argv[])
ret = xor_check(TEST_SOURCES + 1, TEST_LEN, buffs); ret = xor_check(TEST_SOURCES + 1, TEST_LEN, buffs);
if (ret != 0) { // should pass if (ret != 0) { // should pass
fail++; fail++;
printf printf("\nFail rand test with un-corrupted buffer j=%d, i=%d\n", j,
("\nFail rand test with un-corrupted buffer j=%d, i=%d\n", i);
j, i);
goto exit; goto exit;
} }
c = ((char *)buffs[j])[i]; c = ((char *) buffs[j])[i];
((char *)buffs[j])[i] = c ^ 1; // corrupt buffer ((char *) buffs[j])[i] = c ^ 1; // corrupt buffer
ret = xor_check(TEST_SOURCES + 1, TEST_LEN, buffs); ret = xor_check(TEST_SOURCES + 1, TEST_LEN, buffs);
if (ret == 0) { // Check it now fails if (ret == 0) { // Check it now fails
fail++; fail++;
printf("\nfail corrupt buffer test j=%d, i=%d\n", j, i); printf("\nfail corrupt buffer test j=%d, i=%d\n", j, i);
goto exit; goto exit;
} }
((char *)buffs[j])[i] = c; // un-corrupt buffer ((char *) buffs[j])[i] = c; // un-corrupt buffer
} }
#ifdef TEST_VERBOSE #ifdef TEST_VERBOSE
putchar('.'); putchar('.');
@ -176,18 +177,16 @@ int main(int argc, char *argv[])
goto exit; goto exit;
} }
c = ((char *)buffs[i])[k]; c = ((char *) buffs[i])[k];
((char *)buffs[i])[k] = c ^ 1; // corrupt buffer ((char *) buffs[i])[k] = c ^ 1; // corrupt buffer
ret = xor_check(j, TEST_LEN, buffs); ret = xor_check(j, TEST_LEN, buffs);
if (ret == 0) { // Should fail if (ret == 0) { // Should fail
printf printf("\nfail rand test corrupted buffer %d sources\n", j);
("\nfail rand test corrupted buffer %d sources\n",
j);
fail++; fail++;
goto exit; goto exit;
} }
((char *)buffs[i])[k] = c; // un-corrupt buffer ((char *) buffs[i])[k] = c; // un-corrupt buffer
} }
} }
#ifdef TEST_VERBOSE #ifdef TEST_VERBOSE
@ -219,18 +218,18 @@ int main(int argc, char *argv[])
goto exit; goto exit;
} }
c = ((char *)buffs[serr])[lerr]; c = ((char *) buffs[serr])[lerr];
((char *)buffs[serr])[lerr] = c ^ 1; // corrupt buffer ((char *) buffs[serr])[lerr] = c ^ 1; // corrupt buffer
ret = xor_check(j, k, buffs); ret = xor_check(j, k, buffs);
if (ret == 0) { // Should fail if (ret == 0) { // Should fail
printf("\nfail rand test corrupted buffer " printf("\nfail rand test corrupted buffer "
"%d sources, len=%d, ret=%d\n", j, k, "%d sources, len=%d, ret=%d\n",
ret); j, k, ret);
fail++; fail++;
goto exit; goto exit;
} }
((char *)buffs[serr])[lerr] = c; // un-corrupt buffer ((char *) buffs[serr])[lerr] = c; // un-corrupt buffer
} }
} }
} }
@ -245,13 +244,13 @@ int main(int argc, char *argv[])
for (i = 0; i < TEST_LEN; i += 32) { for (i = 0; i < TEST_LEN; i += 32) {
for (j = 0; j < TEST_SOURCES + 1; j++) { for (j = 0; j < TEST_SOURCES + 1; j++) {
rand_buffer(buffs[j], TEST_LEN - i); rand_buffer(buffs[j], TEST_LEN - i);
tmp_buf[j] = (char *)buffs[j] + i; tmp_buf[j] = (char *) buffs[j] + i;
} }
xor_gen_base(TEST_SOURCES + 1, TEST_LEN - i, (void *)tmp_buf); xor_gen_base(TEST_SOURCES + 1, TEST_LEN - i, (void *) tmp_buf);
// Test good data // Test good data
ret = xor_check(TEST_SOURCES + 1, TEST_LEN - i, (void *)tmp_buf); ret = xor_check(TEST_SOURCES + 1, TEST_LEN - i, (void *) tmp_buf);
if (ret != 0) { if (ret != 0) {
printf("fail end test - offset: %d, len: %d\n", i, TEST_LEN - i); printf("fail end test - offset: %d, len: %d\n", i, TEST_LEN - i);
fail++; fail++;
@ -263,12 +262,11 @@ int main(int argc, char *argv[])
c = tmp_buf[serr][lerr]; c = tmp_buf[serr][lerr];
tmp_buf[serr][lerr] = c ^ 1; tmp_buf[serr][lerr] = c ^ 1;
ret = ret = xor_check(TEST_SOURCES + 1, TEST_LEN - i, (void *) tmp_buf);
xor_check(TEST_SOURCES + 1, TEST_LEN - i, (void *)tmp_buf);
if (ret == 0) { if (ret == 0) {
printf("fail end test corrupted buffer - " printf("fail end test corrupted buffer - "
"offset: %d, len: %d, ret: %d\n", i, "offset: %d, len: %d, ret: %d\n",
TEST_LEN - i, ret); i, TEST_LEN - i, ret);
fail++; fail++;
goto exit; goto exit;
} }
@ -286,10 +284,9 @@ int main(int argc, char *argv[])
if (fail == 0) if (fail == 0)
printf("Pass\n"); printf("Pass\n");
exit: exit:
for (i = 0; i < TEST_SOURCES + 1; i++) for (i = 0; i < TEST_SOURCES + 1; i++)
aligned_free(buffs[i]); aligned_free(buffs[i]);
return fail; return fail;
} }

View File

@ -32,9 +32,10 @@
#include "test.h" #include "test.h"
#define TEST_SOURCES 16 #define TEST_SOURCES 16
#define TEST_LEN 16*1024 #define TEST_LEN 16 * 1024
int main(int argc, char *argv[]) int
main(int argc, char *argv[])
{ {
int i, j, should_pass, should_fail, ret = 0; int i, j, should_pass, should_fail, ret = 0;
void *buffs[TEST_SOURCES + 1] = { NULL }; void *buffs[TEST_SOURCES + 1] = { NULL };
@ -52,7 +53,7 @@ int main(int argc, char *argv[])
printf("Make random data\n"); printf("Make random data\n");
for (i = 0; i < TEST_SOURCES + 1; i++) for (i = 0; i < TEST_SOURCES + 1; i++)
for (j = 0; j < TEST_LEN; j++) for (j = 0; j < TEST_LEN; j++)
((char *)buffs[i])[j] = rand(); ((char *) buffs[i])[j] = rand();
printf("Generate xor parity\n"); printf("Generate xor parity\n");
xor_gen(TEST_SOURCES + 1, TEST_LEN, buffs); xor_gen(TEST_SOURCES + 1, TEST_LEN, buffs);
@ -66,13 +67,13 @@ int main(int argc, char *argv[])
} }
printf("Find corruption: "); printf("Find corruption: ");
((char *)buffs[TEST_SOURCES / 2])[TEST_LEN / 2] ^= 1; // flip one bit ((char *) buffs[TEST_SOURCES / 2])[TEST_LEN / 2] ^= 1; // flip one bit
should_fail = xor_check(TEST_SOURCES + 1, TEST_LEN, buffs); //recheck should_fail = xor_check(TEST_SOURCES + 1, TEST_LEN, buffs); // recheck
printf("%s\n", should_fail != 0 ? "Pass" : "Fail"); printf("%s\n", should_fail != 0 ? "Pass" : "Fail");
if (should_fail == 0) if (should_fail == 0)
ret = -1; ret = -1;
exit: exit:
for (i = 0; i < TEST_SOURCES + 1; i++) for (i = 0; i < TEST_SOURCES + 1; i++)
free(buffs[i]); free(buffs[i]);

View File

@ -27,32 +27,33 @@
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
**********************************************************************/ **********************************************************************/
#include<stdio.h> #include <stdio.h>
#include<stdint.h> #include <stdint.h>
#include<string.h> #include <string.h>
#include<stdlib.h> #include <stdlib.h>
#include "raid.h" #include "raid.h"
#include "test.h" #include "test.h"
#ifndef GT_L3_CACHE #ifndef GT_L3_CACHE
# define GT_L3_CACHE 32*1024*1024 /* some number > last level cache */ #define GT_L3_CACHE 32 * 1024 * 1024 /* some number > last level cache */
#endif #endif
#if !defined(COLD_TEST) && !defined(TEST_CUSTOM) #if !defined(COLD_TEST) && !defined(TEST_CUSTOM)
// Cached test, loop many times over small dataset // Cached test, loop many times over small dataset
# define TEST_SOURCES 10 #define TEST_SOURCES 10
# define TEST_LEN 8*1024 #define TEST_LEN 8 * 1024
# define TEST_TYPE_STR "_warm" #define TEST_TYPE_STR "_warm"
#elif defined (COLD_TEST) #elif defined(COLD_TEST)
// Uncached test. Pull from large mem base. // Uncached test. Pull from large mem base.
# define TEST_SOURCES 10 #define TEST_SOURCES 10
# define TEST_LEN GT_L3_CACHE / TEST_SOURCES #define TEST_LEN GT_L3_CACHE / TEST_SOURCES
# define TEST_TYPE_STR "_cold" #define TEST_TYPE_STR "_cold"
#endif #endif
#define TEST_MEM ((TEST_SOURCES + 1)*(TEST_LEN)) #define TEST_MEM ((TEST_SOURCES + 1) * (TEST_LEN))
int main(int argc, char *argv[]) int
main(int argc, char *argv[])
{ {
int i, ret, fail = 0; int i, ret, fail = 0;
void **buffs; void **buffs;
@ -61,7 +62,7 @@ int main(int argc, char *argv[])
printf("Test xor_gen_perf\n"); printf("Test xor_gen_perf\n");
ret = posix_memalign((void **)&buff, 8, sizeof(int *) * (TEST_SOURCES + 6)); ret = posix_memalign((void **) &buff, 8, sizeof(int *) * (TEST_SOURCES + 6));
if (ret) { if (ret) {
printf("alloc error: Fail"); printf("alloc error: Fail");
return 1; return 1;
@ -85,7 +86,7 @@ int main(int argc, char *argv[])
BENCHMARK(&start, BENCHMARK_TIME, xor_gen(TEST_SOURCES + 1, TEST_LEN, buffs)); BENCHMARK(&start, BENCHMARK_TIME, xor_gen(TEST_SOURCES + 1, TEST_LEN, buffs));
printf("xor_gen" TEST_TYPE_STR ": "); printf("xor_gen" TEST_TYPE_STR ": ");
perf_print(start, (long long)TEST_MEM); perf_print(start, (long long) TEST_MEM);
return fail; return fail;
} }

View File

@ -27,30 +27,32 @@
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
**********************************************************************/ **********************************************************************/
#include<stdio.h> #include <stdio.h>
#include<stdint.h> #include <stdint.h>
#include<string.h> #include <string.h>
#include<stdlib.h> #include <stdlib.h>
#include "raid.h" #include "raid.h"
#include "test.h" #include "test.h"
#define TEST_SOURCES 16 #define TEST_SOURCES 16
#define TEST_LEN 1024 #define TEST_LEN 1024
#define TEST_MEM ((TEST_SOURCES + 1)*(TEST_LEN)) #define TEST_MEM ((TEST_SOURCES + 1) * (TEST_LEN))
#ifndef TEST_SEED #ifndef TEST_SEED
# define TEST_SEED 0x1234 #define TEST_SEED 0x1234
#endif #endif
// Generates pseudo-random data // Generates pseudo-random data
void rand_buffer(unsigned char *buf, long buffer_size) void
rand_buffer(unsigned char *buf, long buffer_size)
{ {
long i; long i;
for (i = 0; i < buffer_size; i++) for (i = 0; i < buffer_size; i++)
buf[i] = rand(); buf[i] = rand();
} }
int main(int argc, char *argv[]) int
main(int argc, char *argv[])
{ {
int i, j, k, ret, fail = 0; int i, j, k, ret, fail = 0;
void *buffs[TEST_SOURCES + 1] = { NULL }; void *buffs[TEST_SOURCES + 1] = { NULL };
@ -79,7 +81,7 @@ int main(int argc, char *argv[])
xor_gen(TEST_SOURCES + 1, TEST_LEN, buffs); xor_gen(TEST_SOURCES + 1, TEST_LEN, buffs);
for (i = 0; i < TEST_LEN; i++) { for (i = 0; i < TEST_LEN; i++) {
if (((char *)buffs[TEST_SOURCES])[i] != 0) if (((char *) buffs[TEST_SOURCES])[i] != 0)
fail++; fail++;
} }
@ -137,8 +139,7 @@ int main(int argc, char *argv[])
fail |= xor_check_base(j, k, buffs); fail |= xor_check_base(j, k, buffs);
if (fail > 0) { if (fail > 0) {
printf("fail rand test %d sources, len=%d, ret=%d\n", j, k, printf("fail rand test %d sources, len=%d, ret=%d\n", j, k, fail);
fail);
goto exit; goto exit;
} }
} }
@ -151,12 +152,12 @@ int main(int argc, char *argv[])
// Test at the end of buffer // Test at the end of buffer
for (i = 0; i < TEST_LEN; i += 32) { for (i = 0; i < TEST_LEN; i += 32) {
for (j = 0; j < TEST_SOURCES + 1; j++) { for (j = 0; j < TEST_SOURCES + 1; j++) {
rand_buffer((unsigned char *)buffs[j] + i, TEST_LEN - i); rand_buffer((unsigned char *) buffs[j] + i, TEST_LEN - i);
tmp_buf[j] = (char *)buffs[j] + i; tmp_buf[j] = (char *) buffs[j] + i;
} }
xor_gen(TEST_SOURCES + 1, TEST_LEN - i, (void *)tmp_buf); xor_gen(TEST_SOURCES + 1, TEST_LEN - i, (void *) tmp_buf);
fail |= xor_check_base(TEST_SOURCES + 1, TEST_LEN - i, (void *)tmp_buf); fail |= xor_check_base(TEST_SOURCES + 1, TEST_LEN - i, (void *) tmp_buf);
if (fail > 0) { if (fail > 0) {
printf("fail end test - offset: %d, len: %d\n", i, TEST_LEN - i); printf("fail end test - offset: %d, len: %d\n", i, TEST_LEN - i);
@ -171,7 +172,7 @@ int main(int argc, char *argv[])
if (!fail) if (!fail)
printf(" done: Pass\n"); printf(" done: Pass\n");
exit: exit:
for (i = 0; i < TEST_SOURCES + 1; i++) for (i = 0; i < TEST_SOURCES + 1; i++)
aligned_free(buffs[i]); aligned_free(buffs[i]);