Repository navigation
fix(device): report a refused listed report rate as not applied #2736
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -58,6 +58,8 @@ const EXTENDED_INDEX: u8 = 0x0f; | |
| const LEGACY_INDEX: u8 = 0x0e; | ||
| /// HID++ 2.0 `Busy`. | ||
| const BUSY: u8 = 0x08; | ||
| /// HID++ 2.0 `InvalidArgument`. | ||
| const INVALID_ARGUMENT: u8 = 0x02; | ||
|
|
||
| /// Which report-rate feature a scripted mouse lists. | ||
| #[derive(Clone, Copy, PartialEq, Eq)] | ||
|
|
@@ -84,6 +86,9 @@ struct Mouse { | |
| interval_ms: u8, | ||
| /// Whether a write changes the rate. | ||
| takes_writes: bool, | ||
| /// The HID++ error a rate write answers with instead of an | ||
| /// acknowledgement, if any. | ||
| refuses_writes: Option<u8>, | ||
| /// Whether a rate read after a write fails with `Busy`. | ||
| fails_read_back: bool, | ||
| /// Every rate write, as its wire byte. | ||
|
|
@@ -101,6 +106,7 @@ impl Mouse { | |
| connection: 0, | ||
| interval_ms: 1, | ||
| takes_writes: true, | ||
| refuses_writes: None, | ||
| fails_read_back: false, | ||
| writes: Vec::new(), | ||
| rate_reads: Vec::new(), | ||
|
|
@@ -141,6 +147,9 @@ impl Mouse { | |
| } | ||
| (EXTENDED_INDEX, 0x03) => { | ||
| self.writes.push(request[4]); | ||
| if let Some(code) = self.refuses_writes { | ||
| return Some(feature_error(request, code)); | ||
| } | ||
| if self.takes_writes { | ||
| self.extended_rates[self.connection] = request[4]; | ||
| } | ||
|
|
@@ -154,6 +163,9 @@ impl Mouse { | |
| } | ||
| (LEGACY_INDEX, 0x02) => { | ||
| self.writes.push(request[4]); | ||
| if let Some(code) = self.refuses_writes { | ||
| return Some(feature_error(request, code)); | ||
| } | ||
| if self.takes_writes { | ||
| self.interval_ms = request[4]; | ||
| } | ||
|
|
@@ -301,6 +313,54 @@ async fn a_rate_the_device_does_not_keep_is_not_applied() { | |
| assert_eq!(mouse.lock().expect("mouse lock").writes, [2]); | ||
| } | ||
|
|
||
| /// A G Pro Wireless in onboard mode lists 125–1000 Hz on `0x8060` but | ||
| /// refuses a write of any of them with `InvalidArgument`, keeping the rate | ||
| /// its profile sets. | ||
| #[tokio::test] | ||
| async fn a_listed_rate_the_device_refuses_is_not_applied() { | ||
| let mouse = Arc::new(Mutex::new(Mouse { | ||
| interval_ms: 1, | ||
| refuses_writes: Some(INVALID_ARGUMENT), | ||
| ..Mouse::legacy() | ||
| })); | ||
| let shared = mouse_channel(&mouse, behind_receiver()).await; | ||
|
|
||
| let error = set_report_rate_on(&shared, ReportRate::new(500)) | ||
| .await | ||
| .expect_err("the onboard profile keeps 1 kHz"); | ||
|
Comment on lines
+326
to
+330
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Blocking. Both new tests await channel setup and device writes without a test-owned timeout or an expiry message. This violates the repository requirement that every async test wait have both. Wrap each test's async work in a bounded wait that names what stalled. The PR also omits the required counter-proof. State that reverting the refusal conversion makes Rule Used: Severity: medium. Every bug fix ships a regression test that fails without the fix, and the PR states the counter-proof (the reverted line or the killed mutant). A test that passes with the fix reverted is not a regression test: ask for inputs where ... (source) Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time! |
||
|
|
||
| assert_eq!( | ||
| error, | ||
| WriteError::ReportRateNotApplied { | ||
| requested: ReportRate::new(500), | ||
| actual: ReportRate::new(1000), | ||
| } | ||
| ); | ||
| assert_eq!(mouse.lock().expect("mouse lock").writes, [2]); | ||
| } | ||
|
|
||
| #[tokio::test] | ||
| async fn another_refusal_keeps_the_devices_error() { | ||
| let mouse = Arc::new(Mutex::new(Mouse { | ||
| refuses_writes: Some(BUSY), | ||
| ..Mouse::extended() | ||
| })); | ||
| let shared = mouse_channel(&mouse, direct()).await; | ||
|
|
||
| let error = set_report_rate_on(&shared, ReportRate::new(500)) | ||
| .await | ||
| .expect_err("the mouse is busy"); | ||
|
|
||
| assert_matches!( | ||
| error, | ||
| WriteError::HidppFeature { | ||
| operation: HidppOperation::WriteReportRate, | ||
| feature_hex: 0x8061, | ||
| kind: HidppFeatureErrorKind::Busy, | ||
| } | ||
| ); | ||
| } | ||
|
|
||
| #[tokio::test] | ||
| async fn an_acknowledged_write_whose_read_back_fails_counts_as_written() { | ||
| let mouse = Arc::new(Mutex::new(Mouse { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Blocking. If a wireless mouse returns
InvalidArgumentand then stops answering,refusal_of_listed_ratestarts a five-second read inside the agent's five-second write deadline. The outer deadline cancels the read before_ => errorcan return the original refusal. The caller getsRequestTimedOutinstead.This violates the repository requirement that each nested read fit inside its caller's deadline. Give this read a smaller budget and preserve the refusal on expiry. Add a
refused_write_with_silent_readback_preserves_refusaltest through the agent deadline.Rule Used: Severity: high. Every nested I/O step has its own timeout that fits inside the caller's deadline, and a test asserts the arithmetic. An advisory read the device may ignore (LED, hosts info) gets a budget of hundreds of milliseconds and reads as unkno... (source)