Skip to content

Conversation

@sasdf
Copy link
Contributor

@sasdf sasdf commented Oct 23, 2025

This PR refactors FPGA test_cmd by separating common setup (initialization, bitstream loading, bootstrapping) and cleanup logic from the core test command. In addition to the improved code maintainability, this patch enables more flexible test setups, such as for ROM coverage tests where extra steps are required between bitstream loading and bootstrapping, which can now be easily configured using testopt in the execution environment.

Previously, modifying the test command required repeating these boilerplate steps. Now, these steps are removed from the test_cmd but can still be controlled via a set oftestopt flags in fpga_params.

  • bool testopt_clear_before_test: (Default=False) Call clear-bitstream before loading bitstream.
  • bool testopt_bootstrap: (Default=True) Bootstrap firmware before test.
  • bool testopt_clear_after_test: (Default=False) Call clear-bitstream after test or failure.

This PR also updates the semantic of several things:

  • The param field in exec env rules now partially overrides the param from base exec env.
  • The default test_cmd in FPGA test envs is now empty, which is a good default for custom harness without flags.
  • The ownership_transfer_test will also prepend flags for per-env test_cmd overrides.

We can have a follow-up PRs that also refactors other environments (qemu, silicon, ...) to align with FPGA.


Two tests failed with unread UART log overflow after the refactoring:

  • //sw/device/silicon_creator/rom_ext/e2e/rescue:primary_slot_usbdfu
  • //sw/device/silicon_creator/rom_ext/e2e/rescue:next_slot_usbdfu

We workaround this issue by initializing the console at the beginning of the test.

@sasdf
Copy link
Contributor Author

sasdf commented Oct 23, 2025

@cfrantz @pamaury Could you please provide a brief review of the proposed approach? I'll continue migrating the remaining tests if this method is acceptable.

@sasdf sasdf requested review from cfrantz and pamaury October 23, 2025 11:46
@sasdf sasdf force-pushed the mgTc05c7768 branch 2 times, most recently from cd24921 to d0c98d5 Compare October 23, 2025 16:15
Copy link
Contributor

@cfrantz cfrantz left a comment

Choose a reason for hiding this comment

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

This is nice as it encodes a bunch of common patterns into some bool flags to control those common patterns.

Comment on lines +75 to +76
testopt_clear_after_test = "True",
testopt_clear_before_test = "True",
Copy link
Contributor

Choose a reason for hiding this comment

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

There are many tests in the codebase that want to clear the bitstream both before and after. For example, most of the ownership and rescue tests have this property since they want to initialize with a modified owner config or modify the owner config during the test.

Are there any tests that don't have this property of wanting a clear both before and after?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Some of the tests with changes_otp tag clear the bitstream after but not before.

Comment on lines 169 to 178
# Construct the opentitantool test setup commands
test_setup_cmd = ['--exec="transport init"']
if _get_bool(param, "testopt_clear_before_test"):
test_setup_cmd.append('--exec="fpga clear-bitstream"')
if "bitstream" in param:
test_setup_cmd.append('--exec="fpga load-bitstream {bitstream}"')
if _get_bool(param, "testopt_bootstrap") and "firmware" in param:
test_setup_cmd.append('--exec="bootstrap --leave-in-reset --clear-uart=true {firmware}"')
test_setup_cmd = "\n".join(test_setup_cmd)
test_setup_cmd = test_setup_cmd.format(**param)
Copy link
Contributor

Choose a reason for hiding this comment

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

Most of the custom test-harness tests manage their own bitstream and bootstrapping in the harness. How does this step interact with those tests? (ie: can we set flags appropriately to end up constructing an empty test_setup_cmd so that those tests continue to operate normally)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I removed the load bitstream from the custom harness flags, and will also remove the --bootstrap flags when migrating the test_cmds.

Since the old tests will always re-initialize the FPGA, these setup cmd won't have any impact on the tests except a longer testing time.

"--rcfile=",
"--logging=info",
"--interface={interface}",
"--drop-reset",
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we really add a top-level flag to do this?

How about --exec='gpio remove RESET'

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This flag needs to work with both opentitantool and custom harness (i.e. test_utils) which doesn't understand the --exec flags.

@sasdf sasdf force-pushed the mgTc05c7768 branch 2 times, most recently from da18076 to 56f22d1 Compare October 28, 2025 02:25
@pamaury pamaury requested a review from jwnrt October 29, 2025 09:52
@sasdf sasdf force-pushed the mgTc05c7768 branch 4 times, most recently from e3fff45 to 7003e3b Compare November 5, 2025 12:54
sasdf added 5 commits November 5, 2025 23:39
Currently, an execution environment can derive from a base
execution environment. However, some fields, like `param`,
are dictionaries are completely replaced instead of partially
overridable.

This change introduces `_NESTED_FIELDS` to indicate fields that
should merge their values when derived from a base, rather than
just replacing them. Specifically, it enables `param` to be
partially overridden, allowing a derived environment to add or
modify specific parameters without losing all parameters from
its base.

Change-Id: Ie0922e2e90c80c92749907f491109b527879a278
Signed-off-by: Yi-Hsuan Deng <[email protected]>
This change extracts the FPGA test command setup and cleanup logic
into a more modular system using `testopt` flags, which reduces the
boilerplate needed to customize test commands.

Change-Id: I008cf6ce4617ba5afe2adf81df855e8593d4995e
Signed-off-by: Yi-Hsuan Deng <[email protected]>
Added the `drop-reset` command line option to `opentitantool` and
`opentitanlib`, which allows de-asserting the `RESET` pin before
executing any command. This is useful for devices held in a reset state,
where `RESET` needs to be de-asserted to allow the host to communicate
with the device.

Change-Id: I7c9b3520132f635d9a12733e5e22fe658f6961a3
Signed-off-by: Yi-Hsuan Deng <[email protected]>
This change:
* Cleans up FPGA parameter fields by utilizing the new partial overwrite semantics.
* Sets up FPGA execution environments using `testopt` flags.
* Modifies the default `test_cmd` for FPGA environments to be empty, providing a better default for custom harnesses that don't require flags.

Change-Id: I645ac75eb2007d0d109bcab2fdc0cad042e7c8e1
Signed-off-by: Yi-Hsuan Deng <[email protected]>
This change applies the `testopt_bootstrap`, `testopt_clear_before_test`
and `testopt_clear_after_test` refactoring to existing tests instead of
using the test_cmd to bootstrap and clear the bitstream before/after the
test.

These options simplify test configuration and make it easier to manage
how tests interact with the FPGA and bootstrap process.

Change-Id: Ic05c77684e2d7577bcd328872a230d396035847d
Signed-off-by: Yi-Hsuan Deng <[email protected]>
@sasdf sasdf requested a review from cfrantz November 6, 2025 00:21
@sasdf sasdf marked this pull request as ready for review November 6, 2025 00:22
@sasdf sasdf requested a review from a team as a code owner November 6, 2025 00:22
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