Make clickhouse-test to calculate coverage on a per-test basis

This commit is contained in:
Alexey Milovidov 2023-10-29 17:43:01 +01:00
parent 8e0f487387
commit 4288cb3b78

View File

@ -1175,6 +1175,12 @@ class TestCase:
description_full += result.description description_full += result.description
if BuildFlags.SANITIZE_COVERAGE in args.build_flags: if BuildFlags.SANITIZE_COVERAGE in args.build_flags:
clickhouse_execute(
args,
f"INSERT INTO system.coverage SELECT '{self.case}', coverage()",
retry_error_codes=True,
)
coverage = clickhouse_execute( coverage = clickhouse_execute(
args, args,
f"SELECT length(coverage())", f"SELECT length(coverage())",
@ -1241,6 +1247,14 @@ class TestCase:
+ pattern + pattern
) )
# We want to calculate per-test code coverage. That's why we reset it before each test.
if BuildFlags.SANITIZE_COVERAGE in args.build_flags:
clickhouse_execute(
args,
"SYSTEM RESET COVERAGE",
retry_error_codes=True,
)
command = pattern.format(**params) command = pattern.format(**params)
proc = Popen(command, shell=True, env=os.environ) proc = Popen(command, shell=True, env=os.environ)
@ -2349,6 +2363,18 @@ def main(args):
print(f"Failed to create databases for tests: {e}") print(f"Failed to create databases for tests: {e}")
server_died.set() server_died.set()
if BuildFlags.SANITIZE_COVERAGE in args.build_flags:
clickhouse_execute(
args,
"""
CREATE TABLE IF NOT EXISTS system.coverage
(
test_name String,
coverage Array(UInt64)
) ENGINE = MergeTree ORDER BY test_name;
""",
)
total_tests_run = 0 total_tests_run = 0
for suite in sorted(os.listdir(base_dir), key=suite_key_func): for suite in sorted(os.listdir(base_dir), key=suite_key_func):