summaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
-rw-r--r--tests/extmod/vfs_fat_mtime.py74
-rw-r--r--tests/extmod/vfs_fat_mtime.py.exp3
-rw-r--r--tests/extmod/vfs_fat_ramdisk.py2
-rw-r--r--tests/extmod/vfs_fat_ramdisk.py.exp2
-rw-r--r--tests/extmod/vfs_lfs_mtime.py9
-rw-r--r--tests/extmod/vfs_lfs_mtime.py.exp1
6 files changed, 88 insertions, 3 deletions
diff --git a/tests/extmod/vfs_fat_mtime.py b/tests/extmod/vfs_fat_mtime.py
new file mode 100644
index 0000000000..d8fd66b75f
--- /dev/null
+++ b/tests/extmod/vfs_fat_mtime.py
@@ -0,0 +1,74 @@
+# Test for VfsFat using a RAM device, mtime feature
+
+try:
+ import utime, uos
+
+ utime.time
+ utime.sleep
+ uos.VfsFat
+except (ImportError, AttributeError):
+ print("SKIP")
+ raise SystemExit
+
+
+class RAMBlockDevice:
+ ERASE_BLOCK_SIZE = 512
+
+ def __init__(self, blocks):
+ self.data = bytearray(blocks * self.ERASE_BLOCK_SIZE)
+
+ def readblocks(self, block, buf):
+ addr = block * self.ERASE_BLOCK_SIZE
+ for i in range(len(buf)):
+ buf[i] = self.data[addr + i]
+
+ def writeblocks(self, block, buf):
+ addr = block * self.ERASE_BLOCK_SIZE
+ for i in range(len(buf)):
+ self.data[addr + i] = buf[i]
+
+ def ioctl(self, op, arg):
+ if op == 4: # block count
+ return len(self.data) // self.ERASE_BLOCK_SIZE
+ if op == 5: # block size
+ return self.ERASE_BLOCK_SIZE
+
+
+def test(bdev, vfs_class):
+ print("test", vfs_class)
+
+ # Initial format of block device.
+ vfs_class.mkfs(bdev)
+
+ # construction
+ vfs = vfs_class(bdev)
+
+ # Create an empty file, should have a timestamp.
+ current_time = int(utime.time())
+ vfs.open("test1", "wt").close()
+
+ # Wait 2 seconds so mtime will increase (FAT has 2 second resolution).
+ utime.sleep(2)
+
+ # Create another empty file, should have a timestamp.
+ vfs.open("test2", "wt").close()
+
+ # Stat the files and check mtime is non-zero.
+ stat1 = vfs.stat("test1")
+ stat2 = vfs.stat("test2")
+ print(stat1[8] != 0, stat2[8] != 0)
+
+ # Check that test1 has mtime which matches time.time() at point of creation.
+ # TODO this currently fails on the unix port because FAT stores timestamps
+ # in localtime and stat() is UTC based.
+ # print(current_time - 1 <= stat1[8] <= current_time + 1)
+
+ # Check that test1 is older than test2.
+ print(stat1[8] < stat2[8])
+
+ # Unmount.
+ vfs.umount()
+
+
+bdev = RAMBlockDevice(50)
+test(bdev, uos.VfsFat)
diff --git a/tests/extmod/vfs_fat_mtime.py.exp b/tests/extmod/vfs_fat_mtime.py.exp
new file mode 100644
index 0000000000..55550b9834
--- /dev/null
+++ b/tests/extmod/vfs_fat_mtime.py.exp
@@ -0,0 +1,3 @@
+test <class 'VfsFat'>
+True True
+True
diff --git a/tests/extmod/vfs_fat_ramdisk.py b/tests/extmod/vfs_fat_ramdisk.py
index 5f758bf89c..9a68d94fed 100644
--- a/tests/extmod/vfs_fat_ramdisk.py
+++ b/tests/extmod/vfs_fat_ramdisk.py
@@ -63,7 +63,7 @@ with vfs.open("foo_file.txt", "w") as f:
f.write("hello!")
print(list(vfs.ilistdir()))
-print("stat root:", vfs.stat("/"))
+print("stat root:", vfs.stat("/")[:-3]) # timestamps differ across runs
print("stat file:", vfs.stat("foo_file.txt")[:-3]) # timestamps differ across runs
print(b"FOO_FILETXT" in bdev.data)
diff --git a/tests/extmod/vfs_fat_ramdisk.py.exp b/tests/extmod/vfs_fat_ramdisk.py.exp
index ef6cf1e72b..384fa64c76 100644
--- a/tests/extmod/vfs_fat_ramdisk.py.exp
+++ b/tests/extmod/vfs_fat_ramdisk.py.exp
@@ -4,7 +4,7 @@ statvfs: (512, 512, 16, 16, 16, 0, 0, 0, 0, 255)
getcwd: /
True
[('foo_file.txt', 32768, 0, 6)]
-stat root: (16384, 0, 0, 0, 0, 0, 0, 0, 0, 0)
+stat root: (16384, 0, 0, 0, 0, 0, 0)
stat file: (32768, 0, 0, 0, 0, 0, 6)
True
True
diff --git a/tests/extmod/vfs_lfs_mtime.py b/tests/extmod/vfs_lfs_mtime.py
index 0108076884..bacdd2246c 100644
--- a/tests/extmod/vfs_lfs_mtime.py
+++ b/tests/extmod/vfs_lfs_mtime.py
@@ -3,6 +3,7 @@
try:
import utime, uos
+ utime.time
utime.sleep
uos.VfsLfs2
except (ImportError, AttributeError):
@@ -46,6 +47,7 @@ def test(bdev, vfs_class):
vfs = vfs_class(bdev, mtime=True)
# Create an empty file, should have a timestamp.
+ current_time = int(utime.time())
vfs.open("test1", "wt").close()
# Wait 1 second so mtime will increase by at least 1.
@@ -54,10 +56,15 @@ def test(bdev, vfs_class):
# Create another empty file, should have a timestamp.
vfs.open("test2", "wt").close()
- # Stat the files and check that test1 is older than test2.
+ # Stat the files and check mtime is non-zero.
stat1 = vfs.stat("test1")
stat2 = vfs.stat("test2")
print(stat1[8] != 0, stat2[8] != 0)
+
+ # Check that test1 has mtime which matches time.time() at point of creation.
+ print(current_time <= stat1[8] <= current_time + 1)
+
+ # Check that test1 is older than test2.
print(stat1[8] < stat2[8])
# Wait 1 second so mtime will increase by at least 1.
diff --git a/tests/extmod/vfs_lfs_mtime.py.exp b/tests/extmod/vfs_lfs_mtime.py.exp
index 2e3d7491bc..cf6455c040 100644
--- a/tests/extmod/vfs_lfs_mtime.py.exp
+++ b/tests/extmod/vfs_lfs_mtime.py.exp
@@ -4,6 +4,7 @@ True True
True
True
True
+True
mtime=False
True
True