Skip to content

feat: Thermal service state-tracking implementation + tests#56

Open
dymk wants to merge 5 commits into
OpenDevicePartnership:mainfrom
dymk:dymk/thermal-state-tracking
Open

feat: Thermal service state-tracking implementation + tests#56
dymk wants to merge 5 commits into
OpenDevicePartnership:mainfrom
dymk:dymk/thermal-state-tracking

Conversation

@dymk
Copy link
Copy Markdown
Collaborator

@dymk dymk commented Apr 15, 2026

Summary

Implement stateful thermal service with state-tracking across all 6 opcodes
(get_temperature, set/get_threshold, set/get_variable, get_policy). Adds
comprehensive unit tests covering core round-trip behavior and edge cases.

Changes

  • Add thermal state data types and modify Thermal struct
  • Implement state logic in all 6 Thermal methods
  • Add thermal test module with helpers and core round-trip tests
  • Add edge case tests for thermal service
  • Add len validation to set_variable matching get_variable

Files changed

  • ec-service-lib/src/services/thermal.rs

@dymk dymk force-pushed the dymk/thermal-state-tracking branch 4 times, most recently from 0892334 to 47ca4cb Compare April 15, 2026 18:41
@dymk dymk marked this pull request as ready for review April 15, 2026 19:01
@dymk dymk requested a review from a team as a code owner April 15, 2026 19:01
@dymk dymk requested a review from Copilot April 15, 2026 19:11
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Implements a stateful Thermal service in ec-service-lib that persists threshold/variable data across requests and adds a comprehensive suite of unit tests validating round-trip behavior and several edge cases. Also tightens the repo’s pre-commit checks by treating Clippy warnings as errors and ensuring tests run against the host target.

Changes:

  • Add in-memory state to Thermal for per-sensor thresholds, cooling policy tracking, and a small UUID→u32 variable store with LRU eviction.
  • Update Thermal opcode handlers to read/write that state and return richer responses (e.g., get_threshold returning values).
  • Add a large unit test module covering round-trips, out-of-bounds handling, unknown UUIDs, and LRU eviction; update pre-commit to run clippy with -D warnings and run tests on the host target explicitly.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
ec-service-lib/src/services/thermal.rs Adds Thermal state, implements stateful opcode behavior, and introduces unit tests for round-trip + edge cases.
.husky/pre-commit Makes clippy warnings fatal and runs tests explicitly for the host target.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread ec-service-lib/src/services/thermal.rs
dymk and others added 5 commits April 15, 2026 12:27
cargo test without --target fails locally when rust-toolchain.toml
installs aarch64-unknown-none-softfloat, because no_std-incompatible
transitive deps (futures-timer, slab) are resolved for that target.
Using the host target from rustc -vV ensures portability across
Linux, macOS, and Windows.
- Add MAX_SENSORS (8) and MAX_VARS (16) constants
- Add ThresholdData, CoolingPolicyData state structs
- Add ThresholdRsp response struct with DirectMessagePayload conversion
- Add CoolingPolicyReq request struct with DirectMessagePayload parsing
- Replace empty Thermal struct with state arrays (thresholds, cooling_policies, variables)
- Add LRU tracking fields (var_count, var_timestamps, var_clock)
- Initialize Thermal::new() with nil UUIDs and zero timestamps
… tests

- Add #[cfg(test)] mod tests with 6 helper functions
- Add 4 core tests: threshold round-trip, variable round-trip, cooling policy, temperature response
- Use to_bytes_le() for UUID serialization (matches from_slice_le deserialization)
- Temperature test verifies TempRsp serialization (Yield::exec() untestable in unit tests)
- Add 8 edge case tests: unset defaults, unknown UUID error, threshold/variable upsert,
  LRU eviction, sensor bounds checking, sensor independence, cooling policy bounds
- Remove unused get_temperature_payload helper (temperature tested via TempRsp serialization)
- LRU eviction test verifies correct eviction of least-recently-used entry
- Total: 12 thermal tests + 50 TPM tests = 62 passing
Addresses code review WR-01: set_variable accepted any len value silently,
creating an asymmetry where stored variables could become unretrievable
via get_variable (which requires len == 4). Now rejects non-DWORD writes
with status -1.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@dymk dymk force-pushed the dymk/thermal-state-tracking branch from 47ca4cb to 8666ead Compare April 15, 2026 19:29
philgweber
philgweber previously approved these changes Apr 15, 2026
kurtjd
kurtjd previously approved these changes Apr 15, 2026
@dymk dymk dismissed stale reviews from kurtjd and philgweber April 15, 2026 21:48

The merge-base changed after approval.

philgweber
philgweber previously approved these changes Apr 15, 2026
@dymk dymk dismissed philgweber’s stale review April 15, 2026 21:53

The merge-base changed after approval.

kurtjd
kurtjd previously approved these changes Apr 15, 2026
rogurr
rogurr previously approved these changes Apr 16, 2026
@dymk dymk dismissed rogurr’s stale review April 16, 2026 23:43

The merge-base changed after approval.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: In progress

Development

Successfully merging this pull request may close these issues.

6 participants