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