Skip to content

Commit

Permalink
update tests and fix warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
lulf committed Mar 12, 2024
1 parent 0aeff44 commit f137206
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 32 deletions.
7 changes: 3 additions & 4 deletions host/src/adapter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,23 @@ use crate::ad_structure::AdStructure;
use crate::channel_manager::ChannelManager;
use crate::connection_manager::{ConnectionInfo, ConnectionManager};
use crate::cursor::{ReadCursor, WriteCursor};
use crate::l2cap::{L2capPacket, L2CAP_CID_ATT, L2CAP_CID_DYN_START, L2CAP_CID_LE_U_SIGNAL}; //self, L2capLeSignal, L2capPacket, L2capState, LeCreditConnReq, SignalCode};
use crate::l2cap::{L2capPacket, L2CAP_CID_ATT, L2CAP_CID_DYN_START, L2CAP_CID_LE_U_SIGNAL};
use crate::packet_pool::{DynamicPacketPool, PacketPool, Qos, ATT_ID};
use crate::pdu::Pdu;
use crate::scanner::{ScanReports, Scanner};
use crate::types::l2cap::L2capLeSignal;
use crate::{codec, Error};
use bt_hci::cmd::controller_baseband::SetEventMask;
use bt_hci::cmd::le::{
LeCreateConn, LeCreateConnParams, LeSetAdvData, LeSetAdvEnable, LeSetAdvParams, LeSetScanEnable,
LeSetScanEnableParams, LeSetScanParams,
LeCreateConn, LeCreateConnParams, LeSetAdvData, LeSetAdvEnable, LeSetAdvParams, LeSetScanEnable, LeSetScanParams,
};
use bt_hci::cmd::link_control::{Disconnect, DisconnectParams};
use bt_hci::cmd::{AsyncCmd, SyncCmd};
use bt_hci::data::{AclBroadcastFlag, AclPacket, AclPacketBoundary};
use bt_hci::event::le::LeEvent;
use bt_hci::event::Event;
use bt_hci::param::{BdAddr, ConnHandle, DisconnectReason, EventMask};
use bt_hci::{AsHciBytes, ControllerToHostPacket};
use bt_hci::ControllerToHostPacket;
use bt_hci::{ControllerCmdAsync, ControllerCmdSync};
use embassy_futures::select::{select4, Either4};
use embassy_sync::blocking_mutex::raw::RawMutex;
Expand Down
1 change: 0 additions & 1 deletion host/src/l2cap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ use bt_hci::data::AclPacket;
use bt_hci::param::ConnHandle;
use embassy_sync::blocking_mutex::raw::RawMutex;
use embassy_sync::channel::{DynamicReceiver, DynamicSender};
use embassy_time::{Duration, Timer};

pub(crate) const L2CAP_CID_ATT: u16 = 0x0004;
pub(crate) const L2CAP_CID_LE_U_SIGNAL: u16 = 0x0005;
Expand Down
54 changes: 27 additions & 27 deletions host/src/packet_pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -235,75 +235,75 @@ mod tests {
fn test_fair_qos() {
let pool: PacketPool<NoopRawMutex, 1, 8, 4> = PacketPool::new(Qos::Fair);

let a1 = pool.alloc(0);
let a1 = pool.alloc(AllocId(0));
assert!(a1.is_some());
let a2 = pool.alloc(0);
let a2 = pool.alloc(AllocId(0));
assert!(a2.is_some());
assert!(pool.alloc(0).is_none());
assert!(pool.alloc(AllocId(0)).is_none());
drop(a2);
let a3 = pool.alloc(0);
let a3 = pool.alloc(AllocId(0));
assert!(a3.is_some());

let b1 = pool.alloc(1);
let b1 = pool.alloc(AllocId(1));
assert!(b1.is_some());

let c1 = pool.alloc(2);
let c1 = pool.alloc(AllocId(2));
assert!(c1.is_some());
}

#[test]
fn test_none_qos() {
let pool: PacketPool<NoopRawMutex, 1, 8, 4> = PacketPool::new(Qos::None);

let a1 = pool.alloc(0);
let a1 = pool.alloc(AllocId(0));
assert!(a1.is_some());
let a2 = pool.alloc(0);
let a2 = pool.alloc(AllocId(0));
assert!(a2.is_some());
let a3 = pool.alloc(0);
let a3 = pool.alloc(AllocId(0));
assert!(a3.is_some());
let a4 = pool.alloc(0);
let a4 = pool.alloc(AllocId(0));
assert!(a4.is_some());
let a5 = pool.alloc(0);
let a5 = pool.alloc(AllocId(0));
assert!(a5.is_some());
let a6 = pool.alloc(0);
let a6 = pool.alloc(AllocId(0));
assert!(a6.is_some());
let a7 = pool.alloc(0);
let a7 = pool.alloc(AllocId(0));
assert!(a7.is_some());

let b1 = pool.alloc(1);
let b1 = pool.alloc(AllocId(1));
assert!(b1.is_some());

let b2 = pool.alloc(1);
let b2 = pool.alloc(AllocId(1));
assert!(b2.is_none());
}

#[test]
fn test_guaranteed_qos() {
let pool: PacketPool<NoopRawMutex, 1, 8, 4> = PacketPool::new(Qos::Guaranteed(1));

let a1 = pool.alloc(0);
let a1 = pool.alloc(AllocId(0));
assert!(a1.is_some());
let a2 = pool.alloc(0);
let a2 = pool.alloc(AllocId(0));
assert!(a2.is_some());
let a3 = pool.alloc(0);
let a3 = pool.alloc(AllocId(0));
assert!(a3.is_some());
let a4 = pool.alloc(0);
let a4 = pool.alloc(AllocId(0));
assert!(a4.is_some());
let a5 = pool.alloc(0);
let a5 = pool.alloc(AllocId(0));
assert!(a5.is_some());
// Needs at least 3 for the other clients
assert!(pool.alloc(0).is_none());
assert!(pool.alloc(AllocId(0)).is_none());

let b1 = pool.alloc(1);
let b1 = pool.alloc(AllocId(1));
assert!(b1.is_some());
assert!(pool.alloc(1).is_none());
assert!(pool.alloc(AllocId(1)).is_none());

let c1 = pool.alloc(2);
let c1 = pool.alloc(AllocId(2));
assert!(c1.is_some());
assert!(pool.alloc(2).is_none());
assert!(pool.alloc(AllocId(2)).is_none());

let d1 = pool.alloc(3);
let d1 = pool.alloc(AllocId(3));
assert!(d1.is_some());
assert!(pool.alloc(3).is_none());
assert!(pool.alloc(AllocId(3)).is_none());
}
}

0 comments on commit f137206

Please sign in to comment.