Skip to content

Commit

Permalink
[autogen,testutils] Fix isr_tstutils for multitop
Browse files Browse the repository at this point in the history
The template was still using earlgrey types. This requires to pass
top information to the generator and templates.

Signed-off-by: Amaury Pouly <[email protected]>
  • Loading branch information
pamaury committed Mar 5, 2025
1 parent e475b7c commit 45b349b
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 14 deletions.
19 changes: 13 additions & 6 deletions util/autogen_testutils/gen.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# SPDX-License-Identifier: Apache-2.0

from pathlib import Path
from typing import List
from typing import Dict, List

from autogen_banner import get_autogen_banner
from make_new_dif.ip import Ip
Expand All @@ -15,7 +15,9 @@
REPO_TOP = Path(__file__).resolve().parent.parent.parent


def gen_testutils(outdir: Path, ips_with_difs: List[Ip]) -> List[Path]:
def gen_testutils(outdir: Path,
completecfg: Dict[str, object],
ips_with_difs: List[Ip]) -> List[Path]:
"""Generate testutils libraries that are rendered from Mako templates.
Args:
Expand Down Expand Up @@ -44,10 +46,15 @@ def gen_testutils(outdir: Path, ips_with_difs: List[Ip]) -> List[Path]:
testutils_template = Template(testutils_template_path.read_text())
testutils = outdir / testutils_template_path.stem
testutils.write_text(
testutils_template.render(ips_with_difs=ips_with_difs,
autogen_banner=get_autogen_banner(
"util/autogen_testutils.py",
comment=comment_syntax)))
testutils_template.render(
ips_with_difs=ips_with_difs,
autogen_banner=get_autogen_banner(
"util/autogen_testutils.py",
comment=comment_syntax
),
top = completecfg,
)
)
testutilses += [testutils]

return testutilses
11 changes: 6 additions & 5 deletions util/autogen_testutils/templates/isr_testutils.c.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
// SPDX-License-Identifier: Apache-2.0

${autogen_banner}
<%
top_name = top["name"]
%>

#include "sw/device/lib/testing/autogen/isr_testutils.h"
#include "sw/device/lib/dif/dif_base.h"
Expand All @@ -16,8 +19,6 @@ ${autogen_banner}
% endfor
#include "sw/device/lib/testing/test_framework/check.h"

#include "hw/top_earlgrey/sw/autogen/top_earlgrey.h" // Generated.

% for ip in ips_with_difs:
% if ip.irqs:
void isr_testutils_${ip.name_snake}_isr(
Expand All @@ -26,7 +27,7 @@ ${autogen_banner}
% if ip.has_status_type_irqs():
bool mute_status_irq,
% endif
top_earlgrey_plic_peripheral_t *peripheral_serviced,
top_${top_name}_plic_peripheral_t *peripheral_serviced,
dif_${ip.name_snake}_irq_t *irq_serviced) {
// Claim the IRQ at the PLIC.
Expand All @@ -37,8 +38,8 @@ ${autogen_banner}
&plic_irq_id));
// Get the peripheral the IRQ belongs to.
*peripheral_serviced = (top_earlgrey_plic_peripheral_t)
top_earlgrey_plic_interrupt_for_peripheral[plic_irq_id];
*peripheral_serviced = (top_${top_name}_plic_peripheral_t)
top_${top_name}_plic_interrupt_for_peripheral[plic_irq_id];

// Get the IRQ that was fired from the PLIC IRQ ID.
dif_${ip.name_snake}_irq_t irq = (dif_${ip.name_snake}_irq_t)(plic_irq_id -
Expand Down
7 changes: 5 additions & 2 deletions util/autogen_testutils/templates/isr_testutils.h.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
#define OPENTITAN_SW_DEVICE_LIB_TESTING_AUTOGEN_ISR_TESTUTILS_H_

${autogen_banner}
<%
top_name = top["name"]
%>

/**
* @file
Expand All @@ -19,7 +22,7 @@ ${autogen_banner}
% endif
% endfor

#include "hw/top_earlgrey/sw/autogen/top_earlgrey.h" // Generated.
#include "hw/top_${top_name}/sw/autogen/top_${top_name}.h" // Generated.

/**
* A handle to a PLIC ISR context struct.
Expand Down Expand Up @@ -81,7 +84,7 @@ typedef struct plic_isr_ctx {
% if ip.has_status_type_irqs():
bool mute_status_irq,
% endif
top_earlgrey_plic_peripheral_t *peripheral_serviced,
top_${top_name}_plic_peripheral_t *peripheral_serviced,
dif_${ip.name_snake}_irq_t *irq_serviced);

% endif
Expand Down
2 changes: 1 addition & 1 deletion util/gen_testutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ def main():
ips.append(Ip(ipname, "AUTOGEN", hjson_file))

# Auto-generate testutils files.
testutilses = gen_testutils(outdir, ips)
testutilses = gen_testutils(outdir, topcfg, ips)

# Format autogenerated file with clang-format.
try:
Expand Down

0 comments on commit 45b349b

Please sign in to comment.