Add more tests for COMPRESS package

This commit is contained in:
Richard Berger
2021-03-11 14:21:16 -05:00
parent 14da94d189
commit 76d857e428
12 changed files with 129 additions and 219 deletions

View File

@ -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})

View File

@ -17,9 +17,9 @@
#include "../testing/systems/melt.h"
#include <string>
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:

View File

@ -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 <string>
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<std::string> 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;
}

View File

@ -24,6 +24,7 @@
using ::testing::Eq;
char *BINARY2TXT_BINARY = nullptr;
bool verbose = false;
class DumpAtomTest : public MeltTest {
std::string dump_style = "atom";

View File

@ -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<std::string> 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;
}

View File

@ -21,6 +21,8 @@
using ::testing::Eq;
bool verbose = false;
class DumpCfgTest : public MeltTest {
std::string dump_style = "cfg";

View File

@ -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<std::string> 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;
}

View File

@ -22,6 +22,7 @@
using ::testing::Eq;
char *BINARY2TXT_BINARY = nullptr;
bool verbose = false;
class DumpCustomTest : public MeltTest {
std::string dump_style = "custom";

View File

@ -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<std::string> 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;
}

View File

@ -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<std::string> 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;
}

View File

@ -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<std::string> 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;
}

View File

@ -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: