Use bundled gtest (#4900)
* Suggest to use gtest bundled with dmlc * Use dmlc bundled gtest in all CI scripts * Make clang-tidy to use dmlc embedded gtest
This commit is contained in:
parent
095de3bf5f
commit
80977182c5
@ -29,7 +29,7 @@ option(JVM_BINDINGS "Build JVM bindings" OFF)
|
|||||||
option(R_LIB "Build shared library for R package" OFF)
|
option(R_LIB "Build shared library for R package" OFF)
|
||||||
## Dev
|
## Dev
|
||||||
option(GOOGLE_TEST "Build google tests" OFF)
|
option(GOOGLE_TEST "Build google tests" OFF)
|
||||||
option(USE_DMLC_GTEST "Use google tests bundled with dmlc-core submodule (EXPERIMENTAL)" OFF)
|
option(USE_DMLC_GTEST "Use google tests bundled with dmlc-core submodule" OFF)
|
||||||
option(USE_NVTX "Build with cuda profiling annotations. Developers only." OFF)
|
option(USE_NVTX "Build with cuda profiling annotations. Developers only." OFF)
|
||||||
set(NVTX_HEADER_DIR "" CACHE PATH "Path to the stand-alone nvtx header")
|
set(NVTX_HEADER_DIR "" CACHE PATH "Path to the stand-alone nvtx header")
|
||||||
option(RABIT_MOCK "Build rabit with mock" OFF)
|
option(RABIT_MOCK "Build rabit with mock" OFF)
|
||||||
|
|||||||
2
Jenkinsfile
vendored
2
Jenkinsfile
vendored
@ -116,7 +116,7 @@ def ClangTidy() {
|
|||||||
def docker_binary = "docker"
|
def docker_binary = "docker"
|
||||||
def dockerArgs = "--build-arg CUDA_VERSION=9.2"
|
def dockerArgs = "--build-arg CUDA_VERSION=9.2"
|
||||||
sh """
|
sh """
|
||||||
${dockerRun} ${container_type} ${docker_binary} ${dockerArgs} tests/ci_build/clang_tidy.sh
|
${dockerRun} ${container_type} ${docker_binary} ${dockerArgs} python3 tests/ci_build/tidy.py
|
||||||
"""
|
"""
|
||||||
deleteDir()
|
deleteDir()
|
||||||
}
|
}
|
||||||
|
|||||||
@ -118,21 +118,19 @@ To run this check locally, run the following command from the top level source t
|
|||||||
.. code-block:: bash
|
.. code-block:: bash
|
||||||
|
|
||||||
cd /path/to/xgboost/
|
cd /path/to/xgboost/
|
||||||
python3 tests/ci_build/tidy.py --gtest-path=/path/to/google-test
|
python3 tests/ci_build/tidy.py
|
||||||
|
|
||||||
where ``--gtest-path`` option specifies the full path of Google Test library.
|
|
||||||
|
|
||||||
Also, the script accepts two optional integer arguments, namely ``--cpp`` and ``--cuda``. By default they are both set to 1, meaning that both C++ and CUDA code will be checked. If the CUDA toolkit is not installed on your machine, you'll encounter an error. To exclude CUDA source from linting, use:
|
Also, the script accepts two optional integer arguments, namely ``--cpp`` and ``--cuda``. By default they are both set to 1, meaning that both C++ and CUDA code will be checked. If the CUDA toolkit is not installed on your machine, you'll encounter an error. To exclude CUDA source from linting, use:
|
||||||
|
|
||||||
.. code-block:: bash
|
.. code-block:: bash
|
||||||
|
|
||||||
cd /path/to/xgboost/
|
cd /path/to/xgboost/
|
||||||
python3 tests/ci_build/tidy.py --cuda=0 --gtest-path=/path/to/google-test
|
python3 tests/ci_build/tidy.py --cuda=0
|
||||||
|
|
||||||
Similarly, if you want to exclude C++ source from linting:
|
Similarly, if you want to exclude C++ source from linting:
|
||||||
|
|
||||||
.. code-block:: bash
|
.. code-block:: bash
|
||||||
|
|
||||||
cd /path/to/xgboost/
|
cd /path/to/xgboost/
|
||||||
python3 tests/ci_build/tidy.py --cpp=0 --gtest-path=/path/to/google-test
|
python3 tests/ci_build/tidy.py --cpp=0
|
||||||
|
|
||||||
|
|||||||
@ -104,14 +104,13 @@ In addition, to test CUDA code, run:
|
|||||||
C++: Google Test
|
C++: Google Test
|
||||||
================
|
================
|
||||||
|
|
||||||
To build and run C++ unit tests, install `Google Test <https://github.com/google/googletest>`_ library with headers
|
To build and run C++ unit tests enable tests while running CMake:
|
||||||
and then enable tests while running CMake:
|
|
||||||
|
|
||||||
.. code-block:: bash
|
.. code-block:: bash
|
||||||
|
|
||||||
mkdir build
|
mkdir build
|
||||||
cd build
|
cd build
|
||||||
cmake -DGOOGLE_TEST=ON -DGTEST_ROOT=/path/to/google-test ..
|
cmake -DGOOGLE_TEST=ON -DUSE_DMLC_GTEST=ON ..
|
||||||
make
|
make
|
||||||
make test
|
make test
|
||||||
|
|
||||||
@ -121,7 +120,7 @@ To enable tests for CUDA code, add ``-DUSE_CUDA=ON`` and ``-DUSE_NCCL=ON`` (CUDA
|
|||||||
|
|
||||||
mkdir build
|
mkdir build
|
||||||
cd build
|
cd build
|
||||||
cmake -DGOOGLE_TEST=ON -DGTEST_ROOT=/path/to/google-test -DUSE_CUDA=ON -DUSE_NCCL=ON ..
|
cmake -DGOOGLE_TEST=ON -DUSE_DMLC_GTEST=ON -DUSE_CUDA=ON -DUSE_NCCL=ON ..
|
||||||
make
|
make
|
||||||
make test
|
make test
|
||||||
|
|
||||||
|
|||||||
@ -1,20 +1,10 @@
|
|||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
set -e
|
set -e
|
||||||
|
|
||||||
# Build gtest via cmake
|
|
||||||
rm -rf gtest
|
|
||||||
wget -nc https://github.com/google/googletest/archive/release-1.7.0.zip
|
|
||||||
unzip -n release-1.7.0.zip
|
|
||||||
mv googletest-release-1.7.0 gtest && cd gtest
|
|
||||||
cmake . && make
|
|
||||||
mkdir lib && mv libgtest.a lib
|
|
||||||
cd ..
|
|
||||||
rm -rf release-1.7.0.zip*
|
|
||||||
|
|
||||||
rm -rf build
|
rm -rf build
|
||||||
mkdir build
|
mkdir build
|
||||||
cd build
|
cd build
|
||||||
cmake .. "$@" -DGOOGLE_TEST=ON -DGTEST_ROOT=$PWD/../gtest -DCMAKE_VERBOSE_MAKEFILE=ON
|
cmake .. "$@" -DGOOGLE_TEST=ON -DUSE_DMLC_GTEST=ON -DCMAKE_VERBOSE_MAKEFILE=ON
|
||||||
make clean
|
make clean
|
||||||
make -j$(nproc)
|
make -j$(nproc)
|
||||||
cd ..
|
cd ..
|
||||||
|
|||||||
@ -1,18 +0,0 @@
|
|||||||
#!/bin/bash
|
|
||||||
|
|
||||||
export GTEST_PKG_NAME=release-1.8.1
|
|
||||||
export GTEST_DIR_NAME=googletest-${GTEST_PKG_NAME} # uncompressed directory
|
|
||||||
export GTEST_ZIP_FILE=${GTEST_PKG_NAME}.zip # downloaded zip ball name
|
|
||||||
|
|
||||||
rm -rf gtest googletest-release*
|
|
||||||
|
|
||||||
wget -nc https://github.com/google/googletest/archive/${GTEST_ZIP_FILE}
|
|
||||||
unzip -n ${GTEST_ZIP_FILE}
|
|
||||||
mv ${GTEST_DIR_NAME} gtest && cd gtest
|
|
||||||
cmake . -DCMAKE_INSTALL_PREFIX=./ins && make
|
|
||||||
make install
|
|
||||||
|
|
||||||
cd ..
|
|
||||||
rm ${GTEST_ZIP_FILE}
|
|
||||||
|
|
||||||
python3 tests/ci_build/tidy.py --gtest-path=${PWD}/gtest/ins
|
|
||||||
@ -29,15 +29,12 @@ class ClangTidy(object):
|
|||||||
'''
|
'''
|
||||||
clang tidy wrapper.
|
clang tidy wrapper.
|
||||||
Args:
|
Args:
|
||||||
gtest_path: Full path of Google Test library.
|
|
||||||
cpp_lint: Run linter on C++ source code.
|
cpp_lint: Run linter on C++ source code.
|
||||||
cuda_lint: Run linter on CUDA source code.
|
cuda_lint: Run linter on CUDA source code.
|
||||||
'''
|
'''
|
||||||
def __init__(self, gtest_path, cpp_lint, cuda_lint):
|
def __init__(self, cpp_lint, cuda_lint):
|
||||||
self.gtest_path = gtest_path
|
|
||||||
self.cpp_lint = cpp_lint
|
self.cpp_lint = cpp_lint
|
||||||
self.cuda_lint = cuda_lint
|
self.cuda_lint = cuda_lint
|
||||||
print('Using Google Test from {}'.format(self.gtest_path))
|
|
||||||
print('Run linter on CUDA: ', self.cuda_lint)
|
print('Run linter on CUDA: ', self.cuda_lint)
|
||||||
print('Run linter on C++:', self.cpp_lint)
|
print('Run linter on C++:', self.cpp_lint)
|
||||||
if not self.cpp_lint and not self.cuda_lint:
|
if not self.cpp_lint and not self.cuda_lint:
|
||||||
@ -61,8 +58,7 @@ class ClangTidy(object):
|
|||||||
os.mkdir(self.cdb_path)
|
os.mkdir(self.cdb_path)
|
||||||
os.chdir(self.cdb_path)
|
os.chdir(self.cdb_path)
|
||||||
cmake_args = ['cmake', '..', '-DCMAKE_EXPORT_COMPILE_COMMANDS=ON',
|
cmake_args = ['cmake', '..', '-DCMAKE_EXPORT_COMPILE_COMMANDS=ON',
|
||||||
'-DGOOGLE_TEST=ON', '-DGTEST_ROOT={}'.format(
|
'-DGOOGLE_TEST=ON', '-DUSE_DMLC_GTEST=ON']
|
||||||
self.gtest_path)]
|
|
||||||
if self.cuda_lint:
|
if self.cuda_lint:
|
||||||
cmake_args.extend(['-DUSE_CUDA=ON', '-DUSE_NCCL=ON'])
|
cmake_args.extend(['-DUSE_CUDA=ON', '-DUSE_NCCL=ON'])
|
||||||
subprocess.run(cmake_args)
|
subprocess.run(cmake_args)
|
||||||
@ -108,6 +104,8 @@ class ClangTidy(object):
|
|||||||
'--cuda-gpu-arch=sm_' + capability)
|
'--cuda-gpu-arch=sm_' + capability)
|
||||||
elif components[i].find('--std=c++11') != -1:
|
elif components[i].find('--std=c++11') != -1:
|
||||||
converted_components.append('-std=c++11')
|
converted_components.append('-std=c++11')
|
||||||
|
elif components[i].startswith('-isystem='):
|
||||||
|
converted_components.extend(components[i].split('='))
|
||||||
else:
|
else:
|
||||||
converted_components.append(components[i])
|
converted_components.append(components[i])
|
||||||
|
|
||||||
@ -156,6 +154,7 @@ class ClangTidy(object):
|
|||||||
return False
|
return False
|
||||||
isxgb = path.find('rabit') == -1
|
isxgb = path.find('rabit') == -1
|
||||||
isxgb = isxgb and path.find('dmlc-core') == -1
|
isxgb = isxgb and path.find('dmlc-core') == -1
|
||||||
|
isxgb = isxgb and (not path.startswith(self.cdb_path))
|
||||||
if isxgb:
|
if isxgb:
|
||||||
return True
|
return True
|
||||||
|
|
||||||
@ -235,13 +234,11 @@ if __name__ == '__main__':
|
|||||||
parser = argparse.ArgumentParser(description='Run clang-tidy.')
|
parser = argparse.ArgumentParser(description='Run clang-tidy.')
|
||||||
parser.add_argument('--cpp', type=int, default=1)
|
parser.add_argument('--cpp', type=int, default=1)
|
||||||
parser.add_argument('--cuda', type=int, default=1)
|
parser.add_argument('--cuda', type=int, default=1)
|
||||||
parser.add_argument('--gtest-path', required=True,
|
|
||||||
help='Full path of Google Test library directory')
|
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
|
|
||||||
test_tidy()
|
test_tidy()
|
||||||
|
|
||||||
with ClangTidy(args.gtest_path, args.cpp, args.cuda) as linter:
|
with ClangTidy(args.cpp, args.cuda) as linter:
|
||||||
passed = linter.run()
|
passed = linter.run()
|
||||||
if not passed:
|
if not passed:
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|||||||
@ -31,7 +31,7 @@ TEST(EnumClassParam, Basic) {
|
|||||||
{"foo", "frog"}, {"bar", "10"}
|
{"foo", "frog"}, {"bar", "10"}
|
||||||
};
|
};
|
||||||
// try initializing
|
// try initializing
|
||||||
param.Init(kwargs);
|
param.Init(kwargs); // NOLINT(clang-analyzer-core.UndefinedBinaryOperatorResult)
|
||||||
ASSERT_EQ(param.foo, Foo::kFrog);
|
ASSERT_EQ(param.foo, Foo::kFrog);
|
||||||
ASSERT_EQ(param.bar, 10);
|
ASSERT_EQ(param.bar, 10);
|
||||||
|
|
||||||
|
|||||||
@ -33,20 +33,11 @@ fi
|
|||||||
|
|
||||||
if [ ${TASK} == "cmake_test" ]; then
|
if [ ${TASK} == "cmake_test" ]; then
|
||||||
set -e
|
set -e
|
||||||
# Build gtest via cmake
|
|
||||||
wget -nc https://github.com/google/googletest/archive/release-1.7.0.zip
|
|
||||||
unzip -n release-1.7.0.zip
|
|
||||||
mv googletest-release-1.7.0 gtest && cd gtest
|
|
||||||
CC=gcc-7 CXX=g++-7 cmake . && make
|
|
||||||
mkdir lib && mv libgtest.a lib
|
|
||||||
cd ..
|
|
||||||
rm -rf release-1.7.0.zip
|
|
||||||
|
|
||||||
# Build/test
|
# Build/test
|
||||||
rm -rf build
|
rm -rf build
|
||||||
mkdir build && cd build
|
mkdir build && cd build
|
||||||
PLUGINS="-DPLUGIN_LZ4=ON -DPLUGIN_DENSE_PARSER=ON"
|
PLUGINS="-DPLUGIN_LZ4=ON -DPLUGIN_DENSE_PARSER=ON"
|
||||||
CC=gcc-7 CXX=g++-7 cmake .. -DGOOGLE_TEST=ON -DGTEST_ROOT=$PWD/../gtest/ ${PLUGINS}
|
CC=gcc-7 CXX=g++-7 cmake .. -DGOOGLE_TEST=ON -DUSE_DMLC_GTEST=ON ${PLUGINS}
|
||||||
make
|
make
|
||||||
./testxgboost
|
./testxgboost
|
||||||
cd ..
|
cd ..
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user