Skip to content

Commit

Permalink
Merge pull request #10 from gjwatney/microfsexp
Browse files Browse the repository at this point in the history
Microfsexp
  • Loading branch information
timcanham authored Mar 13, 2023
2 parents 501767a + 540fbee commit ab97c99
Show file tree
Hide file tree
Showing 6 changed files with 70 additions and 14 deletions.
3 changes: 1 addition & 2 deletions Os/MicroFs/MicroFs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -717,7 +717,6 @@ Status getFileSize(const char* path, FwSizeType& size) {

Status getFreeSpace(const char* path, FwSizeType& totalBytes, FwSizeType& freeBytes) {

FwNativeUIntType currFile = 0;
totalBytes = 0;
freeBytes = 0;

Expand All @@ -735,7 +734,7 @@ Status getFreeSpace(const char* path, FwSizeType& totalBytes, FwSizeType& freeBy
for (FwNativeUIntType currFile = 0; currFile < cfgPtr->bins[currBin].numFiles; currFile++) {
totalBytes += statePtr->dataSize;
freeBytes += (statePtr->dataSize - statePtr->currSize);
currFile++;
statePtr += 1;
}

}
Expand Down
4 changes: 4 additions & 0 deletions Os/MicroFs/test/ut/MicroFsTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ TEST(FileSystemOps, OneFileReadDirectory) {
tester.OneFileReadDirectory();
}

TEST(FileOps, OpenStressTest) {
Os::Tester tester;
tester.OpenStressTest();
}

int main(int argc, char **argv) {
::testing::InitGoogleTest(&argc, argv);
Expand Down
21 changes: 14 additions & 7 deletions Os/MicroFs/test/ut/MyRules.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,17 @@
{
printf("--> Rule: %s \n", this->name);

ASSERT_LE(this->numBins, Os::MAX_MICROFS_BINS);

state.testCfg.numBins = this->numBins;
state.testCfg.bins[0].fileSize = this->fileSize;
state.testCfg.bins[0].numFiles = this->numFiles;

for (U16 i=0; i < this->numBins; i++)
{
state.testCfg.bins[i].fileSize = this->fileSize;
state.testCfg.bins[i].numFiles = this->numFiles;
}

Os::MicroFsInit(state.testCfg,0, state.alloc);
Os::MicroFsInit(state.testCfg, 0, state.alloc);

}

Expand All @@ -54,9 +60,10 @@
//
// ------------------------------------------------------------------------------------------------------

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


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

Os::File::Status stat = state.f.open("/bin0/file0", Os::File::OPEN_CREATE);
Os::File::Status stat = state.f.open(this->filename, Os::File::OPEN_CREATE);
ASSERT_EQ(Os::File::OP_OK, stat);
}

Expand Down Expand Up @@ -340,7 +347,7 @@
COMMENT(msg.toChar());
numFiles = 10;

ASSERT_EQ(Os::FileSystem::NOT_DIR,
ASSERT_EQ(Os::FileSystem::INVALID_PATH,
Os::FileSystem::readDirectory(listDir.toChar(),1, files, numFiles));
}

4 changes: 3 additions & 1 deletion Os/MicroFs/test/ut/MyRules.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
// ----------------------------------------------------------------------

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

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

const char *filename;


};

Expand Down
51 changes: 47 additions & 4 deletions Os/MicroFs/test/ut/Tester.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,49 @@ namespace Os {
// Tests
// ----------------------------------------------------------------------

// ----------------------------------------------------------------------
// OpenStressTest
// ----------------------------------------------------------------------
void Tester ::
OpenStressTest()
{
const U16 NUMBER_BINS = 10;
const U16 NUMBER_FILES = 10;
const U16 FILE_SIZE = 100;
const U16 TOTAL_FILES = NUMBER_BINS * NUMBER_FILES;
clearFileBuffer();

// Instantiate the Rules
OpenFile* openFile[TOTAL_FILES];
InitFileSystem initFileSystem(NUMBER_BINS, FILE_SIZE, NUMBER_FILES);
Cleanup cleanup;

char fileName[TOTAL_FILES][20];

U16 fileIndex = 0;
for (U16 bin=0; bin < NUMBER_BINS; bin++)
{
for (U16 file=0; file < NUMBER_FILES; file++)
{
snprintf(fileName[fileIndex], 20, "/bin%d/file%d", bin, file);
fileIndex++;
}
}


// Run the Rules
initFileSystem.apply(*this);

for (U16 i = 0; i < TOTAL_FILES; i++)
{
openFile[i] = new OpenFile(fileName[i]);
openFile[i]->apply(*this);
}

cleanup.apply(*this);


}
// ----------------------------------------------------------------------
// InitTest
// ----------------------------------------------------------------------
Expand Down Expand Up @@ -62,7 +105,7 @@ namespace Os {
U32 fileSize = 100;
U32 numFiles = 1;
InitFileSystem initFileSystem(numBins, fileSize, numFiles);
OpenFile openFile;
OpenFile openFile("/bin0/file0");
ResetFile resetFile;
Cleanup cleanup;
WriteData writeData(fileSize, 0xFF);
Expand Down Expand Up @@ -93,7 +136,7 @@ namespace Os {
U32 fileSize = 100;
U32 numFiles = 1;
InitFileSystem initFileSystem(numBins, fileSize, numFiles);
OpenFile openFile;
OpenFile openFile("/bin0/file0");
ResetFile resetFile;
Cleanup cleanup;
WriteData writeData1(fileSize/2, 0x11);
Expand Down Expand Up @@ -124,7 +167,7 @@ namespace Os {
U32 fileSize = 100;
U32 numFiles = 1;
InitFileSystem initFileSystem(numBins, fileSize, numFiles);
OpenFile openFile;
OpenFile openFile("/bin0/file0");
ResetFile resetFile;
Cleanup cleanup;
WriteData writeData(fileSize, 0xFF);
Expand Down Expand Up @@ -155,7 +198,7 @@ namespace Os {
U32 fileSize = 100;
U32 numFiles = 1;
InitFileSystem initFileSystem(numBins, fileSize, numFiles);
OpenFile openFile;
OpenFile openFile("/bin0/file0");
Cleanup cleanup;
WriteData writeData(fileSize, 0xFF);
CloseFile closeFile;
Expand Down
1 change: 1 addition & 0 deletions Os/MicroFs/test/ut/Tester.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ namespace Os {
void OpenWriteTwiceReadOnceTest();
void OpenWriteOnceReadTwiceTest();
void OneFileReadDirectory();
void OpenStressTest();

// Helper functions
void clearFileBuffer();
Expand Down

0 comments on commit ab97c99

Please sign in to comment.