Add tests for dump cfg/gz

This commit is contained in:
Richard Berger 2020-08-31 13:36:42 -04:00
parent 2f629db3d4
commit 5faca3aef0
No known key found for this signature in database
GPG Key ID: A9E83994E0BA0CAB
3 changed files with 152 additions and 17 deletions

View File

@ -44,6 +44,12 @@ 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}")
find_program(ZSTD_BINARY NAMES zstd)
if (ZSTD_BINARY)

View File

@ -46,7 +46,7 @@ TEST_F(DumpCfgTest, invalid_options)
TEST_F(DumpCfgTest, require_multifile)
{
auto dump_file = "dump_melt_run.cfg";
auto dump_file = "dump.melt.cfg_run.cfg";
auto fields = "mass type xs ys zs id proc procp1 x y z ix iy iz xu yu zu xsu ysu zsu vx vy vz fx fy fz";
if (!verbose) ::testing::internal::CaptureStdout();
@ -60,58 +60,58 @@ TEST_F(DumpCfgTest, require_multifile)
TEST_F(DumpCfgTest, run0)
{
auto dump_file = "dump_cfg_run*.melt";
auto dump_file = "dump_cfg_run*.melt.cfg";
auto fields = "mass type xs ys zs id proc procp1 x y z ix iy iz vx vy vz fx fy fz";
generate_dump(dump_file, fields, "", 0);
ASSERT_FILE_EXISTS("dump_cfg_run0.melt");
auto lines = read_lines("dump_cfg_run0.melt");
ASSERT_FILE_EXISTS("dump_cfg_run0.melt.cfg");
auto lines = read_lines("dump_cfg_run0.melt.cfg");
ASSERT_EQ(lines.size(), 124);
ASSERT_THAT(lines[0], Eq("Number of particles = 32"));
delete_file("dump_cfg_run0.melt");
delete_file("dump_cfg_run0.melt.cfg");
}
TEST_F(DumpCfgTest, unwrap_run0)
{
auto dump_file = "dump_cfg_unwrap_run*.melt";
auto dump_file = "dump_cfg_unwrap_run*.melt.cfg";
auto fields = "mass type xsu ysu zsu id proc procp1 x y z ix iy iz vx vy vz fx fy fz";
generate_dump(dump_file, fields, "", 0);
ASSERT_FILE_EXISTS("dump_cfg_unwrap_run0.melt");
auto lines = read_lines("dump_cfg_unwrap_run0.melt");
ASSERT_FILE_EXISTS("dump_cfg_unwrap_run0.melt.cfg");
auto lines = read_lines("dump_cfg_unwrap_run0.melt.cfg");
ASSERT_EQ(lines.size(), 124);
ASSERT_THAT(lines[0], Eq("Number of particles = 32"));
delete_file("dump_cfg_unwrap_run0.melt");
delete_file("dump_cfg_unwrap_run0.melt.cfg");
}
TEST_F(DumpCfgTest, no_buffer_run0)
{
auto dump_file = "dump_cfg_no_buffer_run*.melt";
auto dump_file = "dump_cfg_no_buffer_run*.melt.cfg";
auto fields = "mass type xsu ysu zsu id proc procp1 x y z ix iy iz vx vy vz fx fy fz";
generate_dump(dump_file, fields, "buffer no", 0);
ASSERT_FILE_EXISTS("dump_cfg_no_buffer_run0.melt");
auto lines = read_lines("dump_cfg_no_buffer_run0.melt");
ASSERT_FILE_EXISTS("dump_cfg_no_buffer_run0.melt.cfg");
auto lines = read_lines("dump_cfg_no_buffer_run0.melt.cfg");
ASSERT_EQ(lines.size(), 124);
ASSERT_THAT(lines[0], Eq("Number of particles = 32"));
delete_file("dump_cfg_no_buffer_run0.melt");
delete_file("dump_cfg_no_buffer_run0.melt.cfg");
}
TEST_F(DumpCfgTest, no_unwrap_no_buffer_run0)
{
auto dump_file = "dump_cfg_no_unwrap_no_buffer_run*.melt";
auto dump_file = "dump_cfg_no_unwrap_no_buffer_run*.melt.cfg";
auto fields = "mass type xs ys zs id proc procp1 x y z ix iy iz vx vy vz fx fy fz";
generate_dump(dump_file, fields, "buffer no", 0);
ASSERT_FILE_EXISTS("dump_cfg_no_unwrap_no_buffer_run0.melt");
auto lines = read_lines("dump_cfg_no_unwrap_no_buffer_run0.melt");
ASSERT_FILE_EXISTS("dump_cfg_no_unwrap_no_buffer_run0.melt.cfg");
auto lines = read_lines("dump_cfg_no_unwrap_no_buffer_run0.melt.cfg");
ASSERT_EQ(lines.size(), 124);
ASSERT_THAT(lines[0], Eq("Number of particles = 32"));
delete_file("dump_cfg_no_unwrap_no_buffer_run0.melt");
delete_file("dump_cfg_no_unwrap_no_buffer_run0.melt.cfg");
}

View File

@ -0,0 +1,129 @@
/* ----------------------------------------------------------------------
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 "gtest/gtest.h"
#include "gmock/gmock.h"
#include "fmt/format.h"
#include "utils.h"
#include "../testing/core.h"
#include "../testing/systems/melt.h"
#include "../testing/utils.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<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;
}