Skip to content

Commit 7b4d08d

Browse files
TaskManager: add disable() functionality and fix unit tests
1 parent 10b14db commit 7b4d08d

File tree

4 files changed

+17
-7
lines changed

4 files changed

+17
-7
lines changed

internal_filesystem/lib/mpos/main.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,9 @@ def custom_exception_handler(e):
8585
# Then start auto_start_app if configured
8686
auto_start_app = prefs.get_string("auto_start_app", None)
8787
if auto_start_app and launcher_app.fullname != auto_start_app:
88-
mpos.apps.start_app(auto_start_app)
88+
result = mpos.apps.start_app(auto_start_app)
89+
if result is not True:
90+
print(f"WARNING: could not run {auto_start_app} app")
8991

9092
# Create limited aiorepl because it's better than nothing:
9193
import aiorepl

internal_filesystem/lib/mpos/task_manager.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ class TaskManager:
66

77
task_list = [] # might be good to periodically remove tasks that are done, to prevent this list from growing huge
88
keep_running = None
9+
disabled = False
910

1011
@classmethod
1112
async def _asyncio_thread(cls, ms_to_sleep):
@@ -17,6 +18,9 @@ async def _asyncio_thread(cls, ms_to_sleep):
1718

1819
@classmethod
1920
def start(cls):
21+
if cls.disabled is True:
22+
print("Not starting TaskManager because it's been disabled.")
23+
return
2024
cls.keep_running = True
2125
# New thread works but LVGL isn't threadsafe so it's preferred to do this in the same thread:
2226
#_thread.stack_size(mpos.apps.good_stack_size())
@@ -28,6 +32,10 @@ def start(cls):
2832
def stop(cls):
2933
cls.keep_running = False
3034

35+
@classmethod
36+
def disable(cls):
37+
cls.disabled = True
38+
3139
@classmethod
3240
def create_task(cls, coroutine):
3341
cls.task_list.append(asyncio.create_task(coroutine))

tests/test_graphical_imu_calibration_ui_bug.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ def test_imu_calibration_bug_test(self):
7373
# Step 4: Click "Check IMU Calibration" (it's a clickable label/container, not a button)
7474
print("Step 4: Clicking 'Check IMU Calibration' menu item...")
7575
self.assertTrue(click_label("Check IMU Calibration"), "Could not find Check IMU Calibration menu item")
76-
wait_for_render(iterations=20)
76+
wait_for_render(iterations=40)
7777

7878
print("Step 5: Checking BEFORE calibration...")
7979
print("Current screen content:")

tests/unittest.sh

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -59,14 +59,14 @@ one_test() {
5959
if [ -z "$ondevice" ]; then
6060
# Desktop execution
6161
if [ $is_graphical -eq 1 ]; then
62-
# Graphical test: include boot_unix.py and main.py
63-
"$binary" -X heapsize=8M -c "$(cat main.py) ; import mpos.main ; import mpos.apps; sys.path.append(\"$tests_abs_path\")
62+
echo "Graphical test: include main.py"
63+
"$binary" -X heapsize=8M -c "import sys ; sys.path.insert(0, 'lib') ; import mpos ; mpos.TaskManager.disable() ; $(cat main.py) ; import mpos.apps; sys.path.append(\"$tests_abs_path\")
6464
$(cat $file)
6565
result = unittest.main() ; sys.exit(0 if result.wasSuccessful() else 1) "
6666
result=$?
6767
else
6868
# Regular test: no boot files
69-
"$binary" -X heapsize=8M -c "$(cat main.py)
69+
"$binary" -X heapsize=8M -c "import sys ; sys.path.insert(0, 'lib') ; import mpos ; mpos.TaskManager.disable() ; $(cat main.py)
7070
$(cat $file)
7171
result = unittest.main() ; sys.exit(0 if result.wasSuccessful() else 1) "
7272
result=$?
@@ -86,7 +86,7 @@ result = unittest.main() ; sys.exit(0 if result.wasSuccessful() else 1) "
8686
echo "$test logging to $testlog"
8787
if [ $is_graphical -eq 1 ]; then
8888
# Graphical test: system already initialized, just add test paths
89-
"$mpremote" exec "$(cat main.py) ; sys.path.append('tests')
89+
"$mpremote" exec "import sys ; sys.path.insert(0, 'lib') ; import mpos ; mpos.TaskManager.disable() ; $(cat main.py) ; sys.path.append('tests')
9090
$(cat $file)
9191
result = unittest.main()
9292
if result.wasSuccessful():
@@ -96,7 +96,7 @@ else:
9696
" | tee "$testlog"
9797
else
9898
# Regular test: no boot files
99-
"$mpremote" exec "$(cat main.py)
99+
"$mpremote" exec "import sys ; sys.path.insert(0, 'lib') ; import mpos ; mpos.TaskManager.disable() ; $(cat main.py)
100100
$(cat $file)
101101
result = unittest.main()
102102
if result.wasSuccessful():

0 commit comments

Comments
 (0)