diff options
Diffstat (limited to 'tests/thread')
-rw-r--r-- | tests/thread/stress_create.py | 22 | ||||
-rw-r--r-- | tests/thread/stress_heap.py | 8 | ||||
-rw-r--r-- | tests/thread/thread_exc2.py.exp | 2 | ||||
-rw-r--r-- | tests/thread/thread_lock4.py | 5 | ||||
-rw-r--r-- | tests/thread/thread_qstr1.py | 8 | ||||
-rw-r--r-- | tests/thread/thread_stacksize1.py | 3 |
6 files changed, 43 insertions, 5 deletions
diff --git a/tests/thread/stress_create.py b/tests/thread/stress_create.py new file mode 100644 index 000000000..2399746cc --- /dev/null +++ b/tests/thread/stress_create.py @@ -0,0 +1,22 @@ +# stress test for creating many threads + +try: + import utime as time +except ImportError: + import time +import _thread + +def thread_entry(n): + pass + +thread_num = 0 +while thread_num < 500: + try: + _thread.start_new_thread(thread_entry, (thread_num,)) + thread_num += 1 + except MemoryError: + pass + +# wait for the last threads to terminate +time.sleep(1) +print('done') diff --git a/tests/thread/stress_heap.py b/tests/thread/stress_heap.py index ac3ebe049..5482a9ac6 100644 --- a/tests/thread/stress_heap.py +++ b/tests/thread/stress_heap.py @@ -3,6 +3,10 @@ # # MIT license; Copyright (c) 2016 Damien P. George on behalf of Pycom Ltd +try: + import utime as time +except ImportError: + import time import _thread def last(l): @@ -37,6 +41,6 @@ n_finished = 0 for i in range(n_thread): _thread.start_new_thread(thread_entry, (10000,)) -# busy wait for threads to finish +# wait for threads to finish while n_finished < n_thread: - pass + time.sleep(1) diff --git a/tests/thread/thread_exc2.py.exp b/tests/thread/thread_exc2.py.exp index 584bfab4d..cc7a20aa2 100644 --- a/tests/thread/thread_exc2.py.exp +++ b/tests/thread/thread_exc2.py.exp @@ -1,5 +1,5 @@ Unhandled exception in thread started by <function thread_entry at 0x\[0-9a-f\]\+> Traceback (most recent call last): - File "thread/thread_exc2.py", line 6, in thread_entry + File \.\+, line 6, in thread_entry ValueError: done diff --git a/tests/thread/thread_lock4.py b/tests/thread/thread_lock4.py index d77aa24ee..2f9d42d6b 100644 --- a/tests/thread/thread_lock4.py +++ b/tests/thread/thread_lock4.py @@ -2,6 +2,10 @@ # # MIT license; Copyright (c) 2016 Damien P. George on behalf of Pycom Ltd +try: + import utime as time +except ImportError: + import time import _thread def fac(n): @@ -39,6 +43,7 @@ while True: with jobs_lock: if len(output) == n_jobs: break + time.sleep(1) # sort and print the results output.sort(key=lambda x: x[0]) diff --git a/tests/thread/thread_qstr1.py b/tests/thread/thread_qstr1.py index c0256316e..f4136d964 100644 --- a/tests/thread/thread_qstr1.py +++ b/tests/thread/thread_qstr1.py @@ -2,6 +2,10 @@ # # MIT license; Copyright (c) 2016 Damien P. George on behalf of Pycom Ltd +try: + import utime as time +except ImportError: + import time import _thread # function to check the interned string @@ -28,8 +32,8 @@ n_qstr_per_thread = 100 # make 1000 for a more stressful test (uses more heap) for i in range(n_thread): _thread.start_new_thread(th, (i * n_qstr_per_thread, n_qstr_per_thread)) -# busy wait for threads to finish +# wait for threads to finish while n_finished < n_thread: - pass + time.sleep(1) print('pass') diff --git a/tests/thread/thread_stacksize1.py b/tests/thread/thread_stacksize1.py index e62899631..62b6e5e40 100644 --- a/tests/thread/thread_stacksize1.py +++ b/tests/thread/thread_stacksize1.py @@ -38,6 +38,9 @@ _thread.stack_size(sz) for i in range(n_thread): _thread.start_new_thread(thread_entry, ()) +# reset stack size to default (for subsequent scripts on baremetal) +_thread.stack_size() + # busy wait for threads to finish while n_finished < n_thread: pass |