@@ -44,6 +44,26 @@ defs_imports = sorted(
4444 "verilator_params",
4545 ]
4646)
47+
48+ ## Check we still have the same number of tests that we expect for each top:
49+ ## if we don't, then before updating these values, the corresponding DV tests
50+ ## need to be updated.
51+ irq_per_test = 10
52+ irq_test_count = len(irq_peripheral_names) // 10 + 1
53+ expected_irq_tests = {
54+ " earlgrey" : 3,
55+ " darjeeling" : 2,
56+ " englishbreakfast" : 1,
57+ }
58+
59+ ## If this check fails, the testplans / DV tests need to be updated to account
60+ ## for the change in software test targets, and then the ## `expected_irq_tests`
61+ ## value needs updating to its new value.
62+ if irq_test_count != expected_irq_tests.get(top["name"], irq_test_count):
63+ raise Exception(
64+ "Number of PLIC IRQ tests does not match the hardcoded number. "
65+ "Testplans / DV tests and this templates/BUILD.tpl file needs updating."
66+ )
4767%>\
4868load(
4969 "//rules/opentitan:defs.bzl",
@@ -55,14 +75,23 @@ load("@bazel_skylib//lib:dicts.bzl", "dicts")
5575
5676package(default_visibility = ["//visibility:public"])
5777
78+ # Number of periphals per test
79+ NR_IRQ_PERIPH_PER_TEST = ${ irq_per_test}
80+
81+ # Total numbers of tests (the last will contain only remaining IRQs)
82+ NR_IRQ_PERIPH_TESTS = ${ irq_test_count}
83+
5884[
5985 opentitan_test(
60- name = "plic_all_irqs_test_{ } ".format(min ),
86+ name = "plic_all_irqs_test_{ } ".format(idx * NR_IRQ_PERIPH_PER_TEST ),
6187 srcs = ["plic_all_irqs_test.c"],
88+ # For the last test, do not specify TEST_MAX_IRQ_PERIPHERAL to be sure
89+ # that we are capturing all peripherals.
6290 copts = [
63- "-DTEST_MIN_IRQ_PERIPHERAL={ } ".format(min),
64- "-DTEST_MAX_IRQ_PERIPHERAL={ } ".format(min + 10),
65- ],
91+ "-DTEST_MIN_IRQ_PERIPHERAL={ } ".format(idx * NR_IRQ_PERIPH_PER_TEST),
92+ ] + ([
93+ "-DTEST_MAX_IRQ_PERIPHERAL={ } ".format((idx + 1) * NR_IRQ_PERIPH_PER_TEST),
94+ ] if idx < NR_IRQ_PERIPH_PER_TEST - 1 else []),
6695 exec_env = dicts.add(
6796% for exec_env in exec_envs:
6897% if isinstance(exec_env, str):
@@ -99,17 +128,14 @@ package(default_visibility = ["//visibility:public"])
99128 "//sw/device/lib/testing/test_framework:ottf_main",
100129 ],
101130 )
102- for min in range(0, $ { len(irq_peripheral_names) } , 10 )
131+ for idx in range(NR_IRQ_PERIPH_TESTS )
103132]
104133
105134test_suite(
106135 name = "plic_all_irqs_test",
107136 tests = [
108- ## Use template loop instead of Starlark loop here to be able to easily detect
109- ## if number of tests have changed (so DV files can be updated accordingly)
110- % for min in range(0, len(irq_peripheral_names), 10):
111- "plic_all_irqs_test_${ min} ",
112- % endfor
137+ "plic_all_irqs_test_{ } ".format(idx * NR_IRQ_PERIPH_PER_TEST)
138+ for idx in range(NR_IRQ_PERIPH_TESTS)
113139 ],
114140)
115141
0 commit comments