ECC-386: Add test (activated if -DENABLE_GRIB_TIMER=ON)

This commit is contained in:
Shahram Najm 2016-12-02 18:44:44 +00:00
parent 5fbc7a9348
commit 8ba5e022a1
5 changed files with 102 additions and 1 deletions

View File

@ -162,7 +162,7 @@ endif()
###############################################################################
# other options
if( GRIB_TIMER )
if( HAVE_GRIB_TIMER )
set( GRIB_TIMER 1 )
else()
set( GRIB_TIMER 0 )

View File

@ -84,3 +84,4 @@ timeRangeIndicator_5.grib
tp_ecmwf.grib
v.grib2
msl.octa.glob.grib1
test_file.grib2

View File

@ -24,6 +24,7 @@ list( APPEND test_bins
grib_2nd_order_numValues
optimize_scaling
optimize_scaling_sh
ecc-386
)
foreach( tool ${test_bins} )
@ -220,3 +221,10 @@ ecbuild_add_test( TARGET eccodes_t_grib_check_param_concepts
CONDITION ENABLE_EXTRA_TESTS
COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/grib_check_param_concepts.sh
)
# Performance test. Must have -DENABLE_GRIB_TIMER=ON
ecbuild_add_test( TARGET eccodes_t_ecc-386
TYPE SCRIPT
CONDITION ENABLE_EXTRA_TESTS AND ENABLE_GRIB_TIMER
COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/ecc-386.sh
TEST_DEPENDS eccodes_download_gribs
)

78
tests/ecc-386.c Normal file
View File

@ -0,0 +1,78 @@
/*
* Copyright 2005-2016 ECMWF.
*
* This software is licensed under the terms of the Apache Licence Version 2.0
* which can be obtained at http://www.apache.org/licenses/LICENSE-2.0.
*
* In applying this licence, ECMWF does not waive the privileges and immunities granted to it by
* virtue of its status as an intergovernmental organisation nor does it submit to any jurisdiction.
*/
/*
* Description: Reads a GRIB message from file, measures read time.
*
*/
#include <stdio.h>
#include <assert.h>
#include "grib_api_internal.h"
void usage(char* prog) {
printf("usage: %s filename\n",prog);
exit(1);
}
#ifdef GRIB_TIMER
int main(int argc, char** argv)
{
grib_timer *tes = grib_get_timer(0,"decoding", 0, 0);
FILE *in = NULL;
int err = 0, i = 0;
grib_handle *h = NULL;
size_t values_len = 0;
double *values = NULL;
double time_taken_actual = 0;
const double time_taken_expected = 6; /* seconds */
const int num_repetitions = 1000;
if (argc<2) usage(argv[0]);
in = fopen(argv[1],"r");
if(!in) {
printf("ERROR: unable to open file %s\n",argv[1]);
return 1;
}
/* create new handle from a message in a file*/
err = 0;
h = grib_handle_new_from_file(0,in,&err);
if (h == NULL) {
printf("Error: unable to create handle from file.\n");
return 1;
}
/* get the size of the values array*/
GRIB_CHECK(grib_get_size(h,"values",&values_len),0);
values = malloc(values_len*sizeof(double));
/* get data values*/
grib_timer_start(tes);
for (i=0; i<num_repetitions; i++) {
GRIB_CHECK(grib_get_double_array(h,"values",values,&values_len),0);
}
grib_timer_stop(tes,0);
time_taken_actual = grib_timer_value(tes);
if (time_taken_actual > time_taken_expected) {
fprintf(stderr, "Decoding took longer than expected! actual time=%g, expected to take less than %g seconds",
time_taken_actual, time_taken_expected);
return 1;
}
printf("Test passed. Actual decode time=%g\n", time_taken_actual);
free(values);
grib_handle_delete(h);
fclose(in);
return 0;
}
#else
int main(int argc, char** argv) { return 0; }
#endif

14
tests/ecc-386.sh Executable file
View File

@ -0,0 +1,14 @@
#!/bin/sh
# Copyright 2005-2016 ECMWF.
#
# This software is licensed under the terms of the Apache Licence Version 2.0
# which can be obtained at http://www.apache.org/licenses/LICENSE-2.0.
#
# In applying this licence, ECMWF does not waive the privileges and immunities granted to it by
# virtue of its status as an intergovernmental organisation nor does it submit to any jurisdiction.
#
. ./include.sh
input=${data_dir}/test_file.grib2
exec ${test_dir}/ecc-386 $input