Skip to content
/ memcov Public

Collect simple coverage information in memory.

Notifications You must be signed in to change notification settings

ganler/memcov

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Quickly allow you to monitor/control in-memory coverage for your C++-implemented-Python-binded libraries.

[C++] Add Coverage Tracing During Library Compilation

INCLUDE(FetchContent)
FetchContent_Declare(
    memcov
    GIT_REPOSITORY https://github.com/ganler/memcov.git
)

FetchContent_GetProperties(memcov)

if(NOT memcov_POPULATED)
    FetchContent_Populate(memcov)
    ADD_SUBDIRECTORY(${memcov_SOURCE_DIR} ${memcov_BINARY_DIR})
endif()

# Allow coverage tracing to specific files!
set_source_files_properties(
    ${CMAKE_CURRENT_SOURCE_DIR}/path/to/what.cpp 
    PROPERTIES COMPILE_OPTIONS
    -fsanitize-coverage=edge,trace-pc-guard)

# Include it to your target!
TARGET_LINK_LIBRARIES(YOUR_TARGET PRIVATE memcov)

[Python] Add Interface to Operate/Monitor Coverage

import ctypes

_LIB = ctypes.CDLL('/PATH/TO/YOUR_LIB.so')

# calling `reset`, the coverage will not be ZERO (but very small, e.g., 6).
reset = _LIB.mcov_reset

push = _LIB.mcov_push_coverage
pop = _LIB.mcov_pop_coverage

get_total = _LIB.mcov_get_total
get_now = _LIB.mcov_get_now

set_now = _LIB.mcov_set_now

_char_array = ctypes.c_char * get_total()


def get_hitmap():
    hitmap_buffer = bytearray(get_total())
    _LIB.mcov_copy_hitmap(_char_array.from_buffer(hitmap_buffer))
    return hitmap_buffer


def set_hitmap(data):
    assert len(data) == get_total()
    _LIB.mcov_set_hitmap(_char_array.from_buffer(data))

About

Collect simple coverage information in memory.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages