diff --git a/Drv/Ip/IpSocket.cpp b/Drv/Ip/IpSocket.cpp index 86fdaf32e5..dbe45703a1 100644 --- a/Drv/Ip/IpSocket.cpp +++ b/Drv/Ip/IpSocket.cpp @@ -148,7 +148,7 @@ SocketIpStatus IpSocket::send(const SocketDescriptor& socketDescriptor, const U8 else if (sent == -1) { return SOCK_SEND_ERROR; } - FW_ASSERT(sent > 0, sent); + FW_ASSERT(sent > 0, static_cast(sent)); total += static_cast(sent); } // Failed to retry enough to send all data diff --git a/Drv/Ip/UdpSocket.cpp b/Drv/Ip/UdpSocket.cpp index 7a811a8678..caf21b70d5 100644 --- a/Drv/Ip/UdpSocket.cpp +++ b/Drv/Ip/UdpSocket.cpp @@ -67,7 +67,7 @@ SocketIpStatus UdpSocket::configure(const char* const hostname, const U16 port, SocketIpStatus UdpSocket::configureSend(const char* const hostname, const U16 port, const U32 timeout_seconds, const U32 timeout_microseconds) { //Timeout is for the send, so configure send will work with the base class - FW_ASSERT(port != 0, port); // Send cannot be on port 0 + FW_ASSERT(port != 0, static_cast(port)); // Send cannot be on port 0 FW_ASSERT(hostname != nullptr); return this->IpSocket::configure(hostname, port, timeout_seconds, timeout_microseconds); } @@ -112,7 +112,7 @@ SocketIpStatus UdpSocket::bind(const PlatformIntType fd) { return SOCK_FAILED_TO_READ_BACK_PORT; } - FW_ASSERT(sizeof(this->m_state->m_addr_recv) == sizeof(address), sizeof(this->m_state->m_addr_recv), sizeof(address)); + FW_ASSERT(sizeof(this->m_state->m_addr_recv) == sizeof(address), static_cast(sizeof(this->m_state->m_addr_recv)), static_cast(sizeof(address))); memcpy(&this->m_state->m_addr_recv, &address, sizeof(this->m_state->m_addr_recv)); return SOCK_SUCCESS; @@ -152,8 +152,8 @@ SocketIpStatus UdpSocket::openProtocol(SocketDescriptor& socketDescriptor) { ::close(socketFd); return status; } - FW_ASSERT(sizeof(this->m_state->m_addr_send) == sizeof(address), sizeof(this->m_state->m_addr_send), - sizeof(address)); + FW_ASSERT(sizeof(this->m_state->m_addr_send) == sizeof(address), static_cast(sizeof(this->m_state->m_addr_send)), + static_cast(sizeof(address))); memcpy(&this->m_state->m_addr_send, &address, sizeof(this->m_state->m_addr_send)); } @@ -184,9 +184,9 @@ SocketIpStatus UdpSocket::openProtocol(SocketDescriptor& socketDescriptor) { } // Neither configuration method was called else { - FW_ASSERT(port > 0 || recv_port > 0, port, recv_port); + FW_ASSERT(port > 0 || recv_port > 0, static_cast(port), static_cast(recv_port)); } - FW_ASSERT(status == SOCK_SUCCESS, status); + FW_ASSERT(status == SOCK_SUCCESS, static_cast(status)); socketDescriptor.fd = socketFd; return status; } diff --git a/Fw/Port/InputPortBase.cpp b/Fw/Port/InputPortBase.cpp index 2834e3f1ee..ed4f5fe536 100644 --- a/Fw/Port/InputPortBase.cpp +++ b/Fw/Port/InputPortBase.cpp @@ -21,7 +21,7 @@ namespace Fw { } void InputPortBase::setPortNum(FwIndexType portNum) { - FW_ASSERT(portNum >= 0,portNum); + FW_ASSERT(portNum >= 0, static_cast(portNum)); this->m_portNum = portNum; } diff --git a/Fw/Time/Time.cpp b/Fw/Time/Time.cpp index 7f3dfb72ec..dbfd037c45 100644 --- a/Fw/Time/Time.cpp +++ b/Fw/Time/Time.cpp @@ -196,10 +196,10 @@ namespace Fw { ) { #if FW_USE_TIME_BASE - FW_ASSERT(a.getTimeBase() == b.getTimeBase(), a.getTimeBase(), b.getTimeBase() ); + FW_ASSERT(a.getTimeBase() == b.getTimeBase(), static_cast(a.getTimeBase()), static_cast(b.getTimeBase()) ); #endif #if FW_USE_TIME_CONTEXT - FW_ASSERT(a.getContext() == b.getContext(), a.getContext(), b.getContext() ); + FW_ASSERT(a.getContext() == b.getContext(), static_cast(a.getContext()), static_cast(b.getContext()) ); #endif U32 seconds = a.getSeconds() + b.getSeconds(); U32 uSeconds = a.getUSeconds() + b.getUSeconds(); @@ -219,10 +219,10 @@ namespace Fw { ) { #if FW_USE_TIME_BASE - FW_ASSERT(minuend.getTimeBase() == subtrahend.getTimeBase(), minuend.getTimeBase(), subtrahend.getTimeBase()); + FW_ASSERT(minuend.getTimeBase() == subtrahend.getTimeBase(), static_cast(minuend.getTimeBase()), static_cast(subtrahend.getTimeBase())); #endif #if FW_USE_TIME_CONTEXT - FW_ASSERT(minuend.getContext() == subtrahend.getContext(), minuend.getContext(), subtrahend.getContext()); + FW_ASSERT(minuend.getContext() == subtrahend.getContext(), static_cast(minuend.getContext()), static_cast(subtrahend.getContext())); #endif // Assert minuend is greater than subtrahend FW_ASSERT(minuend >= subtrahend); diff --git a/Fw/Tlm/TlmPacket.cpp b/Fw/Tlm/TlmPacket.cpp index 899310cf0b..377153f1ac 100644 --- a/Fw/Tlm/TlmPacket.cpp +++ b/Fw/Tlm/TlmPacket.cpp @@ -24,7 +24,7 @@ namespace Fw { this->m_numEntries = 0; // make sure packet type is correct before serializing. It should // never be anything but FW_PACKET_TELEM, so assert. - FW_ASSERT(FW_PACKET_TELEM == this->m_type,this->m_type); + FW_ASSERT(FW_PACKET_TELEM == this->m_type, static_cast(this->m_type)); // serialize descriptor // The function serializeBase inherited from ComPacket converts this->m_type // to type FwPacketDescriptorType and serializes the result into this->m_tlmBuffer. diff --git a/Os/Generic/Types/test/ut/MaxHeap/MaxHeapTest.cpp b/Os/Generic/Types/test/ut/MaxHeap/MaxHeapTest.cpp index 434b0f3dc1..04ae1c7b11 100644 --- a/Os/Generic/Types/test/ut/MaxHeap/MaxHeapTest.cpp +++ b/Os/Generic/Types/test/ut/MaxHeap/MaxHeapTest.cpp @@ -88,7 +88,9 @@ TEST(Nominal, PushPop) { printf("Testing pop...\n"); //heap.print(); - for(FwQueuePriorityType ii = DEPTH-1; ii >= 0; --ii) { + for(FwSizeType i = 0; i < DEPTH; i++) { + ASSERT_TRUE(DEPTH - 1 >= i); + FwSizeType ii = DEPTH - 1 - i; ret = heap.pop(value, id); ASSERT_TRUE(ret); ASSERT_EQ(id, static_cast(ii)); @@ -104,8 +106,8 @@ TEST(Nominal, PushPop) { printf("Passed.\n"); printf("Testing random...\n"); - FwQueuePriorityType values[DEPTH] = {56, 0, 500, 57, 5}; - FwSizeType sorted[DEPTH] = {500, 57, 56, 5, 0}; + FwQueuePriorityType values[DEPTH] = {56, 0, 127, 57, 5}; + FwSizeType sorted[DEPTH] = {127, 57, 56, 5, 0}; //heap.print(); // Push values on in random order: for(FwSizeType ii = 0; ii < DEPTH; ++ii) { @@ -188,9 +190,9 @@ TEST(Nominal, PushPop) { // for things of the same priority and in priority // order for things of different priorities. FwQueuePriorityType pries[DEPTH] = {1, 7, 100, 1, 7}; - FwQueuePriorityType data2[DEPTH] = {4, 22, 99, 12344, 33}; + FwQueuePriorityType data2[DEPTH] = {4, 22, 99, 127, 33}; FwQueuePriorityType orderedPries[DEPTH] = {100, 7, 7, 1, 1}; - FwSizeType ordered[DEPTH] = {99, 22, 33, 4, 12344}; + FwSizeType ordered[DEPTH] = {99, 22, 33, 4, 127}; // Push values on in random order: for(FwSizeType ii = 0; ii < DEPTH; ++ii) { // Push next value in the list: diff --git a/Os/Posix/ConditionVariable.cpp b/Os/Posix/ConditionVariable.cpp index 7ea9bb92c3..72fa498e60 100644 --- a/Os/Posix/ConditionVariable.cpp +++ b/Os/Posix/ConditionVariable.cpp @@ -13,7 +13,7 @@ namespace Mutex { PosixConditionVariable::PosixConditionVariable() { PlatformIntType status = pthread_cond_init(&this->m_handle.m_condition, nullptr); - FW_ASSERT(status == 0, status); // If this fails, something horrible happened. + FW_ASSERT(status == 0, static_cast(status)); // If this fails, something horrible happened. } PosixConditionVariable::~PosixConditionVariable() { (void)pthread_cond_destroy(&this->m_handle.m_condition); diff --git a/Os/Posix/test/ut/PosixMutexTests.cpp b/Os/Posix/test/ut/PosixMutexTests.cpp index 55869b1ee8..29da88479e 100644 --- a/Os/Posix/test/ut/PosixMutexTests.cpp +++ b/Os/Posix/test/ut/PosixMutexTests.cpp @@ -15,7 +15,7 @@ static void testTaskRoutine(void* pointer) { Os::Test::Mutex::Tester* tester = reinterpret_cast(pointer); - for (FwIndexType i = 0; i < 100000; i++) { + for (FwSizeType i = 0; i < 100000; i++) { tester->m_mutex.lock(); tester->m_state = Os::Test::Mutex::Tester::MutexState::LOCKED; @@ -51,7 +51,7 @@ TEST_F(FunctionalityTester, PosixMutexDataProtection) { Os::Test::Mutex::Tester::ProtectDataCheck protect_data_rule; - for (FwIndexType i = 0; i < 100000; i++) { + for (FwSizeType i = 0; i < 100000; i++) { protect_data_rule.apply(*tester); } diff --git a/Os/Queue.cpp b/Os/Queue.cpp index 10e7062067..03ef4e1377 100644 --- a/Os/Queue.cpp +++ b/Os/Queue.cpp @@ -41,7 +41,7 @@ QueueInterface::Status Queue ::create(const Fw::StringBase& name, FwSizeType dep QueueInterface::Status Queue::send(const U8* buffer, FwSizeType size, - PlatformIntType priority, + FwQueuePriorityType priority, QueueInterface::BlockingType blockType) { FW_ASSERT(&this->m_delegate == reinterpret_cast(&this->m_handle_storage[0])); FW_ASSERT(buffer != nullptr); @@ -60,7 +60,7 @@ QueueInterface::Status Queue::receive(U8* destination, FwSizeType capacity, QueueInterface::BlockingType blockType, FwSizeType& actualSize, - PlatformIntType& priority) { + FwQueuePriorityType& priority) { FW_ASSERT(&this->m_delegate == reinterpret_cast(&this->m_handle_storage[0])); FW_ASSERT(destination != nullptr); // Check if initialized @@ -90,14 +90,14 @@ QueueHandle* Queue::getHandle(){ } QueueInterface::Status Queue::send(const Fw::SerializeBufferBase& message, - PlatformIntType priority, + FwQueuePriorityType priority, QueueInterface::BlockingType blockType) { return this->send(message.getBuffAddr(), message.getBuffLength(), priority, blockType); } QueueInterface::Status Queue::receive(Fw::SerializeBufferBase& destination, QueueInterface::BlockingType blockType, - PlatformIntType& priority) { + FwQueuePriorityType& priority) { FwSizeType actualSize = 0; destination.resetSer(); // Reset the buffer QueueInterface::Status status = diff --git a/Os/Stub/test/Queue.cpp b/Os/Stub/test/Queue.cpp index 64c0a081d5..57a729de7f 100644 --- a/Os/Stub/test/Queue.cpp +++ b/Os/Stub/test/Queue.cpp @@ -11,6 +11,7 @@ namespace Queue { namespace Test { StaticData StaticData::data; +U64 InjectableStlQueueHandle::Message::order_counter = 0; InjectableStlQueueHandle::InjectableStlQueueHandle() : // Creates the necessary handle on the heap to keep the handle size small @@ -63,6 +64,7 @@ QueueInterface::Status InjectableStlQueue::send(const U8* buffer, FwSizeType siz (void) std::memcpy(message.data, buffer, static_cast(size)); message.priority = priority; message.size = size; + message.order = InjectableStlQueueHandle::Message::order_counter++; this->m_handle.m_storage.push(message); this->m_handle.m_high_water = FW_MAX(this->m_handle.m_high_water, this->m_handle.m_storage.size()); return QueueInterface::Status::OP_OK; diff --git a/Os/Stub/test/Queue.hpp b/Os/Stub/test/Queue.hpp index 17cd2e3da7..cd946fa5ec 100644 --- a/Os/Stub/test/Queue.hpp +++ b/Os/Stub/test/Queue.hpp @@ -4,7 +4,8 @@ #include "Os/Queue.hpp" #include #include - +#include +#include namespace Os { namespace Stub { @@ -62,10 +63,19 @@ struct InjectableStlQueueHandle : public QueueHandle { U8 data[STUB_QUEUE_TEST_MESSAGE_MAX_SIZE]; FwQueuePriorityType priority; FwSizeType size; + U64 order; + static U64 order_counter; //! \brief comparison utility for messages struct LessMessage { bool operator()(const Message& a, const Message& b) { - return std::greater()(a.priority, b.priority); + // Compare priority for unequal priority + if (a.priority != b.priority) { + return std::greater()(a.priority, b.priority); + } + // Cannot have like ordered items + assert(a.order != b.order); + // Compare received order for unequal received orders + return a.order > b.order; } }; }; diff --git a/Os/test/ut/filesystem/RulesHeaders.hpp b/Os/test/ut/filesystem/RulesHeaders.hpp index 1408dd3956..0eb3be0ed9 100644 --- a/Os/test/ut/filesystem/RulesHeaders.hpp +++ b/Os/test/ut/filesystem/RulesHeaders.hpp @@ -50,7 +50,7 @@ struct Tester { std::vector m_test_dirs; std::vector m_test_files; - FwIndexType m_counter; //!< Counter for generating unique file/directory names + U64 m_counter; //!< Counter for generating unique file/directory names // --------------------------------------------------------------- // Functions to manipulate the state of the Tester w.r.t filesystem @@ -84,9 +84,11 @@ struct Tester { // Helper functions for testing // ---------------------------------------------------------------- std::string get_new_filename() { + assert(m_counter != std::numeric_limits::max()); return "test_file_" + std::to_string(m_counter++); } std::string get_new_dirname() { + assert(m_counter != std::numeric_limits::max()); return "test_dir_" + std::to_string(m_counter++); } TestFile& get_random_file() { diff --git a/Os/test/ut/queue/CommonTests.cpp b/Os/test/ut/queue/CommonTests.cpp index b66724c1a6..2aa0e9a2d1 100644 --- a/Os/test/ut/queue/CommonTests.cpp +++ b/Os/test/ut/queue/CommonTests.cpp @@ -15,6 +15,7 @@ namespace Os { namespace Test { namespace Queue { FwSizeType Tester::QueueState::queues = 0; +U64 Tester::QueueMessage::order_counter = 0; PriorityCompare const Tester::QueueMessageComparer::HELPER = PriorityCompare(); @@ -38,6 +39,10 @@ Os::QueueInterface::Status Tester::shadow_send(const U8* buffer, QueueMessage qm; qm.priority = priority; qm.size = size; + qm.order = QueueMessage::order_counter++; + // Overflow imminent, fail now! + assert(QueueMessage::order_counter != std::numeric_limits::max()); + std::memcpy(qm.data, buffer, static_cast(size)); if (size > this->shadow.messageSize) { return QueueInterface::Status::SIZE_MISMATCH; @@ -113,7 +118,7 @@ TEST(InterfaceUninitialized, SendPointer) { Os::Queue queue; Fw::String name = "My queue"; const FwSizeType messageSize = 200; - const FwQueuePriorityType priority = 300; + const FwQueuePriorityType priority = 127; U8 buffer[messageSize]; Os::QueueInterface::Status status = @@ -125,7 +130,7 @@ TEST(InterfaceUninitialized, SendBuffer) { Os::Queue queue; Fw::String name = "My queue"; const FwSizeType messageSize = 200; - const FwQueuePriorityType priority = 300; + const FwQueuePriorityType priority = 127; U8 storage[messageSize]; Fw::ExternalSerializeBuffer buffer(storage, sizeof storage); @@ -173,7 +178,7 @@ TEST(InterfaceInvalid, SendPointerNull) { Os::Queue queue; Fw::String name = "My queue"; const FwSizeType messageSize = 200; - const FwQueuePriorityType priority = 300; + const FwQueuePriorityType priority = 127; ASSERT_DEATH_IF_SUPPORTED(queue.send(nullptr, messageSize, priority, Os::QueueInterface::BlockingType::BLOCKING), "Assert:.*Queue\\.cpp"); } @@ -182,7 +187,7 @@ TEST(InterfaceInvalid, SendInvalidEnum) { Os::Queue queue; Fw::String name = "My queue"; const FwSizeType messageSize = 200; - const FwQueuePriorityType priority = 300; + const FwQueuePriorityType priority = 127; Os::QueueInterface::BlockingType blockingType = static_cast(Os::QueueInterface::BlockingType::BLOCKING + 1); ASSERT_DEATH_IF_SUPPORTED(queue.send(nullptr, messageSize, priority, blockingType), "Assert:.*Queue\\.cpp"); diff --git a/Os/test/ut/queue/QueueRules.cpp b/Os/test/ut/queue/QueueRules.cpp index c792051349..701d27b460 100644 --- a/Os/test/ut/queue/QueueRules.cpp +++ b/Os/test/ut/queue/QueueRules.cpp @@ -6,6 +6,7 @@ #include "CommonTests.hpp" #include "Fw/Types/String.hpp" + struct PickedMessage { FwSizeType size; FwQueuePriorityType priority; @@ -17,7 +18,8 @@ PickedMessage pick_message(FwSizeType max_size) { PickedMessage message; message.size = STest::Random::lowerUpper(1, max_size); - message.priority = STest::Random::lowerUpper(0, std::numeric_limits::max()); + // Force priority to be in a smaller range to produce more same-priority messages + message.priority = STest::Random::lowerUpper(0, std::numeric_limits::max()); message.sent = new U8[message.size]; for (FwSizeType i = 0; i < message.size; i++) { diff --git a/Os/test/ut/queue/RulesHeaders.hpp b/Os/test/ut/queue/RulesHeaders.hpp index 043250c29d..2d73887817 100644 --- a/Os/test/ut/queue/RulesHeaders.hpp +++ b/Os/test/ut/queue/RulesHeaders.hpp @@ -33,6 +33,8 @@ struct Tester { U8 data[QUEUE_MESSAGE_SIZE_UPPER_BOUND]; FwQueuePriorityType priority = 0; FwSizeType size = 0; + U64 order = 0; + static U64 order_counter; }; struct ReceiveMessage { @@ -42,7 +44,16 @@ struct Tester { }; struct QueueMessageComparer { - bool operator()(const QueueMessage& a, const QueueMessage& b) { return HELPER(a.priority, b.priority); } + bool operator()(const QueueMessage& a, const QueueMessage& b){ + // Compare priority for unequal priority + if (a.priority != b.priority) { + return HELPER(a.priority, b.priority); + } + // Cannot have like ordered items + assert(a.order != b.order); + // Compare received order for unequal received orders + return a.order > b.order; + } private: static const PriorityCompare HELPER; diff --git a/Svc/ActiveRateGroup/ActiveRateGroup.cpp b/Svc/ActiveRateGroup/ActiveRateGroup.cpp index e82f8a52dd..7e08212383 100644 --- a/Svc/ActiveRateGroup/ActiveRateGroup.cpp +++ b/Svc/ActiveRateGroup/ActiveRateGroup.cpp @@ -32,10 +32,12 @@ namespace Svc { void ActiveRateGroup::configure(U32 contexts[], FwIndexType numContexts) { FW_ASSERT(contexts); - FW_ASSERT(numContexts == this->getNum_RateGroupMemberOut_OutputPorts(),numContexts,this->getNum_RateGroupMemberOut_OutputPorts()); + FW_ASSERT(numContexts == this->getNum_RateGroupMemberOut_OutputPorts(), + static_cast(numContexts), + static_cast(this->getNum_RateGroupMemberOut_OutputPorts())); FW_ASSERT(FW_NUM_ARRAY_ELEMENTS(this->m_contexts) == this->getNum_RateGroupMemberOut_OutputPorts(), - FW_NUM_ARRAY_ELEMENTS(this->m_contexts), - this->getNum_RateGroupMemberOut_OutputPorts()); + static_cast(FW_NUM_ARRAY_ELEMENTS(this->m_contexts)), + static_cast(this->getNum_RateGroupMemberOut_OutputPorts())); this->m_numContexts = numContexts; // copy context values diff --git a/Svc/BufferLogger/BufferLoggerFile.cpp b/Svc/BufferLogger/BufferLoggerFile.cpp index ea0b7c0430..623cfc7b33 100644 --- a/Svc/BufferLogger/BufferLoggerFile.cpp +++ b/Svc/BufferLogger/BufferLoggerFile.cpp @@ -62,7 +62,7 @@ namespace Svc { this->m_maxSize = maxFileSize; this->m_sizeOfSize = sizeOfSize; - FW_ASSERT(sizeOfSize <= sizeof(FwSizeType), sizeOfSize); + FW_ASSERT(sizeOfSize <= sizeof(FwSizeType), static_cast(sizeOfSize)); FW_ASSERT(m_maxSize > sizeOfSize, static_cast(m_maxSize)); } diff --git a/Svc/BufferRepeater/BufferRepeater.cpp b/Svc/BufferRepeater/BufferRepeater.cpp index 09c9003f73..f0d8c49ed8 100644 --- a/Svc/BufferRepeater/BufferRepeater.cpp +++ b/Svc/BufferRepeater/BufferRepeater.cpp @@ -32,7 +32,7 @@ void BufferRepeater ::configure(BufferRepeater::BufferRepeaterFailureOption allo bool BufferRepeater ::check_allocation(FwIndexType index, const Fw::Buffer& new_allocation, const Fw::Buffer& incoming_buffer) { - FW_ASSERT(index < NUM_PORTOUT_OUTPUT_PORTS, index); + FW_ASSERT(index < NUM_PORTOUT_OUTPUT_PORTS, static_cast(index)); bool is_valid = (new_allocation.getData() != nullptr) && (new_allocation.getSize() >= incoming_buffer.getSize()); // Respond to invalid buffer allocation diff --git a/Svc/ComQueue/ComQueue.cpp b/Svc/ComQueue/ComQueue.cpp index b41c32d96f..3a40f43e83 100644 --- a/Svc/ComQueue/ComQueue.cpp +++ b/Svc/ComQueue/ComQueue.cpp @@ -105,7 +105,7 @@ void ComQueue::configure(QueueConfigurationTable queueConfig, // Get current queue's allocation size and safety check the values FwSizeType allocationSize = this->m_prioritizedList[i].depth * this->m_prioritizedList[i].msgSize; FW_ASSERT(this->m_prioritizedList[i].index < static_cast(FW_NUM_ARRAY_ELEMENTS(this->m_queues)), - this->m_prioritizedList[i].index); + static_cast(this->m_prioritizedList[i].index)); FW_ASSERT( (allocationSize + allocationOffset) <= totalAllocation, static_cast(allocationSize), @@ -132,14 +132,15 @@ void ComQueue::configure(QueueConfigurationTable queueConfig, void ComQueue::comQueueIn_handler(const FwIndexType portNum, Fw::ComBuffer& data, U32 context) { // Ensure that the port number of comQueueIn is consistent with the expectation - FW_ASSERT(portNum >= 0 && portNum < COM_PORT_COUNT, portNum); + FW_ASSERT(portNum >= 0 && portNum < COM_PORT_COUNT, static_cast(portNum)); (void)this->enqueue(portNum, QueueType::COM_QUEUE, reinterpret_cast(&data), sizeof(Fw::ComBuffer)); } void ComQueue::buffQueueIn_handler(const FwIndexType portNum, Fw::Buffer& fwBuffer) { - const FwIndexType queueNum = portNum + COM_PORT_COUNT; + FW_ASSERT(std::numeric_limits::max() - COM_PORT_COUNT > portNum); + const FwIndexType queueNum = static_cast(portNum + COM_PORT_COUNT); // Ensure that the port number of buffQueueIn is consistent with the expectation - FW_ASSERT(portNum >= 0 && portNum < BUFFER_PORT_COUNT, portNum); + FW_ASSERT(portNum >= 0 && portNum < BUFFER_PORT_COUNT, static_cast(portNum)); FW_ASSERT(queueNum < TOTAL_PORT_COUNT); bool status = this->enqueue(queueNum, QueueType::BUFFER_QUEUE, reinterpret_cast(&fwBuffer), sizeof(Fw::Buffer)); @@ -156,7 +157,7 @@ void ComQueue::comStatusIn_handler(const FwIndexType portNum, Fw::Success& condi this->m_state = READY; this->processQueue(); // A message may or may not be sent. Thus, READY or WAITING are acceptable final states. - FW_ASSERT((this->m_state == WAITING || this->m_state == READY), this->m_state); + FW_ASSERT((this->m_state == WAITING || this->m_state == READY), static_cast(this->m_state)); } else { this->m_state = WAITING; } @@ -164,7 +165,7 @@ void ComQueue::comStatusIn_handler(const FwIndexType portNum, Fw::Success& condi // Both READY and unknown states should not be possible at this point. To receive a status message we must be // one of the WAITING or RETRY states. default: - FW_ASSERT(0, this->m_state); + FW_ASSERT(0, static_cast(this->m_state)); break; } } @@ -192,7 +193,7 @@ void ComQueue::run_handler(const FwIndexType portNum, U32 context) { // ---------------------------------------------------------------------- void ComQueue::buffQueueIn_overflowHook(FwIndexType portNum, Fw::Buffer& fwBuffer) { - FW_ASSERT(portNum >= 0 && portNum < BUFFER_PORT_COUNT, portNum); + FW_ASSERT(portNum >= 0 && portNum < BUFFER_PORT_COUNT, static_cast(portNum)); this->deallocate_out(portNum, fwBuffer); } @@ -204,13 +205,15 @@ bool ComQueue::enqueue(const FwIndexType queueNum, QueueType queueType, const U8 // Enqueue the given message onto the matching queue. When no space is available then emit the queue overflow event, // set the appropriate throttle, and move on. Will assert if passed a message for a depth 0 queue. const FwSizeType expectedSize = (queueType == QueueType::COM_QUEUE) ? sizeof(Fw::ComBuffer) : sizeof(Fw::Buffer); - const FwIndexType portNum = queueNum - ((queueType == QueueType::COM_QUEUE) ? 0 : COM_PORT_COUNT); + FW_ASSERT((queueType == QueueType::COM_QUEUE) || (queueNum >= COM_PORT_COUNT), + static_cast(queueType), static_cast(queueNum)); + const FwIndexType portNum = static_cast(queueNum - ((queueType == QueueType::COM_QUEUE) ? 0 : COM_PORT_COUNT)); bool rvStatus = true; FW_ASSERT( expectedSize == size, static_cast(size), static_cast(expectedSize)); - FW_ASSERT(portNum >= 0, portNum); + FW_ASSERT(portNum >= 0, static_cast(portNum)); Fw::SerializeStatus status = this->m_queues[queueNum].enqueue(data, size); if (status == Fw::FW_SERIALIZE_NO_ROOM_LEFT) { if (!this->m_throttle[queueNum]) { diff --git a/Svc/DpCatalog/DpCatalog.cpp b/Svc/DpCatalog/DpCatalog.cpp index 572db44c73..ca27d56792 100644 --- a/Svc/DpCatalog/DpCatalog.cpp +++ b/Svc/DpCatalog/DpCatalog.cpp @@ -14,7 +14,8 @@ #include // placement new namespace Svc { - + static_assert(DP_MAX_DIRECTORIES > 0, "Configuration DP_MAX_DIRECTORIES must be positive"); + static_assert(DP_MAX_FILES > 0, "Configuration DP_MAX_FILES must be positive"); // ---------------------------------------------------------------------- // Component construction and destruction // ---------------------------------------------------------------------- @@ -321,7 +322,7 @@ namespace Svc { void DpCatalog::appendFileState(const DpStateEntry& entry) { FW_ASSERT(this->m_stateFileData); FW_ASSERT(entry.dir < static_cast(this->m_numDirectories), - entry.dir, + static_cast(entry.dir), static_cast(this->m_numDirectories) ); @@ -459,7 +460,7 @@ namespace Svc { static_cast(this->m_numDpSlots - totalFiles)); // extract metadata for each file - for (FwNativeUIntType file = 0; file < filesRead; file++) { + for (FwSizeType file = 0; file < filesRead; file++) { // only consider files with the DP extension diff --git a/Svc/DpCatalog/test/ut/DpCatalogTester.cpp b/Svc/DpCatalog/test/ut/DpCatalogTester.cpp index 68b76f4364..ad554f5927 100644 --- a/Svc/DpCatalog/test/ut/DpCatalogTester.cpp +++ b/Svc/DpCatalog/test/ut/DpCatalogTester.cpp @@ -204,7 +204,7 @@ namespace Svc { size = dataSize; stat = dpFile.write(dpData,size); if (stat != Os::File::Status::OP_OK) { - printf("Error writing DP file data %s: status: %" PRI_FwNativeIntType "\n",fileName.toChar(),stat); + printf("Error writing DP file data %s: status: %" PRI_FwEnumStoreType "\n",fileName.toChar(),static_cast(stat)); return; } if (static_cast(size) != dataSize) { diff --git a/Svc/FileDownlink/FileDownlink.cpp b/Svc/FileDownlink/FileDownlink.cpp index 8d43b94b2a..b66b2f1684 100644 --- a/Svc/FileDownlink/FileDownlink.cpp +++ b/Svc/FileDownlink/FileDownlink.cpp @@ -61,7 +61,7 @@ namespace Svc { static_cast(fileQueueDepth), static_cast(sizeof(struct FileEntry)) ); - FW_ASSERT(stat == Os::Queue::OP_OK, stat); + FW_ASSERT(stat == Os::Queue::OP_OK, static_cast(stat)); } void FileDownlink :: @@ -191,7 +191,8 @@ namespace Svc { return; } //Non-ignored buffers cannot be returned in "DOWNLINK" and "IDLE" state. Only in "WAIT", "CANCEL" state. - FW_ASSERT(this->m_mode.get() == Mode::WAIT || this->m_mode.get() == Mode::CANCEL, this->m_mode.get()); + FW_ASSERT(this->m_mode.get() == Mode::WAIT || this->m_mode.get() == Mode::CANCEL, + static_cast(this->m_mode.get())); //If the last packet has been sent (and is returning now) then finish the file if (this->m_lastCompletedType == Fw::FilePacket::T_END || this->m_lastCompletedType == Fw::FilePacket::T_CANCEL) { @@ -494,8 +495,9 @@ namespace Svc { void FileDownlink :: downlinkPacket() { - FW_ASSERT(this->m_lastCompletedType != Fw::FilePacket::T_NONE, this->m_lastCompletedType); - FW_ASSERT(this->m_mode.get() == Mode::CANCEL || this->m_mode.get() == Mode::DOWNLINK, this->m_mode.get()); + FW_ASSERT(this->m_lastCompletedType != Fw::FilePacket::T_NONE, static_cast(this->m_lastCompletedType)); + FW_ASSERT(this->m_mode.get() == Mode::CANCEL || this->m_mode.get() == Mode::DOWNLINK, + static_cast(this->m_mode.get())); //If canceled mode and currently downlinking data then send a cancel packet if (this->m_mode.get() == Mode::CANCEL && this->m_lastCompletedType == Fw::FilePacket::T_START) { this->sendCancelPacket(); @@ -540,7 +542,7 @@ namespace Svc { getBuffer(Fw::Buffer& buffer, PacketType type) { //Check type is correct - FW_ASSERT(type < COUNT_PACKET_TYPE && type >= 0, type); + FW_ASSERT(type < COUNT_PACKET_TYPE && type >= 0, static_cast(type)); // Wrap the buffer around our indexed memory. buffer.setData(this->m_memoryStore[type]); buffer.setSize(FILEDOWNLINK_INTERNAL_BUFFER_SIZE); diff --git a/Svc/FrameAccumulator/test/ut/detectors/FprimeFrameDetectorTestMain.cpp b/Svc/FrameAccumulator/test/ut/detectors/FprimeFrameDetectorTestMain.cpp index 984bee4c92..a445fc3d5e 100644 --- a/Svc/FrameAccumulator/test/ut/detectors/FprimeFrameDetectorTestMain.cpp +++ b/Svc/FrameAccumulator/test/ut/detectors/FprimeFrameDetectorTestMain.cpp @@ -16,8 +16,8 @@ constexpr U32 CIRCULAR_BUFFER_TEST_SIZE = 2048; //! \note The frame is generated with random data of random size //! \return The size of the generated frame FwSizeType generate_random_fprime_frame(Types::CircularBuffer& circular_buffer) { - constexpr FwIndexType FRAME_HEADER_SIZE = 8; - constexpr FwIndexType FRAME_FOOTER_SIZE = 4; + constexpr FwSizeType FRAME_HEADER_SIZE = 8; + constexpr FwSizeType FRAME_FOOTER_SIZE = 4; // Generate random packet size (1-1024 bytes; because 0 would trigger undefined behavior warnings) // 1024 is max length as per FrameAccumulator/FrameDetector/FprimeFrameDetector @ LengthToken::MaximumLength U32 packet_size = STest::Random::lowerUpper(1, 1024); @@ -46,15 +46,15 @@ FwSizeType generate_random_fprime_frame(Types::CircularBuffer& circular_buffer) FwSizeType fprime_frame_size = FRAME_HEADER_SIZE + packet_size + FRAME_FOOTER_SIZE; U8 fprime_frame[fprime_frame_size]; // Copy header, packet_data, and CRC into the full frame - for (FwIndexType i = 0; i < static_cast(FRAME_HEADER_SIZE); i++) { + for (FwSizeType i = 0; i < static_cast(FRAME_HEADER_SIZE); i++) { fprime_frame[i] = frame_header[i]; } - for (FwIndexType i = 0; i < static_cast(packet_size); i++) { + for (FwSizeType i = 0; i < static_cast(packet_size); i++) { fprime_frame[i + FRAME_HEADER_SIZE] = packet_data[i]; } - for (FwIndexType i = 0; i < static_cast(FRAME_FOOTER_SIZE); i++) { + for (FwSizeType i = 0; i < static_cast(FRAME_FOOTER_SIZE); i++) { // crc is a U32; unpack into 4 bytes (shift by 24->-16->8->0 bits, mask with 0xFF) - fprime_frame[i + FRAME_HEADER_SIZE + static_cast(packet_size)] = + fprime_frame[i + FRAME_HEADER_SIZE + static_cast(packet_size)] = static_cast((crc_result.asBigEndianU32() >> (8 * (3 - i))) & 0xFF); } // Serialize frame into circular buffer @@ -62,7 +62,7 @@ FwSizeType generate_random_fprime_frame(Types::CircularBuffer& circular_buffer) // Uncomment for debugging // printf("Serialized %llu bytes:\n", fprime_frame_size); - // for (FwIndexType i = 0; i < static_cast(fprime_frame_size); i++) { + // for (FwSizeType i = 0; i < static_cast(fprime_frame_size); i++) { // printf("%02X ", fprime_frame[i]); // } return fprime_frame_size; diff --git a/Svc/PassiveRateGroup/PassiveRateGroup.cpp b/Svc/PassiveRateGroup/PassiveRateGroup.cpp index 04bd27aa16..7643483695 100644 --- a/Svc/PassiveRateGroup/PassiveRateGroup.cpp +++ b/Svc/PassiveRateGroup/PassiveRateGroup.cpp @@ -25,10 +25,12 @@ PassiveRateGroup::~PassiveRateGroup() {} void PassiveRateGroup::configure(U32 contexts[], FwIndexType numContexts) { FW_ASSERT(contexts); - FW_ASSERT(numContexts == this->getNum_RateGroupMemberOut_OutputPorts(),numContexts,this->getNum_RateGroupMemberOut_OutputPorts()); + FW_ASSERT(numContexts == this->getNum_RateGroupMemberOut_OutputPorts(), + static_cast(numContexts), + static_cast(this->getNum_RateGroupMemberOut_OutputPorts())); FW_ASSERT(FW_NUM_ARRAY_ELEMENTS(this->m_contexts) == this->getNum_RateGroupMemberOut_OutputPorts(), - FW_NUM_ARRAY_ELEMENTS(this->m_contexts), - this->getNum_RateGroupMemberOut_OutputPorts()); + static_cast(FW_NUM_ARRAY_ELEMENTS(this->m_contexts)), + static_cast(this->getNum_RateGroupMemberOut_OutputPorts())); this->m_numContexts = numContexts; // copy context values diff --git a/Svc/SeqDispatcher/SeqDispatcher.cpp b/Svc/SeqDispatcher/SeqDispatcher.cpp index 51d64d4b86..881f54d024 100644 --- a/Svc/SeqDispatcher/SeqDispatcher.cpp +++ b/Svc/SeqDispatcher/SeqDispatcher.cpp @@ -33,11 +33,11 @@ void SeqDispatcher::runSequence(FwIndexType sequencerIdx, // this function is only designed for internal usage // we can guarantee it cannot be called with input that would fail FW_ASSERT(sequencerIdx >= 0 && sequencerIdx < SeqDispatcherSequencerPorts, - sequencerIdx); + static_cast(sequencerIdx)); FW_ASSERT(this->isConnected_seqRunOut_OutputPort(sequencerIdx)); FW_ASSERT(this->m_entryTable[sequencerIdx].state == SeqDispatcher_CmdSequencerState::AVAILABLE, - this->m_entryTable[sequencerIdx].state); + static_cast(this->m_entryTable[sequencerIdx].state)); if (block == Fw::Wait::NO_WAIT) { this->m_entryTable[sequencerIdx].state = @@ -61,7 +61,8 @@ void SeqDispatcher::seqStartIn_handler( FwIndexType portNum, //!< The port number const Fw::StringBase& fileName //!< The sequence file name ) { - FW_ASSERT(portNum >= 0 && portNum < SeqDispatcherSequencerPorts, portNum); + FW_ASSERT(portNum >= 0 && portNum < SeqDispatcherSequencerPorts, + static_cast(portNum)); if (this->m_entryTable[portNum].state == SeqDispatcher_CmdSequencerState::RUNNING_SEQUENCE_BLOCK || this->m_entryTable[portNum].state == @@ -96,7 +97,8 @@ void SeqDispatcher::seqDoneIn_handler( U32 cmdSeq, //!< Command Sequence const Fw::CmdResponse& response //!< The command response argument ) { - FW_ASSERT(portNum >= 0 && portNum < SeqDispatcherSequencerPorts, portNum); + FW_ASSERT(portNum >= 0 && portNum < SeqDispatcherSequencerPorts, + static_cast(portNum)); if (this->m_entryTable[portNum].state != SeqDispatcher_CmdSequencerState::RUNNING_SEQUENCE_BLOCK && this->m_entryTable[portNum].state != diff --git a/Svc/StaticMemory/StaticMemoryComponentImpl.cpp b/Svc/StaticMemory/StaticMemoryComponentImpl.cpp index ac3921b60f..3369bab421 100644 --- a/Svc/StaticMemory/StaticMemoryComponentImpl.cpp +++ b/Svc/StaticMemory/StaticMemoryComponentImpl.cpp @@ -38,7 +38,7 @@ StaticMemoryComponentImpl ::~StaticMemoryComponentImpl() {} void StaticMemoryComponentImpl ::bufferDeallocate_handler(const FwIndexType portNum, Fw::Buffer& fwBuffer) { FW_ASSERT(portNum < static_cast(FW_NUM_ARRAY_ELEMENTS(m_static_memory))); - FW_ASSERT(m_allocated[portNum], portNum); // It is also an error to deallocate before returning + FW_ASSERT(m_allocated[portNum], static_cast(portNum)); // It is also an error to deallocate before returning // Check the memory returned is within the region FW_ASSERT(fwBuffer.getData() >= m_static_memory[portNum]); FW_ASSERT( @@ -51,7 +51,7 @@ void StaticMemoryComponentImpl ::bufferDeallocate_handler(const FwIndexType port Fw::Buffer StaticMemoryComponentImpl ::bufferAllocate_handler(const FwIndexType portNum, Fw::Buffer::SizeType size) { FW_ASSERT(portNum < static_cast(FW_NUM_ARRAY_ELEMENTS(m_static_memory))); FW_ASSERT(size <= sizeof(m_static_memory[portNum])); // It is a topology error to ask for too much from this component - FW_ASSERT(not m_allocated[portNum], portNum); // It is also an error to allocate again before returning + FW_ASSERT(not m_allocated[portNum], static_cast(portNum)); // It is also an error to allocate again before returning m_allocated[portNum] = true; Fw::Buffer buffer(m_static_memory[portNum], sizeof(m_static_memory[0])); return buffer; diff --git a/cmake/platform/types/PlatformTypes.h b/cmake/platform/types/PlatformTypes.h index f2312d95a1..593f08db0c 100644 --- a/cmake/platform/types/PlatformTypes.h +++ b/cmake/platform/types/PlatformTypes.h @@ -48,23 +48,23 @@ typedef int PlatformIntType; typedef unsigned int PlatformUIntType; #define PRI_PlatformUIntType "u" -typedef PlatformIntType PlatformIndexType; -#define PRI_PlatformIndexType PRI_PlatformIntType +typedef int16_t PlatformIndexType; +#define PRI_PlatformIndexType PRIi16 typedef int64_t PlatformSignedSizeType; -#define PRI_PlatformSignedSizeType PRId64 +#define PRI_PlatformSignedSizeType PRIi64 typedef uint64_t PlatformSizeType; #define PRI_PlatformSizeType PRIu64 -typedef PlatformIntType PlatformAssertArgType; -#define PRI_PlatformAssertArgType PRI_PlatformIntType +typedef int32_t PlatformAssertArgType; +#define PRI_PlatformAssertArgType PRIi32 -typedef PlatformIntType PlatformTaskPriorityType; -#define PRI_PlatformTaskPriorityType PRI_PlatformIntType +typedef uint8_t PlatformTaskPriorityType; +#define PRI_PlatformTaskPriorityType PRIu8 -typedef PlatformIntType PlatformQueuePriorityType; -#define PRI_PlatformQueuePriorityType PRI_PlatformIntType +typedef uint8_t PlatformQueuePriorityType; +#define PRI_PlatformQueuePriorityType PRIu8 // Linux/Darwin definitions for pointer have various sizes across platforms // and since these definitions need to be consistent we must ask the size. diff --git a/config/DpCatalogCfg.hpp b/config/DpCatalogCfg.hpp index f4406c1312..916c9c69e9 100644 --- a/config/DpCatalogCfg.hpp +++ b/config/DpCatalogCfg.hpp @@ -13,8 +13,8 @@ namespace Svc { // data products can be stored. The array passed // to the initializer for DpCatalog cannot exceed // this size. - static const FwSizeType DP_MAX_DIRECTORIES = 2; - static const FwSizeType DP_MAX_FILES = 1000; + static const FwIndexType DP_MAX_DIRECTORIES = 2; + static const FwIndexType DP_MAX_FILES = 127; } #endif /* SVC_DPCATALOG_CONFIG_HPP_ */ diff --git a/config/FpConfig.h b/config/FpConfig.h index 67be98e03a..f4fe1818d6 100644 --- a/config/FpConfig.h +++ b/config/FpConfig.h @@ -39,14 +39,6 @@ typedef PlatformSizeType FwSizeType; typedef PlatformAssertArgType FwAssertArgType; #define PRI_FwAssertArgType PRI_PlatformAssertArgType -// The type of a machine integer. Ordinarily this should be int. -typedef PlatformIntType FwNativeIntType; -#define PRI_FwNativeIntType PRI_PlatformIntType - -// The type of a machine unsigned integer. Ordinarily this should be unsigned int. -typedef PlatformUIntType FwNativeUIntType; -#define PRI_FwNativeUIntType PRI_PlatformUIntType - // Task priority type typedef PlatformTaskPriorityType FwTaskPriorityType; #define PRI_FwTaskPriorityType PRI_PlatformTaskPriorityType