Skip to content

Commit

Permalink
add zlib smoke test and refactor zlib cmake (#1190)
Browse files Browse the repository at this point in the history
* refactor zlib cmake and add smoke test

* update

* updates

index 53ed31e5a..a900e48f9 100644

* fix typo with zlib smoke buffer sizes
  • Loading branch information
cyrush committed Nov 7, 2023
1 parent 59d0e9e commit 77ccff2
Show file tree
Hide file tree
Showing 5 changed files with 85 additions and 17 deletions.
7 changes: 7 additions & 0 deletions src/cmake/Setup3rdParty.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,13 @@ if(ENABLE_RELAY_WEBSERVER)
include_directories(thirdparty_builtin/civetweb-0a95342/include)
endif()

################################
# Setup ZLib if available
################################
if(ZLIB_DIR)
include(cmake/thirdparty/SetupZlib.cmake)
endif()

if(ENABLE_PYTHON)
################################
# Setup includes for Python & Numpy
Expand Down
17 changes: 0 additions & 17 deletions src/cmake/thirdparty/SetupHDF5.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,6 @@ if(NOT HDF5_DIR)
MESSAGE(FATAL_ERROR "HDF5 support needs explicit HDF5_DIR")
endif()

#
# HDF5 1.8.x and 1.10.x when built static
# with cmake are not reporting zlib as a dep in libhdf5.settings,
# so we need find it and add it
#

# next check for ZLIB_DIR
# TODO: Decide if we want to be strict about this
# if(NOT ZLIB_DIR)
# MESSAGE(FATAL_ERROR "HDF5 support needs explicit ZLIB_DIR")
# endif()

if(ZLIB_DIR)
set(ZLIB_ROOT ${ZLIB_DIR})
find_package(ZLIB REQUIRED)
endif()

# find the absolute path w/ symlinks resolved of the passed HDF5_DIR,
# since sanity checks later need to compare against the real path
get_filename_component(HDF5_DIR_REAL "${HDF5_DIR}" REALPATH)
Expand Down
18 changes: 18 additions & 0 deletions src/cmake/thirdparty/SetupZlib.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Copyright (c) Lawrence Livermore National Security, LLC and other Conduit
# Project developers. See top-level LICENSE AND COPYRIGHT files for dates and
# other details. No copyright assignment is required to contribute to Conduit.
###############################################################################
#

###############################################################################
#
# Setup ZLIB
#
###############################################################################

if(ZLIB_DIR)
set(ZLIB_ROOT ${ZLIB_DIR})
find_package(ZLIB REQUIRED)
endif()

message(STATUS "ZLIB_LIBRARIES: ${ZLIB_LIBRARIES}")
5 changes: 5 additions & 0 deletions src/tests/thirdparty/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@ add_cpp_test(TEST t_fmt_smoke
# Optional TPL Unit Tests
################################

if(ZLIB_FOUND)
message(STATUS "Adding zlib smoke test")
add_cpp_test(TEST t_zlib_smoke DEPENDS_ON ZLIB::ZLIB)
endif()

if(ENABLE_RELAY_WEBSERVER)
message(STATUS "Relay Web Server enabled: Added related third party unit tests")
set(civet_test_deps ${CIVETWEB_LIB_DEPENDS})
Expand Down
55 changes: 55 additions & 0 deletions src/tests/thirdparty/t_zlib_smoke.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
// Copyright (c) Lawrence Livermore National Security, LLC and other Conduit
// Project developers. See top-level LICENSE AND COPYRIGHT files for dates and
// other details. No copyright assignment is required to contribute to Conduit.

//-----------------------------------------------------------------------------
///
/// file: t_zlib_smoke.cpp
///
//-----------------------------------------------------------------------------

#include "gtest/gtest.h"
#include "zlib.h"

//-----------------------------------------------------------------------------
TEST(zlib_smoke, zlib_basic)
{

// exercise compress and uncompress interface

Bytef compress_src[32];
Bytef compress_dest[64];
Bytef uncompress_dest[64];

uLongf compress_src_len = 32;
uLongf compress_dest_len = 64;
uLongf uncompress_dest_len = 64;

for(int i=0;i<32;i++)
{
compress_dest[i] = 0;
uncompress_dest[i] = 0;
// some pattern
compress_dest[i] = i > 4 && i < 28;
}

int compress_res = compress(compress_dest,
&compress_dest_len,
compress_src,
compress_src_len);

EXPECT_EQ(Z_OK,compress_res);


int uncompress_res = uncompress(uncompress_dest,
&uncompress_dest_len,
compress_dest,
compress_dest_len);
EXPECT_EQ(Z_OK,uncompress_res);

for(int i=0;i<32;i++)
{
EXPECT_EQ(compress_src[i],uncompress_dest[i]);
}
}

0 comments on commit 77ccff2

Please sign in to comment.