How to run tests?


#1

I’d like to run xgboost’s tests. I cloned the Github repo and checked out the release_0.81 branch. After following the instructions here, I was able to build xgboost from source using make -j4.

Is there a way to just run the tests? I tried doing make test but ran into a “fatal error”.

I am on Ubuntu 16.04.


#2

FYI, when I run make test, the error I get is:
g++ -DDMLC_LOG_CUSTOMIZE=1 -std=c++11 -Wall -Wno-unknown-pragmas -Iinclude -Idmlc-core/include -Irabit/include -I/include -O3 -funroll-loops -msse2 -fPIC -fopenmp -I/include/ -o build_tests/cpp/helpers.o -c tests/cpp/helpers.cc In file included from tests/cpp/helpers.cc:4:0: tests/cpp/./helpers.h:15:25: fatal error: gtest/gtest.h: No such file or directory compilation terminated. tests/cpp/xgboost_test.mk:22: recipe for target 'build_tests/cpp/helpers.o' failed make: *** [build_tests/cpp/helpers.o] Error 1


#3

In all honesty I couldn’t get CMake to find the GoogleTest libraries even though I did the local install, and installed in Ubuntu, or using Google’s own instructions. Hopefully someone has better instructions, it’s been on the roadmap to document this.

What I did is install gtest locally on Ubuntu: sudo apt install libgtest-dev. You can also follow this guide.

Then remove the GTest requirement in CMakeLists.txt because it can’t seem to find gtest regardless:

# Test
if(GOOGLE_TEST)
  enable_testing()
  # Disable this because I couldn't get it to find the libraries
#  find_package(GTest REQUIRED)

  auto_source_group("${TEST_SOURCES}")
  include_directories(${GTEST_INCLUDE_DIRS})

  if(USE_CUDA)
    file(GLOB_RECURSE CUDA_TEST_SOURCES "tests/cpp/*.cu")
    cuda_compile(CUDA_TEST_OBJS ${CUDA_TEST_SOURCES})
  else()
    set(CUDA_TEST_OBJS "")
  endif()

  add_executable(testxgboost ${TEST_SOURCES} ${CUDA_TEST_OBJS} $<TARGET_OBJECTS:objxgboost>)
  set_output_directory(testxgboost ${PROJECT_SOURCE_DIR})
    # Add gtest manually, the variable is no longer available
  target_link_libraries(testxgboost gtest ${LINK_LIBRARIES})

  add_test(TestXGBoost testxgboost)
endif()

Then you can run make testxgboost in your cmake build directory and run the tests using ../testxgboost. That is, after you’ve installed Gtest and made the changes to CMakeLists.txt:

mkdir build
cd build
cmake  -DGOOGLE_TEST=ON ..
make -j4 testxgboost
../testxgboost

#4

Hi Theodore. Thank you for your detailed reply! I will try your above instructions and let you know if it works.


#5

That’s odd to me. I deprecated the customized gtest CMake script and Linux test farms are running gtest. By the way, location of GTest can be specified by CMake flag -DGTEST_ROOT=/path/to/gtest.


#6

@jiaming could you give directions on how to run the tests on a fresh clone without a local installation of Gtest then?

I’ve tried running cmake -DGTEST_ROOT=googletest-src -DGOOGLE_TEST=ON .. but it still doesn’t find Gtest.


#7

The GTEST_ROOT specifies the installation path of GoogleTests. It’s a parameter from CMake’s own FindGtest script: https://cmake.org/cmake/help/v3.10/module/FindGTest.html

That being said, you have to install googletest somewhere first. We made an ugly hack to run googletest on Travis due to Ubuntu is not distributing it:

But I think the same thing can also be achieved by specifying -DCMAKE_INSTALL_PREFIXwhen compiling googletest. Hope that helps.