Skip to content
Snippets Groups Projects
Commit 2a2ac381 authored by Walter Van Herck's avatar Walter Van Herck Committed by GitHub
Browse files

Merge pull request #251 from gpospelov/develop

Further development of PyEmbedded test machinery
parents 4e8b4b4e ccdbd4da
No related branches found
No related tags found
No related merge requests found
Showing
with 375 additions and 173 deletions
......@@ -65,6 +65,7 @@ if(BORNAGAIN_PYTHON)
set(swig_dependencies ${swig_dependencies} ${AUTO_DIR}/doxygen_core.i)
set(SWIG_FLAGS "-c++;-python;-o;${AUTO_DIR}/libBornAgainCore_wrap.cpp;-outdir;${TMP_DIR}")
set(SWIG_RUNTIME_FLAGS "-c++;-python;-external-runtime;${AUTO_DIR}/swig_runtime.h")
foreach(dir ${include_dirs})
list(APPEND SWIG_FLAGS "-I${dir}")
endforeach(dir)
......@@ -84,6 +85,12 @@ if(BORNAGAIN_PYTHON)
DEPENDS ${swig_dependencies} ${include_files}
)
add_custom_command (
OUTPUT ${AUTO_DIR}/swig_runtime.h
COMMAND ${SWIG_EXECUTABLE} ${SWIG_RUNTIME_FLAGS}
DEPENDS ${swig_dependencies} ${include_files}
)
endif(BORNAGAIN_GENERATE_BINDINGS)
add_custom_target (
......@@ -93,7 +100,10 @@ if(BORNAGAIN_PYTHON)
DEPENDS ${AUTO_DIR}/libBornAgainCore.py
)
add_custom_target(${library_name}_runtime DEPENDS ${AUTO_DIR}/swig_runtime.h)
list(APPEND source_files "${AUTO_DIR}/libBornAgainCore_wrap.cpp")
list(APPEND include_files "${AUTO_DIR}/swig_runtime.h")
configure_file(${WRAP_DIR}/python/plot_utils.py
${CMAKE_BINARY_DIR}/lib/bornagain/plot_utils.py COPYONLY)
......@@ -123,7 +133,7 @@ set(${library_name}_LIBRARY_TYPE SHARED)
if(BORNAGAIN_PYTHON)
add_dependencies(${library_name} ${library_name}_python)
add_dependencies(${library_name} ${library_name}_python ${library_name}_runtime)
endif()
# exposing library name and list of include directories outside
......
......@@ -6,20 +6,6 @@ set(test_cases
# CoreIO
)
# for some reason these flags doesn't propagated here by SetUpWindows.cmake
if(MSVC)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /EHsc ")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /EHsc ")
endif()
include_directories(
${BornAgainCore_INCLUDE_DIRS}
${Boost_INCLUDE_DIRS}
${PYTHON_INCLUDE_DIRS} ${NUMPY_INCLUDE_DIR}
${EIGEN3_INCLUDE_DIR}
${CMAKE_CURRENT_SOURCE_DIR}/../../TestMachinery
)
file(GLOB source_files "*.cpp")
file(GLOB include_files "*.h")
......
......@@ -23,6 +23,5 @@ include_directories(
)
add_subdirectory(GUIStandardTest)
add_subdirectory(GUITranslationTest)
#add_subdirectory(GUIPerformanceTest)
add_subdirectory(GUISpecial)
// ************************************************************************** //
//
// BornAgain: simulate and fit scattering at grazing incidence
//
//! @file Tests/Functional/GUI/GUIPerformanceTest/Benchmark.cpp
//! @brief Implements Benchmark class.
//!
//! @homepage http://www.bornagainproject.org
//! @license GNU General Public License v3 or higher (see COPYING)
//! @copyright Forschungszentrum Jülich GmbH 2016
//! @authors Scientific Computing Group at MLZ Garching
//! @authors Céline Durniak, Marina Ganeva, David Li, Gennady Pospelov
//! @authors Walter Van Herck, Joachim Wuttke
//
// ************************************************************************** //
#include "Benchmark.h"
#include <QElapsedTimer>
#include <QDateTime>
#include <QStringList>
#include <iostream>
//! Do useless calculations to warmUp
Benchmark::Benchmark()
{
}
void Benchmark::test(const QString& name, std::function<void ()> f, int ntries)
{
std::cout << " " << name.toStdString() << " trying " << std::to_string(ntries) << " times\n";
// warming up
for(int i=0; i<ntries/10; ++i)
f();
QElapsedTimer timer;
timer.start();
for(int i=0; i<ntries; ++i)
f();
m_measurements.push_back({name, timer.elapsed()});
}
QString Benchmark::report() const
{
QStringList result;
result << QDateTime::currentDateTime().toString("dd.MM.yyyy hh:mm:ss");
result << " | ";
for(auto meas : m_measurements)
result << meas.name << " " << QString::number(meas.wall_time) << " msec | ";
return result.join(QString());
}
set(test_name GUIPerformanceTest)
add_executable(${test_name} main.cpp GUIPerformanceTest.cpp GUIPerformanceTest.h
Benchmark.h Benchmark.cpp)
target_link_libraries(${test_name} BornAgainCore BornAgainGUI BornAgainTestMachinery)
qt5_use_modules(${test_name} Widgets Core Gui Designer PrintSupport Network)
add_test(${test_name} ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${test_name})
set(test GUISpecial)
set(test_cases
BasicTranslation
RadialParaTranslation
HexParaTranslation
CoreShellTranslation
RoughnessTranslation
SquareLatticeTranslation
RotationTranslation
SizeDistributionTranslation
CompositionTranslation
Para2DTranslation
Lattice1DTranslation
Lattice2DTranslation
TwoLayerRoughnessTranslation
# GUIPerformanceTest # too heavy, call manually when necessary
)
file(GLOB source_files "*.cpp")
file(GLOB include_files "*.h")
add_executable(${test} ${include_files} ${source_files})
target_link_libraries(${test} BornAgainCore BornAgainGUI BornAgainTestMachinery)
qt5_use_modules(${test} Widgets Core Gui Designer PrintSupport Network)
foreach(test_case ${test_cases})
add_test(${test}/${test_case} ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${test} ${test_case})
endforeach()
......@@ -67,11 +67,11 @@ bool GUIPerformanceTest::runTest()
std::cout << "GUIPerformanceTest -> Running ..." << mult << std::endl;
Benchmark bench;
bench.test("domain2gui", [this]() { test_domain_to_gui();}, 300*mult);
bench.test("gui2domain", [this]() { test_gui_to_domain();}, 100*mult);
bench.test("realTime", [this]() { test_real_time();}, 2*mult);
bench.test_method("domain2gui", [this]() { test_domain_to_gui();}, 300*mult);
bench.test_method("gui2domain", [this]() { test_gui_to_domain();}, 100*mult);
bench.test_method("realTime", [this]() { test_real_time();}, 2*mult);
std::cout << bench.report().toStdString() << std::endl;
std::cout << bench.report() << std::endl;
return true;
}
......
......@@ -31,12 +31,13 @@ public:
GUIPerformanceTest();
~GUIPerformanceTest();
bool runTest();
void test_domain_to_gui();
void test_gui_to_domain();
void test_real_time();
protected:
bool runTest();
private:
std::unique_ptr<ApplicationModels> m_models;
QString m_sample_name;
......
// ************************************************************************** //
//
// BornAgain: simulate and fit scattering at grazing incidence
//
//! @file Tests/Functional/GUI/GUISpecial/GUISpecialTestFactory.cpp
//! @brief Implements GUISpecialTestFactory class.
//!
//! @homepage http://www.bornagainproject.org
//! @license GNU General Public License v3 or higher (see COPYING)
//! @copyright Forschungszentrum Jülich GmbH 2015
//! @authors Scientific Computing Group at MLZ Garching
//! @authors C. Durniak, M. Ganeva, G. Pospelov, W. Van Herck, J. Wuttke
//
// ************************************************************************** //
#include "GUISpecialTestFactory.h"
#include "TranslationCases.h"
#include "GUIPerformanceTest.h"
GUISpecialTestFactory::GUISpecialTestFactory()
{
registerItem("BasicTranslation",
create_new<BasicTranslationTest>,
"BasicTranslation test");
registerItem("RadialParaTranslation",
create_new<RadialParaTranslationTest>,
"RadialParaTranslation test");
registerItem("HexParaTranslation",
create_new<HexParaTranslationTest>,
"HexParaTranslation test");
registerItem("CoreShellTranslation",
create_new<CoreShellTranslationTest>,
"CoreShellTranslation test");
registerItem("RoughnessTranslation",
create_new<RoughnessTranslationTest>,
"RoughnessTranslation test");
registerItem("SquareLatticeTranslation",
create_new<SquareLatticeTranslationTest>,
"SquareLatticeTranslation test");
registerItem("RotationTranslation",
create_new<RotationTranslationTest>,
"RotationTranslation test");
registerItem("SizeDistributionTranslation",
create_new<SizeDistributionTranslationTest>,
"SizeDistributionTranslation test");
registerItem("CompositionTranslation",
create_new<CompositionTranslationTest>,
"CompositionTranslation test");
registerItem("Para2DTranslation",
create_new<Para2DTranslationTest>,
"Para2DTranslation test");
registerItem("Lattice1DTranslation",
create_new<Lattice1DTranslationTest>,
"Lattice1DTranslation test");
registerItem("Lattice2DTranslation",
create_new<Lattice2DTranslationTest>,
"Lattice2DTranslation test");
registerItem("TwoLayerRoughnessTranslation",
create_new<TwoLayerRoughnessTranslationTest>,
"TwoLayerRoughnessTranslation test");
registerItem("GUIPerformance",
create_new<GUIPerformanceTest>,
"Measuring GUI performance on typical tasks.");
}
......@@ -2,43 +2,30 @@
//
// BornAgain: simulate and fit scattering at grazing incidence
//
//! @file Tests/Functional/GUI/GUIPerformanceTest/Benchmark.h
//! @brief Defines Benchmark class.
//! @file Tests/Functional/GUI/GUISpecial/GUISpecialTestFactory.h
//! @brief Defines GUISpecialTestFactory class.
//!
//! @homepage http://www.bornagainproject.org
//! @license GNU General Public License v3 or higher (see COPYING)
//! @copyright Forschungszentrum Jülich GmbH 2016
//! @copyright Forschungszentrum Jülich GmbH 2015
//! @authors Scientific Computing Group at MLZ Garching
//! @authors Céline Durniak, Marina Ganeva, David Li, Gennady Pospelov
//! @authors Walter Van Herck, Joachim Wuttke
//! @authors C. Durniak, M. Ganeva, G. Pospelov, W. Van Herck, J. Wuttke
//
// ************************************************************************** //
#ifndef BENCHMARK_H
#define BENCHMARK_H
#ifndef GUISPECIALTESTFACTORY_H
#define GUISPECIALTESTFACTORY_H
#include <functional>
#include <QString>
#include <QVector>
#include "FunctionalTestFactory.h"
//! Measures execution time of given function and stores result in database.
//! @class GUISpecialTestFactory
//! @brief Collection of special tests for GUI library.
class Benchmark
class GUISpecialTestFactory : public FunctionalTestFactory
{
public:
Benchmark();
void test(const QString& name, std::function<void(void)> f, int ntries);
QString report() const;
private:
struct Measurement {
QString name; //!< measurement name
qint64 wall_time; //!< in msec
};
QVector<Measurement> m_measurements;
GUISpecialTestFactory();
};
#endif // GUIPERFORMANCETEST_H
#endif // GUISPECIALTESTFACTORY_H
......@@ -2,7 +2,7 @@
//
// BornAgain: simulate and fit scattering at grazing incidence
//
//! @file Tests/Functional/GUI/GUITranslationTest/GUITranslationTest.cpp
//! @file Tests/Functional/GUI/GUISpecial/GUITranslationTest.cpp
//! @brief Includes GUI translation functional test.
//!
//! @homepage http://www.bornagainproject.org
......
......@@ -2,7 +2,7 @@
//
// BornAgain: simulate and fit scattering at grazing incidence
//
//! @file Tests/Functional/GUI/GUITranslationTest/GUITranslationTest.h
//! @file Tests/Functional/GUI/GUISpecial/GUITranslationTest.h
//! @brief Defines GUI translation functional test.
//!
//! @homepage http://www.bornagainproject.org
......
// ************************************************************************** //
//
// BornAgain: simulate and fit scattering at grazing incidence
//
//! @file Tests/Functional/GUI/GUISpecial/TranslationCases.h
//! @brief Defines classes from TranslationCases family.
//!
//! @homepage http://www.bornagainproject.org
//! @license GNU General Public License v3 or higher (see COPYING)
//! @copyright Forschungszentrum Jülich GmbH 2015
//! @authors Scientific Computing Group at MLZ Garching
//! @authors C. Durniak, M. Ganeva, G. Pospelov, W. Van Herck, J. Wuttke
//
// ************************************************************************** //
#include "TranslationCases.h"
BasicTranslationTest::BasicTranslationTest()
: GUITranslationTest("BasicGISAS", "CylindersAndPrismsBuilder"){}
BasicTranslationTest::~BasicTranslationTest() = default;
RadialParaTranslationTest::RadialParaTranslationTest()
: GUITranslationTest("BasicGISAS", "RadialParaCrystalBuilder"){}
RadialParaTranslationTest::~RadialParaTranslationTest() = default;
HexParaTranslationTest::HexParaTranslationTest()
: GUITranslationTest("BasicGISAS", "HexParaCrystalBuilder"){}
HexParaTranslationTest::~HexParaTranslationTest() = default;
CoreShellTranslationTest::CoreShellTranslationTest()
: GUITranslationTest("BasicGISAS", "CoreShellParticleBuilder"){}
CoreShellTranslationTest::~CoreShellTranslationTest() = default;
RoughnessTranslationTest::RoughnessTranslationTest()
: GUITranslationTest("BasicGISAS", "MultiLayerWithRoughnessBuilder"){}
RoughnessTranslationTest::~RoughnessTranslationTest() = default;
SquareLatticeTranslationTest::SquareLatticeTranslationTest()
: GUITranslationTest("BasicGISAS", "SquareLatticeBuilder"){}
SquareLatticeTranslationTest::~SquareLatticeTranslationTest() = default;
RotationTranslationTest::RotationTranslationTest()
: GUITranslationTest("BasicGISAS", "RotatedPyramidsBuilder"){}
RotationTranslationTest::~RotationTranslationTest() = default;
SizeDistributionTranslationTest::SizeDistributionTranslationTest()
: GUITranslationTest("BasicGISAS", "CylindersWithSizeDistributionBuilder"){}
SizeDistributionTranslationTest::~SizeDistributionTranslationTest() = default;
CompositionTranslationTest::CompositionTranslationTest()
: GUITranslationTest("BasicGISAS", "ParticleCompositionBuilder"){}
CompositionTranslationTest::~CompositionTranslationTest() = default;
Para2DTranslationTest::Para2DTranslationTest()
: GUITranslationTest("BasicGISAS", "Basic2DParaCrystalBuilder"){}
Para2DTranslationTest::~Para2DTranslationTest() = default;
Lattice1DTranslationTest::Lattice1DTranslationTest()
: GUITranslationTest("BasicGISAS", "Lattice1DBuilder"){}
Lattice1DTranslationTest::~Lattice1DTranslationTest() = default;
Lattice2DTranslationTest::Lattice2DTranslationTest()
: GUITranslationTest("BasicGISAS", "Basic2DLatticeBuilder"){}
Lattice2DTranslationTest::~Lattice2DTranslationTest() = default;
TwoLayerRoughnessTranslationTest::TwoLayerRoughnessTranslationTest()
: GUITranslationTest("BasicGISAS", "TwoLayerRoughnessBuilder"){}
TwoLayerRoughnessTranslationTest::~TwoLayerRoughnessTranslationTest() = default;
// ************************************************************************** //
//
// BornAgain: simulate and fit scattering at grazing incidence
//
//! @file Tests/Functional/GUI/GUISpecial/TranslationCases.h
//! @brief Defines classes from TranslationCases family.
//!
//! @homepage http://www.bornagainproject.org
//! @license GNU General Public License v3 or higher (see COPYING)
//! @copyright Forschungszentrum Jülich GmbH 2015
//! @authors Scientific Computing Group at MLZ Garching
//! @authors C. Durniak, M. Ganeva, G. Pospelov, W. Van Herck, J. Wuttke
//
// ************************************************************************** //
#ifndef TRANSLATIONCASES_H
#define TRANSLATIONCASES_H
#include "GUITranslationTest.h"
//! Collection of classes for various translation tests.
class BasicTranslationTest : public GUITranslationTest
{
public:
BasicTranslationTest();
~BasicTranslationTest();
};
class RadialParaTranslationTest : public GUITranslationTest
{
public:
RadialParaTranslationTest();
~RadialParaTranslationTest();
};
class HexParaTranslationTest : public GUITranslationTest
{
public:
HexParaTranslationTest();
~HexParaTranslationTest();
};
class CoreShellTranslationTest : public GUITranslationTest
{
public:
CoreShellTranslationTest();
~CoreShellTranslationTest();
};
class RoughnessTranslationTest : public GUITranslationTest
{
public:
RoughnessTranslationTest();
~RoughnessTranslationTest();
};
class SquareLatticeTranslationTest : public GUITranslationTest
{
public:
SquareLatticeTranslationTest();
~SquareLatticeTranslationTest();
};
class RotationTranslationTest : public GUITranslationTest
{
public:
RotationTranslationTest();
~RotationTranslationTest();
};
class SizeDistributionTranslationTest : public GUITranslationTest
{
public:
SizeDistributionTranslationTest();
~SizeDistributionTranslationTest();
};
class CompositionTranslationTest : public GUITranslationTest
{
public:
CompositionTranslationTest();
~CompositionTranslationTest();
};
class Para2DTranslationTest : public GUITranslationTest
{
public:
Para2DTranslationTest();
~Para2DTranslationTest();
};
class Lattice1DTranslationTest : public GUITranslationTest
{
public:
Lattice1DTranslationTest();
~Lattice1DTranslationTest();
};
class Lattice2DTranslationTest : public GUITranslationTest
{
public:
Lattice2DTranslationTest();
~Lattice2DTranslationTest();
};
class TwoLayerRoughnessTranslationTest : public GUITranslationTest
{
public:
TwoLayerRoughnessTranslationTest();
~TwoLayerRoughnessTranslationTest();
};
#endif // TRANSLATIONCASES_H
......@@ -2,8 +2,8 @@
//
// BornAgain: simulate and fit scattering at grazing incidence
//
//! @file Tests/Functional/GUI/GUITranslationTest/main.cpp
//! @brief Implements main to run GUI performance tests.
//! @file Tests/Functional/GUI/GUISpecial/main.cpp
//! @brief Implements main to run GUI special tests.
//!
//! @homepage http://www.bornagainproject.org
//! @license GNU General Public License v3 or higher (see COPYING)
......@@ -14,22 +14,13 @@
//
// ************************************************************************** //
#include <iostream>
#include "GUIPerformanceTest.h"
#include "TestService.h"
#include "GUISpecialTestFactory.h"
#include <QCoreApplication>
bool run_tests() {
GUIPerformanceTest test;
return test.runTest();
}
//! Runs PyEmbedded functional test.
int main(int argc, char** argv)
{
QCoreApplication a(argc, argv);
// run_tests();
return run_tests() == true ? 0 : 1;
// return a.exec();
return TestService<GUISpecialTestFactory>().execute(argc, argv) ? 0 : 1;
}
set(test_name GUITranslationTest)
add_executable(${test_name} main.cpp GUITranslationTest.cpp GUITranslationTest.h)
target_link_libraries(${test_name} BornAgainCore BornAgainGUI BornAgainTestMachinery)
qt5_use_modules(${test_name} Widgets Core Gui Designer PrintSupport Network)
add_test(${test_name} ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${test_name})
// ************************************************************************** //
//
// BornAgain: simulate and fit scattering at grazing incidence
//
//! @file Tests/Functional/GUI/GUITranslationTest/main.cpp
//! @brief Implements main to run GUI translation tests.
//!
//! @homepage http://www.bornagainproject.org
//! @license GNU General Public License v3 or higher (see COPYING)
//! @copyright Forschungszentrum Jülich GmbH 2016
//! @authors Scientific Computing Group at MLZ Garching
//! @authors Céline Durniak, Marina Ganeva, David Li, Gennady Pospelov
//! @authors Walter Van Herck, Joachim Wuttke
//
// ************************************************************************** //
#include <iostream>
#include "GUITranslationTest.h"
bool run_tests() {
std::vector<std::pair<std::string, std::string>> conditions = {
{"BasicGISAS", "CylindersAndPrismsBuilder"},
{"BasicGISAS", "RadialParaCrystalBuilder"},
{"BasicGISAS", "HexParaCrystalBuilder"},
{"BasicGISAS", "CoreShellParticleBuilder"},
{"BasicGISAS", "MultiLayerWithRoughnessBuilder"},
{"BasicGISAS", "SquareLatticeBuilder"},
{"BasicGISAS", "RotatedPyramidsBuilder"},
{"BasicGISAS", "CylindersWithSizeDistributionBuilder"},
{"BasicGISAS", "ParticleCompositionBuilder"},
{"BasicGISAS", "Basic2DParaCrystalBuilder"},
{"BasicGISAS", "Lattice1DBuilder"},
{"BasicGISAS", "Basic2DLatticeBuilder"},
{"BasicGISAS", "TwoLayerRoughnessBuilder"}
};
bool success(true);
for(auto pair: conditions) {
bool current = GUITranslationTest(pair.first, pair.second).runTest();
std::cout << "Sample: " << pair.second
<< " --> " << (current ? "Success" : "Failure") << std::endl;
success &= current;
}
std::cout << std::string(80, '-') << std::endl;
std::cout << "Summary: " << (success ? "Success" : "Failure") << std::endl;
return success;
}
int main(int , char**)
{
return run_tests() == true ? 0 : 1;
}
......@@ -6,6 +6,8 @@ set(test_cases
FunctionCall
MethodCall
CompiledFunction
ObjectExtract
ExportToPythonAndBack
)
# for some reason these flags doesn't propagated here by SetUpWindows.cmake
......@@ -20,6 +22,7 @@ include_directories(
${PYTHON_INCLUDE_DIRS} ${NUMPY_INCLUDE_DIR}
${EIGEN3_INCLUDE_DIR}
${CMAKE_CURRENT_SOURCE_DIR}/../../TestMachinery
${CMAKE_SOURCE_DIR}/auto/Wrap
)
file(GLOB source_files "*.cpp")
......
......@@ -33,4 +33,14 @@ PyEmbeddedTestFactory::PyEmbeddedTestFactory()
registerItem("CompiledFunction",
create_new<CompiledFunction>,
"Compiling function from multi line string.");
registerItem("ObjectExtract",
create_new<ObjectExtract>,
"Extracting object created in Python into C++.");
registerItem("EmbeddedMultiLayer",
create_new<EmbeddedMultiLayer>,
"Building embedding MultiLayer.");
registerItem("ExportToPythonAndBack",
create_new<ExportToPythonAndBack>,
"Export of standard multilayer to Python code and casting back.");
}
......@@ -17,6 +17,7 @@
#include <stdexcept>
#include <iostream>
std::string PyEmbeddedUtils::toString(PyObject* obj, bool decref)
{
std::string result;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment