more tests added
This commit is contained in:
parent
d4e5919a21
commit
42578ba2ac
@ -24,7 +24,8 @@ ReturnValue_t Q7STestTask::performOneShotAction() {
|
|||||||
//testScratchApi();
|
//testScratchApi();
|
||||||
//testJsonLibDirect();
|
//testJsonLibDirect();
|
||||||
//testDummyParams();
|
//testDummyParams();
|
||||||
testFileSystemHandlerDirect();
|
FsOpCodes opCode = FsOpCodes::REMOVE_TMP_FILE;
|
||||||
|
testFileSystemHandlerDirect(opCode);
|
||||||
return TestTask::performOneShotAction();
|
return TestTask::performOneShotAction();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -130,11 +131,46 @@ void Q7STestTask::testDummyParams() {
|
|||||||
sif::info << "Test value 2 (\"blirb\" expected): " << test2 << std::endl;
|
sif::info << "Test value 2 (\"blirb\" expected): " << test2 << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Q7STestTask::testFileSystemHandlerDirect() {
|
void Q7STestTask::testFileSystemHandlerDirect(FsOpCodes opCode) {
|
||||||
auto fsHandler = ObjectManager::instance()->
|
auto fsHandler = ObjectManager::instance()->
|
||||||
get<FileSystemHandler>(objects::FILE_SYSTEM_HANDLER);
|
get<FileSystemHandler>(objects::FILE_SYSTEM_HANDLER);
|
||||||
if(fsHandler == nullptr) {
|
if(fsHandler == nullptr) {
|
||||||
sif::warning << "Q7STestTask::testFileSystemHandlerDirect: No FS handler running.."
|
sif::warning << "Q7STestTask::testFileSystemHandlerDirect: No FS handler running.."
|
||||||
<< std::endl;
|
<< std::endl;
|
||||||
}
|
}
|
||||||
|
FileSystemHandler::FsCommandCfg cfg;
|
||||||
|
switch(opCode) {
|
||||||
|
case(FsOpCodes::CREATE_EMPTY_FILE_IN_TMP): {
|
||||||
|
// No mount prefix, cause file is created in tmp
|
||||||
|
cfg.useMountPrefix = false;
|
||||||
|
sif::info << "Creating empty file in /tmp folder" << std::endl;
|
||||||
|
// Do not delete file, user can check existence in shell
|
||||||
|
fsHandler->createFile("/tmp", "test.txt", nullptr, 0, &cfg);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case(FsOpCodes::REMOVE_TMP_FILE): {
|
||||||
|
sif::info << "Deleting /tmp/test.txt sample file" << std::endl;
|
||||||
|
// No mount prefix, cause file is created in tmp
|
||||||
|
cfg.useMountPrefix = false;
|
||||||
|
if(not std::filesystem::exists("/tmp/test.txt")) {
|
||||||
|
// Creating sample file
|
||||||
|
sif::info << "Creating sample file /tmp/test.txt to delete" << std::endl;
|
||||||
|
fsHandler->createFile("/tmp", "test.txt", nullptr, 0, &cfg);
|
||||||
|
}
|
||||||
|
ReturnValue_t result = fsHandler->deleteFile("/tmp", "test.txt", &cfg);
|
||||||
|
if(result == HasReturnvaluesIF::RETURN_OK) {
|
||||||
|
sif::info << "File deleted successfully" << std::endl;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
sif::info << "File deletion failed!" << std::endl;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case(FsOpCodes::CREATE_DIR): {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case(FsOpCodes::REMOVE_DIR): {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -15,7 +15,14 @@ private:
|
|||||||
void testScratchApi();
|
void testScratchApi();
|
||||||
void testJsonLibDirect();
|
void testJsonLibDirect();
|
||||||
void testDummyParams();
|
void testDummyParams();
|
||||||
void testFileSystemHandlerDirect();
|
|
||||||
|
enum FsOpCodes {
|
||||||
|
CREATE_EMPTY_FILE_IN_TMP,
|
||||||
|
REMOVE_TMP_FILE,
|
||||||
|
CREATE_DIR,
|
||||||
|
REMOVE_DIR
|
||||||
|
};
|
||||||
|
void testFileSystemHandlerDirect(FsOpCodes opCode);
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -143,9 +143,15 @@ ReturnValue_t FileSystemHandler::appendToFile(const char *repositoryPath, const
|
|||||||
|
|
||||||
ReturnValue_t FileSystemHandler::createFile(const char *repositoryPath, const char *filename,
|
ReturnValue_t FileSystemHandler::createFile(const char *repositoryPath, const char *filename,
|
||||||
const uint8_t *data, size_t size, void *args) {
|
const uint8_t *data, size_t size, void *args) {
|
||||||
|
std::string fullPath;
|
||||||
|
bool useMountPrefix = true;
|
||||||
|
parseCfg(reinterpret_cast<FsCommandCfg*>(args), useMountPrefix);
|
||||||
|
if(useMountPrefix) {
|
||||||
|
fullPath += currentMountPrefix;
|
||||||
|
}
|
||||||
|
|
||||||
// A double slash between repo and filename should not be an issue, so add it in any case
|
// A double slash between repo and filename should not be an issue, so add it in any case
|
||||||
std::string fullPath = currentMountPrefix + std::string(repositoryPath) + "/" +
|
fullPath += std::string(repositoryPath) + "/" + std::string(filename);
|
||||||
std::string(filename);
|
|
||||||
if(std::filesystem::exists(fullPath)) {
|
if(std::filesystem::exists(fullPath)) {
|
||||||
return FILE_ALREADY_EXISTS;
|
return FILE_ALREADY_EXISTS;
|
||||||
}
|
}
|
||||||
@ -159,9 +165,15 @@ ReturnValue_t FileSystemHandler::createFile(const char *repositoryPath, const ch
|
|||||||
|
|
||||||
ReturnValue_t FileSystemHandler::deleteFile(const char *repositoryPath, const char *filename,
|
ReturnValue_t FileSystemHandler::deleteFile(const char *repositoryPath, const char *filename,
|
||||||
void *args) {
|
void *args) {
|
||||||
|
std::string fullPath;
|
||||||
|
bool useMountPrefix = true;
|
||||||
|
parseCfg(reinterpret_cast<FsCommandCfg*>(args), useMountPrefix);
|
||||||
|
if(useMountPrefix) {
|
||||||
|
fullPath += currentMountPrefix;
|
||||||
|
}
|
||||||
|
|
||||||
// A double slash between repo and filename should not be an issue, so add it in any case
|
// A double slash between repo and filename should not be an issue, so add it in any case
|
||||||
std::string fullPath = currentMountPrefix + std::string(repositoryPath) + "/" +
|
fullPath += std::string(repositoryPath) + "/" + std::string(filename);
|
||||||
std::string(filename);
|
|
||||||
if(not std::filesystem::exists(fullPath)) {
|
if(not std::filesystem::exists(fullPath)) {
|
||||||
return FILE_DOES_NOT_EXIST;
|
return FILE_DOES_NOT_EXIST;
|
||||||
}
|
}
|
||||||
@ -174,7 +186,14 @@ ReturnValue_t FileSystemHandler::deleteFile(const char *repositoryPath, const ch
|
|||||||
}
|
}
|
||||||
|
|
||||||
ReturnValue_t FileSystemHandler::createDirectory(const char *repositoryPath, void *args) {
|
ReturnValue_t FileSystemHandler::createDirectory(const char *repositoryPath, void *args) {
|
||||||
std::string fullPath = currentMountPrefix + std::string(repositoryPath);
|
std::string fullPath;
|
||||||
|
bool useMountPrefix = true;
|
||||||
|
parseCfg(reinterpret_cast<FsCommandCfg*>(args), useMountPrefix);
|
||||||
|
if(useMountPrefix) {
|
||||||
|
fullPath += currentMountPrefix;
|
||||||
|
}
|
||||||
|
|
||||||
|
fullPath += std::string(repositoryPath);
|
||||||
if(std::filesystem::exists(fullPath)) {
|
if(std::filesystem::exists(fullPath)) {
|
||||||
return DIRECTORY_ALREADY_EXISTS;
|
return DIRECTORY_ALREADY_EXISTS;
|
||||||
}
|
}
|
||||||
@ -187,7 +206,14 @@ ReturnValue_t FileSystemHandler::createDirectory(const char *repositoryPath, voi
|
|||||||
|
|
||||||
ReturnValue_t FileSystemHandler::removeDirectory(const char *repositoryPath,
|
ReturnValue_t FileSystemHandler::removeDirectory(const char *repositoryPath,
|
||||||
bool deleteRecurively, void *args) {
|
bool deleteRecurively, void *args) {
|
||||||
std::string fullPath = currentMountPrefix + std::string(repositoryPath);
|
std::string fullPath;
|
||||||
|
bool useMountPrefix = true;
|
||||||
|
parseCfg(reinterpret_cast<FsCommandCfg*>(args), useMountPrefix);
|
||||||
|
if(useMountPrefix) {
|
||||||
|
fullPath += currentMountPrefix;
|
||||||
|
}
|
||||||
|
|
||||||
|
fullPath += std::string(repositoryPath);
|
||||||
if(not std::filesystem::exists(fullPath)) {
|
if(not std::filesystem::exists(fullPath)) {
|
||||||
return DIRECTORY_DOES_NOT_EXIST;
|
return DIRECTORY_DOES_NOT_EXIST;
|
||||||
}
|
}
|
||||||
@ -217,3 +243,9 @@ ReturnValue_t FileSystemHandler::removeDirectory(const char *repositoryPath,
|
|||||||
|
|
||||||
return HasReturnvaluesIF::RETURN_OK;
|
return HasReturnvaluesIF::RETURN_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void FileSystemHandler::parseCfg(FsCommandCfg *cfg, bool& useMountPrefix) {
|
||||||
|
if(cfg != nullptr) {
|
||||||
|
useMountPrefix = cfg->useMountPrefix;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -15,6 +15,12 @@ class FileSystemHandler: public SystemObject,
|
|||||||
public ExecutableObjectIF,
|
public ExecutableObjectIF,
|
||||||
public HasFileSystemIF {
|
public HasFileSystemIF {
|
||||||
public:
|
public:
|
||||||
|
struct FsCommandCfg {
|
||||||
|
// Can be used to automatically use mount prefix of active SD card.
|
||||||
|
// Otherwise, the operator has to specify the full path to the mounted SD card as well.
|
||||||
|
bool useMountPrefix = false;
|
||||||
|
};
|
||||||
|
|
||||||
FileSystemHandler(object_id_t fileSystemHandler);
|
FileSystemHandler(object_id_t fileSystemHandler);
|
||||||
virtual~ FileSystemHandler();
|
virtual~ FileSystemHandler();
|
||||||
|
|
||||||
@ -28,17 +34,6 @@ public:
|
|||||||
*/
|
*/
|
||||||
MessageQueueId_t getCommandQueue() const override;
|
MessageQueueId_t getCommandQueue() const override;
|
||||||
|
|
||||||
private:
|
|
||||||
MessageQueueIF* mq = nullptr;
|
|
||||||
std::string currentMountPrefix = SdCardManager::SD_0_MOUNT_POINT;
|
|
||||||
static constexpr uint32_t FS_MAX_QUEUE_SIZE = config::OBSW_FILESYSTEM_HANDLER_QUEUE_SIZE;
|
|
||||||
|
|
||||||
SdCardManager* sdcMan = nullptr;
|
|
||||||
uint8_t opCounter = 0;
|
|
||||||
|
|
||||||
void fileSystemHandlerLoop();
|
|
||||||
void fileSystemCheckup();
|
|
||||||
|
|
||||||
ReturnValue_t appendToFile(const char* repositoryPath,
|
ReturnValue_t appendToFile(const char* repositoryPath,
|
||||||
const char* filename, const uint8_t* data, size_t size,
|
const char* filename, const uint8_t* data, size_t size,
|
||||||
uint16_t packetNumber, void* args = nullptr) override;
|
uint16_t packetNumber, void* args = nullptr) override;
|
||||||
@ -50,6 +45,18 @@ private:
|
|||||||
ReturnValue_t createDirectory(const char* repositoryPath, void* args = nullptr) override;
|
ReturnValue_t createDirectory(const char* repositoryPath, void* args = nullptr) override;
|
||||||
ReturnValue_t removeDirectory(const char* repositoryPath, bool deleteRecurively = false,
|
ReturnValue_t removeDirectory(const char* repositoryPath, bool deleteRecurively = false,
|
||||||
void* args = nullptr) override;
|
void* args = nullptr) override;
|
||||||
|
|
||||||
|
private:
|
||||||
|
MessageQueueIF* mq = nullptr;
|
||||||
|
std::string currentMountPrefix = SdCardManager::SD_0_MOUNT_POINT;
|
||||||
|
static constexpr uint32_t FS_MAX_QUEUE_SIZE = config::OBSW_FILESYSTEM_HANDLER_QUEUE_SIZE;
|
||||||
|
|
||||||
|
SdCardManager* sdcMan = nullptr;
|
||||||
|
uint8_t opCounter = 0;
|
||||||
|
|
||||||
|
void fileSystemHandlerLoop();
|
||||||
|
void fileSystemCheckup();
|
||||||
|
void parseCfg(FsCommandCfg* cfg, bool& useMountPrefix);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user