Initial support in clickhouse-test

This commit is contained in:
Alexey Milovidov 2023-10-29 17:21:45 +01:00
parent 56de2333f9
commit 8e0f487387
2 changed files with 22 additions and 1 deletions

View File

@ -71,7 +71,13 @@ option (SANITIZE_COVERAGE "Instrumentation for code coverage with custom callbac
if (SANITIZE_COVERAGE)
message (INFORMATION "Enabled instrumentation for code coverage")
add_definitions(-DSANITIZE_COVERAGE=1)
# We set this define for whole build to indicate that at least some parts are compiled with coverage.
# And to expose it in system.build_options.
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DSANITIZE_COVERAGE=1")
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DSANITIZE_COVERAGE=1")
# But the actual coverage will be enabled on per-library basis: for ClickHouse code, but not for 3rd-party.
set (COVERAGE_FLAGS "-fsanitize-coverage=trace-pc-guard")
endif()

View File

@ -1173,6 +1173,16 @@ class TestCase:
description_full += result.reason.value
description_full += result.description
if BuildFlags.SANITIZE_COVERAGE in args.build_flags:
coverage = clickhouse_execute(
args,
f"SELECT length(coverage())",
retry_error_codes=True,
).decode()
description_full += f" Coverage: {coverage}"
description_full += "\n"
if result.status == TestStatus.FAIL and self.testcase_args:
@ -1872,6 +1882,7 @@ class BuildFlags:
UNDEFINED = "ubsan"
MEMORY = "msan"
DEBUG = "debug"
SANITIZE_COVERAGE = "sanitize-coverage"
RELEASE = "release"
ORDINARY_DATABASE = "ordinary-database"
POLYMORPHIC_PARTS = "polymorphic-parts"
@ -1891,6 +1902,8 @@ def collect_build_flags(args):
result.append(BuildFlags.UNDEFINED)
elif b"-fsanitize=memory" in value:
result.append(BuildFlags.MEMORY)
elif b"-DSANITIZE_COVERAGE=1" in value:
result.append(BuildFlags.SANITIZE_COVERAGE)
value = clickhouse_execute(
args, "SELECT value FROM system.build_options WHERE name = 'BUILD_TYPE'"
@ -2072,6 +2085,8 @@ def reportCoverageFor(args, what, query, permissive=False):
return True
# This is high-level coverage on per-component basis (functions, data types, etc.)
# Don't be confused with the code coverage.
def reportCoverage(args):
clickhouse_execute(args, "SYSTEM FLUSH LOGS")