Skip to content

Add testhelper.Open with TCP support#436

Merged
josephlr merged 4 commits into
google:mainfrom
crocomegan:main
Jun 2, 2026
Merged

Add testhelper.Open with TCP support#436
josephlr merged 4 commits into
google:mainfrom
crocomegan:main

Conversation

@crocomegan

Copy link
Copy Markdown
Contributor

This pull request adds TCP support to the simulator.

Summary of changes:

  1. Adds flag support (cmd_addr and plat_addr) to specify command and platform TCP ports.
  2. Updates OpenSimulator() to check for these flags. If both are provided, it initializes a TCP transport connection instead of using the default local simulator.

@crocomegan crocomegan requested review from a team, alexmwu and jkl73 as code owners May 28, 2026 17:56
Adds support for spawning a local reference simulator binary via the new '--tpm-sim-path' flag. The simulator is spawned inside a temporary directory with '--pick_ports' enabled. Port files are polled on startup and parsed to open the TCP transport.

All unit tests under `tpm2/test` are refactored to use `testhelper.Open` to utilize this support.

To show that this works:
1. Build the Reference Simulator:
   cmake --build /usr/local/google/home/joerichey/dev/tcg/TPM/build --target Simulator

2. Run tests using the built binary:
   go test ./tpm2/test -tpm-sim-path /usr/local/google/home/joerichey/dev/tcg/TPM/build/Simulator/Simulator

Note:
The RSA 3072 and 4096 parameter tests ('TestTestParms') are expected to fail when executed against the Reference Simulator because the Reference Simulator compiles with native support for 3072-bit and 4096-bit RSA keys, whereas the test suite expects them to be unsupported and return TPM_RC_VALUE.

Signed-off-by: Joe Richey <joerichey@google.com>
@josephlr

Copy link
Copy Markdown
Member

Here's the idea we discussed earlier about how to handle spawning the simulator per-test:

josephlr@49ab706

It uses the testhelper package to simplify some things. It's just a rough idea, but running:

go test ./tpm2/test --tpm-sim-path ~/dev/tcg/TPM/build/Simulator/Simulator

Passes all the tests except for the ones we expect it to fail.

…implify TCP Stop

- Raise maxListLength to 32767 to support larger contexts from modern simulator configurations (Part 2, Section 10.3.1).
- Rename transport/test directory to transport/testhelper and clean up test helper imports.
- Refactor startProcess to initialize the process struct first and defer Close.
- Simplify TCP Stop logic by only sending tpmStop and omitting platformStop.
- Clean up port file polling in readPorts to use io/fs and time.Ticker.
Signed-off-by: Joe Richey <joerichey@google.com>
@josephlr josephlr changed the title Add TCP support to simulator Add testhelper.Open with TCP support May 30, 2026

@josephlr josephlr left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Nice Job on this!

@josephlr josephlr merged commit 9f0977c into google:main Jun 2, 2026
13 of 16 checks passed
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