Update diagnostics/MicroPythonDiagnostics.py

This commit is contained in:
2026-01-30 14:30:56 +00:00
parent 07bbba41e4
commit f5b51cb3aa

View File

@@ -16,18 +16,26 @@ class MicroPythonDiagnostics:
print("[Hub Diagnostics - MicroPython - Memory] Allocating memory while heap is unlocked:") print("[Hub Diagnostics - MicroPython - Memory] Allocating memory while heap is unlocked:")
try: try:
x = 5000 x = 5000
print("[Hub Diagnostics - MicroPython - Memory] There was no MemoryError raised. The value of the variable x is", x) print("[Hub Diagnostics - MicroPython - Memory] [SUCCESS] There was no MemoryError raised. The value of the new variable x is", x)
except MemoryError: except MemoryError:
print("[Hub Diagnostics - MicroPython - Memory] Allocation failed. Your memory may be faulty.") print("[Hub Diagnostics - MicroPython - Memory] [FAIL] Allocation failed. Your memory may be faulty.")
print("[Hub Diagnostics - MicroPython - Memory] Locking the heap:") print("[Hub Diagnostics - MicroPython - Memory] Locking the heap:")
micropython.heap_lock() micropython.heap_lock()
print("[Hub Diagnostics - MicroPython - Memory] Heap was locked. Attempting to allocate memory (this should fail):") print("[Hub Diagnostics - MicroPython - Memory] Heap was locked. Attempting to allocate memory (this should fail):")
try: try:
x = 5000 x = 5000
print("[Hub Diagnostics - MicroPython - Memory] There was no MemoryError raised. Heap lock failed.") print("[Hub Diagnostics - MicroPython - Memory] [FAIL] There was no MemoryError raised. Heap lock failed.")
except MemoryError: except MemoryError:
print("[Hub Diagnostics - MicroPython - Memory] Allocation failed. Test successful. The heap was successfully locked.") print("[Hub Diagnostics - MicroPython - Memory] [SUCCESS] Allocation failed. Test successful. The heap was successfully locked.")
# Attempt to add gc to this for memory diagnostics, in addition test machine.soft_reset() and add that first to reset the heap. # Attempt to add gc to this for memory diagnostics, in addition test machine.soft_reset() and add that first to reset the heap.
print("[Hub Diagnostics - MicroPython - Memory] Unlocking the heap:")
micropython.heap_unlock()
print("[Hub Diagnostics - MicroPython - Memory] Heap was unlocked. Attempting to allocate memory (this should succeed):")
try:
y = 5001
print("[Hub Diagnostics - MicroPython - Memory] [SUCCESS] There was no MemoryError raised. The value of the new variable y is", x)
except MemoryError:
print("[Hub Diagnostics - MicroPython - Memory] [FAIL] Allocation failed. The heap failed to unlock.")
def printAll(): def printAll():
printVersionDiagnostics() printVersionDiagnostics()
performMemoryDiagnostics() performMemoryDiagnostics()