Skip to content

Commit

Permalink
Merge branch 'master' into development/jsonrpc-facilitate-lookup-events
Browse files Browse the repository at this point in the history
  • Loading branch information
pwielders authored Jan 14, 2025
2 parents 19388b0 + 2eafff8 commit a589773
Show file tree
Hide file tree
Showing 30 changed files with 655 additions and 72 deletions.
4 changes: 4 additions & 0 deletions Source/core/Portability.h
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,8 @@
#define DISABLE_WARNING_MAYBE_UNINITIALIZED
#define DISABLE_WARNING_FREE_NONHEAP_OBJECT
#define DISABLE_WARNING_ARRAY_BOUNDS
// Code Analysis - Unannotated fallthrough between switch labels
#define DISABLE_WARNING_IMPLICIT_FALLTHROUGH PUSH_WARNING_ARG_(26819)

#else
#define DISABLE_WARNING_CONDITIONAL_EXPRESSION_IS_CONSTANT
Expand Down Expand Up @@ -227,6 +229,8 @@
#define DISABLE_WARNING_MAYBE_UNINITIALIZED PUSH_WARNING_ARG_("-Wmaybe-uninitialized")
#define DISABLE_WARNING_FREE_NONHEAP_OBJECT PUSH_WARNING_ARG_("-Wfree-nonheap-object")
#define DISABLE_WARNING_ARRAY_BOUNDS PUSH_WARNING_ARG_("-Warray-bounds")
#define DISABLE_WARNING_IMPLICIT_FALLTHROUGH PUSH_WARNING_ARG_("-Wimplicit-fallthrough")

#endif

#if !(defined(__clang__)) && (__GNUC__ >= 4)
Expand Down
2 changes: 1 addition & 1 deletion Source/core/Serialization.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ namespace Thunder {
namespace Core {
PUSH_WARNING(DISABLE_WARNING_DEPRECATED_USE)

#ifndef __CORE_NO_WCHAR_SUPPORT__
void ToString(const wchar_t realString[], std::string& result)
{
#if defined(__WINDOWS__) || defined(__LINUX__)
Expand Down Expand Up @@ -81,6 +80,7 @@ PUSH_WARNING(DISABLE_WARNING_DEPRECATED_USE)
result = std::wstring(convertedText);
}

#ifndef __CORE_NO_WCHAR_SUPPORT__
string ToString(const wchar_t realString[], unsigned int length)
{
#ifdef _UNICODE
Expand Down
5 changes: 3 additions & 2 deletions Source/core/Serialization.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ namespace Core {
#endif
}

EXTERNAL void ToString(const wchar_t realstring[], std::string& result);
EXTERNAL void ToString(const char realstring[], std::wstring& result);

#ifndef __CORE_NO_WCHAR_SUPPORT__
inline int ToCharacter(const wchar_t* character, TCHAR converted[], unsigned int /* DUMMY JUST TO HAVE THE SAME IF */)
{
Expand All @@ -63,8 +66,6 @@ POP_WARNING()
#endif
}
EXTERNAL string ToString(const wchar_t realstring[], const unsigned int length);
EXTERNAL void ToString(const wchar_t realstring[], std::string& result);
EXTERNAL void ToString(const char realstring[], std::wstring& result);

inline void ToString(const wchar_t realstring[], std::wstring& result)
{
Expand Down
4 changes: 2 additions & 2 deletions Source/messaging/MessageDispatcher.h
Original file line number Diff line number Diff line change
Expand Up @@ -264,8 +264,8 @@ namespace Messaging {
return (_dataBuffer.IsValid());
}

void Validate() {
_dataBuffer.Open();
bool Validate() {
return (_dataBuffer.Open());
}

const string& MetadataName() const {
Expand Down
7 changes: 7 additions & 0 deletions Source/messaging/MessageUnit.h
Original file line number Diff line number Diff line change
Expand Up @@ -722,6 +722,13 @@ namespace Thunder {
return (_channel.IsOpen());
}

void Validate()
{
if ((IsValid() == false) && (MessageDataBuffer::Validate() == true)) {
_channel.Open(Core::infinite);
}
}

/**
* @brief Exchanges metadata with the server. Reader needs to register for notifications to recevie this message.
* Passed buffer will be filled with data from the other side
Expand Down
2 changes: 1 addition & 1 deletion Tests/cyclic-buffer/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
} \
RESULT = future.get();

int main(int argc, char* argv[])
int main(VARIABLE_IS_NOT_USED int argc, VARIABLE_IS_NOT_USED char* argv[])
{
using namespace WPEFramework::Core;

Expand Down
8 changes: 4 additions & 4 deletions Tests/cyclic-buffer/process.h
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ public :
fileName
, Core::File::USER_READ // Enable read permissions on the underlying file for other users
| Core::File::USER_WRITE // Enable write permission on the underlying file
| (requiredSharedBufferSize ? Core::File::CREATE : 0) // Create a new underlying memory mapped file
| (requiredSharedBufferSize ? static_cast<std::underlying_type<Core::File::Mode>::type>(Core::File::CREATE) : 0) // Create a new underlying memory mapped file
| Core::File::SHAREABLE // Allow other processes to access the content of the file
, requiredSharedBufferSize // Requested size
, false // Overwrite unread data
Expand Down Expand Up @@ -826,7 +826,7 @@ private :
}
case 0 : // Child
{
const struct timespec timeout = {.tv_sec = _setupTime, .tv_nsec = 0};
const struct timespec timeout{ _setupTime, 0};

std::array<status, 2> flags = {status::uninitialized, status::initialized};

Expand Down Expand Up @@ -924,7 +924,7 @@ private :

TRACE_L1(_T("Parent %ld has woken up %ld child(ren)."), gettid(), retval);

const struct timespec timeout = {.tv_sec = _setupTime, .tv_nsec = 0};
const struct timespec timeout{_setupTime, 0};

flags = {status::initialized, status::ready};

Expand Down Expand Up @@ -1015,8 +1015,8 @@ private :
std::array<uint8_t, 2> _childUsersSet;
std::array<uint8_t, 2> _parentUsersSet;

uint32_t _runTime; // Milliseconds
uint32_t _setupTime; // Seconds
uint32_t _runTime; // Milliseconds

uint8_t _numReservedBlocks;
};
Expand Down
58 changes: 32 additions & 26 deletions Tests/unit/core/test_cyclicbuffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -776,16 +776,18 @@ namespace Core {
EXPECT_EQ(buffer.Free(), static_cast<uint32_t>(cyclicBufferSize - size));

// Try overwrite with size of Free()
uint8_t data3[buffer.Free()];
memset(&data3, 'C', sizeof(data3));
size = sizeof(data3) + 2;
uint32_t count = buffer.Free();
uint8_t* data3 = new uint8_t[count];
memset(data3, 'C', count);
size = count + 2;
reserved = buffer.Reserve(size);
if (reserved == size) {
buffer.Write(reinterpret_cast<const uint8_t*>(&size), 2);
buffer.Write(reinterpret_cast<uint8_t*>(&data3), sizeof(data3));
buffer.Write(data3, count);
}
EXPECT_EQ(buffer.Used(), size);
EXPECT_EQ(buffer.Free(), static_cast<uint32_t>(cyclicBufferSize - size));
delete[] data3;

// Flush to start from beginning
buffer.Flush();
Expand Down Expand Up @@ -832,7 +834,7 @@ namespace Core {
static int ClonedProcessFunc(void* arg) {
Data* data = static_cast<Data*>(arg);
uint32_t cyclicBufferSize = 10;
uint32_t shareableFlag = (data->shareable == true) ? ::Thunder::Core::File::Mode::SHAREABLE : 0;
uint32_t shareableFlag = (data->shareable == true) ? static_cast<std::underlying_type<::Thunder::Core::File::Mode>::type>(::Thunder::Core::File::Mode::SHAREABLE) : 0;

::Thunder::Core::CyclicBuffer buffer(data->bufferName.c_str(),
::Thunder::Core::File::Mode::USER_READ | ::Thunder::Core::File::Mode::USER_WRITE | ::Thunder::Core::File::Mode::USER_EXECUTE |
Expand Down Expand Up @@ -874,7 +876,7 @@ namespace Core {
SetSharePermissionsFromClonedProcess(bufferName, shareable);

uint32_t cyclicBufferSize = 0;
uint32_t shareableFlag = (shareable == true) ? ::Thunder::Core::File::Mode::SHAREABLE : 0;
uint32_t shareableFlag = (shareable == true) ? static_cast<std::underlying_type<::Thunder::Core::File::Mode>::type>(::Thunder::Core::File::Mode::SHAREABLE) : 0;

::Thunder::Core::CyclicBuffer buffer(bufferName.c_str(),
::Thunder::Core::File::Mode::USER_READ | ::Thunder::Core::File::Mode::USER_WRITE |
Expand Down Expand Up @@ -907,7 +909,7 @@ namespace Core {
}
void SetSharePermissionsFromForkedProcessAndVerify(bool shareable, bool usingDataElementFile = false, uint32_t offset = 0)
{
constexpr uint32_t initHandshakeValue = 0, maxWaitTime = 4, maxWaitTimeMs = 4000, maxInitTime = 2000;
constexpr uint32_t initHandshakeValue = 0, maxWaitTime = 4, VARIABLE_IS_NOT_USED maxWaitTimeMs = 4000, maxInitTime = 2000;
constexpr uint8_t maxRetries = 1;

const std::string bufferName {"cyclicbuffer01"};
Expand All @@ -920,7 +922,7 @@ namespace Core {
| ::Thunder::Core::File::Mode::USER_EXECUTE
| ::Thunder::Core::File::Mode::GROUP_READ
| ::Thunder::Core::File::Mode::GROUP_WRITE
| (shareable ? ::Thunder::Core::File::Mode::SHAREABLE : 0)
| (shareable ? static_cast<std::underlying_type<::Thunder::Core::File::Mode>::type>(::Thunder::Core::File::Mode::SHAREABLE) : 0)
);

const struct Data data{shareable, usingDataElementFile, mode, offset, bufferName.c_str()};
Expand Down Expand Up @@ -1095,7 +1097,7 @@ namespace Core {
}
TEST(Core_CyclicBuffer, WithoutOverwriteUsingForksReversed)
{
constexpr uint32_t initHandshakeValue = 0, maxWaitTime = 4, maxWaitTimeMs = 4000, maxInitTime = 2000;
constexpr uint32_t initHandshakeValue = 0, maxWaitTime = 4, VARIABLE_IS_NOT_USED maxWaitTimeMs = 4000, maxInitTime = 2000;
constexpr uint8_t maxRetries = 1;

const std::string bufferName {"cyclicbuffer02"};
Expand Down Expand Up @@ -1228,7 +1230,7 @@ namespace Core {
}
TEST(Core_CyclicBuffer, WithOverWriteUsingFork)
{
constexpr uint32_t initHandshakeValue = 0, maxWaitTime = 4, maxWaitTimeMs = 4000, maxInitTime = 2000;
constexpr uint32_t initHandshakeValue = 0, maxWaitTime = 4, VARIABLE_IS_NOT_USED maxWaitTimeMs = 4000, maxInitTime = 2000;
constexpr uint8_t maxRetries = 1;

const std::string bufferName {"cyclicbuffer03"};
Expand Down Expand Up @@ -1343,7 +1345,7 @@ namespace Core {
}
TEST(Core_CyclicBuffer, WithOverwriteUsingForksReversed)
{
constexpr uint32_t initHandshakeValue = 0, maxWaitTime = 4, maxWaitTimeMs = 4000, maxInitTime = 2000;
constexpr uint32_t initHandshakeValue = 0, maxWaitTime = 4, VARIABLE_IS_NOT_USED maxWaitTimeMs = 4000, maxInitTime = 2000;
constexpr uint8_t maxRetries = 1;

const std::string bufferName {"cyclicbuffer03"};
Expand Down Expand Up @@ -1371,14 +1373,16 @@ namespace Core {
uint16_t size;
EXPECT_EQ(buffer.Read(reinterpret_cast<uint8_t*>(&size), 2), 2);

uint8_t loadBuffer[size + 1];
uint8_t* loadBuffer = new uint8_t[size + 1];

ASSERT_GE(size, 2);

uint32_t result = buffer.Read(loadBuffer, size - 2);
loadBuffer[result] = '\0';
EXPECT_EQ(result, size - 2);

delete[] loadBuffer;

ASSERT_EQ(testAdmin.Signal(initHandshakeValue, maxRetries), ::Thunder::Core::ERROR_NONE);

string data = "j";
Expand Down Expand Up @@ -1542,12 +1546,12 @@ namespace Core {

TEST(Core_CyclicBuffer, DISABLED_LockUnLock_FromParentAndForks)
{
constexpr uint32_t initHandshakeValue = 0, maxWaitTime = 4, maxWaitTimeMs = 4000, maxInitTime = 2000;
constexpr uint8_t maxRetries = 1;
constexpr uint32_t initHandshakeValue = 0, maxWaitTime = 4, VARIABLE_IS_NOT_USED maxWaitTimeMs = 4000, maxInitTime = 2000;
VARIABLE_IS_NOT_USED constexpr uint8_t maxRetries = 1;

std::string bufferName {"cyclicbuffer04"};

IPTestAdministrator::Callback callback_child = [&](IPTestAdministrator& testAdmin) {
IPTestAdministrator::Callback callback_child = [&](VARIABLE_IS_NOT_USED IPTestAdministrator& testAdmin) {
uint32_t cyclicBufferSize = 20;

const uint32_t mode =
Expand Down Expand Up @@ -1581,9 +1585,10 @@ namespace Core {
uint32_t result = buffer.Write(reinterpret_cast<const uint8_t*>(data.c_str()), data.size());
EXPECT_EQ(result, data.size());
EXPECT_EQ(buffer.Used(), data.size() * 2);
uint8_t loadBuffer[cyclicBufferSize + 1];
uint8_t* loadBuffer = new uint8_t[cyclicBufferSize + 1];
result = buffer.Peek(loadBuffer, buffer.Used());
loadBuffer[result] = '\0';
delete[] loadBuffer;
// testAdmin.Sync("server wrote and peeked");

// testAdmin.Sync("client unlocked");
Expand All @@ -1592,7 +1597,7 @@ namespace Core {
// testAdmin.Sync("client read");
};

IPTestAdministrator::Callback callback_parent = [&](IPTestAdministrator& testAdmin) {
IPTestAdministrator::Callback callback_parent = [&](VARIABLE_IS_NOT_USED IPTestAdministrator& testAdmin) {
// a small delay so the child can be set up
SleepMs(maxInitTime);

Expand Down Expand Up @@ -1634,10 +1639,11 @@ namespace Core {
EXPECT_EQ(buffer.LockPid(), 0u);
// testAdmin.Sync("client unlocked");

uint8_t loadBuffer[cyclicBufferSize + 1];
uint8_t* loadBuffer = new uint8_t[cyclicBufferSize + 1];
result = buffer.Read(loadBuffer, 4);
loadBuffer[result] = '\0';
EXPECT_STREQ((char*)loadBuffer, "jklm");
delete[] loadBuffer;

// testAdmin.Sync("client read");

Expand All @@ -1653,12 +1659,12 @@ namespace Core {
//TODO: revisit these test cases after fixing the issues with cyclicbuffer lock/unlock sequence
TEST(Core_CyclicBuffer, DISABLED_LockUnlock_FromParentAndForks_WithDataPresent)
{
constexpr uint32_t initHandshakeValue = 0, maxWaitTime = 4, maxWaitTimeMs = 4000, maxInitTime = 2000;
constexpr uint8_t maxRetries = 1;
constexpr uint32_t initHandshakeValue = 0, maxWaitTime = 4, VARIABLE_IS_NOT_USED maxWaitTimeMs = 4000, VARIABLE_IS_NOT_USED maxInitTime = 2000;
VARIABLE_IS_NOT_USED constexpr uint8_t maxRetries = 1;

std::string bufferName {"cyclicbuffer05"};

IPTestAdministrator::Callback callback_child = [&](IPTestAdministrator& testAdmin) {
IPTestAdministrator::Callback callback_child = [&](VARIABLE_IS_NOT_USED IPTestAdministrator& testAdmin) {
uint32_t cyclicBufferSize = 20;

const uint32_t mode =
Expand Down Expand Up @@ -1747,7 +1753,7 @@ namespace Core {
EXPECT_EQ(buffer.LockPid(), 0u);
};

IPTestAdministrator::Callback callback_parent = [&](IPTestAdministrator& testAdmin) {
IPTestAdministrator::Callback callback_parent = [&](VARIABLE_IS_NOT_USED IPTestAdministrator& testAdmin) {
// testAdmin.Sync("setup server");

uint32_t cyclicBufferSize = 0;
Expand Down Expand Up @@ -1847,12 +1853,12 @@ namespace Core {
}
TEST(Core_CyclicBuffer, DISABLED_LockUnlock_FromParentAndForks_UsingAlert)
{
constexpr uint32_t initHandshakeValue = 0, maxWaitTime = 4, maxWaitTimeMs = 4000, maxInitTime = 2000;
constexpr uint8_t maxRetries = 1;
constexpr uint32_t initHandshakeValue = 0, maxWaitTime = 4, VARIABLE_IS_NOT_USED maxWaitTimeMs = 4000, maxInitTime = 2000;
VARIABLE_IS_NOT_USED constexpr uint8_t maxRetries = 1;

std::string bufferName {"cyclicbuffer05"};

IPTestAdministrator::Callback callback_child = [&](IPTestAdministrator& testAdmin) {
IPTestAdministrator::Callback callback_child = [&](VARIABLE_IS_NOT_USED IPTestAdministrator& testAdmin) {
uint32_t cyclicBufferSize = 20;

const uint32_t mode =
Expand Down Expand Up @@ -1893,7 +1899,7 @@ namespace Core {
EXPECT_EQ(buffer.LockPid(), 0u);
};

IPTestAdministrator::Callback callback_parent = [&](IPTestAdministrator& testAdmin) {
IPTestAdministrator::Callback callback_parent = [&](VARIABLE_IS_NOT_USED IPTestAdministrator& testAdmin) {
// a small delay so the child can be set up
SleepMs(maxInitTime);

Expand Down
2 changes: 1 addition & 1 deletion Tests/unit/core/test_cyclicbuffer_dataexchange.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ namespace Tests {

TEST(Core_CyclicBuffer, DataExchange)
{
constexpr uint32_t initHandshakeValue = 0, maxWaitTime = 4, maxWaitTimeMs = 4000, maxInitTime = 2000;
constexpr uint32_t initHandshakeValue = 0, maxWaitTime = 4, VARIABLE_IS_NOT_USED maxWaitTimeMs = 4000, VARIABLE_IS_NOT_USED maxInitTime = 2000;
constexpr uint8_t maxRetries = 1;

const std::string bufferName {"/tmp/SharedCyclicBuffer"};
Expand Down
3 changes: 2 additions & 1 deletion Tests/unit/core/test_databuffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,10 @@ namespace Core {

::Thunder::Core::ScopedStorage<blocksize> storage;

PUSH_WARNING(DISABLE_WARNING_MAYBE_UNINITIALIZED)
EXPECT_EQ(storage.Size(), blocksize);

EXPECT_NE(storage.Buffer(), nullptr);
POP_WARNING()
}

} // Core
Expand Down
2 changes: 1 addition & 1 deletion Tests/unit/core/test_dataelement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ namespace Core {
TEST(test_linkeddata, simple_linkeddata)
{
uint8_t arr[] = {10,20,30,40,50,60,70,80,90,100};
uint8_t arr1[] ={};
uint8_t arr1[sizeof(arr)/sizeof(arr[0])];
const uint64_t offset= 0;
::Thunder::Core::DataElement objt1(10,arr);
::Thunder::Core::LinkedDataElement ob1;
Expand Down
2 changes: 1 addition & 1 deletion Tests/unit/core/test_jsonparser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ namespace Core {

private:
template <typename U>
void InitValue(U* value, const std::string& name)
void InitValue(VARIABLE_IS_NOT_USED U* value, VARIABLE_IS_NOT_USED const std::string& name)
{
}

Expand Down
2 changes: 1 addition & 1 deletion Tests/unit/core/test_networkinfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ namespace Core {

TEST(DISABLED_test_adapterobserver, simple_adapterobserver)
{
::Thunder::Core::AdapterObserver::INotification* callback;
::Thunder::Core::AdapterObserver::INotification* callback{ nullptr };
::Thunder::Core::AdapterObserver observer(callback);

::Thunder::Core::Singleton::Dispose();
Expand Down
2 changes: 1 addition & 1 deletion Tests/unit/core/test_rpc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ namespace Exchange {
}

private:
virtual void* Acquire(const string& className, const uint32_t interfaceId, const uint32_t versionId)
virtual void* Acquire(VARIABLE_IS_NOT_USED const string& className, const uint32_t interfaceId, VARIABLE_IS_NOT_USED const uint32_t versionId)
{
void* result = nullptr;

Expand Down
Loading

0 comments on commit a589773

Please sign in to comment.