summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/basics/array1.py6
-rw-r--r--tests/basics/errno1.py15
-rw-r--r--tests/basics/errno1.py.exp2
-rw-r--r--tests/basics/struct1.py2
-rw-r--r--tests/extmod/framebuf1.py41
-rw-r--r--tests/extmod/framebuf1.py.exp9
-rw-r--r--tests/extmod/machine_pulse.py54
-rw-r--r--tests/extmod/machine_pulse.py.exp9
-rw-r--r--tests/extmod/urandom_basic.py6
-rw-r--r--tests/extmod/urandom_extra.py37
-rw-r--r--tests/extmod/uzlib_decompio.py15
-rw-r--r--tests/extmod/uzlib_decompio.py.exp3
-rw-r--r--tests/pyb/extint.py9
-rw-r--r--tests/pyb/extint.py.exp1
-rwxr-xr-xtests/run-tests1
15 files changed, 209 insertions, 1 deletions
diff --git a/tests/basics/array1.py b/tests/basics/array1.py
index bce22cc57..e5ea6683c 100644
--- a/tests/basics/array1.py
+++ b/tests/basics/array1.py
@@ -6,6 +6,12 @@ i = array.array('I', [1, 2, 3])
print(i, len(i))
print(a[0])
print(i[-1])
+a = array.array('l', [-1])
+print(len(a), a[0])
+a1 = array.array('l', [1, 2, 3])
+a2 = array.array('L', [1, 2, 3])
+print(a2[1])
+print(a1 == a2)
# Empty arrays
print(len(array.array('h')))
diff --git a/tests/basics/errno1.py b/tests/basics/errno1.py
new file mode 100644
index 000000000..680104481
--- /dev/null
+++ b/tests/basics/errno1.py
@@ -0,0 +1,15 @@
+# test errno's and uerrno module
+
+try:
+ import uerrno
+except ImportError:
+ print("SKIP")
+ import sys
+ sys.exit()
+
+# check that constants exist and are integers
+print(type(uerrno.EIO))
+
+# check that errors are rendered in a nice way
+msg = str(OSError(uerrno.EIO))
+print(msg[:7], msg[-5:])
diff --git a/tests/basics/errno1.py.exp b/tests/basics/errno1.py.exp
new file mode 100644
index 000000000..e60fdf049
--- /dev/null
+++ b/tests/basics/errno1.py.exp
@@ -0,0 +1,2 @@
+<class 'int'>
+[Errno ] EIO
diff --git a/tests/basics/struct1.py b/tests/basics/struct1.py
index 857e171c1..1abe34b4c 100644
--- a/tests/basics/struct1.py
+++ b/tests/basics/struct1.py
@@ -10,6 +10,8 @@ print(struct.unpack(">bI", b"\x80\0\0\x01\0"))
# 32-bit little-endian specific
#print(struct.unpack("bI", b"\x80\xaa\x55\xaa\0\0\x01\0"))
+print(struct.pack("<l", 1))
+print(struct.pack(">l", 1))
print(struct.pack("<i", 1))
print(struct.pack(">i", 1))
print(struct.pack("<h", 1))
diff --git a/tests/extmod/framebuf1.py b/tests/extmod/framebuf1.py
new file mode 100644
index 000000000..f550b6b4f
--- /dev/null
+++ b/tests/extmod/framebuf1.py
@@ -0,0 +1,41 @@
+try:
+ import framebuf
+except ImportError:
+ print("SKIP")
+ import sys
+ sys.exit()
+
+w = 5
+h = 16
+buf = bytearray(w * h // 8)
+fbuf = framebuf.FrameBuffer1(buf, w, h, w)
+
+# fill
+fbuf.fill(1)
+print(buf)
+fbuf.fill(0)
+print(buf)
+
+# put pixel
+fbuf.pixel(0, 0, 1)
+fbuf.pixel(4, 0, 1)
+fbuf.pixel(0, 15, 1)
+fbuf.pixel(4, 15, 1)
+print(buf)
+
+# get pixel
+print(fbuf.pixel(0, 0), fbuf.pixel(1, 1))
+
+# scroll
+fbuf.fill(0)
+fbuf.pixel(2, 7, 1)
+fbuf.scroll(0, 1)
+print(buf)
+fbuf.scroll(0, -2)
+print(buf)
+fbuf.scroll(1, 0)
+print(buf)
+fbuf.scroll(-1, 0)
+print(buf)
+fbuf.scroll(2, 2)
+print(buf)
diff --git a/tests/extmod/framebuf1.py.exp b/tests/extmod/framebuf1.py.exp
new file mode 100644
index 000000000..8fd8c3709
--- /dev/null
+++ b/tests/extmod/framebuf1.py.exp
@@ -0,0 +1,9 @@
+bytearray(b'\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff')
+bytearray(b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00')
+bytearray(b'\x01\x00\x00\x00\x01\x80\x00\x00\x00\x80')
+1 0
+bytearray(b'\x00\x00\x00\x00\x00\x00\x00\x01\x00\x00')
+bytearray(b'\x00\x00@\x00\x00\x00\x00\x00\x00\x00')
+bytearray(b'\x00\x00\x00@\x00\x00\x00\x00\x00\x00')
+bytearray(b'\x00\x00@\x00\x00\x00\x00\x00\x00\x00')
+bytearray(b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01')
diff --git a/tests/extmod/machine_pulse.py b/tests/extmod/machine_pulse.py
new file mode 100644
index 000000000..b6e126435
--- /dev/null
+++ b/tests/extmod/machine_pulse.py
@@ -0,0 +1,54 @@
+try:
+ import umachine as machine
+except ImportError:
+ import machine
+try:
+ machine.PinBase
+ machine.time_pulse_us
+except AttributeError:
+ print("SKIP")
+ import sys
+ sys.exit()
+
+
+class ConstPin(machine.PinBase):
+
+ def __init__(self, value):
+ self.v = value
+
+ def value(self, v=None):
+ if v is None:
+ return self.v
+ else:
+ self.v = v
+
+
+class TogglePin(machine.PinBase):
+
+ def __init__(self):
+ self.v = 0
+
+ def value(self, v=None):
+ if v is None:
+ self.v = 1 - self.v
+ print("value:", self.v)
+ return self.v
+
+
+p = TogglePin()
+
+t = machine.time_pulse_us(p, 1)
+print(type(t))
+t = machine.time_pulse_us(p, 0)
+print(type(t))
+
+p = ConstPin(0)
+try:
+ machine.time_pulse_us(p, 1, 10)
+except OSError:
+ print("OSError")
+
+try:
+ machine.time_pulse_us(p, 0, 10)
+except OSError:
+ print("OSError")
diff --git a/tests/extmod/machine_pulse.py.exp b/tests/extmod/machine_pulse.py.exp
new file mode 100644
index 000000000..f9a474218
--- /dev/null
+++ b/tests/extmod/machine_pulse.py.exp
@@ -0,0 +1,9 @@
+value: 1
+value: 0
+<class 'int'>
+value: 1
+value: 0
+value: 1
+<class 'int'>
+OSError
+OSError
diff --git a/tests/extmod/urandom_basic.py b/tests/extmod/urandom_basic.py
index 7e4d8bf34..bf00035bd 100644
--- a/tests/extmod/urandom_basic.py
+++ b/tests/extmod/urandom_basic.py
@@ -17,3 +17,9 @@ random.seed(1)
r = random.getrandbits(16)
random.seed(1)
print(random.getrandbits(16) == r)
+
+# check that it throws an error for zero bits
+try:
+ random.getrandbits(0)
+except ValueError:
+ print('ValueError')
diff --git a/tests/extmod/urandom_extra.py b/tests/extmod/urandom_extra.py
index a9ecd881d..004fb10cc 100644
--- a/tests/extmod/urandom_extra.py
+++ b/tests/extmod/urandom_extra.py
@@ -16,6 +16,31 @@ for i in range(50):
assert 2 <= random.randrange(2, 6) < 6
assert -2 <= random.randrange(-2, 2) < 2
assert random.randrange(1, 9, 2) in (1, 3, 5, 7)
+ assert random.randrange(2, 1, -1) in (1, 2)
+
+# empty range
+try:
+ random.randrange(0)
+except ValueError:
+ print('ValueError')
+
+# empty range
+try:
+ random.randrange(2, 1)
+except ValueError:
+ print('ValueError')
+
+# zero step
+try:
+ random.randrange(2, 1, 0)
+except ValueError:
+ print('ValueError')
+
+# empty range
+try:
+ random.randrange(2, 1, 1)
+except ValueError:
+ print('ValueError')
print('randint')
for i in range(50):
@@ -23,11 +48,23 @@ for i in range(50):
assert 2 <= random.randint(2, 6) <= 6
assert -2 <= random.randint(-2, 2) <= 2
+# empty range
+try:
+ random.randint(2, 1)
+except ValueError:
+ print('ValueError')
+
print('choice')
lst = [1, 2, 5, 6]
for i in range(50):
assert random.choice(lst) in lst
+# empty sequence
+try:
+ random.choice([])
+except IndexError:
+ print('IndexError')
+
print('random')
for i in range(50):
assert 0 <= random.random() < 1
diff --git a/tests/extmod/uzlib_decompio.py b/tests/extmod/uzlib_decompio.py
index ee3204d07..75a6df0ca 100644
--- a/tests/extmod/uzlib_decompio.py
+++ b/tests/extmod/uzlib_decompio.py
@@ -7,7 +7,7 @@ import uio as io
# Raw DEFLATE bitstream
buf = io.BytesIO(b'\xcbH\xcd\xc9\xc9\x07\x00')
-inp = zlib.DecompIO(buf)
+inp = zlib.DecompIO(buf, -8)
print(buf.seek(0, 1))
print(inp.read(1))
print(buf.seek(0, 1))
@@ -17,3 +17,16 @@ print(buf.seek(0, 1))
print(inp.read(1))
print(inp.read())
print(buf.seek(0, 1))
+
+
+# zlib bitstream
+inp = zlib.DecompIO(io.BytesIO(b'x\x9c30\xa0=\x00\x00\xb3q\x12\xc1'))
+print(inp.read(10))
+print(inp.read())
+
+# zlib bitstream, wrong checksum
+inp = zlib.DecompIO(io.BytesIO(b'x\x9c30\xa0=\x00\x00\xb3q\x12\xc0'))
+try:
+ print(inp.read())
+except OSError as e:
+ print(repr(e))
diff --git a/tests/extmod/uzlib_decompio.py.exp b/tests/extmod/uzlib_decompio.py.exp
index 6ef811d7d..3f5f360fa 100644
--- a/tests/extmod/uzlib_decompio.py.exp
+++ b/tests/extmod/uzlib_decompio.py.exp
@@ -7,3 +7,6 @@ b'lo'
b''
b''
7
+b'0000000000'
+b'000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000'
+OSError(22,)
diff --git a/tests/pyb/extint.py b/tests/pyb/extint.py
index 47d84c8b5..a8ba484b1 100644
--- a/tests/pyb/extint.py
+++ b/tests/pyb/extint.py
@@ -1,8 +1,17 @@
import pyb
+# test basic functionality
ext = pyb.ExtInt('X1', pyb.ExtInt.IRQ_RISING, pyb.Pin.PULL_DOWN, lambda l:print('line:', l))
ext.disable()
ext.enable()
print(ext.line())
ext.swint()
+
+# test swint while disabled, then again after re-enabled
+ext.disable()
+ext.swint()
+ext.enable()
+ext.swint()
+
+# disable now that the test is finished
ext.disable()
diff --git a/tests/pyb/extint.py.exp b/tests/pyb/extint.py.exp
index 28019d75c..daed01c7f 100644
--- a/tests/pyb/extint.py.exp
+++ b/tests/pyb/extint.py.exp
@@ -1,2 +1,3 @@
0
line: 0
+line: 0
diff --git a/tests/run-tests b/tests/run-tests
index 5e8819729..059e4e910 100755
--- a/tests/run-tests
+++ b/tests/run-tests
@@ -203,6 +203,7 @@ def run_tests(pyb, tests, args):
skip_tests.add('thread/thread_gc1.py') # has reliability issues
skip_tests.add('thread/thread_lock4.py') # has reliability issues
skip_tests.add('thread/stress_heap.py') # has reliability issues
+ skip_tests.add('thread/stress_recurse.py') # has reliability issues
if not has_complex:
skip_tests.add('float/complex1.py')