Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue 2457 #2502

Merged
merged 44 commits into from
Feb 28, 2024
Merged
Show file tree
Hide file tree
Changes from 42 commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
7778cac
Os::File refactor: open w/ basic stub, posix UTs
LeStarch Dec 22, 2023
57b2574
Refactoring Os::File for all methods, less UTs
LeStarch Jan 6, 2024
a45d3bf
Adding rules-based common tests
LeStarch Jan 11, 2024
5fb8bb6
Fixing posix file for common UTs
LeStarch Jan 11, 2024
7050e03
Adding WriteRead and WriteReadSeek tests
LeStarch Jan 17, 2024
194afa8
Working random tests
LeStarch Jan 18, 2024
9d0ba81
Working randomized tests and stub testing
LeStarch Jan 23, 2024
f6f6c20
Fixing PrmDb unit tests
LeStarch Jan 24, 2024
0f6668a
Updating files to used FwSignedSizeType
LeStarch Jan 24, 2024
3a9f842
Factoring out the synthetic file system
LeStarch Jan 25, 2024
4434946
Initial work on CmdSequencer UTs
LeStarch Jan 25, 2024
e7740f8
Fixing linux implementation
LeStarch Jan 25, 2024
0f3c3b1
Newlines at end of file
LeStarch Jan 25, 2024
8d8bdd7
sp
LeStarch Jan 25, 2024
c2d19e2
Static analysis checks
LeStarch Jan 25, 2024
abdea47
Changing API to use enums
LeStarch Jan 25, 2024
65c093c
Refactoring for proper class tree
LeStarch Jan 31, 2024
94caa43
CmdSequencer UTs - WIP
LeStarch Feb 1, 2024
758cd81
CmdSequencer UTs work
LeStarch Feb 2, 2024
eed64c7
Adding copy constructor functionality
LeStarch Feb 2, 2024
cc448d0
Spelling and static analysis fixes
LeStarch Feb 2, 2024
f36c968
Copy constructor/assignment operator UTs and fixes
LeStarch Feb 2, 2024
3b66c84
Initial CRC work
LeStarch Feb 4, 2024
0135d84
Working CRC and FPP models
LeStarch Feb 5, 2024
aa8a735
Minor UT fixes
LeStarch Feb 5, 2024
b15e15f
Correcting CMake choices implementation
LeStarch Feb 6, 2024
9734c3b
MAking implementation choices real dependencies
LeStarch Feb 8, 2024
4738c07
Fixing implementation to use source files
LeStarch Feb 8, 2024
11b3899
Fixing posix file read/write permissions
LeStarch Feb 8, 2024
57b1352
Allowing None implementations
LeStarch Feb 8, 2024
b5fbffc
Fixed CI breakages
LeStarch Feb 8, 2024
2325eb7
Fixing MyRules.hpp formatting
LeStarch Feb 8, 2024
af417fc
Minor CRC unit test fix
LeStarch Feb 8, 2024
86bb30b
Removing direct write support
LeStarch Feb 9, 2024
fa19e9f
Changing get delegate to static method of interface
LeStarch Feb 13, 2024
aebeaa2
Replacing old comments with new comments
LeStarch Feb 14, 2024
23e6b3c
Fixing friend regression
LeStarch Feb 14, 2024
91d9bc3
Review fixes
LeStarch Feb 15, 2024
70bdb94
Fixing serialization method usages
LeStarch Feb 27, 2024
3ff666d
Review fixes
LeStarch Feb 27, 2024
6891e65
Fixing RPI build
LeStarch Feb 27, 2024
15a950e
Fixing FwBuffSizeType overflow
LeStarch Feb 28, 2024
fdd538f
Fixing review comment
LeStarch Feb 28, 2024
6e38fc2
Renaming FwExternalSize -> FwSizeStoreType
LeStarch Feb 28, 2024
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
8 changes: 8 additions & 0 deletions Fw/Cfg/ConfigCheck.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
*/

#include <FpConfig.hpp>
#include <limits>

// Check that command/telemetry strings are not larger than an argument buffer

Expand All @@ -23,3 +24,10 @@ static_assert(FW_PARAM_STRING_MAX_SIZE <= FW_PARAM_BUFFER_MAX_SIZE, "FW_PARAM_ST
// value.
static_assert((FW_ENABLE_TEXT_LOGGING == 0) || ( FW_SERIALIZABLE_TO_STRING == 1), "FW_SERIALIZABLE_TO_STRING must be enabled to enable FW_ENABLE_TEXT_LOGGING");

static_assert(std::numeric_limits<FwBuffSizeType>::max() == std::numeric_limits<FwExternalSizeType>::max() &&
std::numeric_limits<FwBuffSizeType>::min() == std::numeric_limits<FwExternalSizeType>::min(),
"FwBuffSizeType must be equivalent to FwExternalSizeType");

static_assert(std::numeric_limits<FwSizeType>::max() >= std::numeric_limits<FwExternalSizeType>::max() &&
std::numeric_limits<FwSizeType>::min() <= std::numeric_limits<FwExternalSizeType>::min(),
"FwSizeType cannot entirely store values of type FwExternalSizeType");
7 changes: 3 additions & 4 deletions Fw/Dp/DpContainer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,9 @@ Fw::SerializeStatus DpContainer::deserializeHeader() {
}
// Deserialize the user data
if (status == Fw::FW_SERIALIZE_OK) {
const bool omitLength = true;
const FwSizeType requestedSize = sizeof this->m_userData;
FwSizeType receivedSize = requestedSize;
status = serializeRepr.deserialize(this->m_userData, receivedSize, omitLength);
status = serializeRepr.deserialize(this->m_userData, receivedSize, Fw::Serialization::OMIT_LENGTH);
if (receivedSize != requestedSize) {
status = Fw::FW_DESERIALIZE_SIZE_MISMATCH;
}
Expand Down Expand Up @@ -111,8 +110,8 @@ void DpContainer::serializeHeader() {
status = serializeRepr.serialize(this->m_procTypes);
FW_ASSERT(status == Fw::FW_SERIALIZE_OK, static_cast<FwAssertArgType>(status));
// Serialize the user data
const bool omitLength = true;
status = serializeRepr.serialize(this->m_userData, sizeof this->m_userData, omitLength);
status = serializeRepr.serialize(this->m_userData, static_cast<FwSizeType>(sizeof this->m_userData),
Fw::Serialization::OMIT_LENGTH);
FW_ASSERT(status == Fw::FW_SERIALIZE_OK, static_cast<FwAssertArgType>(status));
// Serialize the data product state
status = serializeRepr.serialize(this->m_dpState);
Expand Down
9 changes: 3 additions & 6 deletions Fw/SerializableFile/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,10 @@ set(SOURCE_FILES
"${CMAKE_CURRENT_LIST_DIR}/SerializableFile.cpp"
)
set(MOD_DEPS
Fw/Cfg
Fw/Types
Fw/Cfg
Fw/Types
Os
)
# For shared libraries, Os must exist in the module list
if (BUILD_SHARED_LIBS)
list(APPEND MOD_DEPS "Os")
endif()
register_fprime_module()
### UTs ###
set(UT_SOURCE_FILES
Expand Down
14 changes: 6 additions & 8 deletions Fw/SerializableFile/SerializableFile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@
return FILE_OPEN_ERROR;
}

NATIVE_INT_TYPE capacity = this->m_buffer.getBuffCapacity();
NATIVE_INT_TYPE length = capacity;
status = file.read(this->m_buffer.getBuffAddr(), length, false);
FwSignedSizeType capacity = static_cast<FwSignedSizeType>(this->m_buffer.getBuffCapacity());

Check notice

Code scanning / CodeQL

Use of basic integral type Note

capacity uses the basic integral type signed long rather than a typedef with size and signedness.
FwSignedSizeType length = static_cast<FwSignedSizeType>(capacity);

Check notice

Code scanning / CodeQL

Use of basic integral type Note

length uses the basic integral type signed long rather than a typedef with size and signedness.
status = file.read(this->m_buffer.getBuffAddr(), length, Os::File::WaitType::NO_WAIT);
if( Os::File::OP_OK != status ) {
file.close();
return FILE_READ_ERROR;
Expand Down Expand Up @@ -72,12 +72,10 @@
return FILE_OPEN_ERROR;
}

NATIVE_INT_TYPE length = this->m_buffer.getBuffLength();
NATIVE_INT_TYPE size = length;
FwSignedSizeType length = static_cast<FwSignedSizeType>(this->m_buffer.getBuffLength());

Check notice

Code scanning / CodeQL

Use of basic integral type Note

length uses the basic integral type signed long rather than a typedef with size and signedness.
FwSignedSizeType size = length;

Check notice

Code scanning / CodeQL

Use of basic integral type Note

size uses the basic integral type signed long rather than a typedef with size and signedness.
status = file.write(this->m_buffer.getBuffAddr(), length);
if( (Os::File::OP_OK != status) ||
(length != size) )
{
if( (Os::File::OP_OK != status) || (length != size)) {
file.close();
return FILE_WRITE_ERROR;
}
Expand Down
28 changes: 25 additions & 3 deletions Fw/Types/Serializable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -234,10 +234,18 @@ namespace Fw {

}

SerializeStatus SerializeBufferBase::serialize(const U8* buff, NATIVE_UINT_TYPE length) {
return this->serialize(buff, static_cast<FwSizeType>(length), Serialization::INCLUDE_LENGTH);
}

SerializeStatus SerializeBufferBase::serialize(const U8* buff, NATIVE_UINT_TYPE length, bool noLength) {
return this->serialize(buff, static_cast<FwSizeType>(length), noLength ? Serialization::OMIT_LENGTH : Serialization::INCLUDE_LENGTH);
}

SerializeStatus SerializeBufferBase::serialize(const U8* buff, FwSizeType length, Fw::Serialization::t mode) {
// First serialize length
SerializeStatus stat;
if (not noLength) {
if (mode == Serialization::INCLUDE_LENGTH) {
stat = this->serialize(static_cast<FwBuffSizeType>(length));
if (stat != FW_SERIALIZE_OK) {
return stat;
Expand Down Expand Up @@ -499,11 +507,25 @@ namespace Fw {
return FW_SERIALIZE_OK;
}

SerializeStatus SerializeBufferBase::deserialize(U8* buff, NATIVE_UINT_TYPE& length) {
FwSizeType length_in_out = static_cast<FwSizeType>(length);
SerializeStatus status = this->deserialize(buff, length_in_out, Serialization::INCLUDE_LENGTH);
length = static_cast<NATIVE_UINT_TYPE>(length_in_out);
return status;
}

SerializeStatus SerializeBufferBase::deserialize(U8* buff, NATIVE_UINT_TYPE& length, bool noLength) {
FwSizeType length_in_out = static_cast<FwSizeType>(length);
SerializeStatus status = this->deserialize(buff, length_in_out, noLength ? Serialization::OMIT_LENGTH : Serialization::INCLUDE_LENGTH);
length = static_cast<NATIVE_UINT_TYPE>(length_in_out);
return status;
}

SerializeStatus SerializeBufferBase::deserialize(U8* buff, FwSizeType& length, Serialization::t mode) {

FW_ASSERT(this->getBuffAddr());

if (not noLength) {
if (mode == Serialization::INCLUDE_LENGTH) {
FwBuffSizeType storedLength;

SerializeStatus stat = this->deserialize(storedLength);
Expand All @@ -519,7 +541,7 @@ namespace Fw {

(void) memcpy(buff, &this->getBuffAddr()[this->m_deserLoc], storedLength);

length = static_cast<NATIVE_UINT_TYPE>(storedLength);
length = static_cast<FwSizeType>(storedLength);

} else {
// make sure enough is left
Expand Down
47 changes: 41 additions & 6 deletions Fw/Types/Serializable.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#endif

#include <FpConfig.hpp>
#include "Fw/Deprecate.hpp"

namespace Fw {

Expand Down Expand Up @@ -38,6 +39,14 @@ namespace Fw {
virtual ~Serializable(); //!< destructor
};

class Serialization {
public:
enum t {
INCLUDE_LENGTH, //!< Include length as first token in serialization
OMIT_LENGTH //!< Omit length from serialization
};
};

class SerializeBufferBase {
public:

Expand Down Expand Up @@ -70,7 +79,21 @@ namespace Fw {

SerializeStatus serialize(const void* val); //!< serialize pointer (careful, only pointer value, not contents are serialized)

SerializeStatus serialize(const U8* buff, NATIVE_UINT_TYPE length, bool noLength = false); //!< serialize data buffer
//! serialize data buffer
SerializeStatus serialize(const U8* buff, NATIVE_UINT_TYPE length, bool noLength);
//! serialize data buffer
SerializeStatus serialize(const U8* buff, NATIVE_UINT_TYPE length);

//! \brief serialize a byte buffer of a given length
//!
//! Serialize bytes from `buff` up to `length`. If `serializationMode` is set to `INCLUDE_LENGTH` then the
//! length is included as the first token. Length may be omitted with `OMIT_LENGTH`.
//!
//! \param buff: buffer to serialize
//! \param length: length of data to serialize
//! \param mode: serialization type
//! \return status of serialization
SerializeStatus serialize(const U8* buff, FwSizeType length, Serialization::t mode);

SerializeStatus serialize(const SerializeBufferBase& val); //!< serialize a serialized buffer

Expand Down Expand Up @@ -102,11 +125,23 @@ namespace Fw {

SerializeStatus deserialize(void*& val); //!< deserialize point value (careful, pointer value only, not contents)

// length should be set to max, returned value is actual size stored. If noLength
// is true, use the length variable as the actual number of bytes to deserialize
SerializeStatus deserialize(U8* buff, NATIVE_UINT_TYPE& length, bool noLength = false); //!< deserialize data buffer
// serialize/deserialize Serializable

//! deserialize data buffer
SerializeStatus deserialize(U8* buff, NATIVE_UINT_TYPE& length, bool noLength);

//! deserialize data buffer
SerializeStatus deserialize(U8* buff, NATIVE_UINT_TYPE& length);
//! \brief deserialize a byte buffer of a given length
//!
//! Deserialize bytes into `buff` of `length` bytes. If `serializationMode` is set to `INCLUDE_LENGTH` then
//! the length is deserialized first followed by the bytes. Length may be omitted with `OMIT_LENGTH` and
//! in this case `length` bytes will be deserialized. `length` will be filled with the amount of data
//! deserialized.
//!
//! \param buff: buffer to hold deserialized data
//! \param length: length of data to deserialize length is filled with deserialized length
//! \param mode: deserialization type
//! \return status of serialization
SerializeStatus deserialize(U8* buff, FwSizeType& length, Serialization::t mode);

SerializeStatus deserialize(Serializable &val); //!< deserialize an object derived from serializable base class

Expand Down
22 changes: 14 additions & 8 deletions Os/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,15 @@
# MOD_DEPS: (optional) module dependencies
#
####
add_fprime_subdirectory("${CMAKE_CURRENT_LIST_DIR}/Models")
add_fprime_subdirectory("${CMAKE_CURRENT_LIST_DIR}/Stub")
add_fprime_subdirectory("${CMAKE_CURRENT_LIST_DIR}/Posix")

set(SOURCE_FILES
"${CMAKE_CURRENT_LIST_DIR}/test/ut/file/SyntheticFileSystem.cpp"
)
register_fprime_module(Os_Test_File_SyntheticFileSystem)


# Basic module dependencies
set(MOD_DEPS
Expand All @@ -26,7 +35,9 @@ set(SOURCE_FILES
"${CMAKE_CURRENT_LIST_DIR}/MemCommon.cpp"
"${CMAKE_CURRENT_LIST_DIR}/ValidateFileCommon.cpp"
"${CMAKE_CURRENT_LIST_DIR}/ValidatedFile.cpp"
"${CMAKE_CURRENT_LIST_DIR}/FileCommon.cpp"

# Refactored common files
"${CMAKE_CURRENT_LIST_DIR}/File.cpp"
)
# Check for default logger
if (NOT FPRIME_DISABLE_DEFAULT_LOGGER)
Expand All @@ -42,7 +53,6 @@ if (FPRIME_USE_POSIX)
"${CMAKE_CURRENT_LIST_DIR}/Pthreads/BufferQueueCommon.cpp"
"${CMAKE_CURRENT_LIST_DIR}/Pthreads/PriorityBufferQueue.cpp"
"${CMAKE_CURRENT_LIST_DIR}/Pthreads/MaxHeap/MaxHeap.cpp"
"${CMAKE_CURRENT_LIST_DIR}/Linux/File.cpp"
"${CMAKE_CURRENT_LIST_DIR}/Posix/Task.cpp"
"${CMAKE_CURRENT_LIST_DIR}/Linux/InterruptLock.cpp"
"${CMAKE_CURRENT_LIST_DIR}/Linux/WatchdogTimer.cpp"
Expand Down Expand Up @@ -90,20 +100,16 @@ if (FPRIME_USE_BAREMETAL_SCHEDULER)
list(APPEND SOURCE_FILES "${CMAKE_CURRENT_LIST_DIR}/Baremetal/Task.cpp")
endif()
register_fprime_module()

# Add stubs directory for testing builds
if (BUILD_TESTING)
add_fprime_subdirectory("${CMAKE_CURRENT_LIST_DIR}/Stubs/")
endif()
require_fprime_implementation(Os/File)

### UTS ### Note: 3 separate UTs registered here.
set(UT_SOURCE_FILES
"${CMAKE_CURRENT_LIST_DIR}/test/ut/OsQueueTest.cpp"
"${CMAKE_CURRENT_LIST_DIR}/test/ut/OsTestMain.cpp"
"${CMAKE_CURRENT_LIST_DIR}/test/ut/IntervalTimerTest.cpp"
"${CMAKE_CURRENT_LIST_DIR}/test/ut/OsFileSystemTest.cpp"
"${CMAKE_CURRENT_LIST_DIR}/test/ut/OsValidateFileTest.cpp"
"${CMAKE_CURRENT_LIST_DIR}/test/ut/OsTaskTest.cpp"
"${CMAKE_CURRENT_LIST_DIR}/test/ut/OsFileSystemTest.cpp"
"${CMAKE_CURRENT_LIST_DIR}/test/ut/OsSystemResourcesTest.cpp"
"${CMAKE_CURRENT_LIST_DIR}/test/ut/OsMutexBasicLockableTest.cpp"
)
Expand Down
Loading
Loading