From a548ea3bca516006a5ba2d1151ad89e57dc01e95 Mon Sep 17 00:00:00 2001 From: Richard Berger Date: Wed, 10 Mar 2021 13:40:10 -0500 Subject: [PATCH 01/14] Add more tests for dump atom/gz --- unittest/formats/test_dump_atom_gz.cpp | 177 ++++++++++++++++++++++++- unittest/testing/utils.h | 3 + 2 files changed, 177 insertions(+), 3 deletions(-) diff --git a/unittest/formats/test_dump_atom_gz.cpp b/unittest/formats/test_dump_atom_gz.cpp index c8f2eb500c..614910fcf2 100644 --- a/unittest/formats/test_dump_atom_gz.cpp +++ b/unittest/formats/test_dump_atom_gz.cpp @@ -52,14 +52,25 @@ public: void generate_text_and_compressed_dump(std::string text_file, std::string compressed_file, std::string compression_style, std::string dump_modify_options, int ntimesteps) + { + generate_text_and_compressed_dump(text_file, compressed_file, compression_style, + dump_modify_options, dump_modify_options, ntimesteps); + } + + void generate_text_and_compressed_dump(std::string text_file, std::string compressed_file, + std::string compression_style, + std::string text_options, std::string compressed_options, int ntimesteps) { if (!verbose) ::testing::internal::CaptureStdout(); command(fmt::format("dump id0 all {} 1 {}", dump_style, text_file)); command(fmt::format("dump id1 all {} 1 {}", compression_style, compressed_file)); - if (!dump_modify_options.empty()) { - command(fmt::format("dump_modify id0 {}", dump_modify_options)); - command(fmt::format("dump_modify id1 {}", dump_modify_options)); + if (!text_options.empty()) { + command(fmt::format("dump_modify id0 {}", text_options)); + } + + if (!compressed_options.empty()) { + command(fmt::format("dump_modify id1 {}", compressed_options)); } command(fmt::format("run {}", ntimesteps)); @@ -106,6 +117,124 @@ TEST_F(DumpAtomGZTest, compressed_run0) delete_file(converted_file); } +TEST_F(DumpAtomGZTest, compressed_multi_file_run1) +{ + if (!GZIP_BINARY) GTEST_SKIP(); + + auto text_file = "dump_gz_text_multi_file_run1_*.melt"; + auto compressed_file = "dump_gz_compressed_multi_file_run1_*.melt.gz"; + auto text_file_0 = "dump_gz_text_multi_file_run1_0.melt"; + auto text_file_1 = "dump_gz_text_multi_file_run1_1.melt"; + auto compressed_file_0 = "dump_gz_compressed_multi_file_run1_0.melt.gz"; + auto compressed_file_1 = "dump_gz_compressed_multi_file_run1_1.melt.gz"; + + generate_text_and_compressed_dump(text_file, compressed_file, "atom/gz", "", 1); + + TearDown(); + + ASSERT_FILE_EXISTS(text_file_0); + ASSERT_FILE_EXISTS(text_file_1); + ASSERT_FILE_EXISTS(compressed_file_0); + ASSERT_FILE_EXISTS(compressed_file_1); + + auto converted_file_0 = convert_compressed_to_text(compressed_file_0); + auto converted_file_1 = convert_compressed_to_text(compressed_file_1); + + ASSERT_THAT(converted_file_0, Eq("dump_gz_compressed_multi_file_run1_0.melt")); + ASSERT_THAT(converted_file_1, Eq("dump_gz_compressed_multi_file_run1_1.melt")); + ASSERT_FILE_EXISTS(converted_file_0); + ASSERT_FILE_EXISTS(converted_file_1); + ASSERT_FILE_EQUAL(text_file_0, converted_file_0); + ASSERT_FILE_EQUAL(text_file_1, converted_file_1); + + delete_file(text_file_0); + delete_file(text_file_1); + delete_file(compressed_file_0); + delete_file(compressed_file_1); + delete_file(converted_file_0); + delete_file(converted_file_1); +} + +TEST_F(DumpAtomGZTest, compressed_multi_file_with_pad_run1) +{ + if (!GZIP_BINARY) GTEST_SKIP(); + + auto text_file = "dump_gz_text_multi_file_pad_run1_*.melt"; + auto compressed_file = "dump_gz_compressed_multi_file_pad_run1_*.melt.gz"; + auto text_file_0 = "dump_gz_text_multi_file_pad_run1_000.melt"; + auto text_file_1 = "dump_gz_text_multi_file_pad_run1_001.melt"; + auto compressed_file_0 = "dump_gz_compressed_multi_file_pad_run1_000.melt.gz"; + auto compressed_file_1 = "dump_gz_compressed_multi_file_pad_run1_001.melt.gz"; + + generate_text_and_compressed_dump(text_file, compressed_file, "atom/gz", "pad 3", 1); + + TearDown(); + + ASSERT_FILE_EXISTS(text_file_0); + ASSERT_FILE_EXISTS(text_file_1); + ASSERT_FILE_EXISTS(compressed_file_0); + ASSERT_FILE_EXISTS(compressed_file_1); + + auto converted_file_0 = convert_compressed_to_text(compressed_file_0); + auto converted_file_1 = convert_compressed_to_text(compressed_file_1); + + ASSERT_THAT(converted_file_0, Eq("dump_gz_compressed_multi_file_pad_run1_000.melt")); + ASSERT_THAT(converted_file_1, Eq("dump_gz_compressed_multi_file_pad_run1_001.melt")); + ASSERT_FILE_EXISTS(converted_file_0); + ASSERT_FILE_EXISTS(converted_file_1); + ASSERT_FILE_EQUAL(text_file_0, converted_file_0); + ASSERT_FILE_EQUAL(text_file_1, converted_file_1); + + delete_file(text_file_0); + delete_file(text_file_1); + delete_file(compressed_file_0); + delete_file(compressed_file_1); + delete_file(converted_file_0); + delete_file(converted_file_1); +} + +TEST_F(DumpAtomGZTest, compressed_multi_file_with_maxfiles_run1) +{ + if (!GZIP_BINARY) GTEST_SKIP(); + + auto text_file = "dump_gz_text_multi_file_run1_*.melt"; + auto compressed_file = "dump_gz_compressed_multi_file_run1_*.melt.gz"; + auto text_file_0 = "dump_gz_text_multi_file_run1_0.melt"; + auto text_file_1 = "dump_gz_text_multi_file_run1_1.melt"; + auto text_file_2 = "dump_gz_text_multi_file_run1_2.melt"; + auto compressed_file_0 = "dump_gz_compressed_multi_file_run1_0.melt.gz"; + auto compressed_file_1 = "dump_gz_compressed_multi_file_run1_1.melt.gz"; + auto compressed_file_2 = "dump_gz_compressed_multi_file_run1_2.melt.gz"; + + generate_text_and_compressed_dump(text_file, compressed_file, "atom/gz", "maxfiles 2", 2); + + TearDown(); + + ASSERT_FILE_NOT_EXISTS(text_file_0); + ASSERT_FILE_EXISTS(text_file_1); + ASSERT_FILE_EXISTS(text_file_2); + ASSERT_FILE_NOT_EXISTS(compressed_file_0); + ASSERT_FILE_EXISTS(compressed_file_1); + ASSERT_FILE_EXISTS(compressed_file_2); + + auto converted_file_1 = convert_compressed_to_text(compressed_file_1); + auto converted_file_2 = convert_compressed_to_text(compressed_file_2); + + ASSERT_THAT(converted_file_1, Eq("dump_gz_compressed_multi_file_run1_1.melt")); + ASSERT_THAT(converted_file_2, Eq("dump_gz_compressed_multi_file_run1_2.melt")); + ASSERT_FILE_EXISTS(converted_file_1); + ASSERT_FILE_EXISTS(converted_file_2); + ASSERT_FILE_EQUAL(text_file_1, converted_file_1); + ASSERT_FILE_EQUAL(text_file_2, converted_file_2); + + delete_file(text_file_1); + delete_file(text_file_2); + delete_file(compressed_file_1); + delete_file(compressed_file_2); + delete_file(converted_file_1); + delete_file(converted_file_2); +} + TEST_F(DumpAtomGZTest, compressed_with_units_run0) { if (!GZIP_BINARY) GTEST_SKIP(); @@ -252,6 +381,48 @@ TEST_F(DumpAtomGZTest, compressed_triclinic_with_image_run0) delete_file(converted_file); } +TEST_F(DumpAtomGZTest, compressed_modify_bad_param) +{ + command("dump id1 all atom/gz 1 dump_gz_text_modify_bad_param_run0_*.melt.gz"); + + TEST_FAILURE(".*ERROR: Illegal dump_modify command: compression level must in the range of.*", + command("dump_modify id1 compression_level 12"); + ); +} + +TEST_F(DumpAtomGZTest, compressed_modify_multi_bad_param) +{ + command("dump id1 all atom/gz 1 dump_gz_text_modify_bad_param_run0_*.melt.gz"); + + TEST_FAILURE(".*ERROR: Illegal dump_modify command: compression level must in the range of.*", + command("dump_modify id1 pad 3 compression_level 12"); + ); +} + +TEST_F(DumpAtomGZTest, compressed_modify_clevel_run0) +{ + if (!GZIP_BINARY) GTEST_SKIP(); + + auto text_file = "dump_gz_text_modify_clevel_run0.melt"; + auto compressed_file = "dump_gz_compressed_modify_clevel_run0.melt.gz"; + + generate_text_and_compressed_dump(text_file, compressed_file, "atom/gz", "", "compression_level 3", 0); + + TearDown(); + + ASSERT_FILE_EXISTS(text_file); + ASSERT_FILE_EXISTS(compressed_file); + + auto converted_file = convert_compressed_to_text(compressed_file); + + ASSERT_THAT(converted_file, Eq("dump_gz_compressed_modify_clevel_run0.melt")); + ASSERT_FILE_EXISTS(converted_file); + ASSERT_FILE_EQUAL(text_file, converted_file); + delete_file(text_file); + delete_file(compressed_file); + delete_file(converted_file); +} + int main(int argc, char **argv) { MPI_Init(&argc, &argv); diff --git a/unittest/testing/utils.h b/unittest/testing/utils.h index 39a11a3e12..c76b37872a 100644 --- a/unittest/testing/utils.h +++ b/unittest/testing/utils.h @@ -70,6 +70,9 @@ static bool file_exists(const std::string &filename) } #define ASSERT_FILE_EXISTS(NAME) ASSERT_TRUE(file_exists(NAME)) +#define ASSERT_FILE_NOT_EXISTS(NAME) ASSERT_FALSE(file_exists(NAME)) #define ASSERT_FILE_EQUAL(FILE_A, FILE_B) ASSERT_TRUE(equal_lines(FILE_A, FILE_B)) + + #endif From aa625eaf656ec6ab5b54779c9f9d01add4ae11a5 Mon Sep 17 00:00:00 2001 From: Richard Berger Date: Wed, 10 Mar 2021 15:48:20 -0500 Subject: [PATCH 02/14] Unify dump atom/gz and atom/zstd tests --- unittest/formats/CMakeLists.txt | 17 +- ...m_gz.cpp => test_dump_atom_compressed.cpp} | 245 +++++++++------ unittest/formats/test_dump_atom_zstd.cpp | 284 ------------------ 3 files changed, 154 insertions(+), 392 deletions(-) rename unittest/formats/{test_dump_atom_gz.cpp => test_dump_atom_compressed.cpp} (58%) delete mode 100644 unittest/formats/test_dump_atom_zstd.cpp diff --git a/unittest/formats/CMakeLists.txt b/unittest/formats/CMakeLists.txt index 7b96cf2d32..7b19bfde46 100644 --- a/unittest/formats/CMakeLists.txt +++ b/unittest/formats/CMakeLists.txt @@ -40,11 +40,11 @@ set_tests_properties(DumpAtom PROPERTIES ENVIRONMENT "LAMMPS_POTENTIALS=${LAMMPS if(PKG_COMPRESS) find_program(GZIP_BINARY NAMES gzip REQUIRED) - add_executable(test_dump_atom_gz test_dump_atom_gz.cpp) - target_link_libraries(test_dump_atom_gz PRIVATE lammps GTest::GMock GTest::GTest) - add_test(NAME DumpAtomGZ COMMAND test_dump_atom_gz WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) - set_tests_properties(DumpAtomGZ PROPERTIES ENVIRONMENT "LAMMPS_POTENTIALS=${LAMMPS_POTENTIALS_DIR}") - set_tests_properties(DumpAtomGZ PROPERTIES ENVIRONMENT "GZIP_BINARY=${GZIP_BINARY}") + add_executable(test_dump_atom_compressed test_dump_atom_compressed.cpp) + target_link_libraries(test_dump_atom_compressed PRIVATE lammps GTest::GMock GTest::GTest) + + add_test(NAME DumpAtomGZ COMMAND test_dump_atom_compressed gz WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) + set_tests_properties(DumpAtomGZ PROPERTIES ENVIRONMENT "LAMMPS_POTENTIALS=${LAMMPS_POTENTIALS_DIR};COMPRESS_BINARY=${GZIP_BINARY}") add_executable(test_dump_custom_gz test_dump_custom_gz.cpp) target_link_libraries(test_dump_custom_gz PRIVATE lammps GTest::GMock GTest::GTest) @@ -75,11 +75,8 @@ if(PKG_COMPRESS) find_program(ZSTD_BINARY NAMES zstd) if(Zstd_FOUND AND ZSTD_BINARY) - add_executable(test_dump_atom_zstd test_dump_atom_zstd.cpp) - target_link_libraries(test_dump_atom_zstd PRIVATE lammps GTest::GMock GTest::GTest) - add_test(NAME DumpAtomZstd COMMAND test_dump_atom_zstd WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) - set_tests_properties(DumpAtomZstd PROPERTIES ENVIRONMENT "LAMMPS_POTENTIALS=${LAMMPS_POTENTIALS_DIR}") - set_tests_properties(DumpAtomZstd PROPERTIES ENVIRONMENT "ZSTD_BINARY=${ZSTD_BINARY}") + add_test(NAME DumpAtomZstd COMMAND test_dump_atom_compressed zstd WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) + set_tests_properties(DumpAtomZstd PROPERTIES ENVIRONMENT "LAMMPS_POTENTIALS=${LAMMPS_POTENTIALS_DIR};COMPRESS_BINARY=${ZSTD_BINARY}") add_executable(test_dump_custom_zstd test_dump_custom_zstd.cpp) target_link_libraries(test_dump_custom_zstd PRIVATE lammps GTest::GMock GTest::GTest) diff --git a/unittest/formats/test_dump_atom_gz.cpp b/unittest/formats/test_dump_atom_compressed.cpp similarity index 58% rename from unittest/formats/test_dump_atom_gz.cpp rename to unittest/formats/test_dump_atom_compressed.cpp index 614910fcf2..2f3f609744 100644 --- a/unittest/formats/test_dump_atom_gz.cpp +++ b/unittest/formats/test_dump_atom_compressed.cpp @@ -21,14 +21,36 @@ #include -char *GZIP_BINARY = nullptr; +const char * COMPRESS_SUFFIX = nullptr; +const char * COMPRESS_EXTENSION = nullptr; +char * COMPRESS_BINARY = nullptr; using ::testing::Eq; -class DumpAtomGZTest : public MeltTest { +class DumpAtomCompressTest : public MeltTest { +protected: std::string dump_style = "atom"; + std::string compression_style = ""; public: + void SetUp() override + { + MeltTest::SetUp(); + compression_style = fmt::format("{}/{}", dump_style, COMPRESS_SUFFIX); + } + + std::string text_dump_filename(std::string ident) { + return fmt::format("dump_{}_text_{}", COMPRESS_SUFFIX, ident); + } + + std::string compressed_dump_filename(std::string ident) { + return fmt::format("dump_{}_compressed_{}.{}", COMPRESS_SUFFIX, ident, COMPRESS_EXTENSION); + } + + std::string converted_dump_filename(std::string ident) { + return fmt::format("dump_{}_compressed_{}", COMPRESS_SUFFIX, ident); + } + void enable_triclinic() { if (!verbose) ::testing::internal::CaptureStdout(); @@ -50,15 +72,13 @@ public: } void generate_text_and_compressed_dump(std::string text_file, std::string compressed_file, - std::string compression_style, std::string dump_modify_options, int ntimesteps) { - generate_text_and_compressed_dump(text_file, compressed_file, compression_style, + generate_text_and_compressed_dump(text_file, compressed_file, dump_modify_options, dump_modify_options, ntimesteps); } void generate_text_and_compressed_dump(std::string text_file, std::string compressed_file, - std::string compression_style, std::string text_options, std::string compressed_options, int ntimesteps) { if (!verbose) ::testing::internal::CaptureStdout(); @@ -82,7 +102,7 @@ public: if (!verbose) ::testing::internal::CaptureStdout(); std::string converted_file = compressed_file.substr(0, compressed_file.find_last_of('.')); std::string cmdline = - fmt::format("{} -d -c {} > {}", GZIP_BINARY, compressed_file, converted_file); + fmt::format("{} -d -c {} > {}", COMPRESS_BINARY, compressed_file, converted_file); system(cmdline.c_str()); if (!verbose) ::testing::internal::GetCapturedStdout(); return converted_file; @@ -90,17 +110,17 @@ public: }; //------------------------------------------------------------------------------------------------- -// GZ compressed files +// compressed files //------------------------------------------------------------------------------------------------- -TEST_F(DumpAtomGZTest, compressed_run0) +TEST_F(DumpAtomCompressTest, compressed_run0) { - if (!GZIP_BINARY) GTEST_SKIP(); + if (!COMPRESS_BINARY) GTEST_SKIP(); - auto text_file = "dump_gz_text_run0.melt"; - auto compressed_file = "dump_gz_compressed_run0.melt.gz"; + 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, "atom/gz", "", 0); + generate_text_and_compressed_dump(text_file, compressed_file, "", 0); TearDown(); @@ -109,7 +129,7 @@ TEST_F(DumpAtomGZTest, compressed_run0) auto converted_file = convert_compressed_to_text(compressed_file); - ASSERT_THAT(converted_file, Eq("dump_gz_compressed_run0.melt")); + ASSERT_THAT(converted_file, Eq(converted_dump_filename("run0.melt"))); ASSERT_FILE_EXISTS(converted_file); ASSERT_FILE_EQUAL(text_file, converted_file); delete_file(text_file); @@ -117,31 +137,29 @@ TEST_F(DumpAtomGZTest, compressed_run0) delete_file(converted_file); } -TEST_F(DumpAtomGZTest, compressed_multi_file_run1) +TEST_F(DumpAtomCompressTest, compressed_multi_file_run1) { - if (!GZIP_BINARY) GTEST_SKIP(); + if (!COMPRESS_BINARY) GTEST_SKIP(); - auto text_file = "dump_gz_text_multi_file_run1_*.melt"; - auto compressed_file = "dump_gz_compressed_multi_file_run1_*.melt.gz"; - auto text_file_0 = "dump_gz_text_multi_file_run1_0.melt"; - auto text_file_1 = "dump_gz_text_multi_file_run1_1.melt"; - auto compressed_file_0 = "dump_gz_compressed_multi_file_run1_0.melt.gz"; - auto compressed_file_1 = "dump_gz_compressed_multi_file_run1_1.melt.gz"; + auto base_name = "multi_file_run1_*.melt"; + auto base_name_0 = "multi_file_run1_0.melt"; + auto base_name_1 = "multi_file_run1_1.melt"; + auto text_file = text_dump_filename(base_name); + auto text_file_0 = text_dump_filename(base_name_0); + auto text_file_1 = text_dump_filename(base_name_1); + auto compressed_file = compressed_dump_filename(base_name); + 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, "atom/gz", "", 1); + generate_text_and_compressed_dump(text_file, compressed_file, "", 1); TearDown(); - ASSERT_FILE_EXISTS(text_file_0); - ASSERT_FILE_EXISTS(text_file_1); - ASSERT_FILE_EXISTS(compressed_file_0); - ASSERT_FILE_EXISTS(compressed_file_1); - auto converted_file_0 = convert_compressed_to_text(compressed_file_0); auto converted_file_1 = convert_compressed_to_text(compressed_file_1); - ASSERT_THAT(converted_file_0, Eq("dump_gz_compressed_multi_file_run1_0.melt")); - ASSERT_THAT(converted_file_1, Eq("dump_gz_compressed_multi_file_run1_1.melt")); + ASSERT_THAT(converted_file_0, Eq(converted_dump_filename(base_name_0))); + ASSERT_THAT(converted_file_1, Eq(converted_dump_filename(base_name_1))); ASSERT_FILE_EXISTS(converted_file_0); ASSERT_FILE_EXISTS(converted_file_1); ASSERT_FILE_EQUAL(text_file_0, converted_file_0); @@ -155,18 +173,21 @@ TEST_F(DumpAtomGZTest, compressed_multi_file_run1) delete_file(converted_file_1); } -TEST_F(DumpAtomGZTest, compressed_multi_file_with_pad_run1) +TEST_F(DumpAtomCompressTest, compressed_multi_file_with_pad_run1) { - if (!GZIP_BINARY) GTEST_SKIP(); + if (!COMPRESS_BINARY) GTEST_SKIP(); - auto text_file = "dump_gz_text_multi_file_pad_run1_*.melt"; - auto compressed_file = "dump_gz_compressed_multi_file_pad_run1_*.melt.gz"; - auto text_file_0 = "dump_gz_text_multi_file_pad_run1_000.melt"; - auto text_file_1 = "dump_gz_text_multi_file_pad_run1_001.melt"; - auto compressed_file_0 = "dump_gz_compressed_multi_file_pad_run1_000.melt.gz"; - auto compressed_file_1 = "dump_gz_compressed_multi_file_pad_run1_001.melt.gz"; + auto base_name = "multi_file_pad_run1_*.melt"; + auto base_name_0 = "multi_file_pad_run1_000.melt"; + auto base_name_1 = "multi_file_pad_run1_001.melt"; + auto text_file = text_dump_filename(base_name); + auto text_file_0 = text_dump_filename(base_name_0); + auto text_file_1 = text_dump_filename(base_name_1); + auto compressed_file = compressed_dump_filename(base_name); + 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, "atom/gz", "pad 3", 1); + generate_text_and_compressed_dump(text_file, compressed_file, "pad 3", 1); TearDown(); @@ -178,8 +199,8 @@ TEST_F(DumpAtomGZTest, compressed_multi_file_with_pad_run1) auto converted_file_0 = convert_compressed_to_text(compressed_file_0); auto converted_file_1 = convert_compressed_to_text(compressed_file_1); - ASSERT_THAT(converted_file_0, Eq("dump_gz_compressed_multi_file_pad_run1_000.melt")); - ASSERT_THAT(converted_file_1, Eq("dump_gz_compressed_multi_file_pad_run1_001.melt")); + ASSERT_THAT(converted_file_0, Eq(converted_dump_filename(base_name_0))); + ASSERT_THAT(converted_file_1, Eq(converted_dump_filename(base_name_1))); ASSERT_FILE_EXISTS(converted_file_0); ASSERT_FILE_EXISTS(converted_file_1); ASSERT_FILE_EQUAL(text_file_0, converted_file_0); @@ -193,20 +214,24 @@ TEST_F(DumpAtomGZTest, compressed_multi_file_with_pad_run1) delete_file(converted_file_1); } -TEST_F(DumpAtomGZTest, compressed_multi_file_with_maxfiles_run1) +TEST_F(DumpAtomCompressTest, compressed_multi_file_with_maxfiles_run1) { - if (!GZIP_BINARY) GTEST_SKIP(); + if (!COMPRESS_BINARY) GTEST_SKIP(); - auto text_file = "dump_gz_text_multi_file_run1_*.melt"; - auto compressed_file = "dump_gz_compressed_multi_file_run1_*.melt.gz"; - auto text_file_0 = "dump_gz_text_multi_file_run1_0.melt"; - auto text_file_1 = "dump_gz_text_multi_file_run1_1.melt"; - auto text_file_2 = "dump_gz_text_multi_file_run1_2.melt"; - auto compressed_file_0 = "dump_gz_compressed_multi_file_run1_0.melt.gz"; - auto compressed_file_1 = "dump_gz_compressed_multi_file_run1_1.melt.gz"; - auto compressed_file_2 = "dump_gz_compressed_multi_file_run1_2.melt.gz"; + auto base_name = "multi_file_maxfiles_run1_*.melt"; + auto base_name_0 = "multi_file_maxfiles_run1_0.melt"; + auto base_name_1 = "multi_file_maxfiles_run1_1.melt"; + auto base_name_2 = "multi_file_maxfiles_run1_2.melt"; + auto text_file = text_dump_filename(base_name); + auto text_file_0 = text_dump_filename(base_name_0); + auto text_file_1 = text_dump_filename(base_name_1); + auto text_file_2 = text_dump_filename(base_name_2); + auto compressed_file = compressed_dump_filename(base_name); + auto compressed_file_0 = compressed_dump_filename(base_name_0); + auto compressed_file_1 = compressed_dump_filename(base_name_1); + auto compressed_file_2 = compressed_dump_filename(base_name_2); - generate_text_and_compressed_dump(text_file, compressed_file, "atom/gz", "maxfiles 2", 2); + generate_text_and_compressed_dump(text_file, compressed_file, "maxfiles 2", 2); TearDown(); @@ -220,8 +245,8 @@ TEST_F(DumpAtomGZTest, compressed_multi_file_with_maxfiles_run1) auto converted_file_1 = convert_compressed_to_text(compressed_file_1); auto converted_file_2 = convert_compressed_to_text(compressed_file_2); - ASSERT_THAT(converted_file_1, Eq("dump_gz_compressed_multi_file_run1_1.melt")); - ASSERT_THAT(converted_file_2, Eq("dump_gz_compressed_multi_file_run1_2.melt")); + ASSERT_THAT(converted_file_1, Eq(converted_dump_filename(base_name_1))); + ASSERT_THAT(converted_file_2, Eq(converted_dump_filename(base_name_2))); ASSERT_FILE_EXISTS(converted_file_1); ASSERT_FILE_EXISTS(converted_file_2); ASSERT_FILE_EQUAL(text_file_1, converted_file_1); @@ -235,14 +260,15 @@ TEST_F(DumpAtomGZTest, compressed_multi_file_with_maxfiles_run1) delete_file(converted_file_2); } -TEST_F(DumpAtomGZTest, compressed_with_units_run0) +TEST_F(DumpAtomCompressTest, compressed_with_units_run0) { - if (!GZIP_BINARY) GTEST_SKIP(); + if (!COMPRESS_BINARY) GTEST_SKIP(); - auto text_file = "dump_gz_text_with_units_run0.melt"; - auto compressed_file = "dump_gz_compressed_with_units_run0.melt.gz"; + auto base_name = "with_units_run0.melt"; + auto text_file = text_dump_filename(base_name); + auto compressed_file = compressed_dump_filename(base_name); - generate_text_and_compressed_dump(text_file, compressed_file, "atom/gz", "scale no units yes", + generate_text_and_compressed_dump(text_file, compressed_file, "scale no units yes", 0); TearDown(); @@ -259,15 +285,15 @@ TEST_F(DumpAtomGZTest, compressed_with_units_run0) delete_file(converted_file); } -TEST_F(DumpAtomGZTest, compressed_with_time_run0) +TEST_F(DumpAtomCompressTest, compressed_with_time_run0) { - if (!GZIP_BINARY) GTEST_SKIP(); + if (!COMPRESS_BINARY) GTEST_SKIP(); - auto text_file = "dump_gz_text_with_time_run0.melt"; - auto compressed_file = "dump_gz_compressed_with_time_run0.melt.gz"; + auto base_name = "with_time_run0.melt"; + auto text_file = text_dump_filename(base_name); + auto compressed_file = compressed_dump_filename(base_name); - generate_text_and_compressed_dump(text_file, compressed_file, "atom/gz", "scale no time yes", - 0); + generate_text_and_compressed_dump(text_file, compressed_file, "scale no time yes", 0); TearDown(); @@ -283,15 +309,16 @@ TEST_F(DumpAtomGZTest, compressed_with_time_run0) delete_file(converted_file); } -TEST_F(DumpAtomGZTest, compressed_triclinic_run0) +TEST_F(DumpAtomCompressTest, compressed_triclinic_run0) { - if (!GZIP_BINARY) GTEST_SKIP(); + if (!COMPRESS_BINARY) GTEST_SKIP(); - auto text_file = "dump_gz_text_tri_run0.melt"; - auto compressed_file = "dump_gz_compressed_tri_run0.melt.gz"; + auto base_name = "tri_run0.melt"; + auto text_file = text_dump_filename(base_name); + auto compressed_file = compressed_dump_filename(base_name); enable_triclinic(); - generate_text_and_compressed_dump(text_file, compressed_file, "atom/gz", "", 0); + generate_text_and_compressed_dump(text_file, compressed_file, "", 0); TearDown(); @@ -307,16 +334,16 @@ TEST_F(DumpAtomGZTest, compressed_triclinic_run0) delete_file(converted_file); } -TEST_F(DumpAtomGZTest, compressed_triclinic_with_units_run0) +TEST_F(DumpAtomCompressTest, compressed_triclinic_with_units_run0) { - if (!GZIP_BINARY) GTEST_SKIP(); + if (!COMPRESS_BINARY) GTEST_SKIP(); - auto text_file = "dump_gz_text_tri_with_units_run0.melt"; - auto compressed_file = "dump_gz_compressed_tri_with_units_run0.melt.gz"; + auto base_name = "tri_with_units_run0.melt"; + auto text_file = text_dump_filename(base_name); + auto compressed_file = compressed_dump_filename(base_name); enable_triclinic(); - generate_text_and_compressed_dump(text_file, compressed_file, "atom/gz", "scale no units yes", - 0); + generate_text_and_compressed_dump(text_file, compressed_file, "scale no units yes", 0); TearDown(); @@ -332,16 +359,16 @@ TEST_F(DumpAtomGZTest, compressed_triclinic_with_units_run0) delete_file(converted_file); } -TEST_F(DumpAtomGZTest, compressed_triclinic_with_time_run0) +TEST_F(DumpAtomCompressTest, compressed_triclinic_with_time_run0) { - if (!GZIP_BINARY) GTEST_SKIP(); + if (!COMPRESS_BINARY) GTEST_SKIP(); - auto text_file = "dump_gz_text_tri_with_time_run0.melt"; - auto compressed_file = "dump_gz_compressed_tri_with_time_run0.melt.gz"; + auto base_name = "tri_with_time_run0.melt"; + auto text_file = text_dump_filename(base_name); + auto compressed_file = compressed_dump_filename(base_name); enable_triclinic(); - generate_text_and_compressed_dump(text_file, compressed_file, "atom/gz", "scale no time yes", - 0); + generate_text_and_compressed_dump(text_file, compressed_file, "scale no time yes", 0); TearDown(); @@ -357,15 +384,16 @@ TEST_F(DumpAtomGZTest, compressed_triclinic_with_time_run0) delete_file(converted_file); } -TEST_F(DumpAtomGZTest, compressed_triclinic_with_image_run0) +TEST_F(DumpAtomCompressTest, compressed_triclinic_with_image_run0) { - if (!GZIP_BINARY) GTEST_SKIP(); + if (!COMPRESS_BINARY) GTEST_SKIP(); - auto text_file = "dump_gz_text_tri_with_image_run0.melt"; - auto compressed_file = "dump_gz_compressed_tri_with_image_run0.melt.gz"; + auto base_name = "tri_with_image_run0.melt"; + auto text_file = text_dump_filename(base_name); + auto compressed_file = compressed_dump_filename(base_name); enable_triclinic(); - generate_text_and_compressed_dump(text_file, compressed_file, "atom/gz", "image yes", 0); + generate_text_and_compressed_dump(text_file, compressed_file, "image yes", 0); TearDown(); @@ -381,32 +409,37 @@ TEST_F(DumpAtomGZTest, compressed_triclinic_with_image_run0) delete_file(converted_file); } -TEST_F(DumpAtomGZTest, compressed_modify_bad_param) +TEST_F(DumpAtomCompressTest, compressed_modify_bad_param) { - command("dump id1 all atom/gz 1 dump_gz_text_modify_bad_param_run0_*.melt.gz"); + if (compression_style != "atom/gz") GTEST_SKIP(); + + command(fmt::format("dump id1 all {} 1 {}", compression_style, compressed_dump_filename("modify_bad_param_run0_*.melt"))); TEST_FAILURE(".*ERROR: Illegal dump_modify command: compression level must in the range of.*", command("dump_modify id1 compression_level 12"); ); } -TEST_F(DumpAtomGZTest, compressed_modify_multi_bad_param) +TEST_F(DumpAtomCompressTest, compressed_modify_multi_bad_param) { - command("dump id1 all atom/gz 1 dump_gz_text_modify_bad_param_run0_*.melt.gz"); + if (compression_style != "atom/gz") GTEST_SKIP(); + + command(fmt::format("dump id1 all {} 1 {}", compression_style, compressed_dump_filename("modify_multi_bad_param_run0_*.melt"))); TEST_FAILURE(".*ERROR: Illegal dump_modify command: compression level must in the range of.*", command("dump_modify id1 pad 3 compression_level 12"); ); } -TEST_F(DumpAtomGZTest, compressed_modify_clevel_run0) +TEST_F(DumpAtomCompressTest, compressed_modify_clevel_run0) { - if (!GZIP_BINARY) GTEST_SKIP(); + if (!COMPRESS_BINARY) GTEST_SKIP(); - auto text_file = "dump_gz_text_modify_clevel_run0.melt"; - auto compressed_file = "dump_gz_compressed_modify_clevel_run0.melt.gz"; + auto base_name = "modify_clevel_run0.melt"; + auto text_file = text_dump_filename(base_name); + auto compressed_file = compressed_dump_filename(base_name); - generate_text_and_compressed_dump(text_file, compressed_file, "atom/gz", "", "compression_level 3", 0); + generate_text_and_compressed_dump(text_file, compressed_file, "", "compression_level 3", 0); TearDown(); @@ -415,7 +448,7 @@ TEST_F(DumpAtomGZTest, compressed_modify_clevel_run0) auto converted_file = convert_compressed_to_text(compressed_file); - ASSERT_THAT(converted_file, Eq("dump_gz_compressed_modify_clevel_run0.melt")); + ASSERT_THAT(converted_file, Eq(converted_dump_filename(base_name))); ASSERT_FILE_EXISTS(converted_file); ASSERT_FILE_EQUAL(text_file, converted_file); delete_file(text_file); @@ -428,6 +461,24 @@ 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); @@ -438,8 +489,6 @@ int main(int argc, char **argv) } } - GZIP_BINARY = getenv("GZIP_BINARY"); - if ((argc > 1) && (strcmp(argv[1], "-v") == 0)) verbose = true; int rv = RUN_ALL_TESTS(); diff --git a/unittest/formats/test_dump_atom_zstd.cpp b/unittest/formats/test_dump_atom_zstd.cpp deleted file mode 100644 index 41c2fd3c79..0000000000 --- a/unittest/formats/test_dump_atom_zstd.cpp +++ /dev/null @@ -1,284 +0,0 @@ -/* ---------------------------------------------------------------------- - LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator - https://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 "../testing/core.h" -#include "../testing/systems/melt.h" -#include "../testing/utils.h" -#include "fmt/format.h" -#include "utils.h" -#include "gmock/gmock.h" -#include "gtest/gtest.h" - -#include - -char *ZSTD_BINARY = nullptr; - -using ::testing::Eq; - -class DumpAtomZSTDTest : public MeltTest { - std::string dump_style = "atom"; - -public: - void enable_triclinic() - { - if (!verbose) ::testing::internal::CaptureStdout(); - command("change_box all triclinic"); - if (!verbose) ::testing::internal::GetCapturedStdout(); - } - - void generate_dump(std::string dump_file, std::string dump_modify_options, int ntimesteps) - { - if (!verbose) ::testing::internal::CaptureStdout(); - command(fmt::format("dump id all {} 1 {}", dump_style, dump_file)); - - if (!dump_modify_options.empty()) { - command(fmt::format("dump_modify id {}", dump_modify_options)); - } - - command(fmt::format("run {}", ntimesteps)); - if (!verbose) ::testing::internal::GetCapturedStdout(); - } - - void generate_text_and_compressed_dump(std::string text_file, std::string compressed_file, - std::string compression_style, - std::string dump_modify_options, int ntimesteps) - { - if (!verbose) ::testing::internal::CaptureStdout(); - command(fmt::format("dump id0 all {} 1 {}", dump_style, text_file)); - command(fmt::format("dump id1 all {} 1 {}", compression_style, compressed_file)); - - if (!dump_modify_options.empty()) { - command(fmt::format("dump_modify id0 {}", dump_modify_options)); - command(fmt::format("dump_modify id1 {}", dump_modify_options)); - } - - command(fmt::format("run {}", ntimesteps)); - if (!verbose) ::testing::internal::GetCapturedStdout(); - } - - std::string convert_compressed_to_text(std::string compressed_file) - { - if (!verbose) ::testing::internal::CaptureStdout(); - std::string converted_file = compressed_file.substr(0, compressed_file.find_last_of('.')); - std::string cmdline = - fmt::format("{} -d -c {} > {}", ZSTD_BINARY, compressed_file, converted_file); - system(cmdline.c_str()); - if (!verbose) ::testing::internal::GetCapturedStdout(); - return converted_file; - } -}; - -//------------------------------------------------------------------------------------------------- -// ZSTD compressed files -//------------------------------------------------------------------------------------------------- - -TEST_F(DumpAtomZSTDTest, compressed_run0) -{ - if (!ZSTD_BINARY) GTEST_SKIP(); - - auto text_file = "dump_zstd_text_run0.melt"; - auto compressed_file = "dump_zstd_compressed_run0.melt.zst"; - - generate_text_and_compressed_dump(text_file, compressed_file, "atom/zstd", "", 0); - - // make sure file is closed - TearDown(); - - ASSERT_FILE_EXISTS(text_file); - ASSERT_FILE_EXISTS(compressed_file); - - auto converted_file = convert_compressed_to_text(compressed_file); - - ASSERT_THAT(converted_file, Eq("dump_zstd_compressed_run0.melt")); - ASSERT_FILE_EXISTS(converted_file); - ASSERT_FILE_EQUAL(text_file, converted_file); - delete_file(text_file); - delete_file(compressed_file); - delete_file(converted_file); -} - -TEST_F(DumpAtomZSTDTest, compressed_with_units_run0) -{ - if (!ZSTD_BINARY) GTEST_SKIP(); - - auto text_file = "dump_zstd_text_with_units_run0.melt"; - auto compressed_file = "dump_zstd_compressed_with_units_run0.melt.zst"; - - generate_text_and_compressed_dump(text_file, compressed_file, "atom/zstd", "scale no units yes", - 0); - - // make sure file is closed - TearDown(); - - ASSERT_FILE_EXISTS(text_file); - ASSERT_FILE_EXISTS(compressed_file); - - auto converted_file = convert_compressed_to_text(compressed_file); - - ASSERT_FILE_EXISTS(converted_file); - ASSERT_FILE_EQUAL(text_file, converted_file); - delete_file(text_file); - delete_file(compressed_file); - delete_file(converted_file); -} - -TEST_F(DumpAtomZSTDTest, compressed_with_time_run0) -{ - if (!ZSTD_BINARY) GTEST_SKIP(); - - auto text_file = "dump_zstd_text_with_time_run0.melt"; - auto compressed_file = "dump_zstd_compressed_with_time_run0.melt.zst"; - - generate_text_and_compressed_dump(text_file, compressed_file, "atom/zstd", "scale no time yes", - 0); - - // make sure file is closed - TearDown(); - - ASSERT_FILE_EXISTS(text_file); - ASSERT_FILE_EXISTS(compressed_file); - - auto converted_file = convert_compressed_to_text(compressed_file); - - ASSERT_FILE_EXISTS(converted_file); - ASSERT_FILE_EQUAL(text_file, converted_file); - delete_file(text_file); - delete_file(compressed_file); - delete_file(converted_file); -} - -TEST_F(DumpAtomZSTDTest, compressed_triclinic_run0) -{ - if (!ZSTD_BINARY) GTEST_SKIP(); - - auto text_file = "dump_zstd_text_tri_run0.melt"; - auto compressed_file = "dump_zstd_compressed_tri_run0.melt.zst"; - - enable_triclinic(); - generate_text_and_compressed_dump(text_file, compressed_file, "atom/zstd", "", 0); - - // make sure file is closed - TearDown(); - - ASSERT_FILE_EXISTS(text_file); - ASSERT_FILE_EXISTS(compressed_file); - - auto converted_file = convert_compressed_to_text(compressed_file); - - ASSERT_FILE_EXISTS(converted_file); - ASSERT_FILE_EQUAL(text_file, converted_file); - delete_file(text_file); - delete_file(compressed_file); - delete_file(converted_file); -} - -TEST_F(DumpAtomZSTDTest, compressed_triclinic_with_units_run0) -{ - if (!ZSTD_BINARY) GTEST_SKIP(); - - auto text_file = "dump_zstd_text_tri_with_units_run0.melt"; - auto compressed_file = "dump_zstd_compressed_tri_with_units_run0.melt.zst"; - - enable_triclinic(); - generate_text_and_compressed_dump(text_file, compressed_file, "atom/zstd", "scale no units yes", - 0); - - // make sure file is closed - TearDown(); - - ASSERT_FILE_EXISTS(text_file); - ASSERT_FILE_EXISTS(compressed_file); - - auto converted_file = convert_compressed_to_text(compressed_file); - - ASSERT_FILE_EXISTS(converted_file); - ASSERT_FILE_EQUAL(text_file, converted_file); - delete_file(text_file); - delete_file(compressed_file); - delete_file(converted_file); -} - -TEST_F(DumpAtomZSTDTest, compressed_triclinic_with_time_run0) -{ - if (!ZSTD_BINARY) GTEST_SKIP(); - - auto text_file = "dump_zstd_text_tri_with_time_run0.melt"; - auto compressed_file = "dump_zstd_compressed_tri_with_time_run0.melt.zst"; - - enable_triclinic(); - generate_text_and_compressed_dump(text_file, compressed_file, "atom/zstd", "scale no time yes", - 0); - - // make sure file is closed - TearDown(); - - ASSERT_FILE_EXISTS(text_file); - ASSERT_FILE_EXISTS(compressed_file); - - auto converted_file = convert_compressed_to_text(compressed_file); - - ASSERT_FILE_EXISTS(converted_file); - ASSERT_FILE_EQUAL(text_file, converted_file); - delete_file(text_file); - delete_file(compressed_file); - delete_file(converted_file); -} - -TEST_F(DumpAtomZSTDTest, compressed_triclinic_with_image_run0) -{ - if (!ZSTD_BINARY) GTEST_SKIP(); - - auto text_file = "dump_zstd_text_tri_with_image_run0.melt"; - auto compressed_file = "dump_zstd_compressed_tri_with_image_run0.melt.zst"; - - enable_triclinic(); - generate_text_and_compressed_dump(text_file, compressed_file, "atom/zstd", "image yes", 0); - - // make sure file is closed - TearDown(); - - ASSERT_FILE_EXISTS(text_file); - ASSERT_FILE_EXISTS(compressed_file); - - auto converted_file = convert_compressed_to_text(compressed_file); - - ASSERT_FILE_EXISTS(converted_file); - ASSERT_FILE_EQUAL(text_file, converted_file); - delete_file(text_file); - delete_file(compressed_file); - delete_file(converted_file); -} - -int main(int argc, char **argv) -{ - MPI_Init(&argc, &argv); - ::testing::InitGoogleMock(&argc, argv); - - // 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; - } - } - } - - ZSTD_BINARY = getenv("ZSTD_BINARY"); - - if ((argc > 1) && (strcmp(argv[1], "-v") == 0)) verbose = true; - - int rv = RUN_ALL_TESTS(); - MPI_Finalize(); - return rv; -} From 20a546c824ece52221b75513906ef98cb1bdc889 Mon Sep 17 00:00:00 2001 From: Richard Berger Date: Wed, 10 Mar 2021 16:08:51 -0500 Subject: [PATCH 03/14] Move testcase in its own file --- unittest/formats/compressed_dump_test.h | 104 ++++++++++++++++++ .../formats/test_dump_atom_compressed.cpp | 86 +-------------- 2 files changed, 107 insertions(+), 83 deletions(-) create mode 100644 unittest/formats/compressed_dump_test.h diff --git a/unittest/formats/compressed_dump_test.h b/unittest/formats/compressed_dump_test.h new file mode 100644 index 0000000000..80b8550060 --- /dev/null +++ b/unittest/formats/compressed_dump_test.h @@ -0,0 +1,104 @@ +/* ---------------------------------------------------------------------- + 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. +------------------------------------------------------------------------- */ +#ifndef TESTCASE_COMPRESSED_DUMP__H +#define TESTCASE_COMPRESSED_DUMP__H + +#include "../testing/core.h" +#include "../testing/systems/melt.h" +#include + +const char * COMPRESS_SUFFIX = nullptr; +const char * COMPRESS_EXTENSION = nullptr; +char * COMPRESS_BINARY = nullptr; + +class CompressedDumpTest : public MeltTest { +protected: + std::string dump_style; + std::string compression_style; + +public: + CompressedDumpTest(const std::string & dump_style) : MeltTest(), dump_style(dump_style) { + compression_style = fmt::format("{}/{}", dump_style, COMPRESS_SUFFIX); + } + + std::string text_dump_filename(std::string ident) { + return fmt::format("dump_{}_text_{}", COMPRESS_SUFFIX, ident); + } + + std::string compressed_dump_filename(std::string ident) { + return fmt::format("dump_{}_compressed_{}.{}", COMPRESS_SUFFIX, ident, COMPRESS_EXTENSION); + } + + std::string converted_dump_filename(std::string ident) { + return fmt::format("dump_{}_compressed_{}", COMPRESS_SUFFIX, ident); + } + + void enable_triclinic() + { + if (!verbose) ::testing::internal::CaptureStdout(); + command("change_box all triclinic"); + if (!verbose) ::testing::internal::GetCapturedStdout(); + } + + void generate_dump(std::string dump_file, std::string dump_modify_options, int ntimesteps) + { + if (!verbose) ::testing::internal::CaptureStdout(); + command(fmt::format("dump id all {} 1 {}", dump_style, dump_file)); + + if (!dump_modify_options.empty()) { + command(fmt::format("dump_modify id {}", dump_modify_options)); + } + + command(fmt::format("run {}", ntimesteps)); + if (!verbose) ::testing::internal::GetCapturedStdout(); + } + + void generate_text_and_compressed_dump(std::string text_file, std::string compressed_file, + std::string dump_modify_options, int ntimesteps) + { + generate_text_and_compressed_dump(text_file, compressed_file, + dump_modify_options, dump_modify_options, ntimesteps); + } + + void generate_text_and_compressed_dump(std::string text_file, std::string compressed_file, + std::string text_options, std::string compressed_options, int ntimesteps) + { + if (!verbose) ::testing::internal::CaptureStdout(); + command(fmt::format("dump id0 all {} 1 {}", dump_style, text_file)); + command(fmt::format("dump id1 all {} 1 {}", compression_style, compressed_file)); + + if (!text_options.empty()) { + command(fmt::format("dump_modify id0 {}", text_options)); + } + + if (!compressed_options.empty()) { + command(fmt::format("dump_modify id1 {}", compressed_options)); + } + + command(fmt::format("run {}", ntimesteps)); + if (!verbose) ::testing::internal::GetCapturedStdout(); + } + + std::string convert_compressed_to_text(std::string compressed_file) + { + if (!verbose) ::testing::internal::CaptureStdout(); + std::string converted_file = compressed_file.substr(0, compressed_file.find_last_of('.')); + std::string cmdline = + fmt::format("{} -d -c {} > {}", COMPRESS_BINARY, compressed_file, converted_file); + system(cmdline.c_str()); + if (!verbose) ::testing::internal::GetCapturedStdout(); + return converted_file; + } +}; + +#endif diff --git a/unittest/formats/test_dump_atom_compressed.cpp b/unittest/formats/test_dump_atom_compressed.cpp index 2f3f609744..e33366801e 100644 --- a/unittest/formats/test_dump_atom_compressed.cpp +++ b/unittest/formats/test_dump_atom_compressed.cpp @@ -11,9 +11,8 @@ See the README file in the top-level LAMMPS directory. ------------------------------------------------------------------------- */ -#include "../testing/core.h" -#include "../testing/systems/melt.h" #include "../testing/utils.h" +#include "compressed_dump_test.h" #include "fmt/format.h" #include "utils.h" #include "gmock/gmock.h" @@ -21,91 +20,12 @@ #include -const char * COMPRESS_SUFFIX = nullptr; -const char * COMPRESS_EXTENSION = nullptr; -char * COMPRESS_BINARY = nullptr; using ::testing::Eq; -class DumpAtomCompressTest : public MeltTest { -protected: - std::string dump_style = "atom"; - std::string compression_style = ""; - +class DumpAtomCompressTest : public CompressedDumpTest { public: - void SetUp() override - { - MeltTest::SetUp(); - compression_style = fmt::format("{}/{}", dump_style, COMPRESS_SUFFIX); - } - - std::string text_dump_filename(std::string ident) { - return fmt::format("dump_{}_text_{}", COMPRESS_SUFFIX, ident); - } - - std::string compressed_dump_filename(std::string ident) { - return fmt::format("dump_{}_compressed_{}.{}", COMPRESS_SUFFIX, ident, COMPRESS_EXTENSION); - } - - std::string converted_dump_filename(std::string ident) { - return fmt::format("dump_{}_compressed_{}", COMPRESS_SUFFIX, ident); - } - - void enable_triclinic() - { - if (!verbose) ::testing::internal::CaptureStdout(); - command("change_box all triclinic"); - if (!verbose) ::testing::internal::GetCapturedStdout(); - } - - void generate_dump(std::string dump_file, std::string dump_modify_options, int ntimesteps) - { - if (!verbose) ::testing::internal::CaptureStdout(); - command(fmt::format("dump id all {} 1 {}", dump_style, dump_file)); - - if (!dump_modify_options.empty()) { - command(fmt::format("dump_modify id {}", dump_modify_options)); - } - - command(fmt::format("run {}", ntimesteps)); - if (!verbose) ::testing::internal::GetCapturedStdout(); - } - - void generate_text_and_compressed_dump(std::string text_file, std::string compressed_file, - std::string dump_modify_options, int ntimesteps) - { - generate_text_and_compressed_dump(text_file, compressed_file, - dump_modify_options, dump_modify_options, ntimesteps); - } - - void generate_text_and_compressed_dump(std::string text_file, std::string compressed_file, - std::string text_options, std::string compressed_options, int ntimesteps) - { - if (!verbose) ::testing::internal::CaptureStdout(); - command(fmt::format("dump id0 all {} 1 {}", dump_style, text_file)); - command(fmt::format("dump id1 all {} 1 {}", compression_style, compressed_file)); - - if (!text_options.empty()) { - command(fmt::format("dump_modify id0 {}", text_options)); - } - - if (!compressed_options.empty()) { - command(fmt::format("dump_modify id1 {}", compressed_options)); - } - - command(fmt::format("run {}", ntimesteps)); - if (!verbose) ::testing::internal::GetCapturedStdout(); - } - - std::string convert_compressed_to_text(std::string compressed_file) - { - if (!verbose) ::testing::internal::CaptureStdout(); - std::string converted_file = compressed_file.substr(0, compressed_file.find_last_of('.')); - std::string cmdline = - fmt::format("{} -d -c {} > {}", COMPRESS_BINARY, compressed_file, converted_file); - system(cmdline.c_str()); - if (!verbose) ::testing::internal::GetCapturedStdout(); - return converted_file; + DumpAtomCompressTest() : CompressedDumpTest("atom") { } }; From aed8608c7c008f5ae91e6c1a31803d5368df2e45 Mon Sep 17 00:00:00 2001 From: Richard Berger Date: Thu, 11 Mar 2021 11:59:49 -0500 Subject: [PATCH 04/14] Unify dump cfg/gz and cfg/zstd tests --- unittest/formats/CMakeLists.txt | 16 +-- unittest/formats/compressed_dump_test.h | 19 +-- .../formats/test_dump_atom_compressed.cpp | 23 ++- unittest/formats/test_dump_cfg_compressed.cpp | 132 +++++++++++++++++ unittest/formats/test_dump_cfg_gz.cpp | 133 ------------------ unittest/formats/test_dump_cfg_zstd.cpp | 133 ------------------ 6 files changed, 160 insertions(+), 296 deletions(-) create mode 100644 unittest/formats/test_dump_cfg_compressed.cpp delete mode 100644 unittest/formats/test_dump_cfg_gz.cpp delete mode 100644 unittest/formats/test_dump_cfg_zstd.cpp diff --git a/unittest/formats/CMakeLists.txt b/unittest/formats/CMakeLists.txt index 7b19bfde46..cd02aed6b0 100644 --- a/unittest/formats/CMakeLists.txt +++ b/unittest/formats/CMakeLists.txt @@ -52,11 +52,10 @@ if(PKG_COMPRESS) set_tests_properties(DumpCustomGZ PROPERTIES ENVIRONMENT "LAMMPS_POTENTIALS=${LAMMPS_POTENTIALS_DIR}") set_tests_properties(DumpCustomGZ PROPERTIES ENVIRONMENT "GZIP_BINARY=${GZIP_BINARY}") - add_executable(test_dump_cfg_gz test_dump_cfg_gz.cpp) - target_link_libraries(test_dump_cfg_gz PRIVATE lammps GTest::GMock GTest::GTest) - add_test(NAME DumpCfgGZ COMMAND test_dump_cfg_gz WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) - set_tests_properties(DumpCfgGZ PROPERTIES ENVIRONMENT "LAMMPS_POTENTIALS=${LAMMPS_POTENTIALS_DIR}") - set_tests_properties(DumpCfgGZ PROPERTIES ENVIRONMENT "GZIP_BINARY=${GZIP_BINARY}") + add_executable(test_dump_cfg_compressed test_dump_cfg_compressed.cpp) + target_link_libraries(test_dump_cfg_compressed PRIVATE lammps GTest::GMock GTest::GTest) + add_test(NAME DumpCfgGZ COMMAND test_dump_cfg_compressed gz WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) + set_tests_properties(DumpCfgGZ PROPERTIES ENVIRONMENT "LAMMPS_POTENTIALS=${LAMMPS_POTENTIALS_DIR};COMPRESS_BINARY=${GZIP_BINARY}") add_executable(test_dump_xyz_gz test_dump_xyz_gz.cpp) target_link_libraries(test_dump_xyz_gz PRIVATE lammps GTest::GMock GTest::GTest) @@ -84,11 +83,8 @@ if(PKG_COMPRESS) set_tests_properties(DumpCustomZstd PROPERTIES ENVIRONMENT "LAMMPS_POTENTIALS=${LAMMPS_POTENTIALS_DIR}") set_tests_properties(DumpCustomZstd PROPERTIES ENVIRONMENT "ZSTD_BINARY=${ZSTD_BINARY}") - add_executable(test_dump_cfg_zstd test_dump_cfg_zstd.cpp) - target_link_libraries(test_dump_cfg_zstd PRIVATE lammps GTest::GMock GTest::GTest) - add_test(NAME DumpCfgZstd COMMAND test_dump_cfg_zstd WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) - set_tests_properties(DumpCfgZstd PROPERTIES ENVIRONMENT "LAMMPS_POTENTIALS=${LAMMPS_POTENTIALS_DIR}") - set_tests_properties(DumpCfgZstd PROPERTIES ENVIRONMENT "ZSTD_BINARY=${ZSTD_BINARY}") + add_test(NAME DumpCfgZstd COMMAND test_dump_cfg_compressed zstd WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) + set_tests_properties(DumpCfgZstd PROPERTIES ENVIRONMENT "LAMMPS_POTENTIALS=${LAMMPS_POTENTIALS_DIR};COMPRESS_BINARY=${ZSTD_BINARY}") add_executable(test_dump_xyz_zstd test_dump_xyz_zstd.cpp) target_link_libraries(test_dump_xyz_zstd PRIVATE lammps GTest::GMock GTest::GTest) diff --git a/unittest/formats/compressed_dump_test.h b/unittest/formats/compressed_dump_test.h index 80b8550060..c731a3b1b9 100644 --- a/unittest/formats/compressed_dump_test.h +++ b/unittest/formats/compressed_dump_test.h @@ -64,25 +64,28 @@ public: } void generate_text_and_compressed_dump(std::string text_file, std::string compressed_file, - std::string dump_modify_options, int ntimesteps) + std::string dump_options, std::string dump_modify_options, int ntimesteps) { generate_text_and_compressed_dump(text_file, compressed_file, + dump_options, dump_options, dump_modify_options, dump_modify_options, ntimesteps); } void generate_text_and_compressed_dump(std::string text_file, std::string compressed_file, - std::string text_options, std::string compressed_options, int ntimesteps) + std::string text_options, std::string compressed_options, + std::string text_modify_options, std::string compressed_modify_options, + int ntimesteps) { if (!verbose) ::testing::internal::CaptureStdout(); - command(fmt::format("dump id0 all {} 1 {}", dump_style, text_file)); - command(fmt::format("dump id1 all {} 1 {}", compression_style, compressed_file)); + command(fmt::format("dump id0 all {} 1 {} {}", dump_style, text_file, text_options)); + command(fmt::format("dump id1 all {} 1 {} {}", compression_style, compressed_file, compressed_options)); - if (!text_options.empty()) { - command(fmt::format("dump_modify id0 {}", text_options)); + if (!text_modify_options.empty()) { + command(fmt::format("dump_modify id0 {}", text_modify_options)); } - if (!compressed_options.empty()) { - command(fmt::format("dump_modify id1 {}", compressed_options)); + if (!compressed_modify_options.empty()) { + command(fmt::format("dump_modify id1 {}", compressed_modify_options)); } command(fmt::format("run {}", ntimesteps)); diff --git a/unittest/formats/test_dump_atom_compressed.cpp b/unittest/formats/test_dump_atom_compressed.cpp index e33366801e..3360872f9e 100644 --- a/unittest/formats/test_dump_atom_compressed.cpp +++ b/unittest/formats/test_dump_atom_compressed.cpp @@ -40,7 +40,7 @@ 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); + generate_text_and_compressed_dump(text_file, compressed_file, "", "", 0); TearDown(); @@ -71,7 +71,7 @@ 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); + generate_text_and_compressed_dump(text_file, compressed_file, "", "", 1); TearDown(); @@ -107,7 +107,7 @@ TEST_F(DumpAtomCompressTest, compressed_multi_file_with_pad_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, "pad 3", 1); + generate_text_and_compressed_dump(text_file, compressed_file, "", "pad 3", 1); TearDown(); @@ -151,7 +151,7 @@ TEST_F(DumpAtomCompressTest, compressed_multi_file_with_maxfiles_run1) auto compressed_file_1 = compressed_dump_filename(base_name_1); auto compressed_file_2 = compressed_dump_filename(base_name_2); - generate_text_and_compressed_dump(text_file, compressed_file, "maxfiles 2", 2); + generate_text_and_compressed_dump(text_file, compressed_file, "", "maxfiles 2", 2); TearDown(); @@ -188,8 +188,7 @@ TEST_F(DumpAtomCompressTest, compressed_with_units_run0) auto text_file = text_dump_filename(base_name); auto compressed_file = compressed_dump_filename(base_name); - generate_text_and_compressed_dump(text_file, compressed_file, "scale no units yes", - 0); + generate_text_and_compressed_dump(text_file, compressed_file, "", "scale no units yes", 0); TearDown(); @@ -213,7 +212,7 @@ TEST_F(DumpAtomCompressTest, compressed_with_time_run0) auto text_file = text_dump_filename(base_name); auto compressed_file = compressed_dump_filename(base_name); - generate_text_and_compressed_dump(text_file, compressed_file, "scale no time yes", 0); + generate_text_and_compressed_dump(text_file, compressed_file, "", "scale no time yes", 0); TearDown(); @@ -238,7 +237,7 @@ TEST_F(DumpAtomCompressTest, compressed_triclinic_run0) auto compressed_file = compressed_dump_filename(base_name); enable_triclinic(); - generate_text_and_compressed_dump(text_file, compressed_file, "", 0); + generate_text_and_compressed_dump(text_file, compressed_file, "", "", 0); TearDown(); @@ -263,7 +262,7 @@ TEST_F(DumpAtomCompressTest, compressed_triclinic_with_units_run0) auto compressed_file = compressed_dump_filename(base_name); enable_triclinic(); - generate_text_and_compressed_dump(text_file, compressed_file, "scale no units yes", 0); + generate_text_and_compressed_dump(text_file, compressed_file, "", "scale no units yes", 0); TearDown(); @@ -288,7 +287,7 @@ TEST_F(DumpAtomCompressTest, compressed_triclinic_with_time_run0) auto compressed_file = compressed_dump_filename(base_name); enable_triclinic(); - generate_text_and_compressed_dump(text_file, compressed_file, "scale no time yes", 0); + generate_text_and_compressed_dump(text_file, compressed_file, "", "scale no time yes", 0); TearDown(); @@ -313,7 +312,7 @@ TEST_F(DumpAtomCompressTest, compressed_triclinic_with_image_run0) auto compressed_file = compressed_dump_filename(base_name); enable_triclinic(); - generate_text_and_compressed_dump(text_file, compressed_file, "image yes", 0); + generate_text_and_compressed_dump(text_file, compressed_file, "", "image yes", 0); TearDown(); @@ -359,7 +358,7 @@ TEST_F(DumpAtomCompressTest, compressed_modify_clevel_run0) auto text_file = text_dump_filename(base_name); auto compressed_file = compressed_dump_filename(base_name); - generate_text_and_compressed_dump(text_file, compressed_file, "", "compression_level 3", 0); + generate_text_and_compressed_dump(text_file, compressed_file, "", "", "", "compression_level 3", 0); TearDown(); diff --git a/unittest/formats/test_dump_cfg_compressed.cpp b/unittest/formats/test_dump_cfg_compressed.cpp new file mode 100644 index 0000000000..d06eabe57b --- /dev/null +++ b/unittest/formats/test_dump_cfg_compressed.cpp @@ -0,0 +1,132 @@ +/* ---------------------------------------------------------------------- + LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator + https://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 "../testing/utils.h" +#include "compressed_dump_test.h" +#include "fmt/format.h" +#include "utils.h" +#include "gmock/gmock.h" +#include "gtest/gtest.h" + +#include + + +using ::testing::Eq; + +class DumpCfgCompressTest : public CompressedDumpTest { +public: + DumpCfgCompressTest() : CompressedDumpTest("cfg") { + } +}; + +//------------------------------------------------------------------------------------------------- +// compressed files +//------------------------------------------------------------------------------------------------- + +TEST_F(DumpCfgCompressTest, compressed_run0) +{ + if (!COMPRESS_BINARY) GTEST_SKIP(); + + auto base_name = "run*.melt.cfg"; + auto text_files = text_dump_filename(base_name); + auto compressed_files = compressed_dump_filename(base_name); + + auto base_name_0 = "run0.melt.cfg"; + auto text_file_0 = text_dump_filename(base_name_0); + 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); + + TearDown(); + + ASSERT_FILE_EXISTS(text_file_0); + ASSERT_FILE_EXISTS(compressed_file_0); + + auto converted_file_0 = convert_compressed_to_text(compressed_file_0); + + ASSERT_FILE_EXISTS(converted_file_0); + ASSERT_FILE_EQUAL(text_file_0, converted_file_0); + delete_file(text_file_0); + delete_file(compressed_file_0); + delete_file(converted_file_0); +} + +TEST_F(DumpCfgCompressTest, compressed_unwrap_run0) +{ + if (!COMPRESS_BINARY) GTEST_SKIP(); + + auto base_name = "unwrap_run*.melt.cfg"; + auto text_files = text_dump_filename(base_name); + auto compressed_files = compressed_dump_filename(base_name); + + auto base_name_0 = "unwrap_run0.melt.cfg"; + auto text_file_0 = text_dump_filename(base_name_0); + auto compressed_file_0 = compressed_dump_filename(base_name_0); + auto fields = "mass type xsu ysu zsu 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); + + TearDown(); + + ASSERT_FILE_EXISTS(text_file_0); + ASSERT_FILE_EXISTS(compressed_file_0); + + auto converted_file_0 = convert_compressed_to_text(compressed_file_0); + + ASSERT_FILE_EXISTS(converted_file_0); + ASSERT_FILE_EQUAL(text_file_0, converted_file_0); + delete_file(text_file_0); + 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_cfg_gz.cpp b/unittest/formats/test_dump_cfg_gz.cpp deleted file mode 100644 index ced307dc0a..0000000000 --- a/unittest/formats/test_dump_cfg_gz.cpp +++ /dev/null @@ -1,133 +0,0 @@ -/* ---------------------------------------------------------------------- - LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator - https://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 "../testing/core.h" -#include "../testing/systems/melt.h" -#include "../testing/utils.h" -#include "fmt/format.h" -#include "utils.h" -#include "gmock/gmock.h" -#include "gtest/gtest.h" - -char *GZIP_BINARY = nullptr; - -using ::testing::Eq; - -class DumpCfgGZTest : public MeltTest { - std::string dump_style = "cfg"; - -public: - void generate_text_and_compressed_dump(std::string text_file, std::string compressed_file, - std::string compression_style, std::string fields, - std::string dump_modify_options, int ntimesteps) - { - if (!verbose) ::testing::internal::CaptureStdout(); - command(fmt::format("dump id0 all {} 1 {} {}", dump_style, text_file, fields)); - command(fmt::format("dump id1 all {} 1 {} {}", compression_style, compressed_file, fields)); - - if (!dump_modify_options.empty()) { - command(fmt::format("dump_modify id0 {}", dump_modify_options)); - command(fmt::format("dump_modify id1 {}", dump_modify_options)); - } - - command(fmt::format("run {}", ntimesteps)); - if (!verbose) ::testing::internal::GetCapturedStdout(); - } - - std::string convert_compressed_to_text(std::string compressed_file) - { - if (!verbose) ::testing::internal::CaptureStdout(); - std::string converted_file = compressed_file.substr(0, compressed_file.find_last_of('.')); - std::string cmdline = - fmt::format("{} -d -c {} > {}", GZIP_BINARY, compressed_file, converted_file); - system(cmdline.c_str()); - if (!verbose) ::testing::internal::GetCapturedStdout(); - return converted_file; - } -}; - -TEST_F(DumpCfgGZTest, compressed_run0) -{ - if (!GZIP_BINARY) GTEST_SKIP(); - - auto text_files = "dump_cfg_gz_text_run*.melt.cfg"; - auto compressed_files = "dump_cfg_gz_compressed_run*.melt.cfg.gz"; - auto text_file = "dump_cfg_gz_text_run0.melt.cfg"; - auto compressed_file = "dump_cfg_gz_compressed_run0.melt.cfg.gz"; - 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, "cfg/gz", fields, "", 0); - - TearDown(); - - ASSERT_FILE_EXISTS(text_file); - ASSERT_FILE_EXISTS(compressed_file); - - auto converted_file = convert_compressed_to_text(compressed_file); - - ASSERT_FILE_EXISTS(converted_file); - ASSERT_FILE_EQUAL(text_file, converted_file); - delete_file(text_file); - delete_file(compressed_file); - delete_file(converted_file); -} - -TEST_F(DumpCfgGZTest, compressed_unwrap_run0) -{ - if (!GZIP_BINARY) GTEST_SKIP(); - - auto text_files = "dump_cfg_unwrap_gz_text_run*.melt.cfg"; - auto compressed_files = "dump_cfg_unwrap_gz_compressed_run*.melt.cfg.gz"; - auto text_file = "dump_cfg_unwrap_gz_text_run0.melt.cfg"; - auto compressed_file = "dump_cfg_unwrap_gz_compressed_run0.melt.cfg.gz"; - auto fields = "mass type xsu ysu zsu id proc procp1 x y z ix iy iz vx vy vz fx fy fz"; - - generate_text_and_compressed_dump(text_files, compressed_files, "cfg/gz", fields, "", 0); - - TearDown(); - - ASSERT_FILE_EXISTS(text_file); - ASSERT_FILE_EXISTS(compressed_file); - - auto converted_file = convert_compressed_to_text(compressed_file); - - ASSERT_FILE_EXISTS(converted_file); - ASSERT_FILE_EQUAL(text_file, converted_file); - delete_file(text_file); - delete_file(compressed_file); - delete_file(converted_file); -} - -int main(int argc, char **argv) -{ - MPI_Init(&argc, &argv); - ::testing::InitGoogleMock(&argc, argv); - - // 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; - } - } - } - - GZIP_BINARY = getenv("GZIP_BINARY"); - - 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_zstd.cpp b/unittest/formats/test_dump_cfg_zstd.cpp deleted file mode 100644 index c13a3d5eaf..0000000000 --- a/unittest/formats/test_dump_cfg_zstd.cpp +++ /dev/null @@ -1,133 +0,0 @@ -/* ---------------------------------------------------------------------- - LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator - https://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 "../testing/core.h" -#include "../testing/systems/melt.h" -#include "../testing/utils.h" -#include "fmt/format.h" -#include "utils.h" -#include "gmock/gmock.h" -#include "gtest/gtest.h" - -char *ZSTD_BINARY = nullptr; - -using ::testing::Eq; - -class DumpCfgZstdTest : public MeltTest { - std::string dump_style = "cfg"; - -public: - void generate_text_and_compressed_dump(std::string text_file, std::string compressed_file, - std::string compression_style, std::string fields, - std::string dump_modify_options, int ntimesteps) - { - if (!verbose) ::testing::internal::CaptureStdout(); - command(fmt::format("dump id0 all {} 1 {} {}", dump_style, text_file, fields)); - command(fmt::format("dump id1 all {} 1 {} {}", compression_style, compressed_file, fields)); - - if (!dump_modify_options.empty()) { - command(fmt::format("dump_modify id0 {}", dump_modify_options)); - command(fmt::format("dump_modify id1 {}", dump_modify_options)); - } - - command(fmt::format("run {}", ntimesteps)); - if (!verbose) ::testing::internal::GetCapturedStdout(); - } - - std::string convert_compressed_to_text(std::string compressed_file) - { - if (!verbose) ::testing::internal::CaptureStdout(); - std::string converted_file = compressed_file.substr(0, compressed_file.find_last_of('.')); - std::string cmdline = - fmt::format("{} -d -c {} > {}", ZSTD_BINARY, compressed_file, converted_file); - system(cmdline.c_str()); - if (!verbose) ::testing::internal::GetCapturedStdout(); - return converted_file; - } -}; - -TEST_F(DumpCfgZstdTest, compressed_run0) -{ - if (!ZSTD_BINARY) GTEST_SKIP(); - - auto text_files = "dump_cfg_zstd_text_run*.melt.cfg"; - auto compressed_files = "dump_cfg_zstd_compressed_run*.melt.cfg.zst"; - auto text_file = "dump_cfg_zstd_text_run0.melt.cfg"; - auto compressed_file = "dump_cfg_zstd_compressed_run0.melt.cfg.zst"; - 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, "cfg/zstd", fields, "", 0); - - TearDown(); - - ASSERT_FILE_EXISTS(text_file); - ASSERT_FILE_EXISTS(compressed_file); - - auto converted_file = convert_compressed_to_text(compressed_file); - - ASSERT_FILE_EXISTS(converted_file); - ASSERT_FILE_EQUAL(text_file, converted_file); - delete_file(text_file); - delete_file(compressed_file); - delete_file(converted_file); -} - -TEST_F(DumpCfgZstdTest, compressed_unwrap_run0) -{ - if (!ZSTD_BINARY) GTEST_SKIP(); - - auto text_files = "dump_cfg_unwrap_zstd_text_run*.melt.cfg"; - auto compressed_files = "dump_cfg_unwrap_zstd_compressed_run*.melt.cfg.zst"; - auto text_file = "dump_cfg_unwrap_zstd_text_run0.melt.cfg"; - auto compressed_file = "dump_cfg_unwrap_zstd_compressed_run0.melt.cfg.zst"; - auto fields = "mass type xsu ysu zsu id proc procp1 x y z ix iy iz vx vy vz fx fy fz"; - - generate_text_and_compressed_dump(text_files, compressed_files, "cfg/zstd", fields, "", 0); - - TearDown(); - - ASSERT_FILE_EXISTS(text_file); - ASSERT_FILE_EXISTS(compressed_file); - - auto converted_file = convert_compressed_to_text(compressed_file); - - ASSERT_FILE_EXISTS(converted_file); - ASSERT_FILE_EQUAL(text_file, converted_file); - delete_file(text_file); - delete_file(compressed_file); - delete_file(converted_file); -} - -int main(int argc, char **argv) -{ - MPI_Init(&argc, &argv); - ::testing::InitGoogleMock(&argc, argv); - - // 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; - } - } - } - - ZSTD_BINARY = getenv("ZSTD_BINARY"); - - if ((argc > 1) && (strcmp(argv[1], "-v") == 0)) verbose = true; - - int rv = RUN_ALL_TESTS(); - MPI_Finalize(); - return rv; -} From 116ffd62dec936da768d31410c6db873fa3f354d Mon Sep 17 00:00:00 2001 From: Richard Berger Date: Thu, 11 Mar 2021 12:11:23 -0500 Subject: [PATCH 05/14] Unify dump custom/gz and custom/zstd tests --- unittest/formats/CMakeLists.txt | 24 ++- .../formats/test_dump_custom_compressed.cpp | 122 ++++++++++++++ unittest/formats/test_dump_custom_gz.cpp | 154 ------------------ unittest/formats/test_dump_custom_zstd.cpp | 154 ------------------ 4 files changed, 133 insertions(+), 321 deletions(-) create mode 100644 unittest/formats/test_dump_custom_compressed.cpp delete mode 100644 unittest/formats/test_dump_custom_gz.cpp delete mode 100644 unittest/formats/test_dump_custom_zstd.cpp diff --git a/unittest/formats/CMakeLists.txt b/unittest/formats/CMakeLists.txt index cd02aed6b0..7932c037fa 100644 --- a/unittest/formats/CMakeLists.txt +++ b/unittest/formats/CMakeLists.txt @@ -43,17 +43,18 @@ if(PKG_COMPRESS) add_executable(test_dump_atom_compressed test_dump_atom_compressed.cpp) target_link_libraries(test_dump_atom_compressed PRIVATE lammps GTest::GMock GTest::GTest) - add_test(NAME DumpAtomGZ COMMAND test_dump_atom_compressed gz WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) - set_tests_properties(DumpAtomGZ PROPERTIES ENVIRONMENT "LAMMPS_POTENTIALS=${LAMMPS_POTENTIALS_DIR};COMPRESS_BINARY=${GZIP_BINARY}") - - add_executable(test_dump_custom_gz test_dump_custom_gz.cpp) - target_link_libraries(test_dump_custom_gz PRIVATE lammps GTest::GMock GTest::GTest) - add_test(NAME DumpCustomGZ COMMAND test_dump_custom_gz WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) - set_tests_properties(DumpCustomGZ PROPERTIES ENVIRONMENT "LAMMPS_POTENTIALS=${LAMMPS_POTENTIALS_DIR}") - set_tests_properties(DumpCustomGZ PROPERTIES ENVIRONMENT "GZIP_BINARY=${GZIP_BINARY}") + add_executable(test_dump_custom_compressed test_dump_custom_compressed.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) target_link_libraries(test_dump_cfg_compressed PRIVATE lammps GTest::GMock GTest::GTest) + + add_test(NAME DumpAtomGZ COMMAND test_dump_atom_compressed gz WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) + set_tests_properties(DumpAtomGZ PROPERTIES ENVIRONMENT "LAMMPS_POTENTIALS=${LAMMPS_POTENTIALS_DIR};COMPRESS_BINARY=${GZIP_BINARY}") + + add_test(NAME DumpCustomGZ COMMAND test_dump_custom_compressed gz WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) + set_tests_properties(DumpCustomGZ PROPERTIES ENVIRONMENT "LAMMPS_POTENTIALS=${LAMMPS_POTENTIALS_DIR};COMPRESS_BINARY=${GZIP_BINARY}") + add_test(NAME DumpCfgGZ COMMAND test_dump_cfg_compressed gz WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) set_tests_properties(DumpCfgGZ PROPERTIES ENVIRONMENT "LAMMPS_POTENTIALS=${LAMMPS_POTENTIALS_DIR};COMPRESS_BINARY=${GZIP_BINARY}") @@ -77,11 +78,8 @@ if(PKG_COMPRESS) add_test(NAME DumpAtomZstd COMMAND test_dump_atom_compressed zstd WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) set_tests_properties(DumpAtomZstd PROPERTIES ENVIRONMENT "LAMMPS_POTENTIALS=${LAMMPS_POTENTIALS_DIR};COMPRESS_BINARY=${ZSTD_BINARY}") - add_executable(test_dump_custom_zstd test_dump_custom_zstd.cpp) - target_link_libraries(test_dump_custom_zstd PRIVATE lammps GTest::GMock GTest::GTest) - add_test(NAME DumpCustomZstd COMMAND test_dump_custom_zstd WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) - set_tests_properties(DumpCustomZstd PROPERTIES ENVIRONMENT "LAMMPS_POTENTIALS=${LAMMPS_POTENTIALS_DIR}") - set_tests_properties(DumpCustomZstd PROPERTIES ENVIRONMENT "ZSTD_BINARY=${ZSTD_BINARY}") + add_test(NAME DumpCustomZstd COMMAND test_dump_custom_compressed zstd WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) + set_tests_properties(DumpCustomZstd PROPERTIES ENVIRONMENT "LAMMPS_POTENTIALS=${LAMMPS_POTENTIALS_DIR};COMPRESS_BINARY=${ZSTD_BINARY}") add_test(NAME DumpCfgZstd COMMAND test_dump_cfg_compressed zstd WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) set_tests_properties(DumpCfgZstd PROPERTIES ENVIRONMENT "LAMMPS_POTENTIALS=${LAMMPS_POTENTIALS_DIR};COMPRESS_BINARY=${ZSTD_BINARY}") diff --git a/unittest/formats/test_dump_custom_compressed.cpp b/unittest/formats/test_dump_custom_compressed.cpp new file mode 100644 index 0000000000..0afad264fb --- /dev/null +++ b/unittest/formats/test_dump_custom_compressed.cpp @@ -0,0 +1,122 @@ +/* ---------------------------------------------------------------------- + LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator + https://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 "../testing/utils.h" +#include "compressed_dump_test.h" +#include "fmt/format.h" +#include "utils.h" +#include "gmock/gmock.h" +#include "gtest/gtest.h" + +#include + + +using ::testing::Eq; + +class DumpCustomCompressTest : public CompressedDumpTest { +public: + DumpCustomCompressTest() : CompressedDumpTest("custom") { + } +}; + +TEST_F(DumpCustomCompressTest, compressed_run1) +{ + if (!COMPRESS_BINARY) GTEST_SKIP(); + + auto base_name = "custom_run1.melt"; + auto text_file = text_dump_filename(base_name); + 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); + + TearDown(); + + ASSERT_FILE_EXISTS(text_file); + ASSERT_FILE_EXISTS(compressed_file); + + auto converted_file = convert_compressed_to_text(compressed_file); + + ASSERT_FILE_EXISTS(converted_file); + ASSERT_FILE_EQUAL(text_file, converted_file); + delete_file(text_file); + delete_file(compressed_file); + delete_file(converted_file); +} + +TEST_F(DumpCustomCompressTest, compressed_triclinic_run1) +{ + if (!COMPRESS_BINARY) GTEST_SKIP(); + + auto base_name = "custom_tri_run1.melt"; + auto text_file = text_dump_filename(base_name); + auto compressed_file = compressed_dump_filename(base_name); + auto fields = "id type proc x y z xs ys zs xsu ysu zsu vx vy vz fx fy fz"; + + enable_triclinic(); + + generate_text_and_compressed_dump(text_file, compressed_file, fields, "units yes", 1); + + TearDown(); + + ASSERT_FILE_EXISTS(text_file); + ASSERT_FILE_EXISTS(compressed_file); + + auto converted_file = convert_compressed_to_text(compressed_file); + + ASSERT_FILE_EXISTS(converted_file); + ASSERT_FILE_EQUAL(text_file, converted_file); + delete_file(text_file); + 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_custom_gz.cpp b/unittest/formats/test_dump_custom_gz.cpp deleted file mode 100644 index 67c9b535aa..0000000000 --- a/unittest/formats/test_dump_custom_gz.cpp +++ /dev/null @@ -1,154 +0,0 @@ -/* ---------------------------------------------------------------------- - LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator - https://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 "../testing/core.h" -#include "../testing/systems/melt.h" -#include "../testing/utils.h" -#include "fmt/format.h" -#include "utils.h" -#include "gmock/gmock.h" -#include "gtest/gtest.h" - -using ::testing::Eq; - -char *GZIP_BINARY = nullptr; - -class DumpCustomGZTest : public MeltTest { - std::string dump_style = "custom"; - -public: - void enable_triclinic() - { - if (!verbose) ::testing::internal::CaptureStdout(); - command("change_box all triclinic"); - if (!verbose) ::testing::internal::GetCapturedStdout(); - } - - void generate_dump(std::string dump_file, std::string fields, std::string dump_modify_options, - int ntimesteps) - { - if (!verbose) ::testing::internal::CaptureStdout(); - command(fmt::format("dump id all {} 1 {} {}", dump_style, dump_file, fields)); - - if (!dump_modify_options.empty()) { - command(fmt::format("dump_modify id {}", dump_modify_options)); - } - - command(fmt::format("run {}", ntimesteps)); - if (!verbose) ::testing::internal::GetCapturedStdout(); - } - - void generate_text_and_compressed_dump(std::string text_file, std::string compressed_file, - std::string compression_style, std::string fields, - std::string dump_modify_options, int ntimesteps) - { - if (!verbose) ::testing::internal::CaptureStdout(); - command(fmt::format("dump id0 all {} 1 {} {}", dump_style, text_file, fields)); - command(fmt::format("dump id1 all {} 1 {} {}", compression_style, compressed_file, fields)); - - if (!dump_modify_options.empty()) { - command(fmt::format("dump_modify id0 {}", dump_modify_options)); - command(fmt::format("dump_modify id1 {}", dump_modify_options)); - } - - command(fmt::format("run {}", ntimesteps)); - if (!verbose) ::testing::internal::GetCapturedStdout(); - } - - std::string convert_compressed_to_text(std::string compressed_file) - { - if (!verbose) ::testing::internal::CaptureStdout(); - std::string converted_file = compressed_file.substr(0, compressed_file.find_last_of('.')); - std::string cmdline = - fmt::format("{} -d -c {} > {}", GZIP_BINARY, compressed_file, converted_file); - system(cmdline.c_str()); - if (!verbose) ::testing::internal::GetCapturedStdout(); - return converted_file; - } -}; - -TEST_F(DumpCustomGZTest, compressed_run1) -{ - if (!GZIP_BINARY) GTEST_SKIP(); - - auto text_file = "dump_custom_gz_text_run1.melt"; - auto compressed_file = "dump_custom_gz_compressed_run1.melt.gz"; - 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, "custom/gz", fields, "units yes", - 1); - - TearDown(); - - ASSERT_FILE_EXISTS(text_file); - ASSERT_FILE_EXISTS(compressed_file); - - auto converted_file = convert_compressed_to_text(compressed_file); - - ASSERT_FILE_EXISTS(converted_file); - ASSERT_FILE_EQUAL(text_file, converted_file); - delete_file(text_file); - delete_file(compressed_file); - delete_file(converted_file); -} - -TEST_F(DumpCustomGZTest, compressed_triclinic_run1) -{ - if (!GZIP_BINARY) GTEST_SKIP(); - - auto text_file = "dump_custom_gz_tri_text_run1.melt"; - auto compressed_file = "dump_custom_gz_tri_compressed_run1.melt.gz"; - auto fields = "id type proc x y z xs ys zs xsu ysu zsu vx vy vz fx fy fz"; - - enable_triclinic(); - - generate_text_and_compressed_dump(text_file, compressed_file, "custom/gz", fields, "units yes", - 1); - - TearDown(); - - ASSERT_FILE_EXISTS(text_file); - ASSERT_FILE_EXISTS(compressed_file); - - auto converted_file = convert_compressed_to_text(compressed_file); - - ASSERT_FILE_EXISTS(converted_file); - ASSERT_FILE_EQUAL(text_file, converted_file); - delete_file(text_file); - delete_file(compressed_file); - delete_file(converted_file); -} - -int main(int argc, char **argv) -{ - MPI_Init(&argc, &argv); - ::testing::InitGoogleMock(&argc, argv); - - // 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; - } - } - } - - GZIP_BINARY = getenv("GZIP_BINARY"); - - 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_zstd.cpp b/unittest/formats/test_dump_custom_zstd.cpp deleted file mode 100644 index 40328d5592..0000000000 --- a/unittest/formats/test_dump_custom_zstd.cpp +++ /dev/null @@ -1,154 +0,0 @@ -/* ---------------------------------------------------------------------- - LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator - https://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 "../testing/core.h" -#include "../testing/systems/melt.h" -#include "../testing/utils.h" -#include "fmt/format.h" -#include "utils.h" -#include "gmock/gmock.h" -#include "gtest/gtest.h" - -using ::testing::Eq; - -char *ZSTD_BINARY = nullptr; - -class DumpCustomZstdTest : public MeltTest { - std::string dump_style = "custom"; - -public: - void enable_triclinic() - { - if (!verbose) ::testing::internal::CaptureStdout(); - command("change_box all triclinic"); - if (!verbose) ::testing::internal::GetCapturedStdout(); - } - - void generate_dump(std::string dump_file, std::string fields, std::string dump_modify_options, - int ntimesteps) - { - if (!verbose) ::testing::internal::CaptureStdout(); - command(fmt::format("dump id all {} 1 {} {}", dump_style, dump_file, fields)); - - if (!dump_modify_options.empty()) { - command(fmt::format("dump_modify id {}", dump_modify_options)); - } - - command(fmt::format("run {}", ntimesteps)); - if (!verbose) ::testing::internal::GetCapturedStdout(); - } - - void generate_text_and_compressed_dump(std::string text_file, std::string compressed_file, - std::string compression_style, std::string fields, - std::string dump_modify_options, int ntimesteps) - { - if (!verbose) ::testing::internal::CaptureStdout(); - command(fmt::format("dump id0 all {} 1 {} {}", dump_style, text_file, fields)); - command(fmt::format("dump id1 all {} 1 {} {}", compression_style, compressed_file, fields)); - - if (!dump_modify_options.empty()) { - command(fmt::format("dump_modify id0 {}", dump_modify_options)); - command(fmt::format("dump_modify id1 {}", dump_modify_options)); - } - - command(fmt::format("run {}", ntimesteps)); - if (!verbose) ::testing::internal::GetCapturedStdout(); - } - - std::string convert_compressed_to_text(std::string compressed_file) - { - if (!verbose) ::testing::internal::CaptureStdout(); - std::string converted_file = compressed_file.substr(0, compressed_file.find_last_of('.')); - std::string cmdline = - fmt::format("{} -d -c {} > {}", ZSTD_BINARY, compressed_file, converted_file); - system(cmdline.c_str()); - if (!verbose) ::testing::internal::GetCapturedStdout(); - return converted_file; - } -}; - -TEST_F(DumpCustomZstdTest, compressed_run1) -{ - if (!ZSTD_BINARY) GTEST_SKIP(); - - auto text_file = "dump_custom_zstd_text_run1.melt"; - auto compressed_file = "dump_custom_zstd_compressed_run1.melt.zst"; - 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, "custom/zstd", fields, - "units yes", 1); - - TearDown(); - - ASSERT_FILE_EXISTS(text_file); - ASSERT_FILE_EXISTS(compressed_file); - - auto converted_file = convert_compressed_to_text(compressed_file); - - ASSERT_FILE_EXISTS(converted_file); - ASSERT_FILE_EQUAL(text_file, converted_file); - delete_file(text_file); - delete_file(compressed_file); - delete_file(converted_file); -} - -TEST_F(DumpCustomZstdTest, compressed_triclinic_run1) -{ - if (!ZSTD_BINARY) GTEST_SKIP(); - - auto text_file = "dump_custom_zstd_tri_text_run1.melt"; - auto compressed_file = "dump_custom_zstd_tri_compressed_run1.melt.zst"; - auto fields = "id type proc x y z xs ys zs xsu ysu zsu vx vy vz fx fy fz"; - - enable_triclinic(); - - generate_text_and_compressed_dump(text_file, compressed_file, "custom/zstd", fields, - "units yes", 1); - - TearDown(); - - ASSERT_FILE_EXISTS(text_file); - ASSERT_FILE_EXISTS(compressed_file); - - auto converted_file = convert_compressed_to_text(compressed_file); - - ASSERT_FILE_EXISTS(converted_file); - ASSERT_FILE_EQUAL(text_file, converted_file); - delete_file(text_file); - delete_file(compressed_file); - delete_file(converted_file); -} - -int main(int argc, char **argv) -{ - MPI_Init(&argc, &argv); - ::testing::InitGoogleMock(&argc, argv); - - // 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; - } - } - } - - ZSTD_BINARY = getenv("ZSTD_BINARY"); - - if ((argc > 1) && (strcmp(argv[1], "-v") == 0)) verbose = true; - - int rv = RUN_ALL_TESTS(); - MPI_Finalize(); - return rv; -} From fca6d6bf8f6cda4226471bc0d9625a528a06bf4b Mon Sep 17 00:00:00 2001 From: Richard Berger Date: Thu, 11 Mar 2021 12:20:25 -0500 Subject: [PATCH 06/14] Unify dump local/gz and local/zstd tests --- unittest/formats/CMakeLists.txt | 21 ++-- .../formats/test_dump_local_compressed.cpp | 102 ++++++++++++++++ unittest/formats/test_dump_local_gz.cpp | 111 ------------------ unittest/formats/test_dump_local_zstd.cpp | 111 ------------------ 4 files changed, 111 insertions(+), 234 deletions(-) create mode 100644 unittest/formats/test_dump_local_compressed.cpp delete mode 100644 unittest/formats/test_dump_local_gz.cpp delete mode 100644 unittest/formats/test_dump_local_zstd.cpp diff --git a/unittest/formats/CMakeLists.txt b/unittest/formats/CMakeLists.txt index 7932c037fa..731e387fc2 100644 --- a/unittest/formats/CMakeLists.txt +++ b/unittest/formats/CMakeLists.txt @@ -49,6 +49,9 @@ if(PKG_COMPRESS) add_executable(test_dump_cfg_compressed test_dump_cfg_compressed.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) + target_link_libraries(test_dump_local_compressed PRIVATE lammps GTest::GMock GTest::GTest) + add_test(NAME DumpAtomGZ COMMAND test_dump_atom_compressed gz WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) set_tests_properties(DumpAtomGZ PROPERTIES ENVIRONMENT "LAMMPS_POTENTIALS=${LAMMPS_POTENTIALS_DIR};COMPRESS_BINARY=${GZIP_BINARY}") @@ -58,18 +61,15 @@ if(PKG_COMPRESS) add_test(NAME DumpCfgGZ COMMAND test_dump_cfg_compressed gz WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) set_tests_properties(DumpCfgGZ PROPERTIES ENVIRONMENT "LAMMPS_POTENTIALS=${LAMMPS_POTENTIALS_DIR};COMPRESS_BINARY=${GZIP_BINARY}") + add_test(NAME DumpLocalGZ COMMAND test_dump_local_compressed gz WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) + set_tests_properties(DumpLocalGZ PROPERTIES ENVIRONMENT "LAMMPS_POTENTIALS=${LAMMPS_POTENTIALS_DIR};COMPRESS_BINARY=${GZIP_BINARY}") + add_executable(test_dump_xyz_gz test_dump_xyz_gz.cpp) target_link_libraries(test_dump_xyz_gz PRIVATE lammps GTest::GMock GTest::GTest) add_test(NAME DumpXYZGZ COMMAND test_dump_xyz_gz WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) set_tests_properties(DumpXYZGZ PROPERTIES ENVIRONMENT "LAMMPS_POTENTIALS=${LAMMPS_POTENTIALS_DIR}") set_tests_properties(DumpXYZGZ PROPERTIES ENVIRONMENT "GZIP_BINARY=${GZIP_BINARY}") - add_executable(test_dump_local_gz test_dump_local_gz.cpp) - target_link_libraries(test_dump_local_gz PRIVATE lammps GTest::GMock GTest::GTest) - add_test(NAME DumpLocalGZ COMMAND test_dump_local_gz WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) - set_tests_properties(DumpLocalGZ PROPERTIES ENVIRONMENT "LAMMPS_POTENTIALS=${LAMMPS_POTENTIALS_DIR}") - set_tests_properties(DumpLocalGZ PROPERTIES ENVIRONMENT "GZIP_BINARY=${GZIP_BINARY}") - find_package(PkgConfig REQUIRED) pkg_check_modules(Zstd IMPORTED_TARGET libzstd>=1.4) find_program(ZSTD_BINARY NAMES zstd) @@ -84,17 +84,14 @@ if(PKG_COMPRESS) add_test(NAME DumpCfgZstd COMMAND test_dump_cfg_compressed zstd WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) set_tests_properties(DumpCfgZstd PROPERTIES ENVIRONMENT "LAMMPS_POTENTIALS=${LAMMPS_POTENTIALS_DIR};COMPRESS_BINARY=${ZSTD_BINARY}") + add_test(NAME DumpLocalZstd COMMAND test_dump_local_compressed zstd WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) + set_tests_properties(DumpLocalZstd PROPERTIES ENVIRONMENT "LAMMPS_POTENTIALS=${LAMMPS_POTENTIALS_DIR};COMPRESS_BINARY=${ZSTD_BINARY}") + add_executable(test_dump_xyz_zstd test_dump_xyz_zstd.cpp) target_link_libraries(test_dump_xyz_zstd PRIVATE lammps GTest::GMock GTest::GTest) add_test(NAME DumpXYZZstd COMMAND test_dump_xyz_zstd WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) set_tests_properties(DumpXYZZstd PROPERTIES ENVIRONMENT "LAMMPS_POTENTIALS=${LAMMPS_POTENTIALS_DIR}") set_tests_properties(DumpXYZZstd PROPERTIES ENVIRONMENT "ZSTD_BINARY=${ZSTD_BINARY}") - - add_executable(test_dump_local_zstd test_dump_local_zstd.cpp) - target_link_libraries(test_dump_local_zstd PRIVATE lammps GTest::GMock GTest::GTest) - add_test(NAME DumpLocalZstd COMMAND test_dump_local_zstd WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) - set_tests_properties(DumpLocalZstd PROPERTIES ENVIRONMENT "LAMMPS_POTENTIALS=${LAMMPS_POTENTIALS_DIR}") - set_tests_properties(DumpLocalZstd PROPERTIES ENVIRONMENT "ZSTD_BINARY=${ZSTD_BINARY}") endif() endif() diff --git a/unittest/formats/test_dump_local_compressed.cpp b/unittest/formats/test_dump_local_compressed.cpp new file mode 100644 index 0000000000..048053fb9a --- /dev/null +++ b/unittest/formats/test_dump_local_compressed.cpp @@ -0,0 +1,102 @@ +/* ---------------------------------------------------------------------- + LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator + https://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 "../testing/utils.h" +#include "compressed_dump_test.h" +#include "fmt/format.h" +#include "utils.h" +#include "gmock/gmock.h" +#include "gtest/gtest.h" + +#include + + +using ::testing::Eq; + +class DumpLocalCompressTest : public CompressedDumpTest { +public: + DumpLocalCompressTest() : CompressedDumpTest("local") { + } +}; + +TEST_F(DumpLocalCompressTest, compressed_run0) +{ + if (!COMPRESS_BINARY) GTEST_SKIP(); + + if (!verbose) ::testing::internal::CaptureStdout(); + command("compute comp all pair/local dist eng"); + if (!verbose) ::testing::internal::GetCapturedStdout(); + + auto base_name = "run*.melt.local"; + auto base_name_0 = "run0.melt.local"; + auto text_files = text_dump_filename(base_name); + auto compressed_files = compressed_dump_filename(base_name); + auto text_file_0 = text_dump_filename(base_name_0); + 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); + + TearDown(); + + ASSERT_FILE_EXISTS(text_file_0); + ASSERT_FILE_EXISTS(compressed_file_0); + + auto converted_file_0 = convert_compressed_to_text(compressed_file_0); + + ASSERT_FILE_EXISTS(converted_file_0); + ASSERT_FILE_EQUAL(text_file_0, converted_file_0); + delete_file(text_file_0); + 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_local_gz.cpp b/unittest/formats/test_dump_local_gz.cpp deleted file mode 100644 index 6ae25ae33d..0000000000 --- a/unittest/formats/test_dump_local_gz.cpp +++ /dev/null @@ -1,111 +0,0 @@ -/* ---------------------------------------------------------------------- - LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator - https://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 "../testing/core.h" -#include "../testing/systems/melt.h" -#include "../testing/utils.h" -#include "fmt/format.h" -#include "utils.h" -#include "gmock/gmock.h" -#include "gtest/gtest.h" - -char *GZIP_BINARY = nullptr; - -using ::testing::Eq; - -class DumpLocalGZTest : public MeltTest { - std::string dump_style = "local"; - -public: - void generate_text_and_compressed_dump(std::string text_file, std::string compressed_file, - std::string compression_style, std::string fields, - std::string dump_modify_options, int ntimesteps) - { - if (!verbose) ::testing::internal::CaptureStdout(); - command(fmt::format("dump id0 all {} 1 {} {}", dump_style, text_file, fields)); - command(fmt::format("dump id1 all {} 1 {} {}", compression_style, compressed_file, fields)); - - if (!dump_modify_options.empty()) { - command(fmt::format("dump_modify id0 {}", dump_modify_options)); - command(fmt::format("dump_modify id1 {}", dump_modify_options)); - } - - command(fmt::format("run {}", ntimesteps)); - if (!verbose) ::testing::internal::GetCapturedStdout(); - } - - std::string convert_compressed_to_text(std::string compressed_file) - { - if (!verbose) ::testing::internal::CaptureStdout(); - std::string converted_file = compressed_file.substr(0, compressed_file.find_last_of('.')); - std::string cmdline = - fmt::format("{} -d -c {} > {}", GZIP_BINARY, compressed_file, converted_file); - system(cmdline.c_str()); - if (!verbose) ::testing::internal::GetCapturedStdout(); - return converted_file; - } -}; - -TEST_F(DumpLocalGZTest, compressed_run0) -{ - if (!GZIP_BINARY) GTEST_SKIP(); - - if (!verbose) ::testing::internal::CaptureStdout(); - command("compute comp all pair/local dist eng"); - if (!verbose) ::testing::internal::GetCapturedStdout(); - - auto text_files = "dump_local_gz_text_run*.melt.local"; - auto compressed_files = "dump_local_gz_compressed_run*.melt.local.gz"; - auto text_file = "dump_local_gz_text_run0.melt.local"; - auto compressed_file = "dump_local_gz_compressed_run0.melt.local.gz"; - auto fields = "index c_comp[1]"; - - generate_text_and_compressed_dump(text_files, compressed_files, "local/gz", fields, "", 0); - - TearDown(); - - ASSERT_FILE_EXISTS(text_file); - ASSERT_FILE_EXISTS(compressed_file); - - auto converted_file = convert_compressed_to_text(compressed_file); - - ASSERT_FILE_EXISTS(converted_file); - ASSERT_FILE_EQUAL(text_file, converted_file); - delete_file(text_file); - delete_file(compressed_file); - delete_file(converted_file); -} - -int main(int argc, char **argv) -{ - MPI_Init(&argc, &argv); - ::testing::InitGoogleMock(&argc, argv); - - // 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; - } - } - } - - GZIP_BINARY = getenv("GZIP_BINARY"); - - 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_zstd.cpp b/unittest/formats/test_dump_local_zstd.cpp deleted file mode 100644 index 4a15baf4ca..0000000000 --- a/unittest/formats/test_dump_local_zstd.cpp +++ /dev/null @@ -1,111 +0,0 @@ -/* ---------------------------------------------------------------------- - LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator - https://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 "../testing/core.h" -#include "../testing/systems/melt.h" -#include "../testing/utils.h" -#include "fmt/format.h" -#include "utils.h" -#include "gmock/gmock.h" -#include "gtest/gtest.h" - -char *ZSTD_BINARY = nullptr; - -using ::testing::Eq; - -class DumpLocalGZTest : public MeltTest { - std::string dump_style = "local"; - -public: - void generate_text_and_compressed_dump(std::string text_file, std::string compressed_file, - std::string compression_style, std::string fields, - std::string dump_modify_options, int ntimesteps) - { - if (!verbose) ::testing::internal::CaptureStdout(); - command(fmt::format("dump id0 all {} 1 {} {}", dump_style, text_file, fields)); - command(fmt::format("dump id1 all {} 1 {} {}", compression_style, compressed_file, fields)); - - if (!dump_modify_options.empty()) { - command(fmt::format("dump_modify id0 {}", dump_modify_options)); - command(fmt::format("dump_modify id1 {}", dump_modify_options)); - } - - command(fmt::format("run {}", ntimesteps)); - if (!verbose) ::testing::internal::GetCapturedStdout(); - } - - std::string convert_compressed_to_text(std::string compressed_file) - { - if (!verbose) ::testing::internal::CaptureStdout(); - std::string converted_file = compressed_file.substr(0, compressed_file.find_last_of('.')); - std::string cmdline = - fmt::format("{} -d -c {} > {}", ZSTD_BINARY, compressed_file, converted_file); - system(cmdline.c_str()); - if (!verbose) ::testing::internal::GetCapturedStdout(); - return converted_file; - } -}; - -TEST_F(DumpLocalGZTest, compressed_run0) -{ - if (!ZSTD_BINARY) GTEST_SKIP(); - - if (!verbose) ::testing::internal::CaptureStdout(); - command("compute comp all pair/local dist eng"); - if (!verbose) ::testing::internal::GetCapturedStdout(); - - auto text_files = "dump_local_zstd_text_run*.melt.local"; - auto compressed_files = "dump_local_zstd_compressed_run*.melt.local.zst"; - auto text_file = "dump_local_zstd_text_run0.melt.local"; - auto compressed_file = "dump_local_zstd_compressed_run0.melt.local.zst"; - auto fields = "index c_comp[1]"; - - generate_text_and_compressed_dump(text_files, compressed_files, "local/zstd", fields, "", 0); - - TearDown(); - - ASSERT_FILE_EXISTS(text_file); - ASSERT_FILE_EXISTS(compressed_file); - - auto converted_file = convert_compressed_to_text(compressed_file); - - ASSERT_FILE_EXISTS(converted_file); - ASSERT_FILE_EQUAL(text_file, converted_file); - delete_file(text_file); - delete_file(compressed_file); - delete_file(converted_file); -} - -int main(int argc, char **argv) -{ - MPI_Init(&argc, &argv); - ::testing::InitGoogleMock(&argc, argv); - - // 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; - } - } - } - - ZSTD_BINARY = getenv("ZSTD_BINARY"); - - if ((argc > 1) && (strcmp(argv[1], "-v") == 0)) verbose = true; - - int rv = RUN_ALL_TESTS(); - MPI_Finalize(); - return rv; -} From 3ebc7823b0b52615d89408256c3b5ae4d100b557 Mon Sep 17 00:00:00 2001 From: Richard Berger Date: Thu, 11 Mar 2021 12:28:56 -0500 Subject: [PATCH 07/14] Unify dump xyz/gz and xyz/zstd tests --- unittest/formats/CMakeLists.txt | 17 ++- unittest/formats/test_dump_xyz_compressed.cpp | 97 ++++++++++++++++ unittest/formats/test_dump_xyz_gz.cpp | 106 ------------------ unittest/formats/test_dump_xyz_zstd.cpp | 106 ------------------ 4 files changed, 104 insertions(+), 222 deletions(-) create mode 100644 unittest/formats/test_dump_xyz_compressed.cpp delete mode 100644 unittest/formats/test_dump_xyz_gz.cpp delete mode 100644 unittest/formats/test_dump_xyz_zstd.cpp diff --git a/unittest/formats/CMakeLists.txt b/unittest/formats/CMakeLists.txt index 731e387fc2..63c7759005 100644 --- a/unittest/formats/CMakeLists.txt +++ b/unittest/formats/CMakeLists.txt @@ -52,6 +52,9 @@ if(PKG_COMPRESS) add_executable(test_dump_local_compressed test_dump_local_compressed.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) + 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}) set_tests_properties(DumpAtomGZ PROPERTIES ENVIRONMENT "LAMMPS_POTENTIALS=${LAMMPS_POTENTIALS_DIR};COMPRESS_BINARY=${GZIP_BINARY}") @@ -64,11 +67,8 @@ if(PKG_COMPRESS) add_test(NAME DumpLocalGZ COMMAND test_dump_local_compressed gz WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) set_tests_properties(DumpLocalGZ PROPERTIES ENVIRONMENT "LAMMPS_POTENTIALS=${LAMMPS_POTENTIALS_DIR};COMPRESS_BINARY=${GZIP_BINARY}") - add_executable(test_dump_xyz_gz test_dump_xyz_gz.cpp) - target_link_libraries(test_dump_xyz_gz PRIVATE lammps GTest::GMock GTest::GTest) - add_test(NAME DumpXYZGZ COMMAND test_dump_xyz_gz WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) - set_tests_properties(DumpXYZGZ PROPERTIES ENVIRONMENT "LAMMPS_POTENTIALS=${LAMMPS_POTENTIALS_DIR}") - set_tests_properties(DumpXYZGZ PROPERTIES ENVIRONMENT "GZIP_BINARY=${GZIP_BINARY}") + add_test(NAME DumpXYZGZ COMMAND test_dump_xyz_compressed gz WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) + set_tests_properties(DumpXYZGZ PROPERTIES ENVIRONMENT "LAMMPS_POTENTIALS=${LAMMPS_POTENTIALS_DIR};COMPRESS_BINARY=${GZIP_BINARY}") find_package(PkgConfig REQUIRED) pkg_check_modules(Zstd IMPORTED_TARGET libzstd>=1.4) @@ -87,11 +87,8 @@ if(PKG_COMPRESS) add_test(NAME DumpLocalZstd COMMAND test_dump_local_compressed zstd WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) set_tests_properties(DumpLocalZstd PROPERTIES ENVIRONMENT "LAMMPS_POTENTIALS=${LAMMPS_POTENTIALS_DIR};COMPRESS_BINARY=${ZSTD_BINARY}") - add_executable(test_dump_xyz_zstd test_dump_xyz_zstd.cpp) - target_link_libraries(test_dump_xyz_zstd PRIVATE lammps GTest::GMock GTest::GTest) - add_test(NAME DumpXYZZstd COMMAND test_dump_xyz_zstd WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) - set_tests_properties(DumpXYZZstd PROPERTIES ENVIRONMENT "LAMMPS_POTENTIALS=${LAMMPS_POTENTIALS_DIR}") - set_tests_properties(DumpXYZZstd PROPERTIES ENVIRONMENT "ZSTD_BINARY=${ZSTD_BINARY}") + add_test(NAME DumpXYZZstd COMMAND test_dump_xyz_compressed zstd WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) + set_tests_properties(DumpXYZZstd PROPERTIES ENVIRONMENT "LAMMPS_POTENTIALS=${LAMMPS_POTENTIALS_DIR};COMPRESS_BINARY=${ZSTD_BINARY}") endif() endif() diff --git a/unittest/formats/test_dump_xyz_compressed.cpp b/unittest/formats/test_dump_xyz_compressed.cpp new file mode 100644 index 0000000000..8f82ccebe2 --- /dev/null +++ b/unittest/formats/test_dump_xyz_compressed.cpp @@ -0,0 +1,97 @@ +/* ---------------------------------------------------------------------- + LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator + https://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 "../testing/utils.h" +#include "compressed_dump_test.h" +#include "fmt/format.h" +#include "utils.h" +#include "gmock/gmock.h" +#include "gtest/gtest.h" + +#include + + +using ::testing::Eq; + +class DumpXYZCompressTest : public CompressedDumpTest { +public: + DumpXYZCompressTest() : CompressedDumpTest("xyz") { + } +}; + +TEST_F(DumpXYZCompressTest, compressed_run0) +{ + if (!COMPRESS_BINARY) GTEST_SKIP(); + + auto base_name = "run*.melt.xyz"; + auto base_name_0 = "run0.melt.xyz"; + auto text_files = text_dump_filename(base_name); + auto compressed_files = compressed_dump_filename(base_name); + 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); + + TearDown(); + + ASSERT_FILE_EXISTS(text_file_0); + ASSERT_FILE_EXISTS(compressed_file_0); + + auto converted_file_0 = convert_compressed_to_text(compressed_file_0); + + ASSERT_FILE_EXISTS(converted_file_0); + ASSERT_FILE_EQUAL(text_file_0, converted_file_0); + delete_file(text_file_0); + 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_xyz_gz.cpp b/unittest/formats/test_dump_xyz_gz.cpp deleted file mode 100644 index aef54b4820..0000000000 --- a/unittest/formats/test_dump_xyz_gz.cpp +++ /dev/null @@ -1,106 +0,0 @@ -/* ---------------------------------------------------------------------- - LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator - https://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 "../testing/core.h" -#include "../testing/systems/melt.h" -#include "../testing/utils.h" -#include "fmt/format.h" -#include "utils.h" -#include "gmock/gmock.h" -#include "gtest/gtest.h" - -char *GZIP_BINARY = nullptr; - -using ::testing::Eq; - -class DumpXYZGZTest : public MeltTest { - std::string dump_style = "xyz"; - -public: - void generate_text_and_compressed_dump(std::string text_file, std::string compressed_file, - std::string compression_style, - std::string dump_modify_options, int ntimesteps) - { - if (!verbose) ::testing::internal::CaptureStdout(); - command(fmt::format("dump id0 all {} 1 {}", dump_style, text_file)); - command(fmt::format("dump id1 all {} 1 {}", compression_style, compressed_file)); - - if (!dump_modify_options.empty()) { - command(fmt::format("dump_modify id0 {}", dump_modify_options)); - command(fmt::format("dump_modify id1 {}", dump_modify_options)); - } - - command(fmt::format("run {}", ntimesteps)); - if (!verbose) ::testing::internal::GetCapturedStdout(); - } - - std::string convert_compressed_to_text(std::string compressed_file) - { - if (!verbose) ::testing::internal::CaptureStdout(); - std::string converted_file = compressed_file.substr(0, compressed_file.find_last_of('.')); - std::string cmdline = - fmt::format("{} -d -c {} > {}", GZIP_BINARY, compressed_file, converted_file); - system(cmdline.c_str()); - if (!verbose) ::testing::internal::GetCapturedStdout(); - return converted_file; - } -}; - -TEST_F(DumpXYZGZTest, compressed_run0) -{ - if (!GZIP_BINARY) GTEST_SKIP(); - - auto text_files = "dump_xyz_gz_text_run*.melt.xyz"; - auto compressed_files = "dump_xyz_gz_compressed_run*.melt.xyz.gz"; - auto text_file = "dump_xyz_gz_text_run0.melt.xyz"; - auto compressed_file = "dump_xyz_gz_compressed_run0.melt.xyz.gz"; - - generate_text_and_compressed_dump(text_files, compressed_files, "xyz/gz", "", 0); - - TearDown(); - - ASSERT_FILE_EXISTS(text_file); - ASSERT_FILE_EXISTS(compressed_file); - - auto converted_file = convert_compressed_to_text(compressed_file); - - ASSERT_FILE_EXISTS(converted_file); - ASSERT_FILE_EQUAL(text_file, converted_file); - delete_file(text_file); - delete_file(compressed_file); - delete_file(converted_file); -} - -int main(int argc, char **argv) -{ - MPI_Init(&argc, &argv); - ::testing::InitGoogleMock(&argc, argv); - - // 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; - } - } - } - - GZIP_BINARY = getenv("GZIP_BINARY"); - - 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_zstd.cpp b/unittest/formats/test_dump_xyz_zstd.cpp deleted file mode 100644 index ce0b4ed143..0000000000 --- a/unittest/formats/test_dump_xyz_zstd.cpp +++ /dev/null @@ -1,106 +0,0 @@ -/* ---------------------------------------------------------------------- - LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator - https://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 "../testing/core.h" -#include "../testing/systems/melt.h" -#include "../testing/utils.h" -#include "fmt/format.h" -#include "utils.h" -#include "gmock/gmock.h" -#include "gtest/gtest.h" - -char *ZSTD_BINARY = nullptr; - -using ::testing::Eq; - -class DumpXYZGZTest : public MeltTest { - std::string dump_style = "xyz"; - -public: - void generate_text_and_compressed_dump(std::string text_file, std::string compressed_file, - std::string compression_style, - std::string dump_modify_options, int ntimesteps) - { - if (!verbose) ::testing::internal::CaptureStdout(); - command(fmt::format("dump id0 all {} 1 {}", dump_style, text_file)); - command(fmt::format("dump id1 all {} 1 {}", compression_style, compressed_file)); - - if (!dump_modify_options.empty()) { - command(fmt::format("dump_modify id0 {}", dump_modify_options)); - command(fmt::format("dump_modify id1 {}", dump_modify_options)); - } - - command(fmt::format("run {}", ntimesteps)); - if (!verbose) ::testing::internal::GetCapturedStdout(); - } - - std::string convert_compressed_to_text(std::string compressed_file) - { - if (!verbose) ::testing::internal::CaptureStdout(); - std::string converted_file = compressed_file.substr(0, compressed_file.find_last_of('.')); - std::string cmdline = - fmt::format("{} -d -c {} > {}", ZSTD_BINARY, compressed_file, converted_file); - system(cmdline.c_str()); - if (!verbose) ::testing::internal::GetCapturedStdout(); - return converted_file; - } -}; - -TEST_F(DumpXYZGZTest, compressed_run0) -{ - if (!ZSTD_BINARY) GTEST_SKIP(); - - auto text_files = "dump_xyz_zstd_text_run*.melt.xyz"; - auto compressed_files = "dump_xyz_zstd_compressed_run*.melt.xyz.zst"; - auto text_file = "dump_xyz_zstd_text_run0.melt.xyz"; - auto compressed_file = "dump_xyz_zstd_compressed_run0.melt.xyz.zst"; - - generate_text_and_compressed_dump(text_files, compressed_files, "xyz/zstd", "", 0); - - TearDown(); - - ASSERT_FILE_EXISTS(text_file); - ASSERT_FILE_EXISTS(compressed_file); - - auto converted_file = convert_compressed_to_text(compressed_file); - - ASSERT_FILE_EXISTS(converted_file); - ASSERT_FILE_EQUAL(text_file, converted_file); - delete_file(text_file); - delete_file(compressed_file); - delete_file(converted_file); -} - -int main(int argc, char **argv) -{ - MPI_Init(&argc, &argv); - ::testing::InitGoogleMock(&argc, argv); - - // 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; - } - } - } - - ZSTD_BINARY = getenv("ZSTD_BINARY"); - - if ((argc > 1) && (strcmp(argv[1], "-v") == 0)) verbose = true; - - int rv = RUN_ALL_TESTS(); - MPI_Finalize(); - return rv; -} From c5cb294506c478ea0f01c431a162626d4dff5fc3 Mon Sep 17 00:00:00 2001 From: Richard Berger Date: Thu, 11 Mar 2021 12:42:19 -0500 Subject: [PATCH 08/14] Add other compression tests to xyz tests --- unittest/formats/test_dump_xyz_compressed.cpp | 170 ++++++++++++++++++ 1 file changed, 170 insertions(+) diff --git a/unittest/formats/test_dump_xyz_compressed.cpp b/unittest/formats/test_dump_xyz_compressed.cpp index 8f82ccebe2..b0ab846ba3 100644 --- a/unittest/formats/test_dump_xyz_compressed.cpp +++ b/unittest/formats/test_dump_xyz_compressed.cpp @@ -56,6 +56,176 @@ TEST_F(DumpXYZCompressTest, compressed_run0) delete_file(converted_file_0); } +TEST_F(DumpXYZCompressTest, compressed_multi_file_run1) +{ + if (!COMPRESS_BINARY) GTEST_SKIP(); + + auto base_name = "multi_file_run1_*.melt.xyz"; + auto base_name_0 = "multi_file_run1_0.melt.xyz"; + auto base_name_1 = "multi_file_run1_1.melt.xyz"; + auto text_file = text_dump_filename(base_name); + auto text_file_0 = text_dump_filename(base_name_0); + auto text_file_1 = text_dump_filename(base_name_1); + auto compressed_file = compressed_dump_filename(base_name); + 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); + + TearDown(); + + auto converted_file_0 = convert_compressed_to_text(compressed_file_0); + auto converted_file_1 = convert_compressed_to_text(compressed_file_1); + + ASSERT_THAT(converted_file_0, Eq(converted_dump_filename(base_name_0))); + ASSERT_THAT(converted_file_1, Eq(converted_dump_filename(base_name_1))); + ASSERT_FILE_EXISTS(converted_file_0); + ASSERT_FILE_EXISTS(converted_file_1); + ASSERT_FILE_EQUAL(text_file_0, converted_file_0); + ASSERT_FILE_EQUAL(text_file_1, converted_file_1); + + delete_file(text_file_0); + delete_file(text_file_1); + delete_file(compressed_file_0); + delete_file(compressed_file_1); + delete_file(converted_file_0); + delete_file(converted_file_1); +} + +TEST_F(DumpXYZCompressTest, compressed_multi_file_with_pad_run1) +{ + if (!COMPRESS_BINARY) GTEST_SKIP(); + + auto base_name = "multi_file_pad_run1_*.melt.xyz"; + auto base_name_0 = "multi_file_pad_run1_000.melt.xyz"; + auto base_name_1 = "multi_file_pad_run1_001.melt.xyz"; + auto text_file = text_dump_filename(base_name); + auto text_file_0 = text_dump_filename(base_name_0); + auto text_file_1 = text_dump_filename(base_name_1); + auto compressed_file = compressed_dump_filename(base_name); + 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, "", "pad 3", 1); + + TearDown(); + + ASSERT_FILE_EXISTS(text_file_0); + ASSERT_FILE_EXISTS(text_file_1); + ASSERT_FILE_EXISTS(compressed_file_0); + ASSERT_FILE_EXISTS(compressed_file_1); + + auto converted_file_0 = convert_compressed_to_text(compressed_file_0); + auto converted_file_1 = convert_compressed_to_text(compressed_file_1); + + ASSERT_THAT(converted_file_0, Eq(converted_dump_filename(base_name_0))); + ASSERT_THAT(converted_file_1, Eq(converted_dump_filename(base_name_1))); + ASSERT_FILE_EXISTS(converted_file_0); + ASSERT_FILE_EXISTS(converted_file_1); + ASSERT_FILE_EQUAL(text_file_0, converted_file_0); + ASSERT_FILE_EQUAL(text_file_1, converted_file_1); + + delete_file(text_file_0); + delete_file(text_file_1); + delete_file(compressed_file_0); + delete_file(compressed_file_1); + delete_file(converted_file_0); + delete_file(converted_file_1); +} + +TEST_F(DumpXYZCompressTest, compressed_multi_file_with_maxfiles_run1) +{ + if (!COMPRESS_BINARY) GTEST_SKIP(); + + auto base_name = "multi_file_maxfiles_run1_*.melt.xyz"; + auto base_name_0 = "multi_file_maxfiles_run1_0.melt.xyz"; + auto base_name_1 = "multi_file_maxfiles_run1_1.melt.xyz"; + auto base_name_2 = "multi_file_maxfiles_run1_2.melt.xyz"; + auto text_file = text_dump_filename(base_name); + auto text_file_0 = text_dump_filename(base_name_0); + auto text_file_1 = text_dump_filename(base_name_1); + auto text_file_2 = text_dump_filename(base_name_2); + auto compressed_file = compressed_dump_filename(base_name); + auto compressed_file_0 = compressed_dump_filename(base_name_0); + auto compressed_file_1 = compressed_dump_filename(base_name_1); + auto compressed_file_2 = compressed_dump_filename(base_name_2); + + generate_text_and_compressed_dump(text_file, compressed_file, "", "maxfiles 2", 2); + + TearDown(); + + ASSERT_FILE_NOT_EXISTS(text_file_0); + ASSERT_FILE_EXISTS(text_file_1); + ASSERT_FILE_EXISTS(text_file_2); + ASSERT_FILE_NOT_EXISTS(compressed_file_0); + ASSERT_FILE_EXISTS(compressed_file_1); + ASSERT_FILE_EXISTS(compressed_file_2); + + auto converted_file_1 = convert_compressed_to_text(compressed_file_1); + auto converted_file_2 = convert_compressed_to_text(compressed_file_2); + + ASSERT_THAT(converted_file_1, Eq(converted_dump_filename(base_name_1))); + ASSERT_THAT(converted_file_2, Eq(converted_dump_filename(base_name_2))); + ASSERT_FILE_EXISTS(converted_file_1); + ASSERT_FILE_EXISTS(converted_file_2); + ASSERT_FILE_EQUAL(text_file_1, converted_file_1); + ASSERT_FILE_EQUAL(text_file_2, converted_file_2); + + delete_file(text_file_1); + delete_file(text_file_2); + delete_file(compressed_file_1); + delete_file(compressed_file_2); + delete_file(converted_file_1); + delete_file(converted_file_2); +} + +TEST_F(DumpXYZCompressTest, compressed_modify_bad_param) +{ + if (compression_style != "xyz/gz") GTEST_SKIP(); + + command(fmt::format("dump id1 all {} 1 {}", compression_style, compressed_dump_filename("modify_bad_param_run0_*.melt.xyz"))); + + TEST_FAILURE(".*ERROR: Illegal dump_modify command: compression level must in the range of.*", + command("dump_modify id1 compression_level 12"); + ); +} + +TEST_F(DumpXYZCompressTest, compressed_modify_multi_bad_param) +{ + if (compression_style != "xyz/gz") GTEST_SKIP(); + + command(fmt::format("dump id1 all {} 1 {}", compression_style, compressed_dump_filename("modify_multi_bad_param_run0_*.melt.xyz"))); + + TEST_FAILURE(".*ERROR: Illegal dump_modify command: compression level must in the range of.*", + command("dump_modify id1 pad 3 compression_level 12"); + ); +} + +TEST_F(DumpXYZCompressTest, compressed_modify_clevel_run0) +{ + if (!COMPRESS_BINARY) GTEST_SKIP(); + + auto base_name = "modify_clevel_run0.melt.xyz"; + auto text_file = text_dump_filename(base_name); + auto compressed_file = compressed_dump_filename(base_name); + + generate_text_and_compressed_dump(text_file, compressed_file, "", "", "", "compression_level 3", 0); + + TearDown(); + + ASSERT_FILE_EXISTS(text_file); + ASSERT_FILE_EXISTS(compressed_file); + + auto converted_file = convert_compressed_to_text(compressed_file); + + ASSERT_THAT(converted_file, Eq(converted_dump_filename(base_name))); + ASSERT_FILE_EXISTS(converted_file); + ASSERT_FILE_EQUAL(text_file, converted_file); + delete_file(text_file); + delete_file(compressed_file); + delete_file(converted_file); +} + int main(int argc, char **argv) { MPI_Init(&argc, &argv); From 7e3d1923ab181b1d6bf8114d608b6db824c7bf0e Mon Sep 17 00:00:00 2001 From: Richard Berger Date: Thu, 11 Mar 2021 13:02:18 -0500 Subject: [PATCH 09/14] Add more compression tests for dump cfg --- unittest/formats/test_dump_cfg_compressed.cpp | 179 ++++++++++++++++++ 1 file changed, 179 insertions(+) diff --git a/unittest/formats/test_dump_cfg_compressed.cpp b/unittest/formats/test_dump_cfg_compressed.cpp index d06eabe57b..b1eaaeee38 100644 --- a/unittest/formats/test_dump_cfg_compressed.cpp +++ b/unittest/formats/test_dump_cfg_compressed.cpp @@ -91,6 +91,185 @@ TEST_F(DumpCfgCompressTest, compressed_unwrap_run0) delete_file(converted_file_0); } +TEST_F(DumpCfgCompressTest, compressed_multi_file_run1) +{ + if (!COMPRESS_BINARY) GTEST_SKIP(); + + auto base_name = "multi_file_run1_*.melt.cfg"; + auto base_name_0 = "multi_file_run1_0.melt.cfg"; + auto base_name_1 = "multi_file_run1_1.melt.cfg"; + auto text_file = text_dump_filename(base_name); + auto text_file_0 = text_dump_filename(base_name_0); + auto text_file_1 = text_dump_filename(base_name_1); + auto compressed_file = compressed_dump_filename(base_name); + auto compressed_file_0 = compressed_dump_filename(base_name_0); + 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); + + TearDown(); + + auto converted_file_0 = convert_compressed_to_text(compressed_file_0); + auto converted_file_1 = convert_compressed_to_text(compressed_file_1); + + ASSERT_THAT(converted_file_0, Eq(converted_dump_filename(base_name_0))); + ASSERT_THAT(converted_file_1, Eq(converted_dump_filename(base_name_1))); + ASSERT_FILE_EXISTS(converted_file_0); + ASSERT_FILE_EXISTS(converted_file_1); + ASSERT_FILE_EQUAL(text_file_0, converted_file_0); + ASSERT_FILE_EQUAL(text_file_1, converted_file_1); + + delete_file(text_file_0); + delete_file(text_file_1); + delete_file(compressed_file_0); + delete_file(compressed_file_1); + delete_file(converted_file_0); + delete_file(converted_file_1); +} + +TEST_F(DumpCfgCompressTest, compressed_multi_file_with_pad_run1) +{ + if (!COMPRESS_BINARY) GTEST_SKIP(); + + auto base_name = "multi_file_pad_run1_*.melt.cfg"; + auto base_name_0 = "multi_file_pad_run1_000.melt.cfg"; + auto base_name_1 = "multi_file_pad_run1_001.melt.cfg"; + auto text_file = text_dump_filename(base_name); + auto text_file_0 = text_dump_filename(base_name_0); + auto text_file_1 = text_dump_filename(base_name_1); + auto compressed_file = compressed_dump_filename(base_name); + auto compressed_file_0 = compressed_dump_filename(base_name_0); + 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, "pad 3", 1); + + TearDown(); + + ASSERT_FILE_EXISTS(text_file_0); + ASSERT_FILE_EXISTS(text_file_1); + ASSERT_FILE_EXISTS(compressed_file_0); + ASSERT_FILE_EXISTS(compressed_file_1); + + auto converted_file_0 = convert_compressed_to_text(compressed_file_0); + auto converted_file_1 = convert_compressed_to_text(compressed_file_1); + + ASSERT_THAT(converted_file_0, Eq(converted_dump_filename(base_name_0))); + ASSERT_THAT(converted_file_1, Eq(converted_dump_filename(base_name_1))); + ASSERT_FILE_EXISTS(converted_file_0); + ASSERT_FILE_EXISTS(converted_file_1); + ASSERT_FILE_EQUAL(text_file_0, converted_file_0); + ASSERT_FILE_EQUAL(text_file_1, converted_file_1); + + delete_file(text_file_0); + delete_file(text_file_1); + delete_file(compressed_file_0); + delete_file(compressed_file_1); + delete_file(converted_file_0); + delete_file(converted_file_1); +} + +TEST_F(DumpCfgCompressTest, compressed_multi_file_with_maxfiles_run1) +{ + if (!COMPRESS_BINARY) GTEST_SKIP(); + + auto base_name = "multi_file_maxfiles_run1_*.melt.cfg"; + auto base_name_0 = "multi_file_maxfiles_run1_0.melt.cfg"; + auto base_name_1 = "multi_file_maxfiles_run1_1.melt.cfg"; + auto base_name_2 = "multi_file_maxfiles_run1_2.melt.cfg"; + auto text_file = text_dump_filename(base_name); + auto text_file_0 = text_dump_filename(base_name_0); + auto text_file_1 = text_dump_filename(base_name_1); + auto text_file_2 = text_dump_filename(base_name_2); + auto compressed_file = compressed_dump_filename(base_name); + auto compressed_file_0 = compressed_dump_filename(base_name_0); + auto compressed_file_1 = compressed_dump_filename(base_name_1); + auto compressed_file_2 = compressed_dump_filename(base_name_2); + 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, "maxfiles 2", 2); + + TearDown(); + + ASSERT_FILE_NOT_EXISTS(text_file_0); + ASSERT_FILE_EXISTS(text_file_1); + ASSERT_FILE_EXISTS(text_file_2); + ASSERT_FILE_NOT_EXISTS(compressed_file_0); + ASSERT_FILE_EXISTS(compressed_file_1); + ASSERT_FILE_EXISTS(compressed_file_2); + + auto converted_file_1 = convert_compressed_to_text(compressed_file_1); + auto converted_file_2 = convert_compressed_to_text(compressed_file_2); + + ASSERT_THAT(converted_file_1, Eq(converted_dump_filename(base_name_1))); + ASSERT_THAT(converted_file_2, Eq(converted_dump_filename(base_name_2))); + ASSERT_FILE_EXISTS(converted_file_1); + ASSERT_FILE_EXISTS(converted_file_2); + ASSERT_FILE_EQUAL(text_file_1, converted_file_1); + ASSERT_FILE_EQUAL(text_file_2, converted_file_2); + + delete_file(text_file_1); + delete_file(text_file_2); + delete_file(compressed_file_1); + delete_file(compressed_file_2); + delete_file(converted_file_1); + delete_file(converted_file_2); +} + +TEST_F(DumpCfgCompressTest, compressed_modify_bad_param) +{ + if (compression_style != "cfg/gz") GTEST_SKIP(); + + auto fields = "mass type xs ys zs id proc procp1 x y z ix iy iz vx vy vz fx fy fz"; + command(fmt::format("dump id1 all {} 1 {} {}", compression_style, compressed_dump_filename("modify_bad_param_run0_*.melt.cfg"), fields)); + + TEST_FAILURE(".*ERROR: Illegal dump_modify command: compression level must in the range of.*", + command("dump_modify id1 compression_level 12"); + ); +} + +TEST_F(DumpCfgCompressTest, compressed_modify_multi_bad_param) +{ + if (compression_style != "cfg/gz") GTEST_SKIP(); + + auto fields = "mass type xs ys zs id proc procp1 x y z ix iy iz vx vy vz fx fy fz"; + command(fmt::format("dump id1 all {} 1 {} {}", compression_style, compressed_dump_filename("modify_multi_bad_param_run0_*.melt.cfg"), fields)); + + TEST_FAILURE(".*ERROR: Illegal dump_modify command: compression level must in the range of.*", + command("dump_modify id1 pad 3 compression_level 12"); + ); +} + +TEST_F(DumpCfgCompressTest, compressed_modify_clevel_run0) +{ + if (!COMPRESS_BINARY) GTEST_SKIP(); + + auto base_name = "modify_clevel_run*.melt.cfg"; + auto base_name_0 = "modify_clevel_run0.melt.cfg"; + auto text_file = text_dump_filename(base_name); + auto compressed_file = compressed_dump_filename(base_name); + auto text_file_0 = text_dump_filename(base_name_0); + 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_file, compressed_file, fields, fields, "", "compression_level 3", 0); + + TearDown(); + + ASSERT_FILE_EXISTS(text_file_0); + ASSERT_FILE_EXISTS(compressed_file_0); + + auto converted_file_0 = convert_compressed_to_text(compressed_file); + + ASSERT_THAT(converted_file_0, Eq(converted_dump_filename(base_name))); + ASSERT_FILE_EXISTS(converted_file_0); + ASSERT_FILE_EQUAL(text_file_0, converted_file_0); + delete_file(text_file_0); + delete_file(compressed_file_0); + delete_file(converted_file_0); +} + int main(int argc, char **argv) { MPI_Init(&argc, &argv); From f53fcf05456768ea1720fbfb05b19d6d5a5705f2 Mon Sep 17 00:00:00 2001 From: Richard Berger Date: Thu, 11 Mar 2021 13:12:43 -0500 Subject: [PATCH 10/14] Add more compression tests for dump custom --- .../formats/test_dump_atom_compressed.cpp | 4 + unittest/formats/test_dump_cfg_compressed.cpp | 4 + .../formats/test_dump_custom_compressed.cpp | 176 ++++++++++++++++++ unittest/formats/test_dump_xyz_compressed.cpp | 4 + 4 files changed, 188 insertions(+) diff --git a/unittest/formats/test_dump_atom_compressed.cpp b/unittest/formats/test_dump_atom_compressed.cpp index 3360872f9e..c0d1f3bdb6 100644 --- a/unittest/formats/test_dump_atom_compressed.cpp +++ b/unittest/formats/test_dump_atom_compressed.cpp @@ -332,7 +332,9 @@ TEST_F(DumpAtomCompressTest, compressed_modify_bad_param) { if (compression_style != "atom/gz") GTEST_SKIP(); + if (!verbose) ::testing::internal::CaptureStdout(); command(fmt::format("dump id1 all {} 1 {}", compression_style, compressed_dump_filename("modify_bad_param_run0_*.melt"))); + if (!verbose) ::testing::internal::GetCapturedStdout(); TEST_FAILURE(".*ERROR: Illegal dump_modify command: compression level must in the range of.*", command("dump_modify id1 compression_level 12"); @@ -343,7 +345,9 @@ TEST_F(DumpAtomCompressTest, compressed_modify_multi_bad_param) { if (compression_style != "atom/gz") GTEST_SKIP(); + if (!verbose) ::testing::internal::CaptureStdout(); command(fmt::format("dump id1 all {} 1 {}", compression_style, compressed_dump_filename("modify_multi_bad_param_run0_*.melt"))); + if (!verbose) ::testing::internal::GetCapturedStdout(); TEST_FAILURE(".*ERROR: Illegal dump_modify command: compression level must in the range of.*", command("dump_modify id1 pad 3 compression_level 12"); diff --git a/unittest/formats/test_dump_cfg_compressed.cpp b/unittest/formats/test_dump_cfg_compressed.cpp index b1eaaeee38..66ab6921d5 100644 --- a/unittest/formats/test_dump_cfg_compressed.cpp +++ b/unittest/formats/test_dump_cfg_compressed.cpp @@ -222,7 +222,9 @@ TEST_F(DumpCfgCompressTest, compressed_modify_bad_param) if (compression_style != "cfg/gz") GTEST_SKIP(); auto fields = "mass type xs ys zs id proc procp1 x y z ix iy iz vx vy vz fx fy fz"; + if (!verbose) ::testing::internal::CaptureStdout(); command(fmt::format("dump id1 all {} 1 {} {}", compression_style, compressed_dump_filename("modify_bad_param_run0_*.melt.cfg"), fields)); + if (!verbose) ::testing::internal::GetCapturedStdout(); TEST_FAILURE(".*ERROR: Illegal dump_modify command: compression level must in the range of.*", command("dump_modify id1 compression_level 12"); @@ -234,7 +236,9 @@ TEST_F(DumpCfgCompressTest, compressed_modify_multi_bad_param) if (compression_style != "cfg/gz") GTEST_SKIP(); auto fields = "mass type xs ys zs id proc procp1 x y z ix iy iz vx vy vz fx fy fz"; + if (!verbose) ::testing::internal::CaptureStdout(); command(fmt::format("dump id1 all {} 1 {} {}", compression_style, compressed_dump_filename("modify_multi_bad_param_run0_*.melt.cfg"), fields)); + if (!verbose) ::testing::internal::GetCapturedStdout(); TEST_FAILURE(".*ERROR: Illegal dump_modify command: compression level must in the range of.*", command("dump_modify id1 pad 3 compression_level 12"); diff --git a/unittest/formats/test_dump_custom_compressed.cpp b/unittest/formats/test_dump_custom_compressed.cpp index 0afad264fb..8118442dbd 100644 --- a/unittest/formats/test_dump_custom_compressed.cpp +++ b/unittest/formats/test_dump_custom_compressed.cpp @@ -81,6 +81,182 @@ TEST_F(DumpCustomCompressTest, compressed_triclinic_run1) delete_file(converted_file); } +TEST_F(DumpCustomCompressTest, compressed_multi_file_run1) +{ + if (!COMPRESS_BINARY) GTEST_SKIP(); + + auto base_name = "multi_file_run1_*.melt.custom"; + auto base_name_0 = "multi_file_run1_0.melt.custom"; + auto base_name_1 = "multi_file_run1_1.melt.custom"; + auto text_file = text_dump_filename(base_name); + auto text_file_0 = text_dump_filename(base_name_0); + auto text_file_1 = text_dump_filename(base_name_1); + auto compressed_file = compressed_dump_filename(base_name); + auto compressed_file_0 = compressed_dump_filename(base_name_0); + 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); + + TearDown(); + + auto converted_file_0 = convert_compressed_to_text(compressed_file_0); + auto converted_file_1 = convert_compressed_to_text(compressed_file_1); + + ASSERT_THAT(converted_file_0, Eq(converted_dump_filename(base_name_0))); + ASSERT_THAT(converted_file_1, Eq(converted_dump_filename(base_name_1))); + ASSERT_FILE_EXISTS(converted_file_0); + ASSERT_FILE_EXISTS(converted_file_1); + ASSERT_FILE_EQUAL(text_file_0, converted_file_0); + ASSERT_FILE_EQUAL(text_file_1, converted_file_1); + + delete_file(text_file_0); + delete_file(text_file_1); + delete_file(compressed_file_0); + delete_file(compressed_file_1); + delete_file(converted_file_0); + delete_file(converted_file_1); +} + +TEST_F(DumpCustomCompressTest, compressed_multi_file_with_pad_run1) +{ + if (!COMPRESS_BINARY) GTEST_SKIP(); + + auto base_name = "multi_file_pad_run1_*.melt.custom"; + auto base_name_0 = "multi_file_pad_run1_000.melt.custom"; + auto base_name_1 = "multi_file_pad_run1_001.melt.custom"; + auto text_file = text_dump_filename(base_name); + auto text_file_0 = text_dump_filename(base_name_0); + auto text_file_1 = text_dump_filename(base_name_1); + auto compressed_file = compressed_dump_filename(base_name); + auto compressed_file_0 = compressed_dump_filename(base_name_0); + 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, "pad 3", 1); + + TearDown(); + + ASSERT_FILE_EXISTS(text_file_0); + ASSERT_FILE_EXISTS(text_file_1); + ASSERT_FILE_EXISTS(compressed_file_0); + ASSERT_FILE_EXISTS(compressed_file_1); + + auto converted_file_0 = convert_compressed_to_text(compressed_file_0); + auto converted_file_1 = convert_compressed_to_text(compressed_file_1); + + ASSERT_THAT(converted_file_0, Eq(converted_dump_filename(base_name_0))); + ASSERT_THAT(converted_file_1, Eq(converted_dump_filename(base_name_1))); + ASSERT_FILE_EXISTS(converted_file_0); + ASSERT_FILE_EXISTS(converted_file_1); + ASSERT_FILE_EQUAL(text_file_0, converted_file_0); + ASSERT_FILE_EQUAL(text_file_1, converted_file_1); + + delete_file(text_file_0); + delete_file(text_file_1); + delete_file(compressed_file_0); + delete_file(compressed_file_1); + delete_file(converted_file_0); + delete_file(converted_file_1); +} + +TEST_F(DumpCustomCompressTest, compressed_multi_file_with_maxfiles_run1) +{ + if (!COMPRESS_BINARY) GTEST_SKIP(); + + auto base_name = "multi_file_maxfiles_run1_*.melt.custom"; + auto base_name_0 = "multi_file_maxfiles_run1_0.melt.custom"; + auto base_name_1 = "multi_file_maxfiles_run1_1.melt.custom"; + auto base_name_2 = "multi_file_maxfiles_run1_2.melt.custom"; + auto text_file = text_dump_filename(base_name); + auto text_file_0 = text_dump_filename(base_name_0); + auto text_file_1 = text_dump_filename(base_name_1); + auto text_file_2 = text_dump_filename(base_name_2); + auto compressed_file = compressed_dump_filename(base_name); + auto compressed_file_0 = compressed_dump_filename(base_name_0); + auto compressed_file_1 = compressed_dump_filename(base_name_1); + auto compressed_file_2 = compressed_dump_filename(base_name_2); + 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, "maxfiles 2", 2); + + TearDown(); + + ASSERT_FILE_NOT_EXISTS(text_file_0); + ASSERT_FILE_EXISTS(text_file_1); + ASSERT_FILE_EXISTS(text_file_2); + ASSERT_FILE_NOT_EXISTS(compressed_file_0); + ASSERT_FILE_EXISTS(compressed_file_1); + ASSERT_FILE_EXISTS(compressed_file_2); + + auto converted_file_1 = convert_compressed_to_text(compressed_file_1); + auto converted_file_2 = convert_compressed_to_text(compressed_file_2); + + ASSERT_THAT(converted_file_1, Eq(converted_dump_filename(base_name_1))); + ASSERT_THAT(converted_file_2, Eq(converted_dump_filename(base_name_2))); + ASSERT_FILE_EXISTS(converted_file_1); + ASSERT_FILE_EXISTS(converted_file_2); + ASSERT_FILE_EQUAL(text_file_1, converted_file_1); + ASSERT_FILE_EQUAL(text_file_2, converted_file_2); + + delete_file(text_file_1); + delete_file(text_file_2); + delete_file(compressed_file_1); + delete_file(compressed_file_2); + delete_file(converted_file_1); + delete_file(converted_file_2); +} + +TEST_F(DumpCustomCompressTest, compressed_modify_bad_param) +{ + if (compression_style != "custom/gz") GTEST_SKIP(); + + 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"; + command(fmt::format("dump id1 all {} 1 {} {}", compression_style, compressed_dump_filename("modify_bad_param_run0_*.melt.custom"), fields)); + + TEST_FAILURE(".*ERROR: Illegal dump_modify command: compression level must in the range of.*", + command("dump_modify id1 compression_level 12"); + ); +} + +TEST_F(DumpCustomCompressTest, compressed_modify_multi_bad_param) +{ + if (compression_style != "custom/gz") GTEST_SKIP(); + + 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"; + command(fmt::format("dump id1 all {} 1 {} {}", compression_style, compressed_dump_filename("modify_multi_bad_param_run0_*.melt.custom"), fields)); + + TEST_FAILURE(".*ERROR: Illegal dump_modify command: compression level must in the range of.*", + command("dump_modify id1 pad 3 compression_level 12"); + ); +} + +TEST_F(DumpCustomCompressTest, compressed_modify_clevel_run0) +{ + if (!COMPRESS_BINARY) GTEST_SKIP(); + + auto base_name = "modify_clevel_run0.melt.custom"; + auto text_file = text_dump_filename(base_name); + 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, fields, "", "compression_level 3", 0); + + TearDown(); + + ASSERT_FILE_EXISTS(text_file); + ASSERT_FILE_EXISTS(compressed_file); + + auto converted_file = convert_compressed_to_text(compressed_file); + + ASSERT_THAT(converted_file, Eq(converted_dump_filename(base_name))); + ASSERT_FILE_EXISTS(converted_file); + ASSERT_FILE_EQUAL(text_file, converted_file); + delete_file(text_file); + delete_file(compressed_file); + delete_file(converted_file); +} + int main(int argc, char **argv) { MPI_Init(&argc, &argv); diff --git a/unittest/formats/test_dump_xyz_compressed.cpp b/unittest/formats/test_dump_xyz_compressed.cpp index b0ab846ba3..9a61c746a0 100644 --- a/unittest/formats/test_dump_xyz_compressed.cpp +++ b/unittest/formats/test_dump_xyz_compressed.cpp @@ -183,7 +183,9 @@ TEST_F(DumpXYZCompressTest, compressed_modify_bad_param) { if (compression_style != "xyz/gz") GTEST_SKIP(); + if (!verbose) ::testing::internal::CaptureStdout(); command(fmt::format("dump id1 all {} 1 {}", compression_style, compressed_dump_filename("modify_bad_param_run0_*.melt.xyz"))); + if (!verbose) ::testing::internal::GetCapturedStdout(); TEST_FAILURE(".*ERROR: Illegal dump_modify command: compression level must in the range of.*", command("dump_modify id1 compression_level 12"); @@ -194,7 +196,9 @@ TEST_F(DumpXYZCompressTest, compressed_modify_multi_bad_param) { if (compression_style != "xyz/gz") GTEST_SKIP(); + if (!verbose) ::testing::internal::CaptureStdout(); command(fmt::format("dump id1 all {} 1 {}", compression_style, compressed_dump_filename("modify_multi_bad_param_run0_*.melt.xyz"))); + if (!verbose) ::testing::internal::GetCapturedStdout(); TEST_FAILURE(".*ERROR: Illegal dump_modify command: compression level must in the range of.*", command("dump_modify id1 pad 3 compression_level 12"); From 14da94d1893601894f39b86e252ead0eb2f3ec6a Mon Sep 17 00:00:00 2001 From: Richard Berger Date: Thu, 11 Mar 2021 13:27:54 -0500 Subject: [PATCH 11/14] Add more compression tests for dump local --- .../formats/test_dump_local_compressed.cpp | 194 +++++++++++++++++- 1 file changed, 190 insertions(+), 4 deletions(-) diff --git a/unittest/formats/test_dump_local_compressed.cpp b/unittest/formats/test_dump_local_compressed.cpp index 048053fb9a..b3c96b6edc 100644 --- a/unittest/formats/test_dump_local_compressed.cpp +++ b/unittest/formats/test_dump_local_compressed.cpp @@ -27,16 +27,20 @@ class DumpLocalCompressTest : public CompressedDumpTest { public: DumpLocalCompressTest() : CompressedDumpTest("local") { } + + void SetUp() override { + CompressedDumpTest::SetUp(); + + if (!verbose) ::testing::internal::CaptureStdout(); + command("compute comp all pair/local dist eng"); + if (!verbose) ::testing::internal::GetCapturedStdout(); + } }; TEST_F(DumpLocalCompressTest, compressed_run0) { if (!COMPRESS_BINARY) GTEST_SKIP(); - if (!verbose) ::testing::internal::CaptureStdout(); - command("compute comp all pair/local dist eng"); - if (!verbose) ::testing::internal::GetCapturedStdout(); - auto base_name = "run*.melt.local"; auto base_name_0 = "run0.melt.local"; auto text_files = text_dump_filename(base_name); @@ -61,6 +65,188 @@ TEST_F(DumpLocalCompressTest, compressed_run0) delete_file(converted_file_0); } +TEST_F(DumpLocalCompressTest, compressed_multi_file_run1) +{ + if (!COMPRESS_BINARY) GTEST_SKIP(); + + auto base_name = "multi_file_run1_*.melt.local"; + auto base_name_0 = "multi_file_run1_0.melt.local"; + auto base_name_1 = "multi_file_run1_1.melt.local"; + auto text_file = text_dump_filename(base_name); + auto text_file_0 = text_dump_filename(base_name_0); + auto text_file_1 = text_dump_filename(base_name_1); + auto compressed_file = compressed_dump_filename(base_name); + auto compressed_file_0 = compressed_dump_filename(base_name_0); + 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); + + TearDown(); + + auto converted_file_0 = convert_compressed_to_text(compressed_file_0); + auto converted_file_1 = convert_compressed_to_text(compressed_file_1); + + ASSERT_THAT(converted_file_0, Eq(converted_dump_filename(base_name_0))); + ASSERT_THAT(converted_file_1, Eq(converted_dump_filename(base_name_1))); + ASSERT_FILE_EXISTS(converted_file_0); + ASSERT_FILE_EXISTS(converted_file_1); + ASSERT_FILE_EQUAL(text_file_0, converted_file_0); + ASSERT_FILE_EQUAL(text_file_1, converted_file_1); + + delete_file(text_file_0); + delete_file(text_file_1); + delete_file(compressed_file_0); + delete_file(compressed_file_1); + delete_file(converted_file_0); + delete_file(converted_file_1); +} + +TEST_F(DumpLocalCompressTest, compressed_multi_file_with_pad_run1) +{ + if (!COMPRESS_BINARY) GTEST_SKIP(); + + auto base_name = "multi_file_pad_run1_*.melt.local"; + auto base_name_0 = "multi_file_pad_run1_000.melt.local"; + auto base_name_1 = "multi_file_pad_run1_001.melt.local"; + auto text_file = text_dump_filename(base_name); + auto text_file_0 = text_dump_filename(base_name_0); + auto text_file_1 = text_dump_filename(base_name_1); + auto compressed_file = compressed_dump_filename(base_name); + auto compressed_file_0 = compressed_dump_filename(base_name_0); + 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, "pad 3", 1); + + TearDown(); + + ASSERT_FILE_EXISTS(text_file_0); + ASSERT_FILE_EXISTS(text_file_1); + ASSERT_FILE_EXISTS(compressed_file_0); + ASSERT_FILE_EXISTS(compressed_file_1); + + auto converted_file_0 = convert_compressed_to_text(compressed_file_0); + auto converted_file_1 = convert_compressed_to_text(compressed_file_1); + + ASSERT_THAT(converted_file_0, Eq(converted_dump_filename(base_name_0))); + ASSERT_THAT(converted_file_1, Eq(converted_dump_filename(base_name_1))); + ASSERT_FILE_EXISTS(converted_file_0); + ASSERT_FILE_EXISTS(converted_file_1); + ASSERT_FILE_EQUAL(text_file_0, converted_file_0); + ASSERT_FILE_EQUAL(text_file_1, converted_file_1); + + delete_file(text_file_0); + delete_file(text_file_1); + delete_file(compressed_file_0); + delete_file(compressed_file_1); + delete_file(converted_file_0); + delete_file(converted_file_1); +} + +TEST_F(DumpLocalCompressTest, compressed_multi_file_with_maxfiles_run1) +{ + if (!COMPRESS_BINARY) GTEST_SKIP(); + + auto base_name = "multi_file_maxfiles_run1_*.melt.local"; + auto base_name_0 = "multi_file_maxfiles_run1_0.melt.local"; + auto base_name_1 = "multi_file_maxfiles_run1_1.melt.local"; + auto base_name_2 = "multi_file_maxfiles_run1_2.melt.local"; + auto text_file = text_dump_filename(base_name); + auto text_file_0 = text_dump_filename(base_name_0); + auto text_file_1 = text_dump_filename(base_name_1); + auto text_file_2 = text_dump_filename(base_name_2); + auto compressed_file = compressed_dump_filename(base_name); + auto compressed_file_0 = compressed_dump_filename(base_name_0); + auto compressed_file_1 = compressed_dump_filename(base_name_1); + auto compressed_file_2 = compressed_dump_filename(base_name_2); + auto fields = "index c_comp[1]"; + + generate_text_and_compressed_dump(text_file, compressed_file, fields, "maxfiles 2", 2); + + TearDown(); + + ASSERT_FILE_NOT_EXISTS(text_file_0); + ASSERT_FILE_EXISTS(text_file_1); + ASSERT_FILE_EXISTS(text_file_2); + ASSERT_FILE_NOT_EXISTS(compressed_file_0); + ASSERT_FILE_EXISTS(compressed_file_1); + ASSERT_FILE_EXISTS(compressed_file_2); + + auto converted_file_1 = convert_compressed_to_text(compressed_file_1); + auto converted_file_2 = convert_compressed_to_text(compressed_file_2); + + ASSERT_THAT(converted_file_1, Eq(converted_dump_filename(base_name_1))); + ASSERT_THAT(converted_file_2, Eq(converted_dump_filename(base_name_2))); + ASSERT_FILE_EXISTS(converted_file_1); + ASSERT_FILE_EXISTS(converted_file_2); + ASSERT_FILE_EQUAL(text_file_1, converted_file_1); + ASSERT_FILE_EQUAL(text_file_2, converted_file_2); + + delete_file(text_file_1); + delete_file(text_file_2); + delete_file(compressed_file_1); + delete_file(compressed_file_2); + delete_file(converted_file_1); + delete_file(converted_file_2); +} + +TEST_F(DumpLocalCompressTest, compressed_modify_bad_param) +{ + if (compression_style != "local/gz") GTEST_SKIP(); + + auto fields = "index c_comp[1]"; + + if (!verbose) ::testing::internal::CaptureStdout(); + command(fmt::format("dump id1 all {} 1 {} {}", compression_style, compressed_dump_filename("modify_bad_param_run0_*.melt.local"), fields)); + if (!verbose) ::testing::internal::GetCapturedStdout(); + + TEST_FAILURE(".*ERROR: Illegal dump_modify command: compression level must in the range of.*", + command("dump_modify id1 compression_level 12"); + ); +} + +TEST_F(DumpLocalCompressTest, compressed_modify_multi_bad_param) +{ + if (compression_style != "local/gz") GTEST_SKIP(); + + auto fields = "index c_comp[1]"; + + if (!verbose) ::testing::internal::CaptureStdout(); + command(fmt::format("dump id1 all {} 1 {} {}", compression_style, compressed_dump_filename("modify_multi_bad_param_run0_*.melt.local"), fields)); + if (!verbose) ::testing::internal::GetCapturedStdout(); + + TEST_FAILURE(".*ERROR: Illegal dump_modify command: compression level must in the range of.*", + command("dump_modify id1 pad 3 compression_level 12"); + ); +} + +TEST_F(DumpLocalCompressTest, compressed_modify_clevel_run0) +{ + if (!COMPRESS_BINARY) GTEST_SKIP(); + + auto base_name = "modify_clevel_run0.melt.local"; + auto text_file = text_dump_filename(base_name); + auto compressed_file = compressed_dump_filename(base_name); + auto fields = "index c_comp[1]"; + + generate_text_and_compressed_dump(text_file, compressed_file, fields, fields, "", "compression_level 3", 0); + + TearDown(); + + ASSERT_FILE_EXISTS(text_file); + ASSERT_FILE_EXISTS(compressed_file); + + auto converted_file = convert_compressed_to_text(compressed_file); + + ASSERT_THAT(converted_file, Eq(converted_dump_filename(base_name))); + ASSERT_FILE_EXISTS(converted_file); + ASSERT_FILE_EQUAL(text_file, converted_file); + delete_file(text_file); + delete_file(compressed_file); + delete_file(converted_file); +} + int main(int argc, char **argv) { MPI_Init(&argc, &argv); From 76d857e42888300efb128d201dbdf7fb0be72945 Mon Sep 17 00:00:00 2001 From: Richard Berger Date: Thu, 11 Mar 2021 14:21:16 -0500 Subject: [PATCH 12/14] 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: From 012cdf3763f5687bf3044070214942daa126537d Mon Sep 17 00:00:00 2001 From: jrgissing Date: Sat, 20 Mar 2021 16:20:57 -0400 Subject: [PATCH 13/14] performance improvement bugfix --- src/USER-REACTION/fix_bond_react.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/USER-REACTION/fix_bond_react.cpp b/src/USER-REACTION/fix_bond_react.cpp index 91354506d1..46c55f4199 100644 --- a/src/USER-REACTION/fix_bond_react.cpp +++ b/src/USER-REACTION/fix_bond_react.cpp @@ -2566,6 +2566,7 @@ void FixBondReact::unlimit_bond() } // really should only communicate this per-atom property, not entire reneighboring + MPI_Allreduce(MPI_IN_PLACE,&unlimitflag,1,MPI_INT,MPI_MAX,world); if (unlimitflag) next_reneighbor = update->ntimestep; } From b3f465babe387fe8299d50b5bf003e6baf1adbf9 Mon Sep 17 00:00:00 2001 From: jrgissing Date: Sat, 20 Mar 2021 16:34:55 -0400 Subject: [PATCH 14/14] decrease foward_comm nsize due to new placement of probability evaluation --- src/USER-REACTION/fix_bond_react.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/USER-REACTION/fix_bond_react.cpp b/src/USER-REACTION/fix_bond_react.cpp index 46c55f4199..94d1a596f8 100644 --- a/src/USER-REACTION/fix_bond_react.cpp +++ b/src/USER-REACTION/fix_bond_react.cpp @@ -965,7 +965,7 @@ void FixBondReact::post_integrate() // forward comm of partner, so ghosts have it commflag = 2; - comm->forward_comm_fix(this,2); + comm->forward_comm_fix(this,1); // consider for reaction: // only if both atoms list each other as winning bond partner