1 // Copyright 2022, The Android Open Source Project 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 //! This module offers a mocked version of UciManager for testing. 16 //! 17 //! The mocked version of UciManager mimics the behavior of the UCI manager and 18 //! stacks below it, such that tests can be run on a target without the UWB 19 //! hardware. 20 use std::collections::VecDeque; 21 use std::sync::{Arc, Mutex}; 22 use std::time::Duration; 23 24 use async_trait::async_trait; 25 use tokio::sync::{mpsc, Notify}; 26 use tokio::time::timeout; 27 28 use crate::error::{Error, Result}; 29 use crate::params::uci_packets::{ 30 app_config_tlvs_eq, device_config_tlvs_eq, radar_config_tlvs_eq, AndroidRadarConfigResponse, 31 AppConfigTlv, AppConfigTlvType, CapTlv, ControleePhaseList, Controlees, CoreSetConfigResponse, 32 CountryCode, DeviceConfigId, DeviceConfigTlv, GetDeviceInfoResponse, PhaseList, PowerStats, 33 RadarConfigTlv, RadarConfigTlvType, RawUciMessage, ResetConfig, SessionId, SessionState, 34 SessionToken, SessionType, SessionUpdateControllerMulticastResponse, 35 SessionUpdateDtTagRangingRoundsResponse, SetAppConfigResponse, UpdateMulticastListAction, 36 UpdateTime, 37 }; 38 use crate::uci::notification::{ 39 CoreNotification, DataRcvNotification, RadarDataRcvNotification, SessionNotification, 40 UciNotification, 41 }; 42 use crate::uci::uci_logger::UciLoggerMode; 43 use crate::uci::uci_manager::UciManager; 44 45 #[derive(Clone)] 46 /// Mock version of UciManager for testing. 47 pub struct MockUciManager { 48 expected_calls: Arc<Mutex<VecDeque<ExpectedCall>>>, 49 expect_call_consumed: Arc<Notify>, 50 core_notf_sender: mpsc::UnboundedSender<CoreNotification>, 51 session_notf_sender: mpsc::UnboundedSender<SessionNotification>, 52 vendor_notf_sender: mpsc::UnboundedSender<RawUciMessage>, 53 data_rcv_notf_sender: mpsc::UnboundedSender<DataRcvNotification>, 54 radar_data_rcv_notf_sender: mpsc::UnboundedSender<RadarDataRcvNotification>, 55 } 56 57 #[allow(dead_code)] 58 impl MockUciManager { 59 /// Constructor. new() -> Self60 pub fn new() -> Self { 61 Self { 62 expected_calls: Default::default(), 63 expect_call_consumed: Default::default(), 64 core_notf_sender: mpsc::unbounded_channel().0, 65 session_notf_sender: mpsc::unbounded_channel().0, 66 vendor_notf_sender: mpsc::unbounded_channel().0, 67 data_rcv_notf_sender: mpsc::unbounded_channel().0, 68 radar_data_rcv_notf_sender: mpsc::unbounded_channel().0, 69 } 70 } 71 72 /// Wait until expected calls are done. 73 /// 74 /// Returns false if calls are pending after 1 second. wait_expected_calls_done(&mut self) -> bool75 pub async fn wait_expected_calls_done(&mut self) -> bool { 76 while !self.expected_calls.lock().unwrap().is_empty() { 77 if timeout(Duration::from_secs(1), self.expect_call_consumed.notified()).await.is_err() 78 { 79 return false; 80 } 81 } 82 true 83 } 84 85 /// Prepare Mock to expect for open_hal. 86 /// 87 /// MockUciManager expects call, returns out as response, followed by notfs sent. expect_open_hal( &mut self, notfs: Vec<UciNotification>, out: Result<GetDeviceInfoResponse>, )88 pub fn expect_open_hal( 89 &mut self, 90 notfs: Vec<UciNotification>, 91 out: Result<GetDeviceInfoResponse>, 92 ) { 93 self.expected_calls.lock().unwrap().push_back(ExpectedCall::OpenHal { notfs, out }); 94 } 95 96 /// Prepare Mock to expect for close_call. 97 /// 98 /// MockUciManager expects call with parameters, returns out as response. expect_close_hal(&mut self, expected_force: bool, out: Result<()>)99 pub fn expect_close_hal(&mut self, expected_force: bool, out: Result<()>) { 100 self.expected_calls 101 .lock() 102 .unwrap() 103 .push_back(ExpectedCall::CloseHal { expected_force, out }); 104 } 105 106 /// Prepare Mock to expect device_reset. 107 /// 108 /// MockUciManager expects call with parameters, returns out as response. expect_device_reset(&mut self, expected_reset_config: ResetConfig, out: Result<()>)109 pub fn expect_device_reset(&mut self, expected_reset_config: ResetConfig, out: Result<()>) { 110 self.expected_calls 111 .lock() 112 .unwrap() 113 .push_back(ExpectedCall::DeviceReset { expected_reset_config, out }); 114 } 115 116 /// Prepare Mock to expect core_get_device_info. 117 /// 118 /// MockUciManager expects call, returns out as response. expect_core_get_device_info(&mut self, out: Result<GetDeviceInfoResponse>)119 pub fn expect_core_get_device_info(&mut self, out: Result<GetDeviceInfoResponse>) { 120 self.expected_calls.lock().unwrap().push_back(ExpectedCall::CoreGetDeviceInfo { out }); 121 } 122 123 /// Prepare Mock to expect core_get_caps_info. 124 /// 125 /// MockUciManager expects call, returns out as response. expect_core_get_caps_info(&mut self, out: Result<Vec<CapTlv>>)126 pub fn expect_core_get_caps_info(&mut self, out: Result<Vec<CapTlv>>) { 127 self.expected_calls.lock().unwrap().push_back(ExpectedCall::CoreGetCapsInfo { out }); 128 } 129 130 /// Prepare Mock to expect core_set_config. 131 /// 132 /// MockUciManager expects call with parameters, returns out as response. expect_core_set_config( &mut self, expected_config_tlvs: Vec<DeviceConfigTlv>, out: Result<CoreSetConfigResponse>, )133 pub fn expect_core_set_config( 134 &mut self, 135 expected_config_tlvs: Vec<DeviceConfigTlv>, 136 out: Result<CoreSetConfigResponse>, 137 ) { 138 self.expected_calls 139 .lock() 140 .unwrap() 141 .push_back(ExpectedCall::CoreSetConfig { expected_config_tlvs, out }); 142 } 143 144 /// Prepare Mock to expect core_get_config. 145 /// 146 /// MockUciManager expects call with parameters, returns out as response. expect_core_get_config( &mut self, expected_config_ids: Vec<DeviceConfigId>, out: Result<Vec<DeviceConfigTlv>>, )147 pub fn expect_core_get_config( 148 &mut self, 149 expected_config_ids: Vec<DeviceConfigId>, 150 out: Result<Vec<DeviceConfigTlv>>, 151 ) { 152 self.expected_calls 153 .lock() 154 .unwrap() 155 .push_back(ExpectedCall::CoreGetConfig { expected_config_ids, out }); 156 } 157 158 /// Prepare Mock to expect core_query_uwb_timestamp. 159 /// 160 /// MockUciManager expects call with parameters, returns out as response. expect_core_query_uwb_timestamp(&mut self, out: Result<u64>)161 pub fn expect_core_query_uwb_timestamp(&mut self, out: Result<u64>) { 162 self.expected_calls.lock().unwrap().push_back(ExpectedCall::CoreQueryTimeStamp { out }); 163 } 164 165 /// Prepare Mock to expect session_init. 166 /// 167 /// MockUciManager expects call with parameters, returns out as response, followed by notfs 168 /// sent. expect_session_init( &mut self, expected_session_id: SessionId, expected_session_type: SessionType, notfs: Vec<UciNotification>, out: Result<()>, )169 pub fn expect_session_init( 170 &mut self, 171 expected_session_id: SessionId, 172 expected_session_type: SessionType, 173 notfs: Vec<UciNotification>, 174 out: Result<()>, 175 ) { 176 self.expected_calls.lock().unwrap().push_back(ExpectedCall::SessionInit { 177 expected_session_id, 178 expected_session_type, 179 notfs, 180 out, 181 }); 182 } 183 184 /// Prepare Mock to expect session_deinit. 185 /// 186 /// MockUciManager expects call with parameters, returns out as response, followed by notfs 187 /// sent. expect_session_deinit( &mut self, expected_session_id: SessionId, notfs: Vec<UciNotification>, out: Result<()>, )188 pub fn expect_session_deinit( 189 &mut self, 190 expected_session_id: SessionId, 191 notfs: Vec<UciNotification>, 192 out: Result<()>, 193 ) { 194 self.expected_calls.lock().unwrap().push_back(ExpectedCall::SessionDeinit { 195 expected_session_id, 196 notfs, 197 out, 198 }); 199 } 200 201 /// Prepare Mock to expect session_set_app_config. 202 /// 203 /// MockUciManager expects call with parameters, returns out as response, followed by notfs 204 /// sent. expect_session_set_app_config( &mut self, expected_session_id: SessionId, expected_config_tlvs: Vec<AppConfigTlv>, notfs: Vec<UciNotification>, out: Result<SetAppConfigResponse>, )205 pub fn expect_session_set_app_config( 206 &mut self, 207 expected_session_id: SessionId, 208 expected_config_tlvs: Vec<AppConfigTlv>, 209 notfs: Vec<UciNotification>, 210 out: Result<SetAppConfigResponse>, 211 ) { 212 self.expected_calls.lock().unwrap().push_back(ExpectedCall::SessionSetAppConfig { 213 expected_session_id, 214 expected_config_tlvs, 215 notfs, 216 out, 217 }); 218 } 219 220 /// Prepare Mock to expect session_get_app_config. 221 /// 222 /// MockUciManager expects call with parameters, returns out as response. expect_session_get_app_config( &mut self, expected_session_id: SessionId, expected_config_ids: Vec<AppConfigTlvType>, out: Result<Vec<AppConfigTlv>>, )223 pub fn expect_session_get_app_config( 224 &mut self, 225 expected_session_id: SessionId, 226 expected_config_ids: Vec<AppConfigTlvType>, 227 out: Result<Vec<AppConfigTlv>>, 228 ) { 229 self.expected_calls.lock().unwrap().push_back(ExpectedCall::SessionGetAppConfig { 230 expected_session_id, 231 expected_config_ids, 232 out, 233 }); 234 } 235 236 /// Prepare Mock to expect session_get_count. 237 /// 238 /// MockUciManager expects call with parameters, returns out as response. expect_session_get_count(&mut self, out: Result<u8>)239 pub fn expect_session_get_count(&mut self, out: Result<u8>) { 240 self.expected_calls.lock().unwrap().push_back(ExpectedCall::SessionGetCount { out }); 241 } 242 243 /// Prepare Mock to expect session_get_state. 244 /// 245 /// MockUciManager expects call with parameters, returns out as response. expect_session_get_state( &mut self, expected_session_id: SessionId, out: Result<SessionState>, )246 pub fn expect_session_get_state( 247 &mut self, 248 expected_session_id: SessionId, 249 out: Result<SessionState>, 250 ) { 251 self.expected_calls 252 .lock() 253 .unwrap() 254 .push_back(ExpectedCall::SessionGetState { expected_session_id, out }); 255 } 256 257 /// Prepare Mock to expect update_controller_multicast_list. 258 /// 259 /// MockUciManager expects call with parameters, returns out as response, followed by notfs 260 /// sent. expect_session_update_controller_multicast_list( &mut self, expected_session_id: SessionId, expected_action: UpdateMulticastListAction, expected_controlees: Controlees, notfs: Vec<UciNotification>, out: Result<SessionUpdateControllerMulticastResponse>, )261 pub fn expect_session_update_controller_multicast_list( 262 &mut self, 263 expected_session_id: SessionId, 264 expected_action: UpdateMulticastListAction, 265 expected_controlees: Controlees, 266 notfs: Vec<UciNotification>, 267 out: Result<SessionUpdateControllerMulticastResponse>, 268 ) { 269 self.expected_calls.lock().unwrap().push_back( 270 ExpectedCall::SessionUpdateControllerMulticastList { 271 expected_session_id, 272 expected_action, 273 expected_controlees, 274 notfs, 275 out, 276 }, 277 ); 278 } 279 280 /// Prepare Mock to expect session_update_active_rounds_dt_tag. 281 /// 282 /// MockUciManager expects call with parameters, returns out as response. expect_session_update_dt_tag_ranging_rounds( &mut self, expected_session_id: u32, expected_ranging_round_indexes: Vec<u8>, out: Result<SessionUpdateDtTagRangingRoundsResponse>, )283 pub fn expect_session_update_dt_tag_ranging_rounds( 284 &mut self, 285 expected_session_id: u32, 286 expected_ranging_round_indexes: Vec<u8>, 287 out: Result<SessionUpdateDtTagRangingRoundsResponse>, 288 ) { 289 self.expected_calls.lock().unwrap().push_back( 290 ExpectedCall::SessionUpdateDtTagRangingRounds { 291 expected_session_id, 292 expected_ranging_round_indexes, 293 out, 294 }, 295 ); 296 } 297 298 /// Prepare Mock to expect for session_query_max_data_size. 299 /// 300 /// MockUciManager expects call, returns out as response. expect_session_query_max_data_size( &mut self, expected_session_id: SessionId, out: Result<u16>, )301 pub fn expect_session_query_max_data_size( 302 &mut self, 303 expected_session_id: SessionId, 304 out: Result<u16>, 305 ) { 306 self.expected_calls 307 .lock() 308 .unwrap() 309 .push_back(ExpectedCall::SessionQueryMaxDataSize { expected_session_id, out }); 310 } 311 312 /// Prepare Mock to expect range_start. 313 /// 314 /// MockUciManager expects call with parameters, returns out as response, followed by notfs 315 /// sent. expect_range_start( &mut self, expected_session_id: SessionId, notfs: Vec<UciNotification>, out: Result<()>, )316 pub fn expect_range_start( 317 &mut self, 318 expected_session_id: SessionId, 319 notfs: Vec<UciNotification>, 320 out: Result<()>, 321 ) { 322 self.expected_calls.lock().unwrap().push_back(ExpectedCall::RangeStart { 323 expected_session_id, 324 notfs, 325 out, 326 }); 327 } 328 329 /// Prepare Mock to expect range_stop. 330 /// 331 /// MockUciManager expects call with parameters, returns out as response, followed by notfs 332 /// sent. expect_range_stop( &mut self, expected_session_id: SessionId, notfs: Vec<UciNotification>, out: Result<()>, )333 pub fn expect_range_stop( 334 &mut self, 335 expected_session_id: SessionId, 336 notfs: Vec<UciNotification>, 337 out: Result<()>, 338 ) { 339 self.expected_calls.lock().unwrap().push_back(ExpectedCall::RangeStop { 340 expected_session_id, 341 notfs, 342 out, 343 }); 344 } 345 346 /// Prepare Mock to expect range_get_ranging_count. 347 /// 348 /// MockUciManager expects call with parameters, returns out as response. expect_range_get_ranging_count( &mut self, expected_session_id: SessionId, out: Result<usize>, )349 pub fn expect_range_get_ranging_count( 350 &mut self, 351 expected_session_id: SessionId, 352 out: Result<usize>, 353 ) { 354 self.expected_calls 355 .lock() 356 .unwrap() 357 .push_back(ExpectedCall::RangeGetRangingCount { expected_session_id, out }); 358 } 359 360 /// Prepare Mock to expect android_set_country_code. 361 /// 362 /// MockUciManager expects call with parameters, returns out as response. expect_android_set_country_code( &mut self, expected_country_code: CountryCode, out: Result<()>, )363 pub fn expect_android_set_country_code( 364 &mut self, 365 expected_country_code: CountryCode, 366 out: Result<()>, 367 ) { 368 self.expected_calls 369 .lock() 370 .unwrap() 371 .push_back(ExpectedCall::AndroidSetCountryCode { expected_country_code, out }); 372 } 373 374 /// Prepare Mock to expect android_set_country_code. 375 /// 376 /// MockUciManager expects call with parameters, returns out as response. expect_android_get_power_stats(&mut self, out: Result<PowerStats>)377 pub fn expect_android_get_power_stats(&mut self, out: Result<PowerStats>) { 378 self.expected_calls.lock().unwrap().push_back(ExpectedCall::AndroidGetPowerStats { out }); 379 } 380 381 /// Prepare Mock to expect android_set_radar_config. 382 /// 383 /// MockUciManager expects call with parameters, returns out as response, followed by notfs 384 /// sent. expect_android_set_radar_config( &mut self, expected_session_id: SessionId, expected_config_tlvs: Vec<RadarConfigTlv>, notfs: Vec<UciNotification>, out: Result<AndroidRadarConfigResponse>, )385 pub fn expect_android_set_radar_config( 386 &mut self, 387 expected_session_id: SessionId, 388 expected_config_tlvs: Vec<RadarConfigTlv>, 389 notfs: Vec<UciNotification>, 390 out: Result<AndroidRadarConfigResponse>, 391 ) { 392 self.expected_calls.lock().unwrap().push_back(ExpectedCall::AndroidSetRadarConfig { 393 expected_session_id, 394 expected_config_tlvs, 395 notfs, 396 out, 397 }); 398 } 399 400 /// Prepare Mock to expect android_get_app_config. 401 /// 402 /// MockUciManager expects call with parameters, returns out as response. expect_android_get_radar_config( &mut self, expected_session_id: SessionId, expected_config_ids: Vec<RadarConfigTlvType>, out: Result<Vec<RadarConfigTlv>>, )403 pub fn expect_android_get_radar_config( 404 &mut self, 405 expected_session_id: SessionId, 406 expected_config_ids: Vec<RadarConfigTlvType>, 407 out: Result<Vec<RadarConfigTlv>>, 408 ) { 409 self.expected_calls.lock().unwrap().push_back(ExpectedCall::AndroidGetRadarConfig { 410 expected_session_id, 411 expected_config_ids, 412 out, 413 }); 414 } 415 416 /// Prepare Mock to expect raw_uci_cmd. 417 /// 418 /// MockUciManager expects call with parameters, returns out as response. expect_raw_uci_cmd( &mut self, expected_mt: u32, expected_gid: u32, expected_oid: u32, expected_payload: Vec<u8>, out: Result<RawUciMessage>, )419 pub fn expect_raw_uci_cmd( 420 &mut self, 421 expected_mt: u32, 422 expected_gid: u32, 423 expected_oid: u32, 424 expected_payload: Vec<u8>, 425 out: Result<RawUciMessage>, 426 ) { 427 self.expected_calls.lock().unwrap().push_back(ExpectedCall::RawUciCmd { 428 expected_mt, 429 expected_gid, 430 expected_oid, 431 expected_payload, 432 out, 433 }); 434 } 435 436 /// Prepare Mock to expect send_data_packet. 437 /// 438 /// MockUciManager expects call with parameters, returns out as response. expect_send_data_packet( &mut self, expected_session_id: SessionId, expected_address: Vec<u8>, expected_uci_sequence_num: u16, expected_app_payload_data: Vec<u8>, out: Result<()>, )439 pub fn expect_send_data_packet( 440 &mut self, 441 expected_session_id: SessionId, 442 expected_address: Vec<u8>, 443 expected_uci_sequence_num: u16, 444 expected_app_payload_data: Vec<u8>, 445 out: Result<()>, 446 ) { 447 self.expected_calls.lock().unwrap().push_back(ExpectedCall::SendDataPacket { 448 expected_session_id, 449 expected_address, 450 expected_uci_sequence_num, 451 expected_app_payload_data, 452 out, 453 }); 454 } 455 456 /// Prepare Mock to expect session_set_hybrid_controller_config. 457 /// 458 /// MockUciManager expects call with parameters, returns out as response expect_session_set_hybrid_controller_config( &mut self, expected_session_id: SessionId, expected_message_control: u8, expected_number_of_phases: u8, expected_update_time: UpdateTime, expected_phase_list: PhaseList, out: Result<()>, )459 pub fn expect_session_set_hybrid_controller_config( 460 &mut self, 461 expected_session_id: SessionId, 462 expected_message_control: u8, 463 expected_number_of_phases: u8, 464 expected_update_time: UpdateTime, 465 expected_phase_list: PhaseList, 466 out: Result<()>, 467 ) { 468 self.expected_calls.lock().unwrap().push_back( 469 ExpectedCall::SessionSetHybridControllerConfig { 470 expected_session_id, 471 expected_message_control, 472 expected_number_of_phases, 473 expected_update_time, 474 expected_phase_list, 475 out, 476 }, 477 ); 478 } 479 480 /// Prepare Mock to expect session_set_hybrid_controlee_config. 481 /// 482 /// MockUciManager expects call with parameters, returns out as response expect_session_set_hybrid_controlee_config( &mut self, expected_session_id: SessionId, expected_controlee_phase_list: Vec<ControleePhaseList>, out: Result<()>, )483 pub fn expect_session_set_hybrid_controlee_config( 484 &mut self, 485 expected_session_id: SessionId, 486 expected_controlee_phase_list: Vec<ControleePhaseList>, 487 out: Result<()>, 488 ) { 489 self.expected_calls.lock().unwrap().push_back( 490 ExpectedCall::SessionSetHybridControleeConfig { 491 expected_session_id, 492 expected_controlee_phase_list, 493 out, 494 }, 495 ); 496 } 497 498 /// Prepare Mock to expect session_data_transfer_phase_config 499 /// MockUciManager expects call with parameters, returns out as response 500 #[allow(clippy::too_many_arguments)] expect_session_data_transfer_phase_config( &mut self, expected_session_id: SessionId, expected_dtpcm_repetition: u8, expected_data_transfer_control: u8, expected_dtpml_size: u8, expected_mac_address: Vec<u8>, expected_slot_bitmap: Vec<u8>, out: Result<()>, )501 pub fn expect_session_data_transfer_phase_config( 502 &mut self, 503 expected_session_id: SessionId, 504 expected_dtpcm_repetition: u8, 505 expected_data_transfer_control: u8, 506 expected_dtpml_size: u8, 507 expected_mac_address: Vec<u8>, 508 expected_slot_bitmap: Vec<u8>, 509 out: Result<()>, 510 ) { 511 self.expected_calls.lock().unwrap().push_back( 512 ExpectedCall::SessionDataTransferPhaseConfig { 513 expected_session_id, 514 expected_dtpcm_repetition, 515 expected_data_transfer_control, 516 expected_dtpml_size, 517 expected_mac_address, 518 expected_slot_bitmap, 519 out, 520 }, 521 ); 522 } 523 524 /// Call Mock to send notifications. send_notifications(&self, notfs: Vec<UciNotification>)525 fn send_notifications(&self, notfs: Vec<UciNotification>) { 526 for notf in notfs.into_iter() { 527 match notf { 528 UciNotification::Core(notf) => { 529 let _ = self.core_notf_sender.send(notf); 530 } 531 UciNotification::Session(notf) => { 532 let _ = self.session_notf_sender.send(notf); 533 } 534 UciNotification::Vendor(notf) => { 535 let _ = self.vendor_notf_sender.send(notf); 536 } 537 } 538 } 539 } 540 } 541 542 impl Default for MockUciManager { default() -> Self543 fn default() -> Self { 544 Self::new() 545 } 546 } 547 548 #[async_trait] 549 impl UciManager for MockUciManager { set_logger_mode(&self, _logger_mode: UciLoggerMode) -> Result<()>550 async fn set_logger_mode(&self, _logger_mode: UciLoggerMode) -> Result<()> { 551 Ok(()) 552 } set_core_notification_sender( &mut self, core_notf_sender: mpsc::UnboundedSender<CoreNotification>, )553 async fn set_core_notification_sender( 554 &mut self, 555 core_notf_sender: mpsc::UnboundedSender<CoreNotification>, 556 ) { 557 self.core_notf_sender = core_notf_sender; 558 } set_session_notification_sender( &mut self, session_notf_sender: mpsc::UnboundedSender<SessionNotification>, )559 async fn set_session_notification_sender( 560 &mut self, 561 session_notf_sender: mpsc::UnboundedSender<SessionNotification>, 562 ) { 563 self.session_notf_sender = session_notf_sender; 564 } set_vendor_notification_sender( &mut self, vendor_notf_sender: mpsc::UnboundedSender<RawUciMessage>, )565 async fn set_vendor_notification_sender( 566 &mut self, 567 vendor_notf_sender: mpsc::UnboundedSender<RawUciMessage>, 568 ) { 569 self.vendor_notf_sender = vendor_notf_sender; 570 } set_data_rcv_notification_sender( &mut self, data_rcv_notf_sender: mpsc::UnboundedSender<DataRcvNotification>, )571 async fn set_data_rcv_notification_sender( 572 &mut self, 573 data_rcv_notf_sender: mpsc::UnboundedSender<DataRcvNotification>, 574 ) { 575 self.data_rcv_notf_sender = data_rcv_notf_sender; 576 } set_radar_data_rcv_notification_sender( &mut self, radar_data_rcv_notf_sender: mpsc::UnboundedSender<RadarDataRcvNotification>, )577 async fn set_radar_data_rcv_notification_sender( 578 &mut self, 579 radar_data_rcv_notf_sender: mpsc::UnboundedSender<RadarDataRcvNotification>, 580 ) { 581 self.radar_data_rcv_notf_sender = radar_data_rcv_notf_sender; 582 } 583 open_hal(&self) -> Result<GetDeviceInfoResponse>584 async fn open_hal(&self) -> Result<GetDeviceInfoResponse> { 585 let mut expected_calls = self.expected_calls.lock().unwrap(); 586 match expected_calls.pop_front() { 587 Some(ExpectedCall::OpenHal { notfs, out }) => { 588 self.expect_call_consumed.notify_one(); 589 self.send_notifications(notfs); 590 out 591 } 592 Some(call) => { 593 expected_calls.push_front(call); 594 Err(Error::MockUndefined) 595 } 596 None => Err(Error::MockUndefined), 597 } 598 } 599 close_hal(&self, force: bool) -> Result<()>600 async fn close_hal(&self, force: bool) -> Result<()> { 601 let mut expected_calls = self.expected_calls.lock().unwrap(); 602 match expected_calls.pop_front() { 603 Some(ExpectedCall::CloseHal { expected_force, out }) if expected_force == force => { 604 self.expect_call_consumed.notify_one(); 605 out 606 } 607 Some(call) => { 608 expected_calls.push_front(call); 609 Err(Error::MockUndefined) 610 } 611 None => Err(Error::MockUndefined), 612 } 613 } 614 device_reset(&self, reset_config: ResetConfig) -> Result<()>615 async fn device_reset(&self, reset_config: ResetConfig) -> Result<()> { 616 let mut expected_calls = self.expected_calls.lock().unwrap(); 617 match expected_calls.pop_front() { 618 Some(ExpectedCall::DeviceReset { expected_reset_config, out }) 619 if expected_reset_config == reset_config => 620 { 621 self.expect_call_consumed.notify_one(); 622 out 623 } 624 Some(call) => { 625 expected_calls.push_front(call); 626 Err(Error::MockUndefined) 627 } 628 None => Err(Error::MockUndefined), 629 } 630 } 631 core_get_device_info(&self) -> Result<GetDeviceInfoResponse>632 async fn core_get_device_info(&self) -> Result<GetDeviceInfoResponse> { 633 let mut expected_calls = self.expected_calls.lock().unwrap(); 634 match expected_calls.pop_front() { 635 Some(ExpectedCall::CoreGetDeviceInfo { out }) => { 636 self.expect_call_consumed.notify_one(); 637 out 638 } 639 Some(call) => { 640 expected_calls.push_front(call); 641 Err(Error::MockUndefined) 642 } 643 None => Err(Error::MockUndefined), 644 } 645 } 646 core_get_caps_info(&self) -> Result<Vec<CapTlv>>647 async fn core_get_caps_info(&self) -> Result<Vec<CapTlv>> { 648 let mut expected_calls = self.expected_calls.lock().unwrap(); 649 match expected_calls.pop_front() { 650 Some(ExpectedCall::CoreGetCapsInfo { out }) => { 651 self.expect_call_consumed.notify_one(); 652 out 653 } 654 Some(call) => { 655 expected_calls.push_front(call); 656 Err(Error::MockUndefined) 657 } 658 None => Err(Error::MockUndefined), 659 } 660 } 661 core_set_config( &self, config_tlvs: Vec<DeviceConfigTlv>, ) -> Result<CoreSetConfigResponse>662 async fn core_set_config( 663 &self, 664 config_tlvs: Vec<DeviceConfigTlv>, 665 ) -> Result<CoreSetConfigResponse> { 666 let mut expected_calls = self.expected_calls.lock().unwrap(); 667 match expected_calls.pop_front() { 668 Some(ExpectedCall::CoreSetConfig { expected_config_tlvs, out }) 669 if device_config_tlvs_eq(&expected_config_tlvs, &config_tlvs) => 670 { 671 self.expect_call_consumed.notify_one(); 672 out 673 } 674 Some(call) => { 675 expected_calls.push_front(call); 676 Err(Error::MockUndefined) 677 } 678 None => Err(Error::MockUndefined), 679 } 680 } 681 core_get_config( &self, config_ids: Vec<DeviceConfigId>, ) -> Result<Vec<DeviceConfigTlv>>682 async fn core_get_config( 683 &self, 684 config_ids: Vec<DeviceConfigId>, 685 ) -> Result<Vec<DeviceConfigTlv>> { 686 let mut expected_calls = self.expected_calls.lock().unwrap(); 687 match expected_calls.pop_front() { 688 Some(ExpectedCall::CoreGetConfig { expected_config_ids, out }) 689 if expected_config_ids == config_ids => 690 { 691 self.expect_call_consumed.notify_one(); 692 out 693 } 694 Some(call) => { 695 expected_calls.push_front(call); 696 Err(Error::MockUndefined) 697 } 698 None => Err(Error::MockUndefined), 699 } 700 } 701 core_query_uwb_timestamp(&self) -> Result<u64>702 async fn core_query_uwb_timestamp(&self) -> Result<u64> { 703 let mut expected_calls = self.expected_calls.lock().unwrap(); 704 match expected_calls.pop_front() { 705 Some(ExpectedCall::CoreQueryTimeStamp { out }) => { 706 self.expect_call_consumed.notify_one(); 707 out 708 } 709 Some(call) => { 710 expected_calls.push_front(call); 711 Err(Error::MockUndefined) 712 } 713 None => Err(Error::MockUndefined), 714 } 715 } 716 session_init(&self, session_id: SessionId, session_type: SessionType) -> Result<()>717 async fn session_init(&self, session_id: SessionId, session_type: SessionType) -> Result<()> { 718 let mut expected_calls = self.expected_calls.lock().unwrap(); 719 match expected_calls.pop_front() { 720 Some(ExpectedCall::SessionInit { 721 expected_session_id, 722 expected_session_type, 723 notfs, 724 out, 725 }) if expected_session_id == session_id && expected_session_type == session_type => { 726 self.expect_call_consumed.notify_one(); 727 self.send_notifications(notfs); 728 out 729 } 730 Some(call) => { 731 expected_calls.push_front(call); 732 Err(Error::MockUndefined) 733 } 734 None => Err(Error::MockUndefined), 735 } 736 } 737 session_deinit(&self, session_id: SessionId) -> Result<()>738 async fn session_deinit(&self, session_id: SessionId) -> Result<()> { 739 let mut expected_calls = self.expected_calls.lock().unwrap(); 740 match expected_calls.pop_front() { 741 Some(ExpectedCall::SessionDeinit { expected_session_id, notfs, out }) 742 if expected_session_id == session_id => 743 { 744 self.expect_call_consumed.notify_one(); 745 self.send_notifications(notfs); 746 out 747 } 748 Some(call) => { 749 expected_calls.push_front(call); 750 Err(Error::MockUndefined) 751 } 752 None => Err(Error::MockUndefined), 753 } 754 } 755 session_set_app_config( &self, session_id: SessionId, config_tlvs: Vec<AppConfigTlv>, ) -> Result<SetAppConfigResponse>756 async fn session_set_app_config( 757 &self, 758 session_id: SessionId, 759 config_tlvs: Vec<AppConfigTlv>, 760 ) -> Result<SetAppConfigResponse> { 761 let mut expected_calls = self.expected_calls.lock().unwrap(); 762 match expected_calls.pop_front() { 763 Some(ExpectedCall::SessionSetAppConfig { 764 expected_session_id, 765 expected_config_tlvs, 766 notfs, 767 out, 768 }) if expected_session_id == session_id 769 && app_config_tlvs_eq(&expected_config_tlvs, &config_tlvs) => 770 { 771 self.expect_call_consumed.notify_one(); 772 self.send_notifications(notfs); 773 out 774 } 775 Some(call) => { 776 expected_calls.push_front(call); 777 Err(Error::MockUndefined) 778 } 779 None => Err(Error::MockUndefined), 780 } 781 } 782 session_get_app_config( &self, session_id: SessionId, config_ids: Vec<AppConfigTlvType>, ) -> Result<Vec<AppConfigTlv>>783 async fn session_get_app_config( 784 &self, 785 session_id: SessionId, 786 config_ids: Vec<AppConfigTlvType>, 787 ) -> Result<Vec<AppConfigTlv>> { 788 let mut expected_calls = self.expected_calls.lock().unwrap(); 789 match expected_calls.pop_front() { 790 Some(ExpectedCall::SessionGetAppConfig { 791 expected_session_id, 792 expected_config_ids, 793 out, 794 }) if expected_session_id == session_id && expected_config_ids == config_ids => { 795 self.expect_call_consumed.notify_one(); 796 out 797 } 798 Some(call) => { 799 expected_calls.push_front(call); 800 Err(Error::MockUndefined) 801 } 802 None => Err(Error::MockUndefined), 803 } 804 } 805 session_get_count(&self) -> Result<u8>806 async fn session_get_count(&self) -> Result<u8> { 807 let mut expected_calls = self.expected_calls.lock().unwrap(); 808 match expected_calls.pop_front() { 809 Some(ExpectedCall::SessionGetCount { out }) => { 810 self.expect_call_consumed.notify_one(); 811 out 812 } 813 Some(call) => { 814 expected_calls.push_front(call); 815 Err(Error::MockUndefined) 816 } 817 None => Err(Error::MockUndefined), 818 } 819 } 820 session_get_state(&self, session_id: SessionId) -> Result<SessionState>821 async fn session_get_state(&self, session_id: SessionId) -> Result<SessionState> { 822 let mut expected_calls = self.expected_calls.lock().unwrap(); 823 match expected_calls.pop_front() { 824 Some(ExpectedCall::SessionGetState { expected_session_id, out }) 825 if expected_session_id == session_id => 826 { 827 self.expect_call_consumed.notify_one(); 828 out 829 } 830 Some(call) => { 831 expected_calls.push_front(call); 832 Err(Error::MockUndefined) 833 } 834 None => Err(Error::MockUndefined), 835 } 836 } 837 session_update_controller_multicast_list( &self, session_id: SessionId, action: UpdateMulticastListAction, controlees: Controlees, _is_multicast_list_ntf_v2_supported: bool, _is_multicast_list_rsp_v2_supported: bool, ) -> Result<SessionUpdateControllerMulticastResponse>838 async fn session_update_controller_multicast_list( 839 &self, 840 session_id: SessionId, 841 action: UpdateMulticastListAction, 842 controlees: Controlees, 843 _is_multicast_list_ntf_v2_supported: bool, 844 _is_multicast_list_rsp_v2_supported: bool, 845 ) -> Result<SessionUpdateControllerMulticastResponse> { 846 let mut expected_calls = self.expected_calls.lock().unwrap(); 847 match expected_calls.pop_front() { 848 Some(ExpectedCall::SessionUpdateControllerMulticastList { 849 expected_session_id, 850 expected_action, 851 expected_controlees, 852 notfs, 853 out, 854 }) if expected_session_id == session_id 855 && expected_action == action 856 && expected_controlees == controlees => 857 { 858 self.expect_call_consumed.notify_one(); 859 self.send_notifications(notfs); 860 out 861 } 862 Some(call) => { 863 expected_calls.push_front(call); 864 Err(Error::MockUndefined) 865 } 866 None => Err(Error::MockUndefined), 867 } 868 } 869 session_data_transfer_phase_config( &self, session_id: SessionId, dtpcm_repetition: u8, data_transfer_control: u8, dtpml_size: u8, mac_address: Vec<u8>, slot_bitmap: Vec<u8>, ) -> Result<()>870 async fn session_data_transfer_phase_config( 871 &self, 872 session_id: SessionId, 873 dtpcm_repetition: u8, 874 data_transfer_control: u8, 875 dtpml_size: u8, 876 mac_address: Vec<u8>, 877 slot_bitmap: Vec<u8>, 878 ) -> Result<()> { 879 let mut expected_calls = self.expected_calls.lock().unwrap(); 880 match expected_calls.pop_front() { 881 Some(ExpectedCall::SessionDataTransferPhaseConfig { 882 expected_session_id, 883 expected_dtpcm_repetition, 884 expected_data_transfer_control, 885 expected_dtpml_size, 886 expected_mac_address, 887 expected_slot_bitmap, 888 out, 889 }) if expected_session_id == session_id 890 && expected_dtpcm_repetition == dtpcm_repetition 891 && expected_data_transfer_control == data_transfer_control 892 && expected_dtpml_size == dtpml_size 893 && expected_mac_address == mac_address 894 && expected_slot_bitmap == slot_bitmap => 895 { 896 self.expect_call_consumed.notify_one(); 897 out 898 } 899 Some(call) => { 900 expected_calls.push_front(call); 901 Err(Error::MockUndefined) 902 } 903 None => Err(Error::MockUndefined), 904 } 905 } 906 session_update_dt_tag_ranging_rounds( &self, session_id: u32, ranging_round_indexes: Vec<u8>, ) -> Result<SessionUpdateDtTagRangingRoundsResponse>907 async fn session_update_dt_tag_ranging_rounds( 908 &self, 909 session_id: u32, 910 ranging_round_indexes: Vec<u8>, 911 ) -> Result<SessionUpdateDtTagRangingRoundsResponse> { 912 let mut expected_calls = self.expected_calls.lock().unwrap(); 913 match expected_calls.pop_front() { 914 Some(ExpectedCall::SessionUpdateDtTagRangingRounds { 915 expected_session_id, 916 expected_ranging_round_indexes, 917 out, 918 }) if expected_session_id == session_id 919 && expected_ranging_round_indexes == ranging_round_indexes => 920 { 921 self.expect_call_consumed.notify_one(); 922 out 923 } 924 Some(call) => { 925 expected_calls.push_front(call); 926 Err(Error::MockUndefined) 927 } 928 None => Err(Error::MockUndefined), 929 } 930 } 931 session_query_max_data_size(&self, session_id: SessionId) -> Result<u16>932 async fn session_query_max_data_size(&self, session_id: SessionId) -> Result<u16> { 933 let mut expected_calls = self.expected_calls.lock().unwrap(); 934 match expected_calls.pop_front() { 935 Some(ExpectedCall::SessionQueryMaxDataSize { expected_session_id, out }) 936 if expected_session_id == session_id => 937 { 938 self.expect_call_consumed.notify_one(); 939 out 940 } 941 Some(call) => { 942 expected_calls.push_front(call); 943 Err(Error::MockUndefined) 944 } 945 None => Err(Error::MockUndefined), 946 } 947 } 948 range_start(&self, session_id: SessionId) -> Result<()>949 async fn range_start(&self, session_id: SessionId) -> Result<()> { 950 let mut expected_calls = self.expected_calls.lock().unwrap(); 951 match expected_calls.pop_front() { 952 Some(ExpectedCall::RangeStart { expected_session_id, notfs, out }) 953 if expected_session_id == session_id => 954 { 955 self.expect_call_consumed.notify_one(); 956 self.send_notifications(notfs); 957 out 958 } 959 Some(call) => { 960 expected_calls.push_front(call); 961 Err(Error::MockUndefined) 962 } 963 None => Err(Error::MockUndefined), 964 } 965 } 966 range_stop(&self, session_id: SessionId) -> Result<()>967 async fn range_stop(&self, session_id: SessionId) -> Result<()> { 968 let mut expected_calls = self.expected_calls.lock().unwrap(); 969 match expected_calls.pop_front() { 970 Some(ExpectedCall::RangeStop { expected_session_id, notfs, out }) 971 if expected_session_id == session_id => 972 { 973 self.expect_call_consumed.notify_one(); 974 self.send_notifications(notfs); 975 out 976 } 977 Some(call) => { 978 expected_calls.push_front(call); 979 Err(Error::MockUndefined) 980 } 981 None => Err(Error::MockUndefined), 982 } 983 } 984 range_get_ranging_count(&self, session_id: SessionId) -> Result<usize>985 async fn range_get_ranging_count(&self, session_id: SessionId) -> Result<usize> { 986 let mut expected_calls = self.expected_calls.lock().unwrap(); 987 match expected_calls.pop_front() { 988 Some(ExpectedCall::RangeGetRangingCount { expected_session_id, out }) 989 if expected_session_id == session_id => 990 { 991 self.expect_call_consumed.notify_one(); 992 out 993 } 994 Some(call) => { 995 expected_calls.push_front(call); 996 Err(Error::MockUndefined) 997 } 998 None => Err(Error::MockUndefined), 999 } 1000 } 1001 android_set_country_code(&self, country_code: CountryCode) -> Result<()>1002 async fn android_set_country_code(&self, country_code: CountryCode) -> Result<()> { 1003 let mut expected_calls = self.expected_calls.lock().unwrap(); 1004 match expected_calls.pop_front() { 1005 Some(ExpectedCall::AndroidSetCountryCode { expected_country_code, out }) 1006 if expected_country_code == country_code => 1007 { 1008 self.expect_call_consumed.notify_one(); 1009 out 1010 } 1011 Some(call) => { 1012 expected_calls.push_front(call); 1013 Err(Error::MockUndefined) 1014 } 1015 None => Err(Error::MockUndefined), 1016 } 1017 } 1018 android_get_power_stats(&self) -> Result<PowerStats>1019 async fn android_get_power_stats(&self) -> Result<PowerStats> { 1020 let mut expected_calls = self.expected_calls.lock().unwrap(); 1021 match expected_calls.pop_front() { 1022 Some(ExpectedCall::AndroidGetPowerStats { out }) => { 1023 self.expect_call_consumed.notify_one(); 1024 out 1025 } 1026 Some(call) => { 1027 expected_calls.push_front(call); 1028 Err(Error::MockUndefined) 1029 } 1030 None => Err(Error::MockUndefined), 1031 } 1032 } 1033 android_set_radar_config( &self, session_id: SessionId, config_tlvs: Vec<RadarConfigTlv>, ) -> Result<AndroidRadarConfigResponse>1034 async fn android_set_radar_config( 1035 &self, 1036 session_id: SessionId, 1037 config_tlvs: Vec<RadarConfigTlv>, 1038 ) -> Result<AndroidRadarConfigResponse> { 1039 let mut expected_calls = self.expected_calls.lock().unwrap(); 1040 match expected_calls.pop_front() { 1041 Some(ExpectedCall::AndroidSetRadarConfig { 1042 expected_session_id, 1043 expected_config_tlvs, 1044 notfs, 1045 out, 1046 }) if expected_session_id == session_id 1047 && radar_config_tlvs_eq(&expected_config_tlvs, &config_tlvs) => 1048 { 1049 self.expect_call_consumed.notify_one(); 1050 self.send_notifications(notfs); 1051 out 1052 } 1053 Some(call) => { 1054 expected_calls.push_front(call); 1055 Err(Error::MockUndefined) 1056 } 1057 None => Err(Error::MockUndefined), 1058 } 1059 } 1060 android_get_radar_config( &self, session_id: SessionId, config_ids: Vec<RadarConfigTlvType>, ) -> Result<Vec<RadarConfigTlv>>1061 async fn android_get_radar_config( 1062 &self, 1063 session_id: SessionId, 1064 config_ids: Vec<RadarConfigTlvType>, 1065 ) -> Result<Vec<RadarConfigTlv>> { 1066 let mut expected_calls = self.expected_calls.lock().unwrap(); 1067 match expected_calls.pop_front() { 1068 Some(ExpectedCall::AndroidGetRadarConfig { 1069 expected_session_id, 1070 expected_config_ids, 1071 out, 1072 }) if expected_session_id == session_id && expected_config_ids == config_ids => { 1073 self.expect_call_consumed.notify_one(); 1074 out 1075 } 1076 Some(call) => { 1077 expected_calls.push_front(call); 1078 Err(Error::MockUndefined) 1079 } 1080 None => Err(Error::MockUndefined), 1081 } 1082 } 1083 raw_uci_cmd( &self, mt: u32, gid: u32, oid: u32, payload: Vec<u8>, ) -> Result<RawUciMessage>1084 async fn raw_uci_cmd( 1085 &self, 1086 mt: u32, 1087 gid: u32, 1088 oid: u32, 1089 payload: Vec<u8>, 1090 ) -> Result<RawUciMessage> { 1091 let mut expected_calls = self.expected_calls.lock().unwrap(); 1092 match expected_calls.pop_front() { 1093 Some(ExpectedCall::RawUciCmd { 1094 expected_mt, 1095 expected_gid, 1096 expected_oid, 1097 expected_payload, 1098 out, 1099 }) if expected_mt == mt 1100 && expected_gid == gid 1101 && expected_oid == oid 1102 && expected_payload == payload => 1103 { 1104 self.expect_call_consumed.notify_one(); 1105 out 1106 } 1107 Some(call) => { 1108 expected_calls.push_front(call); 1109 Err(Error::MockUndefined) 1110 } 1111 None => Err(Error::MockUndefined), 1112 } 1113 } 1114 send_data_packet( &self, session_id: SessionId, address: Vec<u8>, uci_sequence_num: u16, app_payload_data: Vec<u8>, ) -> Result<()>1115 async fn send_data_packet( 1116 &self, 1117 session_id: SessionId, 1118 address: Vec<u8>, 1119 uci_sequence_num: u16, 1120 app_payload_data: Vec<u8>, 1121 ) -> Result<()> { 1122 let mut expected_calls = self.expected_calls.lock().unwrap(); 1123 match expected_calls.pop_front() { 1124 Some(ExpectedCall::SendDataPacket { 1125 expected_session_id, 1126 expected_address, 1127 expected_uci_sequence_num, 1128 expected_app_payload_data, 1129 out, 1130 }) if expected_session_id == session_id 1131 && expected_address == address 1132 && expected_uci_sequence_num == uci_sequence_num 1133 && expected_app_payload_data == app_payload_data => 1134 { 1135 self.expect_call_consumed.notify_one(); 1136 out 1137 } 1138 Some(call) => { 1139 expected_calls.push_front(call); 1140 Err(Error::MockUndefined) 1141 } 1142 None => Err(Error::MockUndefined), 1143 } 1144 } 1145 get_session_token_from_session_id( &self, _session_id: SessionId, ) -> Result<SessionToken>1146 async fn get_session_token_from_session_id( 1147 &self, 1148 _session_id: SessionId, 1149 ) -> Result<SessionToken> { 1150 Ok(1) // No uci call here, no mock required. 1151 } 1152 session_set_hybrid_controller_config( &self, session_id: SessionId, message_control: u8, number_of_phases: u8, update_time: UpdateTime, phase_lists: PhaseList, ) -> Result<()>1153 async fn session_set_hybrid_controller_config( 1154 &self, 1155 session_id: SessionId, 1156 message_control: u8, 1157 number_of_phases: u8, 1158 update_time: UpdateTime, 1159 phase_lists: PhaseList, 1160 ) -> Result<()> { 1161 let mut expected_calls = self.expected_calls.lock().unwrap(); 1162 match expected_calls.pop_front() { 1163 Some(ExpectedCall::SessionSetHybridControllerConfig { 1164 expected_session_id, 1165 expected_message_control, 1166 expected_number_of_phases, 1167 expected_update_time, 1168 expected_phase_list, 1169 out, 1170 }) if expected_session_id == session_id 1171 && expected_message_control == message_control 1172 && expected_number_of_phases == number_of_phases 1173 && expected_update_time == update_time 1174 && expected_phase_list == phase_lists => 1175 { 1176 self.expect_call_consumed.notify_one(); 1177 out 1178 } 1179 Some(call) => { 1180 expected_calls.push_front(call); 1181 Err(Error::MockUndefined) 1182 } 1183 None => Err(Error::MockUndefined), 1184 } 1185 } 1186 session_set_hybrid_controlee_config( &self, session_id: SessionId, controlee_phase_list: Vec<ControleePhaseList>, ) -> Result<()>1187 async fn session_set_hybrid_controlee_config( 1188 &self, 1189 session_id: SessionId, 1190 controlee_phase_list: Vec<ControleePhaseList>, 1191 ) -> Result<()> { 1192 let mut expected_calls = self.expected_calls.lock().unwrap(); 1193 match expected_calls.pop_front() { 1194 Some(ExpectedCall::SessionSetHybridControleeConfig { 1195 expected_session_id, 1196 expected_controlee_phase_list, 1197 out, 1198 }) if expected_session_id == session_id 1199 && expected_controlee_phase_list.len() == controlee_phase_list.len() 1200 && expected_controlee_phase_list == controlee_phase_list => 1201 { 1202 self.expect_call_consumed.notify_one(); 1203 out 1204 } 1205 Some(call) => { 1206 expected_calls.push_front(call); 1207 Err(Error::MockUndefined) 1208 } 1209 None => Err(Error::MockUndefined), 1210 } 1211 } 1212 } 1213 1214 #[derive(Clone)] 1215 enum ExpectedCall { 1216 OpenHal { 1217 notfs: Vec<UciNotification>, 1218 out: Result<GetDeviceInfoResponse>, 1219 }, 1220 CloseHal { 1221 expected_force: bool, 1222 out: Result<()>, 1223 }, 1224 DeviceReset { 1225 expected_reset_config: ResetConfig, 1226 out: Result<()>, 1227 }, 1228 CoreGetDeviceInfo { 1229 out: Result<GetDeviceInfoResponse>, 1230 }, 1231 CoreGetCapsInfo { 1232 out: Result<Vec<CapTlv>>, 1233 }, 1234 CoreSetConfig { 1235 expected_config_tlvs: Vec<DeviceConfigTlv>, 1236 out: Result<CoreSetConfigResponse>, 1237 }, 1238 CoreGetConfig { 1239 expected_config_ids: Vec<DeviceConfigId>, 1240 out: Result<Vec<DeviceConfigTlv>>, 1241 }, 1242 CoreQueryTimeStamp { 1243 out: Result<u64>, 1244 }, 1245 SessionInit { 1246 expected_session_id: SessionId, 1247 expected_session_type: SessionType, 1248 notfs: Vec<UciNotification>, 1249 out: Result<()>, 1250 }, 1251 SessionDeinit { 1252 expected_session_id: SessionId, 1253 notfs: Vec<UciNotification>, 1254 out: Result<()>, 1255 }, 1256 SessionSetAppConfig { 1257 expected_session_id: SessionId, 1258 expected_config_tlvs: Vec<AppConfigTlv>, 1259 notfs: Vec<UciNotification>, 1260 out: Result<SetAppConfigResponse>, 1261 }, 1262 SessionGetAppConfig { 1263 expected_session_id: SessionId, 1264 expected_config_ids: Vec<AppConfigTlvType>, 1265 out: Result<Vec<AppConfigTlv>>, 1266 }, 1267 SessionGetCount { 1268 out: Result<u8>, 1269 }, 1270 SessionGetState { 1271 expected_session_id: SessionId, 1272 out: Result<SessionState>, 1273 }, 1274 SessionUpdateControllerMulticastList { 1275 expected_session_id: SessionId, 1276 expected_action: UpdateMulticastListAction, 1277 expected_controlees: Controlees, 1278 notfs: Vec<UciNotification>, 1279 out: Result<SessionUpdateControllerMulticastResponse>, 1280 }, 1281 SessionUpdateDtTagRangingRounds { 1282 expected_session_id: u32, 1283 expected_ranging_round_indexes: Vec<u8>, 1284 out: Result<SessionUpdateDtTagRangingRoundsResponse>, 1285 }, 1286 SessionQueryMaxDataSize { 1287 expected_session_id: SessionId, 1288 out: Result<u16>, 1289 }, 1290 RangeStart { 1291 expected_session_id: SessionId, 1292 notfs: Vec<UciNotification>, 1293 out: Result<()>, 1294 }, 1295 RangeStop { 1296 expected_session_id: SessionId, 1297 notfs: Vec<UciNotification>, 1298 out: Result<()>, 1299 }, 1300 RangeGetRangingCount { 1301 expected_session_id: SessionId, 1302 out: Result<usize>, 1303 }, 1304 AndroidSetCountryCode { 1305 expected_country_code: CountryCode, 1306 out: Result<()>, 1307 }, 1308 AndroidGetPowerStats { 1309 out: Result<PowerStats>, 1310 }, 1311 AndroidSetRadarConfig { 1312 expected_session_id: SessionId, 1313 expected_config_tlvs: Vec<RadarConfigTlv>, 1314 notfs: Vec<UciNotification>, 1315 out: Result<AndroidRadarConfigResponse>, 1316 }, 1317 AndroidGetRadarConfig { 1318 expected_session_id: SessionId, 1319 expected_config_ids: Vec<RadarConfigTlvType>, 1320 out: Result<Vec<RadarConfigTlv>>, 1321 }, 1322 RawUciCmd { 1323 expected_mt: u32, 1324 expected_gid: u32, 1325 expected_oid: u32, 1326 expected_payload: Vec<u8>, 1327 out: Result<RawUciMessage>, 1328 }, 1329 SendDataPacket { 1330 expected_session_id: SessionId, 1331 expected_address: Vec<u8>, 1332 expected_uci_sequence_num: u16, 1333 expected_app_payload_data: Vec<u8>, 1334 out: Result<()>, 1335 }, 1336 SessionSetHybridControllerConfig { 1337 expected_session_id: SessionId, 1338 expected_message_control: u8, 1339 expected_number_of_phases: u8, 1340 expected_update_time: UpdateTime, 1341 expected_phase_list: PhaseList, 1342 out: Result<()>, 1343 }, 1344 SessionSetHybridControleeConfig { 1345 expected_session_id: SessionId, 1346 expected_controlee_phase_list: Vec<ControleePhaseList>, 1347 out: Result<()>, 1348 }, 1349 SessionDataTransferPhaseConfig { 1350 expected_session_id: SessionId, 1351 expected_dtpcm_repetition: u8, 1352 expected_data_transfer_control: u8, 1353 expected_dtpml_size: u8, 1354 expected_mac_address: Vec<u8>, 1355 expected_slot_bitmap: Vec<u8>, 1356 out: Result<()>, 1357 }, 1358 } 1359