From 3826c9ddf26d1d48d9f51a15ea137242e012e6ef Mon Sep 17 00:00:00 2001 From: Shahram Najm Date: Mon, 6 Aug 2018 13:44:56 +0100 Subject: [PATCH] Tests: Add option for dump --- tests/bufr_ecc-604.c | 6 +++--- tests/grib_ecc-604.c | 14 ++++++++------ tests/grib_ecc-604.sh | 6 +++--- 3 files changed, 14 insertions(+), 12 deletions(-) diff --git a/tests/bufr_ecc-604.c b/tests/bufr_ecc-604.c index 27f340b7e..3f0c5b577 100644 --- a/tests/bufr_ecc-604.c +++ b/tests/bufr_ecc-604.c @@ -27,7 +27,7 @@ static int encode_file(char *template_file, char *output_file) long numSubsets = 0; in = fopen(template_file,"r"); assert(in); - if (output_file) { + if (opt_write) { out = fopen(output_file,"w"); assert(out); } @@ -43,7 +43,7 @@ static int encode_file(char *template_file, char *output_file) CODES_CHECK(codes_set_long(h, "unpack", 1),0); CODES_CHECK(codes_get_message(h,&buffer,&size),0); - if (output_file) { + if (opt_write) { if(fwrite(buffer,1,size,out) != size) { perror(output_file); return 1; @@ -64,7 +64,7 @@ static int encode_file(char *template_file, char *output_file) if(opt_clone) codes_handle_delete(h); } - if (output_file) fclose(out); + if (opt_write) fclose(out); fclose(in); return 0; diff --git a/tests/grib_ecc-604.c b/tests/grib_ecc-604.c index 8e2de7252..be7be4643 100644 --- a/tests/grib_ecc-604.c +++ b/tests/grib_ecc-604.c @@ -12,6 +12,7 @@ static size_t NUM_THREADS = 0; static size_t FILES_PER_ITERATION = 0; static char* INPUT_FILE = NULL; +int opt_dump = 0; /* If 1 then dump handle to /dev/null */ int opt_clone = 0; /* If 1 then clone source handle */ int opt_write = 0; /* If 1 write handle to file */ @@ -25,7 +26,7 @@ static int encode_file(char *template_file, char *output_file) double *values; in = fopen(template_file,"r"); assert(in); - if (output_file) { + if (opt_write) { out = fopen(output_file,"w"); assert(out); } @@ -58,13 +59,13 @@ static int encode_file(char *template_file, char *output_file) GRIB_CHECK(grib_set_double_array(h,"values",values,values_len),0); GRIB_CHECK(grib_get_message(h,&buffer,&size),0); - if (output_file) { + if (opt_write) { if(fwrite(buffer,1,size,out) != size) { perror(output_file); return 1; } } - { + if (opt_dump) { FILE *devnull = fopen("/dev/null", "w"); grib_dump_content(source_handle,devnull, "debug", 0, NULL); } @@ -74,7 +75,7 @@ static int encode_file(char *template_file, char *output_file) free(values); } - if (output_file) fclose(out); + if (opt_write) fclose(out); fclose(in); return 0; @@ -102,8 +103,9 @@ int main(int argc, char **argv) return 1; } - while ((c = getopt (argc, argv, "cw")) != -1) { + while ((c = getopt (argc, argv, "dcw")) != -1) { switch (c) { + case 'd': opt_dump=1; break; case 'c': opt_clone=1; break; case 'w': opt_write=1; break; } @@ -119,7 +121,7 @@ int main(int argc, char **argv) } if (parallel) { printf("Running parallel in %ld threads. %ld iterations\n", NUM_THREADS, FILES_PER_ITERATION); - printf("Options: clone=%d, write=%d\n", opt_clone, opt_write); + printf("Options: dump=%d, clone=%d, write=%d\n", opt_dump, opt_clone, opt_write); } else { printf("Running sequentially in %ld runs. %ld iterations\n", NUM_THREADS, FILES_PER_ITERATION); } diff --git a/tests/grib_ecc-604.sh b/tests/grib_ecc-604.sh index 4a22eab98..f85d35042 100755 --- a/tests/grib_ecc-604.sh +++ b/tests/grib_ecc-604.sh @@ -45,10 +45,10 @@ process() time ${test_dir}/grib_ecc-604 -w par $input $NUM_THREADS $NUM_ITER validate - # Test 03: Clone + no output - # --------------------------- + # Test 03: Clone + dump + no output + # --------------------------------- rm -fr $OUTPUT - time ${test_dir}/grib_ecc-604 -c par $input $NUM_THREADS $NUM_ITER + time ${test_dir}/grib_ecc-604 -c -d par $input $NUM_THREADS $NUM_ITER # Nothing to validate as there is no output } ###################################################