summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorziyiw <ziyiw@google.com>2024-04-11 18:54:56 +0000
committerziyiw <ziyiw@google.com>2024-04-11 18:56:16 +0000
commit30e37396e2e82c6915e94af01db2a07d011c68fa (patch)
treef1075b0bc2190be92e093b5dd74ddde125a857ce
parent44d5f96a87519679348ba953747f56bf6d237d29 (diff)
downloaduwb-30e37396e2e82c6915e94af01db2a07d011c68fa.tar.gz
[unit_test] Add more unit tests for uci notification.
Test: atest libuwb_core_tests Bug: 330169927 Change-Id: Ifa3ddbbb2c72fc2019238fcb7f339e92210367c0
-rw-r--r--src/rust/uwb_core/src/uci/notification.rs136
-rw-r--r--src/rust/uwb_uci_packets/src/lib.rs38
2 files changed, 173 insertions, 1 deletions
diff --git a/src/rust/uwb_core/src/uci/notification.rs b/src/rust/uwb_core/src/uci/notification.rs
index 86af468..e782959 100644
--- a/src/rust/uwb_core/src/uci/notification.rs
+++ b/src/rust/uwb_core/src/uci/notification.rs
@@ -1089,6 +1089,142 @@ mod tests {
}
#[test]
+ fn test_session_notification_casting_from_session_data_transfer_phase_config_ntf_packet() {
+ let session_data_transfer_phase_config_ntf =
+ uwb_uci_packets::SessionDataTransferPhaseConfigNtfBuilder {
+ session_token: 0x32,
+ status: DataTransferPhaseConfigUpdateStatusCode::UciDtpcmConfigSuccessStatusOk,
+ }
+ .build();
+ let session_notification_packet = uwb_uci_packets::SessionConfigNotification::try_from(
+ session_data_transfer_phase_config_ntf,
+ )
+ .unwrap();
+ let uci_fira_major_version = UCIMajorVersion::V1;
+ let session_notification =
+ SessionNotification::try_from((session_notification_packet, uci_fira_major_version))
+ .unwrap();
+ let uci_notification_from_session_data_transfer_phase_config_ntf =
+ UciNotification::Session(session_notification);
+ assert_eq!(
+ uci_notification_from_session_data_transfer_phase_config_ntf,
+ UciNotification::Session(SessionNotification::DataTransferPhaseConfig {
+ session_token: 0x32,
+ status: DataTransferPhaseConfigUpdateStatusCode::UciDtpcmConfigSuccessStatusOk
+ })
+ );
+ }
+
+ #[test]
+ fn test_session_notification_casting_from_short_mac_dl_tdoa_session_info_ntf_packet() {
+ let dl_tdoa_measurements = vec![
+ 0x0a, 0x01, 0x33, 0x05, // 2(Mac address), Status, Message Type
+ 0x53, 0x05, 0x02, 0x05, // 2(Message control), 2(Block Index)
+ 0x07, 0x09, 0x0a, 0x01, // Round Index, NLoS, 2(AoA Azimuth)
+ 0x02, 0x05, 0x07, 0x09, // AoA Azimuth FOM, 2(AoA Elevation), AoA Elevation FOM
+ 0x0a, 0x01, 0x02, 0x05, // RSSI, 3(Tx Timestamp..)
+ 0x07, 0x09, 0x0a, 0x01, // 4(Tx Timestamp..)
+ 0x02, 0x05, 0x07, 0x09, // Tx Timestamp, 3(Rx Timestamp..)
+ 0x05, 0x07, 0x09, 0x0a, // 2(Rx Timestamp), 2(Anchor Cfo)
+ 0x01, 0x02, 0x05, 0x07, // 2(Cfo), 2(Initiator Reply Time..)
+ 0x09, 0x05, 0x07, 0x09, // 2(Initiator Reply Time), 2(Responder Reply Time..)
+ 0x0a, 0x01, 0x02, 0x05, // 2(Responder Reply Time), 2(Initiator-Responder ToF)
+ 0x07, 0x09, 0x07, 0x09, // 4(Anchor Location..)
+ 0x05, 0x07, 0x09, 0x0a, // 4(Anchor Location..)
+ 0x01, 0x02, 0x05, 0x07, // 2(Anchor Location..), 2(Active Ranging Rounds..)
+ 0x09, 0x0a, 0x01, 0x02, // 4(Active Ranging Rounds..)
+ 0x05, 0x07, 0x09, 0x05, // 4(Active Ranging Rounds)
+ ];
+ let short_mac_dl_tdoa_session_info_ntf =
+ uwb_uci_packets::ShortMacDlTDoASessionInfoNtfBuilder {
+ current_ranging_interval: 0x13,
+ dl_tdoa_measurements: dl_tdoa_measurements.clone(),
+ no_of_ranging_measurements: 1,
+ rcr_indicator: 0x12,
+ sequence_number: 0x10,
+ session_token: 0x11,
+ }
+ .build();
+ let raw_ranging_data =
+ short_mac_dl_tdoa_session_info_ntf.clone().to_bytes()[UCI_PACKET_HEADER_LEN..].to_vec();
+ let short_measurement =
+ ShortAddressDlTdoaRangingMeasurement::parse(&dl_tdoa_measurements, 1).unwrap();
+ let range_notification_packet =
+ uwb_uci_packets::SessionInfoNtf::try_from(short_mac_dl_tdoa_session_info_ntf).unwrap();
+ let session_notification =
+ SessionNotification::try_from(range_notification_packet).unwrap();
+ let uci_notification_from_short_mac_dl_tdoa_session_info_ntf =
+ UciNotification::Session(session_notification);
+ assert_eq!(
+ uci_notification_from_short_mac_dl_tdoa_session_info_ntf,
+ UciNotification::Session(SessionNotification::SessionInfo(SessionRangeData {
+ sequence_number: 0x10,
+ session_token: 0x11,
+ ranging_measurement_type: uwb_uci_packets::RangingMeasurementType::DlTdoa,
+ current_ranging_interval_ms: 0x13,
+ ranging_measurements: RangingMeasurements::ShortAddressDltdoa(short_measurement),
+ rcr_indicator: 0x12,
+ raw_ranging_data,
+ }))
+ );
+ }
+
+ #[test]
+ fn test_session_notification_casting_from_extended_mac_dltdoa_session_info_ntf_packet() {
+ let dl_tdoa_measurements = vec![
+ // All Fields in Little Endian (LE)
+ 0x0a, 0x01, 0x33, 0x05, // 4(Mac address..)
+ 0x33, 0x05, 0x02, 0x05, // 4(Mac address)
+ 0x07, 0x09, 0x0a, 0x01, // Status, Message Type, 2(Message control),
+ 0x02, 0x05, 0x07, 0x09, // 2(Block Index), Round Index, NLoS,
+ 0x0a, 0x01, 0x02, 0x05, // 2(AoA Azimuth), AoA Azimuth FOM, 1(AoA Elevation..)
+ 0x07, 0x09, 0x0a, // 1(AoA Elevation), AoA Elevation FOM, RSSI,
+ 0x01, 0x02, 0x05, 0x07, // 4(Tx Timestamp..)
+ 0x09, 0x05, 0x07, 0x09, // 4(Tx Timestamp),
+ 0x0a, 0x01, 0x02, 0x05, // 4(Rx Timestamp..)
+ 0x07, 0x09, 0x05, 0x07, // 4(Rx Timestamp)
+ 0x09, 0x0a, 0x01, 0x02, // 2(Anchor Cfo), 2(Cfo),
+ 0x05, 0x07, 0x09, 0x05, // 4(Initiator Reply Time)
+ 0x07, 0x09, 0x0a, 0x01, // 4(Responder Reply Time),
+ 0x02, 0x05, 0x02, 0x05, // 2(Initiator-Responder ToF), 2(Active Ranging Rounds)
+ ];
+ let extended_mac_dl_tdoa_session_info_ntf =
+ uwb_uci_packets::ExtendedMacDlTDoASessionInfoNtfBuilder {
+ current_ranging_interval: 0x13,
+ dl_tdoa_measurements: dl_tdoa_measurements.clone(),
+ no_of_ranging_measurements: 1,
+ rcr_indicator: 0x12,
+ sequence_number: 0x10,
+ session_token: 0x11,
+ }
+ .build();
+ let raw_ranging_data = extended_mac_dl_tdoa_session_info_ntf.clone().to_bytes()
+ [UCI_PACKET_HEADER_LEN..]
+ .to_vec();
+ let short_measurement =
+ ExtendedAddressDlTdoaRangingMeasurement::parse(&dl_tdoa_measurements, 1).unwrap();
+ let range_notification_packet =
+ uwb_uci_packets::SessionInfoNtf::try_from(extended_mac_dl_tdoa_session_info_ntf)
+ .unwrap();
+ let session_notification =
+ SessionNotification::try_from(range_notification_packet).unwrap();
+ let uci_notification_from_extended_mac_dl_tdoa_session_info_ntf =
+ UciNotification::Session(session_notification);
+ assert_eq!(
+ uci_notification_from_extended_mac_dl_tdoa_session_info_ntf,
+ UciNotification::Session(SessionNotification::SessionInfo(SessionRangeData {
+ sequence_number: 0x10,
+ session_token: 0x11,
+ ranging_measurement_type: uwb_uci_packets::RangingMeasurementType::DlTdoa,
+ current_ranging_interval_ms: 0x13,
+ ranging_measurements: RangingMeasurements::ExtendedAddressDltdoa(short_measurement),
+ rcr_indicator: 0x12,
+ raw_ranging_data,
+ }))
+ );
+ }
+
+ #[test]
#[allow(non_snake_case)] //override snake case for vendor_A
fn test_vendor_notification_casting() {
let vendor_9_empty_notification: uwb_uci_packets::UciNotification =
diff --git a/src/rust/uwb_uci_packets/src/lib.rs b/src/rust/uwb_uci_packets/src/lib.rs
index 10acea1..085707f 100644
--- a/src/rust/uwb_uci_packets/src/lib.rs
+++ b/src/rust/uwb_uci_packets/src/lib.rs
@@ -1403,7 +1403,7 @@ mod tests {
}
#[test]
- fn test_build_session_set_hybrid_controller_config_cmd() {
+ fn test_build_session_set_hybrid_controller_config_cmd_short_address() {
let phase_list_short_mac_address = PhaseListShortMacAddress {
session_token: 0x1324_3546,
start_slot_index: 0x1111,
@@ -1437,4 +1437,40 @@ mod tests {
]
);
}
+
+ #[test]
+ fn test_build_session_set_hybrid_controller_config_cmd_extended_address() {
+ let phase_list_extended_mac_address = PhaseListExtendedMacAddress {
+ session_token: 0x1324_3546,
+ start_slot_index: 0x1111,
+ end_slot_index: 0x1121,
+ phase_participation: 0x0,
+ mac_address: [0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, 0x8],
+ };
+ let packet: UciControlPacket = build_session_set_hybrid_controller_config_cmd(
+ 0x1234_5678,
+ 0x0,
+ 0x0,
+ [1; 8],
+ PhaseList::ExtendedMacAddress(vec![phase_list_extended_mac_address]),
+ )
+ .unwrap()
+ .into();
+ let packet_fragments: Vec<UciControlPacketHal> = packet.into();
+ let uci_packet: Vec<u8> = packet_fragments[0].clone().into();
+ assert_eq!(
+ uci_packet,
+ vec![
+ 0x21, 0x0c, 0x00, 0x1f, // 2(packet info), RFU, payload length(31)
+ 0x78, 0x56, 0x34, 0x12, // 4(session id (LE))
+ 0x00, 0x00, // message_control, number_of_phases
+ 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, // update_time
+ 0x46, 0x35, 0x24, 0x13, // session id (LE)
+ 0x11, 0x11, // start slot index (LE)
+ 0x21, 0x11, // end slot index (LE)
+ 0x00, // phase_participation
+ 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 // mac address
+ ]
+ );
+ }
}