diff options
| author | Glenn Ruben Bakke <glennbakke@gmail.com> | 2017-02-07 22:26:13 +0100 |
|---|---|---|
| committer | Glenn Ruben Bakke <glennbakke@gmail.com> | 2017-02-07 22:26:13 +0100 |
| commit | 4cf7fd151e98a3d842eb5c9428545cb67ddd57ee (patch) | |
| tree | 947f265a2d498f4879bab3c7d19591133c56c1a0 /tests | |
| parent | 9397583f6c99533fc4c0a2753126120a8552ba4c (diff) | |
| parent | 21f08524baf11e62384814b7cb8fcd2b5a8998fb (diff) | |
Merge branch 'master' into nrf52
Diffstat (limited to 'tests')
44 files changed, 436 insertions, 214 deletions
diff --git a/tests/basics/builtin_pow.py b/tests/basics/builtin_pow.py index a19ab8c84..5012a76be 100644 --- a/tests/basics/builtin_pow.py +++ b/tests/basics/builtin_pow.py @@ -1,11 +1,7 @@ # test builtin pow() with integral values - # 2 arg version + print(pow(0, 1)) print(pow(1, 0)) print(pow(-2, 3)) print(pow(3, 8)) - -# 3 arg version -print(pow(3, 4, 7)) - diff --git a/tests/basics/builtin_pow3.py b/tests/basics/builtin_pow3.py new file mode 100644 index 000000000..35e143a38 --- /dev/null +++ b/tests/basics/builtin_pow3.py @@ -0,0 +1,39 @@ +# test builtin pow() with integral values +# 3 arg version + +try: + print(pow(3, 4, 7)) +except NotImplementedError: + import sys + print("SKIP") + sys.exit() + +print(pow(555557, 1000002, 1000003)) + +# 3 arg pow is defined to only work on integers +try: + print(pow("x", 5, 6)) +except TypeError: + print("TypeError expected") + +try: + print(pow(4, "y", 6)) +except TypeError: + print("TypeError expected") + +try: + print(pow(4, 5, "z")) +except TypeError: + print("TypeError expected") + +# Tests for 3 arg pow with large values + +# This value happens to be prime +x = 0xd48a1e2a099b1395895527112937a391d02d4a208bce5d74b281cf35a57362502726f79a632f063a83c0eba66196712d963aa7279ab8a504110a668c0fc38a7983c51e6ee7a85cae87097686ccdc359ee4bbf2c583bce524e3f7836bded1c771a4efcb25c09460a862fc98e18f7303df46aaeb34da46b0c4d61d5cd78350f3edb60e6bc4befa712a849 +y = 0x3accf60bb1a5365e4250d1588eb0fe6cd81ad495e9063f90880229f2a625e98c59387238670936afb2cafc5b79448e4414d6cd5e9901aa845aa122db58ddd7b9f2b17414600a18c47494ed1f3d49d005a5 + +print(hex(pow(2, 200, x))) # Should not overflow, just 1 << 200 +print(hex(pow(2, x-1, x))) # Should be 1, since x is prime +print(hex(pow(y, x-1, x))) # Should be 1, since x is prime +print(hex(pow(y, y-1, x))) # Should be a 'big value' +print(hex(pow(y, y-1, y))) # Should be a 'big value' diff --git a/tests/basics/set_binop.py b/tests/basics/set_binop.py index a3657d84b..7848920b6 100644 --- a/tests/basics/set_binop.py +++ b/tests/basics/set_binop.py @@ -29,6 +29,25 @@ for s in sets: print(set('abc') == 1) +# make sure inplace operators modify the set + +s1 = s2 = set('abc') +s1 |= set('ad') +print(s1 is s2, len(s1)) + +s1 = s2 = set('abc') +s1 ^= set('ad') +print(s1 is s2, len(s1)) + +s1 = s2 = set('abc') +s1 &= set('ad') +print(s1 is s2, len(s1)) + +s1 = s2 = set('abc') +s1 -= set('ad') +print(s1 is s2, len(s1)) + +# unsupported operator try: set('abc') * 2 except TypeError: diff --git a/tests/basics/string_format_modulo.py b/tests/basics/string_format_modulo.py index 2e4909220..f00502457 100644 --- a/tests/basics/string_format_modulo.py +++ b/tests/basics/string_format_modulo.py @@ -66,6 +66,11 @@ print(">%-08.4d<" % -12) print(">%-+08.4d<" % -12) print(">%-+08.4d<" % 12) +# Should be able to print dicts; in this case they aren't used +# to lookup keywords in formats like %(foo)s +print('%s' % {}) +print('%s' % ({},)) + # Cases when "*" used and there's not enough values total try: print("%*s" % 5) @@ -77,6 +82,7 @@ except TypeError: print("TypeError") print("%(foo)s" % {"foo": "bar", "baz": False}) +print("%s %(foo)s %(foo)s" % {"foo": 1}) try: print("%(foo)s" % {}) except KeyError: @@ -87,6 +93,16 @@ try: except TypeError: print("TypeError") +# When using %(foo)s format the single argument must be a dict +try: + '%(foo)s' % 1 +except TypeError: + print('TypeError') +try: + '%(foo)s' % ({},) +except TypeError: + print('TypeError') + try: '%(a' % {'a':1} except ValueError: diff --git a/tests/basics/zip.py b/tests/basics/zip.py index c0109094f..958addb7a 100644 --- a/tests/basics/zip.py +++ b/tests/basics/zip.py @@ -1,2 +1,10 @@ +try: + zip + set +except NameError: + print("SKIP") + import sys + sys.exit() + print(list(zip())) -print(list(zip([1], {2,3}))) +print(list(zip([1], set([2, 3])))) diff --git a/tests/extmod/framebuf1.py b/tests/extmod/framebuf1.py index 47dd98d7e..c204e63aa 100644 --- a/tests/extmod/framebuf1.py +++ b/tests/extmod/framebuf1.py @@ -89,11 +89,11 @@ print(buf) fbuf.text(str(chr(31)), 0, 0) print(buf) -# test invalid constructor +# test invalid constructor, and stride argument try: - fbuf = framebuf.FrameBuffer(buf, w, h, 2, framebuf.MVLSB) + fbuf = framebuf.FrameBuffer(buf, w, h, -1, w) except ValueError: - print("ValueError") + print("ValueError") # test legacy constructor fbuf = framebuf.FrameBuffer1(buf, w, h) diff --git a/tests/extmod/framebuf4.py b/tests/extmod/framebuf4.py new file mode 100644 index 000000000..641f5bfc5 --- /dev/null +++ b/tests/extmod/framebuf4.py @@ -0,0 +1,54 @@ +try: + import framebuf +except ImportError: + print("SKIP") + import sys + sys.exit() + +def printbuf(): + print("--8<--") + for y in range(h): + print(buf[y * w // 2:(y + 1) * w // 2]) + print("-->8--") + +w = 16 +h = 8 +buf = bytearray(w * h // 2) +fbuf = framebuf.FrameBuffer(buf, w, h, framebuf.GS4_HMSB) + +# fill +fbuf.fill(0x0f) +printbuf() +fbuf.fill(0xa0) +printbuf() + +# put pixel +fbuf.pixel(0, 0, 0x01) +printbuf() +fbuf.pixel(w-1, 0, 0x02) +printbuf() +fbuf.pixel(w-1, h-1, 0x03) +printbuf() +fbuf.pixel(0, h-1, 0x04) +printbuf() + +# get pixel +print(fbuf.pixel(0, 0), fbuf.pixel(w-1, 0), fbuf.pixel(w-1, h-1), fbuf.pixel(0, h-1)) +print(fbuf.pixel(1, 0), fbuf.pixel(w-2, 0), fbuf.pixel(w-2, h-1), fbuf.pixel(1, h-1)) + +# fill rect +fbuf.fill_rect(0, 0, w, h, 0x0f) +printbuf() +fbuf.fill_rect(0, 0, w, h, 0xf0) +fbuf.fill_rect(1, 0, w//2+1, 1, 0xf1) +printbuf() +fbuf.fill_rect(1, 0, w//2+1, 1, 0x10) +fbuf.fill_rect(1, 0, w//2, 1, 0xf1) +printbuf() +fbuf.fill_rect(1, 0, w//2, 1, 0x10) +fbuf.fill_rect(0, h-4, w//2+1, 4, 0xaf) +printbuf() +fbuf.fill_rect(0, h-4, w//2+1, 4, 0xb0) +fbuf.fill_rect(0, h-4, w//2, 4, 0xaf) +printbuf() +fbuf.fill_rect(0, h-4, w//2, 4, 0xb0) diff --git a/tests/extmod/framebuf4.py.exp b/tests/extmod/framebuf4.py.exp new file mode 100644 index 000000000..0865470a0 --- /dev/null +++ b/tests/extmod/framebuf4.py.exp @@ -0,0 +1,112 @@ +--8<-- +bytearray(b'\xff\xff\xff\xff\xff\xff\xff\xff') +bytearray(b'\xff\xff\xff\xff\xff\xff\xff\xff') +bytearray(b'\xff\xff\xff\xff\xff\xff\xff\xff') +bytearray(b'\xff\xff\xff\xff\xff\xff\xff\xff') +bytearray(b'\xff\xff\xff\xff\xff\xff\xff\xff') +bytearray(b'\xff\xff\xff\xff\xff\xff\xff\xff') +bytearray(b'\xff\xff\xff\xff\xff\xff\xff\xff') +bytearray(b'\xff\xff\xff\xff\xff\xff\xff\xff') +-->8-- +--8<-- +bytearray(b'\x00\x00\x00\x00\x00\x00\x00\x00') +bytearray(b'\x00\x00\x00\x00\x00\x00\x00\x00') +bytearray(b'\x00\x00\x00\x00\x00\x00\x00\x00') +bytearray(b'\x00\x00\x00\x00\x00\x00\x00\x00') +bytearray(b'\x00\x00\x00\x00\x00\x00\x00\x00') +bytearray(b'\x00\x00\x00\x00\x00\x00\x00\x00') +bytearray(b'\x00\x00\x00\x00\x00\x00\x00\x00') +bytearray(b'\x00\x00\x00\x00\x00\x00\x00\x00') +-->8-- +--8<-- +bytearray(b'\x10\x00\x00\x00\x00\x00\x00\x00') +bytearray(b'\x00\x00\x00\x00\x00\x00\x00\x00') +bytearray(b'\x00\x00\x00\x00\x00\x00\x00\x00') +bytearray(b'\x00\x00\x00\x00\x00\x00\x00\x00') +bytearray(b'\x00\x00\x00\x00\x00\x00\x00\x00') +bytearray(b'\x00\x00\x00\x00\x00\x00\x00\x00') +bytearray(b'\x00\x00\x00\x00\x00\x00\x00\x00') +bytearray(b'\x00\x00\x00\x00\x00\x00\x00\x00') +-->8-- +--8<-- +bytearray(b'\x10\x00\x00\x00\x00\x00\x00\x02') +bytearray(b'\x00\x00\x00\x00\x00\x00\x00\x00') +bytearray(b'\x00\x00\x00\x00\x00\x00\x00\x00') +bytearray(b'\x00\x00\x00\x00\x00\x00\x00\x00') +bytearray(b'\x00\x00\x00\x00\x00\x00\x00\x00') +bytearray(b'\x00\x00\x00\x00\x00\x00\x00\x00') +bytearray(b'\x00\x00\x00\x00\x00\x00\x00\x00') +bytearray(b'\x00\x00\x00\x00\x00\x00\x00\x00') +-->8-- +--8<-- +bytearray(b'\x10\x00\x00\x00\x00\x00\x00\x02') +bytearray(b'\x00\x00\x00\x00\x00\x00\x00\x00') +bytearray(b'\x00\x00\x00\x00\x00\x00\x00\x00') +bytearray(b'\x00\x00\x00\x00\x00\x00\x00\x00') +bytearray(b'\x00\x00\x00\x00\x00\x00\x00\x00') +bytearray(b'\x00\x00\x00\x00\x00\x00\x00\x00') +bytearray(b'\x00\x00\x00\x00\x00\x00\x00\x00') +bytearray(b'\x00\x00\x00\x00\x00\x00\x00\x03') +-->8-- +--8<-- +bytearray(b'\x10\x00\x00\x00\x00\x00\x00\x02') +bytearray(b'\x00\x00\x00\x00\x00\x00\x00\x00') +bytearray(b'\x00\x00\x00\x00\x00\x00\x00\x00') +bytearray(b'\x00\x00\x00\x00\x00\x00\x00\x00') +bytearray(b'\x00\x00\x00\x00\x00\x00\x00\x00') +bytearray(b'\x00\x00\x00\x00\x00\x00\x00\x00') +bytearray(b'\x00\x00\x00\x00\x00\x00\x00\x00') +bytearray(b'@\x00\x00\x00\x00\x00\x00\x03') +-->8-- +1 2 3 4 +0 0 0 0 +--8<-- +bytearray(b'\xff\xff\xff\xff\xff\xff\xff\xff') +bytearray(b'\xff\xff\xff\xff\xff\xff\xff\xff') +bytearray(b'\xff\xff\xff\xff\xff\xff\xff\xff') +bytearray(b'\xff\xff\xff\xff\xff\xff\xff\xff') +bytearray(b'\xff\xff\xff\xff\xff\xff\xff\xff') +bytearray(b'\xff\xff\xff\xff\xff\xff\xff\xff') +bytearray(b'\xff\xff\xff\xff\xff\xff\xff\xff') +bytearray(b'\xff\xff\xff\xff\xff\xff\xff\xff') +-->8-- +--8<-- +bytearray(b'\x01\x11\x11\x11\x11\x00\x00\x00') +bytearray(b'\x00\x00\x00\x00\x00\x00\x00\x00') +bytearray(b'\x00\x00\x00\x00\x00\x00\x00\x00') +bytearray(b'\x00\x00\x00\x00\x00\x00\x00\x00') +bytearray(b'\x00\x00\x00\x00\x00\x00\x00\x00') +bytearray(b'\x00\x00\x00\x00\x00\x00\x00\x00') +bytearray(b'\x00\x00\x00\x00\x00\x00\x00\x00') +bytearray(b'\x00\x00\x00\x00\x00\x00\x00\x00') +-->8-- +--8<-- +bytearray(b'\x01\x11\x11\x11\x10\x00\x00\x00') +bytearray(b'\x00\x00\x00\x00\x00\x00\x00\x00') +bytearray(b'\x00\x00\x00\x00\x00\x00\x00\x00') +bytearray(b'\x00\x00\x00\x00\x00\x00\x00\x00') +bytearray(b'\x00\x00\x00\x00\x00\x00\x00\x00') +bytearray(b'\x00\x00\x00\x00\x00\x00\x00\x00') +bytearray(b'\x00\x00\x00\x00\x00\x00\x00\x00') +bytearray(b'\x00\x00\x00\x00\x00\x00\x00\x00') +-->8-- +--8<-- +bytearray(b'\x00\x00\x00\x00\x00\x00\x00\x00') +bytearray(b'\x00\x00\x00\x00\x00\x00\x00\x00') +bytearray(b'\x00\x00\x00\x00\x00\x00\x00\x00') +bytearray(b'\x00\x00\x00\x00\x00\x00\x00\x00') +bytearray(b'\xff\xff\xff\xff\xf0\x00\x00\x00') +bytearray(b'\xff\xff\xff\xff\xf0\x00\x00\x00') +bytearray(b'\xff\xff\xff\xff\xf0\x00\x00\x00') +bytearray(b'\xff\xff\xff\xff\xf0\x00\x00\x00') +-->8-- +--8<-- +bytearray(b'\x00\x00\x00\x00\x00\x00\x00\x00') +bytearray(b'\x00\x00\x00\x00\x00\x00\x00\x00') +bytearray(b'\x00\x00\x00\x00\x00\x00\x00\x00') +bytearray(b'\x00\x00\x00\x00\x00\x00\x00\x00') +bytearray(b'\xff\xff\xff\xff\x00\x00\x00\x00') +bytearray(b'\xff\xff\xff\xff\x00\x00\x00\x00') +bytearray(b'\xff\xff\xff\xff\x00\x00\x00\x00') +bytearray(b'\xff\xff\xff\xff\x00\x00\x00\x00') +-->8-- diff --git a/tests/extmod/machine_pulse.py b/tests/extmod/machine_pulse.py index b6e126435..6491b5409 100644 --- a/tests/extmod/machine_pulse.py +++ b/tests/extmod/machine_pulse.py @@ -43,12 +43,5 @@ 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") +print(machine.time_pulse_us(p, 1, 10)) +print(machine.time_pulse_us(p, 0, 10)) diff --git a/tests/extmod/machine_pulse.py.exp b/tests/extmod/machine_pulse.py.exp index f9a474218..20d4c1043 100644 --- a/tests/extmod/machine_pulse.py.exp +++ b/tests/extmod/machine_pulse.py.exp @@ -5,5 +5,5 @@ value: 1 value: 0 value: 1 <class 'int'> -OSError -OSError +-2 +-1 diff --git a/tests/extmod/ure_debug.py b/tests/extmod/ure_debug.py new file mode 100644 index 000000000..303e1789c --- /dev/null +++ b/tests/extmod/ure_debug.py @@ -0,0 +1,3 @@ +# test printing debugging info when compiling +import ure +ure.compile('^a|b[0-9]\w$', ure.DEBUG) diff --git a/tests/extmod/ure_debug.py.exp b/tests/extmod/ure_debug.py.exp new file mode 100644 index 000000000..45f5e20f6 --- /dev/null +++ b/tests/extmod/ure_debug.py.exp @@ -0,0 +1,15 @@ + 0: rsplit 5 (3) + 2: any + 3: jmp 0 (-5) + 5: save 0 + 7: split 14 (5) + 9: assert bol +10: char a +12: jmp 23 (9) +14: char b +16: class 1 0x30-0x39 +20: namedclass w +22: assert eol +23: save 1 +25: match +Bytes: 26, insts: 14 diff --git a/tests/extmod/vfs_fat_fileio.py b/tests/extmod/vfs_fat_fileio.py index f050d94e2..6fdac0710 100644 --- a/tests/extmod/vfs_fat_fileio.py +++ b/tests/extmod/vfs_fat_fileio.py @@ -1,7 +1,11 @@ import sys -import uos import uerrno try: + import uos_vfs as uos + open = uos.vfs_open +except ImportError: + import uos +try: uos.VfsFat except AttributeError: print("SKIP") @@ -34,16 +38,18 @@ class RAMFS: try: - bdev = RAMFS(48) + bdev = RAMFS(50) except MemoryError: print("SKIP") sys.exit() uos.VfsFat.mkfs(bdev) -vfs = uos.VfsFat(bdev, "/ramdisk") +vfs = uos.VfsFat(bdev) +uos.mount(vfs, '/ramdisk') +uos.chdir('/ramdisk') # file IO -f = vfs.open("foo_file.txt", "w") +f = open("foo_file.txt", "w") print(str(f)[:17], str(f)[-1:]) f.write("hello!") f.flush() @@ -65,14 +71,14 @@ except OSError as e: print(e.args[0] == uerrno.EINVAL) try: - vfs.open("foo_file.txt", "x") + open("foo_file.txt", "x") except OSError as e: print(e.args[0] == uerrno.EEXIST) -with vfs.open("foo_file.txt", "a") as f: +with open("foo_file.txt", "a") as f: f.write("world!") -with vfs.open("foo_file.txt") as f2: +with open("foo_file.txt") as f2: print(f2.read()) print(f2.tell()) @@ -90,9 +96,10 @@ with vfs.open("foo_file.txt") as f2: print(f2.read(1)) # using constructor of FileIO type to open a file -FileIO = type(f) -with FileIO("foo_file.txt") as f: - print(f.read()) +# no longer working with new VFS sub-system +#FileIO = type(f) +#with FileIO("/ramdisk/foo_file.txt") as f: +# print(f.read()) # dirs vfs.mkdir("foo_dir") @@ -118,18 +125,18 @@ except OSError as e: print(e.args[0] == uerrno.ENOENT) try: - vfs.rename("foo_dir", "/null") + vfs.rename("foo_dir", "/null/file") except OSError as e: - print(e.args[0] == uerrno.ENODEV) + print(e.args[0] == uerrno.ENOENT) # file in dir -with vfs.open("foo_dir/file-in-dir.txt", "w+t") as f: +with open("foo_dir/file-in-dir.txt", "w+t") as f: f.write("data in file") -with vfs.open("foo_dir/file-in-dir.txt", "r+b") as f: +with open("foo_dir/file-in-dir.txt", "r+b") as f: print(f.read()) -with vfs.open("foo_dir/sub_file.txt", "w") as f: +with open("foo_dir/sub_file.txt", "w") as f: f.write("subdir file") # directory not empty @@ -139,18 +146,18 @@ except OSError as e: print(e.args[0] == uerrno.EACCES) # trim full path -vfs.rename("foo_dir/file-in-dir.txt", "/ramdisk/foo_dir/file.txt") +vfs.rename("foo_dir/file-in-dir.txt", "foo_dir/file.txt") print(vfs.listdir("foo_dir")) vfs.rename("foo_dir/file.txt", "moved-to-root.txt") print(vfs.listdir()) # check that renaming to existing file will overwrite it -with vfs.open("temp", "w") as f: +with open("temp", "w") as f: f.write("new text") vfs.rename("temp", "moved-to-root.txt") print(vfs.listdir()) -with vfs.open("moved-to-root.txt") as f: +with open("moved-to-root.txt") as f: print(f.read()) # valid removes @@ -163,7 +170,7 @@ print(vfs.listdir()) try: bsize = vfs.statvfs("/ramdisk")[0] free = vfs.statvfs("/ramdisk")[2] + 1 - f = vfs.open("large_file.txt", "wb") + f = open("large_file.txt", "wb") f.write(bytearray(bsize * free)) except OSError as e: print("ENOSPC:", e.args[0] == 28) # uerrno.ENOSPC diff --git a/tests/extmod/vfs_fat_fileio.py.exp b/tests/extmod/vfs_fat_fileio.py.exp index a09442ae8..4e34e83a8 100644 --- a/tests/extmod/vfs_fat_fileio.py.exp +++ b/tests/extmod/vfs_fat_fileio.py.exp @@ -9,7 +9,6 @@ h e True d -hello!world! True True True diff --git a/tests/extmod/vfs_fat_fsusermount.py b/tests/extmod/vfs_fat_fsusermount.py deleted file mode 100644 index 7326172ee..000000000 --- a/tests/extmod/vfs_fat_fsusermount.py +++ /dev/null @@ -1,96 +0,0 @@ -import sys -import uos -import uerrno -try: - uos.VfsFat -except AttributeError: - print("SKIP") - sys.exit() - - -class RAMFS: - - SEC_SIZE = 512 - - def __init__(self, blocks): - self.data = bytearray(blocks * self.SEC_SIZE) - - def readblocks(self, n, buf): - #print("readblocks(%s, %x(%d))" % (n, id(buf), len(buf))) - for i in range(len(buf)): - buf[i] = self.data[n * self.SEC_SIZE + i] - - def writeblocks(self, n, buf): - #print("writeblocks(%s, %x)" % (n, id(buf))) - for i in range(len(buf)): - self.data[n * self.SEC_SIZE + i] = buf[i] - - def ioctl(self, op, arg): - #print("ioctl(%d, %r)" % (op, arg)) - if op == 4: # BP_IOCTL_SEC_COUNT - return len(self.data) // self.SEC_SIZE - if op == 5: # BP_IOCTL_SEC_SIZE - return self.SEC_SIZE - - -try: - bdev = RAMFS(48) -except MemoryError: - print("SKIP") - sys.exit() - -# can't mkfs readonly device -try: - uos.vfs_mkfs(bdev, "/ramdisk", readonly=True) -except OSError as e: - print(e) - -# mount before mkfs -try: - uos.vfs_mount(bdev, "/ramdisk") -except OSError as e: - print(e) - -# invalid umount -try: - uos.vfs_umount("/ramdisk") -except OSError as e: - print(e.args[0] == uerrno.EINVAL) - -try: - uos.vfs_mount(None, "/ramdisk") -except OSError as e: - print(e) - -try: - uos.vfs_mkfs(None, "/ramdisk") -except OSError as e: - print(e) - -# valid mkfs/mount -uos.vfs_mkfs(bdev, "/ramdisk") -uos.vfs_mount(bdev, "/ramdisk") - -# umount by path -uos.vfs_umount("/ramdisk") - -# readonly mount -uos.vfs_mount(bdev, "/ramdisk", readonly=True) -vfs = uos.VfsFat(bdev, "/ramdisk") -try: - f = vfs.open("file.txt", "w") -except OSError as e: - print("EROFS:", e.args[0] == 30) # uerrno.EROFS - -# device is None == umount -uos.vfs_mount(None, "/ramdisk") - -# max mounted devices -dev = [] -try: - for i in range(0,4): - dev.append(RAMFS(48)) - uos.vfs_mkfs(dev[i], "/ramdisk" + str(i)) - uos.vfs_mount(dev[i], "/ramdisk" + str(i)) -except OSError as e: - print(e) diff --git a/tests/extmod/vfs_fat_fsusermount.py.exp b/tests/extmod/vfs_fat_fsusermount.py.exp deleted file mode 100644 index 3b30688dd..000000000 --- a/tests/extmod/vfs_fat_fsusermount.py.exp +++ /dev/null @@ -1,7 +0,0 @@ -can't mkfs -can't mount -True -can't umount -can't umount -EROFS: True -too many devices mounted diff --git a/tests/extmod/vfs_fat_oldproto.py b/tests/extmod/vfs_fat_oldproto.py index 73983567d..03ab76e35 100644 --- a/tests/extmod/vfs_fat_oldproto.py +++ b/tests/extmod/vfs_fat_oldproto.py @@ -1,10 +1,11 @@ import sys -import uos import uerrno try: + import uos_vfs as uos +except ImportError: + import uos +try: uos.VfsFat - uos.vfs_mkfs - uos.vfs_mount except AttributeError: print("SKIP") sys.exit() @@ -34,16 +35,16 @@ class RAMFS_OLD: try: - bdev = RAMFS_OLD(48) + bdev = RAMFS_OLD(50) except MemoryError: print("SKIP") sys.exit() -uos.vfs_mkfs(bdev, "/ramdisk") -uos.vfs_mount(bdev, "/ramdisk") +uos.VfsFat.mkfs(bdev) +vfs = uos.VfsFat(bdev) +uos.mount(vfs, "/ramdisk") # file io -vfs = uos.VfsFat(bdev, "/ramdisk") with vfs.open("file.txt", "w") as f: f.write("hello!") @@ -54,10 +55,3 @@ with vfs.open("file.txt", "r") as f: vfs.remove("file.txt") print(vfs.listdir()) - -# umount by device -uos.vfs_umount(bdev) -try: - vfs.listdir() -except OSError as e: - print(e.args[0] == uerrno.ENODEV) diff --git a/tests/extmod/vfs_fat_oldproto.py.exp b/tests/extmod/vfs_fat_oldproto.py.exp index 4120c277a..a389a5217 100644 --- a/tests/extmod/vfs_fat_oldproto.py.exp +++ b/tests/extmod/vfs_fat_oldproto.py.exp @@ -1,4 +1,3 @@ ['file.txt'] hello! [] -True diff --git a/tests/extmod/vfs_fat_ramdisk.py b/tests/extmod/vfs_fat_ramdisk.py index 184672ff1..dc4a1c305 100644 --- a/tests/extmod/vfs_fat_ramdisk.py +++ b/tests/extmod/vfs_fat_ramdisk.py @@ -1,7 +1,10 @@ import sys -import uos import uerrno try: + import uos_vfs as uos +except ImportError: + import uos +try: uos.VfsFat except AttributeError: print("SKIP") @@ -34,7 +37,7 @@ class RAMFS: try: - bdev = RAMFS(48) + bdev = RAMFS(50) except MemoryError: print("SKIP") sys.exit() @@ -44,12 +47,8 @@ uos.VfsFat.mkfs(bdev) print(b"FOO_FILETXT" not in bdev.data) print(b"hello!" not in bdev.data) -vfs = uos.VfsFat(bdev, "/ramdisk") - -try: - vfs.statvfs("/null") -except OSError as e: - print(e.args[0] == uerrno.ENODEV) +vfs = uos.VfsFat(bdev) +uos.mount(vfs, "/ramdisk") print("statvfs:", vfs.statvfs("/ramdisk")) print("getcwd:", vfs.getcwd()) @@ -64,8 +63,7 @@ with vfs.open("foo_file.txt", "w") as f: print(vfs.listdir()) print("stat root:", vfs.stat("/")) -print("stat disk:", vfs.stat("/ramdisk/")) -print("stat file:", vfs.stat("foo_file.txt")) +print("stat file:", vfs.stat("foo_file.txt")[:-3]) # timestamps differ across runs print(b"FOO_FILETXT" in bdev.data) print(b"hello!" in bdev.data) @@ -86,16 +84,7 @@ except OSError as e: vfs.chdir("..") print("getcwd:", vfs.getcwd()) -vfs.umount() -try: - vfs.listdir() -except OSError as e: - print(e.args[0] == uerrno.ENODEV) - -try: - vfs.getcwd() -except OSError as e: - print(e.args[0] == uerrno.ENODEV) +uos.umount(vfs) -vfs = uos.VfsFat(bdev, "/ramdisk") +vfs = uos.VfsFat(bdev) print(vfs.listdir(b"")) diff --git a/tests/extmod/vfs_fat_ramdisk.py.exp b/tests/extmod/vfs_fat_ramdisk.py.exp index eaf637199..137db5841 100644 --- a/tests/extmod/vfs_fat_ramdisk.py.exp +++ b/tests/extmod/vfs_fat_ramdisk.py.exp @@ -1,19 +1,15 @@ True True -True -statvfs: (512, 512, 14, 14, 14, 0, 0, 0, 0, 255) -getcwd: /ramdisk +statvfs: (512, 512, 16, 16, 16, 0, 0, 0, 0, 255) +getcwd: / True ['foo_file.txt'] stat root: (16384, 0, 0, 0, 0, 0, 0, 0, 0, 0) -stat disk: (16384, 0, 0, 0, 0, 0, 0, 0, 0, 0) -stat file: (32768, 0, 0, 0, 0, 0, 6, -631238400, -631238400, -631238400) +stat file: (32768, 0, 0, 0, 0, 0, 6) True True -getcwd: /ramdisk/foo_dir +getcwd: /foo_dir [] True -getcwd: /ramdisk -True -True +getcwd: / [b'foo_file.txt', b'foo_dir'] diff --git a/tests/float/complex1.py b/tests/float/complex1.py index fed65d5d5..1031111f3 100644 --- a/tests/float/complex1.py +++ b/tests/float/complex1.py @@ -28,6 +28,7 @@ print(1j / 2) print((1j / 2j).real) print(1j / (1 + 2j)) ans = 0j ** 0; print("%.5g %.5g" % (ans.real, ans.imag)) +ans = 0j ** 1; print("%.5g %.5g" % (ans.real, ans.imag)) ans = 0j ** 0j; print("%.5g %.5g" % (ans.real, ans.imag)) ans = 1j ** 2.5; print("%.5g %.5g" % (ans.real, ans.imag)) ans = 1j ** 2.5j; print("%.5g %.5g" % (ans.real, ans.imag)) @@ -95,6 +96,10 @@ except ZeroDivisionError: # zero division via power try: + 0j ** -1 +except ZeroDivisionError: + print("ZeroDivisionError") +try: 0j ** 1j except ZeroDivisionError: print("ZeroDivisionError") diff --git a/tests/float/float1.py b/tests/float/float1.py index 0e115032b..93f6f014c 100644 --- a/tests/float/float1.py +++ b/tests/float/float1.py @@ -75,6 +75,11 @@ try: except ZeroDivisionError: print("ZeroDivisionError") +try: + 0.0 ** -1 +except ZeroDivisionError: + print("ZeroDivisionError") + # unsupported unary ops try: diff --git a/tests/float/int_divzero.py b/tests/float/int_divzero.py index b037dd8c7..b311a1dbc 100644 --- a/tests/float/int_divzero.py +++ b/tests/float/int_divzero.py @@ -2,3 +2,8 @@ try: 1 / 0 except ZeroDivisionError: print("ZeroDivisionError") + +try: + 0 ** -1 +except ZeroDivisionError: + print("ZeroDivisionError") diff --git a/tests/micropython/heapalloc_bytesio.py b/tests/micropython/heapalloc_bytesio.py new file mode 100644 index 000000000..311632851 --- /dev/null +++ b/tests/micropython/heapalloc_bytesio.py @@ -0,0 +1,13 @@ +import uio +import micropython + +data = b"1234" * 16 +buf = uio.BytesIO(64) + +micropython.heap_lock() + +buf.write(data) + +micropython.heap_unlock() + +print(buf.getvalue()) diff --git a/tests/micropython/heapalloc_bytesio.py.exp b/tests/micropython/heapalloc_bytesio.py.exp new file mode 100644 index 000000000..675761c2b --- /dev/null +++ b/tests/micropython/heapalloc_bytesio.py.exp @@ -0,0 +1 @@ +b'1234123412341234123412341234123412341234123412341234123412341234' diff --git a/tests/micropython/heapalloc_str.py b/tests/micropython/heapalloc_str.py new file mode 100644 index 000000000..0df39d3c0 --- /dev/null +++ b/tests/micropython/heapalloc_str.py @@ -0,0 +1,14 @@ +# String operations which don't require allocation +import micropython + +micropython.heap_lock() + +b"" + b"" +b"" + b"1" +b"2" + b"" + +"" + "" +"" + "1" +"2" + "" + +micropython.heap_unlock() diff --git a/tests/micropython/heapalloc_str.py.exp b/tests/micropython/heapalloc_str.py.exp new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/tests/micropython/heapalloc_str.py.exp diff --git a/tests/pyb/adc.py b/tests/pyb/adc.py index 6508d7e24..362ca326d 100644 --- a/tests/pyb/adc.py +++ b/tests/pyb/adc.py @@ -9,9 +9,12 @@ print(adc) val = adc.read() assert val < 500 +# timer for read_timed +tim = pyb.Timer(5, freq=500) + # read into bytearray buf = bytearray(50) -adc.read_timed(buf, 500) +adc.read_timed(buf, tim) print(len(buf)) for i in buf: assert i < 500 @@ -19,12 +22,12 @@ for i in buf: # read into arrays with different element sizes import array ar = array.array('h', 25 * [0]) -adc.read_timed(ar, 500) +adc.read_timed(ar, tim) print(len(ar)) for i in buf: assert i < 500 ar = array.array('i', 30 * [0]) -adc.read_timed(ar, 500) +adc.read_timed(ar, tim) print(len(ar)) for i in buf: assert i < 500 diff --git a/tests/pyb/can.py b/tests/pyb/can.py index 594d1d509..617eb7ccc 100644 --- a/tests/pyb/can.py +++ b/tests/pyb/can.py @@ -1,4 +1,10 @@ -from pyb import CAN +try: + from pyb import CAN +except ImportError: + print('SKIP') + import sys + sys.exit() + import pyb # test we can correctly create by id or name diff --git a/tests/pyb/dac.py b/tests/pyb/dac.py index 884ec5829..942f30354 100644 --- a/tests/pyb/dac.py +++ b/tests/pyb/dac.py @@ -1,5 +1,10 @@ import pyb +if not hasattr(pyb, 'DAC'): + print('SKIP') + import sys + sys.exit() + dac = pyb.DAC(1) print(dac) dac.noise(100) diff --git a/tests/pyb/extint.py b/tests/pyb/extint.py index a8ba484b1..ae98ccd5a 100644 --- a/tests/pyb/extint.py +++ b/tests/pyb/extint.py @@ -1,7 +1,7 @@ import pyb # test basic functionality -ext = pyb.ExtInt('X1', pyb.ExtInt.IRQ_RISING, pyb.Pin.PULL_DOWN, lambda l:print('line:', l)) +ext = pyb.ExtInt('Y1', pyb.ExtInt.IRQ_RISING, pyb.Pin.PULL_DOWN, lambda l:print('line:', l)) ext.disable() ext.enable() print(ext.line()) diff --git a/tests/pyb/extint.py.exp b/tests/pyb/extint.py.exp index daed01c7f..1f9da9844 100644 --- a/tests/pyb/extint.py.exp +++ b/tests/pyb/extint.py.exp @@ -1,3 +1,3 @@ -0 -line: 0 -line: 0 +6 +line: 6 +line: 6 diff --git a/tests/pyb/pin.py b/tests/pyb/pin.py index b3eb87b60..9b3788343 100644 --- a/tests/pyb/pin.py +++ b/tests/pyb/pin.py @@ -1,14 +1,14 @@ from pyb import Pin -p = Pin('X1', Pin.IN) +p = Pin('Y1', Pin.IN) print(p) print(p.name()) print(p.pin()) print(p.port()) -p = Pin('X1', Pin.IN, Pin.PULL_UP) -p = Pin('X1', Pin.IN, pull=Pin.PULL_UP) -p = Pin('X1', mode=Pin.IN, pull=Pin.PULL_UP) +p = Pin('Y1', Pin.IN, Pin.PULL_UP) +p = Pin('Y1', Pin.IN, pull=Pin.PULL_UP) +p = Pin('Y1', mode=Pin.IN, pull=Pin.PULL_UP) print(p) print(p.value()) diff --git a/tests/pyb/pin.py.exp b/tests/pyb/pin.py.exp index 599374600..f2f7038fd 100644 --- a/tests/pyb/pin.py.exp +++ b/tests/pyb/pin.py.exp @@ -1,10 +1,10 @@ -Pin(Pin.cpu.A0, mode=Pin.IN) -A0 -0 -0 -Pin(Pin.cpu.A0, mode=Pin.IN, pull=Pin.PULL_UP) +Pin(Pin.cpu.C6, mode=Pin.IN) +C6 +6 +2 +Pin(Pin.cpu.C6, mode=Pin.IN, pull=Pin.PULL_UP) 1 -Pin(Pin.cpu.A0, mode=Pin.IN, pull=Pin.PULL_DOWN) +Pin(Pin.cpu.C6, mode=Pin.IN, pull=Pin.PULL_DOWN) 0 0 1 diff --git a/tests/pyb/pyb1.py b/tests/pyb/pyb1.py index 0087ec050..184acbdc4 100644 --- a/tests/pyb/pyb1.py +++ b/tests/pyb/pyb1.py @@ -27,16 +27,15 @@ print((pyb.millis() - start) // 5) # should print 3 pyb.disable_irq() pyb.enable_irq() -print(pyb.freq()) - print(pyb.have_cdc()) pyb.hid((0, 0, 0, 0)) # won't do anything -pyb.rng() - pyb.sync() print(len(pyb.unique_id())) pyb.wfi() + +pyb.fault_debug(True) +pyb.fault_debug(False) diff --git a/tests/pyb/pyb1.py.exp b/tests/pyb/pyb1.py.exp index 84034d683..5816ea967 100644 --- a/tests/pyb/pyb1.py.exp +++ b/tests/pyb/pyb1.py.exp @@ -1,5 +1,4 @@ 3 3 -(168000000, 168000000, 42000000, 84000000) True 12 diff --git a/tests/pyb/pyb_f405.py b/tests/pyb/pyb_f405.py new file mode 100644 index 000000000..3c81fe109 --- /dev/null +++ b/tests/pyb/pyb_f405.py @@ -0,0 +1,11 @@ +# test pyb module on F405 MCUs + +import os, pyb + +if not 'STM32F405' in os.uname().machine: + print('SKIP') + import sys + sys.exit() + +print(pyb.freq()) +print(type(pyb.rng())) diff --git a/tests/pyb/pyb_f405.py.exp b/tests/pyb/pyb_f405.py.exp new file mode 100644 index 000000000..a90aa0268 --- /dev/null +++ b/tests/pyb/pyb_f405.py.exp @@ -0,0 +1,2 @@ +(168000000, 168000000, 42000000, 84000000) +<class 'int'> diff --git a/tests/pyb/pyb_f411.py b/tests/pyb/pyb_f411.py new file mode 100644 index 000000000..328653965 --- /dev/null +++ b/tests/pyb/pyb_f411.py @@ -0,0 +1,10 @@ +# test pyb module on F411 MCUs + +import os, pyb + +if not 'STM32F411' in os.uname().machine: + print('SKIP') + import sys + sys.exit() + +print(pyb.freq()) diff --git a/tests/pyb/pyb_f411.py.exp b/tests/pyb/pyb_f411.py.exp new file mode 100644 index 000000000..79e0a1062 --- /dev/null +++ b/tests/pyb/pyb_f411.py.exp @@ -0,0 +1 @@ +(96000000, 96000000, 24000000, 48000000) diff --git a/tests/pyb/rtc.py b/tests/pyb/rtc.py index 300c95634..844526b4b 100644 --- a/tests/pyb/rtc.py +++ b/tests/pyb/rtc.py @@ -7,7 +7,7 @@ print(rtc) # make sure that 1 second passes correctly rtc.datetime((2014, 1, 1, 1, 0, 0, 0, 0)) -pyb.delay(1001) +pyb.delay(1002) print(rtc.datetime()[:7]) def set_and_print(datetime): diff --git a/tests/run-tests b/tests/run-tests index 6834d59be..c74d0f24b 100755 --- a/tests/run-tests +++ b/tests/run-tests @@ -145,6 +145,10 @@ def run_micropython(pyb, args, test_file): # canonical form for all ports/platforms is to use \n for end-of-line output_mupy = output_mupy.replace(b'\r\n', b'\n') + # don't try to convert the output if we should skip this test + if output_mupy == b'SKIP\n': + return output_mupy + if is_special or test_file in special_tests: # convert parts of the output that are not stable across runs with open(test_file + '.exp', 'rb') as f: @@ -310,7 +314,7 @@ def run_tests(pyb, tests, args): test_name = os.path.splitext(test_basename)[0] is_native = test_name.startswith("native_") or test_name.startswith("viper_") is_endian = test_name.endswith("_endian") - is_set_type = test_name.startswith("set_") + is_set_type = test_name.startswith("set_") or test_name.startswith("frozenset") skip_it = test_file in skip_tests skip_it |= skip_native and is_native 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_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 |
