type-c-interface-mocks: Create initial port mock structure#904
type-c-interface-mocks: Create initial port mock structure#904RobertZ2011 wants to merge 1 commit into
Conversation
8a9dfb5 to
fb81ede
Compare
956a235 to
f794495
Compare
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. |
Pull request was converted to draft
f794495 to
955a4c2
Compare
955a4c2 to
6e9831f
Compare
6e9831f to
9e741e1
Compare
9e741e1 to
ec5da9f
Compare
jerrysxie
left a comment
There was a problem hiding this comment.
@RobertZ2011 Will this mock be used for testing or just demoing? which issue is tracking this effort?
At the moment the intent is to use this for demoing. I also created and linked an issue for this. |
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.