mirror of
https://github.com/amd/blis.git
synced 2026-04-19 23:28:52 +00:00
CMake: CMake is updated for Code Coverage
CMakelists.txt is Updated to generate code coverage report in html format just by configuring cmake with -DENABLE_COVERAGE=ON. Code supports only on linux with gcc compiler cmake .. -DENABLE_COVERAGE=ON AMD-Internal: [CPUPL-2748] Change-Id: I9b36b6cc3f1f97b53e1c4ee62948a017418e3d41
This commit is contained in:
@@ -279,6 +279,9 @@ endif()
|
||||
set(ENABLE_SANDBOX "" CACHE STRING "Enable a separate sandbox implementation of gemm.")
|
||||
# Do not let ENABLE_SANDBOX appear on cmake-gui since the functionality is not yet implemented.
|
||||
mark_as_advanced(ENABLE_SANDBOX)
|
||||
if(NOT WIN32)
|
||||
option(ENABLE_COVERAGE "Enable Code Coverage using gcov(only GCC/Debug build)" OFF)
|
||||
endif()
|
||||
|
||||
#------------------------------------
|
||||
# Check memkind
|
||||
@@ -650,6 +653,28 @@ if(WIN32)
|
||||
message(" Export APIs with lowercase.")
|
||||
endif()
|
||||
endif()
|
||||
if(NOT WIN32)
|
||||
cmake_print_variables(ENABLE_COVERAGE)
|
||||
if(ENABLE_COVERAGE)
|
||||
if(NOT (${CMAKE_C_COMPILER_ID} MATCHES "GNU"))
|
||||
message(WARNING "Coverage is only supported for GNU/Linux GCC Debug build")
|
||||
message(" Code Coverage is disabled.")
|
||||
set(ENABLE_COVERAGE OFF)
|
||||
endif()
|
||||
if(NOT(ENABLE_DEBUG STREQUAL "noopt"))
|
||||
message(WARNING "Coverage is only supported for debug builds, but ENABLE_DEBUG=noopt was set.\
|
||||
Disabling optimizations to generate the code coverage report.")
|
||||
set(ENABLE_DEBUG "noopt")
|
||||
set(DEBUG_TYPE ${ENABLE_DEBUG})
|
||||
endif()
|
||||
endif()
|
||||
if(ENABLE_COVERAGE)
|
||||
message(" Code Coverage is enabled.")
|
||||
else()
|
||||
cmake_print_variables(ENABLE_COVERAGE)
|
||||
message(" Code Coverage is disabled.")
|
||||
endif()
|
||||
endif()
|
||||
|
||||
# Initialize threading model, using the corresponding cache variable.
|
||||
set(THREADING_MODEL ${ENABLE_THREADING})
|
||||
@@ -821,6 +846,13 @@ if(ENABLE_MEMKIND STREQUAL "yes")
|
||||
list(APPEND LDFLAGS ${LIBMEMKIND})
|
||||
endif()
|
||||
|
||||
#--------------------------------------------
|
||||
# Code-coverage flags
|
||||
#--------------------------------------------
|
||||
if(ENABLE_COVERAGE AND (NOT WIN32))
|
||||
set(CMAKE_C_FLAGS "-fprofile-arcs -ftest-coverage")
|
||||
endif()
|
||||
|
||||
#--------------------------------------------
|
||||
# Configuration-agnostic flags
|
||||
#--------------------------------------------
|
||||
@@ -1095,17 +1127,44 @@ if(ENABLE_BLAS)
|
||||
add_subdirectory(blastest EXCLUDE_FROM_ALL)
|
||||
endif()
|
||||
|
||||
if(ENABLE_BLAS AND WIN32 AND BUILD_SHARED_LIBS)
|
||||
set(DETAILED_BLATEST_MESSAGE "Details: Level2 and level3 API tests define a custom version of xerbla_() to test the error codes. \
|
||||
On Linux and on Windows/static versions of BLIS library, the custom xerbla_() gets called inside the library\
|
||||
due to the linking process and all tests work. On Windows/shared version of the library, symbol resolution\
|
||||
happens at load-time so the blis implementation of xerbla_() gets called instead of the custom one. \
|
||||
That causes errors when the tests are run which are independent of the BLIS library. \
|
||||
Please use static builds only on Windows.")
|
||||
endif()
|
||||
|
||||
# Add generic testing target `test`.
|
||||
set(available_testsuites checkblis)
|
||||
if(ENABLE_BLAS)
|
||||
list(APPEND available_testsuites checkblas)
|
||||
endif()
|
||||
add_custom_target(test DEPENDS ${available_testsuites})
|
||||
|
||||
if(WIN32 AND BUILD_SHARED_LIBS)
|
||||
if(ENABLE_BLAS)
|
||||
set(TEST_WARNING "Target `test` depends only on target `checkblis` because `checkblas` target is not available on Windows for shared builds of BLIS. ")
|
||||
endif()
|
||||
else()
|
||||
if(ENABLE_BLAS)
|
||||
list(APPEND available_testsuites checkblas)
|
||||
endif()
|
||||
endif()
|
||||
add_custom_target(test
|
||||
DEPENDS ${available_testsuites}
|
||||
COMMENT "Running target `test`. ${TEST_WARNING} ${DETAILED_BLATEST_MESSAGE}")
|
||||
|
||||
# Add generic testing target `check`.
|
||||
set(available_testsuites checkblis-fast)
|
||||
if(ENABLE_BLAS)
|
||||
list(APPEND available_testsuites checkblas)
|
||||
if(WIN32 AND BUILD_SHARED_LIBS)
|
||||
if(ENABLE_BLAS)
|
||||
set(CHECK_WARNING "Target `check` depends only on target `checkblis-fast` because `checkblas` target is not available on Windows for shared builds of BLIS. ")
|
||||
endif()
|
||||
else()
|
||||
if(ENABLE_BLAS)
|
||||
list(APPEND available_testsuites checkblas)
|
||||
endif()
|
||||
endif()
|
||||
add_custom_target(check
|
||||
DEPENDS ${available_testsuites}
|
||||
|
||||
@@ -279,6 +279,11 @@ def main():
|
||||
print( " " )
|
||||
print( " Export APIs with uppercase" )
|
||||
print( " " )
|
||||
print( " -DENABLE_COVERAGE=ON or -DENABLE_COVERAGE=OFF" )
|
||||
print( " " )
|
||||
print( " Enable (disabled by default) generation of code coverage" )
|
||||
print( " report in html format. Code coverage support is provided" )
|
||||
print( " only on LINUX with GCC compiler." )
|
||||
print( " " )
|
||||
print( " Additional CMake Variables:" )
|
||||
print( " " )
|
||||
|
||||
@@ -159,6 +159,7 @@ The BLIS CMake system aims to be combatible with the current `make` system. For
|
||||
| `testsuite` | Same as `testblis`. |
|
||||
| `testblas` | Run the BLAS test drivers with default parameters (runs for a few seconds). |
|
||||
| `checkbliscpp` | Run the BLIS C++ tests (runs for a few seconds). |
|
||||
| `coverage` | Run the code-coverage that generates html report (runs for 5-10 minutes). |
|
||||
|
||||
**_NOTE:_**
|
||||
Using those targets sets the environment appropriately, so copying the input files and/or the DLL in case of Windows builds is not required.
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
##Copyright (C) 2022 - 2023, Advanced Micro Devices, Inc. All rights reserved.##
|
||||
##Copyright (C) 2023 - 2024, Advanced Micro Devices, Inc. All rights reserved.##
|
||||
|
||||
# Comments:
|
||||
# - DIST_PATH is assumed to not exist if BLIS_INSTALL_PATH is given.
|
||||
@@ -23,6 +23,10 @@ file(GLOB testsuite_sources LIST_DIRECTORIES false ${CMAKE_CURRENT_SOURCE_DIR}/s
|
||||
# get-user-cflags-for() is not cluttered up with include paths needed only
|
||||
# while building BLIS.
|
||||
set(CINFLAGS ${INC_PATH})
|
||||
if((NOT WIN32) AND ENABLE_COVERAGE)
|
||||
include(coverage.cmake)
|
||||
set(LDFLAGS "${LDFLAGS} -ftest-coverage")
|
||||
endif()
|
||||
|
||||
# Create an executable using the sources above.
|
||||
add_executable(test_libblis.x ${testsuite_sources})
|
||||
|
||||
52
testsuite/coverage.cmake
Normal file
52
testsuite/coverage.cmake
Normal file
@@ -0,0 +1,52 @@
|
||||
##Copyright (C) 2024, Advanced Micro Devices, Inc. All rights reserved.##
|
||||
|
||||
# Comments:
|
||||
|
||||
find_program(LCOV NAMES lcov HINTS "/usr" PATH_SUFFIXES "bin" DOC "lcov - a graphical GCOV front-end" REQUIRED)
|
||||
find_program(GCOV NAMES $ENV{GCOV_NAME} gcov HINTS "/usr" PATH_SUFFIXES "bin" DOC "GNU gcov binary" REQUIRED)
|
||||
find_program(GENHTML NAMES genhtml HINTS "/usr" PATH_SUFFIXES "bin" DOC "genhtml - Generate HTML view from LCOV coverage data files" REQUIRED)
|
||||
|
||||
if(NOT (LCOV AND GCOV) )
|
||||
message(FATAL_ERROR "locv or gcov not found! Aborting...")
|
||||
endif()
|
||||
|
||||
set(LCOV_FILTERS "'/usr/*';'/*/_deps/*';'/*/boost/*'")
|
||||
set(LCOV_FLAGS "--rc;lcov_branch_coverage=1")
|
||||
set(GENHTML_FLAGS "--branch-coverage;--rc;genhtml_med_limit=80;--rc;genhtml_hi_limit=95;--legend")
|
||||
|
||||
message( STATUS "Code Coverage Module (LCOV)" )
|
||||
|
||||
add_custom_target( coverage-clean
|
||||
COMMAND ${CMAKE_COMMAND} -E rm -rf coverage/
|
||||
COMMAND find . -name *.gcda -exec rm -v {} \;
|
||||
WORKING_DIRECTORY ${PROJECT_BINARY_DIR}
|
||||
COMMENT "Cleaning coverage related files"
|
||||
VERBATIM
|
||||
)
|
||||
|
||||
add_custom_target( coverage-run
|
||||
COMMAND ${CMAKE_MAKE_PROGRAM} coverage-clean
|
||||
DEPENDS test_libblis.x
|
||||
COMMAND test_libblis.x -g ${CMAKE_CURRENT_SOURCE_DIR}/input.general -o ${CMAKE_CURRENT_SOURCE_DIR}/input.operations > ${CMAKE_CURRENT_BINARY_DIR}/output.testsuite
|
||||
COMMENT "Code Coverage takes some time : Running test_libblis.x with output redirected to ${CMAKE_CURRENT_BINARY_DIR}/output.testsuite"
|
||||
WORKING_DIRECTORY ${PROJECT_BINARY_DIR}
|
||||
VERBATIM
|
||||
)
|
||||
|
||||
add_custom_target( coverage-report
|
||||
COMMAND ${CMAKE_MAKE_PROGRAM} coverage-run
|
||||
COMMAND ${CMAKE_COMMAND} -E make_directory coverage/
|
||||
COMMAND ${LCOV} ${LCOV_FLAGS} -d .. -c -o coverage/coverage.info --gcov-tool ${GCOV}
|
||||
COMMAND ${LCOV} ${LCOV_FLAGS} --remove coverage/coverage.info --gcov-tool ${GCOV} -o coverage/coverage_filtered.info ${LCOV_FILTERS}
|
||||
COMMAND ${GENHTML} ${GENHTML_FLAGS} coverage/coverage_filtered.info --output coverage/html --title "AOCL-BLAS Code Coverage Report"
|
||||
COMMENT "Building Code Coverage Report (LCOV)"
|
||||
WORKING_DIRECTORY ${PROJECT_BINARY_DIR}
|
||||
VERBATIM
|
||||
)
|
||||
|
||||
# Alias (only Makefile/Linux)
|
||||
add_custom_target( coverage
|
||||
DEPENDS coverage-report
|
||||
WORKING_DIRECTORY ${PROJECT_BINARY_DIR}
|
||||
VERBATIM
|
||||
)
|
||||
Reference in New Issue
Block a user