From f88fa89899ceeb59eab573ea5e2b54ba61585ff0 Mon Sep 17 00:00:00 2001 From: Edward Hartnett Date: Thu, 26 Oct 2023 04:51:48 -0600 Subject: [PATCH 1/2] adding test for jasper warnings --- src/enc_jpeg2000.c | 2 +- tests/CMakeLists.txt | 2 ++ tests/tst_jasper_warning.c | 51 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 54 insertions(+), 1 deletion(-) create mode 100644 tests/tst_jasper_warning.c diff --git a/src/enc_jpeg2000.c b/src/enc_jpeg2000.c index 8fa6699b..a663f3b8 100644 --- a/src/enc_jpeg2000.c +++ b/src/enc_jpeg2000.c @@ -151,7 +151,7 @@ enc_jpeg2000(unsigned char *cin, g2int width, g2int height, g2int nbits, /* static jas_std_allocator_t allocator; */ /* jas_std_allocator_init(&allocator); */ /* jas_conf_set_allocator(JAS_CAST(jas_std_allocator_t *, &allocator)); */ - jas_conf_set_max_mem_usage(10000000); + /* jas_conf_set_max_mem_usage(10000000); */ jas_conf_set_multithread(true); if (jas_init_library()) return G2_JASPER_INIT; diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 5da1d694..0637d66d 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -217,6 +217,7 @@ if(USE_Jasper OR USE_OpenJPEG) g2c_test(tst_jpeg) g2c_test(tst_addfield3) g2c_test(tst_addfield4) + g2c_test(tst_jasper_warning) endif() # Run these shell tests, which require Jasper. @@ -238,3 +239,4 @@ endif() + diff --git a/tests/tst_jasper_warning.c b/tests/tst_jasper_warning.c new file mode 100644 index 00000000..036706f8 --- /dev/null +++ b/tests/tst_jasper_warning.c @@ -0,0 +1,51 @@ +/* This is a test for the NCEPLIBS-g2c project. This test is for the + * JPEG jasper library. It tests that jasper is not writing any + * warnings to stdout. + * + * Ed Hartnett 10/26/23 + */ + +#include +#include +#include "grib2_int.h" + +#define DATA_LEN 4 +#define PACKED_LEN 200 + +int +main() +{ + int i; + + printf("Testing JPEG functions.\n"); + /* g2c_set_log_level(10); */ +#ifdef USE_JPEG2000 + printf("Testing enc_jpeg2000()/dec_jpeg2000() call..."); + { + unsigned char data[DATA_LEN] = {1, 2, 3, 4}; + g2int width = 2, height = 2, nbits = 4; + g2int ltype = 0, ratio = 0, retry = 0, jpclen = PACKED_LEN; + char outjpc[PACKED_LEN]; + g2int outfld[DATA_LEN]; + int ret; + + /* Encode some data. */ + if ((ret = enc_jpeg2000(data, width, height, nbits, ltype, + ratio, retry, outjpc, jpclen)) < 0) + return G2C_ERROR; + + /* Now decode it. */ + if ((ret = dec_jpeg2000(outjpc, jpclen, outfld))) + return G2C_ERROR; + + for (i = 0; i < DATA_LEN; i++) + { + if (outfld[i] != data[i]) + return G2C_ERROR; + } + } + printf("ok!\n"); +#endif + printf("SUCCESS!\n"); + return 0; +} From 5c5aee214204d98029d650c38f9c1be4adb46a8a Mon Sep 17 00:00:00 2001 From: Edward Hartnett Date: Thu, 26 Oct 2023 05:27:18 -0600 Subject: [PATCH 2/2] check for jasper warnings --- src/enc_jpeg2000.c | 2 +- tests/CMakeLists.txt | 17 ++++++++++++++--- tests/data/ref_tst_jasper_warning.txt | 3 +++ tests/run_jasper_warning_test.sh | 21 +++++++++++++++++++++ tests/tst_jasper_warning.c | 5 +---- 5 files changed, 40 insertions(+), 8 deletions(-) create mode 100644 tests/data/ref_tst_jasper_warning.txt create mode 100644 tests/run_jasper_warning_test.sh diff --git a/src/enc_jpeg2000.c b/src/enc_jpeg2000.c index a663f3b8..8fa6699b 100644 --- a/src/enc_jpeg2000.c +++ b/src/enc_jpeg2000.c @@ -151,7 +151,7 @@ enc_jpeg2000(unsigned char *cin, g2int width, g2int height, g2int nbits, /* static jas_std_allocator_t allocator; */ /* jas_std_allocator_init(&allocator); */ /* jas_conf_set_allocator(JAS_CAST(jas_std_allocator_t *, &allocator)); */ - /* jas_conf_set_max_mem_usage(10000000); */ + jas_conf_set_max_mem_usage(10000000); jas_conf_set_multithread(true); if (jas_init_library()) return G2_JASPER_INIT; diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 0637d66d..2c6dd066 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -69,6 +69,7 @@ set(REF_FILES "gdaswave.t00z.wcoast.0p16.f000.grib2.idx" "testgrib2.grb2" "ref_testgrib2.grb2.degrib2" "ref_gdaswave_2.grib1.idx" + "ref_tst_jasper_warning.txt" ) # Copy extra files if needed. @@ -89,12 +90,17 @@ FILE(COPY ${CMAKE_CURRENT_SOURCE_DIR}/../src/CodeFlag.xml FILE(COPY ${CMAKE_CURRENT_SOURCE_DIR}/../src/Template.xml DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/) -# Run a C program test. -function(g2c_test name) +# Build a C program test. +function(g2c_build_test name) add_executable(${name} ${name}.c util.c) target_link_libraries(${name} PUBLIC g2c::g2c) target_link_libraries(${name} PRIVATE ${LIBXML2_LIBRARIES}) target_include_directories(${name} PRIVATE "${LIBXML2_INCLUDE_DIR}") +endfunction() + +# Run a C program test. +function(g2c_test name) + g2c_build_test(${name}) add_test(NAME ${name} COMMAND ${name}) endfunction() @@ -217,7 +223,12 @@ if(USE_Jasper OR USE_OpenJPEG) g2c_test(tst_jpeg) g2c_test(tst_addfield3) g2c_test(tst_addfield4) - g2c_test(tst_jasper_warning) + g2c_build_test(tst_jasper_warning) +endif() + +# Test for warnings from jasper. +if(USE_Jasper) + gu_test(run_jasper_warning_test) endif() # Run these shell tests, which require Jasper. diff --git a/tests/data/ref_tst_jasper_warning.txt b/tests/data/ref_tst_jasper_warning.txt new file mode 100644 index 00000000..d6eb9645 --- /dev/null +++ b/tests/data/ref_tst_jasper_warning.txt @@ -0,0 +1,3 @@ +Testing JPEG functions. +Testing enc_jpeg2000()/dec_jpeg2000() call...ok! +SUCCESS! diff --git a/tests/run_jasper_warning_test.sh b/tests/run_jasper_warning_test.sh new file mode 100644 index 00000000..fad9fa5a --- /dev/null +++ b/tests/run_jasper_warning_test.sh @@ -0,0 +1,21 @@ +#!/bin/sh +# This is a test script for the NCEPLIBS-g2c project. +# +# This script runs a simple program that uses the jasper library, and +# then compares the output to expected output, to ensure that jasper +# is not writing any warning messages to stdout. +# +# Ed Hartnett, 10/26/23 + +set -e +echo "" +echo "*** Running jasper warning test" +set -x +pwd +./tst_jasper_warning &> tst_jasper_warning.txt + +# Check against expected output. +diff -w tst_jasper_warning.txt data/ref_tst_jasper_warning.txt + +echo "*** SUCCESS!" +exit 0 diff --git a/tests/tst_jasper_warning.c b/tests/tst_jasper_warning.c index 036706f8..df50b43a 100644 --- a/tests/tst_jasper_warning.c +++ b/tests/tst_jasper_warning.c @@ -15,11 +15,8 @@ int main() { - int i; - printf("Testing JPEG functions.\n"); /* g2c_set_log_level(10); */ -#ifdef USE_JPEG2000 printf("Testing enc_jpeg2000()/dec_jpeg2000() call..."); { unsigned char data[DATA_LEN] = {1, 2, 3, 4}; @@ -27,6 +24,7 @@ main() g2int ltype = 0, ratio = 0, retry = 0, jpclen = PACKED_LEN; char outjpc[PACKED_LEN]; g2int outfld[DATA_LEN]; + int i; int ret; /* Encode some data. */ @@ -45,7 +43,6 @@ main() } } printf("ok!\n"); -#endif printf("SUCCESS!\n"); return 0; }