Skip to content

Commit

Permalink
build: Fix coverage generation.
Browse files Browse the repository at this point in the history
The essential change is that `tool_exec` should be in the `target` config, not
`exec`.  This alone makes the instrumentation propagate to this attribute!
  • Loading branch information
jaqx0r committed Apr 8, 2024
1 parent 38fd873 commit 5f83991
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 20 deletions.
16 changes: 13 additions & 3 deletions testsuite/dejagnu.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ def _dejagnu_lib_impl(ctx):
return [
DefaultInfo(runfiles = runfiles),
DejaGNULibraryInfo(),
coverage_common.instrumented_files_info(
ctx,
source_attributes = ["srcs"],
dependency_attributes = ["deps"],
),
]

dejagnu_library = rule(
Expand Down Expand Up @@ -62,7 +67,12 @@ def _dejagnu_test_impl(ctx):
])

test_env = {}
if ctx.configuration.coverage_enabled:
# Are this rule's sources or any of the sources for its direct dependencies
# in deps instrumented?
if (ctx.configuration.coverage_enabled and
(ctx.coverage_instrumented() or
any([ctx.coverage_instrumented(dep) for dep in ctx.attr.deps])
or ctx.coverage_instrumented(ctx.attr.tool_exec))):
# Bazel’s coverage runner
# (https://github.com/bazelbuild/bazel/blob/6.4.0/tools/test/collect_coverage.sh)
# needs a binary called “lcov_merge.” Its location is passed in the
Expand Down Expand Up @@ -107,7 +117,7 @@ dejagnu_test = rule(
attrs = {
"srcs": attr.label_list(
allow_files = [".exp"],
doc = "Main test file for dejagnu runtests.",
doc = "Test sources for dejagnu runtests.",
),
"deps": attr.label_list(providers = [DejaGNULibraryInfo]),
"data": attr.label_list(
Expand All @@ -116,7 +126,7 @@ dejagnu_test = rule(
"tool_exec": attr.label(
executable = True,
doc = "Binary target under test.",
cfg = "exec",
cfg = "target",
allow_single_file = True,
),
"_runtest": attr.label(
Expand Down
26 changes: 9 additions & 17 deletions testsuite/dejagnu_runtest_wrapper.tpl
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
#/usr/bin/env bash

set -x

# --- begin runfiles.bash initialization v3 ---
# Copy-pasted from the Bazel Bash runfiles library v3.
set -uo pipefail; set +e; f=bazel_tools/tools/bash/runfiles/runfiles.bash
Expand All @@ -13,32 +11,26 @@ source "${RUNFILES_DIR:-/dev/null}/$f" 2>/dev/null || \
{ echo>&2 "ERROR: cannot find $f"; exit 1; }; f=; set -e
# --- end runfiles.bash initialization v3 ---


echo -n "pwd: "
pwd

runtest=$(rlocation "{runtest}")

export DEJAGNULIBS="{libdir}"


$runtest --version

ls -laLR

set -e

cat >site.exp <<EOF
set tool {tool}
set srcdir {srcdir}
set objdir `pwd`
info exists env(COVERAGE_DIR)
EOF

cat site.exp

$runtest --global_init site.exp --status --all --debug -v -v --tool {tool} --srcdir {srcdir} --outdir $TEST_UNDECLARED_OUTPUTS_DIR


echo "post run directory"
ls -laLR
$runtest \
--global_init site.exp \
--status \
--all \
--debug \
-v -v \
--tool {tool} \
--srcdir {srcdir} \
--outdir $TEST_UNDECLARED_OUTPUTS_DIR \

0 comments on commit 5f83991

Please sign in to comment.