Commit 1c7892a7 authored by Karol Latecki's avatar Karol Latecki Committed by Tomasz Zawadzki
Browse files

autorun_post: normalize paths in coverage files



Test runs might (and in most cases probably are) executed
on a different entity than the one generating aggregated
coverage report. Modify all paths in the coverage files
so that they match current workspace.

Also remove some similar old replace operation which was
done before running genhtml, and which was searching
for "./repo" in lcov's SF path. We haven't been using
"repo" in checkout path for quite a long time now, so
it's very out dated.

Change-Id: Iba9074d764b0c47e6cbe63a2d8375a78b0ed1074
Signed-off-by: default avatarKarol Latecki <karol.latecki@nutanix.com>
Reviewed-on: https://review.spdk.io/c/spdk/spdk/+/25675


Reviewed-by: default avatarMichal Berger <michal.berger@nutanix.com>
Reviewed-by: default avatarKonrad Sztyber <ksztyber@nvidia.com>
Reviewed-by: default avatarTomasz Zawadzki <tomasz@tzawadzki.com>
Tested-by: default avatarTomasz Zawadzki <tomasz@tzawadzki.com>
parent 1c112191
Loading
Loading
Loading
Loading
+15 −10
Original line number Diff line number Diff line
@@ -59,6 +59,7 @@ def generateCoverageReport(output_dir, repo_dir):
    covfiles = [os.path.abspath(p) for p in glob.glob(coveragePath, recursive=True)]
    for f in covfiles:
        print(f)
        normalizePaths(f, repo_dir)
    if len(covfiles) == 0:
        return
    lcov_opts = [
@@ -67,7 +68,7 @@ def generateCoverageReport(output_dir, repo_dir):
        '--rc', 'genhtml_branch_coverage=1',
        '--rc', 'genhtml_function_coverage=1',
        '--rc', 'genhtml_legend=1',
        '--rc', 'geninfo_all_blocks=1',
        '--rc', 'geninfo_all_blocks=1'
    ]

    # HACK: This is a workaround for some odd CI assumptions
@@ -84,15 +85,6 @@ def generateCoverageReport(output_dir, repo_dir):
        print(e)
        return

    with open(cov_total, 'r') as cov_total_file:
        file_contents = cov_total_file.readlines()

    replacement = "SF:" + repo_dir
    os.remove(cov_total)
    with open(cov_total, 'w+') as file:
        for Line in file_contents:
            Line = re.sub("^SF:.*/repo", replacement, Line)
            file.write(Line + '\n')
    try:
        subprocess.check_call(genhtml)
    except subprocess.CalledProcessError as e:
@@ -102,6 +94,19 @@ def generateCoverageReport(output_dir, repo_dir):
        os.remove(f)


def normalizePaths(cov_file, repo_dir):
    with open(cov_file, 'r') as fh:
        replaced = None
        file_contents = fh.read()
        replacement = "SF:" + os.path.abspath(repo_dir) + "/"
        if not re.search(rf'{replacement}', file_contents):
            replaced = re.sub(r'SF:/[^/]+/spdk/', replacement, file_contents)

    if replaced:
        with open(cov_file, 'w') as fh:
            fh.write(replaced)


def collectOne(output_dir, dir_name):
    dirs = glob.glob(os.path.join(output_dir, '*', dir_name))
    dirs.sort()