Refactored generated keyword test to reduce compilation time

This commit is contained in:
Joakim Hove 2019-12-31 14:50:18 +01:00
parent 3c6a60c4a9
commit 087aec6e01
4 changed files with 46 additions and 39 deletions

View File

@ -3,8 +3,8 @@ execute_process(COMMAND ${CMAKE_COMMAND} -E copy_if_different
${BASE_DIR}/ParserInit.cpp)
execute_process(COMMAND ${CMAKE_COMMAND} -E copy_if_different
${BASE_DIR}/tmp_gen/inlinekw.cpp
${BASE_DIR}/inlinekw.cpp)
${BASE_DIR}/tmp_gen/TestKeywords.cpp
${BASE_DIR}/TestKeywords.cpp)
file(GLOB HDRS ${BASE_DIR}/tmp_gen/include/opm/parser/eclipse/Parser/ParserKeywords/*.hpp)

View File

@ -4,10 +4,10 @@ set(EXTRA_TESTS)
# Generated source, needs to be here
opm_add_test(InlineKeywordTest
EXE_NAME inlinekw
SOURCES ${PROJECT_BINARY_DIR}/inlinekw.cpp
EXE_NAME TestKeywords
SOURCES ${PROJECT_BINARY_DIR}/TestKeywords.cpp
LIBRARIES ${TEST_LIBS})
list(APPEND EXTRA_TESTS inlinekw)
list(APPEND EXTRA_TESTS TestKeywords)
# Extra compile definitions and extra parameters
include(cmake/Modules/CheckCaseSensitiveFileSystem.cmake)

View File

@ -74,7 +74,7 @@ add_custom_command( OUTPUT
${PROJECT_BINARY_DIR}/tmp_gen/ParserInit.cpp
${PROJECT_BINARY_DIR}/tmp_gen/include/
opm/parser/eclipse/Parser/ParserKeywords
${PROJECT_BINARY_DIR}/tmp_gen/inlinekw.cpp
${PROJECT_BINARY_DIR}/tmp_gen/TestKeywords.cpp
DEPENDS genkw ${keyword_files} src/opm/parser/eclipse/share/keywords/keyword_list.cmake
)
@ -106,7 +106,7 @@ add_custom_command(OUTPUT
${PROJECT_BINARY_DIR}/ParserKeywords/X.cpp
${PROJECT_BINARY_DIR}/ParserKeywords/Y.cpp
${PROJECT_BINARY_DIR}/ParserKeywords/Z.cpp
${PROJECT_BINARY_DIR}/inlinekw.cpp
${PROJECT_BINARY_DIR}/TestKeywords.cpp
${PROJECT_BINARY_DIR}/ParserInit.cpp
DEPENDS ${PROJECT_BINARY_DIR}/tmp_gen/ParserKeywords/A.cpp
COMMAND ${CMAKE_COMMAND} -DBASE_DIR=${PROJECT_BINARY_DIR}

View File

@ -34,17 +34,6 @@
namespace {
const std::string testHeader =
"#define BOOST_TEST_MODULE ParserRecordTests\n"
"#include <boost/filesystem.hpp>\n"
"#include <boost/test/unit_test.hpp>\n"
"#include <memory>\n"
"#include <opm/json/JsonObject.hpp>\n"
"#include <opm/parser/eclipse/Parser/ParserKeyword.hpp>\n"
"#include <opm/parser/eclipse/Parser/ParserItem.hpp>\n"
"#include <opm/parser/eclipse/Parser/ParserRecord.hpp>\n"
"#include <opm/parser/eclipse/Units/UnitSystem.hpp>\n"
"auto unitSystem = Opm::UnitSystem::newMETRIC();\n";
const std::string sourceHeader =
"#include <opm/parser/eclipse/Deck/UDAValue.hpp>\n"
@ -166,33 +155,51 @@ namespace Opm {
void KeywordGenerator::updateTest(const KeywordLoader& loader , const std::string& testFile) const {
std::stringstream stream;
stream << testHeader;
for(const auto& kw_pair : loader) {
const auto& first_char = kw_pair.first;
stream << "#include <opm/parser/eclipse/Parser/ParserKeywords/" << first_char << ".hpp>" << std::endl;
stream << "namespace Opm {" << std::endl;
}
stream << R"(
#define BOOST_TEST_MODULE GeneratedKeywordTest
#include <boost/filesystem.hpp>
#include <boost/test/unit_test.hpp>
#include <memory>
#include <opm/json/JsonObject.hpp>
#include <opm/parser/eclipse/Parser/ParserKeyword.hpp>
#include <opm/parser/eclipse/Parser/ParserItem.hpp>
#include <opm/parser/eclipse/Parser/ParserRecord.hpp>
#include <opm/parser/eclipse/Units/UnitSystem.hpp>
auto unitSystem = Opm::UnitSystem::newMETRIC();
namespace Opm {
void test_keyword(const ParserKeyword& inline_keyword, const std::string& json_file) {
boost::filesystem::path jsonPath( json_file );
Json::JsonObject jsonConfig( jsonPath );
ParserKeyword json_keyword(jsonConfig);
BOOST_CHECK_EQUAL( json_keyword, inline_keyword);
if (json_keyword.hasDimension()) {
const auto& parserRecord = json_keyword.getRecord(0);
for (size_t i=0; i < parserRecord.size(); i++){
const auto& item = parserRecord.get( i );
for (const auto& dim : item.dimensions())
BOOST_CHECK_NO_THROW( unitSystem.getNewDimension( dim ));
}
}
}
)";
for(const auto& kw_pair : loader) {
stream << std::endl << "BOOST_AUTO_TEST_CASE(TestKeywords" << kw_pair.first << ") {" << std::endl;
const auto& keywords = kw_pair.second;
for (const auto& kw: keywords) {
const std::string& keywordName = kw.getName();
stream << startTest(keywordName);
stream << " std::string jsonFile = \"" << loader.getJsonFile( keywordName) << "\";" << std::endl;
stream << " boost::filesystem::path jsonPath( jsonFile );" << std::endl;
stream << " Json::JsonObject jsonConfig( jsonPath );" << std::endl;
stream << " ParserKeyword jsonKeyword(jsonConfig);" << std::endl;
stream << " ParserKeywords::" << keywordName << " inlineKeyword;" << std::endl;
stream << " BOOST_CHECK_EQUAL( jsonKeyword, inlineKeyword );" << std::endl;
stream << " if (jsonKeyword.hasDimension()) {" <<std::endl;
stream << " const auto& parserRecord = jsonKeyword.getRecord(0);" << std::endl;
stream << " for (size_t i=0; i < parserRecord.size(); i++){" << std::endl;
stream << " const auto& item = parserRecord.get( i );" << std::endl;
stream << " for (const auto& dim : item.dimensions())" << std::endl;
stream << " BOOST_CHECK_NO_THROW( unitSystem.getNewDimension( dim ));" << std::endl;
stream << " }" << std::endl;
stream << " }" << std::endl;
stream << endTest( );
}
for (const auto& kw: keywords)
stream << " test_keyword( ParserKeywords::" << kw.getName() << "(),\"" << loader.getJsonFile( kw.getName()) << "\");" << std::endl;
stream << "}" << std::endl;
}
stream << "}" << std::endl;
updateFile( stream , testFile );
}
}