Skip to content

Commit c7fec9a

Browse files
memtest: allow premature stop
1 parent 87eb030 commit c7fec9a

2 files changed

Lines changed: 18 additions & 8 deletions

File tree

internal_filesystem/apps/com.example.lvgltest/assets/lvgltest.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,6 @@ def janitor_cb(timer):
4141
metrics_label.set_text("Spinners: 0")
4242

4343
print("Starting LVGL spinner benchmark...")
44-
janitor = lv.timer_create(janitor_cb, 500, None)
44+
janitor = lv.timer_create(janitor_cb, 400, None)
4545
add_spinner_timer = lv.timer_create(add_spinner, 2000, None)
4646

internal_filesystem/apps/com.example.memtest/assets/memtest.py

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,16 @@
2525
# 1048576 | 1
2626
# 2097152 | 0
2727
#=====================================
28+
#
29+
# On desktop, this hangs while outputting, for some reason...
2830

2931
import gc
3032
import time
3133
import _thread
3234

3335
# Configuration
3436
ALLOCATION_TIMEOUT_MS = 100 # Timeout for a single allocation (in milliseconds)
35-
37+
keep_running = True
3638

3739
def test_allocation(buffer_size, n):
3840
"""Test how many buffers of a given size can be allocated with a timeout."""
@@ -41,7 +43,7 @@ def test_allocation(buffer_size, n):
4143
count = 0
4244

4345
try:
44-
while appscreen == lv.screen_active():
46+
while keep_running:
4547
# Measure time for allocation
4648
start_time = time.ticks_ms()
4749
# Allocate a new buffer
@@ -66,21 +68,18 @@ def test_allocation(buffer_size, n):
6668
print(f"\nStopped after allocating {count} buffers of {buffer_size} bytes: {e}")
6769

6870
# Free allocated buffers
69-
#buffers.clear()
71+
buffers.clear()
7072
gc.collect()
7173
return count
7274

73-
74-
75-
7675
def stress_test_thread():
7776
summary = "Running RAM memory tests...\n\n"
7877
summary += "Buffer Size (bytes) | Max Allocated\n"
7978
summary += "-----------------------------------\n"
8079
lv.async_call(lambda l: status.set_text(summary), None)
8180
# Test buffer sizes of 2^n, starting from n=1 (2 bytes)
8281
n = 1
83-
while appscreen == lv.screen_active():
82+
while keep_running:
8483
buffer_size = 2 ** n
8584
summary += f"{buffer_size:>12} | "
8685
#lv.async_call(lambda l: status.set_text(summary), None)
@@ -105,6 +104,15 @@ def stress_test_thread():
105104
summary += "Test completed.\n"
106105
lv.async_call(lambda l: status.set_text(summary), None)
107106

107+
108+
109+
def janitor_cb(timer):
110+
global keep_running
111+
if lv.screen_active() != appscreen:
112+
print("memtest.py backgrounded, cleaning up...")
113+
janitor.delete()
114+
keep_running = False
115+
108116
appscreen = lv.screen_active()
109117
status = lv.label(appscreen)
110118
status.align(lv.ALIGN.TOP_LEFT, 5, 10)
@@ -113,3 +121,5 @@ def stress_test_thread():
113121

114122
_thread.stack_size(12*1024)
115123
_thread.start_new_thread(stress_test_thread, ())
124+
125+
janitor = lv.timer_create(janitor_cb, 400, None)

0 commit comments

Comments
 (0)