summaryrefslogtreecommitdiff
path: root/tests/extmod
diff options
context:
space:
mode:
authorScott Shawcroft <scott.shawcroft@gmail.com>2017-06-20 10:56:05 -0700
committerScott Shawcroft <scott.shawcroft@gmail.com>2017-06-20 10:56:05 -0700
commit30ee7019ca651bce1fe966c1089fe977d51dc92b (patch)
tree0114b6f744dd175b7722dd8edcbe24f4ee84bb45 /tests/extmod
parent97fcdfbd08c922efd7470d6482d7c7c703ffc0ae (diff)
parent869cdcfdfc860b1177baf9b0f8818915ba54f3f5 (diff)
Merge tag 'v1.9.1'2.0.0-alpha.0
Fixes for stmhal USB mass storage, lwIP bindings and VFS regressions This release provides an important fix for the USB mass storage device in the stmhal port by implementing the SCSI SYNCHRONIZE_CACHE command, which is now require by some Operating Systems. There are also fixes for the lwIP bindings to improve non-blocking sockets and error codes. The VFS has some regressions fixed including the ability to statvfs the root. All changes are listed below. py core: - modbuiltins: add core-provided version of input() function - objstr: catch case of negative "maxsplit" arg to str.rsplit() - persistentcode: allow to compile with complex numbers disabled - objstr: allow to compile with obj-repr D, and unicode disabled - modsys: allow to compile with obj-repr D and PY_ATTRTUPLE disabled - provide mp_decode_uint_skip() to help reduce stack usage - makeqstrdefs.py: make script run correctly with Python 2.6 - objstringio: if created from immutable object, follow copy on write policy extmod: - modlwip: connect: for non-blocking mode, return EINPROGRESS - modlwip: fix error codes for duplicate calls to connect() - modlwip: accept: fix error code for non-blocking mode - vfs: allow to statvfs the root directory - vfs: allow "buffering" and "encoding" args to VFS's open() - modframebuf: fix signed/unsigned comparison pendantic warning lib: - libm: use isfinite instead of finitef, for C99 compatibility - utils/interrupt_char: remove support for KBD_EXCEPTION disabled tests: - basics/string_rsplit: add tests for negative "maxsplit" argument - float: convert "sys.exit()" to "raise SystemExit" - float/builtin_float_minmax: PEP8 fixes - basics: convert "sys.exit()" to "raise SystemExit" - convert remaining "sys.exit()" to "raise SystemExit" unix port: - convert to use core-provided version of built-in import() - Makefile: replace references to make with $(MAKE) windows port: - convert to use core-provided version of built-in import() qemu-arm port: - Makefile: adjust object-file lists to get correct dependencies - enable micropython.mem_*() functions to allow more tests stmhal port: - boards: enable DAC for NUCLEO_F767ZI board - add support for NUCLEO_F446RE board - pass USB handler as parameter to allow more than one USB handler - usb: use local USB handler variable in Start-of-Frame handler - usb: make state for USB device private to top-level USB driver - usbdev: for MSC implement SCSI SYNCHRONIZE_CACHE command - convert from using stmhal's input() to core provided version cc3200 port: - convert from using stmhal's input() to core provided version teensy port: - convert from using stmhal's input() to core provided version esp8266 port: - Makefile: replace references to make with $(MAKE) - Makefile: add clean-modules target - convert from using stmhal's input() to core provided version zephyr port: - modusocket: getaddrinfo: Fix mp_obj_len() usage - define MICROPY_PY_SYS_PLATFORM (to "zephyr") - machine_pin: use native Zephyr types for Zephyr API calls docs: - machine.Pin: remove out_value() method - machine.Pin: add on() and off() methods - esp8266: consistently replace Pin.high/low methods with .on/off - esp8266/quickref: polish Pin.on()/off() examples - network: move confusingly-named cc3200 Server class to its reference - uos: deconditionalize, remove minor port-specific details - uos: move cc3200 port legacy VFS mounting functions to its ref doc - machine: sort machine classes in logical order, not alphabetically - network: first step to describe standard network class interface examples: - embedding: use core-provided KeyboardInterrupt object
Diffstat (limited to 'tests/extmod')
-rw-r--r--tests/extmod/btree1.py3
-rw-r--r--tests/extmod/framebuf1.py182
-rw-r--r--tests/extmod/framebuf1.py.exp47
-rw-r--r--tests/extmod/framebuf16.py3
-rw-r--r--tests/extmod/framebuf4.py53
-rw-r--r--tests/extmod/framebuf4.py.exp112
-rw-r--r--tests/extmod/machine1.py6
-rw-r--r--tests/extmod/machine_pinbase.py3
-rw-r--r--tests/extmod/machine_pulse.py14
-rw-r--r--tests/extmod/machine_pulse.py.exp4
-rw-r--r--tests/extmod/machine_signal.py39
-rw-r--r--tests/extmod/machine_signal.py.exp4
-rw-r--r--tests/extmod/time_ms_us.py3
-rw-r--r--tests/extmod/ubinascii_a2b_base64.py8
-rw-r--r--tests/extmod/ubinascii_b2a_base64.py8
-rw-r--r--tests/extmod/ubinascii_crc32.py12
-rw-r--r--tests/extmod/ubinascii_hexlify.py8
-rw-r--r--tests/extmod/ubinascii_micropython.py8
-rw-r--r--tests/extmod/ubinascii_unhexlify.py8
-rw-r--r--tests/extmod/uctypes_32bit_intbig.py53
-rw-r--r--tests/extmod/uctypes_32bit_intbig.py.exp11
-rw-r--r--tests/extmod/uctypes_array_assign_le.py6
-rw-r--r--tests/extmod/uctypes_array_assign_native_le.py18
-rw-r--r--tests/extmod/uctypes_array_assign_native_le.py.exp2
-rw-r--r--tests/extmod/uctypes_array_assign_native_le_intbig.py43
-rw-r--r--tests/extmod/uctypes_array_assign_native_le_intbig.py.exp2
-rw-r--r--tests/extmod/uctypes_bytearray.py6
-rw-r--r--tests/extmod/uctypes_le.py6
-rw-r--r--tests/extmod/uctypes_le_float.py6
-rw-r--r--tests/extmod/uctypes_native_float.py6
-rw-r--r--tests/extmod/uctypes_native_le.py8
-rw-r--r--tests/extmod/uctypes_print.py7
-rw-r--r--tests/extmod/uctypes_ptr_le.py8
-rw-r--r--tests/extmod/uctypes_ptr_native_le.py8
-rw-r--r--tests/extmod/uctypes_sizeof.py6
-rw-r--r--tests/extmod/uctypes_sizeof_native.py6
-rw-r--r--tests/extmod/uhashlib_sha1.py5
-rw-r--r--tests/extmod/uhashlib_sha256.py3
-rw-r--r--tests/extmod/uheapq1.py6
-rw-r--r--tests/extmod/ujson_dumps.py6
-rw-r--r--tests/extmod/ujson_dumps_extra.py6
-rw-r--r--tests/extmod/ujson_dumps_float.py6
-rw-r--r--tests/extmod/ujson_load.py8
-rw-r--r--tests/extmod/ujson_loads.py8
-rw-r--r--tests/extmod/ujson_loads_float.py8
-rw-r--r--tests/extmod/urandom_basic.py6
-rw-r--r--tests/extmod/urandom_extra.py9
-rw-r--r--tests/extmod/ure1.py15
-rw-r--r--tests/extmod/ure_debug.py8
-rw-r--r--tests/extmod/ure_debug.py.exp15
-rw-r--r--tests/extmod/ure_error.py8
-rw-r--r--tests/extmod/ure_group.py8
-rw-r--r--tests/extmod/ure_namedclass.py8
-rw-r--r--tests/extmod/ure_split.py6
-rw-r--r--tests/extmod/ure_split_empty.py6
-rw-r--r--tests/extmod/ure_split_notimpl.py11
-rw-r--r--tests/extmod/ure_split_notimpl.py.exp1
-rw-r--r--tests/extmod/ussl_basic.py51
-rw-r--r--tests/extmod/ussl_basic.py.exp8
-rw-r--r--tests/extmod/utimeq1.py38
-rw-r--r--tests/extmod/utimeq_stable.py3
-rw-r--r--tests/extmod/uzlib_decompio.py7
-rw-r--r--tests/extmod/uzlib_decompio_gz.py17
-rw-r--r--tests/extmod/uzlib_decompio_gz.py.exp2
-rw-r--r--tests/extmod/uzlib_decompress.py6
-rw-r--r--tests/extmod/vfs_basic.py151
-rw-r--r--tests/extmod/vfs_basic.py.exp60
-rw-r--r--tests/extmod/vfs_fat_fileio.py.exp25
-rw-r--r--tests/extmod/vfs_fat_fileio1.py117
-rw-r--r--tests/extmod/vfs_fat_fileio1.py.exp13
-rw-r--r--tests/extmod/vfs_fat_fileio2.py (renamed from tests/extmod/vfs_fat_fileio.py)111
-rw-r--r--tests/extmod/vfs_fat_fileio2.py.exp11
-rw-r--r--tests/extmod/vfs_fat_fsusermount.py96
-rw-r--r--tests/extmod/vfs_fat_fsusermount.py.exp7
-rw-r--r--tests/extmod/vfs_fat_more.py116
-rw-r--r--tests/extmod/vfs_fat_more.py.exp28
-rw-r--r--tests/extmod/vfs_fat_oldproto.py38
-rw-r--r--tests/extmod/vfs_fat_oldproto.py.exp3
-rw-r--r--tests/extmod/vfs_fat_ramdisk.py51
-rw-r--r--tests/extmod/vfs_fat_ramdisk.py.exp19
-rw-r--r--tests/extmod/websocket_basic.py60
-rw-r--r--tests/extmod/websocket_basic.py.exp14
82 files changed, 1476 insertions, 460 deletions
diff --git a/tests/extmod/btree1.py b/tests/extmod/btree1.py
index 2127554db..59638ef0a 100644
--- a/tests/extmod/btree1.py
+++ b/tests/extmod/btree1.py
@@ -4,8 +4,7 @@ try:
import uerrno
except ImportError:
print("SKIP")
- import sys
- sys.exit()
+ raise SystemExit
#f = open("_test.db", "w+b")
f = uio.BytesIO()
diff --git a/tests/extmod/framebuf1.py b/tests/extmod/framebuf1.py
index cdc7e5b18..2c1366522 100644
--- a/tests/extmod/framebuf1.py
+++ b/tests/extmod/framebuf1.py
@@ -2,98 +2,108 @@ try:
import framebuf
except ImportError:
print("SKIP")
- import sys
- sys.exit()
+ raise SystemExit
w = 5
h = 16
-buf = bytearray(w * h // 8)
-fbuf = framebuf.FrameBuffer(buf, w, h, framebuf.MVLSB)
-
-# access as buffer
-print(memoryview(fbuf)[0])
-
-# 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)
-
-# clear pixel
-fbuf.pixel(4, 15, 0)
-print(buf)
-
-# get pixel
-print(fbuf.pixel(0, 0), fbuf.pixel(1, 1))
-
-# hline
-fbuf.fill(0)
-fbuf.hline(0, 1, w, 1)
-print('hline', buf)
-
-# vline
-fbuf.fill(0)
-fbuf.vline(1, 0, h, 1)
-print('vline', buf)
-
-# rect
-fbuf.fill(0)
-fbuf.rect(1, 1, 3, 3, 1)
-print('rect', buf)
-
-#fill rect
-fbuf.fill(0)
-fbuf.fill_rect(1, 1, 3, 3, 1)
-print('fill_rect', buf)
-
-# line
-fbuf.fill(0)
-fbuf.line(1, 1, 3, 3, 1)
-print('line', buf)
-
-# line steep negative gradient
-fbuf.fill(0)
-fbuf.line(3, 3, 2, 1, 1)
-print('line', buf)
-
-# 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)
-
-# print text
-fbuf.fill(0)
-fbuf.text("hello", 0, 0, 1)
-print(buf)
-fbuf.text("hello", 0, 0, 0) # clear
-print(buf)
-
-# char out of font range set to chr(127)
-fbuf.text(str(chr(31)), 0, 0)
-print(buf)
-
-# test invalid constructor
+size = w * h // 8
+buf = bytearray(size)
+maps = {framebuf.MONO_VLSB : 'MONO_VLSB',
+ framebuf.MONO_HLSB : 'MONO_HLSB',
+ framebuf.MONO_HMSB : 'MONO_HMSB'}
+
+for mapping in maps.keys():
+ for x in range(size):
+ buf[x] = 0
+ fbuf = framebuf.FrameBuffer(buf, w, h, mapping)
+ print(maps[mapping])
+ # access as buffer
+ print(memoryview(fbuf)[0])
+
+ # 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)
+
+ # clear pixel
+ fbuf.pixel(4, 15, 0)
+ print(buf)
+
+ # get pixel
+ print(fbuf.pixel(0, 0), fbuf.pixel(1, 1))
+
+ # hline
+ fbuf.fill(0)
+ fbuf.hline(0, 1, w, 1)
+ print('hline', buf)
+
+ # vline
+ fbuf.fill(0)
+ fbuf.vline(1, 0, h, 1)
+ print('vline', buf)
+
+ # rect
+ fbuf.fill(0)
+ fbuf.rect(1, 1, 3, 3, 1)
+ print('rect', buf)
+
+ #fill rect
+ fbuf.fill(0)
+ fbuf.fill_rect(0, 0, 0, 3, 1) # zero width, no-operation
+ fbuf.fill_rect(1, 1, 3, 3, 1)
+ print('fill_rect', buf)
+
+ # line
+ fbuf.fill(0)
+ fbuf.line(1, 1, 3, 3, 1)
+ print('line', buf)
+
+ # line steep negative gradient
+ fbuf.fill(0)
+ fbuf.line(3, 3, 2, 1, 1)
+ print('line', buf)
+
+ # 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)
+
+ # print text
+ fbuf.fill(0)
+ fbuf.text("hello", 0, 0, 1)
+ print(buf)
+ fbuf.text("hello", 0, 0, 0) # clear
+ print(buf)
+
+ # char out of font range set to chr(127)
+ fbuf.text(str(chr(31)), 0, 0)
+ print(buf)
+ print()
+
+# 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)
fbuf = framebuf.FrameBuffer1(buf, w, h, w)
+print(framebuf.MVLSB == framebuf.MONO_VLSB)
diff --git a/tests/extmod/framebuf1.py.exp b/tests/extmod/framebuf1.py.exp
index 83d775d3c..d954623de 100644
--- a/tests/extmod/framebuf1.py.exp
+++ b/tests/extmod/framebuf1.py.exp
@@ -1,3 +1,4 @@
+MONO_VLSB
0
bytearray(b'\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff')
bytearray(b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00')
@@ -18,4 +19,50 @@ bytearray(b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01')
bytearray(b'\x00\x7f\x7f\x04\x04\x00\x00\x00\x00\x00')
bytearray(b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00')
bytearray(b'\xaaU\xaaU\xaa\x00\x00\x00\x00\x00')
+
+MONO_HLSB
+0
+bytearray(b'\xf8\xf8\xf8\xf8\xf8\xf8\xf8\xf8\xf8\xf8')
+bytearray(b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00')
+bytearray(b'\x88\x00\x00\x00\x00\x00\x00\x00\x00\x00')
+bytearray(b'\x88\x00\x00\x00\x00\x00\x00\x00\x00\x00')
+1 0
+hline bytearray(b'\x00\xf8\x00\x00\x00\x00\x00\x00\x00\x00')
+vline bytearray(b'@@@@@@@@@@')
+rect bytearray(b'\x00pPp\x00\x00\x00\x00\x00\x00')
+fill_rect bytearray(b'\x00ppp\x00\x00\x00\x00\x00\x00')
+line bytearray(b'\x00@ \x10\x00\x00\x00\x00\x00\x00')
+line bytearray(b'\x00 \x10\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\x10\x00\x00\x00')
+bytearray(b'\x00\x00\x00\x00\x00\x00 \x00\x00\x00')
+bytearray(b'\x00\x00\x00\x00\x00\x00\x00\x00\x08\x00')
+bytearray(b'``x````\x00\x00\x00')
+bytearray(b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00')
+bytearray(b'P\xa8P\xa8P\xa8P\xa8\x00\x00')
+
+MONO_HMSB
+0
+bytearray(b'\x1f\x1f\x1f\x1f\x1f\x1f\x1f\x1f\x1f\x1f')
+bytearray(b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00')
+bytearray(b'\x11\x00\x00\x00\x00\x00\x00\x00\x00\x00')
+bytearray(b'\x11\x00\x00\x00\x00\x00\x00\x00\x00\x00')
+1 0
+hline bytearray(b'\x00\x1f\x00\x00\x00\x00\x00\x00\x00\x00')
+vline bytearray(b'\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02')
+rect bytearray(b'\x00\x0e\n\x0e\x00\x00\x00\x00\x00\x00')
+fill_rect bytearray(b'\x00\x0e\x0e\x0e\x00\x00\x00\x00\x00\x00')
+line bytearray(b'\x00\x02\x04\x08\x00\x00\x00\x00\x00\x00')
+line bytearray(b'\x00\x04\x04\x08\x00\x00\x00\x00\x00\x00')
+bytearray(b'\x00\x00\x00\x00\x00\x00\x00\x00\x04\x00')
+bytearray(b'\x00\x00\x00\x00\x00\x00\x04\x00\x00\x00')
+bytearray(b'\x00\x00\x00\x00\x00\x00\x08\x00\x00\x00')
+bytearray(b'\x00\x00\x00\x00\x00\x00\x04\x00\x00\x00')
+bytearray(b'\x00\x00\x00\x00\x00\x00\x00\x00\x10\x00')
+bytearray(b'\x06\x06\x1e\x06\x06\x06\x06\x00\x00\x00')
+bytearray(b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00')
+bytearray(b'\n\x15\n\x15\n\x15\n\x15\x00\x00')
+
ValueError
+True
diff --git a/tests/extmod/framebuf16.py b/tests/extmod/framebuf16.py
index 3aa1d34de..fe81f7f93 100644
--- a/tests/extmod/framebuf16.py
+++ b/tests/extmod/framebuf16.py
@@ -2,8 +2,7 @@ try:
import framebuf
except ImportError:
print("SKIP")
- import sys
- sys.exit()
+ raise SystemExit
def printbuf():
print("--8<--")
diff --git a/tests/extmod/framebuf4.py b/tests/extmod/framebuf4.py
new file mode 100644
index 000000000..8358fa55b
--- /dev/null
+++ b/tests/extmod/framebuf4.py
@@ -0,0 +1,53 @@
+try:
+ import framebuf
+except ImportError:
+ print("SKIP")
+ raise SystemExit
+
+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/machine1.py b/tests/extmod/machine1.py
index 433a18037..6ff38cc05 100644
--- a/tests/extmod/machine1.py
+++ b/tests/extmod/machine1.py
@@ -5,10 +5,10 @@ try:
import umachine as machine
except ImportError:
import machine
-except ImportError:
+ machine.mem8
+except:
print("SKIP")
- import sys
- sys.exit()
+ raise SystemExit
print(machine.mem8)
diff --git a/tests/extmod/machine_pinbase.py b/tests/extmod/machine_pinbase.py
index 5e82823ec..e91775504 100644
--- a/tests/extmod/machine_pinbase.py
+++ b/tests/extmod/machine_pinbase.py
@@ -6,8 +6,7 @@ try:
machine.PinBase
except AttributeError:
print("SKIP")
- import sys
- sys.exit()
+ raise SystemExit
class MyPin(machine.PinBase):
diff --git a/tests/extmod/machine_pulse.py b/tests/extmod/machine_pulse.py
index b6e126435..d525974e0 100644
--- a/tests/extmod/machine_pulse.py
+++ b/tests/extmod/machine_pulse.py
@@ -7,8 +7,7 @@ try:
machine.time_pulse_us
except AttributeError:
print("SKIP")
- import sys
- sys.exit()
+ raise SystemExit
class ConstPin(machine.PinBase):
@@ -43,12 +42,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/machine_signal.py b/tests/extmod/machine_signal.py
new file mode 100644
index 000000000..53f4f5890
--- /dev/null
+++ b/tests/extmod/machine_signal.py
@@ -0,0 +1,39 @@
+# test machine.Signal class
+
+try:
+ import umachine as machine
+except ImportError:
+ import machine
+try:
+ machine.PinBase
+ machine.Signal
+except AttributeError:
+ print("SKIP")
+ raise SystemExit
+
+class Pin(machine.PinBase):
+ def __init__(self):
+ self.v = 0
+
+ def value(self, v=None):
+ if v is None:
+ return self.v
+ else:
+ self.v = int(v)
+
+
+# test non-inverted
+p = Pin()
+s = machine.Signal(p)
+s.value(0)
+print(p.value(), s.value())
+s.value(1)
+print(p.value(), s.value())
+
+# test inverted, and using on/off methods
+p = Pin()
+s = machine.Signal(p, invert=True)
+s.off()
+print(p.value(), s.value())
+s.on()
+print(p.value(), s.value())
diff --git a/tests/extmod/machine_signal.py.exp b/tests/extmod/machine_signal.py.exp
new file mode 100644
index 000000000..7e9dd6796
--- /dev/null
+++ b/tests/extmod/machine_signal.py.exp
@@ -0,0 +1,4 @@
+0 0
+1 1
+1 0
+0 1
diff --git a/tests/extmod/time_ms_us.py b/tests/extmod/time_ms_us.py
index 2078f1bb5..31f07d31b 100644
--- a/tests/extmod/time_ms_us.py
+++ b/tests/extmod/time_ms_us.py
@@ -1,10 +1,9 @@
-import sys
import utime
try:
utime.sleep_ms
except AttributeError:
print("SKIP")
- sys.exit()
+ raise SystemExit
utime.sleep_ms(1)
utime.sleep_us(1)
diff --git a/tests/extmod/ubinascii_a2b_base64.py b/tests/extmod/ubinascii_a2b_base64.py
index 97c451950..b35f26591 100644
--- a/tests/extmod/ubinascii_a2b_base64.py
+++ b/tests/extmod/ubinascii_a2b_base64.py
@@ -1,7 +1,11 @@
try:
- import ubinascii as binascii
+ try:
+ import ubinascii as binascii
+ except ImportError:
+ import binascii
except ImportError:
- import binascii
+ print("SKIP")
+ raise SystemExit
print(binascii.a2b_base64(b''))
print(binascii.a2b_base64(b'Zg=='))
diff --git a/tests/extmod/ubinascii_b2a_base64.py b/tests/extmod/ubinascii_b2a_base64.py
index fdcaf32dd..f4bb69fe0 100644
--- a/tests/extmod/ubinascii_b2a_base64.py
+++ b/tests/extmod/ubinascii_b2a_base64.py
@@ -1,7 +1,11 @@
try:
- import ubinascii as binascii
+ try:
+ import ubinascii as binascii
+ except ImportError:
+ import binascii
except ImportError:
- import binascii
+ print("SKIP")
+ raise SystemExit
print(binascii.b2a_base64(b''))
print(binascii.b2a_base64(b'f'))
diff --git a/tests/extmod/ubinascii_crc32.py b/tests/extmod/ubinascii_crc32.py
index 2c4017751..89664a9b3 100644
--- a/tests/extmod/ubinascii_crc32.py
+++ b/tests/extmod/ubinascii_crc32.py
@@ -1,13 +1,17 @@
try:
- import ubinascii as binascii
+ try:
+ import ubinascii as binascii
+ except ImportError:
+ import binascii
except ImportError:
- import binascii
+ print("SKIP")
+ raise SystemExit
+
try:
binascii.crc32
except AttributeError:
print("SKIP")
- import sys
- sys.exit()
+ raise SystemExit
print(hex(binascii.crc32(b'The quick brown fox jumps over the lazy dog')))
print(hex(binascii.crc32(b'\x00' * 32)))
diff --git a/tests/extmod/ubinascii_hexlify.py b/tests/extmod/ubinascii_hexlify.py
index 14c37cb4b..bc9928747 100644
--- a/tests/extmod/ubinascii_hexlify.py
+++ b/tests/extmod/ubinascii_hexlify.py
@@ -1,7 +1,11 @@
try:
- import ubinascii as binascii
+ try:
+ import ubinascii as binascii
+ except ImportError:
+ import binascii
except ImportError:
- import binascii
+ print("SKIP")
+ raise SystemExit
print(binascii.hexlify(b'\x00\x01\x02\x03\x04\x05\x06\x07'))
print(binascii.hexlify(b'\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f'))
diff --git a/tests/extmod/ubinascii_micropython.py b/tests/extmod/ubinascii_micropython.py
index d68da3205..a4c00a2cb 100644
--- a/tests/extmod/ubinascii_micropython.py
+++ b/tests/extmod/ubinascii_micropython.py
@@ -1,7 +1,11 @@
try:
- import ubinascii as binascii
+ try:
+ import ubinascii as binascii
+ except ImportError:
+ import binascii
except ImportError:
- import binascii
+ print("SKIP")
+ raise SystemExit
# two arguments supported in uPy but not CPython
a = binascii.hexlify(b'123', ':')
diff --git a/tests/extmod/ubinascii_unhexlify.py b/tests/extmod/ubinascii_unhexlify.py
index 99c2c0208..865abfe3a 100644
--- a/tests/extmod/ubinascii_unhexlify.py
+++ b/tests/extmod/ubinascii_unhexlify.py
@@ -1,7 +1,11 @@
try:
- import ubinascii as binascii
+ try:
+ import ubinascii as binascii
+ except ImportError:
+ import binascii
except ImportError:
- import binascii
+ print("SKIP")
+ raise SystemExit
print(binascii.unhexlify(b'0001020304050607'))
print(binascii.unhexlify(b'08090a0b0c0d0e0f'))
diff --git a/tests/extmod/uctypes_32bit_intbig.py b/tests/extmod/uctypes_32bit_intbig.py
new file mode 100644
index 000000000..6b4d3d76c
--- /dev/null
+++ b/tests/extmod/uctypes_32bit_intbig.py
@@ -0,0 +1,53 @@
+# This test checks previously known problem values for 32-bit ports.
+# It's less useful for 64-bit ports.
+try:
+ import uctypes
+except ImportError:
+ print("SKIP")
+ raise SystemExit
+
+buf = b"12345678abcd"
+struct = uctypes.struct(
+ uctypes.addressof(buf),
+ {"f32": uctypes.UINT32 | 0, "f64": uctypes.UINT64 | 4},
+ uctypes.LITTLE_ENDIAN
+)
+
+struct.f32 = 0x7fffffff
+print(buf)
+
+struct.f32 = 0x80000000
+print(buf)
+
+struct.f32 = 0xff010203
+print(buf)
+
+struct.f64 = 0x80000000
+print(buf)
+
+struct.f64 = 0x80000000 * 2
+print(buf)
+
+print("=")
+
+buf = b"12345678abcd"
+struct = uctypes.struct(
+ uctypes.addressof(buf),
+ {"f32": uctypes.UINT32 | 0, "f64": uctypes.UINT64 | 4},
+ uctypes.BIG_ENDIAN
+)
+
+struct.f32 = 0x7fffffff
+print(buf)
+
+struct.f32 = 0x80000000
+print(buf)
+
+struct.f32 = 0xff010203
+print(buf)
+
+struct.f64 = 0x80000000
+print(buf)
+
+struct.f64 = 0x80000000 * 2
+print(buf)
diff --git a/tests/extmod/uctypes_32bit_intbig.py.exp b/tests/extmod/uctypes_32bit_intbig.py.exp
new file mode 100644
index 000000000..d1fc1fe35
--- /dev/null
+++ b/tests/extmod/uctypes_32bit_intbig.py.exp
@@ -0,0 +1,11 @@
+b'\xff\xff\xff\x7f5678abcd'
+b'\x00\x00\x00\x805678abcd'
+b'\x03\x02\x01\xff5678abcd'
+b'\x03\x02\x01\xff\x00\x00\x00\x80\x00\x00\x00\x00'
+b'\x03\x02\x01\xff\x00\x00\x00\x00\x01\x00\x00\x00'
+=
+b'\x7f\xff\xff\xff5678abcd'
+b'\x80\x00\x00\x005678abcd'
+b'\xff\x01\x02\x035678abcd'
+b'\xff\x01\x02\x03\x00\x00\x00\x00\x80\x00\x00\x00'
+b'\xff\x01\x02\x03\x00\x00\x00\x01\x00\x00\x00\x00'
diff --git a/tests/extmod/uctypes_array_assign_le.py b/tests/extmod/uctypes_array_assign_le.py
index 18d63f8bf..6afa7e0a2 100644
--- a/tests/extmod/uctypes_array_assign_le.py
+++ b/tests/extmod/uctypes_array_assign_le.py
@@ -1,4 +1,8 @@
-import uctypes
+try:
+ import uctypes
+except ImportError:
+ print("SKIP")
+ raise SystemExit
desc = {
# arr is array at offset 0, of UINT8 elements, array size is 2
diff --git a/tests/extmod/uctypes_array_assign_native_le.py b/tests/extmod/uctypes_array_assign_native_le.py
index 632c4d252..a538bf9ad 100644
--- a/tests/extmod/uctypes_array_assign_native_le.py
+++ b/tests/extmod/uctypes_array_assign_native_le.py
@@ -1,9 +1,13 @@
import sys
-import uctypes
+try:
+ import uctypes
+except ImportError:
+ print("SKIP")
+ raise SystemExit
if sys.byteorder != "little":
print("SKIP")
- sys.exit()
+ raise SystemExit
desc = {
# arr is array at offset 0, of UINT8 elements, array size is 2
@@ -66,16 +70,6 @@ S.arr10[0] = 0x11223344
print(hex(S.arr10[0]))
assert hex(S.arr10[0]) == "0x11223344"
-# assign int64
-S.arr11[0] = 0x11223344
-print(hex(S.arr11[0]))
-assert hex(S.arr11[0]) == "0x11223344"
-
-# assign uint64
-S.arr12[0] = 0x11223344
-print(hex(S.arr12[0]))
-assert hex(S.arr12[0]) == "0x11223344"
-
# index out of range
try:
print(S.arr8[2])
diff --git a/tests/extmod/uctypes_array_assign_native_le.py.exp b/tests/extmod/uctypes_array_assign_native_le.py.exp
index 4efcdec66..9d67b1c77 100644
--- a/tests/extmod/uctypes_array_assign_native_le.py.exp
+++ b/tests/extmod/uctypes_array_assign_native_le.py.exp
@@ -6,8 +6,6 @@ True
0x11
0x1122
0x11223344
-0x11223344
-0x11223344
IndexError
TypeError
TypeError
diff --git a/tests/extmod/uctypes_array_assign_native_le_intbig.py b/tests/extmod/uctypes_array_assign_native_le_intbig.py
new file mode 100644
index 000000000..84dfba0e2
--- /dev/null
+++ b/tests/extmod/uctypes_array_assign_native_le_intbig.py
@@ -0,0 +1,43 @@
+import sys
+try:
+ import uctypes
+except ImportError:
+ print("SKIP")
+ raise SystemExit
+
+if sys.byteorder != "little":
+ print("SKIP")
+ raise SystemExit
+
+desc = {
+ # arr is array at offset 0, of UINT8 elements, array size is 2
+ "arr": (uctypes.ARRAY | 0, uctypes.UINT8 | 2),
+ # arr2 is array at offset 0, size 2, of structures defined recursively
+ "arr2": (uctypes.ARRAY | 0, 2, {"b": uctypes.UINT8 | 0}),
+ "arr3": (uctypes.ARRAY | 2, uctypes.UINT16 | 2),
+
+ # aligned
+ "arr5": (uctypes.ARRAY | 0, uctypes.UINT32 | 1),
+ "arr7": (uctypes.ARRAY | 0, 1, {"l": uctypes.UINT32 | 0}),
+
+ "arr8": (uctypes.ARRAY | 0, uctypes.INT8 | 1),
+ "arr9": (uctypes.ARRAY | 0, uctypes.INT16 | 1),
+ "arr10": (uctypes.ARRAY | 0, uctypes.INT32 | 1),
+ "arr11": (uctypes.ARRAY | 0, uctypes.INT64 | 1),
+ "arr12": (uctypes.ARRAY | 0, uctypes.UINT64| 1),
+ "arr13": (uctypes.ARRAY | 1, 1, {"l": {}}),
+}
+
+data = bytearray(8)
+
+S = uctypes.struct(uctypes.addressof(data), desc)
+
+# assign int64
+S.arr11[0] = 0x11223344
+print(hex(S.arr11[0]))
+assert hex(S.arr11[0]) == "0x11223344"
+
+# assign uint64
+S.arr12[0] = 0x11223344
+print(hex(S.arr12[0]))
+assert hex(S.arr12[0]) == "0x11223344"
diff --git a/tests/extmod/uctypes_array_assign_native_le_intbig.py.exp b/tests/extmod/uctypes_array_assign_native_le_intbig.py.exp
new file mode 100644
index 000000000..0394e9ae1
--- /dev/null
+++ b/tests/extmod/uctypes_array_assign_native_le_intbig.py.exp
@@ -0,0 +1,2 @@
+0x11223344
+0x11223344
diff --git a/tests/extmod/uctypes_bytearray.py b/tests/extmod/uctypes_bytearray.py
index 7294b7ea4..61c7da271 100644
--- a/tests/extmod/uctypes_bytearray.py
+++ b/tests/extmod/uctypes_bytearray.py
@@ -1,4 +1,8 @@
-import uctypes
+try:
+ import uctypes
+except ImportError:
+ print("SKIP")
+ raise SystemExit
desc = {
"arr": (uctypes.ARRAY | 0, uctypes.UINT8 | 2),
diff --git a/tests/extmod/uctypes_le.py b/tests/extmod/uctypes_le.py
index 5ae410b01..7df5ac090 100644
--- a/tests/extmod/uctypes_le.py
+++ b/tests/extmod/uctypes_le.py
@@ -1,4 +1,8 @@
-import uctypes
+try:
+ import uctypes
+except ImportError:
+ print("SKIP")
+ raise SystemExit
desc = {
"s0": uctypes.UINT16 | 0,
diff --git a/tests/extmod/uctypes_le_float.py b/tests/extmod/uctypes_le_float.py
index c85b75f36..84ff2b84c 100644
--- a/tests/extmod/uctypes_le_float.py
+++ b/tests/extmod/uctypes_le_float.py
@@ -1,4 +1,8 @@
-import uctypes
+try:
+ import uctypes
+except ImportError:
+ print("SKIP")
+ raise SystemExit
desc = {
"f32": uctypes.FLOAT32 | 0,
diff --git a/tests/extmod/uctypes_native_float.py b/tests/extmod/uctypes_native_float.py
index 89aac8bf3..acef47036 100644
--- a/tests/extmod/uctypes_native_float.py
+++ b/tests/extmod/uctypes_native_float.py
@@ -1,4 +1,8 @@
-import uctypes
+try:
+ import uctypes
+except ImportError:
+ print("SKIP")
+ raise SystemExit
desc = {
"f32": uctypes.FLOAT32 | 0,
diff --git a/tests/extmod/uctypes_native_le.py b/tests/extmod/uctypes_native_le.py
index ef0f9f5e9..8bba03b38 100644
--- a/tests/extmod/uctypes_native_le.py
+++ b/tests/extmod/uctypes_native_le.py
@@ -2,11 +2,15 @@
# Codepaths for packed vs native structures are different. This test only works
# on little-endian machine (no matter if 32 or 64 bit).
import sys
-import uctypes
+try:
+ import uctypes
+except ImportError:
+ print("SKIP")
+ raise SystemExit
if sys.byteorder != "little":
print("SKIP")
- sys.exit()
+ raise SystemExit
desc = {
diff --git a/tests/extmod/uctypes_print.py b/tests/extmod/uctypes_print.py
index 71981ce7e..c310238e5 100644
--- a/tests/extmod/uctypes_print.py
+++ b/tests/extmod/uctypes_print.py
@@ -1,6 +1,9 @@
# test printing of uctypes objects
-
-import uctypes
+try:
+ import uctypes
+except ImportError:
+ print("SKIP")
+ raise SystemExit
# we use an address of "0" because we just want to print something deterministic
# and don't actually need to set/get any values in the struct
diff --git a/tests/extmod/uctypes_ptr_le.py b/tests/extmod/uctypes_ptr_le.py
index d0216dfb8..056e45650 100644
--- a/tests/extmod/uctypes_ptr_le.py
+++ b/tests/extmod/uctypes_ptr_le.py
@@ -1,9 +1,13 @@
import sys
-import uctypes
+try:
+ import uctypes
+except ImportError:
+ print("SKIP")
+ raise SystemExit
if sys.byteorder != "little":
print("SKIP")
- sys.exit()
+ raise SystemExit
desc = {
"ptr": (uctypes.PTR | 0, uctypes.UINT8),
diff --git a/tests/extmod/uctypes_ptr_native_le.py b/tests/extmod/uctypes_ptr_native_le.py
index 6f011c3c2..24508b1cb 100644
--- a/tests/extmod/uctypes_ptr_native_le.py
+++ b/tests/extmod/uctypes_ptr_native_le.py
@@ -1,9 +1,13 @@
import sys
-import uctypes
+try:
+ import uctypes
+except ImportError:
+ print("SKIP")
+ raise SystemExit
if sys.byteorder != "little":
print("SKIP")
- sys.exit()
+ raise SystemExit
desc = {
diff --git a/tests/extmod/uctypes_sizeof.py b/tests/extmod/uctypes_sizeof.py
index fcfd8ecd7..5a6adb437 100644
--- a/tests/extmod/uctypes_sizeof.py
+++ b/tests/extmod/uctypes_sizeof.py
@@ -1,4 +1,8 @@
-import uctypes
+try:
+ import uctypes
+except ImportError:
+ print("SKIP")
+ raise SystemExit
desc = {
# arr is array at offset 0, of UINT8 elements, array size is 2
diff --git a/tests/extmod/uctypes_sizeof_native.py b/tests/extmod/uctypes_sizeof_native.py
index f830a1f85..32c740e77 100644
--- a/tests/extmod/uctypes_sizeof_native.py
+++ b/tests/extmod/uctypes_sizeof_native.py
@@ -1,4 +1,8 @@
-import uctypes
+try:
+ import uctypes
+except ImportError:
+ print("SKIP")
+ raise SystemExit
S1 = {}
assert uctypes.sizeof(S1) == 0
diff --git a/tests/extmod/uhashlib_sha1.py b/tests/extmod/uhashlib_sha1.py
index f12fc649a..4f7066899 100644
--- a/tests/extmod/uhashlib_sha1.py
+++ b/tests/extmod/uhashlib_sha1.py
@@ -1,4 +1,3 @@
-import sys
try:
import uhashlib as hashlib
except ImportError:
@@ -8,14 +7,14 @@ except ImportError:
# This is neither uPy, nor cPy, so must be uPy with
# uhashlib module disabled.
print("SKIP")
- sys.exit()
+ raise SystemExit
try:
hashlib.sha1
except AttributeError:
# SHA1 is only available on some ports
print("SKIP")
- sys.exit()
+ raise SystemExit
sha1 = hashlib.sha1(b'hello')
sha1.update(b'world')
diff --git a/tests/extmod/uhashlib_sha256.py b/tests/extmod/uhashlib_sha256.py
index ff51f2ffa..3200e8f5c 100644
--- a/tests/extmod/uhashlib_sha256.py
+++ b/tests/extmod/uhashlib_sha256.py
@@ -1,4 +1,3 @@
-import sys
try:
import uhashlib as hashlib
except ImportError:
@@ -8,7 +7,7 @@ except ImportError:
# This is neither uPy, nor cPy, so must be uPy with
# uhashlib module disabled.
print("SKIP")
- sys.exit()
+ raise SystemExit
h = hashlib.sha256()
diff --git a/tests/extmod/uheapq1.py b/tests/extmod/uheapq1.py
index e71f817ef..7c1fe4e1e 100644
--- a/tests/extmod/uheapq1.py
+++ b/tests/extmod/uheapq1.py
@@ -1,7 +1,11 @@
try:
import uheapq as heapq
except:
- import heapq
+ try:
+ import heapq
+ except ImportError:
+ print("SKIP")
+ raise SystemExit
try:
heapq.heappop([])
diff --git a/tests/extmod/ujson_dumps.py b/tests/extmod/ujson_dumps.py
index c0ee60d73..d73271801 100644
--- a/tests/extmod/ujson_dumps.py
+++ b/tests/extmod/ujson_dumps.py
@@ -1,7 +1,11 @@
try:
import ujson as json
except ImportError:
- import json
+ try:
+ import json
+ except ImportError:
+ print("SKIP")
+ raise SystemExit
print(json.dumps(False))
print(json.dumps(True))
diff --git a/tests/extmod/ujson_dumps_extra.py b/tests/extmod/ujson_dumps_extra.py
index 0e593c3e9..21a388c32 100644
--- a/tests/extmod/ujson_dumps_extra.py
+++ b/tests/extmod/ujson_dumps_extra.py
@@ -1,5 +1,9 @@
# test uPy ujson behaviour that's not valid in CPy
-import ujson
+try:
+ import ujson
+except ImportError:
+ print("SKIP")
+ raise SystemExit
print(ujson.dumps(b'1234'))
diff --git a/tests/extmod/ujson_dumps_float.py b/tests/extmod/ujson_dumps_float.py
index f6ba5f113..e8cceb6f1 100644
--- a/tests/extmod/ujson_dumps_float.py
+++ b/tests/extmod/ujson_dumps_float.py
@@ -1,6 +1,10 @@
try:
import ujson as json
except ImportError:
- import json
+ try:
+ import json
+ except ImportError:
+ print("SKIP")
+ raise SystemExit
print(json.dumps(1.2))
diff --git a/tests/extmod/ujson_load.py b/tests/extmod/ujson_load.py
index bf484a207..9725ab2dd 100644
--- a/tests/extmod/ujson_load.py
+++ b/tests/extmod/ujson_load.py
@@ -2,8 +2,12 @@ try:
from uio import StringIO
import ujson as json
except:
- from io import StringIO
- import json
+ try:
+ from io import StringIO
+ import json
+ except ImportError:
+ print("SKIP")
+ raise SystemExit
print(json.load(StringIO('null')))
print(json.load(StringIO('"abc\\u0064e"')))
diff --git a/tests/extmod/ujson_loads.py b/tests/extmod/ujson_loads.py
index 37576e6ae..adba3c068 100644
--- a/tests/extmod/ujson_loads.py
+++ b/tests/extmod/ujson_loads.py
@@ -1,7 +1,11 @@
try:
import ujson as json
-except:
- import json
+except ImportError:
+ try:
+ import json
+ except ImportError:
+ print("SKIP")
+ raise SystemExit
def my_print(o):
if isinstance(o, dict):
diff --git a/tests/extmod/ujson_loads_float.py b/tests/extmod/ujson_loads_float.py
index f5e754608..f1b8cc364 100644
--- a/tests/extmod/ujson_loads_float.py
+++ b/tests/extmod/ujson_loads_float.py
@@ -1,7 +1,11 @@
try:
import ujson as json
-except:
- import json
+except ImportError:
+ try:
+ import json
+ except ImportError:
+ print("SKIP")
+ raise SystemExit
def my_print(o):
print('%.3f' % o)
diff --git a/tests/extmod/urandom_basic.py b/tests/extmod/urandom_basic.py
index bf00035bd..57e6b26cb 100644
--- a/tests/extmod/urandom_basic.py
+++ b/tests/extmod/urandom_basic.py
@@ -1,7 +1,11 @@
try:
import urandom as random
except ImportError:
- import random
+ try:
+ import random
+ except ImportError:
+ print("SKIP")
+ raise SystemExit
# check getrandbits returns a value within the bit range
for b in (1, 2, 3, 4, 16, 32):
diff --git a/tests/extmod/urandom_extra.py b/tests/extmod/urandom_extra.py
index 004fb10cc..f5a34e168 100644
--- a/tests/extmod/urandom_extra.py
+++ b/tests/extmod/urandom_extra.py
@@ -1,14 +1,17 @@
try:
import urandom as random
except ImportError:
- import random
+ try:
+ import random
+ except ImportError:
+ print("SKIP")
+ raise SystemExit
try:
random.randint
except AttributeError:
- import sys
print('SKIP')
- sys.exit()
+ raise SystemExit
print('randrange')
for i in range(50):
diff --git a/tests/extmod/ure1.py b/tests/extmod/ure1.py
index aeadf4e5c..1f38b8087 100644
--- a/tests/extmod/ure1.py
+++ b/tests/extmod/ure1.py
@@ -1,7 +1,11 @@
try:
import ure as re
except ImportError:
- import re
+ try:
+ import re
+ except ImportError:
+ print("SKIP")
+ raise SystemExit
r = re.compile(".+")
m = r.match("abc")
@@ -11,6 +15,10 @@ try:
except IndexError:
print("IndexError")
+# conversion of re and match to string
+str(r)
+str(m)
+
r = re.compile("(.+)1")
m = r.match("xyz781")
print(m.group(0))
@@ -63,6 +71,11 @@ m = re.match('^ab$', 'ab'); print(m.group(0))
m = re.match('a|b', 'b'); print(m.group(0))
m = re.match('a|b|c', 'c'); print(m.group(0))
+# Case where anchors fail to match
+r = re.compile("^b|b$")
+m = r.search("abc")
+print(m)
+
try:
re.compile("*")
except:
diff --git a/tests/extmod/ure_debug.py b/tests/extmod/ure_debug.py
new file mode 100644
index 000000000..cfb264bb6
--- /dev/null
+++ b/tests/extmod/ure_debug.py
@@ -0,0 +1,8 @@
+# test printing debugging info when compiling
+try:
+ import ure
+except ImportError:
+ print("SKIP")
+ raise SystemExit
+
+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/ure_error.py b/tests/extmod/ure_error.py
index 1e9f66a9e..f52f735c7 100644
--- a/tests/extmod/ure_error.py
+++ b/tests/extmod/ure_error.py
@@ -2,8 +2,12 @@
try:
import ure as re
-except:
- import re
+except ImportError:
+ try:
+ import re
+ except ImportError:
+ print("SKIP")
+ raise SystemExit
def test_re(r):
try:
diff --git a/tests/extmod/ure_group.py b/tests/extmod/ure_group.py
index 8078a0a85..4e39468c5 100644
--- a/tests/extmod/ure_group.py
+++ b/tests/extmod/ure_group.py
@@ -2,8 +2,12 @@
try:
import ure as re
-except:
- import re
+except ImportError:
+ try:
+ import re
+ except ImportError:
+ print("SKIP")
+ raise SystemExit
def print_groups(match):
print('----')
diff --git a/tests/extmod/ure_namedclass.py b/tests/extmod/ure_namedclass.py
index 25f425ce7..215d09613 100644
--- a/tests/extmod/ure_namedclass.py
+++ b/tests/extmod/ure_namedclass.py
@@ -2,8 +2,12 @@
try:
import ure as re
-except:
- import re
+except ImportError:
+ try:
+ import re
+ except ImportError:
+ print("SKIP")
+ raise SystemExit
def print_groups(match):
print('----')
diff --git a/tests/extmod/ure_split.py b/tests/extmod/ure_split.py
index 620fd9052..317ca9892 100644
--- a/tests/extmod/ure_split.py
+++ b/tests/extmod/ure_split.py
@@ -1,7 +1,11 @@
try:
import ure as re
except ImportError:
- import re
+ try:
+ import re
+ except ImportError:
+ print("SKIP")
+ raise SystemExit
r = re.compile(" ")
s = r.split("a b c foobar")
diff --git a/tests/extmod/ure_split_empty.py b/tests/extmod/ure_split_empty.py
index 6f31e6dc6..76ce97ea6 100644
--- a/tests/extmod/ure_split_empty.py
+++ b/tests/extmod/ure_split_empty.py
@@ -4,7 +4,11 @@
# behaviour will change in a future version. MicroPython just stops
# splitting as soon as an empty match is found.
-import ure as re
+try:
+ import ure as re
+except ImportError:
+ print("SKIP")
+ raise SystemExit
r = re.compile(" *")
s = r.split("a b c foobar")
diff --git a/tests/extmod/ure_split_notimpl.py b/tests/extmod/ure_split_notimpl.py
new file mode 100644
index 000000000..da6e9652d
--- /dev/null
+++ b/tests/extmod/ure_split_notimpl.py
@@ -0,0 +1,11 @@
+try:
+ import ure as re
+except ImportError:
+ print("SKIP")
+ raise SystemExit
+
+r = re.compile('( )')
+try:
+ s = r.split("a b c foobar")
+except NotImplementedError:
+ print('NotImplementedError')
diff --git a/tests/extmod/ure_split_notimpl.py.exp b/tests/extmod/ure_split_notimpl.py.exp
new file mode 100644
index 000000000..437f61670
--- /dev/null
+++ b/tests/extmod/ure_split_notimpl.py.exp
@@ -0,0 +1 @@
+NotImplementedError
diff --git a/tests/extmod/ussl_basic.py b/tests/extmod/ussl_basic.py
new file mode 100644
index 000000000..9f8019a0b
--- /dev/null
+++ b/tests/extmod/ussl_basic.py
@@ -0,0 +1,51 @@
+# very basic test of ssl module, just to test the methods exist
+
+try:
+ import uio as io
+ import ussl as ssl
+except ImportError:
+ print("SKIP")
+ raise SystemExit
+
+# create in client mode
+try:
+ ss = ssl.wrap_socket(io.BytesIO())
+except OSError as er:
+ print('wrap_socket:', repr(er))
+
+# create in server mode (can use this object for further tests)
+socket = io.BytesIO()
+ss = ssl.wrap_socket(socket, server_side=1)
+
+# print
+print(repr(ss)[:12])
+
+# setblocking
+try:
+ ss.setblocking(False)
+except NotImplementedError:
+ print('setblocking: NotImplementedError')
+ss.setblocking(True)
+
+# write
+print(ss.write(b'aaaa'))
+
+# read (underlying socket has no data)
+print(ss.read(8))
+
+# read (underlying socket has data, but it's bad data)
+socket.write(b'aaaaaaaaaaaaaaaa')
+socket.seek(0)
+try:
+ ss.read(8)
+except OSError as er:
+ print('read:', repr(er))
+
+# close
+ss.close()
+
+# write on closed socket
+try:
+ ss.write(b'aaaa')
+except OSError as er:
+ print('write:', repr(er))
diff --git a/tests/extmod/ussl_basic.py.exp b/tests/extmod/ussl_basic.py.exp
new file mode 100644
index 000000000..b4dd03860
--- /dev/null
+++ b/tests/extmod/ussl_basic.py.exp
@@ -0,0 +1,8 @@
+ssl_handshake_status: -256
+wrap_socket: OSError(5,)
+<_SSLSocket
+setblocking: NotImplementedError
+4
+b''
+read: OSError(-261,)
+write: OSError(-256,)
diff --git a/tests/extmod/utimeq1.py b/tests/extmod/utimeq1.py
index 9af723674..dc7f3b660 100644
--- a/tests/extmod/utimeq1.py
+++ b/tests/extmod/utimeq1.py
@@ -5,8 +5,7 @@ try:
from utimeq import utimeq
except ImportError:
print("SKIP")
- import sys
- sys.exit()
+ raise SystemExit
DEBUG = 0
@@ -34,6 +33,41 @@ try:
except IndexError:
pass
+# unsupported unary op
+try:
+ ~h
+ assert False
+except TypeError:
+ pass
+
+# pushing on full queue
+h = utimeq(1)
+h.push(1, 0, 0)
+try:
+ h.push(2, 0, 0)
+ assert False
+except IndexError:
+ pass
+
+# popping into invalid type
+try:
+ h.pop([])
+ assert False
+except TypeError:
+ pass
+
+# length
+assert len(h) == 1
+
+# peektime
+assert h.peektime() == 1
+
+# peektime with empty queue
+try:
+ utimeq(1).peektime()
+ assert False
+except IndexError:
+ pass
def pop_all(h):
l = []
diff --git a/tests/extmod/utimeq_stable.py b/tests/extmod/utimeq_stable.py
index 9f6ba76d4..9fb522d51 100644
--- a/tests/extmod/utimeq_stable.py
+++ b/tests/extmod/utimeq_stable.py
@@ -2,8 +2,7 @@ try:
from utimeq import utimeq
except ImportError:
print("SKIP")
- import sys
- sys.exit()
+ raise SystemExit
h = utimeq(10)
diff --git a/tests/extmod/uzlib_decompio.py b/tests/extmod/uzlib_decompio.py
index 75a6df0ca..112a82597 100644
--- a/tests/extmod/uzlib_decompio.py
+++ b/tests/extmod/uzlib_decompio.py
@@ -1,8 +1,9 @@
try:
- import zlib
-except ImportError:
import uzlib as zlib
-import uio as io
+ import uio as io
+except ImportError:
+ print("SKIP")
+ raise SystemExit
# Raw DEFLATE bitstream
diff --git a/tests/extmod/uzlib_decompio_gz.py b/tests/extmod/uzlib_decompio_gz.py
index c7aac04e8..02087f763 100644
--- a/tests/extmod/uzlib_decompio_gz.py
+++ b/tests/extmod/uzlib_decompio_gz.py
@@ -1,8 +1,9 @@
try:
- import zlib
-except ImportError:
import uzlib as zlib
-import uio as io
+ import uio as io
+except ImportError:
+ print("SKIP")
+ raise SystemExit
# gzip bitstream
@@ -18,6 +19,16 @@ print(inp.read(1))
print(inp.read())
print(buf.seek(0, 1))
+# Check FHCRC field
+buf = io.BytesIO(b'\x1f\x8b\x08\x02\x99\x0c\xe5W\x00\x03\x00\x00\xcbH\xcd\xc9\xc9\x07\x00\x86\xa6\x106\x05\x00\x00\x00')
+inp = zlib.DecompIO(buf, 16 + 8)
+print(inp.read())
+
+# Check FEXTRA field
+buf = io.BytesIO(b'\x1f\x8b\x08\x04\x99\x0c\xe5W\x00\x03\x01\x00X\xcbH\xcd\xc9\xc9\x07\x00\x86\xa6\x106\x05\x00\x00\x00')
+inp = zlib.DecompIO(buf, 16 + 8)
+print(inp.read())
+
# broken header
buf = io.BytesIO(b'\x1f\x8c\x08\x08\x99\x0c\xe5W\x00\x03hello\x00\xcbH\xcd\xc9\xc9\x07\x00\x86\xa6\x106\x05\x00\x00\x00')
try:
diff --git a/tests/extmod/uzlib_decompio_gz.py.exp b/tests/extmod/uzlib_decompio_gz.py.exp
index 2330580f8..20a30c82a 100644
--- a/tests/extmod/uzlib_decompio_gz.py.exp
+++ b/tests/extmod/uzlib_decompio_gz.py.exp
@@ -7,5 +7,7 @@ b'lo'
b''
b''
31
+b'hello'
+b'hello'
ValueError
OSError(22,)
diff --git a/tests/extmod/uzlib_decompress.py b/tests/extmod/uzlib_decompress.py
index 6892808cb..63247955c 100644
--- a/tests/extmod/uzlib_decompress.py
+++ b/tests/extmod/uzlib_decompress.py
@@ -1,7 +1,11 @@
try:
import zlib
except ImportError:
- import uzlib as zlib
+ try:
+ import uzlib as zlib
+ except ImportError:
+ print("SKIP")
+ raise SystemExit
PATTERNS = [
# Packed results produced by CPy's zlib.compress()
diff --git a/tests/extmod/vfs_basic.py b/tests/extmod/vfs_basic.py
new file mode 100644
index 000000000..4fc67d34b
--- /dev/null
+++ b/tests/extmod/vfs_basic.py
@@ -0,0 +1,151 @@
+# test VFS functionality without any particular filesystem type
+
+try:
+ try:
+ import uos_vfs as uos
+ open = uos.vfs_open
+ except ImportError:
+ import uos
+ uos.mount
+except (ImportError, AttributeError):
+ print("SKIP")
+ raise SystemExit
+
+
+class Filesystem:
+ def __init__(self, id):
+ self.id = id
+ def mount(self, readonly, mkfs):
+ print(self.id, 'mount', readonly, mkfs)
+ def umount(self):
+ print(self.id, 'umount')
+ def ilistdir(self, dir):
+ print(self.id, 'ilistdir', dir)
+ return iter([('a%d' % self.id, 0, 0)])
+ def chdir(self, dir):
+ print(self.id, 'chdir', dir)
+ def getcwd(self):
+ print(self.id, 'getcwd')
+ return 'dir%d' % self.id
+ def mkdir(self, path):
+ print(self.id, 'mkdir', path)
+ def remove(self, path):
+ print(self.id, 'remove', path)
+ def rename(self, old_path, new_path):
+ print(self.id, 'rename', old_path, new_path)
+ def rmdir(self, path):
+ print(self.id, 'rmdir', path)
+ def stat(self, path):
+ print(self.id, 'stat', path)
+ return (self.id,)
+ def statvfs(self, path):
+ print(self.id, 'statvfs', path)
+ return (self.id,)
+ def open(self, file, mode):
+ print(self.id, 'open', file, mode)
+
+
+# first we umount any existing mount points the target may have
+try:
+ uos.umount('/')
+except OSError:
+ pass
+for path in uos.listdir('/'):
+ uos.umount('/' + path)
+
+# stat root dir
+print(uos.stat('/'))
+
+# statvfs root dir; verify that f_namemax has a sensible size
+print(uos.statvfs('/')[9] >= 32)
+
+# getcwd when in root dir
+print(uos.getcwd())
+
+# basic mounting and listdir
+uos.mount(Filesystem(1), '/test_mnt')
+print(uos.listdir())
+
+# ilistdir
+i = uos.ilistdir()
+print(next(i))
+try:
+ next(i)
+except StopIteration:
+ print('StopIteration')
+try:
+ next(i)
+except StopIteration:
+ print('StopIteration')
+
+# referencing the mount point in different ways
+print(uos.listdir('test_mnt'))
+print(uos.listdir('/test_mnt'))
+
+# mounting another filesystem
+uos.mount(Filesystem(2), '/test_mnt2', readonly=True)
+print(uos.listdir())
+print(uos.listdir('/test_mnt2'))
+
+# mounting over an existing mount point
+try:
+ uos.mount(Filesystem(3), '/test_mnt2')
+except OSError:
+ print('OSError')
+
+# mkdir of a mount point
+try:
+ uos.mkdir('/test_mnt')
+except OSError:
+ print('OSError')
+
+# rename across a filesystem
+try:
+ uos.rename('/test_mnt/a', '/test_mnt2/b')
+except OSError:
+ print('OSError')
+
+# delegating to mounted filesystem
+uos.chdir('test_mnt')
+print(uos.listdir())
+print(uos.getcwd())
+uos.mkdir('test_dir')
+uos.remove('test_file')
+uos.rename('test_file', 'test_file2')
+uos.rmdir('test_dir')
+print(uos.stat('test_file'))
+print(uos.statvfs('/test_mnt'))
+open('test_file')
+open('test_file', 'wb')
+
+# umount
+uos.umount('/test_mnt')
+uos.umount('/test_mnt2')
+
+# umount a non-existent mount point
+try:
+ uos.umount('/test_mnt')
+except OSError:
+ print('OSError')
+
+# root dir
+uos.mount(Filesystem(3), '/')
+print(uos.stat('/'))
+print(uos.statvfs('/'))
+print(uos.listdir())
+open('test')
+
+uos.mount(Filesystem(4), '/mnt')
+print(uos.listdir())
+print(uos.listdir('/mnt'))
+uos.chdir('/mnt')
+print(uos.listdir())
+
+# chdir to a subdir within root-mounted vfs, and then listdir
+uos.chdir('/subdir')
+print(uos.listdir())
+uos.chdir('/')
+
+uos.umount('/')
+print(uos.listdir('/'))
+uos.umount('/mnt')
diff --git a/tests/extmod/vfs_basic.py.exp b/tests/extmod/vfs_basic.py.exp
new file mode 100644
index 000000000..0ae2c2cc9
--- /dev/null
+++ b/tests/extmod/vfs_basic.py.exp
@@ -0,0 +1,60 @@
+(16384, 0, 0, 0, 0, 0, 0, 0, 0, 0)
+True
+/
+1 mount False False
+['test_mnt']
+('test_mnt', 16384, 0)
+StopIteration
+StopIteration
+1 ilistdir /
+['a1']
+1 ilistdir /
+['a1']
+2 mount True False
+['test_mnt', 'test_mnt2']
+2 ilistdir /
+['a2']
+3 mount False False
+OSError
+OSError
+OSError
+1 chdir /
+1 ilistdir
+['a1']
+1 getcwd
+/test_mntdir1
+1 mkdir test_dir
+1 remove test_file
+1 rename test_file test_file2
+1 rmdir test_dir
+1 stat test_file
+(1,)
+1 statvfs /
+(1,)
+1 open test_file r
+1 open test_file wb
+1 umount
+2 umount
+OSError
+3 mount False False
+(16384, 0, 0, 0, 0, 0, 0, 0, 0, 0)
+3 statvfs /
+(3,)
+3 ilistdir /
+['a3']
+3 open test r
+4 mount False False
+3 ilistdir /
+['mnt', 'a3']
+4 ilistdir /
+['a4']
+4 chdir /
+4 ilistdir
+['a4']
+3 chdir /subdir
+3 ilistdir
+['a3']
+3 chdir /
+3 umount
+['mnt']
+4 umount
diff --git a/tests/extmod/vfs_fat_fileio.py.exp b/tests/extmod/vfs_fat_fileio.py.exp
deleted file mode 100644
index a09442ae8..000000000
--- a/tests/extmod/vfs_fat_fileio.py.exp
+++ /dev/null
@@ -1,25 +0,0 @@
-<io.TextIOWrapper >
-True
-True
-True
-True
-hello!world!
-12
-h
-e
-True
-d
-hello!world!
-True
-True
-True
-True
-True
-b'data in file'
-True
-['sub_file.txt', 'file.txt']
-['foo_file.txt', 'foo_dir', 'moved-to-root.txt']
-['foo_file.txt', 'foo_dir', 'moved-to-root.txt']
-new text
-['moved-to-root.txt']
-ENOSPC: True
diff --git a/tests/extmod/vfs_fat_fileio1.py b/tests/extmod/vfs_fat_fileio1.py
new file mode 100644
index 000000000..d19df120b
--- /dev/null
+++ b/tests/extmod/vfs_fat_fileio1.py
@@ -0,0 +1,117 @@
+try:
+ import uerrno
+ try:
+ import uos_vfs as uos
+ open = uos.vfs_open
+ except ImportError:
+ import uos
+except ImportError:
+ print("SKIP")
+ raise SystemExit
+
+try:
+ uos.VfsFat
+except AttributeError:
+ print("SKIP")
+ raise SystemExit
+
+
+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(50)
+except MemoryError:
+ print("SKIP")
+ raise SystemExit
+
+uos.VfsFat.mkfs(bdev)
+vfs = uos.VfsFat(bdev)
+uos.mount(vfs, '/ramdisk')
+uos.chdir('/ramdisk')
+
+# file IO
+f = open("foo_file.txt", "w")
+print(str(f)[:17], str(f)[-1:])
+f.write("hello!")
+f.flush()
+f.close()
+f.close() # allowed
+try:
+ f.write("world!")
+except OSError as e:
+ print(e.args[0] == uerrno.EINVAL)
+
+try:
+ f.read()
+except OSError as e:
+ print(e.args[0] == uerrno.EINVAL)
+
+try:
+ f.flush()
+except OSError as e:
+ print(e.args[0] == uerrno.EINVAL)
+
+try:
+ open("foo_file.txt", "x")
+except OSError as e:
+ print(e.args[0] == uerrno.EEXIST)
+
+with open("foo_file.txt", "a") as f:
+ f.write("world!")
+
+with open("foo_file.txt") as f2:
+ print(f2.read())
+ print(f2.tell())
+
+ f2.seek(0, 0) # SEEK_SET
+ print(f2.read(1))
+
+ f2.seek(0, 1) # SEEK_CUR
+ print(f2.read(1))
+ try:
+ f2.seek(1, 1) # SEEK_END
+ except OSError as e:
+ print(e.args[0] == uerrno.EOPNOTSUPP)
+
+ f2.seek(-2, 2) # SEEK_END
+ print(f2.read(1))
+
+# using constructor of FileIO type to open a file
+# 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")
+
+try:
+ vfs.rmdir("foo_file.txt")
+except OSError as e:
+ print(e.args[0] == 20) # uerrno.ENOTDIR
+
+vfs.remove("foo_file.txt")
+print(list(vfs.ilistdir()))
diff --git a/tests/extmod/vfs_fat_fileio1.py.exp b/tests/extmod/vfs_fat_fileio1.py.exp
new file mode 100644
index 000000000..d777585cf
--- /dev/null
+++ b/tests/extmod/vfs_fat_fileio1.py.exp
@@ -0,0 +1,13 @@
+<io.TextIOWrapper >
+True
+True
+True
+True
+hello!world!
+12
+h
+e
+True
+d
+True
+[('foo_dir', 16384, 0)]
diff --git a/tests/extmod/vfs_fat_fileio.py b/tests/extmod/vfs_fat_fileio2.py
index f050d94e2..b5adb75c9 100644
--- a/tests/extmod/vfs_fat_fileio.py
+++ b/tests/extmod/vfs_fat_fileio2.py
@@ -1,11 +1,19 @@
-import sys
-import uos
-import uerrno
+try:
+ import uerrno
+ try:
+ import uos_vfs as uos
+ open = uos.vfs_open
+ except ImportError:
+ import uos
+except ImportError:
+ print("SKIP")
+ raise SystemExit
+
try:
uos.VfsFat
except AttributeError:
print("SKIP")
- sys.exit()
+ raise SystemExit
class RAMFS:
@@ -34,73 +42,15 @@ class RAMFS:
try:
- bdev = RAMFS(48)
+ bdev = RAMFS(50)
except MemoryError:
print("SKIP")
- sys.exit()
+ raise SystemExit
uos.VfsFat.mkfs(bdev)
-vfs = uos.VfsFat(bdev, "/ramdisk")
-
-# file IO
-f = vfs.open("foo_file.txt", "w")
-print(str(f)[:17], str(f)[-1:])
-f.write("hello!")
-f.flush()
-f.close()
-f.close() # allowed
-try:
- f.write("world!")
-except OSError as e:
- print(e.args[0] == uerrno.EINVAL)
-
-try:
- f.read()
-except OSError as e:
- print(e.args[0] == uerrno.EINVAL)
-
-try:
- f.flush()
-except OSError as e:
- print(e.args[0] == uerrno.EINVAL)
-
-try:
- vfs.open("foo_file.txt", "x")
-except OSError as e:
- print(e.args[0] == uerrno.EEXIST)
-
-with vfs.open("foo_file.txt", "a") as f:
- f.write("world!")
-
-with vfs.open("foo_file.txt") as f2:
- print(f2.read())
- print(f2.tell())
-
- f2.seek(0, 0) # SEEK_SET
- print(f2.read(1))
-
- f2.seek(0, 1) # SEEK_CUR
- print(f2.read(1))
- try:
- f2.seek(1, 1) # SEEK_END
- except OSError as e:
- print(e.args[0] == uerrno.EOPNOTSUPP)
-
- f2.seek(-2, 2) # SEEK_END
- 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())
-
-# dirs
-vfs.mkdir("foo_dir")
-
-try:
- vfs.rmdir("foo_file.txt")
-except OSError as e:
- print(e.args[0] == 20) # uerrno.ENOTDIR
+vfs = uos.VfsFat(bdev)
+uos.mount(vfs, '/ramdisk')
+uos.chdir('/ramdisk')
try:
vfs.mkdir("foo_dir")
@@ -118,18 +68,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,31 +89,30 @@ 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")
-print(vfs.listdir("foo_dir"))
+vfs.rename("foo_dir/file-in-dir.txt", "foo_dir/file.txt")
+print(list(vfs.ilistdir("foo_dir")))
vfs.rename("foo_dir/file.txt", "moved-to-root.txt")
-print(vfs.listdir())
+print(list(vfs.ilistdir()))
# 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:
+print(list(vfs.ilistdir()))
+with open("moved-to-root.txt") as f:
print(f.read())
# valid removes
vfs.remove("foo_dir/sub_file.txt")
-vfs.remove("foo_file.txt")
vfs.rmdir("foo_dir")
-print(vfs.listdir())
+print(list(vfs.ilistdir()))
# disk full
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_fileio2.py.exp b/tests/extmod/vfs_fat_fileio2.py.exp
new file mode 100644
index 000000000..118dee26b
--- /dev/null
+++ b/tests/extmod/vfs_fat_fileio2.py.exp
@@ -0,0 +1,11 @@
+True
+True
+True
+b'data in file'
+True
+[('sub_file.txt', 32768, 0), ('file.txt', 32768, 0)]
+[('foo_dir', 16384, 0), ('moved-to-root.txt', 32768, 0)]
+[('foo_dir', 16384, 0), ('moved-to-root.txt', 32768, 0)]
+new text
+[('moved-to-root.txt', 32768, 0)]
+ENOSPC: 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_more.py b/tests/extmod/vfs_fat_more.py
new file mode 100644
index 000000000..baec96787
--- /dev/null
+++ b/tests/extmod/vfs_fat_more.py
@@ -0,0 +1,116 @@
+import uerrno
+try:
+ try:
+ import uos_vfs as uos
+ open = uos.vfs_open
+ except ImportError:
+ import uos
+except ImportError:
+ print("SKIP")
+ raise SystemExit
+
+try:
+ uos.VfsFat
+except AttributeError:
+ print("SKIP")
+ raise SystemExit
+
+
+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(50)
+ bdev2 = RAMFS(50)
+except MemoryError:
+ print("SKIP")
+ raise SystemExit
+
+# first we umount any existing mount points the target may have
+try:
+ uos.umount('/')
+except OSError:
+ pass
+for path in uos.listdir('/'):
+ uos.umount('/' + path)
+
+uos.VfsFat.mkfs(bdev)
+uos.mount(bdev, '/')
+
+print(uos.getcwd())
+
+f = open('test.txt', 'w')
+f.write('hello')
+f.close()
+
+print(uos.listdir())
+print(uos.listdir('/'))
+print(uos.stat('')[:-3])
+print(uos.stat('/')[:-3])
+print(uos.stat('test.txt')[:-3])
+print(uos.stat('/test.txt')[:-3])
+
+f = open('/test.txt')
+print(f.read())
+f.close()
+
+uos.rename('test.txt', 'test2.txt')
+print(uos.listdir())
+uos.rename('test2.txt', '/test3.txt')
+print(uos.listdir())
+uos.rename('/test3.txt', 'test4.txt')
+print(uos.listdir())
+uos.rename('/test4.txt', '/test5.txt')
+print(uos.listdir())
+
+uos.mkdir('dir')
+print(uos.listdir())
+uos.mkdir('/dir2')
+print(uos.listdir())
+uos.mkdir('dir/subdir')
+print(uos.listdir('dir'))
+for exist in ('', '/', 'dir', '/dir', 'dir/subdir'):
+ try:
+ uos.mkdir(exist)
+ except OSError as er:
+ print('mkdir OSError', er.args[0] == 17) # EEXIST
+
+uos.chdir('/')
+print(uos.stat('test5.txt')[:-3])
+
+uos.VfsFat.mkfs(bdev2)
+uos.mount(bdev2, '/sys')
+print(uos.listdir())
+print(uos.listdir('sys'))
+print(uos.listdir('/sys'))
+
+uos.rmdir('dir2')
+uos.remove('test5.txt')
+print(uos.listdir())
+
+uos.umount('/')
+print(uos.getcwd())
+print(uos.listdir())
+print(uos.listdir('sys'))
diff --git a/tests/extmod/vfs_fat_more.py.exp b/tests/extmod/vfs_fat_more.py.exp
new file mode 100644
index 000000000..aaca3cc75
--- /dev/null
+++ b/tests/extmod/vfs_fat_more.py.exp
@@ -0,0 +1,28 @@
+/
+['test.txt']
+['test.txt']
+(16384, 0, 0, 0, 0, 0, 0)
+(16384, 0, 0, 0, 0, 0, 0)
+(32768, 0, 0, 0, 0, 0, 5)
+(32768, 0, 0, 0, 0, 0, 5)
+hello
+['test2.txt']
+['test3.txt']
+['test4.txt']
+['test5.txt']
+['test5.txt', 'dir']
+['test5.txt', 'dir', 'dir2']
+['subdir']
+mkdir OSError True
+mkdir OSError True
+mkdir OSError True
+mkdir OSError True
+mkdir OSError True
+(32768, 0, 0, 0, 0, 0, 5)
+['sys', 'test5.txt', 'dir', 'dir2']
+[]
+[]
+['sys', 'dir']
+/
+['sys']
+[]
diff --git a/tests/extmod/vfs_fat_oldproto.py b/tests/extmod/vfs_fat_oldproto.py
index 73983567d..ef4f1da78 100644
--- a/tests/extmod/vfs_fat_oldproto.py
+++ b/tests/extmod/vfs_fat_oldproto.py
@@ -1,13 +1,18 @@
-import sys
-import uos
-import uerrno
+try:
+ import uerrno
+ try:
+ import uos_vfs as uos
+ except ImportError:
+ import uos
+except ImportError:
+ print("SKIP")
+ raise SystemExit
+
try:
uos.VfsFat
- uos.vfs_mkfs
- uos.vfs_mount
except AttributeError:
print("SKIP")
- sys.exit()
+ raise SystemExit
class RAMFS_OLD:
@@ -34,30 +39,23 @@ class RAMFS_OLD:
try:
- bdev = RAMFS_OLD(48)
+ bdev = RAMFS_OLD(50)
except MemoryError:
print("SKIP")
- sys.exit()
+ raise SystemExit
-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!")
-print(vfs.listdir())
+print(list(vfs.ilistdir()))
with vfs.open("file.txt", "r") as f:
print(f.read())
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)
+print(list(vfs.ilistdir()))
diff --git a/tests/extmod/vfs_fat_oldproto.py.exp b/tests/extmod/vfs_fat_oldproto.py.exp
index 4120c277a..ab8338cbb 100644
--- a/tests/extmod/vfs_fat_oldproto.py.exp
+++ b/tests/extmod/vfs_fat_oldproto.py.exp
@@ -1,4 +1,3 @@
-['file.txt']
+[('file.txt', 32768, 0)]
hello!
[]
-True
diff --git a/tests/extmod/vfs_fat_ramdisk.py b/tests/extmod/vfs_fat_ramdisk.py
index 184672ff1..801c69786 100644
--- a/tests/extmod/vfs_fat_ramdisk.py
+++ b/tests/extmod/vfs_fat_ramdisk.py
@@ -1,11 +1,18 @@
-import sys
-import uos
-import uerrno
+try:
+ import uerrno
+ try:
+ import uos_vfs as uos
+ except ImportError:
+ import uos
+except ImportError:
+ print("SKIP")
+ raise SystemExit
+
try:
uos.VfsFat
except AttributeError:
print("SKIP")
- sys.exit()
+ raise SystemExit
class RAMFS:
@@ -34,22 +41,18 @@ class RAMFS:
try:
- bdev = RAMFS(48)
+ bdev = RAMFS(50)
except MemoryError:
print("SKIP")
- sys.exit()
+ raise SystemExit
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())
@@ -61,11 +64,10 @@ except OSError as e:
with vfs.open("foo_file.txt", "w") as f:
f.write("hello!")
-print(vfs.listdir())
+print(list(vfs.ilistdir()))
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)
@@ -73,7 +75,7 @@ print(b"hello!" in bdev.data)
vfs.mkdir("foo_dir")
vfs.chdir("foo_dir")
print("getcwd:", vfs.getcwd())
-print(vfs.listdir())
+print(list(vfs.ilistdir()))
with vfs.open("sub_file.txt", "w") as f:
f.write("subdir file")
@@ -86,16 +88,13 @@ 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)
+uos.umount(vfs)
+vfs = uos.VfsFat(bdev)
+print(list(vfs.ilistdir(b"")))
+
+# list a non-existent directory
try:
- vfs.getcwd()
+ vfs.ilistdir(b"no_exist")
except OSError as e:
- print(e.args[0] == uerrno.ENODEV)
-
-vfs = uos.VfsFat(bdev, "/ramdisk")
-print(vfs.listdir(b""))
+ print('ENOENT:', e.args[0] == uerrno.ENOENT)
diff --git a/tests/extmod/vfs_fat_ramdisk.py.exp b/tests/extmod/vfs_fat_ramdisk.py.exp
index 95d31f44c..ccd0f7134 100644
--- a/tests/extmod/vfs_fat_ramdisk.py.exp
+++ b/tests/extmod/vfs_fat_ramdisk.py.exp
@@ -1,19 +1,16 @@
True
True
+statvfs: (512, 512, 16, 16, 16, 0, 0, 0, 0, 255)
+getcwd: /
True
-statvfs: (512, 512, 38, 38, 38, 0, 0, 0, 0, 255)
-getcwd: /ramdisk
-True
-['foo_file.txt']
+[('foo_file.txt', 32768, 0)]
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
-[b'foo_file.txt', b'foo_dir']
+getcwd: /
+[(b'foo_file.txt', 32768, 0), (b'foo_dir', 16384, 0)]
+ENOENT: True
diff --git a/tests/extmod/websocket_basic.py b/tests/extmod/websocket_basic.py
new file mode 100644
index 000000000..9a80503a0
--- /dev/null
+++ b/tests/extmod/websocket_basic.py
@@ -0,0 +1,60 @@
+try:
+ import uio
+ import uerrno
+ import websocket
+except ImportError:
+ print("SKIP")
+ raise SystemExit
+
+# put raw data in the stream and do a websocket read
+def ws_read(msg, sz):
+ ws = websocket.websocket(uio.BytesIO(msg))
+ return ws.read(sz)
+
+# do a websocket write and then return the raw data from the stream
+def ws_write(msg, sz):
+ s = uio.BytesIO()
+ ws = websocket.websocket(s)
+ ws.write(msg)
+ s.seek(0)
+ return s.read(sz)
+
+# basic frame
+print(ws_read(b"\x81\x04ping", 4))
+print(ws_read(b"\x80\x04ping", 4)) # FRAME_CONT
+print(ws_write(b"pong", 6))
+
+# split frames are not supported
+# print(ws_read(b"\x01\x04ping", 4))
+
+# extended payloads
+print(ws_read(b'\x81~\x00\x80' + b'ping' * 32, 128))
+print(ws_write(b"pong" * 32, 132))
+
+# mask (returned data will be 'mask' ^ 'mask')
+print(ws_read(b"\x81\x84maskmask", 4))
+
+# close control frame
+s = uio.BytesIO(b'\x88\x00') # FRAME_CLOSE
+ws = websocket.websocket(s)
+print(ws.read(1))
+s.seek(2)
+print(s.read(4))
+
+# misc control frames
+print(ws_read(b"\x89\x00\x81\x04ping", 4)) # FRAME_PING
+print(ws_read(b"\x8a\x00\x81\x04pong", 4)) # FRAME_PONG
+
+# close method
+ws = websocket.websocket(uio.BytesIO())
+ws.close()
+
+# ioctl
+ws = websocket.websocket(uio.BytesIO())
+print(ws.ioctl(8)) # GET_DATA_OPTS
+print(ws.ioctl(9, 2)) # SET_DATA_OPTS
+print(ws.ioctl(9))
+try:
+ ws.ioctl(-1)
+except OSError as e:
+ print("ioctl: EINVAL:", e.args[0] == uerrno.EINVAL)
diff --git a/tests/extmod/websocket_basic.py.exp b/tests/extmod/websocket_basic.py.exp
new file mode 100644
index 000000000..2d7657b53
--- /dev/null
+++ b/tests/extmod/websocket_basic.py.exp
@@ -0,0 +1,14 @@
+b'ping'
+b'ping'
+b'\x81\x04pong'
+b'pingpingpingpingpingpingpingpingpingpingpingpingpingpingpingpingpingpingpingpingpingpingpingpingpingpingpingpingpingpingpingping'
+b'\x81~\x00\x80pongpongpongpongpongpongpongpongpongpongpongpongpongpongpongpongpongpongpongpongpongpongpongpongpongpongpongpongpongpongpongpong'
+b'\x00\x00\x00\x00'
+b''
+b'\x81\x02\x88\x00'
+b'ping'
+b'pong'
+0
+1
+2
+ioctl: EINVAL: True