Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
tests/vfs_fat_ramdisk: Add test for VfsFat.
- Loading branch information
Paul Sokolovsky
committed
Feb 14, 2016
1 parent
e3c66a5
commit 0ee1d0f
Showing
2 changed files
with
49 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import sys | ||
import uos | ||
try: | ||
uos.VfsFat | ||
except AttributeError: | ||
print("SKIP") | ||
sys.exit() | ||
|
||
|
||
class RAMFS: | ||
def __init__(self, blocks): | ||
self.data = bytearray(blocks * 512) | ||
|
||
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*512+i] | ||
|
||
def writeblocks(self, n, buf): | ||
#print("writeblocks(%s, %x)" % (n, id(buf))) | ||
for i in range(len(buf)): | ||
self.data[n*512+i] = buf[i] | ||
|
||
def sync(self): | ||
pass | ||
|
||
def count(self): | ||
return len(self.data) // 512 | ||
|
||
|
||
bdev = RAMFS(48) | ||
uos.VfsFat.mkfs(bdev) | ||
|
||
assert b"FOO_FILETXT" not in bdev.data | ||
assert b"hello!" not in bdev.data | ||
|
||
vfs = uos.VfsFat(bdev, "/ramdisk") | ||
|
||
f = vfs.open("foo_file.txt", "w") | ||
f.write("hello!") | ||
f.close() | ||
|
||
f2 = vfs.open("foo_file.txt") | ||
print(f2.read()) | ||
f2.close() | ||
|
||
assert b"FOO_FILETXT" in bdev.data | ||
assert b"hello!" in bdev.data |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
hello! |