Skip to content

Commit ee10258

Browse files
AlexJones0jwnrt
authored andcommitted
[sw,tests] Refactor plic_all_irqs_test to assert test count
Signed-off-by: Alex Jones <[email protected]>
1 parent b8c9bbc commit ee10258

File tree

4 files changed

+84
-31
lines changed
  • hw
    • top_darjeeling/sw/autogen/tests
    • top_earlgrey/sw/autogen/tests
    • top_englishbreakfast/sw/autogen/tests
  • util/topgen/templates

4 files changed

+84
-31
lines changed

hw/top_darjeeling/sw/autogen/tests/BUILD

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,23 @@ load("@bazel_skylib//lib:dicts.bzl", "dicts")
1919

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

22+
# Number of periphals per test
23+
NR_IRQ_PERIPH_PER_TEST = 10
24+
25+
# Total numbers of tests (the last will contain only remaining IRQs)
26+
NR_IRQ_PERIPH_TESTS = 2
27+
2228
[
2329
opentitan_test(
24-
name = "plic_all_irqs_test_{}".format(min),
30+
name = "plic_all_irqs_test_{}".format(idx * NR_IRQ_PERIPH_PER_TEST),
2531
srcs = ["plic_all_irqs_test.c"],
32+
# For the last test, do not specify TEST_MAX_IRQ_PERIPHERAL to be sure
33+
# that we are capturing all peripherals.
2634
copts = [
27-
"-DTEST_MIN_IRQ_PERIPHERAL={}".format(min),
28-
"-DTEST_MAX_IRQ_PERIPHERAL={}".format(min + 10),
29-
],
35+
"-DTEST_MIN_IRQ_PERIPHERAL={}".format(idx * NR_IRQ_PERIPH_PER_TEST),
36+
] + ([
37+
"-DTEST_MAX_IRQ_PERIPHERAL={}".format((idx + 1) * NR_IRQ_PERIPH_PER_TEST),
38+
] if idx < NR_IRQ_PERIPH_PER_TEST - 1 else []),
3039
exec_env = dicts.add(
3140
{
3241
"//hw/top_darjeeling:sim_dv": None,
@@ -72,14 +81,14 @@ package(default_visibility = ["//visibility:public"])
7281
"//sw/device/lib/testing/test_framework:ottf_main",
7382
],
7483
)
75-
for min in range(0, 19, 10)
84+
for idx in range(NR_IRQ_PERIPH_TESTS)
7685
]
7786

7887
test_suite(
7988
name = "plic_all_irqs_test",
8089
tests = [
81-
"plic_all_irqs_test_0",
82-
"plic_all_irqs_test_10",
90+
"plic_all_irqs_test_{}".format(idx * NR_IRQ_PERIPH_PER_TEST)
91+
for idx in range(NR_IRQ_PERIPH_TESTS)
8392
],
8493
)
8594

hw/top_earlgrey/sw/autogen/tests/BUILD

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,23 @@ load("@bazel_skylib//lib:dicts.bzl", "dicts")
2121

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

24+
# Number of periphals per test
25+
NR_IRQ_PERIPH_PER_TEST = 10
26+
27+
# Total numbers of tests (the last will contain only remaining IRQs)
28+
NR_IRQ_PERIPH_TESTS = 3
29+
2430
[
2531
opentitan_test(
26-
name = "plic_all_irqs_test_{}".format(min),
32+
name = "plic_all_irqs_test_{}".format(idx * NR_IRQ_PERIPH_PER_TEST),
2733
srcs = ["plic_all_irqs_test.c"],
34+
# For the last test, do not specify TEST_MAX_IRQ_PERIPHERAL to be sure
35+
# that we are capturing all peripherals.
2836
copts = [
29-
"-DTEST_MIN_IRQ_PERIPHERAL={}".format(min),
30-
"-DTEST_MAX_IRQ_PERIPHERAL={}".format(min + 10),
31-
],
37+
"-DTEST_MIN_IRQ_PERIPHERAL={}".format(idx * NR_IRQ_PERIPH_PER_TEST),
38+
] + ([
39+
"-DTEST_MAX_IRQ_PERIPHERAL={}".format((idx + 1) * NR_IRQ_PERIPH_PER_TEST),
40+
] if idx < NR_IRQ_PERIPH_PER_TEST - 1 else []),
3241
exec_env = dicts.add(
3342
EARLGREY_TEST_ENVS,
3443
EARLGREY_SILICON_OWNER_ROM_EXT_ENVS,
@@ -82,15 +91,14 @@ package(default_visibility = ["//visibility:public"])
8291
"//sw/device/lib/testing/test_framework:ottf_main",
8392
],
8493
)
85-
for min in range(0, 23, 10)
94+
for idx in range(NR_IRQ_PERIPH_TESTS)
8695
]
8796

8897
test_suite(
8998
name = "plic_all_irqs_test",
9099
tests = [
91-
"plic_all_irqs_test_0",
92-
"plic_all_irqs_test_10",
93-
"plic_all_irqs_test_20",
100+
"plic_all_irqs_test_{}".format(idx * NR_IRQ_PERIPH_PER_TEST)
101+
for idx in range(NR_IRQ_PERIPH_TESTS)
94102
],
95103
)
96104

hw/top_englishbreakfast/sw/autogen/tests/BUILD

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,23 @@ load("@bazel_skylib//lib:dicts.bzl", "dicts")
1919

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

22+
# Number of periphals per test
23+
NR_IRQ_PERIPH_PER_TEST = 10
24+
25+
# Total numbers of tests (the last will contain only remaining IRQs)
26+
NR_IRQ_PERIPH_TESTS = 1
27+
2228
[
2329
opentitan_test(
24-
name = "plic_all_irqs_test_{}".format(min),
30+
name = "plic_all_irqs_test_{}".format(idx * NR_IRQ_PERIPH_PER_TEST),
2531
srcs = ["plic_all_irqs_test.c"],
32+
# For the last test, do not specify TEST_MAX_IRQ_PERIPHERAL to be sure
33+
# that we are capturing all peripherals.
2634
copts = [
27-
"-DTEST_MIN_IRQ_PERIPHERAL={}".format(min),
28-
"-DTEST_MAX_IRQ_PERIPHERAL={}".format(min + 10),
29-
],
35+
"-DTEST_MIN_IRQ_PERIPHERAL={}".format(idx * NR_IRQ_PERIPH_PER_TEST),
36+
] + ([
37+
"-DTEST_MAX_IRQ_PERIPHERAL={}".format((idx + 1) * NR_IRQ_PERIPH_PER_TEST),
38+
] if idx < NR_IRQ_PERIPH_PER_TEST - 1 else []),
3039
exec_env = dicts.add(
3140
),
3241
verilator = verilator_params(
@@ -58,13 +67,14 @@ package(default_visibility = ["//visibility:public"])
5867
"//sw/device/lib/testing/test_framework:ottf_main",
5968
],
6069
)
61-
for min in range(0, 8, 10)
70+
for idx in range(NR_IRQ_PERIPH_TESTS)
6271
]
6372

6473
test_suite(
6574
name = "plic_all_irqs_test",
6675
tests = [
67-
"plic_all_irqs_test_0",
76+
"plic_all_irqs_test_{}".format(idx * NR_IRQ_PERIPH_PER_TEST)
77+
for idx in range(NR_IRQ_PERIPH_TESTS)
6878
],
6979
)
7080

util/topgen/templates/BUILD.tpl

Lines changed: 36 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -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
%>\
4868
load(
4969
"//rules/opentitan:defs.bzl",
@@ -55,14 +75,23 @@ load("@bazel_skylib//lib:dicts.bzl", "dicts")
5575

5676
package(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

105134
test_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

Comments
 (0)