Skip to content

Commit

Permalink
Replace deprecated hardware test for littlefs (#331)
Browse files Browse the repository at this point in the history
  • Loading branch information
PatrickKa authored Dec 7, 2024
2 parents 415e6a2 + 2d230c7 commit 1464829
Show file tree
Hide file tree
Showing 3 changed files with 104 additions and 99 deletions.
14 changes: 7 additions & 7 deletions Tests/HardwareTests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,6 @@ target_link_libraries(
)
add_watchdog_version_of(Eps)

add_program(FileSystem FileSystem.test.cpp)
target_link_libraries(
Sts1CobcSwTests_FileSystem PRIVATE rodos::rodos littlefs::littlefs Sts1CobcSw_FileSystem
Sts1CobcSwTests_RfLatchupDisablePin
)
add_watchdog_version_of(FileSystem)

add_program(Flash Flash.test.cpp)
target_link_libraries(
Sts1CobcSwTests_Flash PRIVATE rodos::rodos Sts1CobcSw_Periphery Sts1CobcSw_Serial
Expand Down Expand Up @@ -116,6 +109,13 @@ target_link_libraries(
)
add_watchdog_version_of(Gpio)

add_program(Littlefs Littlefs.test.cpp)
target_link_libraries(
Sts1CobcSwTests_Littlefs PRIVATE littlefs::littlefs rodos::rodos Sts1CobcSw_FileSystem
Sts1CobcSwTests_RfLatchupDisablePin Sts1CobcSwTests_Utility
)
add_watchdog_version_of(Littlefs)

add_program(Rf Rf.test.cpp)
target_link_libraries(
Sts1CobcSwTests_Rf PRIVATE rodos::rodos Sts1CobcSw_Periphery Sts1CobcSwTests_Utility
Expand Down
92 changes: 0 additions & 92 deletions Tests/HardwareTests/FileSystem.test.cpp

This file was deleted.

97 changes: 97 additions & 0 deletions Tests/HardwareTests/Littlefs.test.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
#include <Tests/HardwareTests/RfLatchupDisablePin.hpp>
#include <Tests/HardwareTests/Utility.hpp>

#include <Sts1CobcSw/FileSystem/LfsMemoryDevice.hpp>

#include <littlefs/lfs.h>

#include <rodos_no_using_namespace.h>

#include <cstddef>


namespace sts1cobcsw
{
using RODOS::PRINTF;


// The minimum required stack size is ~2540 bytes
constexpr std::size_t stackSize = 2600;


class LittlefsTest : public RODOS::StaticThread<stackSize>
{
public:
LittlefsTest() : StaticThread("LittlefsTest")
{
}


private:
auto init() -> void override
{
InitializeRfLatchupDisablePins();
fs::Initialize();
}


auto run() -> void override
{
EnableRfLatchupProtection();

PRINTF("\n\n");
PRINTF("littlefs test\n");

PRINTF("\n");
auto lfs = lfs_t{};
PRINTF("Formatting ...\n");
auto errorCode = lfs_format(&lfs, &fs::lfsConfig);
Check(errorCode == 0);
PRINTF("Mounting ...\n");
errorCode = lfs_mount(&lfs, &fs::lfsConfig);
Check(errorCode == 0);

PRINTF("\n");
auto const * directoryPath = "MyFolder";
PRINTF("Creating directory '%s' ...\n", directoryPath);
errorCode = lfs_mkdir(&lfs, directoryPath);
Check(errorCode == 0);

PRINTF("\n");
auto const * filePath = "MyFolder/MyFile";
PRINTF("Creating file '%s' ...\n", filePath);
auto file = lfs_file_t{};
errorCode = lfs_file_open(&lfs, &file, filePath, LFS_O_WRONLY | LFS_O_CREAT);
Check(errorCode == 0);
int number = 123;
PRINTF("Writing %d to file ...\n", number);
errorCode = lfs_file_write(&lfs, &file, &number, sizeof(number));
Check(errorCode == sizeof(number));
PRINTF("Closing file ...\n");
errorCode = lfs_file_close(&lfs, &file);
Check(errorCode == 0);

PRINTF("\n");
PRINTF("Unmounting ...\n");
errorCode = lfs_unmount(&lfs);
Check(errorCode == 0);
PRINTF("Mounting again ...\n");
errorCode = lfs_mount(&lfs, &fs::lfsConfig);
Check(errorCode == 0);

PRINTF("\n");
PRINTF("Opening file '%s' for reading ...\n", filePath);
errorCode = lfs_file_open(&lfs, &file, filePath, LFS_O_RDONLY);
Check(errorCode == 0);
int readNumber = 0;
PRINTF("Reading from file ...\n");
errorCode = lfs_file_read(&lfs, &file, &readNumber, sizeof(number));
Check(errorCode == sizeof(number));
PRINTF("Read number = %d == %d\n", readNumber, number);
Check(readNumber == number);
PRINTF("Closing file ...\n");
errorCode = lfs_file_close(&lfs, &file);
Check(errorCode == 0);
}
} littlefsTest;
}

0 comments on commit 1464829

Please sign in to comment.