diff --git a/Examples/.gitignore b/Examples/.gitignore index 97bbded..b97ec5a 100644 --- a/Examples/.gitignore +++ b/Examples/.gitignore @@ -5,4 +5,5 @@ /liberation_[0-9][0-9] /reed_sol_[0-9][0-9] /reed_sol_test_gf -/reed_sol_time_gf \ No newline at end of file +/reed_sol_time_gf +/test_galois diff --git a/Examples/Makefile.am b/Examples/Makefile.am index 9aa4780..9e20f1c 100644 --- a/Examples/Makefile.am +++ b/Examples/Makefile.am @@ -25,10 +25,15 @@ bin_PROGRAMS = jerasure_01 \ encoder \ decoder -TESTS=test_all_gfs.sh +check_PROGRAMS = + +TESTS=test_all_gfs.sh $(check_PROGRAMS) dist_noinst_SCRIPTS = test_all_gfs.sh time_all_gfs_argv_init.sh +test_galois_SOURCES = test_galois.c +check_PROGRAMS += test_galois + jerasure_01_SOURCES = jerasure_01.c jerasure_02_SOURCES = jerasure_02.c jerasure_03_SOURCES = jerasure_03.c diff --git a/Examples/test_galois.c b/Examples/test_galois.c new file mode 100644 index 0000000..a913a77 --- /dev/null +++ b/Examples/test_galois.c @@ -0,0 +1,23 @@ +#include +#include "galois.h" + +int main(int argc, char **argv) +{ + assert(galois_init_default_field(4) == 0); + assert(galois_uninit_field(4) == 0); + assert(galois_init_default_field(4) == 0); + assert(galois_uninit_field(4) == 0); + + assert(galois_init_default_field(8) == 0); + assert(galois_uninit_field(8) == 0); + assert(galois_init_default_field(8) == 0); + assert(galois_uninit_field(8) == 0); + + return 0; +} +/* + * Local Variables: + * compile-command: "make test_galois && + * libtool --mode=execute valgrind --tool=memcheck --leak-check=full ./test_galois" + * End: + */ diff --git a/include/galois.h b/include/galois.h index b1e4652..78e6567 100644 --- a/include/galois.h +++ b/include/galois.h @@ -47,6 +47,7 @@ extern "C" { #endif extern int galois_init_default_field(int w); +extern int galois_uninit_field(int w); extern void galois_change_technique(gf_t *gf, int w); extern int galois_single_multiply(int a, int b, int w); diff --git a/src/galois.c b/src/galois.c index 95d72bc..6dc4282 100644 --- a/src/galois.c +++ b/src/galois.c @@ -181,6 +181,18 @@ int galois_init_default_field(int w) return 0; } +int galois_uninit_field(int w) +{ + int ret = 0; + if (gfp_array[w] != NULL) { + int recursive = 1; + ret = gf_free(gfp_array[w], recursive); + free(gfp_array[w]); + gfp_array[w] = NULL; + } + return ret; +} + static void galois_init(int w) { if (w <= 0 || w > 32) {