Update diagnostics/micropython_diagnostics.py
This commit is contained in:
42
diagnostics/micropython_diagnostics.py
Normal file
42
diagnostics/micropython_diagnostics.py
Normal file
@@ -0,0 +1,42 @@
|
||||
import usys
|
||||
import micropython
|
||||
from pybricks import version
|
||||
class MicroPythonDiagnostics:
|
||||
def __init__(self, hub):
|
||||
pass
|
||||
def printVersionDiagnostics():
|
||||
print("[Hub Diagnostics - MicroPython - Version] Hub version information:", version)
|
||||
print("[Hub Diagnostics - MicroPython - Version] MicroPython version:", usys.version)
|
||||
print("[Hub Diagnostics - MicroPython - Version] Pybricks version information:", usys.version_info)
|
||||
print("[Hub Diagnostics - MicroPython - Version] MicroPython information:", usys.implementation)
|
||||
def performMemoryDiagnostics():
|
||||
print("[Hub Diagnostics - MicroPython - Memory] Memory information (retrieved from the MicroPython environment):")
|
||||
micropython.mem_info(1)
|
||||
print("[Hub Diagnostics - MicroPython - Memory] Testing heap lock and unlock.")
|
||||
print("[Hub Diagnostics - MicroPython - Memory] Allocating memory while heap is unlocked:")
|
||||
try:
|
||||
x = 5000
|
||||
print("[Hub Diagnostics - MicroPython - Memory] [SUCCESS] There was no MemoryError raised. The value of the new variable x is", x)
|
||||
except MemoryError:
|
||||
print("[Hub Diagnostics - MicroPython - Memory] [FAIL] Allocation failed. Your memory may be faulty.")
|
||||
print("[Hub Diagnostics - MicroPython - Memory] Locking the heap:")
|
||||
micropython.heap_lock()
|
||||
print("[Hub Diagnostics - MicroPython - Memory] Heap was locked. Attempting to allocate memory (this should fail):")
|
||||
try:
|
||||
y = 10000
|
||||
print("[Hub Diagnostics - MicroPython - Memory] [FAIL] There was no MemoryError raised. Heap lock failed.")
|
||||
except MemoryError:
|
||||
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.
|
||||
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:
|
||||
z = 17000
|
||||
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():
|
||||
printVersionDiagnostics()
|
||||
performMemoryDiagnostics()
|
||||
|
||||
Reference in New Issue
Block a user