diff --git a/apps/com.example.memtest/assets/main.py b/apps/com.example.memtest/assets/main.py index 08c9983a..d5630ec8 100644 --- a/apps/com.example.memtest/assets/main.py +++ b/apps/com.example.memtest/assets/main.py @@ -33,7 +33,6 @@ import time ALLOCATION_TIMEOUT_MS = 100 # Timeout for a single allocation (in milliseconds) - def test_allocation(buffer_size, n): """Test how many buffers of a given size can be allocated with a timeout.""" print(f"\nTesting buffer size: {buffer_size} bytes (2^{n})") @@ -41,7 +40,7 @@ def test_allocation(buffer_size, n): count = 0 try: - while True: + while canary.is_valid(): # Measure time for allocation start_time = time.ticks_ms() # Allocate a new buffer @@ -69,23 +68,30 @@ def test_allocation(buffer_size, n): return count -print("Starting memory allocation test...") - -# Store results for summary -results = [] - # Test buffer sizes of 2^n, starting from n=1 (2 bytes) n = 1 +subwindow.clean() canary = lv.obj(subwindow) canary.add_flag(lv.obj.FLAG.HIDDEN) -while canary.get_class(): +status = lv.label(subwindow) +status.align(lv.ALIGN.TOP_LEFT, 5, 10) +status.set_style_text_color(lv.color_hex(0xFFFFFF), 0) + +summary = "Running RAM memory tests...\n\n" +summary += "=== Memory Allocation Test Summary ===\n" +summary += "Buffer Size (bytes) | Max Buffers Allocated\n" +summary += "-" * 40 + "\n" +status.set_text(summary) + +while canary.is_valid(): buffer_size = 2 ** n + summary += f"{buffer_size:>12} | " + status.set_text(summary) # Run allocation test gc.collect() max_buffers = test_allocation(buffer_size, n) - results.append((buffer_size, max_buffers)) # Check if we allocated 0 buffers (indicates we can't allocate this size) if max_buffers == 0: print(f"Cannot allocate buffers of size {buffer_size} bytes. Stopping test.") @@ -94,14 +100,12 @@ while canary.get_class(): gc.collect() time.sleep_ms(100) # Brief delay to stabilize system n += 1 - + summary += f"{buffer_size:>12} | " + status.set_text(summary) + summary += f"{max_buffers:>14}\n" + status.set_text(summary) # Print summary report -print("\n=== Memory Allocation Test Summary ===") -print("Buffer Size (bytes) | Max Buffers Allocated") -print("-" * 40) -for buffer_size, max_buffers in results: - print(f"{buffer_size:>18} | {max_buffers:>20}") - print("=====================================") -print("Test completed.") - +summary += "=====================================\n\n" +summary += "Test completed.\n" +status.set_text(summary)