Skip to content

Commit a88e0ed

Browse files
authored
test: add benchmark coverage for resolve_private_address (#268)
1 parent 95b0c33 commit a88e0ed

2 files changed

Lines changed: 51 additions & 0 deletions

File tree

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
from bluetooth_data_tools import get_cipher_for_irk, resolve_private_address
2+
3+
_IRK = b"\x00" * 16
4+
_CIPHER = get_cipher_for_irk(_IRK)
5+
6+
_NON_RPA = "00:01:ff:a0:3a:76"
7+
_RPA_MATCH = "40:01:02:0a:c4:a6"
8+
_RPA_MISMATCH = "40:00:00:d2:74:ce"
9+
10+
11+
def test_resolve_private_address_non_rpa(benchmark):
12+
benchmark(lambda: resolve_private_address(_CIPHER, _NON_RPA))
13+
14+
15+
def test_resolve_private_address_match(benchmark):
16+
benchmark(lambda: resolve_private_address(_CIPHER, _RPA_MATCH))
17+
18+
19+
def test_resolve_private_address_mismatch(benchmark):
20+
benchmark(lambda: resolve_private_address(_CIPHER, _RPA_MISMATCH))
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
from pytest_codspeed import BenchmarkFixture
2+
3+
from bluetooth_data_tools import get_cipher_for_irk, resolve_private_address
4+
5+
# IRK + addresses borrowed from tests/test_privacy.py so the AES path
6+
# walks the same code shape as the existing functional coverage.
7+
_IRK = b"\x00" * 16
8+
_CIPHER = get_cipher_for_irk(_IRK)
9+
10+
# Top two bits != 0b01: skipped before the AES encrypt. Real BLE scans
11+
# see this every time a public/static-random address is encountered.
12+
_NON_RPA = "00:01:ff:a0:3a:76"
13+
14+
# Top two bits == 0b01 with a hash that matches under the zero IRK.
15+
_RPA_MATCH = "40:01:02:0a:c4:a6"
16+
17+
# Top two bits == 0b01 but the hash does not match — exercises the full
18+
# encrypt + compare_digest path with a False result.
19+
_RPA_MISMATCH = "40:00:00:d2:74:ce"
20+
21+
22+
def test_resolve_private_address_non_rpa(benchmark: BenchmarkFixture) -> None:
23+
benchmark(lambda: resolve_private_address(_CIPHER, _NON_RPA))
24+
25+
26+
def test_resolve_private_address_match(benchmark: BenchmarkFixture) -> None:
27+
benchmark(lambda: resolve_private_address(_CIPHER, _RPA_MATCH))
28+
29+
30+
def test_resolve_private_address_mismatch(benchmark: BenchmarkFixture) -> None:
31+
benchmark(lambda: resolve_private_address(_CIPHER, _RPA_MISMATCH))

0 commit comments

Comments
 (0)