int main(int argc, char *argv[]) { int i, j, rtest, m, k, nerrs, r; void *buf; u8 *temp_buffs[TEST_SOURCES], *buffs[TEST_SOURCES]; u8 a[MMAX * KMAX], b[MMAX * KMAX], c[MMAX * KMAX], d[MMAX * KMAX]; u8 g_tbls[KMAX * TEST_SOURCES * 32], src_in_err[TEST_SOURCES]; u8 src_err_list[TEST_SOURCES], *recov[TEST_SOURCES]; struct perf start, stop; // Pick test parameters m = 14; k = 10; nerrs = 4; const u8 err_list[] = {2, 4, 5, 7}; printf("erasure_code_base_perf: %dx%d %d\n", m, TEST_LEN(m), nerrs); if (m > MMAX || k > KMAX || nerrs > (m - k)){ printf(" Input test parameter error\n"); return -1; } memcpy(src_err_list, err_list, nerrs); memset(src_in_err, 0, TEST_SOURCES); for (i = 0; i < nerrs; i++) src_in_err[src_err_list[i]] = 1; // Allocate the arrays for (i = 0; i < m; i++) { if (posix_memalign(&buf, 64, TEST_LEN(m))) { printf("alloc error: Fail\n"); return -1; } buffs[i] = buf; } for (i = 0; i < (m - k); i++) { if (posix_memalign(&buf, 64, TEST_LEN(m))) { printf("alloc error: Fail\n"); return -1; } temp_buffs[i] = buf; } // Make random data for (i = 0; i < k; i++) for (j = 0; j < TEST_LEN(m); j++) buffs[i][j] = rand(); gf_gen_rs_matrix(a, m, k); ec_init_tables(k, m - k, &a[k * k], g_tbls); ec_encode_data_base(TEST_LEN(m), k, m - k, g_tbls, buffs, &buffs[k]); // Start encode test perf_start(&start); for (rtest = 0; rtest < TEST_LOOPS(m); rtest++) { // Make parity vects ec_init_tables(k, m - k, &a[k * k], g_tbls); ec_encode_data_base(TEST_LEN(m), k, m - k, g_tbls, buffs, &buffs[k]); } perf_stop(&stop); printf("erasure_code_base_encode" TEST_TYPE_STR ": "); perf_print(stop, start, (long long)(TEST_LEN(m)) * (m) * rtest); // Start decode test perf_start(&start); for (rtest = 0; rtest < TEST_LOOPS(m); rtest++) { // Construct b by removing error rows for (i = 0, r = 0; i < k; i++, r++) { while (src_in_err[r]) r++; recov[i] = buffs[r]; for (j = 0; j < k; j++) b[k * i + j] = a[k * r + j]; } if (gf_invert_matrix(b, d, k) < 0) { printf("BAD MATRIX\n"); return -1; } for (i = 0; i < nerrs; i++) for (j = 0; j < k; j++) c[k * i + j] = d[k * src_err_list[i] + j]; // Recover data ec_init_tables(k, nerrs, c, g_tbls); ec_encode_data_base(TEST_LEN(m), k, nerrs, g_tbls, recov, temp_buffs); } perf_stop(&stop); for (i = 0; i < nerrs; i++) { if (0 != memcmp(temp_buffs[i], buffs[src_err_list[i]], TEST_LEN(m))) { printf("Fail error recovery (%d, %d, %d) - ", m, k, nerrs); return -1; } } printf("erasure_code_base_decode" TEST_TYPE_STR ": "); perf_print(stop, start, (long long)(TEST_LEN(m)) * (k + nerrs) * rtest); printf("done all: Pass\n"); return 0; }
int main(int argc, char *argv[]) { int i, j, rtest, m, k, nerrs, r, err; void *buf; u8 *temp_buffs[TEST_SOURCES], *buffs[TEST_SOURCES]; u8 a[MMAX*KMAX], b[MMAX*KMAX], c[MMAX*KMAX], d[MMAX*KMAX]; u8 g_tbls[KMAX*TEST_SOURCES*32], src_in_err[TEST_SOURCES]; u8 src_err_list[TEST_SOURCES], *recov[TEST_SOURCES]; struct perf start, stop; m = 32; k = 28; printf("erasure_code_sse_perf: %dx%d ", m, (TEST_LEN(m))); // Allocate the arrays for(i=0; i<TEST_SOURCES; i++) { if (posix_memalign(&buf, 64, TEST_LEN(m))) { printf("alloc error: Fail"); return -1; } buffs[i] = buf; } for (i=0; i<TEST_SOURCES; i++) { if (posix_memalign(&buf, 64, TEST_LEN(m))) { printf("alloc error: Fail"); return -1; } temp_buffs[i] = buf; } // Test erasure code by encode and recovery // Pick a first test if (m > MMAX || k > KMAX) return -1; // Make random data for(i=0; i<k; i++) for(j=0; j<(TEST_LEN(m)); j++) buffs[i][j] = rand(); memset(src_in_err, 0, TEST_SOURCES); srand(1); for (i=0, nerrs=0; i<k && nerrs<m-k; i++) { err = 1 & rand(); src_in_err[i] = err; if (err) src_err_list[nerrs++] = i; } if (nerrs == 0) { // should have at least one error while ((err = (rand() % KMAX)) >= k) ; src_err_list[nerrs++] = err; src_in_err[err] = 1; } printf("Test erase list = "); for (i=0; i<nerrs; i++) printf(" %d", src_err_list[i]); printf("\n"); perf_start(&start); for (rtest = 0; rtest < TEST_LOOPS(m); rtest++) { gf_gen_rs_matrix(a, m, k); // Make parity vects ec_init_tables(k, m-k, &a[k*k], g_tbls); ec_encode_data_sse((TEST_LEN(m)), k, m-k, g_tbls, buffs, &buffs[k]); } perf_stop(&stop); printf("erasure_code_sse_encode" TEST_TYPE_STR ": "); perf_print(stop,start, (long long)(TEST_LEN(m))*(m)*rtest); perf_start(&start); for (rtest = 0; rtest < TEST_LOOPS(m); rtest++) { // Construct b by removing error rows for(i=0, r=0; i<k; i++, r++) { while (src_in_err[r]) r++; for(j=0; j<k; j++) b[k*i+j] = a[k*r+j]; } if (gf_invert_matrix(b, d, k) < 0) { printf("BAD MATRIX\n"); return -1; } for(i=0, r=0; i<k; i++, r++) { while (src_in_err[r]) r++; recov[i] = buffs[r]; } for(i=0; i<nerrs; i++) { for(j=0; j<k; j++) { c[k*i+j]=d[k*src_err_list[i]+j]; } } // Recover data ec_init_tables(k, nerrs, c, g_tbls); ec_encode_data_sse((TEST_LEN(m)), k, nerrs, g_tbls, recov, &temp_buffs[k]); } perf_stop(&stop); for(i=0; i<nerrs; i++) { if (0 != memcmp(temp_buffs[k+i], buffs[src_err_list[i]], (TEST_LEN(m)))) { printf("Fail error recovery (%d, %d, %d) - ", m, k, nerrs); printf(" - erase list = "); for (j=0; j<nerrs; j++) printf(" %d", src_err_list[j]); printf("\na:\n"); dump_u8xu8((u8*)a, m, k); printf("inv b:\n"); dump_u8xu8((u8*)d, k, k); printf("orig data:\n"); dump_matrix(buffs, m, 25); printf("orig :"); dump(buffs[src_err_list[i]],25); printf("recov %d:",src_err_list[i]); dump(temp_buffs[k+i], 25); return -1; } } printf("erasure_code_sse_decode" TEST_TYPE_STR ": "); perf_print(stop,start, (long long)(TEST_LEN(m))*(k+nerrs)*rtest); printf("done all: Pass\n"); return 0; }