From 8ba5e022a101c0ef9184016af65daab77178347d Mon Sep 17 00:00:00 2001 From: Shahram Najm Date: Fri, 2 Dec 2016 18:44:44 +0000 Subject: [PATCH] ECC-386: Add test (activated if -DENABLE_GRIB_TIMER=ON) --- CMakeLists.txt | 2 +- data/grib_data_files.txt | 1 + tests/CMakeLists.txt | 8 +++++ tests/ecc-386.c | 78 ++++++++++++++++++++++++++++++++++++++++ tests/ecc-386.sh | 14 ++++++++ 5 files changed, 102 insertions(+), 1 deletion(-) create mode 100644 tests/ecc-386.c create mode 100755 tests/ecc-386.sh diff --git a/CMakeLists.txt b/CMakeLists.txt index 8929fc3fc..15c62e951 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -162,7 +162,7 @@ endif() ############################################################################### # other options -if( GRIB_TIMER ) +if( HAVE_GRIB_TIMER ) set( GRIB_TIMER 1 ) else() set( GRIB_TIMER 0 ) diff --git a/data/grib_data_files.txt b/data/grib_data_files.txt index 47f94f1c0..1a0cb7d99 100644 --- a/data/grib_data_files.txt +++ b/data/grib_data_files.txt @@ -84,3 +84,4 @@ timeRangeIndicator_5.grib tp_ecmwf.grib v.grib2 msl.octa.glob.grib1 +test_file.grib2 diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 17cdf2293..9eb014392 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -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 +) diff --git a/tests/ecc-386.c b/tests/ecc-386.c new file mode 100644 index 000000000..f82710b80 --- /dev/null +++ b/tests/ecc-386.c @@ -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 +#include +#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 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 diff --git a/tests/ecc-386.sh b/tests/ecc-386.sh new file mode 100755 index 000000000..61c1273e0 --- /dev/null +++ b/tests/ecc-386.sh @@ -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