combine repetitive code into convenience function
This commit is contained in:
@ -38,7 +38,6 @@
|
||||
#include <cstdio>
|
||||
#include <cstdlib>
|
||||
#include <cstring>
|
||||
#include <ctime>
|
||||
#include <mpi.h>
|
||||
|
||||
#include <map>
|
||||
@ -235,48 +234,8 @@ void generate_yaml_file(const char *outfile, const TestConfig &config)
|
||||
|
||||
YamlWriter writer(outfile);
|
||||
|
||||
// lammps_version
|
||||
writer.emit("lammps_version", 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);
|
||||
// write yaml header
|
||||
write_yaml_header(&writer, &test_config, lmp->version);
|
||||
|
||||
// angle_style
|
||||
writer.emit("angle_style", config.angle_style);
|
||||
|
||||
@ -38,7 +38,6 @@
|
||||
#include <cstdio>
|
||||
#include <cstdlib>
|
||||
#include <cstring>
|
||||
#include <ctime>
|
||||
#include <mpi.h>
|
||||
|
||||
#include <map>
|
||||
@ -235,48 +234,8 @@ void generate_yaml_file(const char *outfile, const TestConfig &config)
|
||||
|
||||
YamlWriter writer(outfile);
|
||||
|
||||
// lammps_version
|
||||
writer.emit("lammps_version", 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);
|
||||
// write yaml header
|
||||
write_yaml_header(&writer, &test_config, lmp->version);
|
||||
|
||||
// bond_style
|
||||
writer.emit("bond_style", config.bond_style);
|
||||
|
||||
@ -38,7 +38,6 @@
|
||||
#include <cstdio>
|
||||
#include <cstdlib>
|
||||
#include <cstring>
|
||||
#include <ctime>
|
||||
#include <mpi.h>
|
||||
|
||||
#include <map>
|
||||
@ -244,40 +243,8 @@ void generate_yaml_file(const char *outfile, const TestConfig &config)
|
||||
|
||||
YamlWriter writer(outfile);
|
||||
|
||||
// lammps_version
|
||||
writer.emit("lammps_version", 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);
|
||||
// write yaml header
|
||||
write_yaml_header(&writer, &test_config, lmp->version);
|
||||
|
||||
// dihedral_style
|
||||
writer.emit("dihedral_style", config.dihedral_style);
|
||||
|
||||
@ -42,7 +42,6 @@
|
||||
#include <cstdio>
|
||||
#include <cstdlib>
|
||||
#include <cstring>
|
||||
#include <ctime>
|
||||
#include <mpi.h>
|
||||
|
||||
#include <map>
|
||||
@ -193,48 +192,8 @@ void generate_yaml_file(const char *outfile, const TestConfig &config)
|
||||
std::string block("");
|
||||
YamlWriter writer(outfile);
|
||||
|
||||
// lammps_version
|
||||
writer.emit("lammps_version", 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);
|
||||
// write yaml header
|
||||
write_yaml_header(&writer, &test_config, lmp->version);
|
||||
|
||||
// natoms
|
||||
writer.emit("natoms", natoms);
|
||||
|
||||
@ -38,7 +38,6 @@
|
||||
#include <cstdio>
|
||||
#include <cstdlib>
|
||||
#include <cstring>
|
||||
#include <ctime>
|
||||
#include <mpi.h>
|
||||
|
||||
#include <map>
|
||||
@ -235,48 +234,8 @@ void generate_yaml_file(const char *outfile, const TestConfig &config)
|
||||
|
||||
YamlWriter writer(outfile);
|
||||
|
||||
// lammps_version
|
||||
writer.emit("lammps_version", 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);
|
||||
// write yaml header
|
||||
write_yaml_header(&writer, &test_config, lmp->version);
|
||||
|
||||
// improper_style
|
||||
writer.emit("improper_style", config.improper_style);
|
||||
|
||||
@ -16,16 +16,19 @@
|
||||
#include "test_config.h"
|
||||
#include "test_config_reader.h"
|
||||
#include "utils.h"
|
||||
#include "yaml_writer.h"
|
||||
#include "gmock/gmock.h"
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
#include <cstdlib>
|
||||
#include <cstring>
|
||||
#include <ctime>
|
||||
#include <iostream>
|
||||
#include <mpi.h>
|
||||
#include <vector>
|
||||
|
||||
using LAMMPS_NS::utils::split_words;
|
||||
using LAMMPS_NS::utils::trim;
|
||||
|
||||
// common read_yaml_file function
|
||||
bool read_yaml_file(const char *infile, TestConfig &config)
|
||||
@ -37,6 +40,55 @@ bool read_yaml_file(const char *infile, TestConfig &config)
|
||||
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
|
||||
extern void generate_yaml_file(const char *, const TestConfig &);
|
||||
|
||||
|
||||
@ -22,6 +22,10 @@ extern bool print_stats;
|
||||
extern bool verbose;
|
||||
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) \
|
||||
do { \
|
||||
const double diff = fabs(val1 - val2); \
|
||||
@ -31,10 +35,11 @@ extern std::string INPUT_FOLDER;
|
||||
EXPECT_PRED_FORMAT2(::testing::DoubleLE, err, eps); \
|
||||
} while (0);
|
||||
|
||||
#endif
|
||||
|
||||
#if defined _WIN32
|
||||
static const char PATH_SEP = '\\';
|
||||
#else
|
||||
static const char PATH_SEP = '/';
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
@ -40,7 +40,6 @@
|
||||
#include <cstdio>
|
||||
#include <cstdlib>
|
||||
#include <cstring>
|
||||
#include <ctime>
|
||||
#include <mpi.h>
|
||||
|
||||
#include <map>
|
||||
@ -244,48 +243,8 @@ void generate_yaml_file(const char *outfile, const TestConfig &config)
|
||||
|
||||
YamlWriter writer(outfile);
|
||||
|
||||
// lammps_version
|
||||
writer.emit("lammps_version", 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);
|
||||
// write yaml header
|
||||
write_yaml_header(&writer, &test_config, lmp->version);
|
||||
|
||||
// pair_style
|
||||
writer.emit("pair_style", config.pair_style);
|
||||
|
||||
Reference in New Issue
Block a user