Skip to content

Conversation

@vgvassilev
Copy link
Member

Add unit tests for TQObject as an example for further reference.

include_directories(${GTEST_INCLUDE_DIR} ${GMOCK_INCLUDE_DIR})

# Note we cannot use ROOT_EXECUTABLE because it requires to pass LIBRARIES to link with.
# The test suites should chose this in their specific CMakeLists.txt file.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you clarify in the comment why ROOT_EXECUTABLE is used here despite what the comment says?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's not clear, I don't remember why I put this comment there. I think it means to say, we cannot just call ROOT_EXECUTABLE from the outside because we need to link against the gtest libraries or we will have to explicitly specify them outside.

@vgvassilev
Copy link
Member Author

@phsft-bot build!

1 similar comment
@martinmine
Copy link
Contributor

@phsft-bot build!

Copy link
Member

@Axel-Naumann Axel-Naumann left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for doing this, Vassil - I agree that this will be nice to have!

@@ -0,0 +1,6 @@
set (link_libs Core)

ROOT_ADD_GTEST(CoreBaseTests
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd prefer to have src/, inc/, test/ at the same level. E.g. sql/mysql would only be enabled if we have the mysql library in the system; that would automatically enable / disable the tests with it.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree. It makes much more sense to have the test for a module under that module's directory rather than under the category (and core is a bad example to talk about the differences between the two :)).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

#
function(ROOT_ADD_GTEST test_suite test_name)
CMAKE_PARSE_ARGUMENTS(ARG "" "" "LIBRARIES" ${ARGN})

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we add the source directory to the include dirs, or does that happen by default? (I want to be able to #include a header in the tests.)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ping?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.


#----------------------------------------------------------------------------
# function ROOT_ADD_GTEST(<testsuite> <name> LIBRARIES)
#
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is test_name TQObjectTests.cxx in the example below? If so, can you rename this to source then? And can we have multiple sources?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the name of the Binary (i.e. test suite). Yeah we can have multiple files.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How do I specify multiple sources? Can you add this to the doc of the CMake function? (I don't see how binary name and source files map to <testsuite> and <name>).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.


#----------------------------------------------------------------------------
# function ROOT_ADD_GTEST(<testsuite> <name> LIBRARIES)
#
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In roottest, I found the following parameters useful:

  CMAKE_PARSE_ARGUMENTS(ARG
    "WILLFAIL"
    ""
    "COPY_TO_BUILDDIR;DEPENDS;OPTS;LABELS;ENVIRONMENT"
    ${ARGN})

Also, I just glob the test sources:

  file(GLOB unittests_SRC
    "*.h"
    "*.hh"
    "*.hpp"
    "*.hxx"
    "*.cpp"
    "*.cxx"
    "*.cc"
    "*.C"
    )

Just drop a source file into test/ and it's part of the unit test.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, that could be done when we start adding tests and need it.

I don't like globbing because it causes quite a few issues if the source folder is unclean, etc. In general, it would be much more often editing tests rather than adding new ones.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would request that we do this from day 0. Else it'll be a mess, with people adding their files by hand, until you find the time to do it.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the suggestion. I don't see it that dramatic, I will clean up all eventual mess if there is any.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The team converged on globbing.

# Note we cannot use ROOT_EXECUTABLE because it requires to pass LIBRARIES to link with.
# The test suites should chose this in their specific CMakeLists.txt file.
ROOT_EXECUTABLE(${test_suite} ${test_name} LIBRARIES ${ARG_LIBRARIES})
target_link_libraries(${test_suite} gtest gtest_main gmock gmock_main)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe this is missing some environment:

  set(environment ENVIRONMENT
                  ${ROOTTEST_ENV_EXTRA}
                  ${ARG_ENVIRONMENT}
                  ROOTSYS=${ROOTSYS}
                  PATH=${_path}:$ENV{PATH}
                  PYTHONPATH=${_pythonpath}:$ENV{PYTHONPATH}
                  ${ld_library_path}=${_librarypath}:$ENV{${ld_library_path}})

is what I pass to ROOT_ADD_TEST in roottest/cmake/modules/RootCTestMacros.cmake's ROOTTEST_ADD_UNITTEST_DIR

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe I am missing context but it seems this is out of the scope of this PR.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is needed for runing the tests without setting thisroot.sh before. I.e. no, AFAIK this is a prerequisite.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ping?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IIUC, this was resolved internally. There was something to check, outside of this PR.

add_subdirectory(lzma)

if(testing)
ROOT_ADD_TEST_SUBDIRECTORY(test)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The nice thing about moving this next to src/ is that we can now systematically include the test/ subdirs in ROOT_LINKER_LIBRARY in cmake/modules/RootNewMacros.cmake. And yes that macro is a misnomer since a while already, it should probably be called ROOT_ADD_MODULE.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems this refactoring is for another PR.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree.

#include "RQ_OBJECT.h"

// FIXME: We should think of a common place to put the mock objects.
class TQConnectionMock : public TQConnection {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where do you use TQConnectionMock?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

#include "RQ_OBJECT.h"

// FIXME: We should think of a common place to put the mock objects.
class TQConnectionMock : public TQConnection {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you (to get us started) include a very simple test - something without mocks etc, but where you literally check whether say TNamed::GetName() returns what was set in the TNamed constructor?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

@vgvassilev
Copy link
Member Author

The comments have been addressed.

@phsft-bot
Copy link

Starting build on centos7/gcc49, mac1011/native, slc6/gcc49, slc6/gcc62, ubuntu14/native

2 similar comments
@phsft-bot
Copy link

Starting build on centos7/gcc49, mac1011/native, slc6/gcc49, slc6/gcc62, ubuntu14/native

@phsft-bot
Copy link

Starting build on centos7/gcc49, mac1011/native, slc6/gcc49, slc6/gcc62, ubuntu14/native

@phsft-bot
Copy link

Starting build on centos7/gcc49, mac1011/native, slc6/gcc49, slc6/gcc62, ubuntu14/native

1 similar comment
@phsft-bot
Copy link

Starting build on centos7/gcc49, mac1011/native, slc6/gcc49, slc6/gcc62, ubuntu14/native

@vgvassilev
Copy link
Member Author

@phsft-bot build!

@phsft-bot
Copy link

Starting build on centos7/gcc49, mac1011/native, slc6/gcc49, slc6/gcc62, ubuntu14/native

@phsft-bot
Copy link

Starting build on centos7/gcc49, mac1011/native, slc6/gcc49, slc6/gcc62, ubuntu14/native

@phsft-bot
Copy link

Starting build on centos7/gcc49, mac1011/native, slc6/gcc49, slc6/gcc62, ubuntu14/native

@phsft-bot
Copy link

Starting build on centos7/gcc49, mac1011/native, slc6/gcc49, slc6/gcc62, ubuntu14/native

@vgvassilev
Copy link
Member Author

@phsft-bot build!

@phsft-bot
Copy link

Starting build on centos7/gcc49, mac1011/native, slc6/gcc49, slc6/gcc62, ubuntu14/native


endfunction()

#----------------------------------------------------------------------------
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is that LIBRARIES <lib1> <lib2> or how does that work? Could you clarify in the comment/doc?

@phsft-bot
Copy link

Starting build on centos7/gcc49, mac1011/native, slc6/gcc49, slc6/gcc62, ubuntu14/native

@phsft-bot
Copy link

Starting build on centos7/gcc49, mac1011/native, slc6/gcc49, slc6/gcc62, ubuntu14/native

@phsft-bot
Copy link

Starting build on centos7/gcc49, mac1011/native, slc6/gcc49, slc6/gcc62, ubuntu14/native and CMake flags -Dccache=ON -Dimt=OFF

# The test suites should choose this in their specific CMakeLists.txt file.
# FIXME: For better coherence we could restrict the libraries the test suite could link
# against. For example, tests in Core should link only against libCore. This could be tricky
# to implement because some ROOT components create more than one library.
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@peremato, this is the problematic line that puts the test binary in the ROOT install dir.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The default output directory for binaries is controlled by this variable CMAKE_RUNTIME_OUTPUT_DIRECTORY. On possibility is to clear the variable before calling ROOT_EXECUTABLE(...) or setting the specific target property afterwards with

set_property(TARGET ${test_suite} 
                       PROPERTY RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})

@Axel-Naumann
Copy link
Member

Re the question "do we need to set env or not":
$ ctest -V -R mathcore-testSpecFuncErf does

17: Test command: /mnt/a/build/local/cmake/cmake-3.7.1-Linux-x86_64/bin/cmake "-DCMD=/home/axel/build/root/github/cmake-reldeb/math/mathcore/test/testSpecFuncErf" "-DSYS=/home/axel/build/root/github/cmake-reldeb" "-P" "/home/axel/build/root/github/src/cmake/modules/RootTestDriver.cmake"

That in turn sets

if(SYS)
  if(WIN32)
    file(TO_NATIVE_PATH ${SYS}/bin _path)
    set(ENV{PATH} "${_path};$ENV{PATH}")
  elseif(APPLE)
    set(ENV{PATH} ${SYS}/bin:$ENV{PATH})
    set(ENV{DYLD_LIBRARY_PATH} ${SYS}/lib:$ENV{DYLD_LIBRARY_PATH})
  else()
    set(ENV{PATH} ${SYS}/bin:$ENV{PATH})
    set(ENV{LD_LIBRARY_PATH} ${SYS}/lib:$ENV{LD_LIBRARY_PATH})
  endif()
endif()

So as long as these tests run through RootTestDriver.cmake we should be good. Do they?

@peremato
Copy link
Contributor

peremato commented Apr 6, 2017

@axel, yes they will always go through the RootTestDriver.cmake because is using ROOT_ADD_TEST(...). The need to define LD_LIBRARY_PATH and PATH comes from dynamically loaded libraries and not to load the test executable. The test executable has the RPATH pointing to build tree. See for example:

$ objdump -x math/mathcore/test/testSpecFuncErf | grep RPATH
  RPATH                /mnt/build/jenkins/workspace/root-nightly-master-imt/BUILDTYPE/Release/COMPILER/gcc49/LABEL/slc6/build/lib

@vgvassilev
Copy link
Member Author

IMO, the unittest should depend as little as possible on environment. They should be written in such a manner that they don't need to tweak environment variables and so on.

@phsft-bot
Copy link

Starting build on centos7/gcc49, mac1011/native, slc6/gcc49, slc6/gcc62, ubuntu14/native and CMake flags -Dccache=ON -Dimt=OFF

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants