Skip to content

Commit

Permalink
tests: log in and out once before collecting memory stats
Browse files Browse the repository at this point in the history
Also give a little more flexibilty if BLE enabled
  • Loading branch information
JamieDriver committed May 29, 2024
1 parent ffb4b3e commit 7ee36ee
Showing 1 changed file with 26 additions and 21 deletions.
47 changes: 26 additions & 21 deletions test_jade.py
Original file line number Diff line number Diff line change
Expand Up @@ -2223,11 +2223,17 @@ def test_handshake_bad_server(jade):


# Check/print memory stats
def check_mem_stats(startinfo, endinfo, check_frag=True, strict=True):
def check_mem_stats(startinfo, endinfo, has_psram, has_ble, strict=True):

# NOTE: skip the fragmentation check when we have BLE enabled
# as there is too much memory allocation outside of our control.
# Also skip for no-psram (qemu) devices.
check_frag = has_psram and not has_ble

# Memory stats to log/check
breaches = []
for field, limit in [('JADE_FREE_HEAP', 1536),
('JADE_FREE_DRAM', 1536),
('JADE_FREE_DRAM', 4096 if has_ble else 1536),
('JADE_LARGEST_DRAM', 4096 if check_frag else -1),
('JADE_FREE_SPIRAM', 0),
('JADE_LARGEST_SPIRAM', 0 if check_frag else -1)]:
Expand Down Expand Up @@ -3295,21 +3301,23 @@ def run_api_tests(jadeapi, isble, qemu, authuser=False):
rslt = jadeapi.set_mnemonic(TEST_MNEMONIC)
assert rslt is True

# Test logout and log back in before we collect mem stats in case there are
# 'one off' allocations when we first log in
assert jadeapi.get_version_info()['JADE_STATE'] == 'READY'
jadeapi.logout()
assert jadeapi.get_version_info()['JADE_STATE'] in ['LOCKED', 'UNINIT']
rslt = jadeapi.set_mnemonic(TEST_MNEMONIC)
assert jadeapi.get_version_info()['JADE_STATE'] == "READY"

rslt = jadeapi.ping()
assert rslt == 0 # idle

time.sleep(5) # Lets idle tasks clean up
startinfo = jadeapi.get_version_info()
assert len(startinfo) == NUM_VALUES_VERINFO
has_psram = startinfo['JADE_FREE_SPIRAM'] > 0
has_ble = startinfo['JADE_CONFIG'] == 'BLE'

# Test logout
assert startinfo['JADE_STATE'] == 'READY'
jadeapi.logout()
assert jadeapi.get_version_info()['JADE_STATE'] in ['LOCKED', 'UNINIT']
rslt = jadeapi.set_mnemonic(TEST_MNEMONIC)
assert jadeapi.get_version_info()['JADE_STATE'] == "READY"

# Test update pinserver details
test_set_pinserver(jadeapi)

Expand Down Expand Up @@ -3387,12 +3395,7 @@ def run_api_tests(jadeapi, isble, qemu, authuser=False):

time.sleep(5) # Lets idle tasks clean up
endinfo = jadeapi.get_version_info()

# NOTE: skip the fragmentation check when we have BLE enabled
# as there is too much memory allocation outside of our control.
# Also skip for no-psram (qemu) devices.
check_frag = has_psram and not has_ble
check_mem_stats(startinfo, endinfo, check_frag=check_frag)
check_mem_stats(startinfo, endinfo, has_psram, has_ble)

rslt = jadeapi.clean_reset()
assert rslt is True
Expand All @@ -3410,6 +3413,13 @@ def run_interface_tests(jadeapi,
rslt = jadeapi.clean_reset()
assert rslt is True

# Log out and log back in before we collect mem stats in case there are
# 'one off' allocations when we first log in
rslt = jadeapi.set_mnemonic(TEST_MNEMONIC)
assert rslt is True
rslt = jadeapi.logout()
assert rslt is True

time.sleep(5) # Lets idle tasks clean up
startinfo = jadeapi.get_version_info()
assert len(startinfo) == NUM_VALUES_VERINFO
Expand Down Expand Up @@ -3486,12 +3496,7 @@ def run_interface_tests(jadeapi,

time.sleep(5) # Lets idle tasks clean up
endinfo = jadeapi.get_version_info()

# NOTE: skip the fragmentation check when we have BLE enabled
# as there is too much memory allocation outside of our control.
# Also skip for no-psram (qemu) devices.
check_frag = has_psram and not has_ble
check_mem_stats(startinfo, endinfo, check_frag=check_frag)
check_mem_stats(startinfo, endinfo, has_psram, has_ble)

rslt = jadeapi.clean_reset()
assert rslt is True
Expand Down

0 comments on commit 7ee36ee

Please sign in to comment.