summaryrefslogtreecommitdiff
path: root/tests/extmod
diff options
context:
space:
mode:
authorScott Shawcroft <scott@chickadee.tech>2016-11-14 10:20:16 -0800
committerScott Shawcroft <scott@chickadee.tech>2016-11-14 11:10:07 -0800
commitbd368733625551b1071b91f6bb0876a1bfcf06ff (patch)
tree4de4cd659205655ee612555ecb03d223131cc481 /tests/extmod
parent722777c2a919cfe5ecb13185cad7b355b9cfb715 (diff)
parent5a1d63fc14dae788f705403a43c2d8639b7dd9cd (diff)
Merge tag 'v1.8.6'
ESP8266 port uses SDK 2.0, has more heap, has support for 512k devices This release brings some code size reductions to the core as well as more tests and improved coverage which is now at 94.3%. The time.ticks_diff(a, b) function has changed: the order of the arguments has been swapped so that it behaves like "a - b", and it can now return a negative number if "a" came before "b" (modulo the period of the ticks functions). For the ESP8266 port the Espressif SDK has been updated to 2.0.0, the heap has been increased from 28k to 36k, and there is support for 512k devices via "make 512k". upip is included by default as frozen bytecode. The network module now allows access-point reconnection without WiFi credentials, and exposes configuration for the station DHCP hostname. The DS18B20 driver now handles negative temperatures, and NeoPixel and APA102 drivers handle 4 bytes-per-pixel LEDs. For the CC3200 port there is now support for loading of precompiled .mpy files and threading now works properly with interrupts. A detailed list of changes follows. py core: - py.mk: automatically add frozen.c to source list if FROZEN_DIR is defined - be more specific with MP_DECLARE_CONST_FUN_OBJ macros - specialise builtin funcs to use separate type for fixed arg count - {modbuiltins,obj}: use MP_PYTHON_PRINTER where possible - modbuiltins: add builtin "slice", pointing to existing slice type - add "delattr" builtin, conditional on MICROPY_CPYTHON_COMPAT - sequence: fix reverse slicing of lists - fix null pointer dereference in mpz.c, fix missing va_end in warning.c - remove asserts that are always true in emitbc.c - fix wrong assumption that m_renew will not move if shrinking - change config default so m_malloc0 uses memset if GC not enabled - add MICROPY_FLOAT_CONST macro for defining float constants - move frozen bytecode Makefile rules from ports to common mk files - strip leading dirs from frozen mpy files, so any path can be used extmod: - vfs_fat_file: check fatfs f_sync() and f_close() returns for errors - vfs_fat_file: make file.close() a no-op if file already closed - utime_mphal: ticks_diff(): switch arg order, return signed value - utime_mphal: add MP_THREAD_GIL_EXIT/ENTER warppers for sleep functions - utime_mphal: implement ticks_add(), add to all maintained ports - utime_mphal: allow ticks functions period be configurable by a port lib: - utils/pyhelp.c: use mp_printf() instead of printf() - utils/pyexec: add mp_hal_set_interrupt_char() prototype - libm: move Thumb-specific sqrtf function to separate file drivers: - add "from micropython import const" when const is used tools: - upgrade upip to 1.1.4: fix error on unix when installing to non-existing absolute path - pip-micropython: remove deprecated wrapper tool - check_code_size.sh: code size validation script for CI - replace upip tarball with just source file, to make its inclusion as frozen modules in multiple ports less magic tests: - extmod/vfs_fat: improve VFS test coverage - basics/builtin_slice: add test for "slice" builtin name - basics: add test for builtin "delattr" - extmod/vfs_fat_fsusermount: improve fsusermount test coverage - extmod/vfs_fat_oldproto: test old block device protocol - basics/gc1: garbage collector threshold() coverage - extmod/uhashlib_sha1: coverage for SHA1 algorithm - extmod/uhashlib_sha256: rename sha256.py test - btree1: fix out of memory error running on esp8266 - extmod/ticks_diff: test for new semantics of ticks_diff() - extmod/framebuf1: test framebuffer pixel clear, and text function minimal port: - Makefile: split rule for firmware.bin generation unix port: - Makefile: remove references to deprecated pip-micropython - modtime: use ticks_diff() implementation from extmod/utime_mphal.c - mphalport.h: add warning of mp_hal_delay_ms() implementation - modtime: switch ticks/sleep_ms/us() to utime_mphal - fix symbol references for x86 Mac - replace upip tarball with just source file windows port: - enable utime_mphal following unix, define mp_hal_ticks_* - fix utime_mphal compilation for msvc - implement mp_hal_ticks_cpu in terms of QueryPerformanceCounter qemu-arm port: - exclude ticks_diff test for qemu-arm port - exclude extmod/vfs_fat_fileio.py test - exclude new vfs_fat tests - enable software floating point support, and float tests stmhal port: - modutime: refactor to use extmod's version of ticks_cpu - refactor pin usage to use mp_hal_pin API - led: refactor LED to use mp_hal_pin_output() init function - Makefile: use standard rules for frozen module generation - modutime: consistently convert to MP_ROM_QSTR/MP_ROM_PTR - enable SD power save (disable CLK on idle) cc3200 port: - use mp_raise_XXX helper functions to reduce code size - mods/pybspi: allow "write" arg of read/readinto to be positional - enable loading of precompiled .mpy files - fix thread mutex's so threading works with interrupts teensy port: - update to provide new mp_hal_pin_XXX functions following stmhal esp8266 port: - Makefile: use latest esptool.py flash size auto-detection - esp_init_data: auto-initialize system params with vendor SDK 2.0.0 - esp8266.ld: move help.o to iROM - esp8266.ld: move modmachine.o to iROM - esp8266.ld: move main.o to iROM - add MP_FASTCODE modifier to put a function to iRAM - main: mark nlr_jump_fail() as MP_FASTCODE - modules/webrepl: enforce only one concurrent WebREPL connection - etshal.h: add few more ESP8266 vendor lib prototypes - modesp: add flash_user_start() function - add support for building firmware version for 512K modules - scripts: make neopixel/apa102 handle 4bpp LEDs with common code - modutime: consistently convert to MP_ROM_QSTR/MP_ROM_PTR - modnetwork: config(): fix copy-paste error in setting "mac" - scripts/port_diag: add descriptions for esf_buf types - modnetwork.c: allows AP reconnection without WiFi credentials - main: bump heap size to 36K - etshal.h: add prototypes for SPIRead/SPIWrite/SPIEraseSector - etshal.h: adjust size of MD5_CTX structure - modules: fix negative temperature in ds18x20 driver - rename "machine" module implementation to use contemporary naming - rework webrepl_setup to run over wired REPL - espneopixel.c: solve glitching LED issues with cpu at 80MHz - include upip as a standard frozen bytecode module - update docs for esptool 1.2.1/SDK 2.0 (--flash_size=detect) - modnetwork.c: expose configuration for station DHCP hostname zephyr port: - implement utime module - use board/SoC values for startup banner based on Zephyr config - initial implementation of machine.Pin - zephyr_getchar: update for recent Zephyr refactor of console hooks - support time -> utime module "weaklink" - README: update for the current featureset, add more info - mpconfigport.h: move less important params to the bottom - Makefile: allow to adjust heap size from make command line - Makefile: update comments to the current state of affairs - Makefile: allow to override Zephyr config from make command line - Makefile: add minimal port - Makefile: add -fomit-frame-pointer to reduce code size - mphalport.h: update for new "unified" kernal API (sleep functions) docs: - machine.SPI: bring up to date with Hardware API, make vendor-neutral - machine.SPI: improve descriptions of xfer methods - library/builtins: add docs for delattr and slice - library/network: reword intro paragraph - library/network: typo fixes, consistent acronym capitalization - library/index: update TOCs so builtins sorted before modules - utime: document ticks_cpu() in more detail - utime: describe new semantics of ticks_diff() (signed ring arithmetics) - utime: add docs for ticks_add(), improvements for other ticks_*() - esp8266: update for new WebREPL setup procedure - */quickref.rst: use new semantics of ticks_diff() - library/machine.Pin: update Pin docs to align with new HW API travis: - integrate tools/check_code_size.sh - minimal: Use CROSS=1, for binary size check examples: - http_server_simplistic: add "not suitable for real use" note - hwapi: example showing best practices for HW API usage in apps - hwapi: add hwconfig for DragonBoard 410c
Diffstat (limited to 'tests/extmod')
-rw-r--r--tests/extmod/btree1.py2
-rw-r--r--tests/extmod/framebuf1.py15
-rw-r--r--tests/extmod/framebuf1.py.exp4
-rw-r--r--tests/extmod/ticks_diff.py33
-rw-r--r--tests/extmod/ticks_diff.py.exp1
-rw-r--r--tests/extmod/uhashlib_sha1.py22
-rw-r--r--tests/extmod/uhashlib_sha256.py (renamed from tests/extmod/sha256.py)0
-rw-r--r--tests/extmod/vfs_fat_fileio.py156
-rw-r--r--tests/extmod/vfs_fat_fileio.py.exp22
-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_oldproto.py63
-rw-r--r--tests/extmod/vfs_fat_oldproto.py.exp4
-rw-r--r--tests/extmod/vfs_fat_ramdisk.py63
-rw-r--r--tests/extmod/vfs_fat_ramdisk.py.exp14
15 files changed, 450 insertions, 52 deletions
diff --git a/tests/extmod/btree1.py b/tests/extmod/btree1.py
index 662983766..715f62824 100644
--- a/tests/extmod/btree1.py
+++ b/tests/extmod/btree1.py
@@ -9,7 +9,7 @@ except ImportError:
#f = open("_test.db", "w+b")
f = uio.BytesIO()
-db = btree.open(f)
+db = btree.open(f, pagesize=512)
db[b"foo3"] = b"bar3"
db[b"foo1"] = b"bar1"
diff --git a/tests/extmod/framebuf1.py b/tests/extmod/framebuf1.py
index f550b6b4f..52899028c 100644
--- a/tests/extmod/framebuf1.py
+++ b/tests/extmod/framebuf1.py
@@ -23,6 +23,10 @@ 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))
@@ -39,3 +43,14 @@ 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)
diff --git a/tests/extmod/framebuf1.py.exp b/tests/extmod/framebuf1.py.exp
index 8fd8c3709..1577faac8 100644
--- a/tests/extmod/framebuf1.py.exp
+++ b/tests/extmod/framebuf1.py.exp
@@ -1,9 +1,13 @@
bytearray(b'\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff')
bytearray(b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00')
bytearray(b'\x01\x00\x00\x00\x01\x80\x00\x00\x00\x80')
+bytearray(b'\x01\x00\x00\x00\x01\x80\x00\x00\x00\x00')
1 0
bytearray(b'\x00\x00\x00\x00\x00\x00\x00\x01\x00\x00')
bytearray(b'\x00\x00@\x00\x00\x00\x00\x00\x00\x00')
bytearray(b'\x00\x00\x00@\x00\x00\x00\x00\x00\x00')
bytearray(b'\x00\x00@\x00\x00\x00\x00\x00\x00\x00')
bytearray(b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01')
+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')
diff --git a/tests/extmod/ticks_diff.py b/tests/extmod/ticks_diff.py
new file mode 100644
index 000000000..4d8df83cf
--- /dev/null
+++ b/tests/extmod/ticks_diff.py
@@ -0,0 +1,33 @@
+from utime import ticks_diff, ticks_add
+
+MAX = ticks_add(0, -1)
+# Should be done like this to avoid small int overflow
+MODULO_HALF = MAX // 2 + 1
+
+# Invariants:
+# if ticks_diff(a, b) = c,
+# then ticks_diff(b, a) = -c
+
+assert ticks_diff(1, 0) == 1, ticks_diff(1, 0)
+assert ticks_diff(0, 1) == -1
+
+assert ticks_diff(0, MAX) == 1
+assert ticks_diff(MAX, 0) == -1
+
+assert ticks_diff(0, MAX - 1) == 2
+
+# Maximum "positive" distance
+assert ticks_diff(MODULO_HALF, 1) == MODULO_HALF - 1, ticks_diff(MODULO_HALF, 1)
+# Step further, and it becomes a negative distance
+assert ticks_diff(MODULO_HALF, 0) == -MODULO_HALF
+
+# Offsetting that in either direction doesn't affect the result
+off = 100
+# Cheating and skipping to use ticks_add() when we know there's no wraparound
+# Real apps should use always it.
+assert ticks_diff(MODULO_HALF + off, 1 + off) == MODULO_HALF - 1
+assert ticks_diff(MODULO_HALF + off, 0 + off) == -MODULO_HALF
+assert ticks_diff(MODULO_HALF - off, ticks_add(1, -off)) == MODULO_HALF - 1
+assert ticks_diff(MODULO_HALF - off, ticks_add(0, -off)) == -MODULO_HALF
+
+print("OK")
diff --git a/tests/extmod/ticks_diff.py.exp b/tests/extmod/ticks_diff.py.exp
new file mode 100644
index 000000000..d86bac9de
--- /dev/null
+++ b/tests/extmod/ticks_diff.py.exp
@@ -0,0 +1 @@
+OK
diff --git a/tests/extmod/uhashlib_sha1.py b/tests/extmod/uhashlib_sha1.py
new file mode 100644
index 000000000..f12fc649a
--- /dev/null
+++ b/tests/extmod/uhashlib_sha1.py
@@ -0,0 +1,22 @@
+import sys
+try:
+ import uhashlib as hashlib
+except ImportError:
+ try:
+ import hashlib
+ except ImportError:
+ # This is neither uPy, nor cPy, so must be uPy with
+ # uhashlib module disabled.
+ print("SKIP")
+ sys.exit()
+
+try:
+ hashlib.sha1
+except AttributeError:
+ # SHA1 is only available on some ports
+ print("SKIP")
+ sys.exit()
+
+sha1 = hashlib.sha1(b'hello')
+sha1.update(b'world')
+print(sha1.digest())
diff --git a/tests/extmod/sha256.py b/tests/extmod/uhashlib_sha256.py
index ff51f2ffa..ff51f2ffa 100644
--- a/tests/extmod/sha256.py
+++ b/tests/extmod/uhashlib_sha256.py
diff --git a/tests/extmod/vfs_fat_fileio.py b/tests/extmod/vfs_fat_fileio.py
new file mode 100644
index 000000000..de8d4953c
--- /dev/null
+++ b/tests/extmod/vfs_fat_fileio.py
@@ -0,0 +1,156 @@
+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()
+
+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))
+
+# dirs
+vfs.mkdir("foo_dir")
+
+try:
+ vfs.rmdir("foo_file.txt")
+except OSError as e:
+ print(e.args[0] == 20) # uerrno.ENOTDIR
+
+try:
+ vfs.mkdir("foo_dir")
+except OSError as e:
+ print(e.args[0] == uerrno.EEXIST)
+
+try:
+ vfs.remove("foo_dir")
+except OSError as e:
+ print(e.args[0] == uerrno.EISDIR)
+
+try:
+ vfs.remove("no_file.txt")
+except OSError as e:
+ print(e.args[0] == uerrno.ENOENT)
+
+try:
+ vfs.rename("foo_dir", "/null")
+except OSError as e:
+ print(e.args[0] == uerrno.ENODEV)
+
+# file in dir
+with vfs.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:
+ print(f.read())
+
+with vfs.open("foo_dir/sub_file.txt", "w") as f:
+ f.write("subdir file")
+
+# directory not empty
+try:
+ vfs.rmdir("foo_dir")
+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.txt", "moved-to-root.txt")
+print(vfs.listdir())
+
+# valid removes
+vfs.remove("foo_dir/sub_file.txt")
+vfs.remove("foo_file.txt")
+vfs.rmdir("foo_dir")
+print(vfs.listdir())
+
+# disk full
+try:
+ bsize = vfs.statvfs("/ramdisk")[0]
+ free = vfs.statvfs("/ramdisk")[2] + 1
+ f = vfs.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
new file mode 100644
index 000000000..c438bc850
--- /dev/null
+++ b/tests/extmod/vfs_fat_fileio.py.exp
@@ -0,0 +1,22 @@
+<io.TextIOWrapper >
+True
+True
+True
+True
+hello!world!
+12
+h
+e
+True
+d
+True
+True
+True
+True
+True
+b'data in file'
+True
+['sub_file.txt', 'file.txt']
+['foo_file.txt', 'foo_dir', 'moved-to-root.txt']
+['moved-to-root.txt']
+ENOSPC: True
diff --git a/tests/extmod/vfs_fat_fsusermount.py b/tests/extmod/vfs_fat_fsusermount.py
new file mode 100644
index 000000000..7326172ee
--- /dev/null
+++ b/tests/extmod/vfs_fat_fsusermount.py
@@ -0,0 +1,96 @@
+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
new file mode 100644
index 000000000..3b30688dd
--- /dev/null
+++ b/tests/extmod/vfs_fat_fsusermount.py.exp
@@ -0,0 +1,7 @@
+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
new file mode 100644
index 000000000..73983567d
--- /dev/null
+++ b/tests/extmod/vfs_fat_oldproto.py
@@ -0,0 +1,63 @@
+import sys
+import uos
+import uerrno
+try:
+ uos.VfsFat
+ uos.vfs_mkfs
+ uos.vfs_mount
+except AttributeError:
+ print("SKIP")
+ sys.exit()
+
+class RAMFS_OLD:
+
+ 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 sync(self):
+ pass
+
+ def count(self):
+ return len(self.data) // self.SEC_SIZE
+
+
+try:
+ bdev = RAMFS_OLD(48)
+except MemoryError:
+ print("SKIP")
+ sys.exit()
+
+uos.vfs_mkfs(bdev, "/ramdisk")
+uos.vfs_mount(bdev, "/ramdisk")
+
+# file io
+vfs = uos.VfsFat(bdev, "/ramdisk")
+with vfs.open("file.txt", "w") as f:
+ f.write("hello!")
+
+print(vfs.listdir())
+
+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)
diff --git a/tests/extmod/vfs_fat_oldproto.py.exp b/tests/extmod/vfs_fat_oldproto.py.exp
new file mode 100644
index 000000000..4120c277a
--- /dev/null
+++ b/tests/extmod/vfs_fat_oldproto.py.exp
@@ -0,0 +1,4 @@
+['file.txt']
+hello!
+[]
+True
diff --git a/tests/extmod/vfs_fat_ramdisk.py b/tests/extmod/vfs_fat_ramdisk.py
index 6380761c6..184672ff1 100644
--- a/tests/extmod/vfs_fat_ramdisk.py
+++ b/tests/extmod/vfs_fat_ramdisk.py
@@ -45,55 +45,38 @@ print(b"FOO_FILETXT" not in bdev.data)
print(b"hello!" not in bdev.data)
vfs = uos.VfsFat(bdev, "/ramdisk")
-print("statvfs:", vfs.statvfs("/ramdisk"))
-
-print("getcwd:", vfs.getcwd())
-
-f = vfs.open("foo_file.txt", "w")
-f.write("hello!")
-f.close()
-
-f2 = vfs.open("foo_file.txt")
-print(f2.read())
-f2.close()
-
-print(b"FOO_FILETXT" in bdev.data)
-print(b"hello!" in bdev.data)
-
-print(vfs.listdir())
try:
- vfs.rmdir("foo_file.txt")
+ vfs.statvfs("/null")
except OSError as e:
- print(e.args[0] == 20) # uerrno.ENOTDIR
-
-vfs.remove('foo_file.txt')
-print(vfs.listdir())
+ print(e.args[0] == uerrno.ENODEV)
-vfs.mkdir("foo_dir")
-print(vfs.listdir())
+print("statvfs:", vfs.statvfs("/ramdisk"))
+print("getcwd:", vfs.getcwd())
try:
- vfs.remove("foo_dir")
+ vfs.stat("no_file.txt")
except OSError as e:
- print(e.args[0] == uerrno.EISDIR)
+ print(e.args[0] == uerrno.ENOENT)
-f = vfs.open("foo_dir/file-in-dir.txt", "w")
-f.write("data in file")
-f.close()
+with vfs.open("foo_file.txt", "w") as f:
+ f.write("hello!")
+print(vfs.listdir())
-print(vfs.listdir("foo_dir"))
+print("stat root:", vfs.stat("/"))
+print("stat disk:", vfs.stat("/ramdisk/"))
+print("stat file:", vfs.stat("foo_file.txt"))
-vfs.rename("foo_dir/file-in-dir.txt", "moved-to-root.txt")
-print(vfs.listdir())
+print(b"FOO_FILETXT" in bdev.data)
+print(b"hello!" in bdev.data)
+vfs.mkdir("foo_dir")
vfs.chdir("foo_dir")
print("getcwd:", vfs.getcwd())
print(vfs.listdir())
with vfs.open("sub_file.txt", "w") as f:
- f.write("test2")
-print(vfs.listdir())
+ f.write("subdir file")
try:
vfs.chdir("sub_file.txt")
@@ -103,20 +86,16 @@ except OSError as e:
vfs.chdir("..")
print("getcwd:", vfs.getcwd())
+vfs.umount()
try:
- vfs.rmdir("foo_dir")
+ vfs.listdir()
except OSError as e:
- print(e.args[0] == uerrno.EACCES)
-
-vfs.remove("foo_dir/sub_file.txt")
-vfs.rmdir("foo_dir")
-print(vfs.listdir())
+ print(e.args[0] == uerrno.ENODEV)
-vfs.umount()
try:
- vfs.listdir()
+ vfs.getcwd()
except OSError as e:
print(e.args[0] == uerrno.ENODEV)
vfs = uos.VfsFat(bdev, "/ramdisk")
-print(vfs.listdir())
+print(vfs.listdir(b""))
diff --git a/tests/extmod/vfs_fat_ramdisk.py.exp b/tests/extmod/vfs_fat_ramdisk.py.exp
index 8a498b2fc..eaf637199 100644
--- a/tests/extmod/vfs_fat_ramdisk.py.exp
+++ b/tests/extmod/vfs_fat_ramdisk.py.exp
@@ -1,23 +1,19 @@
True
True
+True
statvfs: (512, 512, 14, 14, 14, 0, 0, 0, 0, 255)
getcwd: /ramdisk
-hello!
-True
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)
True
-[]
-['foo_dir']
True
-['file-in-dir.txt']
-['foo_dir', 'moved-to-root.txt']
getcwd: /ramdisk/foo_dir
[]
-['sub_file.txt']
True
getcwd: /ramdisk
True
-['moved-to-root.txt']
True
-['moved-to-root.txt']
+[b'foo_file.txt', b'foo_dir']