tests/extmod: Use time_ns instead of time in lfs mtime test.
Because VfsLfs2 uses time_ns to create timestamps for files, and for the test to give consistent results it also needs to use this same function. Signed-off-by: Damien George <damien@micropython.org>
This commit is contained in:
@@ -3,7 +3,7 @@
|
|||||||
try:
|
try:
|
||||||
import time, vfs
|
import time, vfs
|
||||||
|
|
||||||
time.time
|
time.time_ns
|
||||||
time.sleep
|
time.sleep
|
||||||
vfs.VfsLfs2
|
vfs.VfsLfs2
|
||||||
except (ImportError, AttributeError):
|
except (ImportError, AttributeError):
|
||||||
@@ -47,7 +47,8 @@ def test(bdev, vfs_class):
|
|||||||
fs = vfs_class(bdev, mtime=True)
|
fs = vfs_class(bdev, mtime=True)
|
||||||
|
|
||||||
# Create an empty file, should have a timestamp.
|
# Create an empty file, should have a timestamp.
|
||||||
current_time = int(time.time())
|
# Use time_ns() for current time because that's what's used for VfsLfs2 time.
|
||||||
|
current_time = time.time_ns() // 1_000_000_000
|
||||||
fs.open("test1", "wt").close()
|
fs.open("test1", "wt").close()
|
||||||
|
|
||||||
# Wait 1 second so mtime will increase by at least 1.
|
# Wait 1 second so mtime will increase by at least 1.
|
||||||
@@ -61,7 +62,7 @@ def test(bdev, vfs_class):
|
|||||||
stat2 = fs.stat("test2")
|
stat2 = fs.stat("test2")
|
||||||
print(stat1[8] != 0, stat2[8] != 0)
|
print(stat1[8] != 0, stat2[8] != 0)
|
||||||
|
|
||||||
# Check that test1 has mtime which matches time.time() at point of creation.
|
# Check that test1 has mtime which matches time.time_ns() at point of creation.
|
||||||
print(current_time <= stat1[8] <= current_time + 1)
|
print(current_time <= stat1[8] <= current_time + 1)
|
||||||
|
|
||||||
# Check that test1 is older than test2.
|
# Check that test1 is older than test2.
|
||||||
|
|||||||
Reference in New Issue
Block a user