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:
Damien George 2024-10-24 17:54:30 +11:00
parent 120ac0f8d2
commit 1ec0c9b886

View File

@ -3,7 +3,7 @@
try:
import time, vfs
time.time
time.time_ns
time.sleep
vfs.VfsLfs2
except (ImportError, AttributeError):
@ -47,7 +47,8 @@ def test(bdev, vfs_class):
fs = vfs_class(bdev, mtime=True)
# 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()
# Wait 1 second so mtime will increase by at least 1.
@ -61,7 +62,7 @@ def test(bdev, vfs_class):
stat2 = fs.stat("test2")
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)
# Check that test1 is older than test2.