From ed36632c6cc227206994cf68b4a4afec2b694e49 Mon Sep 17 00:00:00 2001 From: Damien George Date: Tue, 19 Apr 2016 17:03:26 +0000 Subject: tests: Add tests for _thread module. Includes functionality and stress tests. --- tests/thread/thread_exit2.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 tests/thread/thread_exit2.py (limited to 'tests/thread/thread_exit2.py') diff --git a/tests/thread/thread_exit2.py b/tests/thread/thread_exit2.py new file mode 100644 index 0000000000..797b52c353 --- /dev/null +++ b/tests/thread/thread_exit2.py @@ -0,0 +1,19 @@ +# test raising SystemExit to finish a thread +# +# 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 thread_entry(): + raise SystemExit + +_thread.start_new_thread(thread_entry, ()) +_thread.start_new_thread(thread_entry, ()) + +# wait for threads to finish +time.sleep(0.2) +print('done') -- cgit v1.2.3 From 15e68277c109d238bfb9c5bb8ab7db2f89e24c26 Mon Sep 17 00:00:00 2001 From: Damien George Date: Tue, 31 May 2016 11:54:34 +0100 Subject: tests/thread: Make sure that thread tests don't rely on floating point. --- tests/thread/stress_aes.py | 2 +- tests/thread/thread_exit1.py | 2 +- tests/thread/thread_exit2.py | 2 +- tests/thread/thread_lock2.py | 2 +- tests/thread/thread_sleep1.py | 2 +- tests/thread/thread_start1.py | 2 +- tests/thread/thread_start2.py | 2 +- 7 files changed, 7 insertions(+), 7 deletions(-) (limited to 'tests/thread/thread_exit2.py') diff --git a/tests/thread/stress_aes.py b/tests/thread/stress_aes.py index 6ef285595a..ecc963c925 100644 --- a/tests/thread/stress_aes.py +++ b/tests/thread/stress_aes.py @@ -252,4 +252,4 @@ if __name__ == '__main__': for i in range(n_thread): _thread.start_new_thread(thread_entry, ()) while count.value < n_thread: - time.sleep(0.1) + time.sleep(1) diff --git a/tests/thread/thread_exit1.py b/tests/thread/thread_exit1.py index aa35995c13..88cdd165c7 100644 --- a/tests/thread/thread_exit1.py +++ b/tests/thread/thread_exit1.py @@ -15,5 +15,5 @@ _thread.start_new_thread(thread_entry, ()) _thread.start_new_thread(thread_entry, ()) # wait for threads to finish -time.sleep(0.2) +time.sleep(1) print('done') diff --git a/tests/thread/thread_exit2.py b/tests/thread/thread_exit2.py index 797b52c353..368a11bba4 100644 --- a/tests/thread/thread_exit2.py +++ b/tests/thread/thread_exit2.py @@ -15,5 +15,5 @@ _thread.start_new_thread(thread_entry, ()) _thread.start_new_thread(thread_entry, ()) # wait for threads to finish -time.sleep(0.2) +time.sleep(1) print('done') diff --git a/tests/thread/thread_lock2.py b/tests/thread/thread_lock2.py index 25953d9ffc..405f10b0b6 100644 --- a/tests/thread/thread_lock2.py +++ b/tests/thread/thread_lock2.py @@ -20,5 +20,5 @@ for i in range(4): _thread.start_new_thread(thread_entry, ()) # wait for threads to finish -time.sleep(0.2) +time.sleep(1) print('done') diff --git a/tests/thread/thread_sleep1.py b/tests/thread/thread_sleep1.py index 0fb8de86e0..5f7534f6a1 100644 --- a/tests/thread/thread_sleep1.py +++ b/tests/thread/thread_sleep1.py @@ -24,5 +24,5 @@ for i in range(n_thread): # wait for threads to finish while n_finished < n_thread: - time.sleep(0.1) + time.sleep(1) print('done', n_thread) diff --git a/tests/thread/thread_start1.py b/tests/thread/thread_start1.py index b799fbe020..d23a74aa21 100644 --- a/tests/thread/thread_start1.py +++ b/tests/thread/thread_start1.py @@ -19,5 +19,5 @@ _thread.start_new_thread(thread_entry, (10,)) _thread.start_new_thread(thread_entry, (20,)) # wait for threads to finish -time.sleep(0.2) +time.sleep(1) print('done') diff --git a/tests/thread/thread_start2.py b/tests/thread/thread_start2.py index 2b444cc0c3..4efa808eb9 100644 --- a/tests/thread/thread_start2.py +++ b/tests/thread/thread_start2.py @@ -15,5 +15,5 @@ def thread_entry(a0, a1, a2, a3): _thread.start_new_thread(thread_entry, (10, 20), {'a2': 0, 'a3': 1}) # wait for thread to finish -time.sleep(0.2) +time.sleep(1) print('done') -- cgit v1.2.3