From 5ad27d4b8bb248954d98178e068a382599dadfa6 Mon Sep 17 00:00:00 2001 From: Damien George Date: Tue, 10 Apr 2018 14:42:42 +1000 Subject: tests: Move recursive tests to the tests/stress/ subdir. Keeping all the stress related tests in one place makes it easier to stress-test a given port, and to also not run such tests on ports that can't handle them. --- tests/stress/recursion.py | 7 +++++ tests/stress/recursive_data.py | 13 ++++++++ tests/stress/recursive_data.py.exp | 1 + tests/stress/recursive_iternext.py | 57 ++++++++++++++++++++++++++++++++++ tests/stress/recursive_iternext.py.exp | 4 +++ 5 files changed, 82 insertions(+) create mode 100644 tests/stress/recursion.py create mode 100644 tests/stress/recursive_data.py create mode 100644 tests/stress/recursive_data.py.exp create mode 100644 tests/stress/recursive_iternext.py create mode 100644 tests/stress/recursive_iternext.py.exp (limited to 'tests/stress') diff --git a/tests/stress/recursion.py b/tests/stress/recursion.py new file mode 100644 index 000000000..227f48396 --- /dev/null +++ b/tests/stress/recursion.py @@ -0,0 +1,7 @@ +def foo(): + foo() + +try: + foo() +except RuntimeError: + print("RuntimeError") diff --git a/tests/stress/recursive_data.py b/tests/stress/recursive_data.py new file mode 100644 index 000000000..3b7fa5095 --- /dev/null +++ b/tests/stress/recursive_data.py @@ -0,0 +1,13 @@ +# This tests that printing recursive data structure doesn't lead to segfault. +try: + import uio as io +except ImportError: + print("SKIP") + raise SystemExit + +l = [1, 2, 3, None] +l[-1] = l +try: + print(l, file=io.StringIO()) +except RuntimeError: + print("RuntimeError") diff --git a/tests/stress/recursive_data.py.exp b/tests/stress/recursive_data.py.exp new file mode 100644 index 000000000..8a2b9bfdd --- /dev/null +++ b/tests/stress/recursive_data.py.exp @@ -0,0 +1 @@ +RuntimeError diff --git a/tests/stress/recursive_iternext.py b/tests/stress/recursive_iternext.py new file mode 100644 index 000000000..edb5a843f --- /dev/null +++ b/tests/stress/recursive_iternext.py @@ -0,0 +1,57 @@ +# This tests that recursion with iternext doesn't lead to segfault. +try: + enumerate + filter + map + max + zip +except: + print("SKIP") + raise SystemExit + +# We need to pick an N that is large enough to hit the recursion +# limit, but not too large that we run out of heap memory. +try: + # large stack/heap, eg unix + [0] * 80000 + N = 2400 +except: + try: + # medium, eg pyboard + [0] * 10000 + N = 1000 + except: + # small, eg esp8266 + N = 100 + +try: + x = (1, 2) + for i in range(N): + x = enumerate(x) + tuple(x) +except RuntimeError: + print("RuntimeError") + +try: + x = (1, 2) + for i in range(N): + x = filter(None, x) + tuple(x) +except RuntimeError: + print("RuntimeError") + +try: + x = (1, 2) + for i in range(N): + x = map(max, x, ()) + tuple(x) +except RuntimeError: + print("RuntimeError") + +try: + x = (1, 2) + for i in range(N): + x = zip(x) + tuple(x) +except RuntimeError: + print("RuntimeError") diff --git a/tests/stress/recursive_iternext.py.exp b/tests/stress/recursive_iternext.py.exp new file mode 100644 index 000000000..80d1488a3 --- /dev/null +++ b/tests/stress/recursive_iternext.py.exp @@ -0,0 +1,4 @@ +RuntimeError +RuntimeError +RuntimeError +RuntimeError -- cgit v1.2.3