From bce9bc55b8c223db9d58b6019c2926020e9f3450 Mon Sep 17 00:00:00 2001 From: Thomas Farstrike Date: Wed, 23 Apr 2025 20:04:32 +0200 Subject: [PATCH] Simplify --- apps/com.example.memtest/assets/main.py | 76 ++++++++++++------------- 1 file changed, 36 insertions(+), 40 deletions(-) diff --git a/apps/com.example.memtest/assets/main.py b/apps/com.example.memtest/assets/main.py index 33bd9fa3..86ff2e37 100644 --- a/apps/com.example.memtest/assets/main.py +++ b/apps/com.example.memtest/assets/main.py @@ -32,6 +32,8 @@ import time # Configuration 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})") @@ -66,46 +68,40 @@ def test_allocation(buffer_size, n): gc.collect() return count -def main(): - print("Starting memory allocation test...") - - # Store results for summary - results = [] - - # Test buffer sizes of 2^n, starting from n=1 (2 bytes) - n = 1 - while True: - buffer_size = 2 ** n - # Run allocation test - 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.") - break - - # Clean up memory before next test - gc.collect() - time.sleep_ms(100) # Brief delay to stabilize system - - n += 1 - - # 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.") -if __name__ == "__main__": - try: - # Run garbage collection before starting to ensure clean state - gc.collect() - main() - except Exception as e: - print(f"Error during test: {e}") +print("Starting memory allocation test...") + +# Store results for summary +results = [] + +# Test buffer sizes of 2^n, starting from n=1 (2 bytes) +n = 1 + +canary = lv.obj(subwindow) +canary.add_flag(0x0001) # LV_OBJ_FLAG_HIDDEN is 0x0001 + +while canary.get_class(): + buffer_size = 2 ** n + # 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.") + break + # Clean up memory before next test + gc.collect() + time.sleep_ms(100) # Brief delay to stabilize system + n += 1 +# 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.") +