Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Combine build file of adolc and tests; Add code coverage #79

Merged
merged 23 commits into from
Nov 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
84 changes: 38 additions & 46 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,52 +1,44 @@
# This starter workflow is for a CMake project running on multiple platforms. There is a different starter workflow if you just want a single platform.
# See: https://github.com/actions/starter-workflows/blob/main/ci/cmake-single-platform.yml
name: Build Multi-Platform
on:
push:
branches: [ "master" ]
pull_request:
branches: [ "master" ]

jobs:
build:
runs-on: ${{ matrix.os }}

strategy:
# Set fail-fast to false to ensure that feedback is delivered for all matrix combinations. Consider changing this to true when your workflow is stable.
fail-fast: false
name: Build
on:
push:
branches: [ "master" ]
pull_request:
branches: [ "master" ]

# Set up a matrix to run the following 3 configurations:
# 1. <Windows, Release, latest MSVC compiler toolchain on the default runner image, default generator>
# 2. <Linux, Release, latest GCC compiler toolchain on the default runner image, default generator>
# 3. <Linux, Release, latest Clang compiler toolchain on the default runner image, default generator>
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
build_type: [Release]
c_compiler: [gcc, clang]
cpp_compiler: [g++, clang++]
jobs:
build:
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
build_type: [Release, Debug]
c_compiler: [gcc, clang]
cpp_compiler: [g++, clang++]
steps:
- uses: actions/checkout@v4

- name: Set reusable strings
# Turn repeated input strings (such as the build output directory) into step outputs. These step outputs can be used throughout the workflow file.
id: strings
shell: bash
run: |
echo "build-output-dir=${{ github.workspace }}/build" >> "$GITHUB_OUTPUT"

steps:
- uses: actions/checkout@v4
- name: Configure and build ADOL-C
run: >
cmake -B ${{ steps.strings.outputs.build-output-dir }}
-DCMAKE_CXX_COMPILER=${{ matrix.cpp_compiler }}
-DCMAKE_C_COMPILER=${{ matrix.c_compiler }}
-DCMAKE_BUILD_TYPE=${{ matrix.build_type }}
-S ${{ github.workspace }}

- name: Set reusable strings
# Turn repeated input strings (such as the build output directory) into step outputs. These step outputs can be used throughout the workflow file.
id: strings
shell: bash
run: |
echo "build-output-dir=${{ github.workspace }}/build" >> "$GITHUB_OUTPUT"
- name: Build
# Build your program with the given configuration. Note that --config is needed because the default Windows generator is a multi-config generator (Visual Studio generator).
run: cmake --build ${{ steps.strings.outputs.build-output-dir }} --config ${{ matrix.build_type }}



- name: Configure CMake
# Configure CMake in a 'build' subdirectory. `CMAKE_BUILD_TYPE` is only required if you are using a single-configuration generator such as make.
# See https://cmake.org/cmake/help/latest/variable/CMAKE_BUILD_TYPE.html?highlight=cmake_build_type
run: >
cmake -B ${{ steps.strings.outputs.build-output-dir }}
-DCMAKE_CXX_COMPILER=${{ matrix.cpp_compiler }}
-DCMAKE_C_COMPILER=${{ matrix.c_compiler }}
-DCMAKE_BUILD_TYPE=${{ matrix.build_type }}
-S ${{ github.workspace }}

- name: Build
# Build your program with the given configuration. Note that --config is needed because the default Windows generator is a multi-config generator (Visual Studio generator).
run: cmake --build ${{ steps.strings.outputs.build-output-dir }} --config ${{ matrix.build_type }}



58 changes: 58 additions & 0 deletions .github/workflows/coverage.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
on: ["push", "pull_request"]

name: Test Coverage

jobs:
run-coverage:
name: Build
runs-on: ubuntu-latest
steps:

- uses: actions/checkout@v4

- name: Install lcov
run: |
sudo apt-get update
sudo apt-get install -y lcov

- name: Install Boost
shell: bash
run: |
sudo apt-get install libboost-all-dev

- name: Configure and build ADOL-C
run: |
mkdir build
cd build
cmake \
-DCMAKE_CXX_COMPILER=g++ \
-DCMAKE_C_COMPILER=gcc \
-DCMAKE_BUILD_TYPE=Debug \
-DBUILD_TESTS_WITH_COV=ON \
-S .. \
-B .
cmake --build .

- name: Run Tests
run: |
set +e # otherwise the coverage report fails if ctest finds errors
ctest --test-dir build/
exit 0

# Capture coverage data
- name: Generate coverage report
run: |
cd build
lcov --capture --directory . --output-file coverage.info
lcov --remove coverage.info '/usr/*' 'boost/*' 'c++11/*' --output-file coverage.info
lcov --list coverage.info

# Upload coverage report to Codecov
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v4
with:
files: build/coverage.info
token: ${{ secrets.CODECOV_TOKEN }}
flags: unittests
name: code-coverage-report

73 changes: 41 additions & 32 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,36 +7,45 @@ on:
branches: [ "master" ]

jobs:
run-tests:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Configure CMake ADOL-C
run: >
cmake
-DCMAKE_CXX_COMPILER=g++
-DCMAKE_C_COMPILER=gcc
-DCMAKE_BUILD_TYPE=Release
-S ${{ github.workspace }}
-DCMAKE_INSTALL_PREFIX=${{ github.workspace }}

- name: Build ADOLC
run: |
make
make install
run-tests:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
build_type: [Release, Debug]
c_compiler: [gcc, clang]
cpp_compiler: [g++, clang++]

steps:
- uses: actions/checkout@v4

- name: Install Boost
shell: bash
run: |
sudo apt-get install libboost-all-dev

- name: Set reusable strings
# Turn repeated input strings (such as the build output directory) into step outputs. These step outputs can be used throughout the workflow file.
id: strings
shell: bash
run: |
echo "build-output-dir=${{ github.workspace }}/build" >> "$GITHUB_OUTPUT"

- name: Configure and build ADOL-C
run: >
cmake -B ${{ steps.strings.outputs.build-output-dir }}
-DCMAKE_CXX_COMPILER=${{ matrix.cpp_compiler }}
-DCMAKE_C_COMPILER=${{ matrix.c_compiler }}
-DCMAKE_BUILD_TYPE=${{ matrix.build_type }}
-DBUILD_TESTS=ON \
-S ${{ github.workspace }}

- name: Build ADOL-C
# Build your program with the given configuration. Note that --config is needed because the default Windows generator is a multi-config generator (Visual Studio generator).
run: cmake --build ${{ steps.strings.outputs.build-output-dir }} --config ${{ matrix.build_type }}

- name: Install Boost
shell: bash
run: |
sudo apt-get install libboost-all-dev

- name: Build and Run Boost-Test
shell: bash
run: |
cd ADOL-C/boost-test
mkdir build && cd build
cmake ../ -DADOLC_BASE=${{ github.workspace }}
make
./boost-test-adolc

- name: Run Tests
run: ctest --test-dir ${{ steps.strings.outputs.build-output-dir }} --output-on-failure



48 changes: 3 additions & 45 deletions ADOL-C/boost-test/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,15 +1,7 @@
cmake_minimum_required(VERSION 3.0)
project(boost-test-adolc CXX)

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")

## BOOST
set(3RDPARTY_BOOST_DIR "" CACHE PATH "The directory where BOOST library is installed")

if(3RDPARTY_BOOST_DIR)
set(BOOST_ROOT ${3RDPARTY_BOOST_DIR})
# set(BOOST_INCLUDEDIR ${3RDPARTY_BOOST_DIR}/include)
# set(BOOST_LIBRARYDIR ${3RDPARTY_BOOST_DIR}/lib)
endif()

set(BOOST_MIN_VERSION "1.59.0")
Expand All @@ -19,41 +11,8 @@ find_package(Boost ${BOOST_MIN_VERSION} REQUIRED COMPONENTS unit_test_framework

if(NOT Boost_FOUND)
message(FATAL_ERROR "Fatal error: Boost (version >= 1.69.0) required.")
else()
message(STATUS "Setting up BOOST")
message(STATUS "Boost include: " ${Boost_INCLUDE_DIRS})
message(STATUS "Boost library: " ${Boost_LIBRARY_DIRS})
endif()

## ADOL-C
set (ADOLC_BASE "" CACHE PATH "The directory where ADOL-C is installed")
if(ADOLC_BASE)
message(STATUS "Setting up ADOL-C")

unset(ADOLC_INCLUDE_DIR CACHE)
find_path(ADOLC_INCLUDE_DIR NAMES adolc/adolc.h PATHS ${ADOLC_BASE}/include NO_DEFAULT_PATH)
if(NOT ADOLC_INCLUDE_DIR)
message(FATAL_ERROR "Fatal error: ADOL-C include directory not found, check if ADOLC_BASE path is correct")
endif()

unset(ADOLC_LIBRARY CACHE)
find_library(ADOLC_LIBRARY NAMES adolc PATHS ${ADOLC_BASE}/lib64 ${ADOLC_BASE}/lib NO_DEFAULT_PATH)
if(NOT ADOLC_LIBRARY)
message(FATAL_ERROR "Fatal error: ADOL-C library not found, check if ADOLC_BASE path is correct")
endif()

unset(ADOLC_LIBRARY_DIR CACHE)
get_filename_component(ADOLC_LIBRARY_DIR ${ADOLC_LIBRARY} DIRECTORY CACHE)

message(STATUS "ADOL-C include: " ${ADOLC_INCLUDE_DIR})
message(STATUS "ADOL-C library: " ${ADOLC_LIBRARY_DIR})
else()
message(FATAL_ERROR "ADOLC_BASE directory has to be specified")
endif()

include_directories(${Boost_INCLUDE_DIRS} ${ADOLC_INCLUDE_DIR})
link_directories(${Boost_LIBRARY_DIRS} ${ADOLC_LIBRARY_DIR})

set(SOURCE_FILES
adouble.cpp
main.cpp
Expand All @@ -68,9 +27,8 @@ set(SOURCE_FILES
traceFixedPointScalarTests.cpp
)
add_executable(boost-test-adolc ${SOURCE_FILES})

target_link_libraries(boost-test-adolc
PRIVATE
${ADOLC_LIBRARY}
target_include_directories(boost-test-adolc PRIVATE "${ADOLC_INCLUDE_DIR}")
target_link_libraries(boost-test-adolc PRIVATE
adolc
Boost::system
Boost::unit_test_framework)
22 changes: 0 additions & 22 deletions ADOL-C/boost-test/README.md

This file was deleted.

31 changes: 28 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@ project(adol-c
DESCRIPTION "A Package for Automatic Differentiation of Algorithms Written in C/C++"
HOMEPAGE_URL "https://github.com/coin-or/ADOL-C")

set(CMAKE_C_FLAGS_RELEASE "-O3")
set(CMAKE_CXX_FLAGS_RELEASE "-O3")

add_library(adolc SHARED)
add_library(adolc::adolc ALIAS adolc)

Expand Down Expand Up @@ -75,6 +72,34 @@ if(BUILD_INTERFACE)
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/adolc)
endif()

# build the tests
# ------------------------------------
option(BUILD_TESTS OFF)
if(BUILD_TESTS)
set(ADOLC_INCLUDE_DIR "${CMAKE_BINARY_DIR}/ADOL-C/include")
add_subdirectory(ADOL-C/boost-test)

enable_testing()
add_test(NAME boost-test-adolc
COMMAND boost-test-adolc)
endif()

# build the adolc and tests with coverage
# ------------------------------------
option(BUILD_TESTS_WITH_COV OFF)
if(BUILD_TESTS_WITH_COV)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g --coverage")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -g --coverage")

set(ADOLC_INCLUDE_DIR "${CMAKE_BINARY_DIR}/ADOL-C/include")
add_subdirectory(ADOL-C/boost-test)

enable_testing()
add_test(NAME boost-test-adolc
COMMAND boost-test-adolc)
endif()


# export the targets
# ------------------

Expand Down
12 changes: 9 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,14 @@ Please refer to the file `MSMSVisualStudio/v14/Readme_VC++.txt` for building the

## Unit tests

ADOL-C provides more than 400 unit tests to verify its basic functionality.
For more information on how to run the tests, please check the `README` file in `ADOL-C/boost-test` directory.
ADOL-C provides more than 500 unit tests to verify its basic functionality including both traceless and trace-based adouble variants. The tests are based on BOOST (version >= 1.59.0). Building the ADOL-C teste requires the BOOST libraries `unit_test_framework` and `system`. In case you are compiling BOOST on your own, be sure to add the flags `--with-test` and `--with-system` to activate the corresponding modules.
You can build and run them as follows:
`mkdir build && cd build`
`cmake -S .. -B . -DCMAKE_BUILD_TYPE=Tests`
`make`
`./ADOL-C/boost-test/boost-test-adolc`

Enjoy this new version!
Cmake will search for the system installed version of BOOST. If the minimum required version is not satisfied, please enter the path where an appropriate BOOST version is installed in `3RDPARTY_BOOST_DIR` in the `CMakelists.txt` inside the `boost-test` folder. Notice that ADOL-C has to be compiled with the same version of BOOST as used here. When using a different BOOST version than the one provided by the operating system, ADOL-C can be configured with `--with-boost` flag before compiling the ADOL-C sources.


Enjoy this new version!
Loading