Skip to content

Commit

Permalink
Some code coverage fixes
Browse files Browse the repository at this point in the history
This is still broken but it's already better
  • Loading branch information
lpereira committed Aug 6, 2024
1 parent 8f27530 commit 7bc2167
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 9 deletions.
1 change: 0 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ include(CheckFunctionExists)
include(CheckSymbolExists)
include(CheckIncludeFile)
include(CheckIncludeFiles)
include(CodeCoverage)
include(EnableCFlag)
include(FindPkgConfig)
include(TrySanitizer)
Expand Down
11 changes: 7 additions & 4 deletions src/bin/testrunner/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,15 @@ target_link_libraries(testrunner
)

if (${CMAKE_BUILD_TYPE} MATCHES "Coverage")
include(CodeCoverage)

if (Python3_Interpreter_FOUND)
setup_target_for_coverage(generate-coverage
"${Python3_EXECUTABLE} ${CMAKE_SOURCE_DIR}/src/scripts/testsuite.py -v ${CMAKE_BINARY_DIR}"
coverage
setup_target_for_coverage_lcov(
NAME generate-coverage
EXECUTABLE ${Python3_EXECUTABLE} ${CMAKE_SOURCE_DIR}/src/scripts/testsuite.py -v ${CMAKE_BINARY_DIR}
DEPENDENCIES testrunner
BASE_DIRECTORY "${CMAKE_SOURCE_DIR}"
)
add_dependencies(generate-coverage testrunner)
message(STATUS "Python found; generate-coverage target enabled")
else ()
message(STATUS "Python not found; coverage report disabled")
Expand Down
2 changes: 1 addition & 1 deletion src/cmake/CodeCoverage.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ include(CMakeParseArguments)
option(CODE_COVERAGE_VERBOSE "Verbose information" FALSE)

get_property(GENERATOR_IS_MULTI_CONFIG GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG)
if(CMAKE_BUILD_TYPE STREQUAL "Debug" OR GENERATOR_IS_MULTI_CONFIG)
if(CMAKE_BUILD_TYPE STREQUAL "Debug" OR GENERATOR_IS_MULTI_CONFIG OR CMAKE_BUILD_TYPE STREQUAL "Coverage")

# Check prereqs
find_program( GCOV_PATH gcov )
Expand Down
13 changes: 10 additions & 3 deletions src/scripts/testsuite.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,13 @@
BUILD_DIR = arg
sys.argv.remove(arg)

HOME_DIR = "."
with open(f"{BUILD_DIR}/CMakeCache.txt", "r") as cache:
for line in cache.readlines():
if line.startswith("CMAKE_HOME_DIRECTORY:INTERNAL"):
_, HOME_DIR = line.strip().split("=")
break

if os.getenv('REQUESTS_DEBUG'):
logging.basicConfig()
logging.getLogger().setLevel(logging.DEBUG)
Expand Down Expand Up @@ -62,7 +69,7 @@ def setUp(self, env=None, harness='testrunner'):
self.files_to_remove = []
for file_to_copy in self.files_to_copy[harness]:
base = os.path.basename(file_to_copy)
shutil.copyfile(file_to_copy, base)
shutil.copyfile(f'{HOME_DIR}/{file_to_copy}', base)
self.files_to_remove.append(base)

open('htpasswd', 'w').close()
Expand Down Expand Up @@ -1041,14 +1048,14 @@ def run_test(self, contents):

@staticmethod
def wrap(name):
with open(os.path.join("fuzz", "regression", name), "rb") as f:
with open(os.path.join(HOME_DIR, "fuzz", "regression", name), "rb") as f:
contents = str(f.read(), "latin-1")
def run_test_wrapped(self):
return self.run_test(contents)
return run_test_wrapped

def only_request_fuzzer_regression():
for path in os.listdir("fuzz/regression"):
for path in os.listdir(f"{HOME_DIR}/fuzz/regression"):
if not "request_fuzzer" in path:
continue
if path.startswith(("clusterfuzz-", "crash-")):
Expand Down

0 comments on commit 7bc2167

Please sign in to comment.