Skip to content

refactor: Tidy up how wildcards get expanded in testpoints#221

Merged
rswarbrick merged 1 commit into
lowRISC:masterfrom
rswarbrick:wildcard-expand
May 26, 2026
Merged

refactor: Tidy up how wildcards get expanded in testpoints#221
rswarbrick merged 1 commit into
lowRISC:masterfrom
rswarbrick:wildcard-expand

Conversation

@rswarbrick

Copy link
Copy Markdown
Contributor

I think the existing implementation had a bit of a problem if you had multiple wildcard patterns that all expanded to lists of values. Presumably no-one ever cared, but it also wasn't very easy to see how the code worked.

Comment thread src/dvsim/testplan.py

A wildcard use with no match in substitutions will be replaced by an
empty string (in a single item). For example, if substitutions is {}
and self.tests is ['test-{a}'] then self.tests will become ['test-'].

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Aside: the original implementation feels unintuitive - I feel like most similar systems would retain one copy of the unsubstituted text (i.e. just leave it as ['test-{a}']).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not completely sure, but this might be an intentional feature. It also guarantees that test names don't have stray curly braces in them at the end.

I think any improvement to this would probably need to be separate work.

Comment thread src/dvsim/testplan.py Outdated
ret.extend(Testpoint._expand_str(pattern, new_vals, txt))
return ret

def do_substitutions(self, substitutions: dict, reserved_names: Sequence[str]) -> None:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we make this substitutions: dict[str, str | list[str]] or is this too strong of a typing to enforce here at this stage? If not, at least substitutions: dict[str, Any]?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because the dictionary fundamentally comes from a parsed hjson file, I think we'll need the weaker type. But that's probably better than what I had.

I think the existing implementation had a bit of a problem if you had
multiple wildcard patterns that all expanded to lists of values.
Presumably no-one ever cared, but it also wasn't very easy to see how
the code worked.

Signed-off-by: Rupert Swarbrick <rswarbrick@lowrisc.org>
@rswarbrick rswarbrick added this pull request to the merge queue May 26, 2026
Merged via the queue into lowRISC:master with commit 78c0fab May 26, 2026
6 checks passed
@rswarbrick rswarbrick deleted the wildcard-expand branch May 26, 2026 09:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants