• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1% Exposure Notification System tests
2#
3# Type the following command to launch start the tests:
4# $ test/run_tests -P "load_contrib('exposure_notification')" -t test/contrib/exposure_notification.uts
5
6+ ENS tests
7
8= Setup
9
10def next_eir(p):
11   return EIR_Hdr(p[Padding].load)
12
13= Presence check
14
15Exposure_Notification_Frame
16
17= Raw payload copied from BluetoothExplorer.app
18
19d = hex_bytes('17df1d67405e3395470e62ca4fda6a9303687b31')
20p = Exposure_Notification_Frame(d)
21
22assert p.identifier == hex_bytes('17df1d67405e3395470e62ca4fda6a93')
23assert p.metadata == hex_bytes('03687b31')
24
25= Raw captured payload
26
27d = hex_bytes('02011a03036ffd17166ffde23f352fa09307a85d4194912443180d484dc151')
28p = EIR_Hdr(d)
29
30# First is a flags header
31assert EIR_Flags in p
32
33# Then the 16-bit Service Class ID
34p = next_eir(p)
35assert p[EIR_CompleteList16BitServiceUUIDs].svc_uuids == [
36    EXPOSURE_NOTIFICATION_UUID]
37
38# Then the ENS
39p = next_eir(p)
40assert p[EIR_ServiceData16BitUUID].svc_uuid == EXPOSURE_NOTIFICATION_UUID
41assert p[Exposure_Notification_Frame].identifier == hex_bytes(
42    'e23f352fa09307a85d4194912443180d')
43assert p[Exposure_Notification_Frame].metadata == hex_bytes('484dc151')
44
45# Rebuild the payload.
46p2 = p[Exposure_Notification_Frame].build_eir()
47
48# Our captured payload was from a mobile phone, but build_eir presumes that
49# we're broadcasting as an non-connectable, LE-only beacon. We need to adjust
50# these flags to match the captured packet.
51p2[0] = EIR_Hdr() / EIR_Flags(flags=[
52    'general_disc_mode', 'simul_le_br_edr_ctrl', 'simul_le_br_edr_host'])
53
54# Ensure we didn't mutate LowEnergyBeaconHelper.base_eir just then.
55assert LowEnergyBeaconHelper.base_eir[0][EIR_Flags].flags == [
56    'general_disc_mode', 'br_edr_not_supported']
57
58# Assemble all packet bytes
59assert b''.join(map(raw, p2)) == d
60