From d712846b164965fbd9a2a57a87a116fe3e7aae2d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Klinkovsk=C3=BD?= <klinkovsky@mmg.fjfi.cvut.cz> Date: Tue, 7 Jul 2020 18:29:12 +0200 Subject: [PATCH] Cleaned up redundant code in ndarray tests --- .../DistributedNDArrayOverlaps_1D_test.h | 60 +------------------ .../DistributedNDArrayOverlaps_semi1D_test.h | 60 +------------------ .../ndarray/DistributedNDArray_1D_test.h | 60 +------------------ .../ndarray/DistributedNDArray_semi1D_test.h | 60 +------------------ .../Containers/ndarray/NDArrayTest.h | 14 ++--- .../Containers/ndarray/NDSubarrayTest.cpp | 14 ++--- .../Containers/ndarray/SlicedNDArrayTest.cpp | 14 ++--- .../ndarray/StaticNDArrayCudaTest.cu | 14 ++--- .../Containers/ndarray/StaticNDArrayTest.cpp | 14 ++--- 9 files changed, 24 insertions(+), 286 deletions(-) diff --git a/src/UnitTests/Containers/ndarray/DistributedNDArrayOverlaps_1D_test.h b/src/UnitTests/Containers/ndarray/DistributedNDArrayOverlaps_1D_test.h index a7609ee747..7377cbff24 100644 --- a/src/UnitTests/Containers/ndarray/DistributedNDArrayOverlaps_1D_test.h +++ b/src/UnitTests/Containers/ndarray/DistributedNDArrayOverlaps_1D_test.h @@ -308,62 +308,4 @@ TYPED_TEST( DistributedNDArrayOverlaps_1D_test, synchronize ) #endif // HAVE_GTEST -#if (defined(HAVE_GTEST) && defined(HAVE_MPI)) -using CommunicatorType = Communicators::MpiCommunicator; - -#include <sstream> - -class MinimalistBufferedPrinter -: public ::testing::EmptyTestEventListener -{ -private: - std::stringstream sout; - -public: - // Called before a test starts. - virtual void OnTestStart(const ::testing::TestInfo& test_info) - { - sout << test_info.test_case_name() << "." << test_info.name() << " Start." << std::endl; - } - - // Called after a failed assertion or a SUCCEED() invocation. - virtual void OnTestPartResult(const ::testing::TestPartResult& test_part_result) - { - sout << (test_part_result.failed() ? "====Failure=== " : "===Success=== ") - << test_part_result.file_name() << " " - << test_part_result.line_number() <<std::endl - << test_part_result.summary() <<std::endl; - } - - // Called after a test ends. - virtual void OnTestEnd(const ::testing::TestInfo& test_info) - { - const int rank = CommunicatorType::GetRank(CommunicatorType::AllGroup); - sout << test_info.test_case_name() << "." << test_info.name() << " End." <<std::endl; - std::cout << rank << ":" << std::endl << sout.str()<< std::endl; - sout.str( std::string() ); - sout.clear(); - } -}; -#endif - -#include "../../GtestMissingError.h" -int main( int argc, char* argv[] ) -{ -#ifdef HAVE_GTEST - ::testing::InitGoogleTest( &argc, argv ); - - #ifdef HAVE_MPI - ::testing::TestEventListeners& listeners = - ::testing::UnitTest::GetInstance()->listeners(); - - delete listeners.Release(listeners.default_result_printer()); - listeners.Append(new MinimalistBufferedPrinter); - - Communicators::ScopedInitializer< CommunicatorType > mpi(argc, argv); - #endif - return RUN_ALL_TESTS(); -#else - throw GtestMissingError(); -#endif -} +#include "../../main_mpi.h" diff --git a/src/UnitTests/Containers/ndarray/DistributedNDArrayOverlaps_semi1D_test.h b/src/UnitTests/Containers/ndarray/DistributedNDArrayOverlaps_semi1D_test.h index a7f28ead5d..f1ac970eb2 100644 --- a/src/UnitTests/Containers/ndarray/DistributedNDArrayOverlaps_semi1D_test.h +++ b/src/UnitTests/Containers/ndarray/DistributedNDArrayOverlaps_semi1D_test.h @@ -348,62 +348,4 @@ void test_helper_synchronize( DistributedArray& a, const int rank, const int npr #endif // HAVE_GTEST -#if (defined(HAVE_GTEST) && defined(HAVE_MPI)) -using CommunicatorType = Communicators::MpiCommunicator; - -#include <sstream> - -class MinimalistBufferedPrinter -: public ::testing::EmptyTestEventListener -{ -private: - std::stringstream sout; - -public: - // Called before a test starts. - virtual void OnTestStart(const ::testing::TestInfo& test_info) - { - sout << test_info.test_case_name() << "." << test_info.name() << " Start." << std::endl; - } - - // Called after a failed assertion or a SUCCEED() invocation. - virtual void OnTestPartResult(const ::testing::TestPartResult& test_part_result) - { - sout << (test_part_result.failed() ? "====Failure=== " : "===Success=== ") - << test_part_result.file_name() << " " - << test_part_result.line_number() <<std::endl - << test_part_result.summary() <<std::endl; - } - - // Called after a test ends. - virtual void OnTestEnd(const ::testing::TestInfo& test_info) - { - const int rank = CommunicatorType::GetRank(CommunicatorType::AllGroup); - sout << test_info.test_case_name() << "." << test_info.name() << " End." <<std::endl; - std::cout << rank << ":" << std::endl << sout.str()<< std::endl; - sout.str( std::string() ); - sout.clear(); - } -}; -#endif - -#include "../../GtestMissingError.h" -int main( int argc, char* argv[] ) -{ -#ifdef HAVE_GTEST - ::testing::InitGoogleTest( &argc, argv ); - - #ifdef HAVE_MPI - ::testing::TestEventListeners& listeners = - ::testing::UnitTest::GetInstance()->listeners(); - - delete listeners.Release(listeners.default_result_printer()); - listeners.Append(new MinimalistBufferedPrinter); - - Communicators::ScopedInitializer< CommunicatorType > mpi(argc, argv); - #endif - return RUN_ALL_TESTS(); -#else - throw GtestMissingError(); -#endif -} +#include "../../main_mpi.h" diff --git a/src/UnitTests/Containers/ndarray/DistributedNDArray_1D_test.h b/src/UnitTests/Containers/ndarray/DistributedNDArray_1D_test.h index 04afb91a40..a8d3bcdab1 100644 --- a/src/UnitTests/Containers/ndarray/DistributedNDArray_1D_test.h +++ b/src/UnitTests/Containers/ndarray/DistributedNDArray_1D_test.h @@ -495,62 +495,4 @@ TYPED_TEST( DistributedNDArray_1D_test, forOverlaps ) #endif // HAVE_GTEST -#if (defined(HAVE_GTEST) && defined(HAVE_MPI)) -using CommunicatorType = Communicators::MpiCommunicator; - -#include <sstream> - -class MinimalistBufferedPrinter -: public ::testing::EmptyTestEventListener -{ -private: - std::stringstream sout; - -public: - // Called before a test starts. - virtual void OnTestStart(const ::testing::TestInfo& test_info) - { - sout << test_info.test_case_name() << "." << test_info.name() << " Start." << std::endl; - } - - // Called after a failed assertion or a SUCCEED() invocation. - virtual void OnTestPartResult(const ::testing::TestPartResult& test_part_result) - { - sout << (test_part_result.failed() ? "====Failure=== " : "===Success=== ") - << test_part_result.file_name() << " " - << test_part_result.line_number() <<std::endl - << test_part_result.summary() <<std::endl; - } - - // Called after a test ends. - virtual void OnTestEnd(const ::testing::TestInfo& test_info) - { - const int rank = CommunicatorType::GetRank(CommunicatorType::AllGroup); - sout << test_info.test_case_name() << "." << test_info.name() << " End." <<std::endl; - std::cout << rank << ":" << std::endl << sout.str()<< std::endl; - sout.str( std::string() ); - sout.clear(); - } -}; -#endif - -#include "../../GtestMissingError.h" -int main( int argc, char* argv[] ) -{ -#ifdef HAVE_GTEST - ::testing::InitGoogleTest( &argc, argv ); - - #ifdef HAVE_MPI - ::testing::TestEventListeners& listeners = - ::testing::UnitTest::GetInstance()->listeners(); - - delete listeners.Release(listeners.default_result_printer()); - listeners.Append(new MinimalistBufferedPrinter); - - Communicators::ScopedInitializer< CommunicatorType > mpi(argc, argv); - #endif - return RUN_ALL_TESTS(); -#else - throw GtestMissingError(); -#endif -} +#include "../../main_mpi.h" diff --git a/src/UnitTests/Containers/ndarray/DistributedNDArray_semi1D_test.h b/src/UnitTests/Containers/ndarray/DistributedNDArray_semi1D_test.h index 17108509d0..6f777c215a 100644 --- a/src/UnitTests/Containers/ndarray/DistributedNDArray_semi1D_test.h +++ b/src/UnitTests/Containers/ndarray/DistributedNDArray_semi1D_test.h @@ -480,62 +480,4 @@ TYPED_TEST( DistributedNDArray_semi1D_test, forOverlaps ) #endif // HAVE_GTEST -#if (defined(HAVE_GTEST) && defined(HAVE_MPI)) -using CommunicatorType = Communicators::MpiCommunicator; - -#include <sstream> - -class MinimalistBufferedPrinter -: public ::testing::EmptyTestEventListener -{ -private: - std::stringstream sout; - -public: - // Called before a test starts. - virtual void OnTestStart(const ::testing::TestInfo& test_info) - { - sout << test_info.test_case_name() << "." << test_info.name() << " Start." << std::endl; - } - - // Called after a failed assertion or a SUCCEED() invocation. - virtual void OnTestPartResult(const ::testing::TestPartResult& test_part_result) - { - sout << (test_part_result.failed() ? "====Failure=== " : "===Success=== ") - << test_part_result.file_name() << " " - << test_part_result.line_number() <<std::endl - << test_part_result.summary() <<std::endl; - } - - // Called after a test ends. - virtual void OnTestEnd(const ::testing::TestInfo& test_info) - { - const int rank = CommunicatorType::GetRank(CommunicatorType::AllGroup); - sout << test_info.test_case_name() << "." << test_info.name() << " End." <<std::endl; - std::cout << rank << ":" << std::endl << sout.str()<< std::endl; - sout.str( std::string() ); - sout.clear(); - } -}; -#endif - -#include "../../GtestMissingError.h" -int main( int argc, char* argv[] ) -{ -#ifdef HAVE_GTEST - ::testing::InitGoogleTest( &argc, argv ); - - #ifdef HAVE_MPI - ::testing::TestEventListeners& listeners = - ::testing::UnitTest::GetInstance()->listeners(); - - delete listeners.Release(listeners.default_result_printer()); - listeners.Append(new MinimalistBufferedPrinter); - - Communicators::ScopedInitializer< CommunicatorType > mpi(argc, argv); - #endif - return RUN_ALL_TESTS(); -#else - throw GtestMissingError(); -#endif -} +#include "../../main_mpi.h" diff --git a/src/UnitTests/Containers/ndarray/NDArrayTest.h b/src/UnitTests/Containers/ndarray/NDArrayTest.h index 1e5d9a30ce..3d2c858887 100644 --- a/src/UnitTests/Containers/ndarray/NDArrayTest.h +++ b/src/UnitTests/Containers/ndarray/NDArrayTest.h @@ -1,3 +1,4 @@ +#ifdef HAVE_GTEST #include "gtest/gtest.h" #include <TNL/Containers/NDArray.h> @@ -1325,14 +1326,7 @@ TEST( NDArrayTest, forBoundary_static_6D ) << "i = " << i << ", j = " << j << ", k = " << k << ", l = " << l << ", m = " << m << ", n = " << n; } } +#endif // HAVE_GTEST -//#include "GtestMissingError.h" -int main( int argc, char* argv[] ) -{ -//#ifdef HAVE_GTEST - ::testing::InitGoogleTest( &argc, argv ); - return RUN_ALL_TESTS(); -//#else -// throw GtestMissingError(); -//#endif -} + +#include "../../main.h" diff --git a/src/UnitTests/Containers/ndarray/NDSubarrayTest.cpp b/src/UnitTests/Containers/ndarray/NDSubarrayTest.cpp index 1b57eed281..f4f44003f8 100644 --- a/src/UnitTests/Containers/ndarray/NDSubarrayTest.cpp +++ b/src/UnitTests/Containers/ndarray/NDSubarrayTest.cpp @@ -1,3 +1,4 @@ +#ifdef HAVE_GTEST #include "gtest/gtest.h" #include <TNL/Containers/NDArray.h> @@ -392,14 +393,7 @@ TEST( NDArraySubarrayTest, Dynamic_6D ) } a.setValue( 0 ); } +#endif // HAVE_GTEST -//#include "GtestMissingError.h" -int main( int argc, char* argv[] ) -{ -//#ifdef HAVE_GTEST - ::testing::InitGoogleTest( &argc, argv ); - return RUN_ALL_TESTS(); -//#else -// throw GtestMissingError(); -//#endif -} + +#include "../../main.h" diff --git a/src/UnitTests/Containers/ndarray/SlicedNDArrayTest.cpp b/src/UnitTests/Containers/ndarray/SlicedNDArrayTest.cpp index 8574a56021..eda47a615f 100644 --- a/src/UnitTests/Containers/ndarray/SlicedNDArrayTest.cpp +++ b/src/UnitTests/Containers/ndarray/SlicedNDArrayTest.cpp @@ -1,3 +1,4 @@ +#ifdef HAVE_GTEST #include "gtest/gtest.h" #include <TNL/Containers/NDArray.h> @@ -238,14 +239,7 @@ TEST( SlicedNDArrayTest, CopySemantics ) EXPECT_EQ( a.getConstView(), c.getConstView() ); EXPECT_EQ( a.getConstView(), c_view.getConstView() ); } +#endif // HAVE_GTEST -//#include "GtestMissingError.h" -int main( int argc, char* argv[] ) -{ -//#ifdef HAVE_GTEST - ::testing::InitGoogleTest( &argc, argv ); - return RUN_ALL_TESTS(); -//#else -// throw GtestMissingError(); -//#endif -} + +#include "../../main.h" diff --git a/src/UnitTests/Containers/ndarray/StaticNDArrayCudaTest.cu b/src/UnitTests/Containers/ndarray/StaticNDArrayCudaTest.cu index 5a0561955f..f2c83ba164 100644 --- a/src/UnitTests/Containers/ndarray/StaticNDArrayCudaTest.cu +++ b/src/UnitTests/Containers/ndarray/StaticNDArrayCudaTest.cu @@ -1,3 +1,4 @@ +#ifdef HAVE_GTEST #include "gtest/gtest.h" #include <TNL/Containers/NDArray.h> @@ -76,14 +77,7 @@ TEST( StaticNDArrayCudaTest, CopyFromArray ) { __test_CopyFromArray(); } +#endif // HAVE_GTEST -//#include "GtestMissingError.h" -int main( int argc, char* argv[] ) -{ -//#ifdef HAVE_GTEST - ::testing::InitGoogleTest( &argc, argv ); - return RUN_ALL_TESTS(); -//#else -// throw GtestMissingError(); -//#endif -} + +#include "../../main.h" diff --git a/src/UnitTests/Containers/ndarray/StaticNDArrayTest.cpp b/src/UnitTests/Containers/ndarray/StaticNDArrayTest.cpp index e3ea290f26..23ffd8066e 100644 --- a/src/UnitTests/Containers/ndarray/StaticNDArrayTest.cpp +++ b/src/UnitTests/Containers/ndarray/StaticNDArrayTest.cpp @@ -1,3 +1,4 @@ +#ifdef HAVE_GTEST #include "gtest/gtest.h" #include <TNL/Containers/NDArray.h> @@ -92,14 +93,7 @@ TEST( StaticNDArrayTest, CopySemantics ) EXPECT_EQ( a.getConstView(), c.getConstView() ); EXPECT_EQ( a.getConstView(), c_view.getConstView() ); } +#endif // HAVE_GTEST -//#include "GtestMissingError.h" -int main( int argc, char* argv[] ) -{ -//#ifdef HAVE_GTEST - ::testing::InitGoogleTest( &argc, argv ); - return RUN_ALL_TESTS(); -//#else -// throw GtestMissingError(); -//#endif -} + +#include "../../main.h" -- GitLab