Skip to content
Closed
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
7 changes: 6 additions & 1 deletion .bazelrc
Original file line number Diff line number Diff line change
Expand Up @@ -112,13 +112,18 @@ build:ci --remote_upload_local_results=true
build:ci --disk_cache=
# Tell the 'ci' config to include 'opt'
build:ci --config=opt
# CI runs all tests including test/orfs; locally they are skipped
# by the default test --test_tag_filters=-orfs below.
test:ci --test_tag_filters=

# Setup remote cache
build --remote_cache=https://bazel.precisioninno.com
build --remote_cache_compression=true
build --remote_upload_local_results=false

# Without this, bazelisk build ... builds the bazel-orfs tests
# Locally, exclude test/orfs targets from wildcard builds and tests.
# CI overrides test_tag_filters above via test:ci --test_tag_filters=
build --build_tag_filters=-orfs
test --test_tag_filters=-orfs

try-import %workspace%/user.bazelrc
42 changes: 36 additions & 6 deletions test/orfs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,17 +97,47 @@ This is more verbose, but eliminates any concerns about what the `make` script m
[ERROR GPL-0305] RePlAce diverged during gradient descent calculation, resulting in an invalid step length (Inf or NaN). This is often caused by numerical instability or high placement density. Consider reducing placement density to potentially resolve the issue.
Error: global_place_skip_io.tcl, 12 GPL-0305

## Adding `tags = ["manual"]` and `test_kwargs = ["orfs"]` to BUILD files
## Tagging policy for `test/orfs/` BUILD files

In OpenROAD, `bazelisk build ...` should not build ORFS targets, only OpenROAD binaries.
Targets under `test/orfs/` use two different tagging strategies:

Since bazel-orfs also has build targets, builds in Bazel can build anything, not just executables, the policy in OpenROAD is to mark non-binary build targets as `tags = ["manual"]`.
- **Test targets** (`sh_test`, `eqy_test`, `test_suite`, `orfs_flow` `test_kwargs`, etc.): `tags = ["orfs"]`
- **Non-test targets** (filegroups, `orfs_run`, `orfs_flow` build targets, etc.): `tags = ["manual"]`

To hunt down missing `tags = ["manual"]` run a query like:
The `manual` tag on non-test targets prevents `bazelisk build //...` from building ORFS artifacts.

bazelisk query 'kind(".*", //test/orfs/mock-array/...) except attr(tags, "manual", //test/orfs/mock-array/...)'
The `orfs` tag on test targets works with `.bazelrc` tag filters to control when tests run:

Note that OpenROAD *does* want `bazelisk test ...` to run all tests, so test targets should be marked `tags = ["orfs"]` instead, so that `.bazelrc` can skip builds of those targets with the `build --build_tag_filters=-orfs` line.
# .bazelrc defaults (local development):
build --build_tag_filters=-orfs
test --test_tag_filters=-orfs

# CI override (--config=ci):
test:ci --test_tag_filters=

This means:
- **Locally**: `bazelisk test //...` skips test/orfs tests
- **CI**: `bazelisk test --config=ci //...` runs all tests including test/orfs

### Enforcement

The tagging policy is enforced at BUILD file loading time by `verify_orfs_tags()` from `//test/orfs:verify_tags.bzl`. Each BUILD file under `test/orfs/` calls this macro at the end of the file. Any `bazelisk` command that loads these packages (build, test, query, etc.) will fail immediately if the policy is violated.

To add a new BUILD file under `test/orfs/`, add the following at the top and bottom:

load("//test/orfs:verify_tags.bzl", "verify_orfs_tags")
...
verify_orfs_tags()

### Verifying manually

To verify that building does nothing under `test/orfs/`:

bazelisk build //test/orfs/...

This should report `0 processes` and build nothing. To verify tests are found when the filter is cleared:

bazelisk test --test_tag_filters= //test/orfs/...

## eqy tests

Expand Down
5 changes: 5 additions & 0 deletions test/orfs/asap7/BUILD
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
load("//test/orfs:verify_tags.bzl", "verify_orfs_tags")

filegroup(
name = "asap7_files",
srcs = [
Expand All @@ -7,5 +9,8 @@ filegroup(
"asap7sc7p5t_SIMPLE_RVT_TT_201020.v",
"@docker_orfs//:OpenROAD-flow-scripts/flow/platforms/asap7/verilog/stdcell/dff.v",
],
tags = ["manual"],
visibility = ["//visibility:public"],
)

verify_orfs_tags()
5 changes: 4 additions & 1 deletion test/orfs/gcd/BUILD
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
load("@bazel-orfs//:openroad.bzl", "orfs_flow")
load("@rules_shell//shell:sh_test.bzl", "sh_test")
load("//test/orfs:eqy-flow.bzl", "eqy_flow_test")
load("//test/orfs:verify_tags.bzl", "verify_orfs_tags")

package(features = ["layering_check"])

Expand Down Expand Up @@ -34,7 +35,7 @@ eqy_flow_test(
name = "gcd_eqy",
flow = "gcd",
module_top = "gcd",
tags = ["manual"],
tags = ["orfs"],
verilog_files = ["gcd.v"],
)

Expand Down Expand Up @@ -63,3 +64,5 @@ sh_test(
],
tags = ["orfs"],
)

verify_orfs_tags()
12 changes: 9 additions & 3 deletions test/orfs/mock-array/BUILD
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
load("@bazel-orfs//:openroad.bzl", "orfs_run")
load("@bazel-orfs//toolchains/scala:chisel.bzl", "chisel_binary")
load("//test/orfs:verify_tags.bzl", "verify_orfs_tags")
load("//test/orfs/asap7:asap7.bzl", "ASAP7_REMOVE_CELLS")
load(":mock-array.bzl", "config", "element", "mock_array", "verilog")

Expand Down Expand Up @@ -28,6 +29,7 @@ filegroup(
data = [
":util.tcl",
],
tags = ["manual"],
visibility = [":__subpackages__"],
)

Expand All @@ -36,6 +38,7 @@ filegroup(
srcs = [
"constraints.sdc",
],
tags = ["manual"],
visibility = [":__subpackages__"],
)

Expand All @@ -47,6 +50,7 @@ filegroup(
data = [
":util.tcl",
],
tags = ["manual"],
visibility = [":__subpackages__"],
)

Expand Down Expand Up @@ -85,10 +89,10 @@ CONFIGS = {name: config(name, rows, cols) for name, rows, cols in [

test_suite(
name = "eqy_tests",
tags = ["manual"],
tests = ["Element_eqy_{variant}".format(variant = name) for name in CONFIGS] +
tags = ["orfs"],
tests = ["Element_eqy_{variant}_tests".format(variant = name) for name in CONFIGS] +
[
"MockArray_eqy_{name}_{variant}".format(
"MockArray_eqy_{name}_{variant}_tests".format(
name = name,
variant = variant,
)
Expand Down Expand Up @@ -139,3 +143,5 @@ orfs_run(
"Element_4x4",
]
]

verify_orfs_tags()
7 changes: 5 additions & 2 deletions test/orfs/mock-array/mock-array.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ def element(name, config):
name = "Element_eqy_{variant}".format(variant = name),
flow = "Element_{variant}_base".format(variant = name),
verilog_files = [":{name}_verilog".format(name = name)],
tags = ["manual"],
tags = ["orfs"],
module_top = "Element",
)

Expand Down Expand Up @@ -307,7 +307,7 @@ def mock_array(name, config):
flow = "MockArray_{variant}".format(variant = variant),
verilog_files = [":{name}_verilog".format(name = name)],
other_verilog_files = [":Element_eqy_{name}_final_verilog".format(name = name)],
tags = ["manual"],
tags = ["orfs"],
module_top = "MockArray",
)

Expand Down Expand Up @@ -351,6 +351,7 @@ def mock_array(name, config):
),
],
output_group = POWER_STAGE_STEM[stage] + ".v",
tags = ["manual"],
)

for stage in POWER_STAGES:
Expand Down Expand Up @@ -535,6 +536,7 @@ def mock_array(name, config):
stage = stage,
),
],
tags = ["orfs"],
)

for power_test in ELEMENT_POWER_TESTS:
Expand Down Expand Up @@ -594,4 +596,5 @@ def mock_array(name, config):
stage = stage,
),
],
tags = ["orfs"],
)
13 changes: 9 additions & 4 deletions test/orfs/ram_8x7/BUILD
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
load("@bazel-orfs//:eqy.bzl", "eqy_test")
load("@bazel-orfs//:openroad.bzl", "orfs_flow", "orfs_run")
load("//test/orfs:verify_tags.bzl", "verify_orfs_tags")
load("//test/orfs/asap7:asap7.bzl", "ASAP7_REMOVE_CELLS")
load(":sim.bzl", "sim_test")

Expand Down Expand Up @@ -69,13 +70,15 @@ filegroup(
srcs = [
"ram_8x7.sv",
],
tags = ["manual"],
)

[filegroup(
name = "ram_8x7_{stage}_files".format(stage = stage),
srcs = [
":ram_8x7_{stage}_verilog".format(stage = stage),
],
tags = ["manual"],
) for stage in STAGES[2:]]

[eqy_test(
Expand All @@ -88,14 +91,14 @@ filegroup(
":ram_8x7_{stage}_files".format(stage = STAGES[i]),
] + ([] if STAGES[i] == "source" else ["//test/orfs/asap7:asap7_files"]),
module_top = "ram_8x7",
tags = ["manual"],
tags = ["orfs"],
) for i in range(len(STAGES) - 1)]

[sim_test(
name = "ram_8x7_{stage}_sim_test".format(stage = stage),
cc_srcs = ["ram_8x7_sim.cpp"],
module_top = "ram_8x7",
tags = ["manual"],
tags = ["orfs"],
verilog = [":ram_8x7_{stage}.v".format(stage = stage) if stage != "source" else ":ram_8x7.sv"],
) for stage in STAGES[1:]]

Expand All @@ -108,7 +111,7 @@ OTHER = [
name = "ram_8x7_{other}_sim_test".format(other = other[:-2]),
cc_srcs = ["ram_8x7_sim.cpp"],
module_top = "ram_8x7",
tags = ["manual"],
tags = ["orfs"],
verilog = [other],
) for other in OTHER]

Expand All @@ -124,5 +127,7 @@ eqy_test(
"//test/orfs/asap7:asap7_files",
],
module_top = "ram_8x7",
tags = ["manual"],
tags = ["orfs"],
)

verify_orfs_tags()
62 changes: 62 additions & 0 deletions test/orfs/verify_tags.bzl
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
"""
Verify tagging policy for test/orfs/ BUILD files.

Policy:
- Test targets must have tags = ["orfs"] (no "manual")
- Non-test targets must have tags = ["manual"] (no "orfs")

The "orfs" tag lets test_tag_filters control whether tests run:
- Locally: test --test_tag_filters=-orfs skips them
- CI: test:ci --test_tag_filters= includes them

The "manual" tag on non-test targets prevents bazelisk build //...
from building ORFS artifacts.

Call verify_orfs_tags() at the end of each BUILD file under test/orfs/.
See test/orfs/README.md for details.
"""

# Rule kinds that are tests
_TEST_KINDS = [
"sh_test",
"test_suite",
# Rules from bazel-orfs and other external repos use
# the _test suffix convention.
]

def _is_test_rule(kind):
"""Check if a rule kind is a test rule."""
if kind in _TEST_KINDS:
return True
if kind.endswith("_test"):
return True
return False

def verify_orfs_tags():
"""Verify that all rules in the current package follow the tagging policy.

Must be called at the end of a BUILD file, after all rules are defined.
Fails the build if any rule violates the policy.
"""
errors = []

for name, rule in native.existing_rules().items():
tags = rule.get("tags", [])
kind = rule.get("kind", "")

if _is_test_rule(kind):
if "orfs" not in tags:
errors.append("%s (%s): test target missing 'orfs' tag" % (name, kind))
if "manual" in tags:
errors.append("%s (%s): test target must not have 'manual' tag" % (name, kind))
else:
if "manual" not in tags:
errors.append("%s (%s): non-test target missing 'manual' tag" % (name, kind))
if "orfs" in tags:
errors.append("%s (%s): non-test target should not have 'orfs' tag" % (name, kind))

if errors:
fail("Tagging policy violations in %s:\n %s\n\nSee test/orfs/README.md for the tagging policy." % (
native.package_name(),
"\n ".join(errors),
))
Loading