diff --git a/raid/aarch64/raid_aarch64_dispatcher.c b/raid/aarch64/raid_aarch64_dispatcher.c index 5a6148e..3251a81 100644 --- a/raid/aarch64/raid_aarch64_dispatcher.c +++ b/raid/aarch64/raid_aarch64_dispatcher.c @@ -31,47 +31,43 @@ DEFINE_INTERFACE_DISPATCHER(xor_gen) { #if defined(__linux__) - if (getauxval(AT_HWCAP) & HWCAP_ASIMD) - return PROVIDER_INFO(xor_gen_neon); + if (getauxval(AT_HWCAP) & HWCAP_ASIMD) + return PROVIDER_INFO(xor_gen_neon); #elif defined(__APPLE__) - return PROVIDER_INFO(xor_gen_neon); + return PROVIDER_INFO(xor_gen_neon); #endif - return PROVIDER_BASIC(xor_gen); - + return PROVIDER_BASIC(xor_gen); } DEFINE_INTERFACE_DISPATCHER(xor_check) { #if defined(__linux__) - if (getauxval(AT_HWCAP) & HWCAP_ASIMD) - return PROVIDER_INFO(xor_check_neon); + if (getauxval(AT_HWCAP) & HWCAP_ASIMD) + return PROVIDER_INFO(xor_check_neon); #elif defined(__APPLE__) - return PROVIDER_INFO(xor_check_neon); + return PROVIDER_INFO(xor_check_neon); #endif - return PROVIDER_BASIC(xor_check); - + return PROVIDER_BASIC(xor_check); } DEFINE_INTERFACE_DISPATCHER(pq_gen) { #if defined(__linux__) - if (getauxval(AT_HWCAP) & HWCAP_ASIMD) - return PROVIDER_INFO(pq_gen_neon); + if (getauxval(AT_HWCAP) & HWCAP_ASIMD) + return PROVIDER_INFO(pq_gen_neon); #elif defined(__APPLE__) - return PROVIDER_INFO(pq_gen_neon); + return PROVIDER_INFO(pq_gen_neon); #endif - return PROVIDER_BASIC(pq_gen); - + return PROVIDER_BASIC(pq_gen); } DEFINE_INTERFACE_DISPATCHER(pq_check) { #if defined(__linux__) - if (getauxval(AT_HWCAP) & HWCAP_ASIMD) - return PROVIDER_INFO(pq_check_neon); + if (getauxval(AT_HWCAP) & HWCAP_ASIMD) + return PROVIDER_INFO(pq_check_neon); #elif defined(__APPLE__) - return PROVIDER_INFO(pq_check_neon); + return PROVIDER_INFO(pq_check_neon); #endif - return PROVIDER_BASIC(pq_check); - + return PROVIDER_BASIC(pq_check); } diff --git a/raid/pq_check_test.c b/raid/pq_check_test.c index f9480d2..556fbb4 100644 --- a/raid/pq_check_test.c +++ b/raid/pq_check_test.c @@ -27,291 +27,291 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. **********************************************************************/ -#include -#include -#include -#include +#include +#include +#include +#include #include "raid.h" #include "test.h" #define TEST_SOURCES 16 #define TEST_LEN 1024 -#define TEST_MEM ((TEST_SOURCES + 2)*(TEST_LEN)) +#define TEST_MEM ((TEST_SOURCES + 2) * (TEST_LEN)) #ifndef TEST_SEED -# define TEST_SEED 0x1234 +#define TEST_SEED 0x1234 #endif -int ref_multi_pq(int vects, int len, void **array) +int +ref_multi_pq(int vects, int len, void **array) { - int i, j; - unsigned char p, q, s; - unsigned char **src = (unsigned char **)array; + int i, j; + unsigned char p, q, s; + unsigned char **src = (unsigned char **) array; - for (i = 0; i < len; i++) { - q = p = src[vects - 3][i]; + for (i = 0; i < len; i++) { + q = p = src[vects - 3][i]; - for (j = vects - 4; j >= 0; j--) { - p ^= s = src[j][i]; - q = s ^ ((q << 1) ^ ((q & 0x80) ? 0x1d : 0)); // mult by GF{2} - } + for (j = vects - 4; j >= 0; j--) { + p ^= s = src[j][i]; + 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 - 1][i] = q; // last pointer is q - } - return 0; + src[vects - 2][i] = p; // second to last pointer is p + src[vects - 1][i] = q; // last pointer is q + } + return 0; } // Generates pseudo-random data -void rand_buffer(unsigned char *buf, long buffer_size) +void +rand_buffer(unsigned char *buf, long buffer_size) { - long i; - for (i = 0; i < buffer_size; i++) - buf[i] = rand(); + long i; + for (i = 0; i < buffer_size; i++) + buf[i] = rand(); } -int main(int argc, char *argv[]) +int +main(int argc, char *argv[]) { - int i, j, k, ret, fail = 0; - void *buffs[TEST_SOURCES + 2] = { NULL }; - char c; - char *tmp_buf[TEST_SOURCES + 2] = { NULL }; - int serr, lerr; + int i, j, k, ret, fail = 0; + void *buffs[TEST_SOURCES + 2] = { NULL }; + char c; + char *tmp_buf[TEST_SOURCES + 2] = { NULL }; + 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 - for (i = 0; i < TEST_SOURCES + 2; i++) { - void *buf; - if (posix_memalign(&buf, 16, TEST_LEN)) { - printf("alloc error: Fail"); - return 1; - } - buffs[i] = buf; - } + // Allocate the arrays + for (i = 0; i < TEST_SOURCES + 2; i++) { + void *buf; + if (posix_memalign(&buf, 16, TEST_LEN)) { + printf("alloc error: Fail"); + return 1; + } + buffs[i] = buf; + } - // Test of all zeros - for (i = 0; i < TEST_SOURCES + 2; i++) - memset(buffs[i], 0, TEST_LEN); + // Test of all zeros + for (i = 0; i < TEST_SOURCES + 2; i++) + memset(buffs[i], 0, TEST_LEN); - ref_multi_pq(TEST_SOURCES + 2, TEST_LEN, buffs); - ret = pq_check(TEST_SOURCES + 2, TEST_LEN, buffs); - if (ret != 0) { - fail++; - printf("\nfail zero test %d\n", ret); - } + ref_multi_pq(TEST_SOURCES + 2, TEST_LEN, buffs); + ret = pq_check(TEST_SOURCES + 2, TEST_LEN, buffs); + if (ret != 0) { + fail++; + printf("\nfail zero test %d\n", ret); + } - ((char *)(buffs[0]))[TEST_LEN - 2] = 0x7; // corrupt buffer - ret = pq_check(TEST_SOURCES + 2, TEST_LEN, buffs); - if (ret == 0) { - fail++; - printf("\nfail corrupt buffer test %d\n", ret); - } - ((char *)(buffs[0]))[TEST_LEN - 2] = 0; // un-corrupt buffer + ((char *) (buffs[0]))[TEST_LEN - 2] = 0x7; // corrupt buffer + ret = pq_check(TEST_SOURCES + 2, TEST_LEN, buffs); + if (ret == 0) { + fail++; + printf("\nfail corrupt buffer test %d\n", ret); + } + ((char *) (buffs[0]))[TEST_LEN - 2] = 0; // un-corrupt buffer - // Test corrupted buffer any location on all sources - for (j = 0; j < TEST_SOURCES + 2; j++) { - for (i = TEST_LEN - 1; i >= 0; i--) { - ((char *)buffs[j])[i] = 0x5; // corrupt buffer - ret = pq_check(TEST_SOURCES + 2, TEST_LEN, buffs); - if (ret == 0) { - fail++; - printf("\nfail corrupt zero buffer test j=%d, i=%d\n", j, i); - goto exit; - } - ((char *)buffs[j])[i] = 0; // un-corrupt buffer - } + // Test corrupted buffer any location on all sources + for (j = 0; j < TEST_SOURCES + 2; j++) { + for (i = TEST_LEN - 1; i >= 0; i--) { + ((char *) buffs[j])[i] = 0x5; // corrupt buffer + ret = pq_check(TEST_SOURCES + 2, TEST_LEN, buffs); + if (ret == 0) { + fail++; + printf("\nfail corrupt zero buffer test j=%d, i=%d\n", j, i); + goto exit; + } + ((char *) buffs[j])[i] = 0; // un-corrupt buffer + } #ifdef TEST_VERBOSE - putchar('.'); + putchar('.'); #endif - } + } - // Test rand1 - for (i = 0; i < TEST_SOURCES + 2; i++) - rand_buffer(buffs[i], TEST_LEN); + // Test rand1 + for (i = 0; i < TEST_SOURCES + 2; i++) + rand_buffer(buffs[i], TEST_LEN); - ref_multi_pq(TEST_SOURCES + 2, TEST_LEN, buffs); - ret = pq_check(TEST_SOURCES + 2, TEST_LEN, buffs); - if (ret != 0) { - fail++; - printf("fail first rand test %d\n", ret); - } + ref_multi_pq(TEST_SOURCES + 2, TEST_LEN, buffs); + ret = pq_check(TEST_SOURCES + 2, TEST_LEN, buffs); + if (ret != 0) { + fail++; + printf("fail first rand test %d\n", ret); + } - c = ((char *)(buffs[0]))[TEST_LEN - 2]; - ((char *)(buffs[0]))[TEST_LEN - 2] = c ^ 0x1; - ret = pq_check(TEST_SOURCES + 2, TEST_LEN, buffs); - if (ret == 0) { - fail++; - printf("\nFail corrupt buffer test, passed when should have failed\n"); - } - ((char *)(buffs[0]))[TEST_LEN - 2] = c; // un-corrupt buffer + c = ((char *) (buffs[0]))[TEST_LEN - 2]; + ((char *) (buffs[0]))[TEST_LEN - 2] = c ^ 0x1; + ret = pq_check(TEST_SOURCES + 2, TEST_LEN, buffs); + if (ret == 0) { + fail++; + printf("\nFail corrupt buffer test, passed when should have failed\n"); + } + ((char *) (buffs[0]))[TEST_LEN - 2] = c; // un-corrupt buffer - // Test corrupted buffer any location on all sources w/ random data - for (j = 0; j < TEST_SOURCES + 2; j++) { - for (i = TEST_LEN - 1; i >= 0; i--) { - // Check it still passes - ret = pq_check(TEST_SOURCES + 2, TEST_LEN, buffs); - if (ret != 0) { // should pass - fail++; - printf - ("\nFail rand test with un-corrupted buffer j=%d, i=%d\n", - j, i); - goto exit; - } - c = ((char *)buffs[j])[i]; - ((char *)buffs[j])[i] = c ^ 1; // corrupt buffer - ret = pq_check(TEST_SOURCES + 2, TEST_LEN, buffs); - if (ret == 0) { // Check it now fails - fail++; - printf("\nfail corrupt buffer test j=%d, i=%d\n", j, i); - goto exit; - } - ((char *)buffs[j])[i] = c; // un-corrupt buffer - } + // Test corrupted buffer any location on all sources w/ random data + for (j = 0; j < TEST_SOURCES + 2; j++) { + for (i = TEST_LEN - 1; i >= 0; i--) { + // Check it still passes + ret = pq_check(TEST_SOURCES + 2, TEST_LEN, buffs); + if (ret != 0) { // should pass + fail++; + printf("\nFail rand test with un-corrupted buffer j=%d, i=%d\n", j, + i); + goto exit; + } + c = ((char *) buffs[j])[i]; + ((char *) buffs[j])[i] = c ^ 1; // corrupt buffer + ret = pq_check(TEST_SOURCES + 2, TEST_LEN, buffs); + if (ret == 0) { // Check it now fails + fail++; + printf("\nfail corrupt buffer test j=%d, i=%d\n", j, i); + goto exit; + } + ((char *) buffs[j])[i] = c; // un-corrupt buffer + } #ifdef TEST_VERBOSE - putchar('.'); + putchar('.'); #endif - } + } - // Test various number of sources, full length - for (j = 4; j <= TEST_SOURCES + 2; j++) { - // New random data - for (i = 0; i < j; i++) - rand_buffer(buffs[i], TEST_LEN); + // Test various number of sources, full length + for (j = 4; j <= TEST_SOURCES + 2; j++) { + // New random data + for (i = 0; i < j; i++) + rand_buffer(buffs[i], TEST_LEN); - // Generate p,q parity for this number of sources - ref_multi_pq(j, TEST_LEN, buffs); + // Generate p,q parity for this number of sources + ref_multi_pq(j, TEST_LEN, buffs); - // Set errors up in each source and len position - for (i = 0; i < j; i++) { - for (k = 0; k < TEST_LEN; k++) { - // See if it still passes - ret = pq_check(j, TEST_LEN, buffs); - if (ret != 0) { // Should pass - printf("\nfail rand fixed len test %d sources\n", j); - fail++; - goto exit; - } + // Set errors up in each source and len position + for (i = 0; i < j; i++) { + for (k = 0; k < TEST_LEN; k++) { + // See if it still passes + ret = pq_check(j, TEST_LEN, buffs); + if (ret != 0) { // Should pass + printf("\nfail rand fixed len test %d sources\n", j); + fail++; + goto exit; + } - c = ((char *)buffs[i])[k]; - ((char *)buffs[i])[k] = c ^ 1; // corrupt buffer + c = ((char *) buffs[i])[k]; + ((char *) buffs[i])[k] = c ^ 1; // corrupt buffer - ret = pq_check(j, TEST_LEN, buffs); - if (ret == 0) { // Should fail - printf - ("\nfail rand fixed len test corrupted buffer %d sources\n", - j); - fail++; - goto exit; - } - ((char *)buffs[i])[k] = c; // un-corrupt buffer - } - } + ret = pq_check(j, TEST_LEN, buffs); + if (ret == 0) { // Should fail + printf("\nfail rand fixed len test corrupted buffer %d " + "sources\n", + j); + fail++; + goto exit; + } + ((char *) buffs[i])[k] = c; // un-corrupt buffer + } + } #ifdef TEST_VERBOSE - putchar('.'); + putchar('.'); #endif - } + } - fflush(0); + fflush(0); - // Test various number of sources and len - k = 16; - while (k <= TEST_LEN) { - char *tmp; - for (j = 4; j <= TEST_SOURCES + 2; j++) { - for (i = 0; i < j; i++) - rand_buffer(buffs[i], k); + // Test various number of sources and len + k = 16; + while (k <= TEST_LEN) { + char *tmp; + for (j = 4; j <= TEST_SOURCES + 2; j++) { + for (i = 0; i < j; i++) + rand_buffer(buffs[i], k); - // Generate p,q parity for this number of sources - ref_multi_pq(j, k, buffs); + // Generate p,q parity for this number of sources + ref_multi_pq(j, k, buffs); - // Inject errors at various source and len positions - for (lerr = 0; lerr < k; lerr++) { - for (serr = 0; serr < j; serr++) { - // See if it still passes - ret = pq_check(j, k, buffs); - if (ret != 0) { // Should pass - printf - ("\nfail rand var src, len test %d sources, len=%d\n", - j, k); - fail++; - goto exit; - } + // Inject errors at various source and len positions + for (lerr = 0; lerr < k; lerr++) { + for (serr = 0; serr < j; serr++) { + // See if it still passes + ret = pq_check(j, k, buffs); + if (ret != 0) { // Should pass + printf("\nfail rand var src, len test %d sources, " + "len=%d\n", + j, k); + fail++; + goto exit; + } - tmp = (char *)buffs[serr]; - c = tmp[lerr]; - ((char *)buffs[serr])[lerr] = c ^ 1; // corrupt buffer + tmp = (char *) buffs[serr]; + c = tmp[lerr]; + ((char *) buffs[serr])[lerr] = c ^ 1; // corrupt buffer - ret = pq_check(j, k, buffs); - if (ret == 0) { // Should fail - printf - ("\nfail rand var src, len test corrupted buffer " - "%d sources, len=%d, ret=%d\n", j, k, - ret); - fail++; - goto exit; - } - ((char *)buffs[serr])[lerr] = c; // un-corrupt buffer - } - } + ret = pq_check(j, k, buffs); + if (ret == 0) { // Should fail + printf("\nfail rand var src, len test corrupted " + "buffer " + "%d sources, len=%d, ret=%d\n", + j, k, ret); + fail++; + goto exit; + } + ((char *) buffs[serr])[lerr] = c; // un-corrupt buffer + } + } #ifdef TEST_VERBOSE - putchar('.'); + putchar('.'); #endif - fflush(0); - } - k += 16; - } + fflush(0); + } + k += 16; + } - // Test at the end of buffer - for (i = 0; i < TEST_LEN; i += 16) { - for (j = 0; j < TEST_SOURCES + 2; j++) { - rand_buffer(buffs[j], TEST_LEN - i); - tmp_buf[j] = (char *)buffs[j] + i; - } + // Test at the end of buffer + for (i = 0; i < TEST_LEN; i += 16) { + for (j = 0; j < TEST_SOURCES + 2; j++) { + rand_buffer(buffs[j], TEST_LEN - 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 - ret = pq_check(TEST_SOURCES + 2, TEST_LEN - i, (void *)tmp_buf); - if (ret != 0) { - printf("fail end test - offset: %d, len: %d\n", i, TEST_LEN - i); - fail++; - return 1; - } - // Test bad data - for (serr = 0; serr < TEST_SOURCES + 2; serr++) { - for (lerr = 0; lerr < (TEST_LEN - i); lerr++) { - c = tmp_buf[serr][lerr]; - tmp_buf[serr][lerr] = c ^ 1; + // Test good data + ret = pq_check(TEST_SOURCES + 2, TEST_LEN - i, (void *) tmp_buf); + if (ret != 0) { + printf("fail end test - offset: %d, len: %d\n", i, TEST_LEN - i); + fail++; + return 1; + } + // Test bad data + for (serr = 0; serr < TEST_SOURCES + 2; serr++) { + for (lerr = 0; lerr < (TEST_LEN - i); lerr++) { + c = tmp_buf[serr][lerr]; + tmp_buf[serr][lerr] = c ^ 1; - ret = - pq_check(TEST_SOURCES + 2, TEST_LEN - i, (void *)tmp_buf); - if (ret == 0) { - printf("fail end test corrupted buffer - " - "offset: %d, len: %d, ret: %d\n", i, - TEST_LEN - i, ret); - fail++; - goto exit; - } + ret = pq_check(TEST_SOURCES + 2, TEST_LEN - i, (void *) tmp_buf); + if (ret == 0) { + printf("fail end test corrupted buffer - " + "offset: %d, len: %d, ret: %d\n", + i, TEST_LEN - i, ret); + fail++; + goto exit; + } - tmp_buf[serr][lerr] = c; - } - } + tmp_buf[serr][lerr] = c; + } + } #ifdef TEST_VERBOSE - putchar('.'); + putchar('.'); #endif - fflush(0); - } + fflush(0); + } - if (fail == 0) - printf("Pass\n"); - - exit: - for (i = 0; i < TEST_SOURCES + 2; i++) - aligned_free(buffs[i]); - return fail; + if (fail == 0) + printf("Pass\n"); +exit: + for (i = 0; i < TEST_SOURCES + 2; i++) + aligned_free(buffs[i]); + return fail; } diff --git a/raid/pq_gen_perf.c b/raid/pq_gen_perf.c index 2a71339..50b190b 100644 --- a/raid/pq_gen_perf.c +++ b/raid/pq_gen_perf.c @@ -27,61 +27,62 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. **********************************************************************/ -#include -#include -#include -#include +#include +#include +#include +#include #include "raid.h" #include "test.h" #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 #if !defined(COLD_TEST) && !defined(TEST_CUSTOM) // Cached test, loop many times over small dataset -# define TEST_SOURCES 10 -# define TEST_LEN 8*1024 -# define TEST_TYPE_STR "_warm" -#elif defined (COLD_TEST) +#define TEST_SOURCES 10 +#define TEST_LEN 8 * 1024 +#define TEST_TYPE_STR "_warm" +#elif defined(COLD_TEST) // Uncached test. Pull from large mem base. -# define TEST_SOURCES 10 -# define TEST_LEN ((GT_L3_CACHE / TEST_SOURCES) & ~(64-1)) -# define TEST_TYPE_STR "_cold" -#elif defined (TEST_CUSTOM) -# define TEST_TYPE_STR "_cus" +#define TEST_SOURCES 10 +#define TEST_LEN ((GT_L3_CACHE / TEST_SOURCES) & ~(64 - 1)) +#define TEST_TYPE_STR "_cold" +#elif defined(TEST_CUSTOM) +#define TEST_TYPE_STR "_cus" #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; - void *buffs[TEST_SOURCES + 2]; - struct perf start; + int i; + void *buffs[TEST_SOURCES + 2]; + 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 - for (i = 0; i < TEST_SOURCES + 2; i++) { - int ret; - void *buf; - ret = posix_memalign(&buf, 64, TEST_LEN); - if (ret) { - printf("alloc error: Fail"); - return 1; - } - buffs[i] = buf; - } + // Allocate the arrays + for (i = 0; i < TEST_SOURCES + 2; i++) { + int ret; + void *buf; + ret = posix_memalign(&buf, 64, TEST_LEN); + if (ret) { + printf("alloc error: Fail"); + return 1; + } + buffs[i] = buf; + } - // Setup data - for (i = 0; i < TEST_SOURCES + 2; i++) - memset(buffs[i], 0, TEST_LEN); + // Setup data + for (i = 0; i < TEST_SOURCES + 2; i++) + memset(buffs[i], 0, TEST_LEN); - // Warm up - BENCHMARK(&start, BENCHMARK_TIME, pq_gen(TEST_SOURCES + 2, TEST_LEN, buffs)); - printf("pq_gen" TEST_TYPE_STR ": "); - perf_print(start, (long long)TEST_MEM); + // Warm up + BENCHMARK(&start, BENCHMARK_TIME, pq_gen(TEST_SOURCES + 2, TEST_LEN, buffs)); + printf("pq_gen" TEST_TYPE_STR ": "); + perf_print(start, (long long) TEST_MEM); - return 0; + return 0; } diff --git a/raid/pq_gen_test.c b/raid/pq_gen_test.c index b6c9756..6be5658 100644 --- a/raid/pq_gen_test.c +++ b/raid/pq_gen_test.c @@ -27,181 +27,186 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. **********************************************************************/ -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include #include "raid.h" #include "test.h" #define TEST_SOURCES 16 #define TEST_LEN 1024 -#define TEST_MEM ((TEST_SOURCES + 2)*(TEST_LEN)) +#define TEST_MEM ((TEST_SOURCES + 2) * (TEST_LEN)) #ifndef TEST_SEED -# define TEST_SEED 0x1234 +#define TEST_SEED 0x1234 #endif // Generates pseudo-random data -void rand_buffer(unsigned char *buf, long buffer_size) +void +rand_buffer(unsigned char *buf, long buffer_size) { - long i; - for (i = 0; i < buffer_size; i++) - buf[i] = rand(); + long i; + for (i = 0; i < buffer_size; i++) + buf[i] = rand(); } -int dump(unsigned char *buf, int len) +int +dump(unsigned char *buf, int len) { - int i; - for (i = 0; i < len;) { - printf(" %2x", buf[i++]); - if (i % 16 == 0) - printf("\n"); - } - printf("\n"); - return 0; + int i; + for (i = 0; i < len;) { + printf(" %2x", buf[i++]); + if (i % 16 == 0) + printf("\n"); + } + printf("\n"); + return 0; } -int main(int argc, char *argv[]) +int +main(int argc, char *argv[]) { - int i, j, k, ret = 0, fail = 0; - void *buffs[TEST_SOURCES + 2] = { NULL }; // Pointers to src and dest - char *tmp_buf[TEST_SOURCES + 2] = { NULL }; + int i, j, k, ret = 0, fail = 0; + void *buffs[TEST_SOURCES + 2] = { NULL }; // Pointers to src and dest + 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 - for (i = 0; i < TEST_SOURCES + 2; i++) { - void *buf; - ret = posix_memalign(&buf, 32, TEST_LEN); - if (ret) { - printf("alloc error: Fail"); - fail = 1; - goto exit; - } - buffs[i] = buf; - } + // Allocate the arrays + for (i = 0; i < TEST_SOURCES + 2; i++) { + void *buf; + ret = posix_memalign(&buf, 32, TEST_LEN); + if (ret) { + printf("alloc error: Fail"); + fail = 1; + goto exit; + } + buffs[i] = buf; + } - // Test of all zeros - for (i = 0; i < TEST_SOURCES + 2; i++) - memset(buffs[i], 0, TEST_LEN); + // Test of all zeros + for (i = 0; i < TEST_SOURCES + 2; i++) + 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++) { - if (((char *)buffs[TEST_SOURCES])[i] != 0) - fail++; - } + for (i = 0; i < TEST_LEN; i++) { + if (((char *) buffs[TEST_SOURCES])[i] != 0) + fail++; + } - for (i = 0; i < TEST_LEN; i++) { - if (((char *)buffs[TEST_SOURCES + 1])[i] != 0) - fail++; - } + for (i = 0; i < TEST_LEN; i++) { + if (((char *) buffs[TEST_SOURCES + 1])[i] != 0) + fail++; + } - if (fail > 0) { - printf("fail zero test %d\n", fail); - goto exit; - } + if (fail > 0) { + printf("fail zero test %d\n", fail); + goto exit; + } #ifdef TEST_VERBOSE - putchar('.'); + putchar('.'); #endif - // Test rand1 - for (i = 0; i < TEST_SOURCES + 2; i++) - rand_buffer(buffs[i], TEST_LEN); + // Test rand1 + for (i = 0; i < TEST_SOURCES + 2; i++) + rand_buffer(buffs[i], TEST_LEN); - ret = pq_gen(TEST_SOURCES + 2, TEST_LEN, buffs); - fail |= pq_check_base(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); - if (fail > 0) { - int t; - printf(" Fail rand test1 fail=%d, ret=%d\n", fail, ret); - for (t = 0; t < TEST_SOURCES + 2; t++) - dump(buffs[t], 15); + if (fail > 0) { + int t; + printf(" Fail rand test1 fail=%d, ret=%d\n", fail, ret); + for (t = 0; t < TEST_SOURCES + 2; t++) + dump(buffs[t], 15); - printf(" reference function p,q\n"); - pq_gen_base(TEST_SOURCES + 2, TEST_LEN, buffs); - for (t = TEST_SOURCES; t < TEST_SOURCES + 2; t++) - dump(buffs[t], 15); + printf(" reference function p,q\n"); + pq_gen_base(TEST_SOURCES + 2, TEST_LEN, buffs); + for (t = TEST_SOURCES; t < TEST_SOURCES + 2; t++) + dump(buffs[t], 15); - goto exit; - } + goto exit; + } #ifdef TEST_VERBOSE - putchar('.'); + putchar('.'); #endif - // Test various number of sources - for (j = 4; j <= TEST_SOURCES + 2; j++) { - for (i = 0; i < j; i++) - rand_buffer(buffs[i], TEST_LEN); + // Test various number of sources + for (j = 4; j <= TEST_SOURCES + 2; j++) { + for (i = 0; i < j; i++) + rand_buffer(buffs[i], TEST_LEN); - pq_gen(j, TEST_LEN, buffs); - fail |= pq_check_base(j, TEST_LEN, buffs); + pq_gen(j, TEST_LEN, buffs); + fail |= pq_check_base(j, TEST_LEN, buffs); - if (fail > 0) { - printf("fail rand test %d sources\n", j); - goto exit; - } + if (fail > 0) { + printf("fail rand test %d sources\n", j); + goto exit; + } #ifdef TEST_VERBOSE - putchar('.'); + putchar('.'); #endif - } + } - fflush(0); + fflush(0); - // Test various number of sources and len - k = 0; - while (k <= TEST_LEN) { - for (j = 4; j <= TEST_SOURCES + 2; j++) { - for (i = 0; i < j; i++) - rand_buffer(buffs[i], k); + // Test various number of sources and len + k = 0; + while (k <= TEST_LEN) { + for (j = 4; j <= TEST_SOURCES + 2; j++) { + for (i = 0; i < j; i++) + rand_buffer(buffs[i], k); - ret = pq_gen(j, k, buffs); - fail |= pq_check_base(j, k, buffs); + ret = pq_gen(j, k, buffs); + fail |= pq_check_base(j, k, buffs); - if (fail > 0) { - printf("fail rand test %d sources, len=%d, fail=" - "%d, ret=%d\n", j, k, fail, ret); - goto exit; - } - } + if (fail > 0) { + printf("fail rand test %d sources, len=%d, fail=" + "%d, ret=%d\n", + j, k, fail, ret); + goto exit; + } + } #ifdef TEST_VERBOSE - putchar('.'); + putchar('.'); #endif - k += 32; - } + k += 32; + } - // Test at the end of buffer - k = 0; - while (k <= TEST_LEN) { - for (j = 0; j < (TEST_SOURCES + 2); j++) { - rand_buffer(buffs[j], TEST_LEN - k); - tmp_buf[j] = (char *)buffs[j] + k; - } + // Test at the end of buffer + k = 0; + while (k <= TEST_LEN) { + for (j = 0; j < (TEST_SOURCES + 2); j++) { + rand_buffer(buffs[j], TEST_LEN - k); + tmp_buf[j] = (char *) buffs[j] + k; + } - 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); + 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); - if (fail > 0) { - printf("fail end test - offset: %d, len: %d, fail: %d, " - "ret: %d\n", k, TEST_LEN - k, fail, ret); - goto exit; - } + if (fail > 0) { + printf("fail end test - offset: %d, len: %d, fail: %d, " + "ret: %d\n", + k, TEST_LEN - k, fail, ret); + goto exit; + } #ifdef TEST_VERBOSE - putchar('.'); - fflush(0); + putchar('.'); + fflush(0); #endif - k += 32; - } + k += 32; + } - if (!fail) - printf(" done: Pass\n"); + if (!fail) + printf(" done: 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; } diff --git a/raid/raid_base.c b/raid/raid_base.c index 62bdca7..e06a6a7 100644 --- a/raid/raid_base.c +++ b/raid/raid_base.c @@ -31,111 +31,114 @@ #include #if __WORDSIZE == 64 || _WIN64 || __x86_64__ -# define notbit0 0xfefefefefefefefeULL -# define bit7 0x8080808080808080ULL -# define gf8poly 0x1d1d1d1d1d1d1d1dULL +#define notbit0 0xfefefefefefefefeULL +#define bit7 0x8080808080808080ULL +#define gf8poly 0x1d1d1d1d1d1d1d1dULL #else -# define notbit0 0xfefefefeUL -# define bit7 0x80808080UL -# define gf8poly 0x1d1d1d1dUL +#define notbit0 0xfefefefeUL +#define bit7 0x80808080UL +#define gf8poly 0x1d1d1d1dUL #endif -int pq_gen_base(int vects, int len, void **array) +int +pq_gen_base(int vects, int len, void **array) { - int i, j; - unsigned long p, q, s; - unsigned long **src = (unsigned long **)array; - int blocks = len / sizeof(long); + int i, j; + unsigned long p, q, s; + unsigned long **src = (unsigned long **) array; + int blocks = len / sizeof(long); - if (vects < 4) - return 1; // Must have at least 2 src and 2 dest + if (vects < 4) + return 1; // Must have at least 2 src and 2 dest - for (i = 0; i < blocks; i++) { - q = p = src[vects - 3][i]; + for (i = 0; i < blocks; i++) { + q = p = src[vects - 3][i]; - for (j = vects - 4; j >= 0; j--) { - p ^= s = src[j][i]; - q = s ^ (((q << 1) & notbit0) ^ // shift each byte - ((((q & bit7) << 1) - ((q & bit7) >> 7)) // mask out bytes - & gf8poly)); // apply poly - } + for (j = vects - 4; j >= 0; j--) { + p ^= s = src[j][i]; + q = s ^ (((q << 1) & notbit0) ^ // shift each byte + ((((q & bit7) << 1) - ((q & bit7) >> 7)) // mask out bytes + & gf8poly)); // apply poly + } - src[vects - 2][i] = p; // second to last pointer is p - src[vects - 1][i] = q; // last pointer is q - } - return 0; + src[vects - 2][i] = p; // second to last pointer is p + src[vects - 1][i] = q; // last pointer is q + } + 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; - unsigned char p, q, s; - unsigned char **src = (unsigned char **)array; + int i, j; + unsigned char p, q, s; + unsigned char **src = (unsigned char **) array; - if (vects < 4) - return 1; // Must have at least 2 src and 2 dest + if (vects < 4) + return 1; // Must have at least 2 src and 2 dest - for (i = 0; i < len; i++) { - q = p = src[vects - 3][i]; + for (i = 0; i < len; i++) { + q = p = src[vects - 3][i]; - for (j = vects - 4; j >= 0; j--) { - s = src[j][i]; - p ^= s; + for (j = vects - 4; j >= 0; j--) { + s = src[j][i]; + p ^= s; - // mult by GF{2} - q = s ^ ((q << 1) ^ ((q & 0x80) ? 0x1d : 0)); - } + // mult by GF{2} + q = s ^ ((q << 1) ^ ((q & 0x80) ? 0x1d : 0)); + } - if (src[vects - 2][i] != p) // second to last pointer is p - return i | 1; - if (src[vects - 1][i] != q) // last pointer is q - return i | 2; - } - return 0; + if (src[vects - 2][i] != p) // second to last pointer is p + return i | 1; + if (src[vects - 1][i] != q) // last pointer is q + return i | 2; + } + 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; - unsigned char parity; - unsigned char **src = (unsigned char **)array; + int i, j; + unsigned char parity; + unsigned char **src = (unsigned char **) array; - if (vects < 3) - return 1; // Must have at least 2 src and 1 dest + if (vects < 3) + return 1; // Must have at least 2 src and 1 dest - for (i = 0; i < len; i++) { - parity = src[0][i]; - for (j = 1; j < vects - 1; j++) - parity ^= src[j][i]; + for (i = 0; i < len; i++) { + parity = src[0][i]; + for (j = 1; j < vects - 1; j++) + 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 **src = (unsigned char **)array; + unsigned char parity; + unsigned char **src = (unsigned char **) array; - if (vects < 2) - return 1; // Must have at least 2 src + if (vects < 2) + return 1; // Must have at least 2 src - for (i = 0; i < len; i++) { - parity = 0; - for (j = 0; j < vects; j++) - parity ^= src[j][i]; + for (i = 0; i < len; i++) { + parity = 0; + for (j = 0; j < vects; j++) + parity ^= src[j][i]; - if (parity != 0) { - fail = 1; - break; - } - } - if (fail && len > 0) - return len; - return fail; + if (parity != 0) { + fail = 1; + break; + } + } + if (fail && len > 0) + return len; + return fail; } diff --git a/raid/raid_base_aliases.c b/raid/raid_base_aliases.c index f81792a..d654f47 100644 --- a/raid/raid_base_aliases.c +++ b/raid/raid_base_aliases.c @@ -29,22 +29,26 @@ #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); } diff --git a/raid/xor_check_test.c b/raid/xor_check_test.c index 76c29e8..f370789 100644 --- a/raid/xor_check_test.c +++ b/raid/xor_check_test.c @@ -27,269 +27,266 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. **********************************************************************/ -#include -#include -#include -#include +#include +#include +#include +#include #include "raid.h" #include "test.h" #define TEST_SOURCES 16 #define TEST_LEN 1024 -#define TEST_MEM ((TEST_SOURCES + 1)*(TEST_LEN)) +#define TEST_MEM ((TEST_SOURCES + 1) * (TEST_LEN)) #ifndef TEST_SEED -# define TEST_SEED 0x1234 +#define TEST_SEED 0x1234 #endif // Generates pseudo-random data -void rand_buffer(unsigned char *buf, long buffer_size) +void +rand_buffer(unsigned char *buf, long buffer_size) { - long i; - for (i = 0; i < buffer_size; i++) - buf[i] = rand(); + long i; + for (i = 0; i < buffer_size; i++) + buf[i] = rand(); } -int main(int argc, char *argv[]) +int +main(int argc, char *argv[]) { - int i, j, k, ret, fail = 0; - void *buffs[TEST_SOURCES + 1] = { NULL }; - char c; - int serr, lerr; - char *tmp_buf[TEST_SOURCES + 1]; + int i, j, k, ret, fail = 0; + void *buffs[TEST_SOURCES + 1] = { NULL }; + char c; + int serr, lerr; + 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 - for (i = 0; i < TEST_SOURCES + 1; i++) { - void *buf; - if (posix_memalign(&buf, 16, TEST_LEN)) { - printf("alloc error: Fail"); - fail = 1; - goto exit; - } - buffs[i] = buf; - } + // Allocate the arrays + for (i = 0; i < TEST_SOURCES + 1; i++) { + void *buf; + if (posix_memalign(&buf, 16, TEST_LEN)) { + printf("alloc error: Fail"); + fail = 1; + goto exit; + } + buffs[i] = buf; + } - // Test of all zeros - for (i = 0; i < TEST_SOURCES + 1; i++) - memset(buffs[i], 0, TEST_LEN); + // Test of all zeros + for (i = 0; i < TEST_SOURCES + 1; i++) + memset(buffs[i], 0, TEST_LEN); - xor_gen_base(TEST_SOURCES + 1, TEST_LEN, buffs); - ret = xor_check(TEST_SOURCES + 1, TEST_LEN, buffs); - if (ret != 0) { - fail++; - printf("\nfail zero test %d\n", ret); - } + xor_gen_base(TEST_SOURCES + 1, TEST_LEN, buffs); + ret = xor_check(TEST_SOURCES + 1, TEST_LEN, buffs); + if (ret != 0) { + fail++; + printf("\nfail zero test %d\n", ret); + } - ((char *)(buffs[0]))[TEST_LEN - 2] = 0x7; // corrupt buffer - ret = xor_check(TEST_SOURCES + 1, TEST_LEN, buffs); - if (ret == 0) { - fail++; - printf("\nfail corrupt buffer test %d\n", ret); - } - ((char *)(buffs[0]))[TEST_LEN - 2] = 0; // un-corrupt buffer + ((char *) (buffs[0]))[TEST_LEN - 2] = 0x7; // corrupt buffer + ret = xor_check(TEST_SOURCES + 1, TEST_LEN, buffs); + if (ret == 0) { + fail++; + printf("\nfail corrupt buffer test %d\n", ret); + } + ((char *) (buffs[0]))[TEST_LEN - 2] = 0; // un-corrupt buffer - // Test corrupted buffer any location on all sources - for (j = 0; j < TEST_SOURCES + 1; j++) { - for (i = TEST_LEN - 1; i >= 0; i--) { - ((char *)buffs[j])[i] = 0x5; // corrupt buffer - ret = xor_check(TEST_SOURCES + 1, TEST_LEN, buffs); - if (ret == 0) { - fail++; - printf("\nfail corrupt buffer test j=%d, i=%d\n", j, i); - goto exit; - } - ((char *)buffs[j])[i] = 0; // un-corrupt buffer - } + // Test corrupted buffer any location on all sources + for (j = 0; j < TEST_SOURCES + 1; j++) { + for (i = TEST_LEN - 1; i >= 0; i--) { + ((char *) buffs[j])[i] = 0x5; // corrupt buffer + ret = xor_check(TEST_SOURCES + 1, TEST_LEN, buffs); + if (ret == 0) { + fail++; + printf("\nfail corrupt buffer test j=%d, i=%d\n", j, i); + goto exit; + } + ((char *) buffs[j])[i] = 0; // un-corrupt buffer + } #ifdef TEST_VERBOSE - putchar('.'); + putchar('.'); #endif - } + } - // Test rand1 - for (i = 0; i < TEST_SOURCES + 1; i++) - rand_buffer(buffs[i], TEST_LEN); + // Test rand1 + for (i = 0; i < TEST_SOURCES + 1; i++) + rand_buffer(buffs[i], TEST_LEN); - xor_gen_base(TEST_SOURCES + 1, TEST_LEN, buffs); - ret = xor_check(TEST_SOURCES + 1, TEST_LEN, buffs); - if (ret != 0) { - fail++; - printf("fail first rand test %d\n", ret); - } + xor_gen_base(TEST_SOURCES + 1, TEST_LEN, buffs); + ret = xor_check(TEST_SOURCES + 1, TEST_LEN, buffs); + if (ret != 0) { + fail++; + printf("fail first rand test %d\n", ret); + } - c = ((char *)(buffs[0]))[TEST_LEN - 2]; - ((char *)(buffs[0]))[TEST_LEN - 2] = c ^ 0x1; - ret = xor_check(TEST_SOURCES + 1, TEST_LEN, buffs); - if (ret == 0) { - fail++; - printf("\nFail corrupt buffer test, passed when should have failed\n"); - } - ((char *)(buffs[0]))[TEST_LEN - 2] = c; // un-corrupt buffer + c = ((char *) (buffs[0]))[TEST_LEN - 2]; + ((char *) (buffs[0]))[TEST_LEN - 2] = c ^ 0x1; + ret = xor_check(TEST_SOURCES + 1, TEST_LEN, buffs); + if (ret == 0) { + fail++; + printf("\nFail corrupt buffer test, passed when should have failed\n"); + } + ((char *) (buffs[0]))[TEST_LEN - 2] = c; // un-corrupt buffer - // Test corrupted buffer any location on all sources w/ random data - for (j = 0; j < TEST_SOURCES + 1; j++) { - for (i = TEST_LEN - 1; i >= 0; i--) { - // Check it still passes - ret = xor_check(TEST_SOURCES + 1, TEST_LEN, buffs); - if (ret != 0) { // should pass - fail++; - printf - ("\nFail rand test with un-corrupted buffer j=%d, i=%d\n", - j, i); - goto exit; - } - c = ((char *)buffs[j])[i]; - ((char *)buffs[j])[i] = c ^ 1; // corrupt buffer - ret = xor_check(TEST_SOURCES + 1, TEST_LEN, buffs); - if (ret == 0) { // Check it now fails - fail++; - printf("\nfail corrupt buffer test j=%d, i=%d\n", j, i); - goto exit; - } - ((char *)buffs[j])[i] = c; // un-corrupt buffer - } + // Test corrupted buffer any location on all sources w/ random data + for (j = 0; j < TEST_SOURCES + 1; j++) { + for (i = TEST_LEN - 1; i >= 0; i--) { + // Check it still passes + ret = xor_check(TEST_SOURCES + 1, TEST_LEN, buffs); + if (ret != 0) { // should pass + fail++; + printf("\nFail rand test with un-corrupted buffer j=%d, i=%d\n", j, + i); + goto exit; + } + c = ((char *) buffs[j])[i]; + ((char *) buffs[j])[i] = c ^ 1; // corrupt buffer + ret = xor_check(TEST_SOURCES + 1, TEST_LEN, buffs); + if (ret == 0) { // Check it now fails + fail++; + printf("\nfail corrupt buffer test j=%d, i=%d\n", j, i); + goto exit; + } + ((char *) buffs[j])[i] = c; // un-corrupt buffer + } #ifdef TEST_VERBOSE - putchar('.'); + putchar('.'); #endif - } + } - // Test various number of sources, full length - for (j = 3; j <= TEST_SOURCES + 1; j++) { - // New random data - for (i = 0; i < j; i++) - rand_buffer(buffs[i], TEST_LEN); + // Test various number of sources, full length + for (j = 3; j <= TEST_SOURCES + 1; j++) { + // New random data + for (i = 0; i < j; i++) + rand_buffer(buffs[i], TEST_LEN); - // Generate xor parity for this number of sources - xor_gen_base(j, TEST_LEN, buffs); + // Generate xor parity for this number of sources + xor_gen_base(j, TEST_LEN, buffs); - // Set errors up in each source and len position - for (i = 0; i < j; i++) { - for (k = 0; k < TEST_LEN; k++) { - // See if it still passes - ret = xor_check(j, TEST_LEN, buffs); - if (ret != 0) { // Should pass - printf("\nfail rand test %d sources\n", j); - fail++; - goto exit; - } + // Set errors up in each source and len position + for (i = 0; i < j; i++) { + for (k = 0; k < TEST_LEN; k++) { + // See if it still passes + ret = xor_check(j, TEST_LEN, buffs); + if (ret != 0) { // Should pass + printf("\nfail rand test %d sources\n", j); + fail++; + goto exit; + } - c = ((char *)buffs[i])[k]; - ((char *)buffs[i])[k] = c ^ 1; // corrupt buffer + c = ((char *) buffs[i])[k]; + ((char *) buffs[i])[k] = c ^ 1; // corrupt buffer - ret = xor_check(j, TEST_LEN, buffs); - if (ret == 0) { // Should fail - printf - ("\nfail rand test corrupted buffer %d sources\n", - j); - fail++; - goto exit; - } - ((char *)buffs[i])[k] = c; // un-corrupt buffer - } - } + ret = xor_check(j, TEST_LEN, buffs); + if (ret == 0) { // Should fail + printf("\nfail rand test corrupted buffer %d sources\n", j); + fail++; + goto exit; + } + ((char *) buffs[i])[k] = c; // un-corrupt buffer + } + } #ifdef TEST_VERBOSE - putchar('.'); + putchar('.'); #endif - } + } - fflush(0); + fflush(0); - // Test various number of sources and len - k = 1; - while (k <= TEST_LEN) { - for (j = 3; j <= TEST_SOURCES + 1; j++) { - for (i = 0; i < j; i++) - rand_buffer(buffs[i], k); + // Test various number of sources and len + k = 1; + while (k <= TEST_LEN) { + for (j = 3; j <= TEST_SOURCES + 1; j++) { + for (i = 0; i < j; i++) + rand_buffer(buffs[i], k); - // Generate xor parity for this number of sources - xor_gen_base(j, k, buffs); + // Generate xor parity for this number of sources + xor_gen_base(j, k, buffs); - // Inject errors at various source and len positions - for (lerr = 0; lerr < k; lerr += 10) { - for (serr = 0; serr < j; serr++) { + // Inject errors at various source and len positions + for (lerr = 0; lerr < k; lerr += 10) { + for (serr = 0; serr < j; serr++) { - // See if it still passes - ret = xor_check(j, k, buffs); - if (ret != 0) { // Should pass - printf("\nfail rand test %d sources\n", j); - fail++; - goto exit; - } + // See if it still passes + ret = xor_check(j, k, buffs); + if (ret != 0) { // Should pass + printf("\nfail rand test %d sources\n", j); + fail++; + goto exit; + } - c = ((char *)buffs[serr])[lerr]; - ((char *)buffs[serr])[lerr] = c ^ 1; // corrupt buffer + c = ((char *) buffs[serr])[lerr]; + ((char *) buffs[serr])[lerr] = c ^ 1; // corrupt buffer - ret = xor_check(j, k, buffs); - if (ret == 0) { // Should fail - printf("\nfail rand test corrupted buffer " - "%d sources, len=%d, ret=%d\n", j, k, - ret); - fail++; - goto exit; - } - ((char *)buffs[serr])[lerr] = c; // un-corrupt buffer - } - } - } + ret = xor_check(j, k, buffs); + if (ret == 0) { // Should fail + printf("\nfail rand test corrupted buffer " + "%d sources, len=%d, ret=%d\n", + j, k, ret); + fail++; + goto exit; + } + ((char *) buffs[serr])[lerr] = c; // un-corrupt buffer + } + } + } #ifdef TEST_VERBOSE - putchar('.'); + putchar('.'); #endif - fflush(0); - k += 1; - } + fflush(0); + k += 1; + } - // Test at the end of buffer - for (i = 0; i < TEST_LEN; i += 32) { - for (j = 0; j < TEST_SOURCES + 1; j++) { - rand_buffer(buffs[j], TEST_LEN - i); - tmp_buf[j] = (char *)buffs[j] + i; - } + // Test at the end of buffer + for (i = 0; i < TEST_LEN; i += 32) { + for (j = 0; j < TEST_SOURCES + 1; j++) { + rand_buffer(buffs[j], TEST_LEN - 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 - ret = xor_check(TEST_SOURCES + 1, TEST_LEN - i, (void *)tmp_buf); - if (ret != 0) { - printf("fail end test - offset: %d, len: %d\n", i, TEST_LEN - i); - fail++; - goto exit; - } - // Test bad data - for (serr = 0; serr < TEST_SOURCES + 1; serr++) { - for (lerr = 0; lerr < (TEST_LEN - i); lerr++) { - c = tmp_buf[serr][lerr]; - tmp_buf[serr][lerr] = c ^ 1; + // Test good data + ret = xor_check(TEST_SOURCES + 1, TEST_LEN - i, (void *) tmp_buf); + if (ret != 0) { + printf("fail end test - offset: %d, len: %d\n", i, TEST_LEN - i); + fail++; + goto exit; + } + // Test bad data + for (serr = 0; serr < TEST_SOURCES + 1; serr++) { + for (lerr = 0; lerr < (TEST_LEN - i); lerr++) { + c = tmp_buf[serr][lerr]; + tmp_buf[serr][lerr] = c ^ 1; - ret = - xor_check(TEST_SOURCES + 1, TEST_LEN - i, (void *)tmp_buf); - if (ret == 0) { - printf("fail end test corrupted buffer - " - "offset: %d, len: %d, ret: %d\n", i, - TEST_LEN - i, ret); - fail++; - goto exit; - } + ret = xor_check(TEST_SOURCES + 1, TEST_LEN - i, (void *) tmp_buf); + if (ret == 0) { + printf("fail end test corrupted buffer - " + "offset: %d, len: %d, ret: %d\n", + i, TEST_LEN - i, ret); + fail++; + goto exit; + } - tmp_buf[serr][lerr] = c; - } - } + tmp_buf[serr][lerr] = c; + } + } #ifdef TEST_VERBOSE - putchar('.'); + putchar('.'); #endif - fflush(0); - } + fflush(0); + } - if (fail == 0) - printf("Pass\n"); + if (fail == 0) + printf("Pass\n"); - exit: - for (i = 0; i < TEST_SOURCES + 1; i++) - aligned_free(buffs[i]); - - return fail; +exit: + for (i = 0; i < TEST_SOURCES + 1; i++) + aligned_free(buffs[i]); + return fail; } diff --git a/raid/xor_example.c b/raid/xor_example.c index 60dda16..21742e3 100644 --- a/raid/xor_example.c +++ b/raid/xor_example.c @@ -32,49 +32,50 @@ #include "test.h" #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; - void *buffs[TEST_SOURCES + 1] = { NULL }; + int i, j, should_pass, should_fail, ret = 0; + void *buffs[TEST_SOURCES + 1] = { NULL }; - printf("XOR example\n"); - for (i = 0; i < TEST_SOURCES + 1; i++) { - void *buf; - if (posix_memalign(&buf, 32, TEST_LEN)) { - printf("alloc error: Fail"); - goto exit; - } - buffs[i] = buf; - } + printf("XOR example\n"); + for (i = 0; i < TEST_SOURCES + 1; i++) { + void *buf; + if (posix_memalign(&buf, 32, TEST_LEN)) { + printf("alloc error: Fail"); + goto exit; + } + buffs[i] = buf; + } - printf("Make random data\n"); - for (i = 0; i < TEST_SOURCES + 1; i++) - for (j = 0; j < TEST_LEN; j++) - ((char *)buffs[i])[j] = rand(); + printf("Make random data\n"); + for (i = 0; i < TEST_SOURCES + 1; i++) + for (j = 0; j < TEST_LEN; j++) + ((char *) buffs[i])[j] = rand(); - printf("Generate xor parity\n"); - xor_gen(TEST_SOURCES + 1, TEST_LEN, buffs); + printf("Generate xor parity\n"); + xor_gen(TEST_SOURCES + 1, TEST_LEN, buffs); - printf("Check parity: "); - should_pass = xor_check(TEST_SOURCES + 1, TEST_LEN, buffs); - printf("%s\n", should_pass == 0 ? "Pass" : "Fail"); - if (should_pass != 0) { - ret = -1; - goto exit; - } + printf("Check parity: "); + should_pass = xor_check(TEST_SOURCES + 1, TEST_LEN, buffs); + printf("%s\n", should_pass == 0 ? "Pass" : "Fail"); + if (should_pass != 0) { + ret = -1; + goto exit; + } - printf("Find corruption: "); - ((char *)buffs[TEST_SOURCES / 2])[TEST_LEN / 2] ^= 1; // flip one bit - should_fail = xor_check(TEST_SOURCES + 1, TEST_LEN, buffs); //recheck - printf("%s\n", should_fail != 0 ? "Pass" : "Fail"); + printf("Find corruption: "); + ((char *) buffs[TEST_SOURCES / 2])[TEST_LEN / 2] ^= 1; // flip one bit + should_fail = xor_check(TEST_SOURCES + 1, TEST_LEN, buffs); // recheck + printf("%s\n", should_fail != 0 ? "Pass" : "Fail"); - if (should_fail == 0) - ret = -1; - exit: - for (i = 0; i < TEST_SOURCES + 1; i++) - free(buffs[i]); + if (should_fail == 0) + ret = -1; +exit: + for (i = 0; i < TEST_SOURCES + 1; i++) + free(buffs[i]); - return ret; + return ret; } diff --git a/raid/xor_gen_perf.c b/raid/xor_gen_perf.c index b35ec72..886d732 100644 --- a/raid/xor_gen_perf.c +++ b/raid/xor_gen_perf.c @@ -27,65 +27,66 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. **********************************************************************/ -#include -#include -#include -#include +#include +#include +#include +#include #include "raid.h" #include "test.h" #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 #if !defined(COLD_TEST) && !defined(TEST_CUSTOM) // Cached test, loop many times over small dataset -# define TEST_SOURCES 10 -# define TEST_LEN 8*1024 -# define TEST_TYPE_STR "_warm" -#elif defined (COLD_TEST) +#define TEST_SOURCES 10 +#define TEST_LEN 8 * 1024 +#define TEST_TYPE_STR "_warm" +#elif defined(COLD_TEST) // Uncached test. Pull from large mem base. -# define TEST_SOURCES 10 -# define TEST_LEN GT_L3_CACHE / TEST_SOURCES -# define TEST_TYPE_STR "_cold" +#define TEST_SOURCES 10 +#define TEST_LEN GT_L3_CACHE / TEST_SOURCES +#define TEST_TYPE_STR "_cold" #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; - void **buffs; - void *buff; - struct perf start; + int i, ret, fail = 0; + void **buffs; + void *buff; + 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)); - if (ret) { - printf("alloc error: Fail"); - return 1; - } - buffs = buff; + ret = posix_memalign((void **) &buff, 8, sizeof(int *) * (TEST_SOURCES + 6)); + if (ret) { + printf("alloc error: Fail"); + return 1; + } + buffs = buff; - // Allocate the arrays - for (i = 0; i < TEST_SOURCES + 1; i++) { - void *buf; - ret = posix_memalign(&buf, 64, TEST_LEN); - if (ret) { - printf("alloc error: Fail"); - return 1; - } - buffs[i] = buf; - } + // Allocate the arrays + for (i = 0; i < TEST_SOURCES + 1; i++) { + void *buf; + ret = posix_memalign(&buf, 64, TEST_LEN); + if (ret) { + printf("alloc error: Fail"); + return 1; + } + buffs[i] = buf; + } - // Setup data - for (i = 0; i < TEST_SOURCES + 1; i++) - memset(buffs[i], 0, TEST_LEN); + // Setup data + for (i = 0; i < TEST_SOURCES + 1; i++) + memset(buffs[i], 0, TEST_LEN); - BENCHMARK(&start, BENCHMARK_TIME, xor_gen(TEST_SOURCES + 1, TEST_LEN, buffs)); - printf("xor_gen" TEST_TYPE_STR ": "); - perf_print(start, (long long)TEST_MEM); + BENCHMARK(&start, BENCHMARK_TIME, xor_gen(TEST_SOURCES + 1, TEST_LEN, buffs)); + printf("xor_gen" TEST_TYPE_STR ": "); + perf_print(start, (long long) TEST_MEM); - return fail; + return fail; } diff --git a/raid/xor_gen_test.c b/raid/xor_gen_test.c index ed6853b..9005166 100644 --- a/raid/xor_gen_test.c +++ b/raid/xor_gen_test.c @@ -27,153 +27,154 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. **********************************************************************/ -#include -#include -#include -#include +#include +#include +#include +#include #include "raid.h" #include "test.h" #define TEST_SOURCES 16 #define TEST_LEN 1024 -#define TEST_MEM ((TEST_SOURCES + 1)*(TEST_LEN)) +#define TEST_MEM ((TEST_SOURCES + 1) * (TEST_LEN)) #ifndef TEST_SEED -# define TEST_SEED 0x1234 +#define TEST_SEED 0x1234 #endif // Generates pseudo-random data -void rand_buffer(unsigned char *buf, long buffer_size) +void +rand_buffer(unsigned char *buf, long buffer_size) { - long i; - for (i = 0; i < buffer_size; i++) - buf[i] = rand(); + long i; + for (i = 0; i < buffer_size; i++) + buf[i] = rand(); } -int main(int argc, char *argv[]) +int +main(int argc, char *argv[]) { - int i, j, k, ret, fail = 0; - void *buffs[TEST_SOURCES + 1] = { NULL }; - char *tmp_buf[TEST_SOURCES + 1] = { NULL }; + int i, j, k, ret, fail = 0; + void *buffs[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 - for (i = 0; i < TEST_SOURCES + 1; i++) { - void *buf; - ret = posix_memalign(&buf, 32, TEST_LEN); - if (ret) { - printf("alloc error: Fail"); - fail = 1; - goto exit; - } - buffs[i] = buf; - } + // Allocate the arrays + for (i = 0; i < TEST_SOURCES + 1; i++) { + void *buf; + ret = posix_memalign(&buf, 32, TEST_LEN); + if (ret) { + printf("alloc error: Fail"); + fail = 1; + goto exit; + } + buffs[i] = buf; + } - // Test of all zeros - for (i = 0; i < TEST_SOURCES + 1; i++) - memset(buffs[i], 0, TEST_LEN); + // Test of all zeros + for (i = 0; i < TEST_SOURCES + 1; i++) + 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++) { - if (((char *)buffs[TEST_SOURCES])[i] != 0) - fail++; - } + for (i = 0; i < TEST_LEN; i++) { + if (((char *) buffs[TEST_SOURCES])[i] != 0) + fail++; + } - if (fail > 0) { - printf("fail zero test"); - goto exit; - } + if (fail > 0) { + printf("fail zero test"); + goto exit; + } #ifdef TEST_VERBOSE - putchar('.'); + putchar('.'); #endif - // Test rand1 - for (i = 0; i < TEST_SOURCES + 1; i++) - rand_buffer(buffs[i], TEST_LEN); + // Test rand1 + for (i = 0; i < TEST_SOURCES + 1; i++) + 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) { - printf("fail rand test %d\n", fail); - goto exit; - } + if (fail > 0) { + printf("fail rand test %d\n", fail); + goto exit; + } #ifdef TEST_VERBOSE - putchar('.'); + putchar('.'); #endif - // Test various number of sources - for (j = 3; j <= TEST_SOURCES + 1; j++) { - for (i = 0; i < j; i++) - rand_buffer(buffs[i], TEST_LEN); + // Test various number of sources + for (j = 3; j <= TEST_SOURCES + 1; j++) { + for (i = 0; i < j; i++) + rand_buffer(buffs[i], TEST_LEN); - xor_gen(j, TEST_LEN, buffs); - fail |= xor_check_base(j, TEST_LEN, buffs); + xor_gen(j, TEST_LEN, buffs); + fail |= xor_check_base(j, TEST_LEN, buffs); - if (fail > 0) { - printf("fail rand test %d sources\n", j); - goto exit; - } + if (fail > 0) { + printf("fail rand test %d sources\n", j); + goto exit; + } #ifdef TEST_VERBOSE - putchar('.'); + putchar('.'); #endif - } + } - fflush(0); + fflush(0); - // Test various number of sources and len - k = 0; - while (k <= TEST_LEN) { - for (j = 3; j <= TEST_SOURCES + 1; j++) { - for (i = 0; i < j; i++) - rand_buffer(buffs[i], k); + // Test various number of sources and len + k = 0; + while (k <= TEST_LEN) { + for (j = 3; j <= TEST_SOURCES + 1; j++) { + for (i = 0; i < j; i++) + rand_buffer(buffs[i], k); - xor_gen(j, k, buffs); - fail |= xor_check_base(j, k, buffs); + xor_gen(j, k, buffs); + fail |= xor_check_base(j, k, buffs); - if (fail > 0) { - printf("fail rand test %d sources, len=%d, ret=%d\n", j, k, - fail); - goto exit; - } - } + if (fail > 0) { + printf("fail rand test %d sources, len=%d, ret=%d\n", j, k, fail); + goto exit; + } + } #ifdef TEST_VERBOSE - putchar('.'); + putchar('.'); #endif - k += 1; - } + k += 1; + } - // Test at the end of buffer - for (i = 0; i < TEST_LEN; i += 32) { - for (j = 0; j < TEST_SOURCES + 1; j++) { - rand_buffer((unsigned char *)buffs[j] + i, TEST_LEN - i); - tmp_buf[j] = (char *)buffs[j] + i; - } + // Test at the end of buffer + for (i = 0; i < TEST_LEN; i += 32) { + for (j = 0; j < TEST_SOURCES + 1; j++) { + rand_buffer((unsigned char *) buffs[j] + i, TEST_LEN - i); + tmp_buf[j] = (char *) buffs[j] + i; + } - xor_gen(TEST_SOURCES + 1, TEST_LEN - i, (void *)tmp_buf); - fail |= xor_check_base(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); - if (fail > 0) { - printf("fail end test - offset: %d, len: %d\n", i, TEST_LEN - i); - goto exit; - } + if (fail > 0) { + printf("fail end test - offset: %d, len: %d\n", i, TEST_LEN - i); + goto exit; + } #ifdef TEST_VERBOSE - putchar('.'); + putchar('.'); #endif - fflush(0); - } + fflush(0); + } - if (!fail) - printf(" done: Pass\n"); + if (!fail) + printf(" done: Pass\n"); - exit: - for (i = 0; i < TEST_SOURCES + 1; i++) - aligned_free(buffs[i]); +exit: + for (i = 0; i < TEST_SOURCES + 1; i++) + aligned_free(buffs[i]); - return fail; + return fail; }