Skip to content

Commit

Permalink
tests/thread: Make exc1,exit1,exit2,stacksize1,start1 tests run on rp2.
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
dpgeorge committed May 10, 2021
1 parent b6b39bf commit 4cdcbdb
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 8 deletions.
7 changes: 6 additions & 1 deletion tests/thread/thread_exc1.py
Expand Up @@ -25,7 +25,12 @@ def thread_entry():

# spawn threads
for i in range(n_thread):
_thread.start_new_thread(thread_entry, ())
while True:
try:
_thread.start_new_thread(thread_entry, ())
break
except OSError:
pass

# busy wait for threads to finish
while n_finished < n_thread:
Expand Down
9 changes: 7 additions & 2 deletions tests/thread/thread_exit1.py
Expand Up @@ -13,8 +13,13 @@ def thread_entry():
_thread.exit()


_thread.start_new_thread(thread_entry, ())
_thread.start_new_thread(thread_entry, ())
for i in range(2):
while True:
try:
_thread.start_new_thread(thread_entry, ())
break
except OSError:
pass

# wait for threads to finish
time.sleep(1)
Expand Down
9 changes: 7 additions & 2 deletions tests/thread/thread_exit2.py
Expand Up @@ -13,8 +13,13 @@ def thread_entry():
raise SystemExit


_thread.start_new_thread(thread_entry, ())
_thread.start_new_thread(thread_entry, ())
for i in range(2):
while True:
try:
_thread.start_new_thread(thread_entry, ())
break
except OSError:
pass

# wait for threads to finish
time.sleep(1)
Expand Down
7 changes: 6 additions & 1 deletion tests/thread/thread_stacksize1.py
Expand Up @@ -41,7 +41,12 @@ def thread_entry():
# set stack size and spawn a few threads
_thread.stack_size(sz)
for i in range(n_thread):
_thread.start_new_thread(thread_entry, ())
while True:
try:
_thread.start_new_thread(thread_entry, ())
break
except OSError:
pass

# reset stack size to default (for subsequent scripts on baremetal)
_thread.stack_size()
Expand Down
9 changes: 7 additions & 2 deletions tests/thread/thread_start1.py
Expand Up @@ -18,8 +18,13 @@ def thread_entry(n):
foo()


_thread.start_new_thread(thread_entry, (10,))
_thread.start_new_thread(thread_entry, (20,))
for i in range(2):
while True:
try:
_thread.start_new_thread(thread_entry, ((i + 1) * 10,))
break
except OSError:
pass

# wait for threads to finish
time.sleep(1)
Expand Down

0 comments on commit 4cdcbdb

Please sign in to comment.