Unverified Commit 211ef787 authored by Nikita Titov's avatar Nikita Titov Committed by GitHub
Browse files

[ci] run cpp tests at CI (#4166)



* run cpp tests at CI

* Update docs/Installation-Guide.rst
Co-authored-by: default avatarJames Lamb <jaylamb20@gmail.com>
Co-authored-by: default avatarJames Lamb <jaylamb20@gmail.com>
parent 3fd9b275
......@@ -13,6 +13,14 @@ if [[ "${TASK}" == "r-package" ]]; then
exit 0
fi
if [[ "$TASK" == "cpp-tests" ]]; then
mkdir $BUILD_DIRECTORY/build && cd $BUILD_DIRECTORY/build
cmake -DBUILD_CPP_TEST=ON -DUSE_OPENMP=OFF ..
make testlightgbm -j4 || exit -1
./../testlightgbm || exit -1
exit 0
fi
conda create -q -y -n $CONDA_ENV python=$PYTHON_VERSION
source activate $CONDA_ENV
......@@ -71,9 +79,9 @@ fi
if [[ $TASK == "if-else" ]]; then
conda install -q -y -n $CONDA_ENV numpy
mkdir $BUILD_DIRECTORY/build && cd $BUILD_DIRECTORY/build && cmake .. && make lightgbm -j4 || exit -1
cd $BUILD_DIRECTORY/tests/cpp_test && ../../lightgbm config=train.conf convert_model_language=cpp convert_model=../../src/boosting/gbdt_prediction.cpp && ../../lightgbm config=predict.conf output_result=origin.pred || exit -1
cd $BUILD_DIRECTORY/tests/cpp_tests && ../../lightgbm config=train.conf convert_model_language=cpp convert_model=../../src/boosting/gbdt_prediction.cpp && ../../lightgbm config=predict.conf output_result=origin.pred || exit -1
cd $BUILD_DIRECTORY/build && make lightgbm -j4 || exit -1
cd $BUILD_DIRECTORY/tests/cpp_test && ../../lightgbm config=predict.conf output_result=ifelse.pred && python test.py || exit -1
cd $BUILD_DIRECTORY/tests/cpp_tests && ../../lightgbm config=predict.conf output_result=ifelse.pred && python test.py || exit -1
exit 0
fi
......
......@@ -16,6 +16,14 @@ if ($env:TASK -eq "r-package") {
Exit 0
}
if ($env:TASK -eq "cpp-tests") {
mkdir $env:BUILD_SOURCESDIRECTORY/build; cd $env:BUILD_SOURCESDIRECTORY/build
cmake -DBUILD_CPP_TEST=ON -DUSE_OPENMP=OFF -A x64 ..
cmake --build . --target testlightgbm --config Debug ; Check-Output $?
Start-Process -FilePath "./../Debug/testlightgbm.exe" -NoNewWindow -Wait ; Check-Output $?
Exit 0
}
# setup for Python
conda init powershell
conda activate
......
......@@ -20,7 +20,7 @@ include/ @guolinke @chivee @btrotta @shiyu1994
src/ @guolinke @chivee @btrotta @shiyu1994
CMakeLists.txt @guolinke @chivee @Laurae2 @jameslamb @wxchan @henry0312 @StrikerRUS @huanzhang12 @btrotta @shiyu1994
tests/c_api_test/ @guolinke @chivee @btrotta @shiyu1994
tests/cpp_test/ @guolinke @chivee @btrotta @shiyu1994
tests/cpp_tests/ @guolinke @chivee @btrotta @shiyu1994
tests/data/ @guolinke @chivee @btrotta @shiyu1994
windows/ @guolinke @chivee @btrotta @StrikerRUS @shiyu1994
......
......@@ -51,6 +51,8 @@ jobs:
METHOD: source
swig:
TASK: swig
cpp_tests:
TASK: cpp-tests
steps:
- script: |
echo "##vso[task.setvariable variable=BUILD_DIRECTORY]$BUILD_SOURCESDIRECTORY"
......@@ -222,6 +224,8 @@ jobs:
TASK: bdist
swig:
TASK: swig
cpp_tests:
TASK: cpp-tests
steps:
- script: |
echo "##vso[task.setvariable variable=BUILD_DIRECTORY]$BUILD_SOURCESDIRECTORY"
......@@ -258,6 +262,8 @@ jobs:
TASK: bdist
swig:
TASK: swig
cpp_tests:
TASK: cpp-tests
steps:
- powershell: |
Write-Host "##vso[task.prependpath]$env:CONDA\Scripts"
......
......@@ -478,7 +478,21 @@ if(BUILD_CPP_TEST)
FetchContent_MakeAvailable(googletest)
add_library(GTest::GTest ALIAS gtest)
endif()
file(GLOB CPP_TEST_SOURCES tests/cpp_test/*.cpp)
file(GLOB CPP_TEST_SOURCES tests/cpp_tests/*.cpp)
if(MSVC)
set(
CompilerFlags
CMAKE_CXX_FLAGS
CMAKE_CXX_FLAGS_DEBUG
CMAKE_CXX_FLAGS_RELEASE
CMAKE_C_FLAGS
CMAKE_C_FLAGS_DEBUG
CMAKE_C_FLAGS_RELEASE
)
foreach(CompilerFlag ${CompilerFlags})
string(REPLACE "/MD" "/MT" ${CompilerFlag} "${${CompilerFlag}}")
endforeach()
endif(MSVC)
add_executable(testlightgbm ${CPP_TEST_SOURCES} ${SOURCES})
target_link_libraries(testlightgbm PRIVATE GTest::GTest)
endif()
......
......@@ -66,7 +66,7 @@ Code Structure
+---------------------+------------------------------------------------------------------------------------------------------------------------------------+
Documents API
~~~~~~~~~~~~~
-------------
Refer to `docs README <./README.rst>`__.
......@@ -75,6 +75,12 @@ C API
Refer to `C API <./C-API.rst>`__ or the comments in `c\_api.h <https://github.com/microsoft/LightGBM/blob/master/include/LightGBM/c_api.h>`__ file, from which the documentation is generated.
Tests
-----
C++ unit tests are located in the ``./tests/cpp_tests`` folder and written with the help of Google Test framework.
To run tests locally first refer to the `Installation Guide <./Installation-Guide.rst#build-c-unit-tests>`__ for how to build tests and then simply run compiled executable file.
High Level Language Package
---------------------------
......
......@@ -693,7 +693,6 @@ The ``.jar`` file will be in ``LightGBM/build`` folder and the ``.dll`` files wi
It is recommended to use **VS Build Tools (Visual Studio)** since it has better multithreading efficiency in **Windows** for many-core systems
(see `Question 4 <./FAQ.rst#i-am-using-windows-should-i-use-visual-studio-or-mingw-for-compiling-lightgbm>`__ and `Question 8 <./FAQ.rst#cpu-usage-is-low-like-10-in-windows-when-using-lightgbm-on-very-large-datasets-with-many-core-systems>`__).
Also, you may want to read `gcc Tips <./gcc-Tips.rst>`__.
Linux
......@@ -779,6 +778,103 @@ gcc
Also, you may want to read `gcc Tips <./gcc-Tips.rst>`__.
Build C++ Unit Tests
~~~~~~~~~~~~~~~~~~~~
Windows
^^^^^^^
On Windows, C++ unit tests of LightGBM can be built using **CMake** and **VS Build Tools**.
1. Install `Git for Windows`_, `CMake`_ (3.8 or higher) and `VS Build Tools`_ (**VS Build Tools** is not needed if **Visual Studio** (2015 or newer) is already installed).
2. Run the following commands:
.. code::
git clone --recursive https://github.com/microsoft/LightGBM
cd LightGBM
mkdir build
cd build
cmake -A x64 -DBUILD_CPP_TEST=ON -DUSE_OPENMP=OFF ..
cmake --build . --target testlightgbm --config Debug
The ``.exe`` file will be in ``LightGBM/Debug`` folder.
Linux
^^^^^
On Linux a C++ unit tests of LightGBM can be built using **CMake** and **gcc** or **Clang**.
1. Install `CMake`_.
2. Run the following commands:
.. code::
git clone --recursive https://github.com/microsoft/LightGBM
cd LightGBM
mkdir build
cd build
cmake -DBUILD_CPP_TEST=ON -DUSE_OPENMP=OFF ..
make testlightgbm -j4
**Note**: glibc >= 2.14 is required.
macOS
^^^^^
On macOS a C++ unit tests of LightGBM can be built using **CMake** and **Apple Clang** or **gcc**.
Apple Clang
***********
Only **Apple Clang** version 8.1 or higher is supported.
1. Install `CMake`_ (3.16 or higher):
.. code::
brew install cmake
2. Run the following commands:
.. code::
git clone --recursive https://github.com/microsoft/LightGBM
cd LightGBM
mkdir build
cd build
cmake -DBUILD_CPP_TEST=ON -DUSE_OPENMP=OFF ..
make testlightgbm -j4
gcc
***
1. Install `CMake`_ (3.2 or higher):
.. code::
brew install cmake
2. Install **gcc**:
.. code::
brew install gcc
3. Run the following commands:
.. code::
git clone --recursive https://github.com/microsoft/LightGBM
cd LightGBM
export CXX=g++-7 CC=gcc-7 # replace "7" with version of gcc installed on your machine
mkdir build
cd build
cmake -DBUILD_CPP_TEST=ON -DUSE_OPENMP=OFF ..
make testlightgbm -j4
.. |download artifacts| image:: ./_static/images/artifacts-not-available.svg
:target: https://lightgbm.readthedocs.io/en/latest/Installation-Guide.html
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment