8000 tests/thread: Make exc1,exit1,exit2,stacksize1,start1 tests run on rp2. · micropython/micropython@b63767a · GitHub
[go: up one dir, main page]

Skip to content

Commit b63767a

Browse files
committed
tests/thread: Make exc1,exit1,exit2,stacksize1,start1 tests run on rp2.
The RP2040 has 2 cores and supports running at most 2 Python threads (the main one plus another), and will raise OSError if a thread cannot be created because core1 is already in use. This commit adjusts some thread tests to be robust against such OSError's. These tests now pass on rp2 boards. Signed-off-by: Damien George <damien@micropython.org>
1 parent 555fa59 commit b63767a

File tree

5 files changed

+33
-8
lines changed

5 files changed

+33
-8
lines changed

tests/thread/thread_exc1.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,12 @@ def thread_entry():
2525

2626
# spawn threads
2727
for i in range(n_thread):
28-
_thread.start_new_thread(thread_entry, ())
28+
while True:
29+
try:
30+
_thread.start_new_thread(thread_entry, ())
31+
break
32+
except OSError:
33+
pass
2934

3035
# busy wait for threads to finish
3136
while n_finished < n_thread:

tests/thread/thread_exit1.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,13 @@ def thread_entry():
1313
_thread.exit()
1414

1515

16-
_thread.start_new_thread(thread_entry, ())
17-
_thread.start_new_thread(thread_entry, ())
16+
for i in range(2):
17+
while True:
18+
try:
19+
_thread.start_new_thread(thread_entry, ())
20+
break
21+
except OSError:
22+
pass
1823

1924
# wait for threads to finish
2025
time.sleep(1)

tests/thread/thread_exit2.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,13 @@ def thread_entry():
1313
raise SystemExit
1414

1515

16-
_thread.start_new_thread(thread_entry, ())
17-
_thread.start_new_thread(thread_entry, ())
16+
for i in range(2):
17+
while True:
18+
try:
19+
_thread.start_new_thread(thread_entry, ())
20+
break
21+
except OSError:
22+
pass
1823

1924
# wait for threads to finish
2025
time.sleep(1)

tests/thread/thread_stacksize1.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,12 @@ def thread_entry():
4141
# set stack size and spawn a few threads
4242
_thread.stack_size(sz)
4343
for i in range(n_thread):
44-
_thread.start_new_thread(thread_entry, ())
44+
while True:
45+
try:
46+
_thread.start_new_thread(thread_entry, ())
47+
break
48+
except OSError:
49+
pass
4550

4651
# reset stack size to default (for subsequent scripts on baremetal)
4752
_thread.stack_size()

tests/thread/thread_start1.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,13 @@ def thread_entry(n):
1818
foo()
1919

2020

21-
_thread.start_new_thread(thread_entry, (10,))
22-
_thread.start_new_thread(thread_entry, (20,))
21+
for i in range(2):
22+
while True:
23+
try:
24+
_thread.start_new_thread(thread_entry, ((i + 1) * 10,))
25+
break
26+
except OSError:
27+
pass
2328

2429
# wait for threads to finish
2530
time.sleep(1)

0 commit comments

Comments
 (0)
0