fix test task
Some checks are pending
EIVE/eive-obsw/pipeline/head Build started...

This commit is contained in:
Robin Müller 2022-05-03 11:39:12 +02:00
parent 08d7b3b859
commit c131c685a4
No known key found for this signature in database
GPG Key ID: 71B58F8A3CDFA9AC
2 changed files with 159 additions and 178 deletions

View File

@ -23,7 +23,7 @@
Q7STestTask::Q7STestTask(object_id_t objectId) : TestTask(objectId) { Q7STestTask::Q7STestTask(object_id_t objectId) : TestTask(objectId) {
doTestSdCard = false; doTestSdCard = false;
doTestScratchApi = false; doTestScratchApi = false;
doTestGpsShm = true; doTestGpsShm = false;
doTestGpsSocket = false; doTestGpsSocket = false;
doTestXadc = false; doTestXadc = false;
} }
@ -156,13 +156,13 @@ void Q7STestTask::testDummyParams() {
result = param.getValue<int>(DummyParameter::DUMMY_KEY_PARAM_1, test); result = param.getValue<int>(DummyParameter::DUMMY_KEY_PARAM_1, test);
if (result != HasReturnvaluesIF::RETURN_OK) { if (result != HasReturnvaluesIF::RETURN_OK) {
sif::warning << "Q7STestTask::testDummyParams: Key " << DummyParameter::DUMMY_KEY_PARAM_1 sif::warning << "Q7STestTask::testDummyParams: Key " << DummyParameter::DUMMY_KEY_PARAM_1
<< " does not exist" << std::endl; << " does not exist" << std::endl;
} }
std::string test2; std::string test2;
result = param.getValue<std::string>(DummyParameter::DUMMY_KEY_PARAM_2, test2); result = param.getValue<std::string>(DummyParameter::DUMMY_KEY_PARAM_2, test2);
if (result != HasReturnvaluesIF::RETURN_OK) { if (result != HasReturnvaluesIF::RETURN_OK) {
sif::warning << "Q7STestTask::testDummyParams: Key " << DummyParameter::DUMMY_KEY_PARAM_1 sif::warning << "Q7STestTask::testDummyParams: Key " << DummyParameter::DUMMY_KEY_PARAM_1
<< " does not exist" << std::endl; << " does not exist" << std::endl;
} }
sif::info << "Test value (3 expected): " << test << std::endl; sif::info << "Test value (3 expected): " << test << std::endl;
sif::info << "Test value 2 (\"blirb\" expected): " << test2 << std::endl; sif::info << "Test value 2 (\"blirb\" expected): " << test2 << std::endl;
@ -172,7 +172,7 @@ ReturnValue_t Q7STestTask::initialize() {
coreController = ObjectManager::instance()->get<CoreController>(objects::CORE_CONTROLLER); coreController = ObjectManager::instance()->get<CoreController>(objects::CORE_CONTROLLER);
if (coreController == nullptr) { if (coreController == nullptr) {
sif::warning << "Q7STestTask::initialize: Could not retrieve CORE_CONTROLLER object" sif::warning << "Q7STestTask::initialize: Could not retrieve CORE_CONTROLLER object"
<< std::endl; << std::endl;
} }
return TestTask::initialize(); return TestTask::initialize();
} }
@ -182,14 +182,14 @@ void Q7STestTask::testProtHandler() {
ReturnValue_t result = HasReturnvaluesIF::RETURN_OK; ReturnValue_t result = HasReturnvaluesIF::RETURN_OK;
// If any chips are unlocked, lock them here // If any chips are unlocked, lock them here
result = coreController->setBootCopyProtection(xsc::Chip::ALL_CHIP, xsc::Copy::ALL_COPY, true, result = coreController->setBootCopyProtection(xsc::Chip::ALL_CHIP, xsc::Copy::ALL_COPY, true,
opPerformed, true); opPerformed, true);
if (result != HasReturnvaluesIF::RETURN_OK) { if (result != HasReturnvaluesIF::RETURN_OK) {
sif::warning << "Q7STestTask::testProtHandler: Op failed" << std::endl; sif::warning << "Q7STestTask::testProtHandler: Op failed" << std::endl;
} }
// unlock own copy // unlock own copy
result = coreController->setBootCopyProtection(xsc::Chip::SELF_CHIP, xsc::Copy::SELF_COPY, false, result = coreController->setBootCopyProtection(xsc::Chip::SELF_CHIP, xsc::Copy::SELF_COPY, false,
opPerformed, true); opPerformed, true);
if (result != HasReturnvaluesIF::RETURN_OK) { if (result != HasReturnvaluesIF::RETURN_OK) {
sif::warning << "Q7STestTask::testProtHandler: Op failed" << std::endl; sif::warning << "Q7STestTask::testProtHandler: Op failed" << std::endl;
} }
@ -203,7 +203,7 @@ void Q7STestTask::testProtHandler() {
// lock own copy // lock own copy
result = coreController->setBootCopyProtection(xsc::Chip::SELF_CHIP, xsc::Copy::SELF_COPY, true, result = coreController->setBootCopyProtection(xsc::Chip::SELF_CHIP, xsc::Copy::SELF_COPY, true,
opPerformed, true); opPerformed, true);
if (result != HasReturnvaluesIF::RETURN_OK) { if (result != HasReturnvaluesIF::RETURN_OK) {
sif::warning << "Q7STestTask::testProtHandler: Op failed" << std::endl; sif::warning << "Q7STestTask::testProtHandler: Op failed" << std::endl;
} }
@ -217,7 +217,7 @@ void Q7STestTask::testProtHandler() {
// unlock specific copy // unlock specific copy
result = coreController->setBootCopyProtection(xsc::Chip::CHIP_1, xsc::Copy::COPY_1, false, result = coreController->setBootCopyProtection(xsc::Chip::CHIP_1, xsc::Copy::COPY_1, false,
opPerformed, true); opPerformed, true);
if (result != HasReturnvaluesIF::RETURN_OK) { if (result != HasReturnvaluesIF::RETURN_OK) {
sif::warning << "Q7STestTask::testProtHandler: Op failed" << std::endl; sif::warning << "Q7STestTask::testProtHandler: Op failed" << std::endl;
} }
@ -231,7 +231,7 @@ void Q7STestTask::testProtHandler() {
// lock specific copy // lock specific copy
result = coreController->setBootCopyProtection(xsc::Chip::CHIP_1, xsc::Copy::COPY_1, true, result = coreController->setBootCopyProtection(xsc::Chip::CHIP_1, xsc::Copy::COPY_1, true,
opPerformed, true); opPerformed, true);
if (result != HasReturnvaluesIF::RETURN_OK) { if (result != HasReturnvaluesIF::RETURN_OK) {
sif::warning << "Q7STestTask::testProtHandler: Op failed" << std::endl; sif::warning << "Q7STestTask::testProtHandler: Op failed" << std::endl;
} }
@ -273,94 +273,73 @@ void Q7STestTask::testGpsDaemonShm() {
} }
void Q7STestTask::testGpsDaemonSocket() { void Q7STestTask::testGpsDaemonSocket() {
gpsmm gpsmm("localhost", DEFAULT_GPSD_PORT); if(gpsmmPtr == nullptr) {
gpsmmPtr = new gpsmm("localhost", DEFAULT_GPSD_PORT);
}
// The data from the device will generally be read all at once. Therefore, we // The data from the device will generally be read all at once. Therefore, we
// can set all field here // can set all field here
if (not gpsmm.is_open()) { if (not gpsmmPtr->is_open()) {
if (gpsNotOpenSwitch) { if (gpsNotOpenSwitch) {
// Opening failed // Opening failed
#if FSFW_VERBOSE_LEVEL >= 1 #if FSFW_VERBOSE_LEVEL >= 1
sif::warning << "Q7STestTask::testGpsDaemonSocket: Opening GPSMM failed | " sif::warning << "Q7STestTask::testGpsDaemonSocket: Opening GPSMM failed | "
<< "Error " << errno << " | " << gps_errstr(errno) << std::endl; << "Error " << errno << " | " << gps_errstr(errno) << std::endl;
#endif #endif
gpsNotOpenSwitch = false; gpsNotOpenSwitch = false;
} }
return; return;
} }
for (;;) { // Stopwatch watch;
struct gps_data_t* gps; gps_data_t *gps = nullptr;
gpsmmPtr->stream(WATCH_ENABLE | WATCH_JSON);
if (!gpsmm.waiting(50000000)) continue; if(not gpsmmPtr->waiting(50000000)) {
return;
if ((gps = gpsmm.read()) == NULL) {
std::cerr << "Read error.\n";
} else {
sif::info << "-- Q7STestTask: GPS socket read test --" << std::endl;
#if LIBGPS_VERSION_MINOR <= 17
time_t timeRaw = gps->fix.time;
#else
time_t timeRaw = gps->fix.time.tv_sec;
#endif
std::tm* time = gmtime(&timeRaw);
sif::info << "Time: " << std::put_time(time, "%c %Z") << std::endl;
sif::info << "Visible satellites: " << gps->satellites_visible << std::endl;
sif::info << "Satellites used: " << gps->satellites_used << std::endl;
sif::info << "Fix (0:Not Seen|1:No Fix|2:2D|3:3D): " << gps->fix.mode << std::endl;
sif::info << "Latitude: " << gps->fix.latitude << std::endl;
sif::info << "Longitude: " << gps->fix.longitude << std::endl;
}
} }
// // Stopwatch watch; gps = gpsmmPtr->read();
// gps_data_t *gps = nullptr; if (gps == nullptr) {
// gpsmm.stream(WATCH_ENABLE | WATCH_JSON); if (gpsReadFailedSwitch) {
// if(not gpsmm.waiting(50000000)) { gpsReadFailedSwitch = false;
// return; sif::warning << "Q7STestTask::testGpsDaemonSocket: Reading GPS data failed"
// } << std::endl;
// gps = gpsmm.read(); }
// if (gps == nullptr) { return;
// if (gpsReadFailedSwitch) { }
// gpsReadFailedSwitch = false; if (MODE_SET != (MODE_SET & gps->set)) {
// sif::warning << "Q7STestTask::testGpsDaemonSocket: Reading GPS data failed" if (noModeSetCntr >= 0) {
// << std::endl; noModeSetCntr++;
// } }
// return; if (noModeSetCntr == 10) {
// } // TODO: Trigger event here
// if (MODE_SET != (MODE_SET & gps->set)) { sif::warning << "Q7STestTask::testGpsDaemonSocket: No mode could be "
// if (noModeSetCntr >= 0) { "read for 10 consecutive reads"
// noModeSetCntr++; << std::endl;
// } noModeSetCntr = -1;
// if (noModeSetCntr == 10) { }
// // TODO: Trigger event here return;
// sif::warning << "Q7STestTask::testGpsDaemonSocket: No mode could be " } else {
// "read for 10 consecutive reads" noModeSetCntr = 0;
// << std::endl; }
// noModeSetCntr = -1; sif::info << "-- Q7STestTask: GPS socket read test --" << std::endl;
// } #if LIBGPS_VERSION_MINOR <= 17
// return; time_t timeRaw = gps->fix.time;
// } else { #else
// noModeSetCntr = 0; time_t timeRaw = gps->fix.time.tv_sec;
// } #endif
// sif::info << "-- Q7STestTask: GPS socket read test --" << std::endl; std::tm* time = gmtime(&timeRaw);
//#if LIBGPS_VERSION_MINOR <= 17 sif::info << "Time: " << std::put_time(time, "%c %Z") << std::endl;
// time_t timeRaw = gps->fix.time; sif::info << "Visible satellites: " << gps->satellites_visible << std::endl;
//#else sif::info << "Satellites used: " << gps->satellites_used << std::endl;
// time_t timeRaw = gps->fix.time.tv_sec; sif::info << "Fix (0:Not Seen|1:No Fix|2:2D|3:3D): " << gps->fix.mode << std::endl;
//#endif sif::info << "Latitude: " << gps->fix.latitude << std::endl;
// std::tm* time = gmtime(&timeRaw); sif::info << "Longitude: " << gps->fix.longitude << std::endl;
// sif::info << "Time: " << std::put_time(time, "%c %Z") << std::endl;
// sif::info << "Visible satellites: " << gps->satellites_visible << std::endl;
// sif::info << "Satellites used: " << gps->satellites_used << std::endl;
// sif::info << "Fix (0:Not Seen|1:No Fix|2:2D|3:3D): " << gps->fix.mode << std::endl;
// sif::info << "Latitude: " << gps->fix.latitude << std::endl;
// sif::info << "Longitude: " << gps->fix.longitude << std::endl;
} }
void Q7STestTask::testFileSystemHandlerDirect(FsOpCodes opCode) { void Q7STestTask::testFileSystemHandlerDirect(FsOpCodes opCode) {
auto fsHandler = ObjectManager::instance()->get<FileSystemHandler>(objects::FILE_SYSTEM_HANDLER); auto fsHandler = ObjectManager::instance()->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 = {}; FileSystemHandler::FsCommandCfg cfg = {};
ReturnValue_t result = HasReturnvaluesIF::RETURN_OK; ReturnValue_t result = HasReturnvaluesIF::RETURN_OK;
@ -387,115 +366,115 @@ void Q7STestTask::testFileSystemHandlerDirect(FsOpCodes opCode) {
}; };
switch (opCode) { switch (opCode) {
case (FsOpCodes::CREATE_EMPTY_FILE_IN_TMP): { case (FsOpCodes::CREATE_EMPTY_FILE_IN_TMP): {
// No mount prefix, cause file is created in tmp // No mount prefix, cause file is created in tmp
cfg.useMountPrefix = false; cfg.useMountPrefix = false;
sif::info << "Creating empty file in /tmp folder" << std::endl; sif::info << "Creating empty file in /tmp folder" << std::endl;
// Do not delete file, user can check existence in shell // 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); fsHandler->createFile("/tmp/", "test.txt", nullptr, 0, &cfg);
break;
} }
case (FsOpCodes::REMOVE_TMP_FILE): { result = fsHandler->removeFile("/tmp", "test.txt", &cfg);
sif::info << "Deleting /tmp/test.txt sample file" << std::endl; if (result == HasReturnvaluesIF::RETURN_OK) {
// No mount prefix, cause file is created in tmp sif::info << "File removed successfully" << std::endl;
cfg.useMountPrefix = false; } else {
if (not std::filesystem::exists("/tmp/test.txt")) { sif::warning << "File removal failed!" << std::endl;
// Creating sample file
sif::info << "Creating sample file /tmp/test.txt to delete" << std::endl;
fsHandler->createFile("/tmp/", "test.txt", nullptr, 0, &cfg);
}
result = fsHandler->removeFile("/tmp", "test.txt", &cfg);
if (result == HasReturnvaluesIF::RETURN_OK) {
sif::info << "File removed successfully" << std::endl;
} else {
sif::warning << "File removal failed!" << std::endl;
}
break;
} }
case (FsOpCodes::CREATE_DIR_IN_TMP): { break;
// No mount prefix, cause file is created in tmp }
cfg.useMountPrefix = false; case (FsOpCodes::CREATE_DIR_IN_TMP): {
sif::info << "Creating empty file in /tmp folder" << std::endl; // No mount prefix, cause file is created in tmp
// Do not delete file, user can check existence in shell cfg.useMountPrefix = false;
ReturnValue_t result = fsHandler->createDirectory("/tmp/", "test", false, &cfg); sif::info << "Creating empty file in /tmp folder" << std::endl;
if (result == HasReturnvaluesIF::RETURN_OK) { // Do not delete file, user can check existence in shell
sif::info << "Directory created successfully" << std::endl; ReturnValue_t result = fsHandler->createDirectory("/tmp/", "test", false, &cfg);
} else { if (result == HasReturnvaluesIF::RETURN_OK) {
sif::warning << "Directory creation failed!" << std::endl; sif::info << "Directory created successfully" << std::endl;
} } else {
break; sif::warning << "Directory creation failed!" << std::endl;
} }
case (FsOpCodes::REMOVE_EMPTY_DIR_IN_TMP): { break;
// No mount prefix, cause file is created in tmp }
cfg.useMountPrefix = false; case (FsOpCodes::REMOVE_EMPTY_DIR_IN_TMP): {
if (not std::filesystem::exists("/tmp/test")) { // No mount prefix, cause file is created in tmp
result = fsHandler->createDirectory("/tmp", "test", false, &cfg); cfg.useMountPrefix = false;
} else { if (not std::filesystem::exists("/tmp/test")) {
// Delete any leftover files to regular dir removal works result = fsHandler->createDirectory("/tmp", "test", false, &cfg);
std::remove("/tmp/test/*"); } else {
} // Delete any leftover files to regular dir removal works
result = fsHandler->removeDirectory("/tmp/", "test", false, &cfg); std::remove("/tmp/test/*");
if (result == HasReturnvaluesIF::RETURN_OK) {
sif::info << "Directory removed successfully" << std::endl;
} else {
sif::warning << "Directory removal failed!" << std::endl;
}
break;
} }
case (FsOpCodes::REMOVE_FILLED_DIR_IN_TMP): { result = fsHandler->removeDirectory("/tmp/", "test", false, &cfg);
result = createNonEmptyTmpDir(); if (result == HasReturnvaluesIF::RETURN_OK) {
if (result != HasReturnvaluesIF::RETURN_OK) { sif::info << "Directory removed successfully" << std::endl;
return; } else {
} sif::warning << "Directory removal failed!" << std::endl;
result = fsHandler->removeDirectory("/tmp/", "test", true, &cfg);
if (result == HasReturnvaluesIF::RETURN_OK) {
sif::info << "Directory removed recursively successfully" << std::endl;
} else {
sif::warning << "Recursive directory removal failed!" << std::endl;
}
break;
} }
case (FsOpCodes::ATTEMPT_DIR_REMOVAL_NON_EMPTY): { break;
result = createNonEmptyTmpDir(); }
if (result != HasReturnvaluesIF::RETURN_OK) { case (FsOpCodes::REMOVE_FILLED_DIR_IN_TMP): {
return; result = createNonEmptyTmpDir();
} if (result != HasReturnvaluesIF::RETURN_OK) {
result = fsHandler->removeDirectory("/tmp/", "test", false, &cfg); return;
if (result != HasReturnvaluesIF::RETURN_OK) {
sif::info << "Directory removal attempt failed as expected" << std::endl;
} else {
sif::warning << "Directory removal worked when it should not have!" << std::endl;
}
break;
} }
case (FsOpCodes::RENAME_FILE): { result = fsHandler->removeDirectory("/tmp/", "test", true, &cfg);
// No mount prefix, cause file is created in tmp if (result == HasReturnvaluesIF::RETURN_OK) {
cfg.useMountPrefix = false; sif::info << "Directory removed recursively successfully" << std::endl;
if (std::filesystem::exists("/tmp/test.txt")) { } else {
fsHandler->removeDirectory("/tmp/", "test", false, &cfg); sif::warning << "Recursive directory removal failed!" << std::endl;
}
sif::info << "Creating empty file /tmp/test.txt and rename to /tmp/test2.txt" << std::endl;
// Do not delete file, user can check existence in shell
fsHandler->createFile("/tmp/", "test.txt", nullptr, 0, &cfg);
fsHandler->renameFile("/tmp/", "test.txt", "test2.txt", &cfg);
break;
} }
case (FsOpCodes::APPEND_TO_FILE): { break;
// No mount prefix, cause file is created in tmp }
cfg.useMountPrefix = false; case (FsOpCodes::ATTEMPT_DIR_REMOVAL_NON_EMPTY): {
if (std::filesystem::exists("/tmp/test.txt")) { result = createNonEmptyTmpDir();
fsHandler->removeDirectory("/tmp/", "test", false, &cfg); if (result != HasReturnvaluesIF::RETURN_OK) {
} return;
if (std::filesystem::exists("/tmp/test.txt")) {
fsHandler->removeDirectory("/tmp/", "test", false, &cfg);
}
sif::info << "Creating empty file /tmp/test.txt and adding content" << std::endl;
std::string content = "Hello World\n";
// Do not delete file, user can check existence in shell
fsHandler->createFile("/tmp/", "test.txt", nullptr, 0, &cfg);
fsHandler->appendToFile("/tmp/", "test.txt", reinterpret_cast<const uint8_t*>(content.data()),
content.size(), 0, &cfg);
} }
result = fsHandler->removeDirectory("/tmp/", "test", false, &cfg);
if (result != HasReturnvaluesIF::RETURN_OK) {
sif::info << "Directory removal attempt failed as expected" << std::endl;
} else {
sif::warning << "Directory removal worked when it should not have!" << std::endl;
}
break;
}
case (FsOpCodes::RENAME_FILE): {
// No mount prefix, cause file is created in tmp
cfg.useMountPrefix = false;
if (std::filesystem::exists("/tmp/test.txt")) {
fsHandler->removeDirectory("/tmp/", "test", false, &cfg);
}
sif::info << "Creating empty file /tmp/test.txt and rename to /tmp/test2.txt" << std::endl;
// Do not delete file, user can check existence in shell
fsHandler->createFile("/tmp/", "test.txt", nullptr, 0, &cfg);
fsHandler->renameFile("/tmp/", "test.txt", "test2.txt", &cfg);
break;
}
case (FsOpCodes::APPEND_TO_FILE): {
// No mount prefix, cause file is created in tmp
cfg.useMountPrefix = false;
if (std::filesystem::exists("/tmp/test.txt")) {
fsHandler->removeDirectory("/tmp/", "test", false, &cfg);
}
if (std::filesystem::exists("/tmp/test.txt")) {
fsHandler->removeDirectory("/tmp/", "test", false, &cfg);
}
sif::info << "Creating empty file /tmp/test.txt and adding content" << std::endl;
std::string content = "Hello World\n";
// Do not delete file, user can check existence in shell
fsHandler->createFile("/tmp/", "test.txt", nullptr, 0, &cfg);
fsHandler->appendToFile("/tmp/", "test.txt", reinterpret_cast<const uint8_t*>(content.data()),
content.size(), 0, &cfg);
}
} }
} }

View File

@ -1,6 +1,7 @@
#ifndef BSP_Q7S_BOARDTEST_Q7STESTTASK_H_ #ifndef BSP_Q7S_BOARDTEST_Q7STESTTASK_H_
#define BSP_Q7S_BOARDTEST_Q7STESTTASK_H_ #define BSP_Q7S_BOARDTEST_Q7STESTTASK_H_
#include <libgpsmm.h>
#include "test/testtasks/TestTask.h" #include "test/testtasks/TestTask.h"
class CoreController; class CoreController;
@ -22,6 +23,7 @@ class Q7STestTask : public TestTask {
bool gpsNotOpenSwitch = false; bool gpsNotOpenSwitch = false;
bool gpsReadFailedSwitch = false; bool gpsReadFailedSwitch = false;
int32_t noModeSetCntr = 0; int32_t noModeSetCntr = 0;
gpsmm* gpsmmPtr = nullptr;
CoreController* coreController = nullptr; CoreController* coreController = nullptr;
ReturnValue_t performOneShotAction() override; ReturnValue_t performOneShotAction() override;