Skip to content
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .github/actions/spelling/expect.txt
Original file line number Diff line number Diff line change
Expand Up @@ -417,6 +417,8 @@ ncsl
newtio
nmsgs
NOBLOCK
NOLINT
NOLINTNEXTLINE
noparent
norecords
NOSPEC
Expand All @@ -439,6 +441,7 @@ openmct
openpyxl
openssldir
optarg
optin
optind
orgslist
ortega
Expand Down
2 changes: 1 addition & 1 deletion Os/Posix/test/ut/PosixConsoleTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ TEST(Nominal, SwitchStream) {
}
TEST(OffNominal, SwitchStream) {
Os::Posix::Console::PosixConsole posix_console;
ASSERT_DEATH(posix_console.setOutputStream(static_cast<Os::Posix::Console::PosixConsole::Stream>(3)), "Posix/|\\Console.cpp:33");
ASSERT_DEATH(posix_console.setOutputStream(static_cast<Os::Posix::Console::PosixConsole::Stream>(3)), "Posix/|\\Console.cpp:33"); // NOLINT(clang-analyzer-optin.core.EnumCastOutOfRange) intentional death test
}

int main(int argc, char** argv) {
Expand Down
6 changes: 5 additions & 1 deletion Os/Posix/test/ut/PosixDirectoryTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include "Fw/Types/String.hpp"

#include <fcntl.h> // for ::open()
#include <unistd.h> // for ::close()

namespace Os {
namespace Test {
Expand All @@ -35,7 +36,10 @@ void setUp(Os::Test::Directory::Tester* tester) {
tester->m_filenames.push_back(FILENAME_PREFIX + std::to_string(i));
}
for (auto filename : tester->m_filenames) {
::open((tester->m_path + "/" + filename).c_str(), O_CREAT);
int fd = ::open((tester->m_path + "/" + filename).c_str(), O_CREAT | O_WRONLY, 0644);
if (fd >= 0) {
::close(fd);
}
}
}

Expand Down
36 changes: 19 additions & 17 deletions Os/test/ut/queue/QueueRules.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,20 @@

#include "CommonTests.hpp"
#include "Fw/Types/String.hpp"
#include <memory>


struct PickedMessage {
FwSizeType size;
FwQueuePriorityType priority;
U8* sent;
std::unique_ptr<U8[]> sent;
U8 received[QUEUE_MESSAGE_SIZE_UPPER_BOUND];

// Constructor
PickedMessage() : size(0), priority(0), sent(nullptr) {}

// Get raw pointer for API compatibility
U8* get_sent() const { return sent.get(); }
};

PickedMessage pick_message(FwSizeType max_size) {
Expand All @@ -21,7 +28,7 @@ PickedMessage pick_message(FwSizeType max_size) {
// Force priority to be in a smaller range to produce more same-priority messages
message.priority = STest::Random::lowerUpper(0, std::numeric_limits<I8>::max());

message.sent = new U8[message.size];
message.sent.reset(new U8[message.size]);
for (FwSizeType i = 0; i < message.size; i++) {
message.sent[i] = STest::Random::lowerUpper(0, std::numeric_limits<U8>::max());
}
Expand Down Expand Up @@ -83,9 +90,8 @@ void Os::Test::Queue::Tester::SendNotFull::action(Os::Test::Queue::Tester& state
// Prevent lock-up
ASSERT_LT(state.queue.getMessagesAvailable(), state.queue.getDepth());
ASSERT_FALSE(state.is_shadow_full());
QueueInterface::Status status = state.shadow_send(pick.sent, pick.size, pick.priority, blocking);
QueueInterface::Status test_status = state.queue.send(pick.sent, pick.size, pick.priority, blocking);
delete[] pick.sent; // Clean-up
QueueInterface::Status status = state.shadow_send(pick.get_sent(), pick.size, pick.priority, blocking);
QueueInterface::Status test_status = state.queue.send(pick.get_sent(), pick.size, pick.priority, blocking);
ASSERT_EQ(status, QueueInterface::Status::OP_OK);
ASSERT_EQ(test_status, status);
if (this->m_end_check) {
Expand All @@ -108,10 +114,9 @@ bool Os::Test::Queue::Tester::SendFullNoBlock::precondition(const Os::Test::Queu
void Os::Test::Queue::Tester::SendFullNoBlock::action(Os::Test::Queue::Tester& state //!< The test state
) {
PickedMessage pick = pick_message(state.shadow.messageSize);
QueueInterface::Status status = state.shadow_send(pick.sent, pick.size, pick.priority, QueueInterface::NONBLOCKING);
QueueInterface::Status status = state.shadow_send(pick.get_sent(), pick.size, pick.priority, QueueInterface::NONBLOCKING);
QueueInterface::Status test_status =
state.queue.send(pick.sent, pick.size, pick.priority, QueueInterface::NONBLOCKING);
delete[] pick.sent;
state.queue.send(pick.get_sent(), pick.size, pick.priority, QueueInterface::NONBLOCKING);

ASSERT_EQ(status, QueueInterface::Status::FULL);
ASSERT_EQ(test_status, status);
Expand Down Expand Up @@ -201,19 +206,17 @@ void Os::Test::Queue::Tester::Overflow::action(Os::Test::Queue::Tester& state /
while (not state.is_shadow_full()) {
PickedMessage pick = pick_message(state.shadow.messageSize);
QueueInterface::Status status =
state.shadow_send(pick.sent, pick.size, pick.priority, QueueInterface::BlockingType::NONBLOCKING);
state.shadow_send(pick.get_sent(), pick.size, pick.priority, QueueInterface::BlockingType::NONBLOCKING);
QueueInterface::Status test_status =
state.queue.send(pick.sent, pick.size, pick.priority, QueueInterface::BlockingType::NONBLOCKING);
delete[] pick.sent;
state.queue.send(pick.get_sent(), pick.size, pick.priority, QueueInterface::BlockingType::NONBLOCKING);
ASSERT_EQ(status, QueueInterface::Status::OP_OK);
ASSERT_EQ(status, test_status);
}
PickedMessage pick = pick_message(state.shadow.messageSize);
QueueInterface::Status status =
state.shadow_send(pick.sent, pick.size, pick.priority, QueueInterface::BlockingType::NONBLOCKING);
state.shadow_send(pick.get_sent(), pick.size, pick.priority, QueueInterface::BlockingType::NONBLOCKING);
QueueInterface::Status test_status =
state.queue.send(pick.sent, pick.size, pick.priority, QueueInterface::BlockingType::NONBLOCKING);
delete[] pick.sent;
state.queue.send(pick.get_sent(), pick.size, pick.priority, QueueInterface::BlockingType::NONBLOCKING);
ASSERT_EQ(status, QueueInterface::Status::FULL);
ASSERT_EQ(status, test_status);
state.shadow_check();
Expand Down Expand Up @@ -282,16 +285,15 @@ void Os::Test::Queue::Tester::SendBlock::action(Os::Test::Queue::Tester& state
PickedMessage pick = pick_message(state.shadow.messageSize);
this->notify_other("SendUnblock");
QueueInterface::Status status =
state.shadow_send(pick.sent, pick.size, pick.priority, QueueInterface::BlockingType::BLOCKING);
state.shadow_send(pick.get_sent(), pick.size, pick.priority, QueueInterface::BlockingType::BLOCKING);
getLock().unlock();
QueueInterface::Status test_status =
state.queue.send(pick.sent, pick.size, pick.priority, QueueInterface::BlockingType::BLOCKING);
state.queue.send(pick.get_sent(), pick.size, pick.priority, QueueInterface::BlockingType::BLOCKING);
getLock().lock();
// Condition should be set after block
ASSERT_TRUE(this->getCondition());
// Unblock the shadow queue send
state.shadow_send_unblock();
delete[] pick.sent;

ASSERT_EQ(status, QueueInterface::Status::OP_OK);
ASSERT_EQ(test_status, status);
Expand Down
2 changes: 1 addition & 1 deletion Svc/ActiveTextLogger/ActiveTextLogger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@

// Format the string here, so that it is done in the task context
// of the caller. Format doc borrowed from PassiveTextLogger.
const char *severityString = "UNKNOWN";
const char *severityString = nullptr;

Check notice

Code scanning / CodeQL

Use of basic integral type Note

severityString uses the basic integral type char rather than a typedef with size and signedness.
switch (severity.e) {
case Fw::LogSeverity::FATAL:
severityString = "FATAL";
Expand Down
3 changes: 3 additions & 0 deletions Svc/BufferManager/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ set(SOURCE_FILES
register_fprime_module()

### UTS ###
set(UT_MOD_DEPS
STest
)
set(UT_SOURCE_FILES
"${FPRIME_FRAMEWORK_PATH}/Svc/BufferManager/BufferManager.fpp"
"${CMAKE_CURRENT_LIST_DIR}/test/ut/BufferManagerTester.cpp"
Expand Down
5 changes: 1 addition & 4 deletions Svc/BufferManager/test/ut/BufferManagerTester.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -235,15 +235,12 @@ namespace Svc {
REQUIREMENT("FPRIME-BM-006");

// randomly return buffers
time_t t;
srand(static_cast<unsigned>(time(&t)));

bool returned[BIN1_NUM_BUFFERS] = {false};

for (U16 b=0; b<BIN1_NUM_BUFFERS; b++) {
U16 entry;
while (true) {
entry = rand() % BIN1_NUM_BUFFERS;
entry = STest::Pick::lowerUpper(0, BIN1_NUM_BUFFERS - 1);
if (not returned[entry]) {
returned[entry] = true;
break;
Expand Down
3 changes: 3 additions & 0 deletions Svc/BufferManager/test/ut/BufferManagerTester.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

#include "BufferManagerGTestBase.hpp"
#include "Svc/BufferManager/BufferManagerComponentImpl.hpp"
#include <STest/Pick/Pick.hpp>

namespace Svc {

Expand Down Expand Up @@ -76,6 +77,8 @@ namespace Svc {
//!
BufferManagerComponentImpl component;



void textLogIn(
const FwEventIdType id, //!< The event ID
const Fw::Time& timeTag, //!< The time
Expand Down
4 changes: 2 additions & 2 deletions Svc/CmdSequencer/test/ut/SequenceFiles/BadDescriptorFile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ namespace Svc {
Fw::Time t(TimeBase::TB_WORKSTATION_TIME, 0, 0);
// Force an invalid record descriptor
FPrime::Records::Descriptor descriptor =
static_cast<FPrime::Records::Descriptor>(10);
static_cast<FPrime::Records::Descriptor>(10); // NOLINT(clang-analyzer-optin.core.EnumCastOutOfRange) intentional test
FPrime::Records::serialize(
descriptor,
t,
Expand All @@ -73,7 +73,7 @@ namespace Svc {
for (U32 i = 0; i < this->n; ++i) {
// Force an invalid time flag
const AMPCSSequence::Record::TimeFlag::t timeFlag =
static_cast<AMPCSSequence::Record::TimeFlag::t>(10);
static_cast<AMPCSSequence::Record::TimeFlag::t>(10); // NOLINT(clang-analyzer-optin.core.EnumCastOutOfRange) intentional test
const AMPCSSequence::Record::Time::t time = 0;
const AMPCSSequence::Record::Opcode::t opcode = i;
const U32 argument = i + 1;
Expand Down
3 changes: 3 additions & 0 deletions Svc/DpCatalog/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ set(HEADER_FILES

register_fprime_module()
### UTs ###
set(UT_MOD_DEPS
STest
)
set(UT_SOURCE_FILES
"${CMAKE_CURRENT_LIST_DIR}/DpCatalog.fpp"
"${CMAKE_CURRENT_LIST_DIR}/test/ut/DpCatalogTester.cpp"
Expand Down
30 changes: 10 additions & 20 deletions Svc/DpCatalog/test/ut/DpCatalogTester.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -311,20 +311,18 @@ namespace Svc {

std::list<Svc::DpCatalog::DpStateEntry> entryList;

srand(time(nullptr));

// fill the input entries with random priorities
for (FwIndexType entry = 0; entry < static_cast<FwIndexType>(FW_NUM_ARRAY_ELEMENTS(inputs)); entry++) {
U32 randVal = rand()%NUM_ENTRIES;
U32 randVal = STest::Pick::lowerUpper(0, NUM_ENTRIES - 1);
inputs[entry].record.set_priority(randVal);
randVal = rand()%NUM_ENTRIES;
randVal = STest::Pick::lowerUpper(0, NUM_ENTRIES - 1);
inputs[entry].record.set_id(randVal);
randVal = rand()%NUM_ENTRIES;
randVal = STest::Pick::lowerUpper(0, NUM_ENTRIES - 1);
inputs[entry].record.set_tSec(randVal);
inputs[entry].record.set_tSub(1500);
inputs[entry].record.set_size(100);
// randomly set if it is transmitted or not
randVal = rand()%2;
randVal = STest::Pick::lowerUpper(0, 1);
if (randVal == 0) {
inputs[entry].record.set_state(Fw::DpState::UNTRANSMITTED);
// only put untransmitted products in list, since the catalog algorithm only returns untransmitted product IDs
Expand Down Expand Up @@ -618,11 +616,9 @@ namespace Svc {

std::list<Svc::DpCatalog::DpStateEntry> entryList;

srand(time(nullptr));

// fill the input entries with random priorities
for (FwIndexType entry = 0; entry < static_cast<FwIndexType>(FW_NUM_ARRAY_ELEMENTS(inputs)); entry++) {
U32 randVal = rand()%NUM_ENTRIES;
U32 randVal = STest::Pick::lowerUpper(0, NUM_ENTRIES - 1);
inputs[entry].record.set_priority(randVal);
inputs[entry].record.set_id(entry);
inputs[entry].record.set_state(Fw::DpState::UNTRANSMITTED);
Expand Down Expand Up @@ -671,11 +667,9 @@ namespace Svc {

std::list<Svc::DpCatalog::DpStateEntry> entryList;

srand(time(nullptr));

// fill the input entries with random priorities
for (FwIndexType entry = 0; entry < static_cast<FwIndexType>(FW_NUM_ARRAY_ELEMENTS(inputs)); entry++) {
U32 randVal = rand()%NUM_ENTRIES;
U32 randVal = STest::Pick::lowerUpper(0, NUM_ENTRIES - 1);
inputs[entry].record.set_priority(100);
inputs[entry].record.set_id(entry);
inputs[entry].record.set_state(Fw::DpState::UNTRANSMITTED);
Expand Down Expand Up @@ -726,11 +720,9 @@ namespace Svc {

std::list<Svc::DpCatalog::DpStateEntry> entryList;

srand(time(nullptr));

// fill the input entries with random priorities
for (FwIndexType entry = 0; entry < static_cast<FwIndexType>(FW_NUM_ARRAY_ELEMENTS(inputs)); entry++) {
U32 randVal = rand()%NUM_ENTRIES;
U32 randVal = STest::Pick::lowerUpper(0, NUM_ENTRIES - 1);
inputs[entry].record.set_priority(100);
inputs[entry].record.set_id(randVal);
inputs[entry].record.set_state(Fw::DpState::UNTRANSMITTED);
Expand Down Expand Up @@ -779,16 +771,14 @@ namespace Svc {

std::list<Svc::DpCatalog::DpStateEntry> entryList;

srand(time(nullptr));

// fill the input entries with random priorities
for (FwIndexType entry = 0; entry < static_cast<FwIndexType>(FW_NUM_ARRAY_ELEMENTS(inputs)); entry++) {
U32 randVal = rand()%NUM_ENTRIES;
U32 randVal = STest::Pick::lowerUpper(0, NUM_ENTRIES - 1);
inputs[entry].record.set_priority(randVal);
randVal = rand()%NUM_ENTRIES;
randVal = STest::Pick::lowerUpper(0, NUM_ENTRIES - 1);
inputs[entry].record.set_id(randVal);
inputs[entry].record.set_state(Fw::DpState::UNTRANSMITTED);
randVal = rand()%NUM_ENTRIES;
randVal = STest::Pick::lowerUpper(0, NUM_ENTRIES - 1);
inputs[entry].record.set_tSec(randVal);
inputs[entry].record.set_tSub(1500);
inputs[entry].record.set_size(100);
Expand Down
3 changes: 3 additions & 0 deletions Svc/DpCatalog/test/ut/DpCatalogTester.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

#include "Svc/DpCatalog/DpCatalogGTestBase.hpp"
#include "Svc/DpCatalog/DpCatalog.hpp"
#include <STest/Pick/Pick.hpp>

namespace Svc {

Expand Down Expand Up @@ -147,6 +148,8 @@ namespace Svc {
//! The component under test
DpCatalog component;



public:
// ----------------------------------------------------------------------
// Moved Tests due to private/protected access
Expand Down
4 changes: 4 additions & 0 deletions Svc/EventManager/test/ut/EventManagerTester.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -145,19 +145,22 @@ void EventManagerTester::runFilterInvalidCommands() {
U32 cmdSeq = 21;
this->clearHistory();
FilterSeverity reportFilterLevel = FilterSeverity::WARNING_HI;
// NOLINTNEXTLINE(clang-analyzer-optin.core.EnumCastOutOfRange) intentional invalid test
Enabled filterEnabled(static_cast<Enabled::t>(10));
this->sendCmd_SET_EVENT_FILTER(0, cmdSeq, reportFilterLevel, filterEnabled);
ASSERT_CMD_RESPONSE_SIZE(1);
ASSERT_CMD_RESPONSE(0, EventManager::OPCODE_SET_EVENT_FILTER, cmdSeq, Fw::CmdResponse::FORMAT_ERROR);
this->clearHistory();
reportFilterLevel = FilterSeverity::WARNING_HI;
// NOLINTNEXTLINE(clang-analyzer-optin.core.EnumCastOutOfRange) intentional invalid test
filterEnabled.e = static_cast<Enabled::t>(-2);
this->sendCmd_SET_EVENT_FILTER(0, cmdSeq, reportFilterLevel, filterEnabled);
ASSERT_CMD_RESPONSE_SIZE(1);
ASSERT_CMD_RESPONSE(0, EventManager::OPCODE_SET_EVENT_FILTER, cmdSeq, Fw::CmdResponse::FORMAT_ERROR);
FilterSeverity eventLevel;
this->clearHistory();
Enabled reportEnable = Enabled::ENABLED;
// NOLINTNEXTLINE(clang-analyzer-optin.core.EnumCastOutOfRange) intentional invalid test
eventLevel.e = static_cast<FilterSeverity::t>(-1);
this->sendCmd_SET_EVENT_FILTER(0, cmdSeq, eventLevel, reportEnable);
ASSERT_CMD_RESPONSE_SIZE(1);
Expand All @@ -166,6 +169,7 @@ void EventManagerTester::runFilterInvalidCommands() {
this->clearHistory();

reportEnable = Enabled::ENABLED;
// NOLINTNEXTLINE(clang-analyzer-optin.core.EnumCastOutOfRange) intentional invalid test
eventLevel.e = static_cast<FilterSeverity::t>(100);
this->sendCmd_SET_EVENT_FILTER(0, cmdSeq, eventLevel, reportEnable);
ASSERT_CMD_RESPONSE_SIZE(1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
ConsoleTextLoggerImpl::~ConsoleTextLoggerImpl() {}

void ConsoleTextLoggerImpl::TextLogger_handler(FwIndexType portNum, FwEventIdType id, Fw::Time &timeTag, const Fw::LogSeverity& severity, Fw::TextLogString &text) {
const char *severityString = "UNKNOWN";
const char *severityString = nullptr;

Check notice

Code scanning / CodeQL

Use of basic integral type Note

severityString uses the basic integral type char rather than a typedef with size and signedness.
switch (severity.e) {
case Fw::LogSeverity::FATAL:
severityString = "FATAL";
Expand Down
1 change: 1 addition & 0 deletions Utils/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ set(UT_SOURCE_FILES
"${CMAKE_CURRENT_LIST_DIR}/test/ut/TokenBucketTester.cpp"
)
set(UT_MOD_DEPS
STest
Fw/Types
Fw/Time
Os
Expand Down
Loading
Loading