Unify dump xyz/gz and xyz/zstd tests
This commit is contained in:
@ -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()
|
||||
|
||||
|
||||
97
unittest/formats/test_dump_xyz_compressed.cpp
Normal file
97
unittest/formats/test_dump_xyz_compressed.cpp
Normal file
@ -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 <string>
|
||||
|
||||
|
||||
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<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;
|
||||
}
|
||||
@ -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<std::string> 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;
|
||||
}
|
||||
@ -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<std::string> 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;
|
||||
}
|
||||
Reference in New Issue
Block a user