Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
5 changes: 4 additions & 1 deletion .github/actions/spelling/expect.txt
Original file line number Diff line number Diff line change
Expand Up @@ -419,6 +419,8 @@ ncsl
newtio
nmsgs
NOBLOCK
NOLINT
NOLINTNEXTLINE
noparent
norecords
NOSPEC
Expand All @@ -441,6 +443,7 @@ openmct
openpyxl
openssldir
optarg
optin
optind
orgslist
ortega
Expand Down Expand Up @@ -683,8 +686,8 @@ TPP
trinomials
tts
TXD
typedef'ed
typedef
typedef'ed
uart
UDPSOCKET
uge
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;
switch (severity.e) {
case Fw::LogSeverity::FATAL:
severityString = "FATAL";
Expand Down
7 changes: 5 additions & 2 deletions Svc/BufferManager/test/ut/BufferManagerTester.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include <Fw/Types/MallocAllocator.hpp>
#include <Fw/Test/UnitTest.hpp>
#include <cstdlib>
#include <random>

#define INSTANCE 0
#define MAX_HISTORY_SIZE 100
Expand Down Expand Up @@ -93,7 +94,8 @@ namespace Svc {
BufferManagerTester ::
BufferManagerTester() :
BufferManagerGTestBase("Tester", MAX_HISTORY_SIZE),
component("BufferManager")
component("BufferManager"),
m_rng(std::random_device{}())
{
this->initComponents();
this->connectPorts();
Expand Down Expand Up @@ -243,7 +245,8 @@ namespace Svc {
for (U16 b=0; b<BIN1_NUM_BUFFERS; b++) {
U16 entry;
while (true) {
entry = rand() % BIN1_NUM_BUFFERS;
std::uniform_int_distribution<U16> dis(0, BIN1_NUM_BUFFERS - 1);
entry = dis(this->m_rng);
if (not returned[entry]) {
returned[entry] = true;
break;
Expand Down
5 changes: 5 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 <random>

namespace Svc {

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

//! Random number generator for tests
//!
std::mt19937 m_rng;

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
30 changes: 19 additions & 11 deletions Svc/DpCatalog/test/ut/DpCatalogTester.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include "Fw/Types/FileNameString.hpp"
#include "config/DpCfg.hpp"
#include <list>
#include <random>

namespace Svc {

Expand All @@ -23,7 +24,8 @@ namespace Svc {
DpCatalogTester ::
DpCatalogTester() :
DpCatalogGTestBase("DpCatalogTester", DpCatalogTester::MAX_HISTORY_SIZE),
component("DpCatalog")
component("DpCatalog"),
m_rng(std::random_device{}())
{
this->initComponents();
this->connectPorts();
Expand Down Expand Up @@ -315,16 +317,18 @@ namespace Svc {

// 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;
std::uniform_int_distribution<U32> numEntriesDis(0, NUM_ENTRIES - 1);
U32 randVal = numEntriesDis(this->m_rng);
inputs[entry].record.set_priority(randVal);
randVal = rand()%NUM_ENTRIES;
randVal = numEntriesDis(this->m_rng);
inputs[entry].record.set_id(randVal);
randVal = rand()%NUM_ENTRIES;
randVal = numEntriesDis(this->m_rng);
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;
std::uniform_int_distribution<U32> binaryDis(0, 1);
randVal = binaryDis(this->m_rng);
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 @@ -622,7 +626,8 @@ namespace Svc {

// 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;
std::uniform_int_distribution<U32> numEntriesDis(0, NUM_ENTRIES - 1);
U32 randVal = numEntriesDis(this->m_rng);
inputs[entry].record.set_priority(randVal);
inputs[entry].record.set_id(entry);
inputs[entry].record.set_state(Fw::DpState::UNTRANSMITTED);
Expand Down Expand Up @@ -675,7 +680,8 @@ namespace Svc {

// 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;
std::uniform_int_distribution<U32> numEntriesDis(0, NUM_ENTRIES - 1);
U32 randVal = numEntriesDis(this->m_rng);
inputs[entry].record.set_priority(100);
inputs[entry].record.set_id(entry);
inputs[entry].record.set_state(Fw::DpState::UNTRANSMITTED);
Expand Down Expand Up @@ -730,7 +736,8 @@ namespace Svc {

// 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;
std::uniform_int_distribution<U32> numEntriesDis(0, NUM_ENTRIES - 1);
U32 randVal = numEntriesDis(this->m_rng);
inputs[entry].record.set_priority(100);
inputs[entry].record.set_id(randVal);
inputs[entry].record.set_state(Fw::DpState::UNTRANSMITTED);
Expand Down Expand Up @@ -783,12 +790,13 @@ namespace Svc {

// 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;
std::uniform_int_distribution<U32> numEntriesDis(0, NUM_ENTRIES - 1);
U32 randVal = numEntriesDis(this->m_rng);
inputs[entry].record.set_priority(randVal);
randVal = rand()%NUM_ENTRIES;
randVal = numEntriesDis(this->m_rng);
inputs[entry].record.set_id(randVal);
inputs[entry].record.set_state(Fw::DpState::UNTRANSMITTED);
randVal = rand()%NUM_ENTRIES;
randVal = numEntriesDis(this->m_rng);
inputs[entry].record.set_tSec(randVal);
inputs[entry].record.set_tSub(1500);
inputs[entry].record.set_size(100);
Expand Down
4 changes: 4 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 <random>

namespace Svc {

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

//! Random number generator for tests
std::mt19937 m_rng;

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;
switch (severity.e) {
case Fw::LogSeverity::FATAL:
severityString = "FATAL";
Expand Down
Loading
Loading