Skip to content

Commit

Permalink
Define a set of GlobalFixtures for the unittests.
Browse files Browse the repository at this point in the history
Currently these clear the AnalysisDataService & AlgorithmManager when
their tearDownWorld() methods are called, which ensures that all
workspaces placed in these singletons are cleared up before the end of
main.

If this it not done then the process hangs on MSVC while trying to
delete a Workspace2D, which contains an OpenMP loop in its destructor and
omp is not allowed to be called on Windows outside of main.

Refs #8216
  • Loading branch information
martyngigg committed Mar 17, 2014
1 parent 63296e3 commit f564331
Show file tree
Hide file tree
Showing 18 changed files with 132 additions and 18 deletions.
3 changes: 2 additions & 1 deletion Code/Mantid/Framework/API/test/CMakeLists.txt
Expand Up @@ -4,7 +4,8 @@ if ( CXXTEST_FOUND )
include_directories ( ../../TestHelpers/inc )
# This variable is used within the cxxtest_add_test macro to build these helper classes into the test executable.
# It will go out of scope at the end of this file so doesn't need un-setting
set ( TESTHELPER_SRCS ../../TestHelpers/src/ComponentCreationHelper.cpp
set ( TESTHELPER_SRCS ../../TestHelpers/src/TearDownWorld.cpp
../../TestHelpers/src/ComponentCreationHelper.cpp
../../TestHelpers/src/BoxControllerDummyIO.cpp
../../TestHelpers/src/NexusTestHelper.cpp
)
Expand Down
3 changes: 2 additions & 1 deletion Code/Mantid/Framework/Algorithms/test/CMakeLists.txt
Expand Up @@ -30,7 +30,8 @@ if ( CXXTEST_FOUND )
include_directories ( ../../CurveFitting/inc ../../DataHandling/inc ../../Nexus/inc ../../TestHelpers/inc ../../MDEvents/inc)
# This variable is used within the cxxtest_add_test macro to build these helper classes into the test executable.
# It will go out of scope at the end of this file so doesn't need un-setting
set ( TESTHELPER_SRCS ../../TestHelpers/src/ComponentCreationHelper.cpp
set ( TESTHELPER_SRCS ../../TestHelpers/src/TearDownWorld.cpp
../../TestHelpers/src/ComponentCreationHelper.cpp
../../TestHelpers/src/WorkspaceCreationHelper.cpp
../../TestHelpers/src/SANSInstrumentCreationHelper.cpp
../../TestHelpers/src/MDEventsTestHelper.cpp
Expand Down
3 changes: 2 additions & 1 deletion Code/Mantid/Framework/Crystal/test/CMakeLists.txt
Expand Up @@ -4,7 +4,8 @@ if ( CXXTEST_FOUND )
include_directories ( ../../DataHandling/inc ../../MDEvents/inc ../../TestHelpers/inc )
# This variable is used within the cxxtest_add_test macro to build these helper classes into the test executable.
# It will go out of scope at the end of this file so doesn't need un-setting
set ( TESTHELPER_SRCS ../../TestHelpers/src/ComponentCreationHelper.cpp
set ( TESTHELPER_SRCS ../../TestHelpers/src/TearDownWorld.cpp
../../TestHelpers/src/ComponentCreationHelper.cpp
../../TestHelpers/src/WorkspaceCreationHelper.cpp
../../TestHelpers/src/MDEventsTestHelper.cpp )
cxxtest_add_test ( CrystalTest ${TEST_FILES} )
Expand Down
3 changes: 2 additions & 1 deletion Code/Mantid/Framework/CurveFitting/test/CMakeLists.txt
Expand Up @@ -4,7 +4,8 @@ if ( CXXTEST_FOUND )
include_directories ( ../../DataHandling/inc ../../TestHelpers/inc )
# This variable is used within the cxxtest_add_test macro to build these helper classes into the test executable.
# It will go out of scope at the end of this file so doesn't need un-setting
set ( TESTHELPER_SRCS ../../TestHelpers/src/WorkspaceCreationHelper.cpp
set ( TESTHELPER_SRCS ../../TestHelpers/src/TearDownWorld.cpp
../../TestHelpers/src/WorkspaceCreationHelper.cpp
../../TestHelpers/src/ComponentCreationHelper.cpp
../../TestHelpers/src/StartFrameworkManager.cpp
)
Expand Down
7 changes: 4 additions & 3 deletions Code/Mantid/Framework/DataHandling/test/CMakeLists.txt
Expand Up @@ -4,10 +4,11 @@ if ( CXXTEST_FOUND )
include_directories ( ../../TestHelpers/inc )
# This variable is used within the cxxtest_add_test macro to build this helper class into the test executable.
# It will go out of scope at the end of this file so doesn't need un-setting
set ( TESTHELPER_SRCS ../../TestHelpers/src/ComponentCreationHelper.cpp
set ( TESTHELPER_SRCS ../../TestHelpers/src/TearDownWorld.cpp
../../TestHelpers/src/ComponentCreationHelper.cpp
../../TestHelpers/src/ScopedFileHelper.cpp
../../TestHelpers/src/StartFrameworkManager.cpp
../../TestHelpers/src/WorkspaceCreationHelper.cpp
../../TestHelpers/src/ScopedFileHelper.cpp
../../TestHelpers/src/StartFrameworkManager.cpp
)

cxxtest_add_test ( DataHandlingTest ${TEST_FILES} )
Expand Down
3 changes: 2 additions & 1 deletion Code/Mantid/Framework/DataObjects/test/CMakeLists.txt
Expand Up @@ -4,7 +4,8 @@ if ( CXXTEST_FOUND )
include_directories ( ../../TestHelpers/inc )
# This variable is used within the cxxtest_add_test macro to build this helper class into the test executable.
# It will go out of scope at the end of this file so doesn't need un-setting
set ( TESTHELPER_SRCS ../../TestHelpers/src/ComponentCreationHelper.cpp
set ( TESTHELPER_SRCS ../../TestHelpers/src/TearDownWorld.cpp
../../TestHelpers/src/ComponentCreationHelper.cpp
../../TestHelpers/src/WorkspaceCreationHelper.cpp
../../TestHelpers/src/NexusTestHelper.cpp
)
Expand Down
5 changes: 4 additions & 1 deletion Code/Mantid/Framework/ICat/test/CMakeLists.txt
@@ -1,9 +1,12 @@
if ( CXXTEST_FOUND )
include_directories ( SYSTEM ${CXXTEST_INCLUDE_DIR} ${GMOCK_INCLUDE_DIR} ${GTEST_INCLUDE_DIR} )

include_directories ( ../../TestHelpers/inc )
# This variable is used within the cxxtest_add_test macro to build this helper class into the test executable.
# It will go out of scope at the end of this file so doesn't need un-setting
set ( TESTHELPER_SRCS ICatTestHelper.cpp )
set ( TESTHELPER_SRCS ICatTestHelper.cpp
../../TestHelpers/src/TearDownWorld.cpp
)

# The actual test suite
cxxtest_add_test ( ICatTest ${TEST_FILES} )
Expand Down
6 changes: 5 additions & 1 deletion Code/Mantid/Framework/ISISLiveData/test/CMakeLists.txt
Expand Up @@ -4,7 +4,11 @@ if ( CXXTEST_FOUND )
include_directories ( ../../TestHelpers/inc )
# This variable is used within the cxxtest_add_test macro to build this helper class into the test executable.
# It will go out of scope at the end of this file so doesn't need un-setting
set ( TESTHELPER_SRCS ../../TestHelpers/src/ComponentCreationHelper.cpp ../../TestHelpers/src/WorkspaceCreationHelper.cpp )
set ( TESTHELPER_SRCS ../../TestHelpers/src/TearDownWorld.cpp
../../TestHelpers/src/ComponentCreationHelper.cpp
../../TestHelpers/src/WorkspaceCreationHelper.cpp
)

cxxtest_add_test ( ISISLiveDataTest ${TEST_FILES} )
target_link_libraries( ISISLiveDataTest ISISLiveData )
# Specify implicit dependency, but don't link to it
Expand Down
1 change: 1 addition & 0 deletions Code/Mantid/Framework/LiveData/test/CMakeLists.txt
Expand Up @@ -6,6 +6,7 @@ if ( CXXTEST_FOUND )
# It will go out of scope at the end of this file so doesn't need un-setting
set ( TESTHELPER_SRCS TestDataListener.cpp
TestGroupDataListener.cpp
../../TestHelpers/src/TearDownWorld.cpp
../../TestHelpers/src/ComponentCreationHelper.cpp
../../TestHelpers/src/WorkspaceCreationHelper.cpp
../../TestHelpers/src/StartFrameworkManager.cpp
Expand Down
3 changes: 2 additions & 1 deletion Code/Mantid/Framework/MDAlgorithms/test/CMakeLists.txt
Expand Up @@ -4,7 +4,8 @@ if ( CXXTEST_FOUND )
include_directories( ../../TestHelpers/inc ../../DataHandling/inc ../../CurveFitting/inc)
# This variable is used within the cxxtest_add_test macro to build these helper classes into the test executable.
# It will go out of scope at the end of this file so doesn't need un-setting
set ( TESTHELPER_SRCS ../../TestHelpers/src/ComponentCreationHelper.cpp
set ( TESTHELPER_SRCS ../../TestHelpers/src/TearDownWorld.cpp
../../TestHelpers/src/ComponentCreationHelper.cpp
../../TestHelpers/src/WorkspaceCreationHelper.cpp
../../TestHelpers/src/MDEventsTestHelper.cpp
../../TestHelpers/src/BinaryOperationMDTestHelper.cpp )
Expand Down
3 changes: 2 additions & 1 deletion Code/Mantid/Framework/MDEvents/test/CMakeLists.txt
Expand Up @@ -4,7 +4,8 @@ if ( CXXTEST_FOUND )
include_directories ( ../../TestHelpers/inc ../../DataHandling/inc )
# This variable is used within the cxxtest_add_test macro to build these helper classes into the test executable.
# It will go out of scope at the end of this file so doesn't need un-setting
set ( TESTHELPER_SRCS ../../TestHelpers/src/ComponentCreationHelper.cpp
set ( TESTHELPER_SRCS ../../TestHelpers/src/TearDownWorld.cpp
../../TestHelpers/src/ComponentCreationHelper.cpp
../../TestHelpers/src/WorkspaceCreationHelper.cpp
../../TestHelpers/src/MDEventsTestHelper.cpp
../../TestHelpers/src/ScopedFileHelper.cpp
Expand Down
7 changes: 6 additions & 1 deletion Code/Mantid/Framework/MPIAlgorithms/test/CMakeLists.txt
Expand Up @@ -2,7 +2,12 @@ if ( CXXTEST_FOUND )
include_directories ( SYSTEM ${CXXTEST_INCLUDE_DIR} ${GMOCK_INCLUDE_DIR} ${GTEST_INCLUDE_DIR} )

include_directories ( ../../TestHelpers/inc )
set ( TESTHELPER_SRCS ../../TestHelpers/src/ComponentCreationHelper.cpp ../../TestHelpers/src/WorkspaceCreationHelper.cpp )
set ( TESTHELPER_SRCS
../../TestHelpers/src/TearDownWorld.cpp
../../TestHelpers/src/ComponentCreationHelper.cpp
../../TestHelpers/src/WorkspaceCreationHelper.cpp
)

cxxtest_add_test ( MPIAlgorithmsTest ${TEST_FILES} )
target_link_libraries ( MPIAlgorithmsTest MPIAlgorithms )
add_dependencies ( FrameworkTests MPIAlgorithmsTest )
Expand Down
5 changes: 3 additions & 2 deletions Code/Mantid/Framework/SINQ/test/CMakeLists.txt
Expand Up @@ -2,8 +2,9 @@ if ( CXXTEST_FOUND )
include_directories ( SYSTEM ${CXXTEST_INCLUDE_DIR} ${GMOCK_INCLUDE_DIR} ${GTEST_INCLUDE_DIR} )

include_directories ( ../../MDEvents/inc ../../MDAlgorithms/inc ../../Nexus/inc ../../NexusCPP/inc ../../TestHelpers/inc)

set ( TESTHELPER_SRCS ../../TestHelpers/src/ComponentCreationHelper.cpp

set ( TESTHELPER_SRCS ../../TestHelpers/src/TearDownWorld.cpp
../../TestHelpers/src/ComponentCreationHelper.cpp
../../TestHelpers/src/WorkspaceCreationHelper.cpp )

if ( GMOCK_FOUND AND GTEST_FOUND )
Expand Down
@@ -0,0 +1,51 @@
#ifndef TEARDOWNWORLD_H_
#define TEARDOWNWORLD_H_
/**
Copyright © 2007-9 ISIS Rutherford Appleton Laboratory & NScD Oak Ridge National Laboratory
This file is part of Mantid.
Mantid is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
Mantid is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
File change history is stored at: <https://github.com/mantidproject/mantid>.
Code Documentation is available at: <http://doxygen.mantidproject.org>
*/
#include <cxxtest/GlobalFixture.h>

// This file defines a set of CxxTest::GlobalFixture classes that
// are used to control various aspects of the global test setUp and tearDown
// process

/**
* Defines a CxxTest::GlobalFixture that clears the AlgorithmManager
* when its tearDownWorld() method is called.
*/
class ClearAlgorithmManager : public CxxTest::GlobalFixture
{
bool tearDownWorld();
};

//-----------------------------------------------------------------------------

/**
* Defines a CxxTest::GlobalFixture that clears the AnalysisDataService
* when its tearDownWorld() method is called.
*/
class ClearADS : public CxxTest::GlobalFixture
{
bool tearDownWorld();
};


#endif // TEARDOWNWORLD_H_
36 changes: 36 additions & 0 deletions Code/Mantid/Framework/TestHelpers/src/TearDownWorld.cpp
@@ -0,0 +1,36 @@
//-----------------------------------------------------------------------------
// Includes
//-----------------------------------------------------------------------------
#include "MantidTestHelpers/TearDownWorld.h"
#include "MantidAPI/AlgorithmManager.h"
#include "MantidAPI/AnalysisDataService.h"

namespace
{
/// Define single ClearAlgorithmManager object
ClearAlgorithmManager clearAlgManager;
/// Definition of ClearADS object;
ClearADS clearADS;
}

//-----------------------------------------------------------------------------
// ClearAlgorithmManager
//-----------------------------------------------------------------------------
/// @return True to indicate success of the tear down process
bool ClearAlgorithmManager::tearDownWorld()
{
Mantid::API::AlgorithmManager::Instance().clear();
return true;
}


//-----------------------------------------------------------------------------
// ClearADS
//-----------------------------------------------------------------------------

/// @return True to indicate success of the tear down process
bool ClearADS::tearDownWorld()
{
Mantid::API::AnalysisDataService::Instance().clear();
return true;
}
3 changes: 2 additions & 1 deletion Code/Mantid/Framework/WorkflowAlgorithms/test/CMakeLists.txt
Expand Up @@ -5,7 +5,8 @@ if ( CXXTEST_FOUND )
include_directories ( ../../Algorithms/inc ../../DataHandling/inc ../../TestHelpers/inc )
# This variable is used within the cxxtest_add_test macro to build these helper classes into the test executable.
# It will go out of scope at the end of this file so doesn't need un-setting
set ( TESTHELPER_SRCS ../../TestHelpers/src/ComponentCreationHelper.cpp
set ( TESTHELPER_SRCS ../../TestHelpers/src/TearDownWorld.cpp
../../TestHelpers/src/ComponentCreationHelper.cpp
../../TestHelpers/src/WorkspaceCreationHelper.cpp )
cxxtest_add_test ( WorkflowAlgorithmsTest ${TEST_FILES} )
target_link_libraries ( WorkflowAlgorithmsTest WorkflowAlgorithms Algorithms DataHandling )
Expand Down
6 changes: 4 additions & 2 deletions Code/Mantid/MantidQt/API/test/CMakeLists.txt
Expand Up @@ -6,8 +6,10 @@ if ( CXXTEST_FOUND )

# This variable is used within the cxxtest_add_test macro to build these helper classes into the test executable.
# It will go out of scope at the end of this file so doesn't need un-setting
set ( TESTHELPER_SRCS ../../../Framework/TestHelpers/src/ComponentCreationHelper.cpp
../../../Framework/TestHelpers/src/WorkspaceCreationHelper.cpp )
set ( TESTHELPER_SRCS ../../../Framework/TestHelpers/src/TearDownWorld.cpp
../../../Framework/TestHelpers/src/ComponentCreationHelper.cpp
../../../Framework/TestHelpers/src/WorkspaceCreationHelper.cpp
)

cxxtest_add_test ( MantidQtAPITest ${TEST_FILES} )
target_link_libraries( MantidQtAPITest MantidQtAPI DataObjects)
Expand Down
2 changes: 2 additions & 0 deletions Code/Mantid/MantidQt/CustomInterfaces/test/CMakeLists.txt
Expand Up @@ -9,6 +9,8 @@ if ( CXXTEST_FOUND )
)

if ( GMOCK_FOUND AND GTEST_FOUND )
set ( TESTHELPER_SRCS ../../../Framework/TestHelpers/src/TearDownWorld.cpp )

cxxtest_add_test ( CustomInterfacesTest ${TEST_FILES} ${GMOCK_TEST_FILES} )
target_link_libraries( CustomInterfacesTest CustomInterfaces DataObjects ${GMOCK_LIBRARIES} ${GTEST_LIBRARIES} )
add_dependencies( CustomInterfacesTest MDAlgorithms )
Expand Down

0 comments on commit f564331

Please sign in to comment.