Tests: Add option for dump

This commit is contained in:
Shahram Najm 2018-08-06 13:44:56 +01:00
parent 4ac5e3691e
commit 3826c9ddf2
3 changed files with 14 additions and 12 deletions

View File

@ -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;

View File

@ -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);
}

View File

@ -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
}
###################################################