Skip to content

Commit

Permalink
Development/buildwarnings (#1821)
Browse files Browse the repository at this point in the history
* [Tests] : Reduce compiler warnings

* [Tests/unit/core] : amend '0badc'
  • Loading branch information
msieben authored Jan 6, 2025
1 parent fb031fb commit 8da9b20
Show file tree
Hide file tree
Showing 19 changed files with 87 additions and 57 deletions.
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
4 changes: 2 additions & 2 deletions Tests/unit/core/test_sharedbuffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ namespace Core {
constexpr uint32_t initHandshakeValue = 0, maxWaitTime = 6, maxWaitTimeMs = 6000, maxInitTime = 2000;
constexpr uint8_t maxRetries = 20;

constexpr uint16_t administrationSize = 64;
VARIABLE_IS_NOT_USED constexpr uint16_t administrationSize = 64;
constexpr uint32_t bufferSize = 8 * 1024;

const std::string bufferName {"testbuffer02"} ;
Expand Down Expand Up @@ -147,7 +147,7 @@ namespace Core {

uint16_t administrationSize = 64;
uint32_t bufferSize = 8 * 1024;
uint32_t result;
VARIABLE_IS_NOT_USED uint32_t result;

::Thunder::Core::SharedBuffer buff01(bufferName.c_str(),
::Thunder::Core::File::USER_READ |
Expand Down
2 changes: 1 addition & 1 deletion Tests/unit/core/test_socketstreamjson.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ namespace Core {
}
}

virtual void Send(::Thunder::Core::ProxyType<::Thunder::Core::JSON::IElement>& newElement)
virtual void Send(VARIABLE_IS_NOT_USED ::Thunder::Core::ProxyType<::Thunder::Core::JSON::IElement>& newElement)
{
}

Expand Down
2 changes: 1 addition & 1 deletion Tests/unit/core/test_socketstreamtext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ namespace Core {
_dataReceived.clear();
}

virtual void Send(const string& text)
virtual void Send(VARIABLE_IS_NOT_USED const string& text)
{
}

Expand Down
2 changes: 1 addition & 1 deletion Tests/unit/core/test_synchronous.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ namespace Core {
EXPECT_EQ(::Thunder::Core::SynchronousChannelType<::Thunder::Core::SocketPort>::Close(maxWaitTimeMs), ::Thunder::Core::ERROR_NONE);
}

virtual uint16_t Deserialize(const uint8_t* dataFrame, const uint16_t availableData)
virtual uint16_t Deserialize(VARIABLE_IS_NOT_USED const uint8_t* dataFrame, VARIABLE_IS_NOT_USED const uint16_t availableData)
{
return 1;
}
Expand Down
2 changes: 1 addition & 1 deletion Tests/unit/core/test_systeminfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -538,7 +538,7 @@ namespace Core {
loadFromSystem[2] = Round(loadFromSystem[2], 2);

uint64_t* cpuLoadAvg = ::Thunder::Core::SystemInfo::Instance().GetCpuLoadAvg();
double loadFromThunder[3];
VARIABLE_IS_NOT_USED double loadFromThunder[3];
#ifndef __APPLE__
// Fixed point arithmetic
EXPECT_DOUBLE_EQ(loadFromSystem[0], cpuLoadAvg[0] / (1 << SI_LOAD_SHIFT));
Expand Down
Loading

0 comments on commit 8da9b20

Please sign in to comment.