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

@ -31,47 +31,43 @@
DEFINE_INTERFACE_DISPATCHER(xor_gen) DEFINE_INTERFACE_DISPATCHER(xor_gen)
{ {
#if defined(__linux__) #if defined(__linux__)
if (getauxval(AT_HWCAP) & HWCAP_ASIMD) if (getauxval(AT_HWCAP) & HWCAP_ASIMD)
return PROVIDER_INFO(xor_gen_neon); return PROVIDER_INFO(xor_gen_neon);
#elif defined(__APPLE__) #elif defined(__APPLE__)
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)
{ {
#if defined(__linux__) #if defined(__linux__)
if (getauxval(AT_HWCAP) & HWCAP_ASIMD) if (getauxval(AT_HWCAP) & HWCAP_ASIMD)
return PROVIDER_INFO(xor_check_neon); return PROVIDER_INFO(xor_check_neon);
#elif defined(__APPLE__) #elif defined(__APPLE__)
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)
{ {
#if defined(__linux__) #if defined(__linux__)
if (getauxval(AT_HWCAP) & HWCAP_ASIMD) if (getauxval(AT_HWCAP) & HWCAP_ASIMD)
return PROVIDER_INFO(pq_gen_neon); return PROVIDER_INFO(pq_gen_neon);
#elif defined(__APPLE__) #elif defined(__APPLE__)
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)
{ {
#if defined(__linux__) #if defined(__linux__)
if (getauxval(AT_HWCAP) & HWCAP_ASIMD) if (getauxval(AT_HWCAP) & HWCAP_ASIMD)
return PROVIDER_INFO(pq_check_neon); return PROVIDER_INFO(pq_check_neon);
#elif defined(__APPLE__) #elif defined(__APPLE__)
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,291 +27,291 @@
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];
for (j = vects - 4; j >= 0; j--) { for (j = vects - 4; j >= 0; j--) {
p ^= s = src[j][i]; p ^= s = src[j][i];
q = s ^ ((q << 1) ^ ((q & 0x80) ? 0x1d : 0)); // mult by GF{2} q = s ^ ((q << 1) ^ ((q & 0x80) ? 0x1d : 0)); // mult by GF{2}
} }
src[vects - 2][i] = p; // second to last pointer is p src[vects - 2][i] = p; // second to last pointer is p
src[vects - 1][i] = q; // last pointer is q src[vects - 1][i] = q; // last pointer is q
} }
return 0; return 0;
} }
// 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 };
char c; char c;
char *tmp_buf[TEST_SOURCES + 2] = { NULL }; char *tmp_buf[TEST_SOURCES + 2] = { NULL };
int serr, lerr; int serr, lerr;
printf("Test pq_check_test %d sources X %d bytes\n", TEST_SOURCES, TEST_LEN); printf("Test pq_check_test %d sources X %d bytes\n", TEST_SOURCES, TEST_LEN);
srand(TEST_SEED); srand(TEST_SEED);
// Allocate the arrays // Allocate the arrays
for (i = 0; i < TEST_SOURCES + 2; i++) { for (i = 0; i < TEST_SOURCES + 2; i++) {
void *buf; void *buf;
if (posix_memalign(&buf, 16, TEST_LEN)) { if (posix_memalign(&buf, 16, TEST_LEN)) {
printf("alloc error: Fail"); printf("alloc error: Fail");
return 1; return 1;
} }
buffs[i] = buf; buffs[i] = buf;
} }
// Test of all zeros // Test of all zeros
for (i = 0; i < TEST_SOURCES + 2; i++) for (i = 0; i < TEST_SOURCES + 2; i++)
memset(buffs[i], 0, TEST_LEN); memset(buffs[i], 0, TEST_LEN);
ref_multi_pq(TEST_SOURCES + 2, TEST_LEN, buffs); ref_multi_pq(TEST_SOURCES + 2, TEST_LEN, buffs);
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 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('.');
#endif #endif
} }
// Test rand1 // Test rand1
for (i = 0; i < TEST_SOURCES + 2; i++) for (i = 0; i < TEST_SOURCES + 2; i++)
rand_buffer(buffs[i], TEST_LEN); rand_buffer(buffs[i], TEST_LEN);
ref_multi_pq(TEST_SOURCES + 2, TEST_LEN, buffs); ref_multi_pq(TEST_SOURCES + 2, TEST_LEN, buffs);
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("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++) {
for (i = TEST_LEN - 1; i >= 0; i--) { for (i = TEST_LEN - 1; i >= 0; i--) {
// Check it still passes // Check it still passes
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('.');
#endif #endif
} }
// Test various number of sources, full length // Test various number of sources, full length
for (j = 4; j <= TEST_SOURCES + 2; j++) { for (j = 4; j <= TEST_SOURCES + 2; j++) {
// New random data // New random data
for (i = 0; i < j; i++) for (i = 0; i < j; i++)
rand_buffer(buffs[i], TEST_LEN); rand_buffer(buffs[i], TEST_LEN);
// Generate p,q parity for this number of sources // Generate p,q parity for this number of sources
ref_multi_pq(j, TEST_LEN, buffs); ref_multi_pq(j, TEST_LEN, buffs);
// Set errors up in each source and len position // Set errors up in each source and len position
for (i = 0; i < j; i++) { for (i = 0; i < j; i++) {
for (k = 0; k < TEST_LEN; k++) { for (k = 0; k < TEST_LEN; k++) {
// See if it still passes // See if it still passes
ret = pq_check(j, TEST_LEN, buffs); ret = pq_check(j, TEST_LEN, buffs);
if (ret != 0) { // Should pass if (ret != 0) { // Should pass
printf("\nfail rand fixed len test %d sources\n", j); printf("\nfail rand fixed len test %d sources\n", j);
fail++; fail++;
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
putchar('.'); putchar('.');
#endif #endif
} }
fflush(0); fflush(0);
// Test various number of sources and len // Test various number of sources and len
k = 16; k = 16;
while (k <= TEST_LEN) { while (k <= TEST_LEN) {
char *tmp; char *tmp;
for (j = 4; j <= TEST_SOURCES + 2; j++) { for (j = 4; j <= TEST_SOURCES + 2; j++) {
for (i = 0; i < j; i++) for (i = 0; i < j; i++)
rand_buffer(buffs[i], k); rand_buffer(buffs[i], k);
// Generate p,q parity for this number of sources // Generate p,q parity for this number of sources
ref_multi_pq(j, k, buffs); ref_multi_pq(j, k, buffs);
// Inject errors at various source and len positions // Inject errors at various source and len positions
for (lerr = 0; lerr < k; lerr++) { for (lerr = 0; lerr < k; lerr++) {
for (serr = 0; serr < j; serr++) { for (serr = 0; serr < j; serr++) {
// 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
putchar('.'); putchar('.');
#endif #endif
fflush(0); fflush(0);
} }
k += 16; k += 16;
} }
// Test at the end of buffer // Test at the end of buffer
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++;
return 1; return 1;
} }
// Test bad data // Test bad data
for (serr = 0; serr < TEST_SOURCES + 2; serr++) { for (serr = 0; serr < TEST_SOURCES + 2; serr++) {
for (lerr = 0; lerr < (TEST_LEN - i); lerr++) { for (lerr = 0; lerr < (TEST_LEN - i); lerr++) {
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",
"offset: %d, len: %d, ret: %d\n", i, i, TEST_LEN - i, ret);
TEST_LEN - i, ret); fail++;
fail++; goto exit;
goto exit; }
}
tmp_buf[serr][lerr] = c; tmp_buf[serr][lerr] = c;
} }
} }
#ifdef TEST_VERBOSE #ifdef TEST_VERBOSE
putchar('.'); putchar('.');
#endif #endif
fflush(0); fflush(0);
} }
if (fail == 0) if (fail == 0)
printf("Pass\n"); printf("Pass\n");
exit:
for (i = 0; i < TEST_SOURCES + 2; i++)
aligned_free(buffs[i]);
return fail;
exit:
for (i = 0; i < TEST_SOURCES + 2; i++)
aligned_free(buffs[i]);
return fail;
} }

View File

@ -27,61 +27,62 @@
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];
struct perf start; struct perf start;
printf("Test pq_gen_perf %d sources X %d bytes\n", TEST_SOURCES, TEST_LEN); printf("Test pq_gen_perf %d sources X %d bytes\n", TEST_SOURCES, TEST_LEN);
// Allocate the arrays // Allocate the arrays
for (i = 0; i < TEST_SOURCES + 2; i++) { for (i = 0; i < TEST_SOURCES + 2; i++) {
int ret; int ret;
void *buf; void *buf;
ret = posix_memalign(&buf, 64, TEST_LEN); ret = posix_memalign(&buf, 64, TEST_LEN);
if (ret) { if (ret) {
printf("alloc error: Fail"); printf("alloc error: Fail");
return 1; return 1;
} }
buffs[i] = buf; buffs[i] = buf;
} }
// Setup data // Setup data
for (i = 0; i < TEST_SOURCES + 2; i++) for (i = 0; i < TEST_SOURCES + 2; i++)
memset(buffs[i], 0, TEST_LEN); memset(buffs[i], 0, TEST_LEN);
// 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,181 +27,186 @@
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;) {
printf(" %2x", buf[i++]); printf(" %2x", buf[i++]);
if (i % 16 == 0) if (i % 16 == 0)
printf("\n"); printf("\n");
} }
printf("\n"); printf("\n");
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
char *tmp_buf[TEST_SOURCES + 2] = { NULL }; char *tmp_buf[TEST_SOURCES + 2] = { NULL };
printf("Test pq_gen_test "); printf("Test pq_gen_test ");
srand(TEST_SEED); srand(TEST_SEED);
// Allocate the arrays // Allocate the arrays
for (i = 0; i < TEST_SOURCES + 2; i++) { for (i = 0; i < TEST_SOURCES + 2; i++) {
void *buf; void *buf;
ret = posix_memalign(&buf, 32, TEST_LEN); ret = posix_memalign(&buf, 32, TEST_LEN);
if (ret) { if (ret) {
printf("alloc error: Fail"); printf("alloc error: Fail");
fail = 1; fail = 1;
goto exit; goto exit;
} }
buffs[i] = buf; buffs[i] = buf;
} }
// Test of all zeros // Test of all zeros
for (i = 0; i < TEST_SOURCES + 2; i++) for (i = 0; i < TEST_SOURCES + 2; i++)
memset(buffs[i], 0, TEST_LEN); memset(buffs[i], 0, TEST_LEN);
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++;
} }
if (fail > 0) { if (fail > 0) {
printf("fail zero test %d\n", fail); printf("fail zero test %d\n", fail);
goto exit; goto exit;
} }
#ifdef TEST_VERBOSE #ifdef TEST_VERBOSE
putchar('.'); putchar('.');
#endif #endif
// Test rand1 // Test rand1
for (i = 0; i < TEST_SOURCES + 2; i++) for (i = 0; i < TEST_SOURCES + 2; i++)
rand_buffer(buffs[i], TEST_LEN); rand_buffer(buffs[i], TEST_LEN);
ret = pq_gen(TEST_SOURCES + 2, TEST_LEN, buffs); ret = pq_gen(TEST_SOURCES + 2, TEST_LEN, buffs);
fail |= pq_check_base(TEST_SOURCES + 2, TEST_LEN, buffs); fail |= pq_check_base(TEST_SOURCES + 2, TEST_LEN, buffs);
if (fail > 0) { if (fail > 0) {
int t; int t;
printf(" Fail rand test1 fail=%d, ret=%d\n", fail, ret); printf(" Fail rand test1 fail=%d, ret=%d\n", fail, ret);
for (t = 0; t < TEST_SOURCES + 2; t++) for (t = 0; t < TEST_SOURCES + 2; t++)
dump(buffs[t], 15); dump(buffs[t], 15);
printf(" reference function p,q\n"); printf(" reference function p,q\n");
pq_gen_base(TEST_SOURCES + 2, TEST_LEN, buffs); pq_gen_base(TEST_SOURCES + 2, TEST_LEN, buffs);
for (t = TEST_SOURCES; t < TEST_SOURCES + 2; t++) for (t = TEST_SOURCES; t < TEST_SOURCES + 2; t++)
dump(buffs[t], 15); dump(buffs[t], 15);
goto exit; goto exit;
} }
#ifdef TEST_VERBOSE #ifdef TEST_VERBOSE
putchar('.'); putchar('.');
#endif #endif
// Test various number of sources // Test various number of sources
for (j = 4; j <= TEST_SOURCES + 2; j++) { for (j = 4; j <= TEST_SOURCES + 2; j++) {
for (i = 0; i < j; i++) for (i = 0; i < j; i++)
rand_buffer(buffs[i], TEST_LEN); rand_buffer(buffs[i], TEST_LEN);
pq_gen(j, TEST_LEN, buffs); pq_gen(j, TEST_LEN, buffs);
fail |= pq_check_base(j, TEST_LEN, buffs); fail |= pq_check_base(j, TEST_LEN, buffs);
if (fail > 0) { if (fail > 0) {
printf("fail rand test %d sources\n", j); printf("fail rand test %d sources\n", j);
goto exit; goto exit;
} }
#ifdef TEST_VERBOSE #ifdef TEST_VERBOSE
putchar('.'); putchar('.');
#endif #endif
} }
fflush(0); fflush(0);
// Test various number of sources and len // Test various number of sources and len
k = 0; k = 0;
while (k <= TEST_LEN) { while (k <= TEST_LEN) {
for (j = 4; j <= TEST_SOURCES + 2; j++) { for (j = 4; j <= TEST_SOURCES + 2; j++) {
for (i = 0; i < j; i++) for (i = 0; i < j; i++)
rand_buffer(buffs[i], k); rand_buffer(buffs[i], k);
ret = pq_gen(j, k, buffs); ret = pq_gen(j, k, buffs);
fail |= pq_check_base(j, k, buffs); fail |= pq_check_base(j, k, buffs);
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",
goto exit; j, k, fail, ret);
} goto exit;
} }
}
#ifdef TEST_VERBOSE #ifdef TEST_VERBOSE
putchar('.'); putchar('.');
#endif #endif
k += 32; k += 32;
} }
// Test at the end of buffer // Test at the end of buffer
k = 0; k = 0;
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",
goto exit; k, TEST_LEN - k, fail, ret);
} goto exit;
}
#ifdef TEST_VERBOSE #ifdef TEST_VERBOSE
putchar('.'); putchar('.');
fflush(0); fflush(0);
#endif #endif
k += 32; k += 32;
} }
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,111 +31,114 @@
#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)
return 1; // Must have at least 2 src and 2 dest return 1; // Must have at least 2 src and 2 dest
for (i = 0; i < blocks; i++) { for (i = 0; i < blocks; i++) {
q = p = src[vects - 3][i]; q = p = src[vects - 3][i];
for (j = vects - 4; j >= 0; j--) { for (j = vects - 4; j >= 0; j--) {
p ^= s = src[j][i]; p ^= s = src[j][i];
q = s ^ (((q << 1) & notbit0) ^ // shift each byte q = s ^ (((q << 1) & notbit0) ^ // shift each byte
((((q & bit7) << 1) - ((q & bit7) >> 7)) // mask out bytes ((((q & bit7) << 1) - ((q & bit7) >> 7)) // mask out bytes
& gf8poly)); // apply poly & gf8poly)); // apply poly
} }
src[vects - 2][i] = p; // second to last pointer is p src[vects - 2][i] = p; // second to last pointer is p
src[vects - 1][i] = q; // last pointer is q src[vects - 1][i] = q; // last pointer is q
} }
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
for (i = 0; i < len; i++) { for (i = 0; i < len; i++) {
q = p = src[vects - 3][i]; q = p = src[vects - 3][i];
for (j = vects - 4; j >= 0; j--) { for (j = vects - 4; j >= 0; j--) {
s = src[j][i]; s = src[j][i];
p ^= s; p ^= s;
// mult by GF{2} // mult by GF{2}
q = s ^ ((q << 1) ^ ((q & 0x80) ? 0x1d : 0)); q = s ^ ((q << 1) ^ ((q & 0x80) ? 0x1d : 0));
} }
if (src[vects - 2][i] != p) // second to last pointer is p if (src[vects - 2][i] != p) // second to last pointer is p
return i | 1; return i | 1;
if (src[vects - 1][i] != q) // last pointer is q if (src[vects - 1][i] != q) // last pointer is q
return i | 2; return i | 2;
} }
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
for (i = 0; i < len; i++) { for (i = 0; i < len; i++) {
parity = src[0][i]; parity = src[0][i];
for (j = 1; j < vects - 1; j++) for (j = 1; j < vects - 1; j++)
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
for (i = 0; i < len; i++) { for (i = 0; i < len; i++) {
parity = 0; parity = 0;
for (j = 0; j < vects; j++) for (j = 0; j < vects; j++)
parity ^= src[j][i]; parity ^= src[j][i];
if (parity != 0) { if (parity != 0) {
fail = 1; fail = 1;
break; break;
} }
} }
if (fail && len > 0) if (fail && len > 0)
return len; return len;
return fail; return fail;
} }

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,269 +27,266 @@
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 };
char c; char c;
int serr, lerr; int serr, lerr;
char *tmp_buf[TEST_SOURCES + 1]; char *tmp_buf[TEST_SOURCES + 1];
printf("Test xor_check_test %d sources X %d bytes\n", TEST_SOURCES, TEST_LEN); printf("Test xor_check_test %d sources X %d bytes\n", TEST_SOURCES, TEST_LEN);
srand(TEST_SEED); srand(TEST_SEED);
// Allocate the arrays // Allocate the arrays
for (i = 0; i < TEST_SOURCES + 1; i++) { for (i = 0; i < TEST_SOURCES + 1; i++) {
void *buf; void *buf;
if (posix_memalign(&buf, 16, TEST_LEN)) { if (posix_memalign(&buf, 16, TEST_LEN)) {
printf("alloc error: Fail"); printf("alloc error: Fail");
fail = 1; fail = 1;
goto exit; goto exit;
} }
buffs[i] = buf; buffs[i] = buf;
} }
// Test of all zeros // Test of all zeros
for (i = 0; i < TEST_SOURCES + 1; i++) for (i = 0; i < TEST_SOURCES + 1; i++)
memset(buffs[i], 0, TEST_LEN); memset(buffs[i], 0, TEST_LEN);
xor_gen_base(TEST_SOURCES + 1, TEST_LEN, buffs); xor_gen_base(TEST_SOURCES + 1, TEST_LEN, buffs);
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 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('.');
#endif #endif
} }
// Test rand1 // Test rand1
for (i = 0; i < TEST_SOURCES + 1; i++) for (i = 0; i < TEST_SOURCES + 1; i++)
rand_buffer(buffs[i], TEST_LEN); rand_buffer(buffs[i], TEST_LEN);
xor_gen_base(TEST_SOURCES + 1, TEST_LEN, buffs); xor_gen_base(TEST_SOURCES + 1, TEST_LEN, buffs);
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("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++) {
for (i = TEST_LEN - 1; i >= 0; i--) { for (i = TEST_LEN - 1; i >= 0; i--) {
// Check it still passes // Check it still passes
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('.');
#endif #endif
} }
// Test various number of sources, full length // Test various number of sources, full length
for (j = 3; j <= TEST_SOURCES + 1; j++) { for (j = 3; j <= TEST_SOURCES + 1; j++) {
// New random data // New random data
for (i = 0; i < j; i++) for (i = 0; i < j; i++)
rand_buffer(buffs[i], TEST_LEN); rand_buffer(buffs[i], TEST_LEN);
// Generate xor parity for this number of sources // Generate xor parity for this number of sources
xor_gen_base(j, TEST_LEN, buffs); xor_gen_base(j, TEST_LEN, buffs);
// Set errors up in each source and len position // Set errors up in each source and len position
for (i = 0; i < j; i++) { for (i = 0; i < j; i++) {
for (k = 0; k < TEST_LEN; k++) { for (k = 0; k < TEST_LEN; k++) {
// See if it still passes // See if it still passes
ret = xor_check(j, TEST_LEN, buffs); ret = xor_check(j, TEST_LEN, buffs);
if (ret != 0) { // Should pass if (ret != 0) { // Should pass
printf("\nfail rand test %d sources\n", j); printf("\nfail rand test %d sources\n", j);
fail++; fail++;
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", fail++;
j); goto exit;
fail++; }
goto exit; ((char *) buffs[i])[k] = c; // un-corrupt buffer
} }
((char *)buffs[i])[k] = c; // un-corrupt buffer }
}
}
#ifdef TEST_VERBOSE #ifdef TEST_VERBOSE
putchar('.'); putchar('.');
#endif #endif
} }
fflush(0); fflush(0);
// Test various number of sources and len // Test various number of sources and len
k = 1; k = 1;
while (k <= TEST_LEN) { while (k <= TEST_LEN) {
for (j = 3; j <= TEST_SOURCES + 1; j++) { for (j = 3; j <= TEST_SOURCES + 1; j++) {
for (i = 0; i < j; i++) for (i = 0; i < j; i++)
rand_buffer(buffs[i], k); rand_buffer(buffs[i], k);
// Generate xor parity for this number of sources // Generate xor parity for this number of sources
xor_gen_base(j, k, buffs); xor_gen_base(j, k, buffs);
// Inject errors at various source and len positions // Inject errors at various source and len positions
for (lerr = 0; lerr < k; lerr += 10) { for (lerr = 0; lerr < k; lerr += 10) {
for (serr = 0; serr < j; serr++) { for (serr = 0; serr < j; serr++) {
// See if it still passes // See if it still passes
ret = xor_check(j, k, buffs); ret = xor_check(j, k, buffs);
if (ret != 0) { // Should pass if (ret != 0) { // Should pass
printf("\nfail rand test %d sources\n", j); printf("\nfail rand test %d sources\n", j);
fail++; fail++;
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
} }
} }
} }
#ifdef TEST_VERBOSE #ifdef TEST_VERBOSE
putchar('.'); putchar('.');
#endif #endif
fflush(0); fflush(0);
k += 1; k += 1;
} }
// 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(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++;
goto exit; goto exit;
} }
// Test bad data // Test bad data
for (serr = 0; serr < TEST_SOURCES + 1; serr++) { for (serr = 0; serr < TEST_SOURCES + 1; serr++) {
for (lerr = 0; lerr < (TEST_LEN - i); lerr++) { for (lerr = 0; lerr < (TEST_LEN - i); lerr++) {
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",
"offset: %d, len: %d, ret: %d\n", i, i, TEST_LEN - i, ret);
TEST_LEN - i, ret); fail++;
fail++; goto exit;
goto exit; }
}
tmp_buf[serr][lerr] = c; tmp_buf[serr][lerr] = c;
} }
} }
#ifdef TEST_VERBOSE #ifdef TEST_VERBOSE
putchar('.'); putchar('.');
#endif #endif
fflush(0); fflush(0);
} }
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,49 +32,50 @@
#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 };
printf("XOR example\n"); printf("XOR example\n");
for (i = 0; i < TEST_SOURCES + 1; i++) { for (i = 0; i < TEST_SOURCES + 1; i++) {
void *buf; void *buf;
if (posix_memalign(&buf, 32, TEST_LEN)) { if (posix_memalign(&buf, 32, TEST_LEN)) {
printf("alloc error: Fail"); printf("alloc error: Fail");
goto exit; goto exit;
} }
buffs[i] = buf; buffs[i] = buf;
} }
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);
printf("Check parity: "); printf("Check parity: ");
should_pass = xor_check(TEST_SOURCES + 1, TEST_LEN, buffs); should_pass = xor_check(TEST_SOURCES + 1, TEST_LEN, buffs);
printf("%s\n", should_pass == 0 ? "Pass" : "Fail"); printf("%s\n", should_pass == 0 ? "Pass" : "Fail");
if (should_pass != 0) { if (should_pass != 0) {
ret = -1; ret = -1;
goto exit; goto exit;
} }
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]);
return ret; return ret;
} }

View File

@ -27,65 +27,66 @@
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;
void *buff; void *buff;
struct perf start; struct perf start;
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;
} }
buffs = buff; buffs = buff;
// Allocate the arrays // Allocate the arrays
for (i = 0; i < TEST_SOURCES + 1; i++) { for (i = 0; i < TEST_SOURCES + 1; i++) {
void *buf; void *buf;
ret = posix_memalign(&buf, 64, TEST_LEN); ret = posix_memalign(&buf, 64, TEST_LEN);
if (ret) { if (ret) {
printf("alloc error: Fail"); printf("alloc error: Fail");
return 1; return 1;
} }
buffs[i] = buf; buffs[i] = buf;
} }
// Setup data // Setup data
for (i = 0; i < TEST_SOURCES + 1; i++) for (i = 0; i < TEST_SOURCES + 1; i++)
memset(buffs[i], 0, TEST_LEN); memset(buffs[i], 0, TEST_LEN);
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,153 +27,154 @@
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 };
char *tmp_buf[TEST_SOURCES + 1] = { NULL }; char *tmp_buf[TEST_SOURCES + 1] = { NULL };
printf("Test xor_gen_test "); printf("Test xor_gen_test ");
srand(TEST_SEED); srand(TEST_SEED);
// Allocate the arrays // Allocate the arrays
for (i = 0; i < TEST_SOURCES + 1; i++) { for (i = 0; i < TEST_SOURCES + 1; i++) {
void *buf; void *buf;
ret = posix_memalign(&buf, 32, TEST_LEN); ret = posix_memalign(&buf, 32, TEST_LEN);
if (ret) { if (ret) {
printf("alloc error: Fail"); printf("alloc error: Fail");
fail = 1; fail = 1;
goto exit; goto exit;
} }
buffs[i] = buf; buffs[i] = buf;
} }
// Test of all zeros // Test of all zeros
for (i = 0; i < TEST_SOURCES + 1; i++) for (i = 0; i < TEST_SOURCES + 1; i++)
memset(buffs[i], 0, TEST_LEN); memset(buffs[i], 0, TEST_LEN);
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++;
} }
if (fail > 0) { if (fail > 0) {
printf("fail zero test"); printf("fail zero test");
goto exit; goto exit;
} }
#ifdef TEST_VERBOSE #ifdef TEST_VERBOSE
putchar('.'); putchar('.');
#endif #endif
// Test rand1 // Test rand1
for (i = 0; i < TEST_SOURCES + 1; i++) for (i = 0; i < TEST_SOURCES + 1; i++)
rand_buffer(buffs[i], TEST_LEN); rand_buffer(buffs[i], TEST_LEN);
xor_gen(TEST_SOURCES + 1, TEST_LEN, buffs); xor_gen(TEST_SOURCES + 1, TEST_LEN, buffs);
fail |= xor_check_base(TEST_SOURCES + 1, TEST_LEN, buffs); fail |= xor_check_base(TEST_SOURCES + 1, TEST_LEN, buffs);
if (fail > 0) { if (fail > 0) {
printf("fail rand test %d\n", fail); printf("fail rand test %d\n", fail);
goto exit; goto exit;
} }
#ifdef TEST_VERBOSE #ifdef TEST_VERBOSE
putchar('.'); putchar('.');
#endif #endif
// Test various number of sources // Test various number of sources
for (j = 3; j <= TEST_SOURCES + 1; j++) { for (j = 3; j <= TEST_SOURCES + 1; j++) {
for (i = 0; i < j; i++) for (i = 0; i < j; i++)
rand_buffer(buffs[i], TEST_LEN); rand_buffer(buffs[i], TEST_LEN);
xor_gen(j, TEST_LEN, buffs); xor_gen(j, TEST_LEN, buffs);
fail |= xor_check_base(j, TEST_LEN, buffs); fail |= xor_check_base(j, TEST_LEN, buffs);
if (fail > 0) { if (fail > 0) {
printf("fail rand test %d sources\n", j); printf("fail rand test %d sources\n", j);
goto exit; goto exit;
} }
#ifdef TEST_VERBOSE #ifdef TEST_VERBOSE
putchar('.'); putchar('.');
#endif #endif
} }
fflush(0); fflush(0);
// Test various number of sources and len // Test various number of sources and len
k = 0; k = 0;
while (k <= TEST_LEN) { while (k <= TEST_LEN) {
for (j = 3; j <= TEST_SOURCES + 1; j++) { for (j = 3; j <= TEST_SOURCES + 1; j++) {
for (i = 0; i < j; i++) for (i = 0; i < j; i++)
rand_buffer(buffs[i], k); rand_buffer(buffs[i], k);
xor_gen(j, k, buffs); xor_gen(j, k, buffs);
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; }
} }
}
#ifdef TEST_VERBOSE #ifdef TEST_VERBOSE
putchar('.'); putchar('.');
#endif #endif
k += 1; k += 1;
} }
// 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);
goto exit; goto exit;
} }
#ifdef TEST_VERBOSE #ifdef TEST_VERBOSE
putchar('.'); putchar('.');
#endif #endif
fflush(0); fflush(0);
} }
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]);
return fail; return fail;
} }