diff --git a/apps/com.example.cputest/META-INF/MANIFEST.MF b/apps/com.example.cputest/META-INF/MANIFEST.MF new file mode 100644 index 00000000..9e456428 --- /dev/null +++ b/apps/com.example.cputest/META-INF/MANIFEST.MF @@ -0,0 +1,2 @@ +Manifest-Version: 1.0 +Name: CPUTester diff --git a/apps/com.example.cputest/assets/main.py b/apps/com.example.cputest/assets/main.py new file mode 100644 index 00000000..ff9fe3d5 --- /dev/null +++ b/apps/com.example.cputest/assets/main.py @@ -0,0 +1,83 @@ +import time +import hashlib +import os + +# Configuration +TEST_DURATION = 5 # Duration of each test in seconds +DATA_SIZE = 1024 # 1KB of data for SHA-256 test +DATA = os.urandom(DATA_SIZE) # Generate 1KB of random data for SHA-256 + +def stress_test_busy_loop(): + print("\nStarting busy loop stress test...") + iterations = 0 + start_time = time.ticks_ms() + end_time = start_time + (TEST_DURATION * 1000) + + while time.ticks_ms() < end_time: + iterations += 1 + + duration_ms = time.ticks_diff(time.ticks_ms(), start_time) + iterations_per_second = (iterations / duration_ms) * 1000 + print(f"Busy loop test completed: {iterations_per_second:.2f} iterations/second") + return iterations_per_second + +def stress_test_busy_loop_with_yield(): + print("\nStarting busy loop with yield (sleep_ms(0)) stress test...") + iterations = 0 + start_time = time.ticks_ms() + end_time = start_time + (TEST_DURATION * 1000) + + while time.ticks_ms() < end_time: + iterations += 1 + time.sleep_ms(0) # Yield to other tasks + + duration_ms = time.ticks_diff(time.ticks_ms(), start_time) + iterations_per_second = (iterations / duration_ms) * 1000 + print(f"Busy loop with yield test completed: {iterations_per_second:.2f} iterations/second") + return iterations_per_second + +def stress_test_sha256(): + print("\nStarting SHA-256 stress test (1KB data)...") + iterations = 0 + start_time = time.ticks_ms() + end_time = start_time + (TEST_DURATION * 1000) + + while time.ticks_ms() < end_time: + hashlib.sha256(DATA).digest() # Compute SHA-256 on 1KB data + iterations += 1 + + duration_ms = time.ticks_diff(time.ticks_ms(), start_time) + iterations_per_second = (iterations / duration_ms) * 1000 + print(f"SHA-256 test completed: {iterations_per_second:.2f} iterations/second") + return iterations_per_second + +def main(): + print("Starting CPU stress tests...") + + # Run busy loop test + busy_loop_ips = stress_test_busy_loop() + + # Small delay to stabilize system + time.sleep_ms(500) + + # Run busy loop with yield test + yield_loop_ips = stress_test_busy_loop_with_yield() + + # Small delay to stabilize system + time.sleep_ms(500) + + # Run SHA-256 test + sha256_ips = stress_test_sha256() + + # Summary + print("\nTest Summary:") + print(f"Busy loop: {busy_loop_ips:.2f} iterations/second") + print(f"Busy loop with yield: {yield_loop_ips:.2f} iterations/second") + print(f"SHA-256 (1KB): {sha256_ips:.2f} iterations/second") + print("All tests completed.") + +try: + main() +except Exception as e: + print(f"Error during tests: {e}") + diff --git a/apps/com.example.cputest/res/mipmap-mdpi/launcher_icon.png b/apps/com.example.cputest/res/mipmap-mdpi/launcher_icon.png new file mode 100644 index 00000000..f28f284c Binary files /dev/null and b/apps/com.example.cputest/res/mipmap-mdpi/launcher_icon.png differ diff --git a/apps/com.example.memtester/META-INF/MANIFEST.MF b/apps/com.example.memtester/META-INF/MANIFEST.MF new file mode 100644 index 00000000..0c810526 --- /dev/null +++ b/apps/com.example.memtester/META-INF/MANIFEST.MF @@ -0,0 +1,2 @@ +Manifest-Version: 1.0 +Name: MemTest diff --git a/apps/com.example.memtester/assets/main.py b/apps/com.example.memtester/assets/main.py new file mode 100644 index 00000000..1c0f7686 --- /dev/null +++ b/apps/com.example.memtester/assets/main.py @@ -0,0 +1,83 @@ +import gc +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})") + buffers = [] + count = 0 + + try: + while True: + # Measure time for allocation + start_time = time.ticks_ms() + # Allocate a new buffer + buffer = bytearray(buffer_size) + allocation_time = time.ticks_diff(time.ticks_ms(), start_time) + + # Check if allocation took too long + if allocation_time > ALLOCATION_TIMEOUT_MS: + print(f"\nStopped after allocating {count} buffers of {buffer_size} bytes: Allocation timeout ({allocation_time}ms > {ALLOCATION_TIMEOUT_MS}ms)") + break + + buffers.append(buffer) + count += 1 + # Print progress every 100 allocations to avoid flooding serial + if count % 100 == 0: + print(f"Allocated {count} buffers of {buffer_size} bytes", end="\r") + except MemoryError: + print(f"\nStopped after allocating {count} buffers of {buffer_size} bytes: MemoryError") + except Exception as e: + print(f"\nStopped after allocating {count} buffers of {buffer_size} bytes: {e}") + + # Free allocated buffers + buffers.clear() + 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}") + + diff --git a/apps/com.example.memtester/res/mipmap-mdpi/launcher_icon.png b/apps/com.example.memtester/res/mipmap-mdpi/launcher_icon.png new file mode 100644 index 00000000..f28f284c Binary files /dev/null and b/apps/com.example.memtester/res/mipmap-mdpi/launcher_icon.png differ diff --git a/apps/com.example.threadtester/assets/main.py b/apps/com.example.threadtester/assets/main.py index 168a318e..1c663261 100644 --- a/apps/com.example.threadtester/assets/main.py +++ b/apps/com.example.threadtester/assets/main.py @@ -1,3 +1,11 @@ +# Maximum threads with stack size 1024: 48 +# Maximum threads with stack size 2048: 48 +# Maximum threads with stack size 4096: 48 +# Maximum threads with stack size 8192: 22 +# Maximum threads with stack size 16386: 10 +# Maximum threads with stack size 32768: 3 +# Maximum threads with stack size 65536: 1 + import _thread import time @@ -65,7 +73,7 @@ def main(): wifi_icon = lv.label(lv.screen_active()) wifi_icon.set_text("Test label") wifi_icon.align(lv.ALIGN.CENTER, 0, 0) - wifi_icon.set_style_text_color(COLOR_TEXT_WHITE, 0) + wifi_icon.set_style_text_color(lv.color_hex(0x0000FF), 0) print("done!") @@ -76,4 +84,3 @@ if __name__ == "__main__": except Exception as e: print(f"Error in main: {e}") -main() diff --git a/main.py b/main.py index 754a5a5b..2ffea7a8 100644 --- a/main.py +++ b/main.py @@ -230,8 +230,8 @@ def execute_script(script_source, is_file, lvgl_obj, return_to_launcher): script_globals = { 'lv': lv, 'subwindow': lvgl_obj, - 'run_app': run_app - #'run_launcher' : run_launcher + 'run_app': run_app, + '__name__': "__main__" } if is_file: print(f"Thread {thread_id}: reading script from file: {script_source}")