Skip to content

Commit

Permalink
Merge pull request #12 from gjwatney/microfsexp
Browse files Browse the repository at this point in the history
Microfsexp
  • Loading branch information
timcanham committed Mar 14, 2023
2 parents 10e3716 + 73181b9 commit cfdb74d
Show file tree
Hide file tree
Showing 5 changed files with 214 additions and 120 deletions.
9 changes: 9 additions & 0 deletions Os/MicroFs/test/ut/MicroFsTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include <Fw/Types/String.hpp>
#include "Tester.hpp"


TEST(Initialization, InitTest) {
Os::Tester tester;
tester.InitTest();
Expand Down Expand Up @@ -42,6 +43,14 @@ TEST(FileOps, OpenStressTest) {
tester.OpenStressTest();
}

#if 0

TEST(FileOps, OddTest) {
Os::Tester tester;
tester.OddTest();
}
#endif

int main(int argc, char **argv) {
::testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
Expand Down
111 changes: 59 additions & 52 deletions Os/MicroFs/test/ut/MyRules.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,9 @@
{
printf("--> Rule: %s %s\n", this->name, this->filename);

Os::File::Status stat = state.f.open(this->filename, Os::File::OPEN_CREATE);
I16 descIndex = state.getIndex(this->filename);
ASSERT_NE(descIndex, -1);
Os::File::Status stat = state.fileDesc[descIndex].open(this->filename, Os::File::OPEN_CREATE);
ASSERT_EQ(Os::File::OP_OK, stat);
}

Expand Down Expand Up @@ -127,11 +129,13 @@
//
// ------------------------------------------------------------------------------------------------------

Os::Tester::WriteData::WriteData(NATIVE_INT_TYPE size, U8 value) :
Os::Tester::WriteData::WriteData(const char *filename, NATIVE_INT_TYPE size, U8 value) :
STest::Rule<Os::Tester>("WriteData")
{
this->size = size;
this->value = value;
this->filename = filename;

}


Expand All @@ -149,23 +153,17 @@
{
printf("--> Rule: %s \n", this->name);

ASSERT_LE(state.curPtr + this->size, Tester::BUFFER_SIZE);
I32 descIndex = state.getIndex(this->filename);
ASSERT_NE(descIndex, -1);

ASSERT_LE(state.curPtr + this->size, Tester::FILE_SIZE);
memset(state.buffOut + state.curPtr, this->value, this->size);
NATIVE_INT_TYPE retSize = this->size;
Os::File::Status stat = state.f.write(state.buffOut + state.curPtr, retSize);
Os::File::Status stat = state.fileDesc[descIndex].write(state.buffOut + state.curPtr, retSize);
state.curPtr = state.curPtr + this->size;
ASSERT_EQ(stat, Os::File::OP_OK);
ASSERT_EQ(retSize, this->size);

#if 0
for (U16 i=0; i<Tester::BUFFER_SIZE; i++)
{
printf("%X ", state.buffOut[i]);
}
printf("\n");
#endif


}


Expand All @@ -177,10 +175,11 @@
//
// ------------------------------------------------------------------------------------------------------

Os::Tester::ReadData::ReadData(NATIVE_INT_TYPE size) :
Os::Tester::ReadData::ReadData(const char *filename, NATIVE_INT_TYPE size) :
STest::Rule<Os::Tester>("ReadData")
{
this->size = size;
this->filename = filename;
}


Expand All @@ -198,17 +197,20 @@
{
printf("--> Rule: %s \n", this->name);

I32 descIndex = state.getIndex(this->filename);
ASSERT_NE(descIndex, -1);

BYTE buffIn[state.testCfg.bins[0].fileSize];
NATIVE_INT_TYPE bufferSize = sizeof(buffIn);
memset(buffIn,0xA5,sizeof(buffIn));
ASSERT_LE(this->size, sizeof(buffIn));
NATIVE_INT_TYPE retSize = this->size;
Os::File::Status stat = state.f.read(buffIn, retSize);
Os::File::Status stat = state.fileDesc[descIndex].read(buffIn, retSize);
ASSERT_EQ(stat, Os::File::OP_OK);
ASSERT_EQ(retSize, this->size);

// Check the returned data
ASSERT_LE(state.curPtr + this->size, Tester::BUFFER_SIZE);
ASSERT_LE(state.curPtr + this->size, Tester::FILE_SIZE);
ASSERT_EQ(0,memcmp(buffIn, state.buffOut+state.curPtr, this->size));

}
Expand All @@ -222,9 +224,10 @@
//
// ------------------------------------------------------------------------------------------------------

Os::Tester::ResetFile::ResetFile() :
Os::Tester::ResetFile::ResetFile(const char *filename) :
STest::Rule<Os::Tester>("ResetFile")
{
this->filename = filename;
}


Expand All @@ -242,8 +245,11 @@
{
printf("--> Rule: %s \n", this->name);

I32 descIndex = state.getIndex(this->filename);
ASSERT_NE(descIndex, -1);

// seek back to beginning
ASSERT_EQ(Os::File::OP_OK, state.f.seek(0));
ASSERT_EQ(Os::File::OP_OK, state.fileDesc[descIndex].seek(0));
state.curPtr = 0;
}

Expand All @@ -256,9 +262,10 @@
//
// ------------------------------------------------------------------------------------------------------

Os::Tester::CloseFile::CloseFile() :
Os::Tester::CloseFile::CloseFile(const char *filename) :
STest::Rule<Os::Tester>("CloseFile")
{
this->filename = filename;
}


Expand All @@ -274,10 +281,12 @@
Os::Tester& state //!< The test state
)
{
printf("--> Rule: %s \n", this->name);
printf("--> Rule: %s %s\n", this->name, this->filename);

// close file
state.f.close();
I32 descIndex = state.getIndex(this->filename);
ASSERT_NE(descIndex, -1);
state.fileDesc[descIndex].close();
}


Expand All @@ -289,9 +298,11 @@
//
// ------------------------------------------------------------------------------------------------------

Os::Tester::Listings::Listings() :
Os::Tester::Listings::Listings(U16 numBins, U16 numFiles) :
STest::Rule<Os::Tester>("Listings")
{
this->numBins = numBins;
this->numFiles = numFiles;
}


Expand All @@ -311,44 +322,40 @@

Fw::String listDir;
Fw::String expectedFile;
Fw::String files[1];
U32 numFiles = 10; // oversize to check return
Fw::String bins[MAX_BINS];
Fw::String files[MAX_FILES_PER_BIN];
U32 totalBins = MAX_BINS + 1; // oversize to check return

COMMENT("Listing /");
listDir = "/";

// get root directory listing
ASSERT_EQ(Os::FileSystem::OP_OK,
Os::FileSystem::readDirectory(listDir.toChar(),1, files, numFiles));
ASSERT_EQ(1,numFiles);

expectedFile.format("/%s0", MICROFS_BIN_STRING);
ASSERT_EQ(0,strcmp(expectedFile.toChar(), files[0].toChar()));

// get file listing
listDir.format("/%s0",MICROFS_BIN_STRING);
Fw::String msg;
msg.format("Listing %s",listDir.toChar());
COMMENT(msg.toChar());
numFiles = 10;

ASSERT_EQ(Os::FileSystem::OP_OK,
Os::FileSystem::readDirectory(listDir.toChar(),1, files, numFiles));

expectedFile.format("/%s0/%s0",MICROFS_BIN_STRING,MICROFS_FILE_STRING);
printf("%s\n", expectedFile.toChar());
Os::FileSystem::readDirectory(listDir.toChar(), MAX_BINS, bins, totalBins));
ASSERT_EQ(this->numBins, totalBins);

ASSERT_EQ(0,strcmp(expectedFile.toChar(),files[0].toChar()));

// check nonexistent bin

listDir.format("/%s1",MICROFS_BIN_STRING);
msg.format("Listing nonexistent %s",listDir.toChar());
COMMENT(msg.toChar());
numFiles = 10;
for (U16 binIndex=0; binIndex < this->numBins; binIndex++)
{
printf("%s\n", bins[binIndex].toChar());
expectedFile.format("/%s%d", MICROFS_BIN_STRING, binIndex);
ASSERT_EQ(0,strcmp(expectedFile.toChar(), bins[binIndex].toChar()));
}

ASSERT_EQ(Os::FileSystem::INVALID_PATH,
Os::FileSystem::readDirectory(listDir.toChar(),1, files, numFiles));
U32 totalFiles = MAX_FILES_PER_BIN + 1; // oversize to check return
for (U16 binIndex=0; binIndex < this->numBins; binIndex++)
{
// get file listing
ASSERT_EQ(Os::FileSystem::OP_OK,
Os::FileSystem::readDirectory(bins[binIndex].toChar(), this->numFiles, files, totalFiles));
ASSERT_EQ(this->numFiles, totalFiles);
COMMENT(bins[binIndex].toChar());
for (U16 fileIndex=0; fileIndex < this->numFiles; fileIndex++)
{
printf("%s\n", files[fileIndex].toChar());
expectedFile.format("/%s%d/%s%d", MICROFS_BIN_STRING, binIndex, MICROFS_FILE_STRING, fileIndex);
ASSERT_EQ(0,strcmp(expectedFile.toChar(), files[fileIndex].toChar()));
}
}
}

// ------------------------------------------------------------------------------------------------------
Expand Down
19 changes: 14 additions & 5 deletions Os/MicroFs/test/ut/MyRules.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@
// ----------------------------------------------------------------------

//! Constructor
WriteData(NATIVE_INT_TYPE size, U8 value);
WriteData(const char *filename, NATIVE_INT_TYPE size, U8 value);

// ----------------------------------------------------------------------
// Public member functions
Expand All @@ -136,6 +136,7 @@

NATIVE_INT_TYPE size;
U8 value;
const char* filename;

};

Expand All @@ -154,7 +155,7 @@
// ----------------------------------------------------------------------

//! Constructor
ReadData(NATIVE_INT_TYPE size);
ReadData(const char *filename, NATIVE_INT_TYPE size);

// ----------------------------------------------------------------------
// Public member functions
Expand All @@ -171,6 +172,7 @@
);

NATIVE_INT_TYPE size;
const char *filename;

};

Expand All @@ -189,7 +191,7 @@
// ----------------------------------------------------------------------

//! Constructor
ResetFile();
ResetFile(const char *filename);

// ----------------------------------------------------------------------
// Public member functions
Expand All @@ -205,6 +207,8 @@
Os::Tester& state //!< The test state
);

const char *filename;

};


Expand All @@ -222,7 +226,7 @@
// ----------------------------------------------------------------------

//! Constructor
CloseFile();
CloseFile(const char *filename);

// ----------------------------------------------------------------------
// Public member functions
Expand All @@ -238,6 +242,8 @@
Os::Tester& state //!< The test state
);

const char *filename;

};


Expand All @@ -255,7 +261,7 @@
// ----------------------------------------------------------------------

//! Constructor
Listings();
Listings(U16 numBins, U16 numFiles);

// ----------------------------------------------------------------------
// Public member functions
Expand All @@ -271,6 +277,9 @@
Os::Tester& state //!< The test state
);

U16 numBins;
U16 numFiles;

};

// ------------------------------------------------------------------------------------------------------
Expand Down
Loading

0 comments on commit cfdb74d

Please sign in to comment.