Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
120 changes: 116 additions & 4 deletions MODULE.bazel.lock

Large diffs are not rendered by default.

86 changes: 86 additions & 0 deletions rules/coverage/view.bzl
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
# Copyright lowRISC contributors (OpenTitan project).
# Licensed under the Apache License, Version 2.0, see LICENSE for details.
# SPDX-License-Identifier: Apache-2.0

load(
"//rules/opentitan:providers.bzl",
"SiliconBinaryInfo",
"get_binary_files",
)

_TEST_SCRIPT = """\
{generate_coverage_view} \
--elf="{elf_file}" \
--kind="{kind}" \
--output="$COVERAGE_OUTPUT_FILE" \
--temp-dir="$TEST_UNDECLARED_OUTPUTS_DIR" \
"""

def _coverage_view_test(ctx):
# This suffix is required to distinguish the coverage view LCOV files from
# the coverage data of other tests.
if not ctx.label.name.endswith("_coverage_view"):
fail("The name of the coverage_view_test rule must end with '_coverage_view'")

elf_label = ctx.attr.elf
groups = elf_label.output_groups

if "silicon_creator_elf" in groups:
elf_list = groups["silicon_creator_elf"].to_list()
elif "elf" in ctx.attr.elf.output_groups:
elf_list = groups["elf"].to_list()
else:
elf_list = get_binary_files(elf_label, field = "elf", providers = [SiliconBinaryInfo])

if len(elf_list) != 1:
fail("The target must have exactly one elf file.")
elf = elf_list[0]

runfiles = ctx.runfiles()

# Coverage view tests are only applicable when coverage is enabled.
if ctx.var.get("ot_coverage_enabled", "false") == "true":
runfiles = runfiles.merge(ctx.runfiles(files = [elf]))
runfiles = runfiles.merge(ctx.attr._generate_coverage_view[DefaultInfo].default_runfiles)

script_content = _TEST_SCRIPT.format(
generate_coverage_view = ctx.executable._generate_coverage_view.short_path,
elf_file = elf.short_path,
kind = ctx.attr.kind,
)
else:
script_content = ""

script = ctx.actions.declare_file(ctx.label.name + ".sh")
ctx.actions.write(
output = script,
content = script_content,
is_executable = True,
)

return DefaultInfo(
executable = script,
runfiles = runfiles,
)

coverage_view_test = rule(
implementation = _coverage_view_test,
attrs = {
"elf": attr.label(
allow_files = True,
doc = "ELF file to extract coverage view",
),
"kind": attr.string(
doc = "Kind of given elf file",
default = "ibex",
values = ["ibex", "otbn"],
),
"_generate_coverage_view": attr.label(
default = "//util/coverage/collect_cc_coverage:generate_coverage_view",
executable = True,
cfg = "exec",
),
},
fragments = ["cpp"],
test = True,
)
51 changes: 51 additions & 0 deletions sw/device/silicon_creator/rom_ext/sival/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ load("@rules_pkg//pkg:tar.bzl", "pkg_tar")
load("//rules:const.bzl", "CONST", "hex")
load("//rules:manifest.bzl", "manifest")
load("//rules:signing.bzl", "offline_presigning_artifacts", "offline_signature_attach")
load("//rules/coverage:view.bzl", "coverage_view_test")
load("//rules/opentitan:defs.bzl", "opentitan_binary")
load(
"//sw/device/silicon_creator/rom_ext:defs.bzl",
Expand Down Expand Up @@ -105,6 +106,56 @@ manifest(d = {
for slot in SLOTS
]

ROM_EXT_CONFIGS = {
"dice_x509_xmodem": {
"dice": "dice_x509",
"deps": ["//sw/device/silicon_creator/lib/rescue:rescue_xmodem"],
},
"dice_cwt_spidfu": {
"dice": "dice_cwt",
"deps": ["//sw/device/silicon_creator/lib/rescue:rescue_spidfu"],
},
"dice_x509_usbdfu": {
"dice": "dice_x509",
"deps": ["//sw/device/silicon_creator/lib/rescue:rescue_usbdfu"],
},
}

[
opentitan_binary(
name = "rom_ext_prod_{}".format(name),
exec_env = [
"//hw/top_earlgrey:silicon_creator",
],
extra_bazel_features = [
"minsize",
"use_lld",
],
linker_script = "//sw/device/silicon_creator/rom_ext:ld_slot_virtual",
linkopts = [
"$(location //sw/device/silicon_creator/rom_ext:rom_ext_{})".format(config["dice"]),
"$(location //sw/device/lib/crt)",
],
deps = [
# The sival_owner C library is excluded from the real ROM_EXT,
# as chips maintain their ownership configuration in flash.
"//sw/device/lib/crt",
"//sw/device/silicon_creator/lib:manifest_def",
"//sw/device/silicon_creator/rom_ext:rom_ext_{}".format(config["dice"]),
"//sw/device/silicon_creator/rom_ext/imm_section:main_section_{}_slot_virtual".format(config["dice"]),
] + config["deps"],
)
for name, config in ROM_EXT_CONFIGS.items()
]

[
coverage_view_test(
name = "rom_ext_prod_{}_coverage_view".format(name),
elf = "rom_ext_prod_{}".format(name),
)
for name in ROM_EXT_CONFIGS.keys()
]

offline_presigning_artifacts(
name = "presigning",
testonly = True,
Expand Down
7 changes: 7 additions & 0 deletions sw/otbn/crypto/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
# SPDX-License-Identifier: Apache-2.0

load("//rules:otbn.bzl", "otbn_binary", "otbn_library")
load("//rules/coverage:view.bzl", "coverage_view_test")

package(default_visibility = ["//visibility:public"])

Expand All @@ -19,6 +20,12 @@ otbn_binary(
],
)

coverage_view_test(
name = "boot_coverage_view",
elf = ":boot",
kind = "otbn",
)

otbn_library(
name = "ed25519",
srcs = [
Expand Down
67 changes: 65 additions & 2 deletions third_party/rust/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions third_party/rust/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ path = "empty_file_to_appease_cargo.rs"
#
# Do not modify the Cargo.lock file via cargo.
[dependencies]
addr2line = "0.24.2"
aes = "0.8.2"
anyhow = { version = "1.0.57", features=["backtrace"] }
arrayvec = { version = "0.7", features=["serde"] }
Expand Down
14 changes: 14 additions & 0 deletions util/coverage/collect_cc_coverage/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,17 @@ rust_binary(
"@crate_index//:clap",
],
)

rust_binary(
name = "generate_coverage_view",
srcs = ["generate_coverage_view.rs"],
deps = [
":coverage_lib",
"@crate_index//:addr2line",
"@crate_index//:anyhow",
"@crate_index//:clap",
"@crate_index//:object",
"@crate_index//:serde",
"@crate_index//:serde_json",
],
)
Loading
Loading