Skip to content

Commit

Permalink
Add coverage build (#560)
Browse files Browse the repository at this point in the history
Summary:
tl;dr -- our coverage can be better.

Wanted to check out codecov - this is what came of it. Code coverage reports are enabled for the org - add them in CI.
- Codecov is capable of generating super cool reports like flashlight/flashlight#560 (comment) in PR comments, but I've disabled those for now
- View coverage details like https://codecov.io/gh/flashlight/flashlight/tree/17c14502a3c99550e69973e9d0cb1e9374e9ed3e/flashlight
- codecov checks appear in CI which will yell at people if they are landing untested code

Pull Request resolved: flashlight/flashlight#560

Test Plan:
CI

PR comments [disabled for now] like
<img width="1054" alt="Screen Shot 2021-04-22 at 5 55 33 PM" src="https://user-images.githubusercontent.com/7871817/115796168-fa053800-a396-11eb-8d91-8f8b87693b8f.png">

cool visualizations of what we have tests for like
![screencapture-codecov-io-gh-flashlight-flashlight-src-17c14502a3c99550e69973e9d0cb1e9374e9ed3e-flashlight-fl-autograd-Functions-cpp-2021-04-22-17_53_25](https://user-images.githubusercontent.com/7871817/115796181-fe315580-a396-11eb-9dda-fafad249f9de.png)

Reviewed By: tlikhomanenko

Differential Revision: D27954344

Pulled By: jacobkahn

fbshipit-source-id: 30cff2176c97ffdf499fe2bbc41a2feba2b1cb69
  • Loading branch information
jacobkahn authored and facebook-github-bot committed Apr 22, 2021
1 parent 3852550 commit e3c0f0b
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 1 deletion.
19 changes: 19 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,22 @@ eggs/
.installed.cfg
*.egg
wheels/

# Coverage
*.info

# Precompiled Headers
*.gch
*.pch

# Compiled Object files
*.slo
*.lo
*.o
*.obj

# Compiled Static libraries
*.lai
*.la
*.a
*.lib
11 changes: 10 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,15 @@ include(CMakeDependentOption)
# ----------------------------- Setup -----------------------------
find_program(CCACHE_PROGRAM ccache)
if(CCACHE_PROGRAM)
set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE "${CCACHE_PROGRAM}")
set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE "${CCACHE_PROGRAM}")
endif()

set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake")
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

option(FL_CODE_COVERAGE "Enable coverage reporting" OFF)

# Default directories for installation
set(FL_INSTALL_INC_DIR "include" CACHE PATH "Install path for headers")
set(FL_INSTALL_INC_DIR_HEADER_LOC ${FL_INSTALL_INC_DIR}/flashlight)
Expand Down Expand Up @@ -136,6 +138,9 @@ if (FL_BUILD_LIBRARIES OR (FL_BUILD_CORE AND FL_BUILD_TESTS))
endif ()

setup_install_headers(${FL_LIB_DIR} ${FL_INSTALL_INC_DIR_HEADER_LOC})
if (FL_CODE_COVERAGE)
add_coverage_to_target(TARGET fl-libraries)
endif()
endif() # if FL_BUILD_LIBRARIES

# --------------------------- flashlight ---------------------------
Expand All @@ -157,6 +162,10 @@ if (FL_BUILD_CORE)
target_link_libraries(flashlight PUBLIC fl-libraries)
endif()

if (FL_CODE_COVERAGE)
add_coverage_to_target(TARGET flashlight)
endif()

# ------------------------ Global External Dependencies ------------------------
# ArrayFire
find_package(ArrayFire REQUIRED)
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
[![Docker Image Build Status](https://img.shields.io/github/workflow/status/flashlight/flashlight/Publish%20Docker%20images?label=docker%20image%20build)](https://hub.docker.com/r/flml/flashlight/tags)
[![Join the chat at https://gitter.im/flashlight-ml/community](https://img.shields.io/gitter/room/flashlight-ml/community)](https://gitter.im/flashlight-ml/community?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)

[![codecov](https://codecov.io/gh/flashlight/flashlight/branch/master/graph/badge.svg?token=rBp4AilMc0)](https://codecov.io/gh/flashlight/flashlight)

[![Docker Image for CUDA backend](https://img.shields.io/docker/image-size/flml/flashlight/cuda-latest?label=docker%20%28cuda%29&logo=docker)](https://hub.docker.com/r/flml/flashlight/tags?page=1&ordering=last_updated&name=cuda-latest)
[![Docker Image for CPU backend](https://img.shields.io/docker/image-size/flml/flashlight/cpu-latest?label=docker%20%28cpu%29&logo=docker)](https://hub.docker.com/r/flml/flashlight/tags?page=1&ordering=last_updated&name=cpu-latest)

Expand Down
24 changes: 24 additions & 0 deletions cmake/InternalUtils.cmake
Original file line number Diff line number Diff line change
@@ -1,3 +1,27 @@
function(add_coverage_to_target)
set(oneValueArgs TARGET)
cmake_parse_arguments(add_coverage_to_target "${options}" "${oneValueArgs}"
"${multiValueArgs}" ${ARGN})

if(CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang")
# Add required flags (GCC & LLVM/Clang)
target_compile_options(${add_coverage_to_target_TARGET} PUBLIC
-O0 # TODO: reconcile this with CMake modes for something cleaner
-g
$<$<COMPILE_LANGUAGE:CXX>:--coverage>
)
if(CMAKE_VERSION VERSION_GREATER_EQUAL 3.13)
target_link_options(${add_coverage_to_target_TARGET}
PUBLIC
$<$<COMPILE_LANGUAGE:CXX>:--coverage>)
else()
target_link_libraries(${add_coverage_to_target_TARGET}
PUBLIC
--coverage)
endif()
endif()
endfunction()

function(setup_install_targets)
set(multiValueArgs INSTALL_TARGETS INSTALL_HEADERS)
cmake_parse_arguments(setup_install_targets "${options}" "${oneValueArgs}"
Expand Down
1 change: 1 addition & 0 deletions codecov.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
comment: false

0 comments on commit e3c0f0b

Please sign in to comment.