Skip to content

Commit

Permalink
Merge pull request #73 from google/gbg/faster-l2cap-test
Browse files Browse the repository at this point in the history
lower the number of test cases for l2cap in order to speed up the test
  • Loading branch information
barbibulle committed Nov 15, 2022
2 parents 25ce38c + 867e8c1 commit f213323
Showing 1 changed file with 21 additions and 21 deletions.
42 changes: 21 additions & 21 deletions tests/l2cap_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,40 +85,40 @@ async def setup_connection():
await two_devices.devices[0].connect(two_devices.devices[1].random_address)

# Check the post conditions
assert(two_devices.connections[0] is not None)
assert(two_devices.connections[1] is not None)
assert two_devices.connections[0] is not None
assert two_devices.connections[1] is not None

return two_devices


# -----------------------------------------------------------------------------
def test_helpers():
psm = L2CAP_Connection_Request.serialize_psm(0x01)
assert(psm == bytes([0x01, 0x00]))
assert psm == bytes([0x01, 0x00])

psm = L2CAP_Connection_Request.serialize_psm(0x1023)
assert(psm == bytes([0x23, 0x10]))
assert psm == bytes([0x23, 0x10])

psm = L2CAP_Connection_Request.serialize_psm(0x242311)
assert(psm == bytes([0x11, 0x23, 0x24]))
assert psm == bytes([0x11, 0x23, 0x24])

(offset, psm) = L2CAP_Connection_Request.parse_psm(bytes([0x00, 0x01, 0x00, 0x44]), 1)
assert(offset == 3)
assert(psm == 0x01)
assert offset == 3
assert psm == 0x01

(offset, psm) = L2CAP_Connection_Request.parse_psm(bytes([0x00, 0x23, 0x10, 0x44]), 1)
assert(offset == 3)
assert(psm == 0x1023)
assert offset == 3
assert psm == 0x1023

(offset, psm) = L2CAP_Connection_Request.parse_psm(bytes([0x00, 0x11, 0x23, 0x24, 0x44]), 1)
assert(offset == 4)
assert(psm == 0x242311)
assert offset == 4
assert psm == 0x242311

rq = L2CAP_Connection_Request(psm = 0x01, source_cid = 0x44)
brq = bytes(rq)
srq = L2CAP_Connection_Request.from_bytes(brq)
assert(srq.psm == rq.psm)
assert(srq.source_cid == rq.source_cid)
assert srq.psm == rq.psm
assert srq.source_cid == rq.source_cid


# -----------------------------------------------------------------------------
Expand Down Expand Up @@ -170,12 +170,12 @@ def on_close(which, event):
l2cap_channel.on('close', lambda: on_close(0, None))
incoming_channel.on('close', lambda: on_close(1, closed_event))
await l2cap_channel.disconnect()
assert(closed == [True, True])
assert closed == [True, True]
await closed_event.wait()

sent_bytes = b''.join(messages)
received_bytes = b''.join(received)
assert(sent_bytes == received_bytes)
assert sent_bytes == received_bytes


# -----------------------------------------------------------------------------
Expand All @@ -201,7 +201,7 @@ def on_data(data):

messages = [
bytes([1, 2, 3, 4, 5, 6, 7]) * x
for x in (3, 10, 100, 500, 789)
for x in (3, 10, 100, 789)
]
for message in messages:
l2cap_channel.write(message)
Expand All @@ -214,14 +214,14 @@ def on_data(data):

sent_bytes = b''.join(messages)
received_bytes = b''.join(received)
assert(sent_bytes == received_bytes)
assert sent_bytes == received_bytes


@pytest.mark.asyncio
async def test_transfer():
for max_credits in (1, 10, 100, 10000):
for mtu in (23, 24, 25, 26, 50, 200, 255, 256, 1000):
for mps in (23, 24, 25, 26, 50, 200, 255, 256, 1000):
for mtu in (50, 255, 256, 1000):
for mps in (50, 255, 256, 1000):
# print(max_credits, mtu, mps)
await transfer_payload(max_credits, mtu, mps)

Expand Down Expand Up @@ -267,8 +267,8 @@ def on_client_data(data):
message_bytes = b''.join(messages)
client_received_bytes = b''.join(client_received)
server_received_bytes = b''.join(server_received)
assert(client_received_bytes == message_bytes)
assert(server_received_bytes == message_bytes)
assert client_received_bytes == message_bytes
assert server_received_bytes == message_bytes


# -----------------------------------------------------------------------------
Expand Down

0 comments on commit f213323

Please sign in to comment.