combine repetitive code into convenience function
This commit is contained in:
@ -38,7 +38,6 @@
|
|||||||
#include <cstdio>
|
#include <cstdio>
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
#include <ctime>
|
|
||||||
#include <mpi.h>
|
#include <mpi.h>
|
||||||
|
|
||||||
#include <map>
|
#include <map>
|
||||||
@ -235,48 +234,8 @@ void generate_yaml_file(const char *outfile, const TestConfig &config)
|
|||||||
|
|
||||||
YamlWriter writer(outfile);
|
YamlWriter writer(outfile);
|
||||||
|
|
||||||
// lammps_version
|
// write yaml header
|
||||||
writer.emit("lammps_version", lmp->version);
|
write_yaml_header(&writer, &test_config, lmp->version);
|
||||||
|
|
||||||
// date_generated
|
|
||||||
std::time_t now = time(NULL);
|
|
||||||
block = utils::trim(ctime(&now));
|
|
||||||
writer.emit("date_generated", block);
|
|
||||||
|
|
||||||
// epsilon
|
|
||||||
writer.emit("epsilon", config.epsilon);
|
|
||||||
|
|
||||||
// skip tests
|
|
||||||
block.clear();
|
|
||||||
for (auto &skip_tests : config.skip_tests) {
|
|
||||||
if (block.empty()) block = skip_tests;
|
|
||||||
else block += " " + skip_tests;
|
|
||||||
}
|
|
||||||
writer.emit("skip_tests", block);
|
|
||||||
|
|
||||||
// prerequisites
|
|
||||||
block.clear();
|
|
||||||
for (auto &prerequisite : config.prerequisites) {
|
|
||||||
block += prerequisite.first + " " + prerequisite.second + "\n";
|
|
||||||
}
|
|
||||||
writer.emit_block("prerequisites", block);
|
|
||||||
|
|
||||||
// pre_commands
|
|
||||||
block.clear();
|
|
||||||
for (auto &command : config.pre_commands) {
|
|
||||||
block += command + "\n";
|
|
||||||
}
|
|
||||||
writer.emit_block("pre_commands", block);
|
|
||||||
|
|
||||||
// post_commands
|
|
||||||
block.clear();
|
|
||||||
for (auto &command : config.post_commands) {
|
|
||||||
block += command + "\n";
|
|
||||||
}
|
|
||||||
writer.emit_block("post_commands", block);
|
|
||||||
|
|
||||||
// input_file
|
|
||||||
writer.emit("input_file", config.input_file);
|
|
||||||
|
|
||||||
// angle_style
|
// angle_style
|
||||||
writer.emit("angle_style", config.angle_style);
|
writer.emit("angle_style", config.angle_style);
|
||||||
|
|||||||
@ -38,7 +38,6 @@
|
|||||||
#include <cstdio>
|
#include <cstdio>
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
#include <ctime>
|
|
||||||
#include <mpi.h>
|
#include <mpi.h>
|
||||||
|
|
||||||
#include <map>
|
#include <map>
|
||||||
@ -235,48 +234,8 @@ void generate_yaml_file(const char *outfile, const TestConfig &config)
|
|||||||
|
|
||||||
YamlWriter writer(outfile);
|
YamlWriter writer(outfile);
|
||||||
|
|
||||||
// lammps_version
|
// write yaml header
|
||||||
writer.emit("lammps_version", lmp->version);
|
write_yaml_header(&writer, &test_config, lmp->version);
|
||||||
|
|
||||||
// date_generated
|
|
||||||
std::time_t now = time(NULL);
|
|
||||||
block = utils::trim(ctime(&now));
|
|
||||||
writer.emit("date_generated", block);
|
|
||||||
|
|
||||||
// epsilon
|
|
||||||
writer.emit("epsilon", config.epsilon);
|
|
||||||
|
|
||||||
// skip tests
|
|
||||||
block.clear();
|
|
||||||
for (auto &skip_tests : config.skip_tests) {
|
|
||||||
if (block.empty()) block = skip_tests;
|
|
||||||
else block += " " + skip_tests;
|
|
||||||
}
|
|
||||||
writer.emit("skip_tests", block);
|
|
||||||
|
|
||||||
// prerequisites
|
|
||||||
block.clear();
|
|
||||||
for (auto &prerequisite : config.prerequisites) {
|
|
||||||
block += prerequisite.first + " " + prerequisite.second + "\n";
|
|
||||||
}
|
|
||||||
writer.emit_block("prerequisites", block);
|
|
||||||
|
|
||||||
// pre_commands
|
|
||||||
block.clear();
|
|
||||||
for (auto &command : config.pre_commands) {
|
|
||||||
block += command + "\n";
|
|
||||||
}
|
|
||||||
writer.emit_block("pre_commands", block);
|
|
||||||
|
|
||||||
// post_commands
|
|
||||||
block.clear();
|
|
||||||
for (auto &command : config.post_commands) {
|
|
||||||
block += command + "\n";
|
|
||||||
}
|
|
||||||
writer.emit_block("post_commands", block);
|
|
||||||
|
|
||||||
// input_file
|
|
||||||
writer.emit("input_file", config.input_file);
|
|
||||||
|
|
||||||
// bond_style
|
// bond_style
|
||||||
writer.emit("bond_style", config.bond_style);
|
writer.emit("bond_style", config.bond_style);
|
||||||
|
|||||||
@ -38,7 +38,6 @@
|
|||||||
#include <cstdio>
|
#include <cstdio>
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
#include <ctime>
|
|
||||||
#include <mpi.h>
|
#include <mpi.h>
|
||||||
|
|
||||||
#include <map>
|
#include <map>
|
||||||
@ -244,40 +243,8 @@ void generate_yaml_file(const char *outfile, const TestConfig &config)
|
|||||||
|
|
||||||
YamlWriter writer(outfile);
|
YamlWriter writer(outfile);
|
||||||
|
|
||||||
// lammps_version
|
// write yaml header
|
||||||
writer.emit("lammps_version", lmp->version);
|
write_yaml_header(&writer, &test_config, lmp->version);
|
||||||
|
|
||||||
// date_generated
|
|
||||||
std::time_t now = time(NULL);
|
|
||||||
block = utils::trim(ctime(&now));
|
|
||||||
writer.emit("date_generated", block);
|
|
||||||
|
|
||||||
// epsilon
|
|
||||||
writer.emit("epsilon", config.epsilon);
|
|
||||||
|
|
||||||
// prerequisites
|
|
||||||
block.clear();
|
|
||||||
for (auto &prerequisite : config.prerequisites) {
|
|
||||||
block += prerequisite.first + " " + prerequisite.second + "\n";
|
|
||||||
}
|
|
||||||
writer.emit_block("prerequisites", block);
|
|
||||||
|
|
||||||
// pre_commands
|
|
||||||
block.clear();
|
|
||||||
for (auto &command : config.pre_commands) {
|
|
||||||
block += command + "\n";
|
|
||||||
}
|
|
||||||
writer.emit_block("pre_commands", block);
|
|
||||||
|
|
||||||
// post_commands
|
|
||||||
block.clear();
|
|
||||||
for (auto &command : config.post_commands) {
|
|
||||||
block += command + "\n";
|
|
||||||
}
|
|
||||||
writer.emit_block("post_commands", block);
|
|
||||||
|
|
||||||
// input_file
|
|
||||||
writer.emit("input_file", config.input_file);
|
|
||||||
|
|
||||||
// dihedral_style
|
// dihedral_style
|
||||||
writer.emit("dihedral_style", config.dihedral_style);
|
writer.emit("dihedral_style", config.dihedral_style);
|
||||||
|
|||||||
@ -42,7 +42,6 @@
|
|||||||
#include <cstdio>
|
#include <cstdio>
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
#include <ctime>
|
|
||||||
#include <mpi.h>
|
#include <mpi.h>
|
||||||
|
|
||||||
#include <map>
|
#include <map>
|
||||||
@ -193,48 +192,8 @@ void generate_yaml_file(const char *outfile, const TestConfig &config)
|
|||||||
std::string block("");
|
std::string block("");
|
||||||
YamlWriter writer(outfile);
|
YamlWriter writer(outfile);
|
||||||
|
|
||||||
// lammps_version
|
// write yaml header
|
||||||
writer.emit("lammps_version", lmp->version);
|
write_yaml_header(&writer, &test_config, lmp->version);
|
||||||
|
|
||||||
// date_generated
|
|
||||||
std::time_t now = time(NULL);
|
|
||||||
block = utils::trim(ctime(&now));
|
|
||||||
writer.emit("date_generated", block);
|
|
||||||
|
|
||||||
// epsilon
|
|
||||||
writer.emit("epsilon", config.epsilon);
|
|
||||||
|
|
||||||
// skip tests
|
|
||||||
block.clear();
|
|
||||||
for (auto &skip_tests : config.skip_tests) {
|
|
||||||
if (block.empty()) block = skip_tests;
|
|
||||||
else block += " " + skip_tests;
|
|
||||||
}
|
|
||||||
writer.emit("skip_tests", block);
|
|
||||||
|
|
||||||
// prerequisites
|
|
||||||
block.clear();
|
|
||||||
for (auto &prerequisite : config.prerequisites) {
|
|
||||||
block += prerequisite.first + " " + prerequisite.second + "\n";
|
|
||||||
}
|
|
||||||
writer.emit_block("prerequisites", block);
|
|
||||||
|
|
||||||
// pre_commands
|
|
||||||
block.clear();
|
|
||||||
for (auto &command : config.pre_commands) {
|
|
||||||
block += command + "\n";
|
|
||||||
}
|
|
||||||
writer.emit_block("pre_commands", block);
|
|
||||||
|
|
||||||
// post_commands
|
|
||||||
block.clear();
|
|
||||||
for (auto &command : config.post_commands) {
|
|
||||||
block += command + "\n";
|
|
||||||
}
|
|
||||||
writer.emit_block("post_commands", block);
|
|
||||||
|
|
||||||
// input_file
|
|
||||||
writer.emit("input_file", config.input_file);
|
|
||||||
|
|
||||||
// natoms
|
// natoms
|
||||||
writer.emit("natoms", natoms);
|
writer.emit("natoms", natoms);
|
||||||
|
|||||||
@ -38,7 +38,6 @@
|
|||||||
#include <cstdio>
|
#include <cstdio>
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
#include <ctime>
|
|
||||||
#include <mpi.h>
|
#include <mpi.h>
|
||||||
|
|
||||||
#include <map>
|
#include <map>
|
||||||
@ -235,48 +234,8 @@ void generate_yaml_file(const char *outfile, const TestConfig &config)
|
|||||||
|
|
||||||
YamlWriter writer(outfile);
|
YamlWriter writer(outfile);
|
||||||
|
|
||||||
// lammps_version
|
// write yaml header
|
||||||
writer.emit("lammps_version", lmp->version);
|
write_yaml_header(&writer, &test_config, lmp->version);
|
||||||
|
|
||||||
// date_generated
|
|
||||||
std::time_t now = time(NULL);
|
|
||||||
block = utils::trim(ctime(&now));
|
|
||||||
writer.emit("date_generated", block);
|
|
||||||
|
|
||||||
// epsilon
|
|
||||||
writer.emit("epsilon", config.epsilon);
|
|
||||||
|
|
||||||
// skip tests
|
|
||||||
block.clear();
|
|
||||||
for (auto &skip_tests : config.skip_tests) {
|
|
||||||
if (block.empty()) block = skip_tests;
|
|
||||||
else block += " " + skip_tests;
|
|
||||||
}
|
|
||||||
writer.emit("skip_tests", block);
|
|
||||||
|
|
||||||
// prerequisites
|
|
||||||
block.clear();
|
|
||||||
for (auto &prerequisite : config.prerequisites) {
|
|
||||||
block += prerequisite.first + " " + prerequisite.second + "\n";
|
|
||||||
}
|
|
||||||
writer.emit_block("prerequisites", block);
|
|
||||||
|
|
||||||
// pre_commands
|
|
||||||
block.clear();
|
|
||||||
for (auto &command : config.pre_commands) {
|
|
||||||
block += command + "\n";
|
|
||||||
}
|
|
||||||
writer.emit_block("pre_commands", block);
|
|
||||||
|
|
||||||
// post_commands
|
|
||||||
block.clear();
|
|
||||||
for (auto &command : config.post_commands) {
|
|
||||||
block += command + "\n";
|
|
||||||
}
|
|
||||||
writer.emit_block("post_commands", block);
|
|
||||||
|
|
||||||
// input_file
|
|
||||||
writer.emit("input_file", config.input_file);
|
|
||||||
|
|
||||||
// improper_style
|
// improper_style
|
||||||
writer.emit("improper_style", config.improper_style);
|
writer.emit("improper_style", config.improper_style);
|
||||||
|
|||||||
@ -16,16 +16,19 @@
|
|||||||
#include "test_config.h"
|
#include "test_config.h"
|
||||||
#include "test_config_reader.h"
|
#include "test_config_reader.h"
|
||||||
#include "utils.h"
|
#include "utils.h"
|
||||||
|
#include "yaml_writer.h"
|
||||||
#include "gmock/gmock.h"
|
#include "gmock/gmock.h"
|
||||||
#include "gtest/gtest.h"
|
#include "gtest/gtest.h"
|
||||||
|
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
|
#include <ctime>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <mpi.h>
|
#include <mpi.h>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
using LAMMPS_NS::utils::split_words;
|
using LAMMPS_NS::utils::split_words;
|
||||||
|
using LAMMPS_NS::utils::trim;
|
||||||
|
|
||||||
// common read_yaml_file function
|
// common read_yaml_file function
|
||||||
bool read_yaml_file(const char *infile, TestConfig &config)
|
bool read_yaml_file(const char *infile, TestConfig &config)
|
||||||
@ -37,6 +40,55 @@ bool read_yaml_file(const char *infile, TestConfig &config)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// write out common header items for yaml files
|
||||||
|
void write_yaml_header(YamlWriter *writer,
|
||||||
|
TestConfig *cfg,
|
||||||
|
const char *version)
|
||||||
|
{
|
||||||
|
// lammps_version
|
||||||
|
writer->emit("lammps_version", version);
|
||||||
|
|
||||||
|
// date_generated
|
||||||
|
std::time_t now = time(NULL);
|
||||||
|
std::string block = trim(ctime(&now));
|
||||||
|
writer->emit("date_generated", block);
|
||||||
|
|
||||||
|
// epsilon
|
||||||
|
writer->emit("epsilon", cfg->epsilon);
|
||||||
|
|
||||||
|
// skip tests
|
||||||
|
block.clear();
|
||||||
|
for (auto &skip : cfg->skip_tests) {
|
||||||
|
if (block.empty()) block = skip;
|
||||||
|
else block += " " + skip;
|
||||||
|
}
|
||||||
|
writer->emit("skip_tests", block);
|
||||||
|
|
||||||
|
// prerequisites
|
||||||
|
block.clear();
|
||||||
|
for (auto &prerequisite : cfg->prerequisites) {
|
||||||
|
block += prerequisite.first + " " + prerequisite.second + "\n";
|
||||||
|
}
|
||||||
|
writer->emit_block("prerequisites", block);
|
||||||
|
|
||||||
|
// pre_commands
|
||||||
|
block.clear();
|
||||||
|
for (auto &command : cfg->pre_commands) {
|
||||||
|
block += command + "\n";
|
||||||
|
}
|
||||||
|
writer->emit_block("pre_commands", block);
|
||||||
|
|
||||||
|
// post_commands
|
||||||
|
block.clear();
|
||||||
|
for (auto &command : cfg->post_commands) {
|
||||||
|
block += command + "\n";
|
||||||
|
}
|
||||||
|
writer->emit_block("post_commands", block);
|
||||||
|
|
||||||
|
// input_file
|
||||||
|
writer->emit("input_file", cfg->input_file);
|
||||||
|
}
|
||||||
|
|
||||||
// need to be defined in unit test body
|
// need to be defined in unit test body
|
||||||
extern void generate_yaml_file(const char *, const TestConfig &);
|
extern void generate_yaml_file(const char *, const TestConfig &);
|
||||||
|
|
||||||
|
|||||||
@ -22,6 +22,10 @@ extern bool print_stats;
|
|||||||
extern bool verbose;
|
extern bool verbose;
|
||||||
extern std::string INPUT_FOLDER;
|
extern std::string INPUT_FOLDER;
|
||||||
|
|
||||||
|
// convenience method to write out common entries
|
||||||
|
void write_yaml_header(class YamlWriter *writer, TestConfig *cfg,
|
||||||
|
const char *version);
|
||||||
|
|
||||||
#define EXPECT_FP_LE_WITH_EPS(val1, val2, eps) \
|
#define EXPECT_FP_LE_WITH_EPS(val1, val2, eps) \
|
||||||
do { \
|
do { \
|
||||||
const double diff = fabs(val1 - val2); \
|
const double diff = fabs(val1 - val2); \
|
||||||
@ -31,10 +35,11 @@ extern std::string INPUT_FOLDER;
|
|||||||
EXPECT_PRED_FORMAT2(::testing::DoubleLE, err, eps); \
|
EXPECT_PRED_FORMAT2(::testing::DoubleLE, err, eps); \
|
||||||
} while (0);
|
} while (0);
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if defined _WIN32
|
#if defined _WIN32
|
||||||
static const char PATH_SEP = '\\';
|
static const char PATH_SEP = '\\';
|
||||||
#else
|
#else
|
||||||
static const char PATH_SEP = '/';
|
static const char PATH_SEP = '/';
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|||||||
@ -40,7 +40,6 @@
|
|||||||
#include <cstdio>
|
#include <cstdio>
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
#include <ctime>
|
|
||||||
#include <mpi.h>
|
#include <mpi.h>
|
||||||
|
|
||||||
#include <map>
|
#include <map>
|
||||||
@ -244,48 +243,8 @@ void generate_yaml_file(const char *outfile, const TestConfig &config)
|
|||||||
|
|
||||||
YamlWriter writer(outfile);
|
YamlWriter writer(outfile);
|
||||||
|
|
||||||
// lammps_version
|
// write yaml header
|
||||||
writer.emit("lammps_version", lmp->version);
|
write_yaml_header(&writer, &test_config, lmp->version);
|
||||||
|
|
||||||
// date_generated
|
|
||||||
std::time_t now = time(NULL);
|
|
||||||
block = utils::trim(ctime(&now));
|
|
||||||
writer.emit("date_generated", block);
|
|
||||||
|
|
||||||
// epsilon
|
|
||||||
writer.emit("epsilon", config.epsilon);
|
|
||||||
|
|
||||||
// skip tests
|
|
||||||
block.clear();
|
|
||||||
for (auto &skip_tests : config.skip_tests) {
|
|
||||||
if (block.empty()) block = skip_tests;
|
|
||||||
else block += " " + skip_tests;
|
|
||||||
}
|
|
||||||
writer.emit("skip_tests", block);
|
|
||||||
|
|
||||||
// prerequisites
|
|
||||||
block.clear();
|
|
||||||
for (auto &prerequisite : config.prerequisites) {
|
|
||||||
block += prerequisite.first + " " + prerequisite.second + "\n";
|
|
||||||
}
|
|
||||||
writer.emit_block("prerequisites", block);
|
|
||||||
|
|
||||||
// pre_commands
|
|
||||||
block.clear();
|
|
||||||
for (auto &command : config.pre_commands) {
|
|
||||||
block += command + "\n";
|
|
||||||
}
|
|
||||||
writer.emit_block("pre_commands", block);
|
|
||||||
|
|
||||||
// post_commands
|
|
||||||
block.clear();
|
|
||||||
for (auto &command : config.post_commands) {
|
|
||||||
block += command + "\n";
|
|
||||||
}
|
|
||||||
writer.emit_block("post_commands", block);
|
|
||||||
|
|
||||||
// input_file
|
|
||||||
writer.emit("input_file", config.input_file);
|
|
||||||
|
|
||||||
// pair_style
|
// pair_style
|
||||||
writer.emit("pair_style", config.pair_style);
|
writer.emit("pair_style", config.pair_style);
|
||||||
|
|||||||
Reference in New Issue
Block a user