worked on FAT stuff and tests
This commit is contained in:
@@ -11,7 +11,7 @@
|
||||
|
||||
|
||||
|
||||
TEST(TestCreat, structure) {
|
||||
TEST(TestCreate, structure) {
|
||||
|
||||
FAT32::FSHeader header;
|
||||
|
||||
@@ -35,7 +35,7 @@ TEST (TestCreat, writeRead) {
|
||||
TestDevice dev(size);
|
||||
BlockDev bDev(dev);
|
||||
FS fs(bDev, 0);
|
||||
fs.setup(size);
|
||||
fs.setup(size, true);
|
||||
|
||||
for (int i = 0; i < 64; ++i) {
|
||||
|
||||
@@ -45,7 +45,7 @@ TEST (TestCreat, writeRead) {
|
||||
const size_t sizeA = (size/4096+1) * 4096;
|
||||
std::cout << name << " - " << size << std::endl;
|
||||
|
||||
FAT32::FS<BlockDev>::File2 f = fs.getOrCreateFile(name);
|
||||
FAT32::FS<BlockDev>::File f = fs.getOrCreateFile(name);
|
||||
uint8_t* data = (uint8_t*)malloc(128 + i * 512);
|
||||
for (uint32_t j = 0; j < size; ++j) {data[j] = j;}
|
||||
uint32_t written = f.write(size, data);
|
||||
@@ -73,10 +73,10 @@ TEST (TestCreat, writeRead) {
|
||||
const size_t size = 128 + i * 512;
|
||||
const size_t sizeA = (size/4096+1) * 4096;
|
||||
|
||||
FAT32::DirEntryAt dea = di.nextUsable();
|
||||
FS::File2 f = fs.open2(dea);
|
||||
FAT32::DirHandle h = di.nextUsable();
|
||||
FS::File f = fs.open(h);
|
||||
|
||||
ASSERT_EQ(name, dea.getName());
|
||||
ASSERT_EQ(name, h.getName());
|
||||
ASSERT_EQ(name, f.getName());
|
||||
ASSERT_EQ(size, f.getSize());
|
||||
ASSERT_EQ(sizeA, f.getAllocatedSize());
|
||||
@@ -96,7 +96,46 @@ TEST (TestCreat, writeRead) {
|
||||
|
||||
}
|
||||
|
||||
TEST (TestCreate, getOrCreateFile) {
|
||||
TEST (TestCreat, init) {
|
||||
|
||||
using BlockDev = AccessHelper<TestDevice>;
|
||||
using FS = FAT32::FS<BlockDev>;
|
||||
|
||||
size_t size = 32*1024*1024;
|
||||
TestDevice dev(size);
|
||||
|
||||
// write non-zero data into the device's memory
|
||||
for (uint32_t i = 0; i < size; ++i) {dev.buf[i] = 0x55;}
|
||||
|
||||
BlockDev bDev(dev);
|
||||
|
||||
FS fs(bDev, 0);
|
||||
|
||||
// filesystem must not be considered valid, header contains only zeros
|
||||
ASSERT_FALSE(fs.isValid());
|
||||
|
||||
// initialize the filesystem
|
||||
fs.setup(size, true);
|
||||
|
||||
// must be considered valid now
|
||||
ASSERT_TRUE(fs.isValid());
|
||||
|
||||
// size indication must match 32 MiB
|
||||
ASSERT_EQ(size, fs.getSize());
|
||||
|
||||
// data size indication (32 MiB - FATs and reserved sectors)
|
||||
ASSERT_EQ(size - 81920, fs.getSizeForData());
|
||||
|
||||
// currently, one cluster (4096 bytes) is used (for the root dir)
|
||||
ASSERT_EQ(4096, fs.getSizeUsed());
|
||||
|
||||
// there MUST NOT be any valid entry in the root dir, as this is a new FS!
|
||||
FS::DirIterator di = fs.getRoot();
|
||||
ASSERT_FALSE(di.nextUsable().isValid());
|
||||
|
||||
}
|
||||
|
||||
TEST (TestCreat, getOrCreateFile) {
|
||||
|
||||
using BlockDev = AccessHelper<TestDevice>;
|
||||
using FS = FAT32::FS<BlockDev>;
|
||||
@@ -104,10 +143,22 @@ TEST (TestCreate, getOrCreateFile) {
|
||||
size_t size = 32*1024*1024;
|
||||
TestDevice dev(size);
|
||||
BlockDev bDev(dev);
|
||||
FS fs(bDev, 0);
|
||||
fs.setup(size);
|
||||
|
||||
FS::File2 f1 = fs.getOrCreateFile("test.txt");
|
||||
FS fs(bDev, 0);
|
||||
|
||||
// filesystem must not be considered valid, header contains only zeros
|
||||
ASSERT_FALSE(fs.isValid());
|
||||
|
||||
// initialize the filesystem
|
||||
fs.setup(size, true);
|
||||
|
||||
// must be considered valid now
|
||||
ASSERT_TRUE(fs.isValid());
|
||||
|
||||
// size indication must match 32 MB
|
||||
ASSERT_EQ(size, fs.getSize());
|
||||
|
||||
FS::File f1 = fs.getOrCreateFile("test.txt");
|
||||
ASSERT_EQ(0, f1.getSize());
|
||||
ASSERT_EQ(4096, f1.getAllocatedSize());
|
||||
ASSERT_EQ("test.txt", f1.getName());
|
||||
@@ -118,10 +169,76 @@ TEST (TestCreate, getOrCreateFile) {
|
||||
for (int i = 0; i < 128; ++i) {d1[i] = 1;}
|
||||
ASSERT_EQ(128, f1.write(128, d1));
|
||||
|
||||
FS::File2 f2 = fs.getOrCreateFile("test.txt");
|
||||
FS::File f2 = fs.getOrCreateFile("test.txt");
|
||||
|
||||
ASSERT_EQ(128, f2.getSize());
|
||||
ASSERT_EQ(128, f2.read(128, d2));
|
||||
for (uint32_t i = 0; i < 128; ++i) {ASSERT_EQ(d1[i], d2[i]);}
|
||||
|
||||
}
|
||||
|
||||
|
||||
template <typename FS, typename DirIter> void dumpStructure(FS& fs, DirIter dirIter) {
|
||||
|
||||
while(true) {
|
||||
auto h = dirIter.nextUsable();
|
||||
if (!h.isValid()) {return;}
|
||||
std::cout << h.getName() << std::endl;
|
||||
if (h.isDot()) {continue;}
|
||||
if (h.isDotDot()) {continue;}
|
||||
if (h.isDirectory()) {
|
||||
dumpStructure(fs, DirIter(fs, h));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
TEST (TestCreate, subfolders) {
|
||||
|
||||
using BlockDev = AccessHelper<TestDevice>;
|
||||
using FS = FAT32::FS<BlockDev>;
|
||||
|
||||
size_t size = 32*1024*1024;
|
||||
TestDevice dev(size);
|
||||
BlockDev bDev(dev);
|
||||
|
||||
FS fs(bDev, 0);
|
||||
fs.setup(size, true);
|
||||
|
||||
|
||||
|
||||
fs.mkdirs("/test1");
|
||||
fs.mkdirs("/test1/1");
|
||||
fs.mkdirs("/test1/2");
|
||||
fs.mkdirs("/test1/2/3");
|
||||
|
||||
fs.mkdirs("/test2/1/2/3");
|
||||
|
||||
fs.mkdirs("/test1/a/b");
|
||||
fs.mkdirs("/test2/x/y");
|
||||
|
||||
fs.getOrCreateFile("/hallo.txt");
|
||||
|
||||
fs.getOrCreateFile("/test1/x/y/z.txt");
|
||||
|
||||
fs.getOrCreateFile("/test3/a/bbbb.txt");
|
||||
|
||||
FAT32::DirHandle dh1a = fs.getHandle("/");
|
||||
FAT32::DirHandle dh1b = fs.getHandle("");
|
||||
FAT32::DirHandle dh2 = fs.getHandle("/test1");
|
||||
FAT32::DirHandle dh3 = fs.getHandle("/test1/1");
|
||||
|
||||
FS::DirIterator di(fs, 0);
|
||||
|
||||
ASSERT_EQ(2, dh1a.getFirstCluster()); ASSERT_TRUE(dh1a.isValid());
|
||||
ASSERT_EQ(2, dh1b.getFirstCluster()); ASSERT_TRUE(dh1b.isValid());
|
||||
ASSERT_EQ(3, dh2.getFirstCluster()); ASSERT_TRUE(dh2.isValid());
|
||||
ASSERT_EQ(4, dh3.getFirstCluster()); ASSERT_TRUE(dh3.isValid());
|
||||
|
||||
|
||||
dev.toFile("/tmp/ram/subdirs.fat32");
|
||||
// mount -t vfat /tmp/ram/subdirs.fat32 /mnt/fat/ && ls -l /mnt/fat/ && umount /mnt/fat
|
||||
|
||||
dumpStructure(fs, fs.getRoot());
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user