From 76d857e42888300efb128d201dbdf7fb0be72945 Mon Sep 17 00:00:00 2001 From: Richard Berger Date: Thu, 11 Mar 2021 14:21:16 -0500 Subject: [PATCH] Add more tests for COMPRESS package --- unittest/formats/CMakeLists.txt | 10 +-- unittest/formats/compressed_dump_test.h | 6 +- .../formats/compressed_dump_test_main.cpp | 66 +++++++++++++++++++ unittest/formats/test_dump_atom.cpp | 1 + .../formats/test_dump_atom_compressed.cpp | 52 +++------------ unittest/formats/test_dump_cfg.cpp | 2 + unittest/formats/test_dump_cfg_compressed.cpp | 52 +++------------ unittest/formats/test_dump_custom.cpp | 1 + .../formats/test_dump_custom_compressed.cpp | 52 +++------------ .../formats/test_dump_local_compressed.cpp | 52 +++------------ unittest/formats/test_dump_xyz_compressed.cpp | 52 +++------------ unittest/testing/core.h | 2 +- 12 files changed, 129 insertions(+), 219 deletions(-) create mode 100644 unittest/formats/compressed_dump_test_main.cpp diff --git a/unittest/formats/CMakeLists.txt b/unittest/formats/CMakeLists.txt index 63c7759005..be0d14c47d 100644 --- a/unittest/formats/CMakeLists.txt +++ b/unittest/formats/CMakeLists.txt @@ -40,19 +40,19 @@ set_tests_properties(DumpAtom PROPERTIES ENVIRONMENT "LAMMPS_POTENTIALS=${LAMMPS if(PKG_COMPRESS) find_program(GZIP_BINARY NAMES gzip REQUIRED) - add_executable(test_dump_atom_compressed test_dump_atom_compressed.cpp) + add_executable(test_dump_atom_compressed test_dump_atom_compressed.cpp compressed_dump_test_main.cpp) target_link_libraries(test_dump_atom_compressed PRIVATE lammps GTest::GMock GTest::GTest) - add_executable(test_dump_custom_compressed test_dump_custom_compressed.cpp) + add_executable(test_dump_custom_compressed test_dump_custom_compressed.cpp compressed_dump_test_main.cpp) target_link_libraries(test_dump_custom_compressed PRIVATE lammps GTest::GMock GTest::GTest) - add_executable(test_dump_cfg_compressed test_dump_cfg_compressed.cpp) + add_executable(test_dump_cfg_compressed test_dump_cfg_compressed.cpp compressed_dump_test_main.cpp) target_link_libraries(test_dump_cfg_compressed PRIVATE lammps GTest::GMock GTest::GTest) - add_executable(test_dump_local_compressed test_dump_local_compressed.cpp) + add_executable(test_dump_local_compressed test_dump_local_compressed.cpp compressed_dump_test_main.cpp) target_link_libraries(test_dump_local_compressed PRIVATE lammps GTest::GMock GTest::GTest) - add_executable(test_dump_xyz_compressed test_dump_xyz_compressed.cpp) + add_executable(test_dump_xyz_compressed test_dump_xyz_compressed.cpp compressed_dump_test_main.cpp) target_link_libraries(test_dump_xyz_compressed PRIVATE lammps GTest::GMock GTest::GTest) add_test(NAME DumpAtomGZ COMMAND test_dump_atom_compressed gz WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) diff --git a/unittest/formats/compressed_dump_test.h b/unittest/formats/compressed_dump_test.h index c731a3b1b9..c8afb2aac3 100644 --- a/unittest/formats/compressed_dump_test.h +++ b/unittest/formats/compressed_dump_test.h @@ -17,9 +17,9 @@ #include "../testing/systems/melt.h" #include -const char * COMPRESS_SUFFIX = nullptr; -const char * COMPRESS_EXTENSION = nullptr; -char * COMPRESS_BINARY = nullptr; +extern const char * COMPRESS_SUFFIX; +extern const char * COMPRESS_EXTENSION; +extern char * COMPRESS_BINARY; class CompressedDumpTest : public MeltTest { protected: diff --git a/unittest/formats/compressed_dump_test_main.cpp b/unittest/formats/compressed_dump_test_main.cpp new file mode 100644 index 0000000000..e1334f1b9b --- /dev/null +++ b/unittest/formats/compressed_dump_test_main.cpp @@ -0,0 +1,66 @@ +/* ---------------------------------------------------------------------- + LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator + http://lammps.sandia.gov, Sandia National Laboratories + Steve Plimpton, sjplimp@sandia.gov + + Copyright (2003) Sandia Corporation. Under the terms of Contract + DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government retains + certain rights in this software. This software is distributed under + the GNU General Public License. + + See the README file in the top-level LAMMPS directory. +------------------------------------------------------------------------- */ + +#include "compressed_dump_test.h" +#include "../testing/utils.h" +#include "fmt/format.h" +#include "utils.h" +#include "gmock/gmock.h" +#include "gtest/gtest.h" + +#include + +const char * COMPRESS_SUFFIX = nullptr; +const char * COMPRESS_EXTENSION = nullptr; +char * COMPRESS_BINARY = nullptr; +bool verbose = false; + +int main(int argc, char **argv) +{ + MPI_Init(&argc, &argv); + ::testing::InitGoogleMock(&argc, argv); + + if (argc < 2) { + std::cerr << "usage: " << argv[0] << " (gz|zstd)\n\n" << std::endl; + return 1; + } + + if(strcmp(argv[1], "gz") == 0) { + COMPRESS_SUFFIX = "gz"; + COMPRESS_EXTENSION = "gz"; + } else if(strcmp(argv[1], "zstd") == 0) { + COMPRESS_SUFFIX = "zstd"; + COMPRESS_EXTENSION = "zst"; + } else { + std::cerr << "usage: " << argv[0] << " (gz|zstd)\n\n" << std::endl; + return 1; + } + + COMPRESS_BINARY = getenv("COMPRESS_BINARY"); + + // handle arguments passed via environment variable + if (const char *var = getenv("TEST_ARGS")) { + std::vector env = utils::split_words(var); + for (auto arg : env) { + if (arg == "-v") { + verbose = true; + } + } + } + + if ((argc > 1) && (strcmp(argv[1], "-v") == 0)) verbose = true; + + int rv = RUN_ALL_TESTS(); + MPI_Finalize(); + return rv; +} diff --git a/unittest/formats/test_dump_atom.cpp b/unittest/formats/test_dump_atom.cpp index 2472aabf2d..39cefdccea 100644 --- a/unittest/formats/test_dump_atom.cpp +++ b/unittest/formats/test_dump_atom.cpp @@ -24,6 +24,7 @@ using ::testing::Eq; char *BINARY2TXT_BINARY = nullptr; +bool verbose = false; class DumpAtomTest : public MeltTest { std::string dump_style = "atom"; diff --git a/unittest/formats/test_dump_atom_compressed.cpp b/unittest/formats/test_dump_atom_compressed.cpp index c0d1f3bdb6..ed591184c3 100644 --- a/unittest/formats/test_dump_atom_compressed.cpp +++ b/unittest/formats/test_dump_atom_compressed.cpp @@ -40,7 +40,11 @@ TEST_F(DumpAtomCompressTest, compressed_run0) auto text_file = text_dump_filename("run0.melt"); auto compressed_file = compressed_dump_filename("run0.melt"); - generate_text_and_compressed_dump(text_file, compressed_file, "", "", 0); + if(compression_style == "atom/zstd") { + generate_text_and_compressed_dump(text_file, compressed_file, "", "", "", "checksum yes", 0); + } else { + generate_text_and_compressed_dump(text_file, compressed_file, "", "", 0); + } TearDown(); @@ -71,7 +75,11 @@ TEST_F(DumpAtomCompressTest, compressed_multi_file_run1) auto compressed_file_0 = compressed_dump_filename(base_name_0); auto compressed_file_1 = compressed_dump_filename(base_name_1); - generate_text_and_compressed_dump(text_file, compressed_file, "", "", 1); + if(compression_style == "atom/zstd") { + generate_text_and_compressed_dump(text_file, compressed_file, "", "", "", "checksum no", 1); + } else { + generate_text_and_compressed_dump(text_file, compressed_file, "", "", 1); + } TearDown(); @@ -378,43 +386,3 @@ TEST_F(DumpAtomCompressTest, compressed_modify_clevel_run0) delete_file(compressed_file); delete_file(converted_file); } - -int main(int argc, char **argv) -{ - MPI_Init(&argc, &argv); - ::testing::InitGoogleMock(&argc, argv); - - if (argc < 2) { - std::cerr << "usage: " << argv[0] << " (gz|zstd)\n\n" << std::endl; - return 1; - } - - if(strcmp(argv[1], "gz") == 0) { - COMPRESS_SUFFIX = "gz"; - COMPRESS_EXTENSION = "gz"; - } else if(strcmp(argv[1], "zstd") == 0) { - COMPRESS_SUFFIX = "zstd"; - COMPRESS_EXTENSION = "zst"; - } else { - std::cerr << "usage: " << argv[0] << " (gz|zstd)\n\n" << std::endl; - return 1; - } - - COMPRESS_BINARY = getenv("COMPRESS_BINARY"); - - // handle arguments passed via environment variable - if (const char *var = getenv("TEST_ARGS")) { - std::vector env = utils::split_words(var); - for (auto arg : env) { - if (arg == "-v") { - verbose = true; - } - } - } - - if ((argc > 1) && (strcmp(argv[1], "-v") == 0)) verbose = true; - - int rv = RUN_ALL_TESTS(); - MPI_Finalize(); - return rv; -} diff --git a/unittest/formats/test_dump_cfg.cpp b/unittest/formats/test_dump_cfg.cpp index a7f331a0d0..327a9caca7 100644 --- a/unittest/formats/test_dump_cfg.cpp +++ b/unittest/formats/test_dump_cfg.cpp @@ -21,6 +21,8 @@ using ::testing::Eq; +bool verbose = false; + class DumpCfgTest : public MeltTest { std::string dump_style = "cfg"; diff --git a/unittest/formats/test_dump_cfg_compressed.cpp b/unittest/formats/test_dump_cfg_compressed.cpp index 66ab6921d5..834a71db70 100644 --- a/unittest/formats/test_dump_cfg_compressed.cpp +++ b/unittest/formats/test_dump_cfg_compressed.cpp @@ -46,7 +46,11 @@ TEST_F(DumpCfgCompressTest, compressed_run0) auto compressed_file_0 = compressed_dump_filename(base_name_0); auto fields = "mass type xs ys zs id proc procp1 x y z ix iy iz vx vy vz fx fy fz"; - generate_text_and_compressed_dump(text_files, compressed_files, fields, "", 0); + if(compression_style == "cfg/zstd") { + generate_text_and_compressed_dump(text_files, compressed_files, fields, fields, "", "checksum yes", 0); + } else { + generate_text_and_compressed_dump(text_files, compressed_files, fields, "", 0); + } TearDown(); @@ -106,7 +110,11 @@ TEST_F(DumpCfgCompressTest, compressed_multi_file_run1) auto compressed_file_1 = compressed_dump_filename(base_name_1); auto fields = "mass type xs ys zs id proc procp1 x y z ix iy iz vx vy vz fx fy fz"; - generate_text_and_compressed_dump(text_file, compressed_file, fields, "", 1); + if(compression_style == "cfg/zstd") { + generate_text_and_compressed_dump(text_file, compressed_file, fields, fields, "", "checksum no", 1); + } else { + generate_text_and_compressed_dump(text_file, compressed_file, fields, "", 1); + } TearDown(); @@ -273,43 +281,3 @@ TEST_F(DumpCfgCompressTest, compressed_modify_clevel_run0) delete_file(compressed_file_0); delete_file(converted_file_0); } - -int main(int argc, char **argv) -{ - MPI_Init(&argc, &argv); - ::testing::InitGoogleMock(&argc, argv); - - if (argc < 2) { - std::cerr << "usage: " << argv[0] << " (gz|zstd)\n\n" << std::endl; - return 1; - } - - if(strcmp(argv[1], "gz") == 0) { - COMPRESS_SUFFIX = "gz"; - COMPRESS_EXTENSION = "gz"; - } else if(strcmp(argv[1], "zstd") == 0) { - COMPRESS_SUFFIX = "zstd"; - COMPRESS_EXTENSION = "zst"; - } else { - std::cerr << "usage: " << argv[0] << " (gz|zstd)\n\n" << std::endl; - return 1; - } - - COMPRESS_BINARY = getenv("COMPRESS_BINARY"); - - // handle arguments passed via environment variable - if (const char *var = getenv("TEST_ARGS")) { - std::vector env = utils::split_words(var); - for (auto arg : env) { - if (arg == "-v") { - verbose = true; - } - } - } - - if ((argc > 1) && (strcmp(argv[1], "-v") == 0)) verbose = true; - - int rv = RUN_ALL_TESTS(); - MPI_Finalize(); - return rv; -} diff --git a/unittest/formats/test_dump_custom.cpp b/unittest/formats/test_dump_custom.cpp index dee27d9f0d..f2d7935426 100644 --- a/unittest/formats/test_dump_custom.cpp +++ b/unittest/formats/test_dump_custom.cpp @@ -22,6 +22,7 @@ using ::testing::Eq; char *BINARY2TXT_BINARY = nullptr; +bool verbose = false; class DumpCustomTest : public MeltTest { std::string dump_style = "custom"; diff --git a/unittest/formats/test_dump_custom_compressed.cpp b/unittest/formats/test_dump_custom_compressed.cpp index 8118442dbd..fb70206590 100644 --- a/unittest/formats/test_dump_custom_compressed.cpp +++ b/unittest/formats/test_dump_custom_compressed.cpp @@ -38,7 +38,11 @@ TEST_F(DumpCustomCompressTest, compressed_run1) auto compressed_file = compressed_dump_filename(base_name); auto fields = "id type proc x y z ix iy iz xs ys zs xu yu zu xsu ysu zsu vx vy vz fx fy fz"; - generate_text_and_compressed_dump(text_file, compressed_file, fields, "units yes", 1); + if(compression_style == "custom/zstd") { + generate_text_and_compressed_dump(text_file, compressed_file, fields, fields, "units yes", "units yes checksum yes", 1); + } else { + generate_text_and_compressed_dump(text_file, compressed_file, fields, "units yes", 1); + } TearDown(); @@ -96,7 +100,11 @@ TEST_F(DumpCustomCompressTest, compressed_multi_file_run1) auto compressed_file_1 = compressed_dump_filename(base_name_1); auto fields = "id type proc x y z ix iy iz xs ys zs xu yu zu xsu ysu zsu vx vy vz fx fy fz"; - generate_text_and_compressed_dump(text_file, compressed_file, fields, "", 1); + if(compression_style == "custom/zstd") { + generate_text_and_compressed_dump(text_file, compressed_file, fields, fields, "", "checksum no", 1); + } else { + generate_text_and_compressed_dump(text_file, compressed_file, fields, "", 1); + } TearDown(); @@ -256,43 +264,3 @@ TEST_F(DumpCustomCompressTest, compressed_modify_clevel_run0) delete_file(compressed_file); delete_file(converted_file); } - -int main(int argc, char **argv) -{ - MPI_Init(&argc, &argv); - ::testing::InitGoogleMock(&argc, argv); - - if (argc < 2) { - std::cerr << "usage: " << argv[0] << " (gz|zstd)\n\n" << std::endl; - return 1; - } - - if(strcmp(argv[1], "gz") == 0) { - COMPRESS_SUFFIX = "gz"; - COMPRESS_EXTENSION = "gz"; - } else if(strcmp(argv[1], "zstd") == 0) { - COMPRESS_SUFFIX = "zstd"; - COMPRESS_EXTENSION = "zst"; - } else { - std::cerr << "usage: " << argv[0] << " (gz|zstd)\n\n" << std::endl; - return 1; - } - - COMPRESS_BINARY = getenv("COMPRESS_BINARY"); - - // handle arguments passed via environment variable - if (const char *var = getenv("TEST_ARGS")) { - std::vector env = utils::split_words(var); - for (auto arg : env) { - if (arg == "-v") { - verbose = true; - } - } - } - - if ((argc > 1) && (strcmp(argv[1], "-v") == 0)) verbose = true; - - int rv = RUN_ALL_TESTS(); - MPI_Finalize(); - return rv; -} diff --git a/unittest/formats/test_dump_local_compressed.cpp b/unittest/formats/test_dump_local_compressed.cpp index b3c96b6edc..20f90984a1 100644 --- a/unittest/formats/test_dump_local_compressed.cpp +++ b/unittest/formats/test_dump_local_compressed.cpp @@ -49,7 +49,11 @@ TEST_F(DumpLocalCompressTest, compressed_run0) auto compressed_file_0 = compressed_dump_filename(base_name_0); auto fields = "index c_comp[1]"; - generate_text_and_compressed_dump(text_files, compressed_files, fields, "", 0); + if(compression_style == "local/zstd") { + generate_text_and_compressed_dump(text_files, compressed_files, fields, fields, "", "checksum yes", 0); + } else { + generate_text_and_compressed_dump(text_files, compressed_files, fields, "", 0); + } TearDown(); @@ -80,7 +84,11 @@ TEST_F(DumpLocalCompressTest, compressed_multi_file_run1) auto compressed_file_1 = compressed_dump_filename(base_name_1); auto fields = "index c_comp[1]"; - generate_text_and_compressed_dump(text_file, compressed_file, fields, "", 1); + if(compression_style == "local/zstd") { + generate_text_and_compressed_dump(text_file, compressed_file, fields, fields, "", "checksum no", 1); + } else { + generate_text_and_compressed_dump(text_file, compressed_file, fields, "", 1); + } TearDown(); @@ -246,43 +254,3 @@ TEST_F(DumpLocalCompressTest, compressed_modify_clevel_run0) delete_file(compressed_file); delete_file(converted_file); } - -int main(int argc, char **argv) -{ - MPI_Init(&argc, &argv); - ::testing::InitGoogleMock(&argc, argv); - - if (argc < 2) { - std::cerr << "usage: " << argv[0] << " (gz|zstd)\n\n" << std::endl; - return 1; - } - - if(strcmp(argv[1], "gz") == 0) { - COMPRESS_SUFFIX = "gz"; - COMPRESS_EXTENSION = "gz"; - } else if(strcmp(argv[1], "zstd") == 0) { - COMPRESS_SUFFIX = "zstd"; - COMPRESS_EXTENSION = "zst"; - } else { - std::cerr << "usage: " << argv[0] << " (gz|zstd)\n\n" << std::endl; - return 1; - } - - COMPRESS_BINARY = getenv("COMPRESS_BINARY"); - - // handle arguments passed via environment variable - if (const char *var = getenv("TEST_ARGS")) { - std::vector env = utils::split_words(var); - for (auto arg : env) { - if (arg == "-v") { - verbose = true; - } - } - } - - if ((argc > 1) && (strcmp(argv[1], "-v") == 0)) verbose = true; - - int rv = RUN_ALL_TESTS(); - MPI_Finalize(); - return rv; -} diff --git a/unittest/formats/test_dump_xyz_compressed.cpp b/unittest/formats/test_dump_xyz_compressed.cpp index 9a61c746a0..f80201872c 100644 --- a/unittest/formats/test_dump_xyz_compressed.cpp +++ b/unittest/formats/test_dump_xyz_compressed.cpp @@ -40,7 +40,11 @@ TEST_F(DumpXYZCompressTest, compressed_run0) auto text_file_0 = text_dump_filename(base_name_0); auto compressed_file_0 = compressed_dump_filename(base_name_0); - generate_text_and_compressed_dump(text_files, compressed_files, "", "", 0); + if(compression_style == "xyz/zstd") { + generate_text_and_compressed_dump(text_files, compressed_files, "", "", "", "checksum yes", 0); + } else { + generate_text_and_compressed_dump(text_files, compressed_files, "", "", 0); + } TearDown(); @@ -70,7 +74,11 @@ TEST_F(DumpXYZCompressTest, compressed_multi_file_run1) auto compressed_file_0 = compressed_dump_filename(base_name_0); auto compressed_file_1 = compressed_dump_filename(base_name_1); - generate_text_and_compressed_dump(text_file, compressed_file, "", "", 1); + if(compression_style == "xyz/zstd") { + generate_text_and_compressed_dump(text_file, compressed_file, "", "", "", "checksum no", 1); + } else { + generate_text_and_compressed_dump(text_file, compressed_file, "", "", 1); + } TearDown(); @@ -229,43 +237,3 @@ TEST_F(DumpXYZCompressTest, compressed_modify_clevel_run0) delete_file(compressed_file); delete_file(converted_file); } - -int main(int argc, char **argv) -{ - MPI_Init(&argc, &argv); - ::testing::InitGoogleMock(&argc, argv); - - if (argc < 2) { - std::cerr << "usage: " << argv[0] << " (gz|zstd)\n\n" << std::endl; - return 1; - } - - if(strcmp(argv[1], "gz") == 0) { - COMPRESS_SUFFIX = "gz"; - COMPRESS_EXTENSION = "gz"; - } else if(strcmp(argv[1], "zstd") == 0) { - COMPRESS_SUFFIX = "zstd"; - COMPRESS_EXTENSION = "zst"; - } else { - std::cerr << "usage: " << argv[0] << " (gz|zstd)\n\n" << std::endl; - return 1; - } - - COMPRESS_BINARY = getenv("COMPRESS_BINARY"); - - // handle arguments passed via environment variable - if (const char *var = getenv("TEST_ARGS")) { - std::vector env = utils::split_words(var); - for (auto arg : env) { - if (arg == "-v") { - verbose = true; - } - } - } - - if ((argc > 1) && (strcmp(argv[1], "-v") == 0)) verbose = true; - - int rv = RUN_ALL_TESTS(); - MPI_Finalize(); - return rv; -} diff --git a/unittest/testing/core.h b/unittest/testing/core.h index 5852f7fd06..6243eb219e 100644 --- a/unittest/testing/core.h +++ b/unittest/testing/core.h @@ -39,7 +39,7 @@ using ::testing::MatchesRegex; } // whether to print verbose output (i.e. not capturing LAMMPS screen output). -bool verbose = false; +extern bool verbose; class LAMMPSTest : public ::testing::Test { public: