Skip to content

type-c-interface-mocks: Create initial port mock structure#904

Open
RobertZ2011 wants to merge 1 commit into
OpenDevicePartnership:mainfrom
RobertZ2011:type-c-interface-hardware-mocks
Open

type-c-interface-mocks: Create initial port mock structure#904
RobertZ2011 wants to merge 1 commit into
OpenDevicePartnership:mainfrom
RobertZ2011:type-c-interface-hardware-mocks

Conversation

@RobertZ2011

@RobertZ2011 RobertZ2011 commented Jun 24, 2026

Copy link
Copy Markdown
Contributor

Create the initial structure for a type-C port mock that is intended to run in a no_std environment to mock hardware that isn't physically present. This will mostly be used for demonstration purposes.

@RobertZ2011 RobertZ2011 self-assigned this Jun 24, 2026
@RobertZ2011
RobertZ2011 force-pushed the type-c-interface-hardware-mocks branch 3 times, most recently from 8a9dfb5 to fb81ede Compare June 24, 2026 21:23
@RobertZ2011
RobertZ2011 force-pushed the type-c-interface-hardware-mocks branch 2 times, most recently from 956a235 to f794495 Compare July 20, 2026 15:56
@RobertZ2011 RobertZ2011 changed the title Type c interface hardware mocks type-c-interface-mocks: Create initial port mock structure Jul 20, 2026
@RobertZ2011
RobertZ2011 marked this pull request as ready for review July 20, 2026 16:01
@RobertZ2011
RobertZ2011 requested a review from a team as a code owner July 20, 2026 16:01
@RobertZ2011
RobertZ2011 enabled auto-merge (squash) July 20, 2026 16:01
@RobertZ2011
RobertZ2011 requested review from asasine and tullom July 20, 2026 16:01

Copilot AI left a comment

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.

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-mocks crate (no_std) with an initial PortMock implementation 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

  1. Mock port structure & public surface

    • PortMock is generic over NonBlockingSender implementations for Type-C and power-policy event streams, keeping it no_std compatible and avoiding heap use.
    • Control helpers (connect / disconnect) directly mutate stored PortStatus + PSU State, then emit a StatusChanged event and PSU attach/detach events.
  2. Event semantics & state-machine alignment

    • The Type-C status event bitfields (new_power_contract_as_provider vs ..._as_consumer, sink_ready) have specific meaning and are used by the Type-C service’s power-policy integration.
    • Power-policy State has distinct transitions for attach/detach vs connect/disconnect; mocks should mirror those transitions so services under test behave realistically.
  3. Workspace integration

    • The new crate is added to the workspace members and [workspace.dependencies], enabling reuse and consistent dependency resolution.

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.

Comment thread type-c-interface-mocks/src/port/mod.rs
Comment thread type-c-interface-mocks/tests/connect_disconnect.rs
Comment thread type-c-interface-mocks/tests/connect_disconnect.rs Outdated
Comment thread type-c-interface-mocks/src/port/mod.rs
Comment thread type-c-interface-mocks/src/port/mod.rs Outdated
Comment thread type-c-interface-mocks/Cargo.toml Outdated
@RobertZ2011
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
RobertZ2011 force-pushed the type-c-interface-hardware-mocks branch from f794495 to 955a4c2 Compare July 20, 2026 17:32
@RobertZ2011
RobertZ2011 requested a review from Copilot July 20, 2026 17:34

Copilot AI left a comment

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.

Pull request overview

Copilot reviewed 5 out of 6 changed files in this pull request and generated 2 comments.

Comment thread type-c-interface-mocks/src/port/mod.rs
Comment thread type-c-interface-mocks/src/port/mod.rs Outdated
@RobertZ2011
RobertZ2011 force-pushed the type-c-interface-hardware-mocks branch from 955a4c2 to 6e9831f Compare July 20, 2026 17:45
@RobertZ2011
RobertZ2011 marked this pull request as ready for review July 20, 2026 18:06
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