From 831a4a780827fc96e5782b052e03761a26c45e9a Mon Sep 17 00:00:00 2001 From: William F Godoy Date: Fri, 1 Nov 2019 10:56:16 -0400 Subject: [PATCH] Serial test for config files --- testing/adios2/xml/CMakeLists.txt | 10 ++ testing/adios2/xml/TestXMLConfigSerial.cpp | 112 +++++++++++++++++++++ 2 files changed, 122 insertions(+) create mode 100644 testing/adios2/xml/TestXMLConfigSerial.cpp diff --git a/testing/adios2/xml/CMakeLists.txt b/testing/adios2/xml/CMakeLists.txt index 947dd6328b..2e0424daff 100644 --- a/testing/adios2/xml/CMakeLists.txt +++ b/testing/adios2/xml/CMakeLists.txt @@ -4,6 +4,16 @@ #------------------------------------------------------------------------------# gtest_add_tests_helper(XMLConfig ${test_mpi} "" "" "") +if(ADIOS2_HAVE_MPI) + gtest_add_tests_helper(XMLConfigSerial NOEXEC "" "" "") +else() + gtest_add_tests_helper(XMLConfigSerial FALSE "" "" "") +endif() + target_compile_definitions(Test.XMLConfig PRIVATE "XML_CONFIG_DIR=${CMAKE_CURRENT_SOURCE_DIR}" ) + +target_compile_definitions(Test.XMLConfigSerial PRIVATE + "XML_CONFIG_DIR=${CMAKE_CURRENT_SOURCE_DIR}" +) diff --git a/testing/adios2/xml/TestXMLConfigSerial.cpp b/testing/adios2/xml/TestXMLConfigSerial.cpp new file mode 100644 index 0000000000..9e5aa6ac64 --- /dev/null +++ b/testing/adios2/xml/TestXMLConfigSerial.cpp @@ -0,0 +1,112 @@ +#include + +#include +#include + +#include + +#include + +#define str_helper(X) #X +#define str(X) str_helper(X) + +class XMLConfigSerialTest : public ::testing::Test +{ +public: + XMLConfigSerialTest() : configDir(str(XML_CONFIG_DIR)) {} + + // protected: + // virtual void SetUp() { } + + // virtual void TearDown() { } + std::string configDir; +}; + +TEST_F(XMLConfigSerialTest, TwoIOs) +{ + const std::string configFile( + configDir + std::string(&adios2::PathSeparator, 1) + "config1.xml"); + + adios2::ADIOS adios(configFile, adios2::DebugON); + + // must be declared at least once + EXPECT_THROW(adios2::IO io = adios.AtIO("Test IO 1"), + std::invalid_argument); + + EXPECT_NO_THROW({ + adios2::IO io = adios.DeclareIO("Test IO 1"); + const adios2::Params params = io.Parameters(); + ASSERT_EQ(params.size(), 5); + EXPECT_THROW(params.at("DoesNotExist"), std::out_of_range); + EXPECT_EQ(params.at("Threads"), "1"); + EXPECT_EQ(params.at("ProfileUnits"), "Microseconds"); + EXPECT_EQ(params.at("MaxBufferSize"), "20Mb"); + EXPECT_EQ(params.at("InitialBufferSize"), "1Mb"); + EXPECT_EQ(params.at("BufferGrowthFactor"), "2"); + adios2::Engine engine = + io.Open("Test BP Writer 1", adios2::Mode::Write); + engine.Close(); + }); + EXPECT_NO_THROW(adios2::IO io = adios.AtIO("Test IO 1")); + + EXPECT_THROW(adios2::IO io = adios.AtIO("Test IO 2"), + std::invalid_argument); + EXPECT_NO_THROW({ + adios2::IO io = adios.DeclareIO("Test IO 2"); + const adios2::Params params = io.Parameters(); + ASSERT_EQ(params.size(), 0); + }); + EXPECT_NO_THROW(adios.AtIO("Test IO 2")); + + // double declaring + EXPECT_THROW(adios.DeclareIO("Test IO 1"), std::invalid_argument); + EXPECT_THROW(adios.DeclareIO("Test IO 2"), std::invalid_argument); +} + +TEST_F(XMLConfigSerialTest, TwoEnginesException) +{ + const std::string configFile( + configDir + std::string(&adios2::PathSeparator, 1) + "config2.xml"); + + EXPECT_THROW(adios2::ADIOS adios(configFile, adios2::DebugON), + std::invalid_argument); +} + +TEST_F(XMLConfigSerialTest, OpTypeException) +{ + const std::string configFile(configDir + + std::string(&adios2::PathSeparator, 1) + + "configOpTypeException.xml"); + + EXPECT_THROW(adios2::ADIOS adios(configFile, adios2::DebugON), + std::invalid_argument); +} + +TEST_F(XMLConfigSerialTest, OpNullException) +{ + const std::string configFile(configDir + + std::string(&adios2::PathSeparator, 1) + + "configOpNullException.xml"); + + EXPECT_THROW(adios2::ADIOS adios(configFile, adios2::DebugON), + std::invalid_argument); +} + +TEST_F(XMLConfigSerialTest, OpNoneException) +{ + const std::string configFile(configDir + + std::string(&adios2::PathSeparator, 1) + + "configOpNoneException.xml"); + + EXPECT_THROW(adios2::ADIOS adios(configFile, adios2::DebugON), + std::invalid_argument); +} + +int main(int argc, char **argv) +{ + int result; + ::testing::InitGoogleTest(&argc, argv); + result = RUN_ALL_TESTS(); + + return result; +}