Commit 868579776a4c69863163494660ad31a4355e8048

Authored by KMG
2 parents c94348f7 11dc3fcb
Exists in master

Merge pull request #2 from dachary/wip-exit

Merging a set of commits from Loic: Use assert(0) to exit(1) and clean-up some of the test code.
Examples/Makefile.am
... ... @@ -27,7 +27,7 @@ bin_PROGRAMS = jerasure_01 \
27 27  
28 28 check_PROGRAMS =
29 29  
30   -TESTS=test_all_gfs.sh $(check_PROGRAMS)
  30 +TESTS=test_all_gfs.sh encode_decode.sh $(check_PROGRAMS)
31 31  
32 32 dist_noinst_SCRIPTS = test_all_gfs.sh time_all_gfs_argv_init.sh
33 33  
... ...
Examples/decoder.c
... ... @@ -62,6 +62,7 @@ same arguments, and encoder.c does error check.
62 62 #include <stdlib.h>
63 63 #include <string.h>
64 64 #include <time.h>
  65 +#include <assert.h>
65 66 #include <unistd.h>
66 67 #include <sys/time.h>
67 68 #include <sys/stat.h>
... ... @@ -104,12 +105,11 @@ int main (int argc, char **argv) {
104 105 char *c_tech;
105 106  
106 107 int i, j; // loop control variable, s
107   - int blocksize; // size of individual files
  108 + int blocksize = 0; // size of individual files
108 109 int origsize; // size of file before padding
109 110 int total; // used to write data, not padding to file
110 111 struct stat status; // used to find size of individual files
111 112 int numerased; // number of erased files
112   - int dummy;
113 113  
114 114 /* Used to recreate file names */
115 115 char *temp;
... ... @@ -138,8 +138,8 @@ int main (int argc, char **argv) {
138 138 fprintf(stderr, "usage: inputfile\n");
139 139 exit(0);
140 140 }
141   - curdir = (char *)malloc(sizeof(char)*100);
142   - getcwd(curdir, 100);
  141 + curdir = (char *)malloc(sizeof(char)*1000);
  142 + assert(curdir == getcwd(curdir, 1000));
143 143  
144 144 /* Begin recreation of file names */
145 145 cs1 = (char*)malloc(sizeof(char)*strlen(argv[1]));
... ... @@ -270,11 +270,11 @@ int main (int argc, char **argv) {
270 270 stat(fname, &status);
271 271 blocksize = status.st_size;
272 272 data[i-1] = (char *)malloc(sizeof(char)*blocksize);
273   - dummy = fread(data[i-1], sizeof(char), blocksize, fp);
  273 + assert(blocksize == fread(data[i-1], sizeof(char), blocksize, fp));
274 274 }
275 275 else {
276 276 fseek(fp, blocksize*(n-1), SEEK_SET);
277   - dummy = fread(data[i-1], sizeof(char), buffersize/k, fp);
  277 + assert(buffersize/k == fread(data[i-1], sizeof(char), buffersize/k, fp));
278 278 }
279 279 fclose(fp);
280 280 }
... ... @@ -293,11 +293,11 @@ int main (int argc, char **argv) {
293 293 stat(fname, &status);
294 294 blocksize = status.st_size;
295 295 coding[i-1] = (char *)malloc(sizeof(char)*blocksize);
296   - dummy = fread(coding[i-1], sizeof(char), blocksize, fp);
  296 + assert(blocksize == fread(coding[i-1], sizeof(char), blocksize, fp));
297 297 }
298 298 else {
299 299 fseek(fp, blocksize*(n-1), SEEK_SET);
300   - dummy = fread(coding[i-1], sizeof(char), blocksize, fp);
  300 + assert(blocksize == fread(coding[i-1], sizeof(char), blocksize, fp));
301 301 }
302 302 fclose(fp);
303 303 }
... ...
Examples/encode_decode.sh 0 → 100755
... ... @@ -0,0 +1,21 @@
  1 +#!/bin/bash -e
  2 +#
  3 +# Copyright (C) 2014 Red Hat <contact@redhat.com>
  4 +#
  5 +# Author: Loic Dachary <loic@dachary.org>
  6 +#
  7 +# This program is free software; you can redistribute it and/or modify
  8 +# it under the terms of the GNU Library Public License as published by
  9 +# the Free Software Foundation; either version 2, or (at your option)
  10 +# any later version.
  11 +#
  12 +# This program is distributed in the hope that it will be useful,
  13 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
  14 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15 +# GNU Library Public License for more details.
  16 +#
  17 +trap "rm -fr T Coding" EXIT
  18 +
  19 +dd if=/dev/urandom of=T bs=4096 count=1
  20 +./encoder T 3 2 reed_sol_van 8 0 0
  21 +./decoder T
... ...
Examples/encoder.c
... ... @@ -326,7 +326,7 @@ int main (int argc, char **argv) {
326 326  
327 327 /* Get current working directory for construction of file names */
328 328 curdir = (char*)malloc(sizeof(char)*1000);
329   - getcwd(curdir, 1000);
  329 + assert(curdir == getcwd(curdir, 1000));
330 330  
331 331 if (argv[1][0] != '-') {
332 332  
... ...
Examples/test_all_gfs.sh
1   -#
  1 +#!/bin/bash
2 2 #
3 3 # Copyright (c) 2013, James S. Plank and Kevin Greenan
4 4 # All rights reserved.
... ... @@ -42,6 +42,11 @@ k=12
42 42 m=3
43 43 seed=1370
44 44  
  45 +if ! test -x ${GF_METHODS} ; then
  46 + ${GF_METHODS}
  47 + exit 1
  48 +fi
  49 +
45 50 # Test all w=8
46 51 ${GF_METHODS} 8 -B -L | awk -F: '{ if ($1 == "w=8") print $2; }' |
47 52 while read method; do
... ...
src/galois.c
... ... @@ -48,6 +48,7 @@
48 48 #include <stdlib.h>
49 49 #include <string.h>
50 50 #include <errno.h>
  51 +#include <assert.h>
51 52  
52 53 #include "galois.h"
53 54  
... ... @@ -78,25 +79,25 @@ gf_t* galois_init_field(int w,
78 79  
79 80 if (w <= 0 || w > 32) {
80 81 fprintf(stderr, "ERROR -- cannot init default Galois field for w=%d\n", w);
81   - exit(1);
  82 + assert(0);
82 83 }
83 84  
84 85 gfp = (gf_t *) malloc(sizeof(gf_t));
85 86 if (!gfp) {
86 87 fprintf(stderr, "ERROR -- cannot allocate memory for Galois field w=%d\n", w);
87   - exit(1);
  88 + assert(0);
88 89 }
89 90  
90 91 scratch_size = gf_scratch_size(w, mult_type, region_type, divide_type, arg1, arg2);
91 92 if (!scratch_size) {
92 93 fprintf(stderr, "ERROR -- cannot get scratch size for base field w=%d\n", w);
93   - exit(1);
  94 + assert(0);
94 95 }
95 96  
96 97 scratch_memory = malloc(scratch_size);
97 98 if (!scratch_memory) {
98 99 fprintf(stderr, "ERROR -- cannot get scratch memory for base field w=%d\n", w);
99   - exit(1);
  100 + assert(0);
100 101 }
101 102  
102 103 if(!gf_init_hard(gfp,
... ... @@ -111,7 +112,7 @@ gf_t* galois_init_field(int w,
111 112 scratch_memory))
112 113 {
113 114 fprintf(stderr, "ERROR -- cannot init default Galois field for w=%d\n", w);
114   - exit(1);
  115 + assert(0);
115 116 }
116 117  
117 118 gfp_is_composite[w] = 0;
... ... @@ -130,25 +131,25 @@ gf_t* galois_init_composite_field(int w,
130 131  
131 132 if (w <= 0 || w > 32) {
132 133 fprintf(stderr, "ERROR -- cannot init composite field for w=%d\n", w);
133   - exit(1);
  134 + assert(0);
134 135 }
135 136  
136 137 gfp = (gf_t *) malloc(sizeof(gf_t));
137 138 if (!gfp) {
138 139 fprintf(stderr, "ERROR -- cannot allocate memory for Galois field w=%d\n", w);
139   - exit(1);
  140 + assert(0);
140 141 }
141 142  
142 143 scratch_size = gf_scratch_size(w, GF_MULT_COMPOSITE, region_type, divide_type, degree, 0);
143 144 if (!scratch_size) {
144 145 fprintf(stderr, "ERROR -- cannot get scratch size for composite field w=%d\n", w);
145   - exit(1);
  146 + assert(0);
146 147 }
147 148  
148 149 scratch_memory = malloc(scratch_size);
149 150 if (!scratch_memory) {
150 151 fprintf(stderr, "ERROR -- cannot get scratch memory for composite field w=%d\n", w);
151   - exit(1);
  152 + assert(0);
152 153 }
153 154  
154 155 if(!gf_init_hard(gfp,
... ... @@ -163,7 +164,7 @@ gf_t* galois_init_composite_field(int w,
163 164 scratch_memory))
164 165 {
165 166 fprintf(stderr, "ERROR -- cannot init default composite field for w=%d\n", w);
166   - exit(1);
  167 + assert(0);
167 168 }
168 169 gfp_is_composite[w] = 1;
169 170 return gfp;
... ... @@ -197,17 +198,17 @@ static void galois_init(int w)
197 198 {
198 199 if (w <= 0 || w > 32) {
199 200 fprintf(stderr, "ERROR -- cannot init default Galois field for w=%d\n", w);
200   - exit(1);
  201 + assert(0);
201 202 }
202 203  
203 204 switch (galois_init_default_field(w)) {
204 205 case ENOMEM:
205 206 fprintf(stderr, "ERROR -- cannot allocate memory for Galois field w=%d\n", w);
206   - exit(1);
  207 + assert(0);
207 208 break;
208 209 case EINVAL:
209 210 fprintf(stderr, "ERROR -- cannot init default Galois field for w=%d\n", w);
210   - exit(1);
  211 + assert(0);
211 212 break;
212 213 }
213 214 }
... ... @@ -246,12 +247,12 @@ void galois_change_technique(gf_t *gf, int w)
246 247 {
247 248 if (w <= 0 || w > 32) {
248 249 fprintf(stderr, "ERROR -- cannot support Galois field for w=%d\n", w);
249   - exit(1);
  250 + assert(0);
250 251 }
251 252  
252 253 if (!is_valid_gf(gf, w)) {
253 254 fprintf(stderr, "ERROR -- overriding with invalid Galois field for w=%d\n", w);
254   - exit(1);
  255 + assert(0);
255 256 }
256 257  
257 258 if (gfp_array[w] != NULL) {
... ...
src/jerasure.c
... ... @@ -47,6 +47,7 @@
47 47 #include <stdio.h>
48 48 #include <stdlib.h>
49 49 #include <string.h>
  50 +#include <assert.h>
50 51  
51 52 #include "galois.h"
52 53 #include "jerasure.h"
... ... @@ -311,7 +312,7 @@ void jerasure_matrix_encode(int k, int m, int w, int *matrix,
311 312  
312 313 if (w != 8 && w != 16 && w != 32) {
313 314 fprintf(stderr, "ERROR: jerasure_matrix_encode() and w is not 8, 16 or 32\n");
314   - exit(1);
  315 + assert(0);
315 316 }
316 317  
317 318 for (i = 0; i < m; i++) {
... ... @@ -328,7 +329,7 @@ void jerasure_bitmatrix_dotprod(int k, int w, int *bitmatrix_row,
328 329  
329 330 if (size%(w*packetsize) != 0) {
330 331 fprintf(stderr, "jerasure_bitmatrix_dotprod - size%c(w*packetsize)) must = 0\n", '%');
331   - exit(1);
  332 + assert(0);
332 333 }
333 334  
334 335 bpptr = (dest_id < k) ? data_ptrs[dest_id] : coding_ptrs[dest_id-k];
... ... @@ -567,7 +568,7 @@ void jerasure_free_schedule_cache(int k, int m, int ***cache)
567 568  
568 569 if (m != 2) {
569 570 fprintf(stderr, "jerasure_free_schedule_cache(): m must equal 2\n");
570   - exit(1);
  571 + assert(0);
571 572 }
572 573  
573 574 for (e1 = 0; e1 < k+m; e1++) {
... ... @@ -589,7 +590,7 @@ void jerasure_matrix_dotprod(int k, int w, int *matrix_row,
589 590  
590 591 if (w != 1 && w != 8 && w != 16 && w != 32) {
591 592 fprintf(stderr, "ERROR: jerasure_matrix_dotprod() called and w is not 1, 8, 16 or 32\n");
592   - exit(1);
  593 + assert(0);
593 594 }
594 595  
595 596 init = 0;
... ... @@ -1456,12 +1457,12 @@ void jerasure_bitmatrix_encode(int k, int m, int w, int *bitmatrix,
1456 1457  
1457 1458 if (packetsize%sizeof(long) != 0) {
1458 1459 fprintf(stderr, "jerasure_bitmatrix_encode - packetsize(%d) %c sizeof(long) != 0\n", packetsize, '%');
1459   - exit(1);
  1460 + assert(0);
1460 1461 }
1461 1462 if (size%(packetsize*w) != 0) {
1462 1463 fprintf(stderr, "jerasure_bitmatrix_encode - size(%d) %c (packetsize(%d)*w(%d))) != 0\n",
1463 1464 size, '%', packetsize, w);
1464   - exit(1);
  1465 + assert(0);
1465 1466 }
1466 1467  
1467 1468 for (i = 0; i < m; i++) {
... ...
src/reed_sol.c
... ... @@ -47,6 +47,7 @@
47 47 #include <stdio.h>
48 48 #include <stdlib.h>
49 49 #include <string.h>
  50 +#include <assert.h>
50 51  
51 52 #include <gf_complete.h>
52 53 #include "galois.h"
... ... @@ -107,7 +108,7 @@ void reed_sol_galois_w08_region_multby_2(char *region, int nbytes)
107 108 if (!gf_init_hard(&GF08, 8, GF_MULT_BYTWO_b, GF_REGION_DEFAULT, GF_DIVIDE_DEFAULT,
108 109 prim08, 0, 0, NULL, NULL)) {
109 110 fprintf(stderr, "Error: Can't initialize the GF for reed_sol_galois_w08_region_multby_2\n");
110   - exit(1);
  111 + assert(0);
111 112 }
112 113 }
113 114 GF08.multiply_region.w32(&GF08, region, region, 2, nbytes, 0);
... ... @@ -123,7 +124,7 @@ void reed_sol_galois_w16_region_multby_2(char *region, int nbytes)
123 124 if (!gf_init_hard(&GF16, 16, GF_MULT_BYTWO_b, GF_REGION_DEFAULT, GF_DIVIDE_DEFAULT,
124 125 prim16, 0, 0, NULL, NULL)) {
125 126 fprintf(stderr, "Error: Can't initialize the GF for reed_sol_galois_w16_region_multby_2\n");
126   - exit(1);
  127 + assert(0);
127 128 }
128 129 }
129 130 GF16.multiply_region.w32(&GF16, region, region, 2, nbytes, 0);
... ... @@ -139,7 +140,7 @@ void reed_sol_galois_w32_region_multby_2(char *region, int nbytes)
139 140 if (!gf_init_hard(&GF32, 32, GF_MULT_BYTWO_b, GF_REGION_DEFAULT, GF_DIVIDE_DEFAULT,
140 141 prim32, 0, 0, NULL, NULL)) {
141 142 fprintf(stderr, "Error: Can't initialize the GF for reed_sol_galois_w32_region_multby_2\n");
142   - exit(1);
  143 + assert(0);
143 144 }
144 145 }
145 146 GF32.multiply_region.w32(&GF32, region, region, 2, nbytes, 0);
... ... @@ -223,7 +224,7 @@ int *reed_sol_big_vandermonde_distribution_matrix(int rows, int cols, int w)
223 224 if (j >= rows) { /* This should never happen if rows/w are correct */
224 225 fprintf(stderr, "reed_sol_big_vandermonde_distribution_matrix(%d,%d,%d) - couldn't make matrix\n",
225 226 rows, cols, w);
226   - exit(1);
  227 + assert(0);
227 228 }
228 229  
229 230 /* If necessary, swap rows */
... ...