aboutsummaryrefslogtreecommitdiff
path: root/tests/thread/thread_stacksize1.py
diff options
context:
space:
mode:
authorDamien George2016-04-20 14:23:55 +0000
committerDamien George2016-06-28 11:09:31 +0100
commit2d5ea38b4996bec01cabda68b6ef12631a7b7a08 (patch)
tree968674ad27f0ef01a8f5b4c8b546831ddfa7260b /tests/thread/thread_stacksize1.py
parented36632c6cc227206994cf68b4a4afec2b694e49 (diff)
tests: Add 3 more tests for _thread module.
Diffstat (limited to 'tests/thread/thread_stacksize1.py')
-rw-r--r--tests/thread/thread_stacksize1.py36
1 files changed, 36 insertions, 0 deletions
diff --git a/tests/thread/thread_stacksize1.py b/tests/thread/thread_stacksize1.py
new file mode 100644
index 000000000..b0118843b
--- /dev/null
+++ b/tests/thread/thread_stacksize1.py
@@ -0,0 +1,36 @@
+# test setting the thread stack size
+#
+# MIT license; Copyright (c) 2016 Damien P. George on behalf of Pycom Ltd
+
+import sys
+try:
+ import utime as time
+except ImportError:
+ import time
+import _thread
+
+# different implementations have different minimum sizes
+if sys.implementation == 'micropython':
+ sz = 2 * 1024
+else:
+ sz = 32 * 1024
+
+def foo():
+ pass
+
+def thread_entry():
+ foo()
+
+# test set/get of stack size
+print(_thread.stack_size())
+print(_thread.stack_size(sz))
+print(_thread.stack_size() == sz)
+print(_thread.stack_size())
+
+# set stack size and spawn a few threads
+_thread.stack_size(sz)
+for i in range(2):
+ _thread.start_new_thread(thread_entry, ())
+
+time.sleep(0.2)
+print('done')