Add tests for dump local/gz and xyz/gz
This commit is contained in:
@ -116,18 +116,18 @@ void DumpLocalGZ::write_header(bigint ndump)
|
||||
|
||||
gzprintf(gzFp,"ITEM: TIMESTEP\n");
|
||||
gzprintf(gzFp,BIGINT_FORMAT "\n",update->ntimestep);
|
||||
gzprintf(gzFp,"ITEM: NUMBER OF ATOMS\n");
|
||||
gzprintf(gzFp,"ITEM: NUMBER OF ENTRIES\n");
|
||||
gzprintf(gzFp,BIGINT_FORMAT "\n",ndump);
|
||||
if (domain->triclinic == 0) {
|
||||
gzprintf(gzFp,"ITEM: BOX BOUNDS %s\n",boundstr);
|
||||
gzprintf(gzFp,"%-1.16g %-1.16g\n",boxxlo,boxxhi);
|
||||
gzprintf(gzFp,"%-1.16g %-1.16g\n",boxylo,boxyhi);
|
||||
gzprintf(gzFp,"%-1.16g %-1.16g\n",boxzlo,boxzhi);
|
||||
} else {
|
||||
if (domain->triclinic) {
|
||||
gzprintf(gzFp,"ITEM: BOX BOUNDS xy xz yz %s\n",boundstr);
|
||||
gzprintf(gzFp,"%-1.16g %-1.16g %-1.16g\n",boxxlo,boxxhi,boxxy);
|
||||
gzprintf(gzFp,"%-1.16g %-1.16g %-1.16g\n",boxylo,boxyhi,boxxz);
|
||||
gzprintf(gzFp,"%-1.16g %-1.16g %-1.16g\n",boxzlo,boxzhi,boxyz);
|
||||
} else {
|
||||
gzprintf(gzFp,"ITEM: BOX BOUNDS %s\n",boundstr);
|
||||
gzprintf(gzFp,"%-1.16g %-1.16g\n",boxxlo,boxxhi);
|
||||
gzprintf(gzFp,"%-1.16g %-1.16g\n",boxylo,boxyhi);
|
||||
gzprintf(gzFp,"%-1.16g %-1.16g\n",boxzlo,boxzhi);
|
||||
}
|
||||
gzprintf(gzFp,"ITEM: %s %s\n",label,columns);
|
||||
}
|
||||
|
||||
@ -268,14 +268,14 @@ void DumpLocal::write_header(bigint ndump)
|
||||
fprintf(fp,BIGINT_FORMAT "\n",ndump);
|
||||
if (domain->triclinic) {
|
||||
fprintf(fp,"ITEM: BOX BOUNDS xy xz yz %s\n",boundstr);
|
||||
fprintf(fp,"%g %g %g\n",boxxlo,boxxhi,boxxy);
|
||||
fprintf(fp,"%g %g %g\n",boxylo,boxyhi,boxxz);
|
||||
fprintf(fp,"%g %g %g\n",boxzlo,boxzhi,boxyz);
|
||||
fprintf(fp,"%-1.16g %-1.16g %-1.16g\n",boxxlo,boxxhi,boxxy);
|
||||
fprintf(fp,"%-1.16g %-1.16g %-1.16g\n",boxylo,boxyhi,boxxz);
|
||||
fprintf(fp,"%-1.16g %-1.16g %-1.16g\n",boxzlo,boxzhi,boxyz);
|
||||
} else {
|
||||
fprintf(fp,"ITEM: BOX BOUNDS %s\n",boundstr);
|
||||
fprintf(fp,"%g %g\n",boxxlo,boxxhi);
|
||||
fprintf(fp,"%g %g\n",boxylo,boxyhi);
|
||||
fprintf(fp,"%g %g\n",boxzlo,boxzhi);
|
||||
fprintf(fp,"%-1.16g %-1.16g\n",boxxlo,boxxhi);
|
||||
fprintf(fp,"%-1.16g %-1.16g\n",boxylo,boxyhi);
|
||||
fprintf(fp,"%-1.16g %-1.16g\n",boxzlo,boxzhi);
|
||||
}
|
||||
fprintf(fp,"ITEM: %s %s\n",label,columns);
|
||||
}
|
||||
|
||||
@ -50,6 +50,18 @@ if (PKG_COMPRESS)
|
||||
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_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_program(ZSTD_BINARY NAMES zstd)
|
||||
|
||||
if (ZSTD_BINARY)
|
||||
|
||||
106
unittest/formats/test_dump_local_gz.cpp
Normal file
106
unittest/formats/test_dump_local_gz.cpp
Normal file
@ -0,0 +1,106 @@
|
||||
/* ----------------------------------------------------------------------
|
||||
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 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<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;
|
||||
}
|
||||
101
unittest/formats/test_dump_xyz_gz.cpp
Normal file
101
unittest/formats/test_dump_xyz_gz.cpp
Normal file
@ -0,0 +1,101 @@
|
||||
/* ----------------------------------------------------------------------
|
||||
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 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;
|
||||
}
|
||||
Reference in New Issue
Block a user