type-c-interface-mocks: Create initial port mock structure#904
Open
RobertZ2011 wants to merge 1 commit into
Open
type-c-interface-mocks: Create initial port mock structure#904RobertZ2011 wants to merge 1 commit into
RobertZ2011 wants to merge 1 commit into
Conversation
RobertZ2011
force-pushed
the
type-c-interface-hardware-mocks
branch
3 times, most recently
from
June 24, 2026 21:23
8a9dfb5 to
fb81ede
Compare
RobertZ2011
force-pushed
the
type-c-interface-hardware-mocks
branch
2 times, most recently
from
July 20, 2026 15:56
956a235 to
f794495
Compare
RobertZ2011
marked this pull request as ready for review
July 20, 2026 16:01
RobertZ2011
requested review from
Copilot,
felipebalbi,
jerrysxie,
kurtjd and
williampMSFT
July 20, 2026 16:01
RobertZ2011
enabled auto-merge (squash)
July 20, 2026 16:01
Contributor
There was a problem hiding this comment.
Pull request overview
Summary of changes
This PR introduces a new type-c-interface-mocks crate intended to provide a no_std-friendly mock implementation of per-port Type-C (Pd) and power-policy (Psu) traits. It adds a PortMock with control helpers (connect / disconnect) that broadcast Type-C and power-policy events, plus integration tests validating the emitted events and internal state updates. The crate is wired into the workspace so it can be used by other components and demos.
Changes:
- Added a new
type-c-interface-mockscrate (no_std) with an initialPortMockimplementation for Type-C + PSU traits. - Added integration tests for
PortMock::connect()/PortMock::disconnect()event broadcasting. - Registered the crate in the workspace (
Cargo.toml) and lockfile (Cargo.lock).
Step-by-step review guide
-
Mock port structure & public surface
PortMockis generic overNonBlockingSenderimplementations for Type-C and power-policy event streams, keeping itno_stdcompatible and avoiding heap use.- Control helpers (
connect/disconnect) directly mutate storedPortStatus+ PSUState, then emit aStatusChangedevent and PSU attach/detach events.
-
Event semantics & state-machine alignment
- The Type-C status event bitfields (
new_power_contract_as_providervs..._as_consumer,sink_ready) have specific meaning and are used by the Type-C service’s power-policy integration. - Power-policy
Statehas distinct transitions for attach/detach vs connect/disconnect; mocks should mirror those transitions so services under test behave realistically.
- The Type-C status event bitfields (
-
Workspace integration
- The new crate is added to the workspace members and
[workspace.dependencies], enabling reuse and consistent dependency resolution.
- The new crate is added to the workspace members and
Potential issues
| # | Severity | File | Description | Code |
|---|---|---|---|---|
| 1 | High | type-c-interface-mocks/src/port/mod.rs:119-130 |
connect() sets consumer-side status bits and updates consumer capability when PowerRole::Source; this inverts provider/consumer semantics. |
set_new_power_contract_as_consumer(true) |
| 2 | High | type-c-interface-mocks/tests/connect_disconnect.rs:76-80 |
Source-role test asserts consumer-side status bits; it should assert provider contract bit(s). | new_power_contract_as_consumer() |
| 3 | High | type-c-interface-mocks/tests/connect_disconnect.rs:82-88 |
Source-role test checks consumer_capability, but source/provider flow should track requested provider capability in PSU state. |
consumer_capability.map(...) |
| 4 | Medium | type-c-interface-mocks/src/port/mod.rs:281-285 |
Psu::disconnect() uses detach() (physical unplug) rather than disconnect(...) (commanded power disconnect), diverging from power-policy state machine behavior. |
self.psu_state.detach(); |
| 5 | Medium | type-c-interface-mocks/src/port/mod.rs:287-289 |
Psu::connect_provider() is a stub and never transitions the PSU state to ConnectedProvider. |
async fn connect_provider ... { Ok(()) } |
| 6 | Low | type-c-interface-mocks/Cargo.toml:26 |
log feature doesn’t enable power-policy-interface/log, risking inconsistent logging backend propagation vs the defmt feature. |
log = ["dep:log", ...] |
Reviewed changes
Copilot reviewed 5 out of 6 changed files in this pull request and generated 6 comments.
Show a summary per file
| File | Description |
|---|---|
| type-c-interface-mocks/src/lib.rs | Adds new no_std crate entry point exposing the port module. |
| type-c-interface-mocks/src/port/mod.rs | Introduces PortMock implementing Type-C Pd + power-policy Psu, plus connect/disconnect helpers and event emission. |
| type-c-interface-mocks/tests/connect_disconnect.rs | Adds integration tests validating connect/disconnect broadcasts and internal state. |
| type-c-interface-mocks/Cargo.toml | Defines crate deps/features (defmt/log) and dev-deps for tokio-based tests. |
| Cargo.toml | Registers the new crate as a workspace member and workspace dependency. |
| Cargo.lock | Adds the new crate entry to the lockfile. |
RobertZ2011
marked this pull request as draft
July 20, 2026 16:44
auto-merge was automatically disabled
July 20, 2026 16:44
Pull request was converted to draft
RobertZ2011
force-pushed
the
type-c-interface-hardware-mocks
branch
from
July 20, 2026 17:32
f794495 to
955a4c2
Compare
RobertZ2011
force-pushed
the
type-c-interface-hardware-mocks
branch
from
July 20, 2026 17:45
955a4c2 to
6e9831f
Compare
RobertZ2011
marked this pull request as ready for review
July 20, 2026 18:06
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Create the initial structure for a type-C port mock that is intended to run in a
no_stdenvironment to mock hardware that isn't physically present. This will mostly be used for demonstration purposes.