Skip to content

Commit

Permalink
Merge pull request #271 from andreasfertig/libCppTests
Browse files Browse the repository at this point in the history
Added libc++ option to `runTest.py` for test coverage with libc++.
  • Loading branch information
andreasfertig authored Nov 1, 2019
2 parents 10359a0 + 42b2ce4 commit 0963154
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 21 deletions.
11 changes: 10 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,15 @@ jobs:
- docker pull andreasfertig/cppinsights-builder
env: COMPILER='g++-8' LLVM_CONFIG=/usr/bin/llvm-config-9 COVERAGE='Yes' STATIC='No' DEBUG='No' TIDY='No' USE_DOCKER='Yes'

- os: linux
name: "GCC 8 / LLVM 9 @ Ubuntu Code Coverage (libc++)"
sudo: required
services:
- docker
before_install:
- docker pull andreasfertig/cppinsights-builder
env: COMPILER='g++-8' LLVM_CONFIG=/usr/bin/llvm-config-9 COVERAGE='Yes' STATIC='No' DEBUG='No' TIDY='No' USE_DOCKER='Yes' USE_LIBCPP='Yes'

- stage: "Deploy Docker"
install: true
before_script: true
Expand Down Expand Up @@ -196,7 +205,7 @@ before_script:
- cd build
- |
if [[ "${USE_DOCKER}" == "Yes" ]]; then
docker run -v ${TRAVIS_BUILD_DIR}:/home/builder --rm andreasfertig/cppinsights-builder /bin/bash -c "cd /home/builder/build && cmake -G Ninja -DINSIGHTS_STATIC=${STATIC} -DDEBUG=${DEBUG} -DINSIGHTS_COVERAGE=${COVERAGE} .."
docker run -v ${TRAVIS_BUILD_DIR}:/home/builder --rm andreasfertig/cppinsights-builder /bin/bash -c "cd /home/builder/build && cmake -G Ninja -DINSIGHTS_STATIC=${STATIC} -DDEBUG=${DEBUG} -DINSIGHTS_COVERAGE=${COVERAGE} -DINSIGHTS_USE_LIBCPP=${USE_LIBCPP} .."
elif [[ "${CFORMAT}" == "Yes" ]]; then
echo "Nothing to do here for the clang-format check run."
else
Expand Down
26 changes: 16 additions & 10 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,13 @@ include(CMakePrintHelpers)

# TODO: enable those options on Windows once tested
if(NOT WIN32)
option(DEBUG "Enable debug" Off)
option(INSIGHTS_STRIP "Strip insight after build" On )
option(INSIGHTS_TIDY "Run clang-tidy" Off)
option(INSIGHTS_IWYU "Run include-what-you-use" Off)
option(INSIGHTS_STATIC "Use static linking" Off)
option(INSIGHTS_COVERAGE "Enable code coverage" Off)
option(DEBUG "Enable debug" Off)
option(INSIGHTS_STRIP "Strip insight after build" On )
option(INSIGHTS_TIDY "Run clang-tidy" Off)
option(INSIGHTS_IWYU "Run include-what-you-use" Off)
option(INSIGHTS_STATIC "Use static linking" Off)
option(INSIGHTS_COVERAGE "Enable code coverage" Off)
option(INSIGHTS_USE_LIBCPP "Enable code coverage" Off)
endif()

set(INSIGHTS_LLVM_CONFIG "llvm-config" CACHE STRING "LLVM config executable to use")
Expand Down Expand Up @@ -499,9 +500,14 @@ if (NOT WIN32)
set(TEST_FAILURE_IS_OK "--failure-is-ok")
endif()

set(TEST_USE_LIBCPP "")
if(INSIGHTS_USE_LIBCPP)
set(TEST_USE_LIBCPP "--use-libcpp")
endif()

# add a target to generate run tests
add_custom_target(tests
COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/tests/runTest.py --insights ${CMAKE_CURRENT_BINARY_DIR}/insights --cxx ${CMAKE_CXX_COMPILER} ${TEST_FAILURE_IS_OK}
COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/tests/runTest.py --insights ${CMAKE_CURRENT_BINARY_DIR}/insights --cxx ${CMAKE_CXX_COMPILER} ${TEST_FAILURE_IS_OK} ${TEST_USE_LIBCPP}
COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/tests/testSTDIN.sh ${CMAKE_CURRENT_BINARY_DIR}/insights
DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/insights ${CMAKE_CURRENT_SOURCE_DIR}/tests/runTest.py
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/tests
Expand All @@ -519,23 +525,23 @@ if (NOT WIN32)

# run tests in a docker container
add_custom_target(docker-tests
COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/scripts/docker-shell.sh ${CMAKE_CURRENT_BINARY_DIR}/docker_build compile "-DINSIGHTS_STATIC=${INSIGHTS_STATIC} -DINSIGHTS_COVERAGE=${INSIGHTS_COVERAGE} -DDEBUG=${DEBUG}" tests
COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/scripts/docker-shell.sh ${CMAKE_CURRENT_BINARY_DIR}/docker_build compile "-DINSIGHTS_STATIC=${INSIGHTS_STATIC} -DINSIGHTS_COVERAGE=${INSIGHTS_COVERAGE} -DDEBUG=${DEBUG} -DINSIGHTS_USE_LIBCPP=${INSIGHTS_USE_LIBCPP}" tests
DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/tests/runTest.py ${CMAKE_CURRENT_SOURCE_DIR}/scripts/docker-shell.sh
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/scripts
COMMENT "Running tests in docker" VERBATIM
)

# run code coverage in docker container
add_custom_target(docker-coverage
COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/scripts/docker-shell.sh ${CMAKE_CURRENT_BINARY_DIR}/docker_build compile "-DINSIGHTS_STATIC=${INSIGHTS_STATIC} -DINSIGHTS_COVERAGE=Yes -DDEBUG=${DEBUG}" coverage-html
COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/scripts/docker-shell.sh ${CMAKE_CURRENT_BINARY_DIR}/docker_build compile "-DINSIGHTS_STATIC=${INSIGHTS_STATIC} -DINSIGHTS_COVERAGE=Yes -DDEBUG=${DEBUG} -DINSIGHTS_USE_LIBCPP=${INSIGHTS_USE_LIBCPP}" coverage-html
DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/tests/runTest.py ${CMAKE_CURRENT_SOURCE_DIR}/scripts/docker-shell.sh
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/scripts
COMMENT "Running tests in docker" VERBATIM
)

# run tests in a docker container
add_custom_target(docker-build
COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/scripts/docker-shell.sh ${CMAKE_CURRENT_BINARY_DIR}/docker_build compile "-DINSIGHTS_STATIC=${INSIGHTS_STATIC} -DINSIGHTS_COVERAGE=${INSIGHTS_COVERAGE} -DDEBUG=${DEBUG}"
COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/scripts/docker-shell.sh ${CMAKE_CURRENT_BINARY_DIR}/docker_build compile "-DINSIGHTS_STATIC=${INSIGHTS_STATIC} -DINSIGHTS_COVERAGE=${INSIGHTS_COVERAGE} -DDEBUG=${DEBUG} -DINSIGHTS_USE_LIBCPP=${INSIGHTS_USE_LIBCPP}"
DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/tests/runTest.py ${CMAKE_CURRENT_SOURCE_DIR}/scripts/docker-shell.sh
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/scripts
COMMENT "Bulding insights in docker" VERBATIM
Expand Down
13 changes: 7 additions & 6 deletions Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -134,12 +134,13 @@ Then build clang as you normally do.
There are a couple of options which can be enable with [cmake](https://cmake.org):
| Option | Description | Default |
|-------------------|:---------------------------| --------|
| INSIGHTS_STRIP | Strip insight after build | ON |
| INSIGHTS_STATIC | Use static linking | OFF |
| INSIGHTS_COVERAGE | Enable code coverage | OFF |
| DEBUG | Enable debug | OFF |
| Option | Description | Default |
|---------------------|:---------------------------| --------|
| INSIGHTS_STRIP | Strip insight after build | ON |
| INSIGHTS_STATIC | Use static linking | OFF |
| INSIGHTS_COVERAGE | Enable code coverage | OFF |
| INSIGHTS_USE_LIBCPP | Use libc++ for tests | OFF |
| DEBUG | Enable debug | OFF |
### Use it with [Cevelop](https://www.cevelop.com)
Expand Down
15 changes: 11 additions & 4 deletions tests/runTest.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ def main():
parser.add_argument('--failure-is-ok', help='Failing tests are ok', default=False, action='store_true')
parser.add_argument('--update-tests', help='Update failing tests', default=False, action='store_true')
parser.add_argument('--std', help='C++ Standard to used', default='c++17')
parser.add_argument('--use-libcpp', help='Use libst++', default=False, action='store_true')
parser.add_argument('args', nargs=argparse.REMAINDER)
args = vars(parser.parse_args())

Expand Down Expand Up @@ -128,10 +129,16 @@ def main():
missingExpected += 1
continue

if '' == insightsOpts:
cmd = [insightsPath, f, '--', cppStd, '-m64']
else:
cmd = [insightsPath, f, insightsOpts, '--', cppStd, '-m64']
cmd = [insightsPath, f]

if args['use_libcpp']:
cmd.append('-use-libc++')


if '' != insightsOpts:
cmd.append(insightsOpts)

cmd.extend(['--', cppStd, '-m64'])

begin = datetime.datetime.now()
p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
Expand Down

0 comments on commit 0963154

Please sign in to comment.