Skip to content
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

Refactors HID connections to support busy response #699

Merged
merged 5 commits into from
Sep 5, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions libraries/opensk/src/ctap/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3350,10 +3350,9 @@ mod test {
#[test]
fn test_check_user_presence_timeout() {
let mut env = TestEnv::default();
let now_ms = env.clock().access();
let clock = env.clock().clone();
env.user_presence().set(move || {
let mut locked_now_ms = now_ms.lock().unwrap();
*locked_now_ms += 100;
clock.advance(100);
Err(UserPresenceError::Timeout)
});
let response = check_user_presence(&mut env, DUMMY_CHANNEL);
Expand Down
18 changes: 9 additions & 9 deletions libraries/opensk/src/env/test/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,20 +48,20 @@ pub struct TestTimer {
end_ms: usize,
}

#[derive(Debug, Default)]
#[derive(Clone, Debug, Default)]
pub struct TestClock {
/// The current time, as advanced, in milliseconds.
now_ms: Arc<Mutex<usize>>,
}

impl TestClock {
pub fn advance(&mut self, milliseconds: usize) {
let mut locked_now_ms = self.now_ms.lock().unwrap();
*locked_now_ms += milliseconds;
pub fn now(&self) -> usize {
*self.now_ms.lock().unwrap()
}

pub fn access(&self) -> Arc<Mutex<usize>> {
self.now_ms.clone()
pub fn advance(&self, milliseconds: usize) {
let mut locked_now_ms = self.now_ms.lock().unwrap();
*locked_now_ms += milliseconds;
Comment on lines +63 to +64
Copy link
Member

Choose a reason for hiding this comment

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

fyi, this could have just been *self.now_ms.lock().unwrap() += milliseconds

}
}

Expand All @@ -70,18 +70,18 @@ impl Clock for TestClock {

fn make_timer(&mut self, milliseconds: usize) -> Self::Timer {
TestTimer {
end_ms: *self.now_ms.lock().unwrap() + milliseconds,
end_ms: self.now() + milliseconds,
}
}

fn is_elapsed(&mut self, timer: &Self::Timer) -> bool {
*self.now_ms.lock().unwrap() >= timer.end_ms
self.now() >= timer.end_ms
}

#[cfg(feature = "debug_ctap")]
fn timestamp_us(&mut self) -> usize {
// Unused, but let's implement something because it's easy.
*self.now_ms.lock().unwrap() * 1000
self.now() * 1000
}
}

Expand Down
Loading