chore: add benchmark and tests for GetManagedObjects (#150)
This commit is contained in:
parent
61d2869d96
commit
2d566224d3
25
bench/unmarshall_getmanagedobjects.py
Normal file
25
bench/unmarshall_getmanagedobjects.py
Normal file
@ -0,0 +1,25 @@
|
||||
import io
|
||||
import timeit
|
||||
|
||||
from dbus_fast._private.unmarshaller import Unmarshaller
|
||||
|
||||
# cythonize -X language_level=3 -a -i src/dbus_fast/_private/unmarshaller.py
|
||||
|
||||
with open("tests/data/get_managed_objects.hex") as fp:
|
||||
msg = fp.read()
|
||||
|
||||
|
||||
stream = io.BytesIO(bytes.fromhex(msg))
|
||||
|
||||
unmarshaller = Unmarshaller(stream)
|
||||
|
||||
|
||||
def unmarhsall_bluez_get_managed_objects_message():
|
||||
stream.seek(0)
|
||||
unmarshaller.reset()
|
||||
unmarshaller.unmarshall()
|
||||
|
||||
|
||||
count = 10000
|
||||
time = timeit.Timer(unmarhsall_bluez_get_managed_objects_message).timeit(count)
|
||||
print(f"Unmarshalling {count} bluetooth GetManagedObjects messages took {time} seconds")
|
||||
1
tests/data/get_managed_objects.hex
Normal file
1
tests/data/get_managed_objects.hex
Normal file
File diff suppressed because one or more lines are too long
@ -26,6 +26,9 @@ def print_buf(buf):
|
||||
with open(os.path.dirname(__file__) + "/data/messages.json") as f:
|
||||
table = json.load(f)
|
||||
|
||||
with open(os.path.dirname(__file__) + "/data/get_managed_objects.hex") as fp:
|
||||
get_managed_objects_msg = fp.read()
|
||||
|
||||
|
||||
def json_to_message(message: Dict[str, Any]) -> Message:
|
||||
copy = dict(message)
|
||||
@ -483,3 +486,23 @@ def test_ay_buffer():
|
||||
|
||||
def tests_fallback_no_cython():
|
||||
assert FakeCython().compiled is False
|
||||
|
||||
|
||||
def test_unmarshall_large_message():
|
||||
|
||||
stream = io.BytesIO(bytes.fromhex(get_managed_objects_msg))
|
||||
unmarshaller = Unmarshaller(stream)
|
||||
unmarshaller.unmarshall()
|
||||
message = unmarshaller.message
|
||||
unpacked = unpack_variants(message.body)
|
||||
objects = unpacked[0]
|
||||
assert objects["/org/bluez/hci0/dev_CD_A3_FA_D1_50_56/service000b/char000c"] == {
|
||||
"org.bluez.GattCharacteristic1": {
|
||||
"Flags": ["read"],
|
||||
"Service": "/org/bluez/hci0/dev_CD_A3_FA_D1_50_56/service000b",
|
||||
"UUID": "e604e95d-a759-4817-87d3-aa005083a0d1",
|
||||
"Value": bytearray(b""),
|
||||
},
|
||||
"org.freedesktop.DBus.Introspectable": {},
|
||||
"org.freedesktop.DBus.Properties": {},
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user