Commit 8d673c08fc66f4ac61c9a29c9ad992d943a33b34

Authored by KMG
1 parent 5eb73fa7
Exists in master and in 1 other branch v2

Re-org and re-named some stuff...

Examples/makefile
... ... @@ -61,6 +61,8 @@ ALL = jerasure_01 \
61 61 reed_sol_02 \
62 62 reed_sol_03 \
63 63 reed_sol_04 \
  64 + reed_sol_test_gf \
  65 + reed_sol_time_gf \
64 66 cauchy_01 \
65 67 cauchy_02 \
66 68 cauchy_03 \
... ... @@ -186,3 +188,11 @@ encoder: encoder.o galois.o jerasure.o liberation.o reed_sol.o cauchy.o
186 188 decoder.o: galois.h liberation.h jerasure.h reed_sol.h cauchy.h
187 189 decoder: decoder.o galois.o jerasure.o liberation.o reed_sol.o cauchy.o
188 190 $(CC) $(CFLAGS) -o decoder decoder.o liberation.o jerasure.o galois.o reed_sol.o cauchy.o -lgf_complete
  191 +
  192 +reed_sol_test_gf.o: galois.h reed_sol.h jerasure.h
  193 +reed_sol_test_gf: reed_sol_test_gf.o galois.o ${LIBDIR}/gf_complete.a jerasure.o reed_sol.o
  194 + $(CC) $(CFLAGS) -o reed_sol_test_gf reed_sol_test_gf.o reed_sol.o jerasure.o galois.o ${LIBDIR}/gf_complete.a
  195 +
  196 +reed_sol_time_gf.o: galois.h reed_sol.h jerasure.h
  197 +reed_sol_time_gf: reed_sol_time_gf.o galois.o ${LIBDIR}/gf_complete.a jerasure.o reed_sol.o
  198 + $(CC) $(CFLAGS) -o reed_sol_time_gf reed_sol_time_gf.o reed_sol.o jerasure.o galois.o ${LIBDIR}/gf_complete.a
... ...
Examples/reed_sol_test_gf.c 0 → 100644
... ... @@ -0,0 +1,188 @@
  1 +/* Examples/reed_sol_01.c
  2 +Jerasure - A C/C++ Library for a Variety of Reed-Solomon and RAID-6 Erasure Coding Techniques
  3 +
  4 +Revision 1.2A
  5 +May 24, 2011
  6 +
  7 +James S. Plank
  8 +Department of Electrical Engineering and Computer Science
  9 +University of Tennessee
  10 +Knoxville, TN 37996
  11 +plank@cs.utk.edu
  12 +
  13 +Copyright (c) 2011, James S. Plank
  14 +All rights reserved.
  15 +
  16 +Redistribution and use in source and binary forms, with or without
  17 +modification, are permitted provided that the following conditions
  18 +are met:
  19 +
  20 + - Redistributions of source code must retain the above copyright
  21 + notice, this list of conditions and the following disclaimer.
  22 +
  23 + - Redistributions in binary form must reproduce the above copyright
  24 + notice, this list of conditions and the following disclaimer in
  25 + the documentation and/or other materials provided with the
  26 + distribution.
  27 +
  28 + - Neither the name of the University of Tennessee nor the names of its
  29 + contributors may be used to endorse or promote products derived
  30 + from this software without specific prior written permission.
  31 +
  32 +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  33 +"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  34 +LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  35 +A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  36 +HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  37 +INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
  38 +BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
  39 +OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
  40 +AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  41 +LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY
  42 +WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  43 +POSSIBILITY OF SUCH DAMAGE.
  44 +
  45 +
  46 + */
  47 +
  48 +#include <stdio.h>
  49 +#include <stdlib.h>
  50 +#include <string.h>
  51 +#include <gf_complete.h>
  52 +#include "jerasure.h"
  53 +#include "reed_sol.h"
  54 +
  55 +#define BUFSIZE 4096
  56 +
  57 +static void *malloc16(int size) {
  58 + void *mem = malloc(size+16+sizeof(void*));
  59 + void **ptr = (void**)((long)(mem+16+sizeof(void*)) & ~(15));
  60 + ptr[-1] = mem;
  61 + return ptr;
  62 +}
  63 +
  64 +static void free16(void *ptr) {
  65 + free(((void**)ptr)[-1]);
  66 +}
  67 +
  68 +#define talloc(type, num) (type *) malloc16(sizeof(type)*(num))
  69 +
  70 +usage(char *s)
  71 +{
  72 + fprintf(stderr, "usage: reed_sol_test_gf k m w [additional GF args]- Tests Reed-Solomon in GF(2^w).\n");
  73 + fprintf(stderr, " \n");
  74 + fprintf(stderr, " w must be 8, 16 or 32. k+m must be <= 2^w.\n");
  75 + fprintf(stderr, " See the README for information on the additional GF args.\n");
  76 + fprintf(stderr, " Set up a Vandermonde-based distribution matrix and encodes k devices of\n");
  77 + fprintf(stderr, " %d bytes each with it. Then it decodes.\n", BUFSIZE);
  78 + fprintf(stderr, " \n");
  79 + fprintf(stderr, "This tests: jerasure_matrix_encode()\n");
  80 + fprintf(stderr, " jerasure_matrix_decode()\n");
  81 + fprintf(stderr, " jerasure_print_matrix()\n");
  82 + fprintf(stderr, " galois_change_technique()\n");
  83 + fprintf(stderr, " reed_sol_vandermonde_coding_matrix()\n");
  84 + if (s != NULL) fprintf(stderr, "%s\n", s);
  85 + exit(1);
  86 +}
  87 +
  88 +gf_t* get_gf(int w, int argc, char **argv, int starting)
  89 +{
  90 + gf_t *gf = (gf_t*)malloc(sizeof(gf_t));
  91 + if (create_gf_from_argv(gf, w, argc, argv, starting) == 0) {
  92 + free(gf);
  93 + gf = NULL;
  94 + }
  95 + return gf;
  96 +}
  97 +
  98 +static void fill_buffer(unsigned char *buf, int size)
  99 +{
  100 + int i;
  101 +
  102 + buf[0] = (char)(lrand48() % 256);
  103 +
  104 + for (i=1; i < size; i++) {
  105 + buf[i] = ((buf[i-1] + i) % 256);
  106 + }
  107 +}
  108 +
  109 +int main(int argc, char **argv)
  110 +{
  111 + long l;
  112 + int k, w, i, j, m;
  113 + int *matrix;
  114 + char **data, **coding, **old_values;
  115 + int *erasures, *erased;
  116 + int *decoding_matrix, *dm_ids;
  117 + gf_t *gf = NULL;
  118 +
  119 + if (argc < 4) usage(NULL);
  120 + if (sscanf(argv[1], "%d", &k) == 0 || k <= 0) usage("Bad k");
  121 + if (sscanf(argv[2], "%d", &m) == 0 || m <= 0) usage("Bad m");
  122 + if (sscanf(argv[3], "%d", &w) == 0 || (w != 8 && w != 16 && w != 32)) usage("Bad w");
  123 + if (w <= 16 && k + m > (1 << w)) usage("k + m is too big");
  124 +
  125 + srand48(time(0));
  126 +
  127 + gf = get_gf(w, argc, argv, 4);
  128 +
  129 + if (gf == NULL) {
  130 + usage("Invalid arguments given for GF!\n");
  131 + }
  132 +
  133 + galois_change_technique(gf, w);
  134 +
  135 + matrix = reed_sol_vandermonde_coding_matrix(k, m, w);
  136 +
  137 + printf("Last m rows of the Distribution Matrix:\n\n");
  138 + jerasure_print_matrix(matrix, m, k, w);
  139 + printf("\n");
  140 +
  141 + data = talloc(char *, k);
  142 + for (i = 0; i < k; i++) {
  143 + data[i] = talloc(char, BUFSIZE);
  144 + fill_buffer(data[i], BUFSIZE);
  145 + }
  146 +
  147 + coding = talloc(char *, m);
  148 + old_values = talloc(char *, m);
  149 + for (i = 0; i < m; i++) {
  150 + coding[i] = talloc(char, BUFSIZE);
  151 + old_values[i] = talloc(char, BUFSIZE);
  152 + }
  153 +
  154 + jerasure_matrix_encode(k, m, w, matrix, data, coding, BUFSIZE);
  155 +
  156 + erasures = talloc(int, (m+1));
  157 + erased = talloc(int, (k+m));
  158 + for (i = 0; i < m+k; i++) erased[i] = 0;
  159 + l = 0;
  160 + for (i = 0; i < m; ) {
  161 + erasures[i] = ((unsigned int)lrand48())%(k+m);
  162 + if (erased[erasures[i]] == 0) {
  163 + erased[erasures[i]] = 1;
  164 + memcpy(old_values[i], (erasures[i] < k) ? data[erasures[i]] : coding[erasures[i]-k], BUFSIZE);
  165 + bzero((erasures[i] < k) ? data[erasures[i]] : coding[erasures[i]-k], BUFSIZE);
  166 + i++;
  167 + }
  168 + }
  169 + erasures[i] = -1;
  170 +
  171 + i = jerasure_matrix_decode(k, m, w, matrix, 1, erasures, data, coding, BUFSIZE);
  172 +
  173 + for (i = 0; i < m; i++) {
  174 + if (erasures[i] < k) {
  175 + if (memcmp(data[erasures[i]], old_values[i], BUFSIZE)) {
  176 + fprintf(stderr, "Decoding failed for %d!\n", erasures[i]);
  177 + exit(1);
  178 + }
  179 + } else {
  180 + if (memcmp(coding[erasures[i]-k], old_values[i], BUFSIZE)) {
  181 + fprintf(stderr, "Decoding failed for %d!\n", erasures[i]);
  182 + exit(1);
  183 + }
  184 + }
  185 + }
  186 +
  187 + return 0;
  188 +}
... ...
Examples/reed_sol_time_gf.c 0 → 100644
... ... @@ -0,0 +1,222 @@
  1 +/* Examples/reed_sol_01.c
  2 +Jerasure - A C/C++ Library for a Variety of Reed-Solomon and RAID-6 Erasure Coding Techniques
  3 +
  4 +Revision 1.2A
  5 +May 24, 2011
  6 +
  7 +James S. Plank
  8 +Department of Electrical Engineering and Computer Science
  9 +University of Tennessee
  10 +Knoxville, TN 37996
  11 +plank@cs.utk.edu
  12 +
  13 +Copyright (c) 2011, James S. Plank
  14 +All rights reserved.
  15 +
  16 +Redistribution and use in source and binary forms, with or without
  17 +modification, are permitted provided that the following conditions
  18 +are met:
  19 +
  20 + - Redistributions of source code must retain the above copyright
  21 + notice, this list of conditions and the following disclaimer.
  22 +
  23 + - Redistributions in binary form must reproduce the above copyright
  24 + notice, this list of conditions and the following disclaimer in
  25 + the documentation and/or other materials provided with the
  26 + distribution.
  27 +
  28 + - Neither the name of the University of Tennessee nor the names of its
  29 + contributors may be used to endorse or promote products derived
  30 + from this software without specific prior written permission.
  31 +
  32 +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  33 +"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  34 +LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  35 +A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  36 +HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  37 +INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
  38 +BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
  39 +OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
  40 +AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  41 +LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY
  42 +WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  43 +POSSIBILITY OF SUCH DAMAGE.
  44 +
  45 +
  46 + */
  47 +
  48 +
  49 +#include <stdio.h>
  50 +#include <stdlib.h>
  51 +#include <string.h>
  52 +#include <gf_complete.h>
  53 +#include "jerasure.h"
  54 +#include "reed_sol.h"
  55 +
  56 +static void *malloc16(int size) {
  57 + void *mem = malloc(size+16+sizeof(void*));
  58 + void **ptr = (void**)((long)(mem+16+sizeof(void*)) & ~(15));
  59 + ptr[-1] = mem;
  60 + return ptr;
  61 +}
  62 +
  63 +static void free16(void *ptr) {
  64 + free(((void**)ptr)[-1]);
  65 +}
  66 +
  67 +#define talloc(type, num) (type *) malloc16(sizeof(type)*(num))
  68 +
  69 +void
  70 +timer_start (double *t)
  71 +{
  72 + struct timeval tv;
  73 +
  74 + gettimeofday (&tv, NULL);
  75 + *t = (double)tv.tv_sec + (double)tv.tv_usec * 1e-6;
  76 +}
  77 +
  78 +double
  79 +timer_split (const double *t)
  80 +{
  81 + struct timeval tv;
  82 + double cur_t;
  83 +
  84 + gettimeofday (&tv, NULL);
  85 + cur_t = (double)tv.tv_sec + (double)tv.tv_usec * 1e-6;
  86 + return (cur_t - *t);
  87 +}
  88 +
  89 +usage(char *s)
  90 +{
  91 + fprintf(stderr, "usage: reed_sol_test_gf k m w [additional GF args]- Test and time Reed-Solomon in a particular GF(2^w).\n");
  92 + fprintf(stderr, " \n");
  93 + fprintf(stderr, " w must be 8, 16 or 32. k+m must be <= 2^w.\n");
  94 + fprintf(stderr, " See the README for information on the additional GF args.\n");
  95 + fprintf(stderr, " Set up a Vandermonde-based distribution matrix and encodes k devices of\n");
  96 + fprintf(stderr, " %d bytes each with it. Then it decodes.\n", BUFSIZE);
  97 + fprintf(stderr, " \n");
  98 + fprintf(stderr, "This tests: jerasure_matrix_encode()\n");
  99 + fprintf(stderr, " jerasure_matrix_decode()\n");
  100 + fprintf(stderr, " jerasure_print_matrix()\n");
  101 + fprintf(stderr, " galois_change_technique()\n");
  102 + fprintf(stderr, " reed_sol_vandermonde_coding_matrix()\n");
  103 + if (s != NULL) fprintf(stderr, "%s\n", s);
  104 + exit(1);
  105 +}
  106 +
  107 +gf_t* get_gf(int w, int argc, char **argv, int starting)
  108 +{
  109 + gf_t *gf = (gf_t*)malloc(sizeof(gf_t));
  110 + if (create_gf_from_argv(gf, w, argc, argv, starting) == 0) {
  111 + free(gf);
  112 + gf = NULL;
  113 + }
  114 + return gf;
  115 +}
  116 +
  117 +static void fill_buffer(unsigned char *buf, int size)
  118 +{
  119 + int i;
  120 +
  121 + buf[0] = (char)(lrand48() % 256);
  122 +
  123 + for (i=1; i < size; i++) {
  124 + buf[i] = ((buf[i-1] + i) % 256);
  125 + }
  126 +}
  127 +
  128 +int main(int argc, char **argv)
  129 +{
  130 + long l;
  131 + int k, w, i, j, m, iterations, bufsize;
  132 + int *matrix;
  133 + char **data, **coding, **old_values;
  134 + int *erasures, *erased;
  135 + int *decoding_matrix, *dm_ids;
  136 + double t = 0, total_time = 0;
  137 + gf_t *gf = NULL;
  138 +
  139 + if (argc < 6) usage(NULL);
  140 + if (sscanf(argv[1], "%d", &k) == 0 || k <= 0) usage("Bad k");
  141 + if (sscanf(argv[2], "%d", &m) == 0 || m <= 0) usage("Bad m");
  142 + if (sscanf(argv[3], "%d", &w) == 0 || (w != 8 && w != 16 && w != 32)) usage("Bad w");
  143 + if (sscanf(argv[4], "%d", &iterations) == 0) usage("Bad iterations");
  144 + if (sscanf(argv[5], "%d", &bufsize) == 0) usage("Bad bufsize");
  145 + if (w <= 16 && k + m > (1 << w)) usage("k + m is too big");
  146 +
  147 + srand48(time(0));
  148 +
  149 + gf = get_gf(w, argc, argv, 6);
  150 +
  151 + if (gf == NULL) {
  152 + usage("Invalid arguments given for GF!\n");
  153 + }
  154 +
  155 + galois_change_technique(gf, w);
  156 +
  157 + matrix = reed_sol_vandermonde_coding_matrix(k, m, w);
  158 +
  159 + printf("Last m rows of the Distribution Matrix:\n\n");
  160 + jerasure_print_matrix(matrix, m, k, w);
  161 + printf("\n");
  162 +
  163 + data = talloc(char *, k);
  164 + for (i = 0; i < k; i++) {
  165 + data[i] = talloc(char, bufsize);
  166 + fill_buffer(data[i], bufsize);
  167 + }
  168 +
  169 + coding = talloc(char *, m);
  170 + old_values = talloc(char *, m);
  171 + for (i = 0; i < m; i++) {
  172 + coding[i] = talloc(char, bufsize);
  173 + old_values[i] = talloc(char, bufsize);
  174 + }
  175 +
  176 + for (i = 0; i < iterations; i++) {
  177 + timer_start(&t);
  178 + jerasure_matrix_encode(k, m, w, matrix, data, coding, bufsize);
  179 + total_time += timer_split(&t);
  180 + }
  181 +
  182 + fprintf(stderr, "Encode thput for %d iterations: %.2f MB/s (%.2f sec)\n", iterations, (double)(k*iterations*bufsize/1024/1024) / total_time, total_time);
  183 +
  184 + erasures = talloc(int, (m+1));
  185 + erased = talloc(int, (k+m));
  186 + for (i = 0; i < m+k; i++) erased[i] = 0;
  187 + l = 0;
  188 + for (i = 0; i < m; ) {
  189 + erasures[i] = ((unsigned int)lrand48())%(k+m);
  190 + if (erased[erasures[i]] == 0) {
  191 + erased[erasures[i]] = 1;
  192 + memcpy(old_values[i], (erasures[i] < k) ? data[erasures[i]] : coding[erasures[i]-k], bufsize);
  193 + bzero((erasures[i] < k) ? data[erasures[i]] : coding[erasures[i]-k], bufsize);
  194 + i++;
  195 + }
  196 + }
  197 + erasures[i] = -1;
  198 +
  199 + for (i = 0; i < iterations; i++) {
  200 + timer_start(&t);
  201 + jerasure_matrix_decode(k, m, w, matrix, 1, erasures, data, coding, bufsize);
  202 + total_time += timer_split(&t);
  203 + }
  204 +
  205 + fprintf(stderr, "Decode thput for %d iterations: %.2f MB/s (%.2f sec)\n", iterations, (double)(m*iterations*bufsize/1024/1024) / total_time, total_time);
  206 +
  207 + for (i = 0; i < m; i++) {
  208 + if (erasures[i] < k) {
  209 + if (memcmp(data[erasures[i]], old_values[i], bufsize)) {
  210 + fprintf(stderr, "Decoding failed for %d!\n", erasures[i]);
  211 + exit(1);
  212 + }
  213 + } else {
  214 + if (memcmp(coding[erasures[i]-k], old_values[i], bufsize)) {
  215 + fprintf(stderr, "Decoding failed for %d!\n", erasures[i]);
  216 + exit(1);
  217 + }
  218 + }
  219 + }
  220 +
  221 + return 0;
  222 +}
... ...
Examples/test_all_gfs.sh 0 → 100755
... ... @@ -0,0 +1,55 @@
  1 +GF_COMPLETE_DIR=/usr/local/bin
  2 +GF_METHODS=${GF_COMPLETE_DIR}/gf_methods
  3 +k=12
  4 +m=3
  5 +FAIL=
  6 +
  7 +# Test all w=8
  8 +${GF_METHODS} | awk -F: '{ if ($1 == "w=8") print $2; }' |
  9 +while read method; do
  10 + echo "Testing ${k} ${m} 8 ${method}"
  11 + ./reed_sol_test_gf ${k} ${m} 8 ${method}
  12 + if [[ $? != "0" ]]; then
  13 + echo "Failed test for ${k} ${m} 8 ${method}"
  14 + FAIL=1
  15 + exit 1
  16 + fi
  17 +done
  18 +
  19 +if [ -n ${FAIL} ]; then
  20 + exit 1
  21 +fi
  22 +
  23 +# Test all w=16
  24 +${GF_METHODS} | awk -F: '{ if ($1 == "w=16") print $2; }' |
  25 +while read method; do
  26 + echo "Testing ${k} ${m} 16 ${method}"
  27 + ./reed_sol_test_gf ${k} ${m} 16 ${method}
  28 + if [[ $? != "0" ]]; then
  29 + echo "Failed test for ${k} ${m} 16 ${method}"
  30 + FAIL=1
  31 + exit 1
  32 + fi
  33 +done
  34 +
  35 +if [ -n ${FAIL} ]; then
  36 + exit 1
  37 +fi
  38 +
  39 +# Test all w=32
  40 +${GF_METHODS} | awk -F: '{ if ($1 == "w=32") print $2; }' |
  41 +while read method; do
  42 + echo "Testing ${k} ${m} 32 ${method}"
  43 + ./reed_sol_test_gf ${k} ${m} 32 ${method}
  44 + if [[ $? != "0" ]]; then
  45 + echo "Failed test for ${k} ${m} 32 ${method}"
  46 + FAIL=1
  47 + exit 1
  48 + fi
  49 +done
  50 +
  51 +if [ -n ${FAIL} ]; then
  52 + exit 1
  53 +fi
  54 +
  55 +echo "Passed all tests!"
... ...
Examples/time_all_gfs.sh 0 → 100755
... ... @@ -0,0 +1,57 @@
  1 +GF_COMPLETE_DIR=/usr/local/bin
  2 +GF_METHODS=${GF_COMPLETE_DIR}/gf_methods
  3 +ITERATIONS=128
  4 +BUFSIZE=65536
  5 +k=12
  6 +m=3
  7 +FAIL=
  8 +
  9 +# Test all w=8
  10 +${GF_METHODS} | awk -F: '{ if ($1 == "w=8") print $2; }' |
  11 +while read method; do
  12 + echo "Testing ${k} ${m} 8 ${ITERATIONS} ${BUFSIZE} ${method}"
  13 + ./reed_sol_time_gf ${k} ${m} 8 ${ITERATIONS} ${BUFSIZE} ${method}
  14 + if [[ $? != "0" ]]; then
  15 + echo "Failed test for ${k} ${m} 8 ${ITERATIONS} ${BUFSIZE} ${method}"
  16 + FAIL=1
  17 + exit 1
  18 + fi
  19 +done
  20 +
  21 +if [ -n ${FAIL} ]; then
  22 + exit 1
  23 +fi
  24 +
  25 +# Test all w=16
  26 +${GF_METHODS} | grep -v 'TABLE' | awk -F: '{ if ($1 == "w=16") print $2; }' |
  27 +while read method; do
  28 + echo "Testing ${k} ${m} 16 ${ITERATIONS} ${BUFSIZE} ${method}"
  29 + ./reed_sol_time_gf ${k} ${m} 16 ${ITERATIONS} ${BUFSIZE} ${method}
  30 + if [[ $? != "0" ]]; then
  31 + echo "Failed test for ${k} ${m} 16 ${ITERATIONS} ${BUFSIZE} ${method}"
  32 + FAIL=1
  33 + exit 1
  34 + fi
  35 +done
  36 +
  37 +if [ -n ${FAIL} ]; then
  38 + exit 1
  39 +fi
  40 +
  41 +# Test all w=32
  42 +${GF_METHODS} | awk -F: '{ if ($1 == "w=32") print $2; }' |
  43 +while read method; do
  44 + echo "Testing ${k} ${m} 32 ${ITERATIONS} ${BUFSIZE} ${method}"
  45 + ./reed_sol_time_gf ${k} ${m} 32 ${ITERATIONS} ${BUFSIZE} ${method}
  46 + if [[ $? != "0" ]]; then
  47 + echo "Failed test for ${k} ${m} 32 ${ITERATIONS} ${BUFSIZE} ${method}"
  48 + FAIL=1
  49 + exit 1
  50 + fi
  51 +done
  52 +
  53 +if [ -n ${FAIL} ]; then
  54 + exit 1
  55 +fi
  56 +
  57 +echo "Passed all tests!"
... ...
Test/makefile
... ... @@ -1,103 +0,0 @@
1   -# Examples/makefile
2   -# Jerasure - A C/C++ Library for a Variety of Reed-Solomon and RAID-6 Erasure Coding Techniques
3   -#
4   -# Revision 1.2A
5   -# May 24, 2011
6   -#
7   -# James S. Plank
8   -# Department of Electrical Engineering and Computer Science
9   -# University of Tennessee
10   -# Knoxville, TN 37996
11   -# plank@cs.utk.edu
12   -#
13   -# Copyright (c) 2011, James S. Plank
14   -# All rights reserved.
15   -#
16   -# Redistribution and use in source and binary forms, with or without
17   -# modification, are permitted provided that the following conditions
18   -# are met:
19   -#
20   -# - Redistributions of source code must retain the above copyright
21   -# notice, this list of conditions and the following disclaimer.
22   -#
23   -# - Redistributions in binary form must reproduce the above copyright
24   -# notice, this list of conditions and the following disclaimer in
25   -# the documentation and/or other materials provided with the
26   -# distribution.
27   -#
28   -# - Neither the name of the University of Tennessee nor the names of its
29   -# contributors may be used to endorse or promote products derived
30   -# from this software without specific prior written permission.
31   -#
32   -# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
33   -# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
34   -# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
35   -# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
36   -# HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
37   -# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
38   -# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
39   -# OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
40   -# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
41   -# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY
42   -# WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
43   -# POSSIBILITY OF SUCH DAMAGE.
44   -
45   -PREFIX=/usr/local
46   -BINDIR=${PREFIX}/bin
47   -LIBDIR=${PREFIX}/lib
48   -INCDIR=${PREFIX}/include
49   -CC = gcc
50   -CFLAGS = -O3 -I$(HOME)/include
51   -
52   -ALL = reed_sol_test_01 reed_sol_test_02
53   -
54   -all: $(ALL)
55   -
56   -clean:
57   - rm -f core *.o $(ALL) a.out cauchy.h cauchy.c liberation.h liberation.c reed_sol.c reed_sol.h\
58   - jerasure.c jerasure.h galois.c galois.h
59   -
60   -.SUFFIXES: .c .o
61   -.c.o:
62   - $(CC) $(CFLAGS) -c $*.c
63   -
64   -liberation.h: ../liberation.h
65   - rm -f liberation.h ; cp ../liberation.h . ; chmod 0444 liberation.h
66   -
67   -liberation.c: ../liberation.c
68   - rm -f liberation.c ; cp ../liberation.c . ; chmod 0444 liberation.c
69   -
70   -cauchy.h: ../cauchy.h
71   - rm -f cauchy.h ; cp ../cauchy.h . ; chmod 0444 cauchy.h
72   -
73   -cauchy.c: ../cauchy.c
74   - rm -f cauchy.c ; cp ../cauchy.c . ; chmod 0444 cauchy.c
75   -
76   -reed_sol.h: ../reed_sol.h
77   - rm -f reed_sol.h ; cp ../reed_sol.h . ; chmod 0444 reed_sol.h
78   -
79   -reed_sol.c: ../reed_sol.c
80   - rm -f reed_sol.c ; cp ../reed_sol.c . ; chmod 0444 reed_sol.c
81   -
82   -jerasure.h: ../jerasure.h
83   - rm -f jerasure.h ; cp ../jerasure.h . ; chmod 0444 jerasure.h
84   -
85   -jerasure.c: ../jerasure.c
86   - rm -f jerasure.c ; cp ../jerasure.c . ; chmod 0444 jerasure.c
87   -
88   -galois.h: ../galois.h
89   - rm -f galois.h ; cp ../galois.h . ; chmod 0444 galois.h
90   -
91   -galois.c: ../galois.c
92   - rm -f galois.c ; cp ../galois.c . ; chmod 0444 galois.c
93   -
94   -galois.o ${LIBDIR}/gf_complete.a: galois.h
95   -jerasure.o: jerasure.h galois.h
96   -
97   -reed_sol_test_01.o: galois.h reed_sol.h jerasure.h
98   -reed_sol_test_01: reed_sol_test_01.o galois.o ${LIBDIR}/gf_complete.a jerasure.o reed_sol.o
99   - $(CC) $(CFLAGS) -o reed_sol_test_01 reed_sol_test_01.o reed_sol.o jerasure.o galois.o ${LIBDIR}/gf_complete.a
100   -
101   -reed_sol_test_02.o: galois.h reed_sol.h jerasure.h
102   -reed_sol_test_02: reed_sol_test_02.o galois.o ${LIBDIR}/gf_complete.a jerasure.o reed_sol.o
103   - $(CC) $(CFLAGS) -o reed_sol_test_02 reed_sol_test_02.o reed_sol.o jerasure.o galois.o ${LIBDIR}/gf_complete.a
Test/reed_sol_test_01.c
... ... @@ -1,191 +0,0 @@
1   -/* Examples/reed_sol_01.c
2   -Jerasure - A C/C++ Library for a Variety of Reed-Solomon and RAID-6 Erasure Coding Techniques
3   -
4   -Revision 1.2A
5   -May 24, 2011
6   -
7   -James S. Plank
8   -Department of Electrical Engineering and Computer Science
9   -University of Tennessee
10   -Knoxville, TN 37996
11   -plank@cs.utk.edu
12   -
13   -Copyright (c) 2011, James S. Plank
14   -All rights reserved.
15   -
16   -Redistribution and use in source and binary forms, with or without
17   -modification, are permitted provided that the following conditions
18   -are met:
19   -
20   - - Redistributions of source code must retain the above copyright
21   - notice, this list of conditions and the following disclaimer.
22   -
23   - - Redistributions in binary form must reproduce the above copyright
24   - notice, this list of conditions and the following disclaimer in
25   - the documentation and/or other materials provided with the
26   - distribution.
27   -
28   - - Neither the name of the University of Tennessee nor the names of its
29   - contributors may be used to endorse or promote products derived
30   - from this software without specific prior written permission.
31   -
32   -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
33   -"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
34   -LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
35   -A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
36   -HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
37   -INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
38   -BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
39   -OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
40   -AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
41   -LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY
42   -WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
43   -POSSIBILITY OF SUCH DAMAGE.
44   -
45   -
46   - */
47   -
48   -
49   -/*
50   - revised by S. Simmerman
51   - 2/25/08
52   -*/
53   -#include <stdio.h>
54   -#include <stdlib.h>
55   -#include <string.h>
56   -#include <gf_complete.h>
57   -#include "jerasure.h"
58   -#include "reed_sol.h"
59   -
60   -#define BUFSIZE 4096
61   -
62   -static void *malloc16(int size) {
63   - void *mem = malloc(size+16+sizeof(void*));
64   - void **ptr = (void**)((long)(mem+16+sizeof(void*)) & ~(15));
65   - ptr[-1] = mem;
66   - return ptr;
67   -}
68   -
69   -static void free16(void *ptr) {
70   - free(((void**)ptr)[-1]);
71   -}
72   -
73   -#define talloc(type, num) (type *) malloc16(sizeof(type)*(num))
74   -
75   -usage(char *s)
76   -{
77   - fprintf(stderr, "usage: reed_sol_test_01 k m w [additional GF args]- Tests Reed-Solomon in GF(2^w).\n");
78   - fprintf(stderr, " \n");
79   - fprintf(stderr, " w must be 8, 16 or 32. k+m must be <= 2^w. It sets up a classic\n");
80   - fprintf(stderr, " Vandermonde-based distribution matrix and encodes k devices of\n");
81   - fprintf(stderr, " %d bytes each with it. Then it decodes.\n", BUFSIZE);
82   - fprintf(stderr, " \n");
83   - fprintf(stderr, "This tests: jerasure_matrix_encode()\n");
84   - fprintf(stderr, " jerasure_matrix_decode()\n");
85   - fprintf(stderr, " jerasure_print_matrix()\n");
86   - fprintf(stderr, " reed_sol_vandermonde_coding_matrix()\n");
87   - if (s != NULL) fprintf(stderr, "%s\n", s);
88   - exit(1);
89   -}
90   -
91   -gf_t* get_gf(int w, int argc, char **argv, int starting)
92   -{
93   - gf_t *gf = (gf_t*)malloc(sizeof(gf_t));
94   - if (create_gf_from_argv(gf, w, argc, argv, starting) == 0) {
95   - free(gf);
96   - gf = NULL;
97   - }
98   - return gf;
99   -}
100   -
101   -static void fill_buffer(unsigned char *buf, int size)
102   -{
103   - int i;
104   -
105   - buf[0] = (char)(lrand48() % 256);
106   -
107   - for (i=1; i < size; i++) {
108   - buf[i] = ((buf[i-1] + i) % 256);
109   - }
110   -}
111   -
112   -int main(int argc, char **argv)
113   -{
114   - long l;
115   - int k, w, i, j, m;
116   - int *matrix;
117   - char **data, **coding, **old_values;
118   - int *erasures, *erased;
119   - int *decoding_matrix, *dm_ids;
120   - gf_t *gf = NULL;
121   -
122   - if (argc < 4) usage(NULL);
123   - if (sscanf(argv[1], "%d", &k) == 0 || k <= 0) usage("Bad k");
124   - if (sscanf(argv[2], "%d", &m) == 0 || m <= 0) usage("Bad m");
125   - if (sscanf(argv[3], "%d", &w) == 0 || (w != 8 && w != 16 && w != 32)) usage("Bad w");
126   - if (w <= 16 && k + m > (1 << w)) usage("k + m is too big");
127   -
128   - srand48(time(0));
129   -
130   - gf = get_gf(w, argc, argv, 4);
131   -
132   - if (gf == NULL) {
133   - usage("Invalid arguments given for GF!\n");
134   - }
135   -
136   - galois_change_technique(gf, w);
137   -
138   - matrix = reed_sol_vandermonde_coding_matrix(k, m, w);
139   -
140   - printf("Last m rows of the Distribution Matrix:\n\n");
141   - jerasure_print_matrix(matrix, m, k, w);
142   - printf("\n");
143   -
144   - data = talloc(char *, k);
145   - for (i = 0; i < k; i++) {
146   - data[i] = talloc(char, BUFSIZE);
147   - fill_buffer(data[i], BUFSIZE);
148   - }
149   -
150   - coding = talloc(char *, m);
151   - old_values = talloc(char *, m);
152   - for (i = 0; i < m; i++) {
153   - coding[i] = talloc(char, BUFSIZE);
154   - old_values[i] = talloc(char, BUFSIZE);
155   - }
156   -
157   - jerasure_matrix_encode(k, m, w, matrix, data, coding, BUFSIZE);
158   -
159   - erasures = talloc(int, (m+1));
160   - erased = talloc(int, (k+m));
161   - for (i = 0; i < m+k; i++) erased[i] = 0;
162   - l = 0;
163   - for (i = 0; i < m; ) {
164   - erasures[i] = ((unsigned int)lrand48())%(k+m);
165   - if (erased[erasures[i]] == 0) {
166   - erased[erasures[i]] = 1;
167   - memcpy(old_values[i], (erasures[i] < k) ? data[erasures[i]] : coding[erasures[i]-k], BUFSIZE);
168   - bzero((erasures[i] < k) ? data[erasures[i]] : coding[erasures[i]-k], BUFSIZE);
169   - i++;
170   - }
171   - }
172   - erasures[i] = -1;
173   -
174   - i = jerasure_matrix_decode(k, m, w, matrix, 1, erasures, data, coding, BUFSIZE);
175   -
176   - for (i = 0; i < m; i++) {
177   - if (erasures[i] < k) {
178   - if (memcmp(data[erasures[i]], old_values[i], BUFSIZE)) {
179   - fprintf(stderr, "Decoding failed for %d!\n", erasures[i]);
180   - exit(1);
181   - }
182   - } else {
183   - if (memcmp(coding[erasures[i]-k], old_values[i], BUFSIZE)) {
184   - fprintf(stderr, "Decoding failed for %d!\n", erasures[i]);
185   - exit(1);
186   - }
187   - }
188   - }
189   -
190   - return 0;
191   -}
Test/reed_sol_test_02.c
... ... @@ -1,224 +0,0 @@
1   -/* Examples/reed_sol_01.c
2   -Jerasure - A C/C++ Library for a Variety of Reed-Solomon and RAID-6 Erasure Coding Techniques
3   -
4   -Revision 1.2A
5   -May 24, 2011
6   -
7   -James S. Plank
8   -Department of Electrical Engineering and Computer Science
9   -University of Tennessee
10   -Knoxville, TN 37996
11   -plank@cs.utk.edu
12   -
13   -Copyright (c) 2011, James S. Plank
14   -All rights reserved.
15   -
16   -Redistribution and use in source and binary forms, with or without
17   -modification, are permitted provided that the following conditions
18   -are met:
19   -
20   - - Redistributions of source code must retain the above copyright
21   - notice, this list of conditions and the following disclaimer.
22   -
23   - - Redistributions in binary form must reproduce the above copyright
24   - notice, this list of conditions and the following disclaimer in
25   - the documentation and/or other materials provided with the
26   - distribution.
27   -
28   - - Neither the name of the University of Tennessee nor the names of its
29   - contributors may be used to endorse or promote products derived
30   - from this software without specific prior written permission.
31   -
32   -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
33   -"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
34   -LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
35   -A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
36   -HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
37   -INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
38   -BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
39   -OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
40   -AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
41   -LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY
42   -WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
43   -POSSIBILITY OF SUCH DAMAGE.
44   -
45   -
46   - */
47   -
48   -
49   -/*
50   - revised by S. Simmerman
51   - 2/25/08
52   -*/
53   -#include <stdio.h>
54   -#include <stdlib.h>
55   -#include <string.h>
56   -#include <gf_complete.h>
57   -#include "jerasure.h"
58   -#include "reed_sol.h"
59   -
60   -static void *malloc16(int size) {
61   - void *mem = malloc(size+16+sizeof(void*));
62   - void **ptr = (void**)((long)(mem+16+sizeof(void*)) & ~(15));
63   - ptr[-1] = mem;
64   - return ptr;
65   -}
66   -
67   -static void free16(void *ptr) {
68   - free(((void**)ptr)[-1]);
69   -}
70   -
71   -#define talloc(type, num) (type *) malloc16(sizeof(type)*(num))
72   -
73   -void
74   -timer_start (double *t)
75   -{
76   - struct timeval tv;
77   -
78   - gettimeofday (&tv, NULL);
79   - *t = (double)tv.tv_sec + (double)tv.tv_usec * 1e-6;
80   -}
81   -
82   -double
83   -timer_split (const double *t)
84   -{
85   - struct timeval tv;
86   - double cur_t;
87   -
88   - gettimeofday (&tv, NULL);
89   - cur_t = (double)tv.tv_sec + (double)tv.tv_usec * 1e-6;
90   - return (cur_t - *t);
91   -}
92   -
93   -usage(char *s)
94   -{
95   - fprintf(stderr, "usage: reed_sol_test_01 k m w iterations bufsize [additional GF args]- Tests Reed-Solomon in GF(2^w).\n");
96   - fprintf(stderr, " \n");
97   - fprintf(stderr, " w must be 8, 16 or 32. k+m must be <= 2^w. It sets up a classic\n");
98   - fprintf(stderr, " Vandermonde-based distribution matrix and encodes k devices of\n");
99   - fprintf(stderr, " <bufsize> bytes each with it. Then it decodes.\n");
100   - fprintf(stderr, " \n");
101   - fprintf(stderr, "This tests: jerasure_matrix_encode()\n");
102   - fprintf(stderr, " jerasure_matrix_decode()\n");
103   - fprintf(stderr, " jerasure_print_matrix()\n");
104   - fprintf(stderr, " reed_sol_vandermonde_coding_matrix()\n");
105   - if (s != NULL) fprintf(stderr, "%s\n", s);
106   - exit(1);
107   -}
108   -
109   -gf_t* get_gf(int w, int argc, char **argv, int starting)
110   -{
111   - gf_t *gf = (gf_t*)malloc(sizeof(gf_t));
112   - if (create_gf_from_argv(gf, w, argc, argv, starting) == 0) {
113   - free(gf);
114   - gf = NULL;
115   - }
116   - return gf;
117   -}
118   -
119   -static void fill_buffer(unsigned char *buf, int size)
120   -{
121   - int i;
122   -
123   - buf[0] = (char)(lrand48() % 256);
124   -
125   - for (i=1; i < size; i++) {
126   - buf[i] = ((buf[i-1] + i) % 256);
127   - }
128   -}
129   -
130   -int main(int argc, char **argv)
131   -{
132   - long l;
133   - int k, w, i, j, m, iterations, bufsize;
134   - int *matrix;
135   - char **data, **coding, **old_values;
136   - int *erasures, *erased;
137   - int *decoding_matrix, *dm_ids;
138   - double t = 0, total_time = 0;
139   - gf_t *gf = NULL;
140   -
141   - if (argc < 6) usage(NULL);
142   - if (sscanf(argv[1], "%d", &k) == 0 || k <= 0) usage("Bad k");
143   - if (sscanf(argv[2], "%d", &m) == 0 || m <= 0) usage("Bad m");
144   - if (sscanf(argv[3], "%d", &w) == 0 || (w != 8 && w != 16 && w != 32)) usage("Bad w");
145   - if (sscanf(argv[4], "%d", &iterations) == 0) usage("Bad iterations");
146   - if (sscanf(argv[5], "%d", &bufsize) == 0) usage("Bad bufsize");
147   - if (w <= 16 && k + m > (1 << w)) usage("k + m is too big");
148   -
149   - srand48(time(0));
150   -
151   - gf = get_gf(w, argc, argv, 6);
152   -
153   - if (gf == NULL) {
154   - usage("Invalid arguments given for GF!\n");
155   - }
156   -
157   - galois_change_technique(gf, w);
158   -
159   - matrix = reed_sol_vandermonde_coding_matrix(k, m, w);
160   -
161   - printf("Last m rows of the Distribution Matrix:\n\n");
162   - jerasure_print_matrix(matrix, m, k, w);
163   - printf("\n");
164   -
165   - data = talloc(char *, k);
166   - for (i = 0; i < k; i++) {
167   - data[i] = talloc(char, bufsize);
168   - fill_buffer(data[i], bufsize);
169   - }
170   -
171   - coding = talloc(char *, m);
172   - old_values = talloc(char *, m);
173   - for (i = 0; i < m; i++) {
174   - coding[i] = talloc(char, bufsize);
175   - old_values[i] = talloc(char, bufsize);
176   - }
177   -
178   - for (i = 0; i < iterations; i++) {
179   - timer_start(&t);
180   - jerasure_matrix_encode(k, m, w, matrix, data, coding, bufsize);
181