Skip to content

Commit

Permalink
Add separate target for unit tests for easier test access. Remove uni…
Browse files Browse the repository at this point in the history
…t tests from ResInsight application.

Clean up cmake configuration a bit, and pull down gtest when needed, no longer use a thirdparty subfolder

Fixes by cmake-format

Some cleanup

Update build script to use new unit tests

Fixes by cmake-format

Some fixes

Add target for copying dependencies to output folder (work in progress)

Make sure we copy the needed dependencies to the output build folder

Revert "Make sure we copy the needed dependencies to the output build folder"

This reverts commit d412597.

Fixes by cmake-format

TEst

Fixes by cmake-format

Add install target for tests

Cleanup obsolete command

Fix merge gone wrong

Fix comment
  • Loading branch information
jonjenssen committed Feb 11, 2024
1 parent 5a3894b commit fe3e085
Show file tree
Hide file tree
Showing 26 changed files with 267 additions and 27,094 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/ResInsightWithCache.yml
Original file line number Diff line number Diff line change
Expand Up @@ -240,11 +240,12 @@ jobs:
- name: Stats for buildcache
run: ${{ github.workspace }}/buildcache/bin/buildcache -s

- name: Run Unit Tests
if: matrix.config.execute-unit-tests
shell: bash
run: |
cmakebuild/ApplicationExeCode/ResInsight --unittest
cmakebuild/ApplicationLibCode/UnitTests/ResInsight-tests
- name: (Python) Check types using mypy
if: matrix.config.build-python-module
Expand Down
66 changes: 2 additions & 64 deletions ApplicationExeCode/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -271,14 +271,14 @@ set(LINK_LIBRARIES
${VIZ_FWK_LIBRARIES}
ApplicationLibCode
Commands
RigGeoMechDataModel
RifGeoMechFileInterface
)

if(RESINSIGHT_ENABLE_GRPC)
list(APPEND LINK_LIBRARIES GrpcInterface)
endif()

list(APPEND LINK_LIBRARIES RigGeoMechDataModel RifGeoMechFileInterface)

if(RESINSIGHT_USE_ODB_API)
add_definitions(-DUSE_ODB_API)
list(APPEND LINK_LIBRARIES RifOdbReader)
Expand Down Expand Up @@ -317,68 +317,6 @@ endif()
# ##############################################################################
# Copy Dlls on MSVC
# ##############################################################################
if(MSVC)

if(NOT ${RESINSIGHT_ODB_API_DIR} EQUAL "")
set(RESINSIGHT_USE_ODB_API 1)
endif()

# Odb Dlls
if(RESINSIGHT_USE_ODB_API)
# Find all the dlls
file(GLOB RI_ALL_ODB_DLLS ${RESINSIGHT_ODB_API_DIR}/lib/*.dll)

# Strip off the path
foreach(aDLL ${RI_ALL_ODB_DLLS})
get_filename_component(filenameWithExt ${aDLL} NAME)
list(APPEND RI_ODB_DLLS ${filenameWithExt})
endforeach(aDLL)

foreach(aDLL ${RI_ODB_DLLS})
list(APPEND RI_FILENAMES ${RESINSIGHT_ODB_API_DIR}/lib/${aDLL})
endforeach()
endif()

# OpenVDS Dlls
set(OPENVDS_DLL_NAMES openvds segyutils)
foreach(OPENVDS_DLL_NAME ${OPENVDS_DLL_NAMES})
list(APPEND RI_FILENAMES
${RESINSIGHT_OPENVDS_API_DIR}/bin/msvc_141/${OPENVDS_DLL_NAME}.dll
)
endforeach(OPENVDS_DLL_NAME)
list(APPEND RI_FILENAMES
${RESINSIGHT_OPENVDS_API_DIR}/bin/msvc_141/SEGYImport.exe
)

# HDF5 Dlls
if(RESINSIGHT_FOUND_HDF5)
set(HDF5_DLL_NAMES hdf5 hdf5_cpp szip zlib)
foreach(HDF5_DLL_NAME ${HDF5_DLL_NAMES})
list(APPEND RI_FILENAMES ${RESINSIGHT_HDF5_DIR}/bin/${HDF5_DLL_NAME}.dll)
endforeach(HDF5_DLL_NAME)
endif()

else()
# Linux

# OpenVDS lib files
list(APPEND RI_FILENAMES ${RESINSIGHT_OPENVDS_API_DIR}/bin/SEGYImport)

set(OPENVDS_LIB_NAMES
libopenvds.so
libopenvds.so.3
libopenvds.so.3.2.7
libopenvds-e1541338.so.3.2.7
libsegyutils.so
libsegyutils.so.3
libsegyutils.so.3.2.7
)
foreach(OPENVDS_LIB_NAME ${OPENVDS_LIB_NAMES})
list(APPEND RI_FILENAMES
${RESINSIGHT_OPENVDS_API_DIR}/lib64/${OPENVDS_LIB_NAME}
)
endforeach(OPENVDS_LIB_NAME)
endif(MSVC)

# create an empty library target that will be used to copy files to the build
# folder
Expand Down
62 changes: 0 additions & 62 deletions ApplicationLibCode/Application/RiaApplication.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,10 +125,6 @@
#include <unistd.h> // for usleep
#endif // WIN32

#ifdef USE_UNIT_TESTS
#include "gtest/gtest.h"
#endif // USE_UNIT_TESTS

// Required to ignore warning of usused variable when defining caf::PdmMarkdownGenerator
#if defined( __clang__ )
#pragma clang diagnostic ignored "-Wunused-variable"
Expand Down Expand Up @@ -1395,56 +1391,6 @@ void RiaApplication::waitUntilCommandObjectsHasBeenProcessed()
m_commandQueueLock.unlock();
}

//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
int RiaApplication::launchUnitTests()
{
#ifdef USE_UNIT_TESTS

caf::ProgressInfoBlocker progressBlocker;
cvf::Assert::setReportMode( cvf::Assert::CONSOLE );

int argc = QCoreApplication::arguments().size();
QStringList arguments = QCoreApplication::arguments();
std::vector<std::string> argumentsStd;
for ( QString qstring : arguments )
{
argumentsStd.push_back( qstring.toStdString() );
}
std::vector<char*> argVector;
for ( std::string& string : argumentsStd )
{
argVector.push_back( &string.front() );
}
char** argv = argVector.data();

testing::InitGoogleTest( &argc, argv );

//
// Use the gtest filter to execute a subset of tests
QString filterText = RiaPreferencesSystem::current()->gtestFilter();
if ( !filterText.isEmpty() )
{
::testing::GTEST_FLAG( filter ) = filterText.toStdString();

// Example on filter syntax
//::testing::GTEST_FLAG( filter ) = "*RifCaseRealizationParametersReaderTest*";
}

// Use this macro in main() to run all tests. It returns 0 if all
// tests are successful, or 1 otherwise.
//
// RUN_ALL_TESTS() should be invoked after the command line has been
// parsed by InitGoogleTest().

return RUN_ALL_TESTS();

#else
return -1;
#endif
}

//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
Expand Down Expand Up @@ -1562,14 +1508,6 @@ void RiaApplication::initialize()
caf::SelectionManager::instance()->setPdmRootObject( project() );
}

//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
int RiaApplication::launchUnitTestsWithConsole()
{
return launchUnitTests();
}

//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
Expand Down
1 change: 0 additions & 1 deletion ApplicationLibCode/Application/RiaApplication.h
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,6 @@ class RiaApplication
// Public implementation specific overrides
virtual void initialize();
virtual ApplicationStatus handleArguments( gsl::not_null<cvf::ProgramOptions*> progOpt ) = 0;
virtual int launchUnitTestsWithConsole();
virtual void addToRecentFiles( const QString& fileName ) {}
virtual void showFormattedTextInMessageBoxOrConsole( const QString& errMsg ) = 0;

Expand Down
16 changes: 0 additions & 16 deletions ApplicationLibCode/Application/RiaConsoleApplication.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -154,22 +154,6 @@ RiaApplication::ApplicationStatus RiaConsoleApplication::handleArguments( gsl::n
return RiaApplication::ApplicationStatus::EXIT_COMPLETED;
}

// Unit testing
// --------------------------------------------------------
if ( cvf::Option o = progOpt->option( "unittest" ) )
{
int testReturnValue = launchUnitTestsWithConsole();
if ( testReturnValue == 0 )
{
return RiaApplication::ApplicationStatus::EXIT_COMPLETED;
}
else
{
RiaLogging::error( "Error running unit tests" );
return RiaApplication::ApplicationStatus::EXIT_WITH_ERROR;
}
}

if ( cvf::Option o = progOpt->option( "startdir" ) )
{
CVF_ASSERT( o.valueCount() == 1 );
Expand Down
45 changes: 0 additions & 45 deletions ApplicationLibCode/Application/RiaGuiApplication.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -142,10 +142,6 @@
#include <unistd.h> // for usleep
#endif // WIN32

#ifdef USE_UNIT_TESTS
#include "gtest/gtest.h"
#endif // USE_UNIT_TESTS

//==================================================================================================
///
/// \class RiaGuiApplication
Expand Down Expand Up @@ -484,22 +480,6 @@ RiaApplication::ApplicationStatus RiaGuiApplication::handleArguments( gsl::not_n
return RiaApplication::ApplicationStatus::EXIT_COMPLETED;
}

// Unit testing
// --------------------------------------------------------
if ( cvf::Option o = progOpt->option( "unittest" ) )
{
int testReturnValue = launchUnitTestsWithConsole();
if ( testReturnValue == 0 )
{
return RiaApplication::ApplicationStatus::EXIT_COMPLETED;
}
else
{
RiaLogging::error( "Error running unit tests" );
return RiaApplication::ApplicationStatus::EXIT_WITH_ERROR;
}
}

if ( cvf::Option o = progOpt->option( "regressiontest" ) )
{
CVF_ASSERT( o.valueCount() == 1 );
Expand Down Expand Up @@ -891,31 +871,6 @@ RiaApplication::ApplicationStatus RiaGuiApplication::handleArguments( gsl::not_n
return ApplicationStatus::KEEP_GOING;
}

//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
int RiaGuiApplication::launchUnitTestsWithConsole()
{
// Following code is taken from cvfAssert.cpp
#ifdef WIN32
{
// Allocate a new console for this app
// Only one console can be associated with an app, so should fail if a console is already present.
AllocConsole();

FILE* consoleFilePointer;

freopen_s( &consoleFilePointer, "CONOUT$", "w", stdout );
freopen_s( &consoleFilePointer, "CONOUT$", "w", stderr );

// Make cout, wcout, cin, wcin, wcerr, cerr, wclog and clog point to console as well
std::ios::sync_with_stdio();
}
#endif

return launchUnitTests();
}

//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
Expand Down
1 change: 0 additions & 1 deletion ApplicationLibCode/Application/RiaGuiApplication.h
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,6 @@ class RiaGuiApplication : public QApplication, public RiaApplication
// Public RiaApplication overrides
void initialize() override;
ApplicationStatus handleArguments( gsl::not_null<cvf::ProgramOptions*> progOpt ) override;
int launchUnitTestsWithConsole() override;
void addToRecentFiles( const QString& fileName ) override;
void showFormattedTextInMessageBoxOrConsole( const QString& errMsg ) override;

Expand Down
3 changes: 0 additions & 3 deletions ApplicationLibCode/Application/Tools/RiaArgumentParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -130,9 +130,6 @@ bool RiaArgumentParser::parseArguments( cvf::ProgramOptions* progOpt )

progOpt->registerOption( "updateregressiontestbase", "<folder>", "System command", cvf::ProgramOptions::SINGLE_VALUE );
progOpt->registerOption( "regressiontest", "<folder>", "System command", cvf::ProgramOptions::SINGLE_VALUE );
#ifdef USE_UNIT_TESTS
progOpt->registerOption( "unittest", "", "System command" );
#endif
progOpt->registerOption( "generate", "[<outputFile>]", "Generate code or documentation", cvf::ProgramOptions::SINGLE_VALUE );
progOpt->registerOption( "ignoreArgs", "", "System command. Ignore all arguments. Mostly for testing purposes" );
progOpt->registerOption( "version", "", "Display the application version string" );
Expand Down
Loading

0 comments on commit fe3e085

Please sign in to comment.