From e8272bb41d707b03bedc6a3d0bb56281fe7a81ca Mon Sep 17 00:00:00 2001 From: "Joachim Wuttke (h)" <j.wuttke@fz-juelich.de> Date: Fri, 20 Nov 2020 21:37:58 +0100 Subject: [PATCH] document and simplify std test machinery --- Tests/Functional/Core/Std/CMakeLists.txt | 10 ++++++-- Tests/Functional/Core/Std/Check.cpp | 6 ++++- Tests/Functional/Core/Std/macros.cpp | 16 ------------- Tests/Functional/GUI/Std/CMakeLists.txt | 26 +++++++++++++++++++-- Tests/Functional/GUI/Std/Check.cpp | 8 ++++++- Tests/Functional/GUI/Std/macros.cpp | 18 --------------- Tests/Functional/Python/Std/CMakeLists.txt | 27 ++++++++++++++++++++-- Tests/Functional/Python/Std/Check.cpp | 6 +++++ Tests/Functional/Python/Std/macros.cpp | 18 --------------- Tests/Functional/Std/Run.cpp | 2 ++ 10 files changed, 77 insertions(+), 60 deletions(-) delete mode 100644 Tests/Functional/Core/Std/macros.cpp delete mode 100644 Tests/Functional/GUI/Std/macros.cpp delete mode 100644 Tests/Functional/Python/Std/macros.cpp diff --git a/Tests/Functional/Core/Std/CMakeLists.txt b/Tests/Functional/Core/Std/CMakeLists.txt index 58deac910c6..4f83c955c33 100644 --- a/Tests/Functional/Core/Std/CMakeLists.txt +++ b/Tests/Functional/Core/Std/CMakeLists.txt @@ -5,6 +5,12 @@ #! @file Tests/Functional/Core/Std/CMakeLists.txt #! @brief Builds Core standard tests. # +# .../Std/TestAll.cpp provides main, which essentially runs RUN_ALL_TESTS(). +# RUN_ALL_TESTS is a gtest macro that runs tests defined by TEST_F macros. +# .../Std/Run.cpp uses such TEST_F macros to define our standard test cases. +# Check.cpp provides a callback function that executes one Core tests: +# Run a given simulation, and compare result with reference data. +# #! @homepage http://www.bornagainproject.org #! @license GNU General Public License v3 or higher (see COPYING) #! @copyright Forschungszentrum Jülich GmbH 2018 @@ -16,9 +22,9 @@ include(GoogleTest) # provides gtest_discover_tests set(test TestCoreStd) -file(GLOB source_files "*.cpp" "../../Std/Run.cpp") +set(source_files Check.cpp ../../Std/Run.cpp ${CMAKE_SOURCE_DIR}/Tests/GTestWrapper/TestAll.cpp) -add_executable(${test} ${source_files} ${CMAKE_SOURCE_DIR}/Tests/GTestWrapper/TestAll.cpp) +add_executable(${test} ${source_files}) target_include_directories(${test} PUBLIC ${BornAgainCore_INCLUDE_DIRS} ${CMAKE_SOURCE_DIR}/ThirdParty/common/gtest/gtest-1.8.0/include) diff --git a/Tests/Functional/Core/Std/Check.cpp b/Tests/Functional/Core/Std/Check.cpp index d606065e063..0a8a056b840 100644 --- a/Tests/Functional/Core/Std/Check.cpp +++ b/Tests/Functional/Core/Std/Check.cpp @@ -22,13 +22,17 @@ #include "Sample/StandardSamples/SampleBuilderFactory.h" #include <iostream> +//! Run simulation directly (in C+ core), and compare result with reference data. + bool checkSimulation(const std::string& name, const ISimulation& direct_simulation, const double limit) { + + // Run simulation directly. const auto result_data = direct_simulation.result().data(); std::unique_ptr<OutputData<double>> reference; - // Load reference if available + // Load reference if available. ASSERT(name != ""); try { const std::string refPath = FileSystemUtils::jointPath( diff --git a/Tests/Functional/Core/Std/macros.cpp b/Tests/Functional/Core/Std/macros.cpp deleted file mode 100644 index 5fd0f0f2e9d..00000000000 --- a/Tests/Functional/Core/Std/macros.cpp +++ /dev/null @@ -1,16 +0,0 @@ -// ************************************************************************************************ -// -// BornAgain: simulate and fit scattering at grazing incidence -// -//! @file Tests/Functional/Core/Std/macros.cpp -//! @brief Implements Core standard tests through gtest macros. -//! -//! @homepage http://www.bornagainproject.org -//! @license GNU General Public License v3 or higher (see COPYING) -//! @copyright Forschungszentrum Jülich GmbH 2018 -//! @authors Scientific Computing Group at MLZ (see CITATION, AUTHORS) -// -// ************************************************************************************************ - -#include "Tests/Functional/Std/Run.h" -#include "Tests/Functional/Std/StandardTests.h" // contains macros that are executed by gtest diff --git a/Tests/Functional/GUI/Std/CMakeLists.txt b/Tests/Functional/GUI/Std/CMakeLists.txt index ea1616a0a45..337f7cc2a13 100644 --- a/Tests/Functional/GUI/Std/CMakeLists.txt +++ b/Tests/Functional/GUI/Std/CMakeLists.txt @@ -1,10 +1,32 @@ +# ************************************************************************************************ +# +# BornAgain: simulate and fit scattering at grazing incidence +# +#! @file Tests/Functional/GUI/Std/CMakeLists.txt +#! @brief Builds GUI standard tests. +# +# .../Std/TestAll.cpp provides main, which essentially runs RUN_ALL_TESTS(). +# RUN_ALL_TESTS is a gtest macro that runs tests defined by TEST_F macros. +# .../Std/Run.cpp uses such TEST_F macros to define our standard test cases. +# Check.cpp provides a callback function that executes one GUI tests: +# Run a given simulation directly, and through GUI model, and compare results. +# +#! @homepage http://www.bornagainproject.org +#! @license GNU General Public License v3 or higher (see COPYING) +#! @copyright Forschungszentrum Jülich GmbH 2018 +#! @authors Scientific Computing Group at MLZ (see CITATION, AUTHORS) +# +# ************************************************************************************************ + include(GoogleTest) # provides gtest_discover_tests set(test TestGuiStd) -file(GLOB source_files "*.cpp" "../../Std/Run.cpp") +set(source_files Check.cpp ../../Std/Run.cpp ${CMAKE_SOURCE_DIR}/Tests/GTestWrapper/TestAll.cpp) + +add_executable(${test} ${source_files}) +target_compile_options(${test} PUBLIC -DGUI_STD_TEST) -add_executable(${test} ${source_files} ${CMAKE_SOURCE_DIR}/Tests/GTestWrapper/TestAll.cpp) target_include_directories(${test} PUBLIC ${BornAgainGUI_INCLUDE_DIRS} ${CMAKE_SOURCE_DIR}/ThirdParty/common/gtest/gtest-1.8.0/include) diff --git a/Tests/Functional/GUI/Std/Check.cpp b/Tests/Functional/GUI/Std/Check.cpp index 6e1bcbe3841..8d229f705b3 100644 --- a/Tests/Functional/GUI/Std/Check.cpp +++ b/Tests/Functional/GUI/Std/Check.cpp @@ -3,7 +3,7 @@ // BornAgain: simulate and fit scattering at grazing incidence // //! @file Tests/Functional/GUI/Std/Check.cpp -//! @brief Implements function checkSimulation for Python standard test +//! @brief Implements function checkSimulation for GUI standard test //! //! @homepage http://www.bornagainproject.org //! @license GNU General Public License v3 or higher (see COPYING) @@ -22,6 +22,8 @@ #include "GUI/coregui/Models/MaterialModel.h" #include "GUI/coregui/Models/SampleModel.h" +namespace { + std::unique_ptr<OutputData<double>> domainData(const std::string& /*test_name*/, const ISimulation& direct_simulation) { // initializing necessary GUI @@ -43,6 +45,10 @@ std::unique_ptr<OutputData<double>> domainData(const std::string& /*test_name*/, return std::unique_ptr<OutputData<double>>(domain_simulation->result().data()); } +} // namespace + +//! Run simulation directly (in core) and through GUI model, and compare results. + bool checkSimulation(const std::string& name, const ISimulation& direct_simulation, const double limit) { const std::unique_ptr<OutputData<double>> domain_data = domainData(name, direct_simulation); diff --git a/Tests/Functional/GUI/Std/macros.cpp b/Tests/Functional/GUI/Std/macros.cpp deleted file mode 100644 index 5e2e413b0e9..00000000000 --- a/Tests/Functional/GUI/Std/macros.cpp +++ /dev/null @@ -1,18 +0,0 @@ -// ************************************************************************************************ -// -// BornAgain: simulate and fit scattering at grazing incidence -// -//! @file Tests/Functional/GUI/Std/macros.cpp -//! @brief Implements Core standard tests through gtest macros. -//! -//! @homepage http://www.bornagainproject.org -//! @license GNU General Public License v3 or higher (see COPYING) -//! @copyright Forschungszentrum Jülich GmbH 2018 -//! @authors Scientific Computing Group at MLZ (see CITATION, AUTHORS) -// -// ************************************************************************************************ - -#include "Tests/Functional/Std/Run.h" - -#define GUI_STD_TEST -#include "Tests/Functional/Std/StandardTests.h" // contains macros that are executed by gtest diff --git a/Tests/Functional/Python/Std/CMakeLists.txt b/Tests/Functional/Python/Std/CMakeLists.txt index afc25e554a5..46b1004170e 100644 --- a/Tests/Functional/Python/Std/CMakeLists.txt +++ b/Tests/Functional/Python/Std/CMakeLists.txt @@ -1,10 +1,33 @@ +# ************************************************************************************************ +# +# BornAgain: simulate and fit scattering at grazing incidence +# +#! @file Tests/Functional/Python/Std/CMakeLists.txt +#! @brief Builds Python standard tests. +# +# .../Std/TestAll.cpp provides main, which essentially runs RUN_ALL_TESTS(). +# RUN_ALL_TESTS is a gtest macro that runs tests defined by TEST_F macros. +# .../Std/Run.cpp uses such TEST_F macros to define our standard test cases. +# Check.cpp provides a callback function that executes one Python tests: +# Export a simulation to Python, run that Python script, and compare the +# result with a direct simulation in the C++ core. +# +#! @homepage http://www.bornagainproject.org +#! @license GNU General Public License v3 or higher (see COPYING) +#! @copyright Forschungszentrum Jülich GmbH 2018 +#! @authors Scientific Computing Group at MLZ (see CITATION, AUTHORS) +# +# ************************************************************************************************ + include(GoogleTest) # provides gtest_discover_tests set(test TestPyStd) -file(GLOB source_files "*.cpp" "../../Std/Run.cpp") +set(source_files Check.cpp ../../Std/Run.cpp ${CMAKE_SOURCE_DIR}/Tests/GTestWrapper/TestAll.cpp) + +add_executable(${test} ${source_files}) +target_compile_options(${test} PUBLIC -DPYTHON_STD_TEST) -add_executable(${test} ${source_files} ${CMAKE_SOURCE_DIR}/Tests/GTestWrapper/TestAll.cpp) target_include_directories(${test} PUBLIC ${BornAgainCore_INCLUDE_DIRS} ${CMAKE_SOURCE_DIR}/ThirdParty/common/gtest/gtest-1.8.0/include) diff --git a/Tests/Functional/Python/Std/Check.cpp b/Tests/Functional/Python/Std/Check.cpp index 940c30efafd..fc372e9db51 100644 --- a/Tests/Functional/Python/Std/Check.cpp +++ b/Tests/Functional/Python/Std/Check.cpp @@ -22,6 +22,8 @@ #include <fstream> #include <iostream> +namespace { + std::unique_ptr<OutputData<double>> domainData(const std::string& test_name, const ISimulation& direct_simulation) { const std::string output_name = @@ -59,6 +61,10 @@ std::unique_ptr<OutputData<double>> domainData(const std::string& test_name, return std::unique_ptr<OutputData<double>>(IntensityDataIOFactory::readOutputData(output_path)); } +} // namespace + +//! Run simulation directly (in C+ core) and through Python export, and compare results. + bool checkSimulation(const std::string& name, const ISimulation& direct_simulation, const double limit) { const std::unique_ptr<OutputData<double>> domain_data = domainData(name, direct_simulation); diff --git a/Tests/Functional/Python/Std/macros.cpp b/Tests/Functional/Python/Std/macros.cpp deleted file mode 100644 index 8340cd33bc2..00000000000 --- a/Tests/Functional/Python/Std/macros.cpp +++ /dev/null @@ -1,18 +0,0 @@ -// ************************************************************************************************ -// -// BornAgain: simulate and fit scattering at grazing incidence -// -//! @file Tests/Functional/Python/Std/macros.cpp -//! @brief Implements Core standard tests through gtest macros. -//! -//! @homepage http://www.bornagainproject.org -//! @license GNU General Public License v3 or higher (see COPYING) -//! @copyright Forschungszentrum Jülich GmbH 2018 -//! @authors Scientific Computing Group at MLZ (see CITATION, AUTHORS) -// -// ************************************************************************************************ - -#include "Tests/Functional/Std/Run.h" - -#define PYTHON_STD_TEST -#include "Tests/Functional/Std/StandardTests.h" // contains macros that are executed by gtest diff --git a/Tests/Functional/Std/Run.cpp b/Tests/Functional/Std/Run.cpp index a2505a205d6..2ac071ab615 100644 --- a/Tests/Functional/Std/Run.cpp +++ b/Tests/Functional/Std/Run.cpp @@ -12,9 +12,11 @@ // // ************************************************************************************************ +#include "Tests/Functional/Std/Run.h" #include "Core/Simulation/SimulationFactory.h" #include "Sample/Multilayer/MultiLayer.h" #include "Sample/StandardSamples/SampleBuilderFactory.h" +#include "Tests/Functional/Std/StandardTests.h" // provides F_TEST macros to be executed by gtest #include <iostream> //! This function, called from run, has different implementations in Core/Py/Gui tests: -- GitLab