Skip to content

Commit

Permalink
Merge branch 'master' into development/ipcchannel_dangling_handlers
Browse files Browse the repository at this point in the history
  • Loading branch information
msieben committed Aug 6, 2024
2 parents 1f41988 + 0e27788 commit c0fca0f
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 6 deletions.
19 changes: 15 additions & 4 deletions Tests/unit/IPTestAdministrator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,11 @@ IPTestAdministrator::IPTestAdministrator(Callback parent, Callback child, const
{
ASSERT(waitTime > 0 && waitTime < ::Thunder::Core::infinite);

int shm_id = shmget(IPC_PRIVATE, sizeof(struct SharedData) /* size */, IPC_CREAT | 0666 /* read and write for user, group and others */);
_shm_id = shmget(IPC_PRIVATE, sizeof(struct SharedData) /* size */, IPC_CREAT | 0666 /* read and write for user, group and others */);

ASSERT(shm_id >= 0);
ASSERT(_shm_id >= 0);

_sharedData = reinterpret_cast<struct SharedData*>(shmat(shm_id, nullptr, 0 /* attach for reading and writing */));
_sharedData = reinterpret_cast<struct SharedData*>(shmat(_shm_id, nullptr, 0 /* attach for reading and writing */));

ASSERT(_sharedData != nullptr);

Expand Down Expand Up @@ -96,6 +96,7 @@ IPTestAdministrator::~IPTestAdministrator()
do {} while(false);
case 0 : // Timeout expired before events are available
{
// Potential leak of shared memory descriptor
int result = syscall(SYS_kill, _pid, SIGKILL);

ASSERT(result == 0);
Expand All @@ -111,12 +112,22 @@ IPTestAdministrator::~IPTestAdministrator()

if(shmdt(_sharedData) == -1) {
switch(errno) {
case EINVAL : // The shared data is not the start address of the sahred segment
case EINVAL : // The shared data is not the start address of the shared segment
do {} while(false);
default : // Uninpsected or unknown error
;
}
}

if (shmctl(_shm_id, IPC_RMID, nullptr) == -1) {
switch(errno) {
case EPERM : // User ID is not that of the creator, owner or insufficient privileges
do {} while(false);
default : // Uninpsected or unknown error
;
}

}
}

uint32_t IPTestAdministrator::Wait(uint32_t expectedHandshakeValue) const
Expand Down
1 change: 1 addition & 0 deletions Tests/unit/IPTestAdministrator.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ private :
constexpr static uint32_t _waitTimeDivisor = 10;

SharedData* _sharedData;
int _shm_id;
pid_t _pid;
uint32_t _waitTime; // Seconds
};
47 changes: 45 additions & 2 deletions Tests/unit/core/test_message_unit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
* limitations under the License.
*/

#include <algorithm>

#include <gtest/gtest.h>

#ifndef MODULE_NAME
Expand All @@ -29,6 +31,8 @@

#include "../IPTestAdministrator.h"

#define PRINT_MODULES(NAME, MODULES) {std::cout << NAME << " ---> "; std::for_each(MODULES.begin(), MODULES.end(), [](std::string MODULE){std::cout << " " << MODULE;}); std::cout << std::endl;};

namespace Thunder {
namespace Tests {
namespace Core {
Expand Down Expand Up @@ -249,6 +253,8 @@ namespace Core {
std::vector<std::string> modules;
client.Modules(modules);

PRINT_MODULES(__PRETTY_FUNCTION__, modules);

int matches = 0;
int count = 0;

Expand Down Expand Up @@ -295,6 +301,8 @@ namespace Core {
std::vector<std::string> modules;
client.Modules(modules);

PRINT_MODULES(__PRETTY_FUNCTION__, modules);

int matches = 0;
int count = 0;

Expand Down Expand Up @@ -323,6 +331,8 @@ namespace Core {
modules.clear();
client.Modules(modules);

PRINT_MODULES(__PRETTY_FUNCTION__, modules);

/* bool */ enabled = false;

for (auto it = modules.begin(), end = modules.end(); it != end; it++) {
Expand All @@ -348,7 +358,8 @@ namespace Core {

client.RemoveInstance(0);

ToggleDefaultConfig(false);
// Direct call required
::Thunder::Messaging::MessageUnit::Instance().Close();
}

TEST_F(Core_Messaging_MessageUnit, EnablingMessagesShouldAddToDefaultConfigListIfNotPresent)
Expand All @@ -364,6 +375,8 @@ namespace Core {
std::vector<std::string> modules;
client.Modules(modules);

PRINT_MODULES(__PRETTY_FUNCTION__, modules);

bool enabled = false;

for (auto it = modules.begin(), end = modules.end(); it != end; it++) {
Expand Down Expand Up @@ -392,6 +405,8 @@ namespace Core {
modules.clear();
client.Modules(modules);

PRINT_MODULES(__PRETTY_FUNCTION__, modules);

enabled = false;

for (auto it = modules.begin(), end = modules.end(); it != end; it++) {
Expand Down Expand Up @@ -430,6 +445,8 @@ namespace Core {
std::vector<std::string> modules;
client.Modules(modules);

PRINT_MODULES(__PRETTY_FUNCTION__, modules);

bool enabled = true;

for (auto it = modules.begin(), end = modules.end(); it != end; it++) {
Expand All @@ -453,6 +470,8 @@ namespace Core {
modules.clear();
client.Modules(modules);

PRINT_MODULES(__PRETTY_FUNCTION__, modules);

enabled = true;

for (auto it = modules.begin(), end = modules.end(); it != end; it++) {
Expand Down Expand Up @@ -487,6 +506,8 @@ namespace Core {
std::vector<std::string> modules;
client.Modules(modules);

PRINT_MODULES(__PRETTY_FUNCTION__, modules);

int matches = 0;

for (auto it = modules.begin(), end = modules.end(); it != end; it++) {
Expand All @@ -512,6 +533,8 @@ namespace Core {
modules.clear();
client.Modules(modules);

PRINT_MODULES(__PRETTY_FUNCTION__, modules);

matches = 0;

for (auto it = modules.begin(), end = modules.end(); it != end; it++) {
Expand Down Expand Up @@ -552,6 +575,8 @@ namespace Core {
std::vector<std::string> modules;
client.Modules(modules);

PRINT_MODULES(__PRETTY_FUNCTION__, modules);

bool enabled = false;

for (auto it = modules.begin(), end = modules.end(); it != end; it++) {
Expand Down Expand Up @@ -593,6 +618,8 @@ namespace Core {
std::vector<std::string> modules;
client.Modules(modules);

PRINT_MODULES(__PRETTY_FUNCTION__, modules);

bool enabled = false;

for (auto it = modules.begin(), end = modules.end(); it != end; it++) {
Expand Down Expand Up @@ -621,6 +648,8 @@ namespace Core {
modules.clear();
client.Modules(modules);

PRINT_MODULES(__PRETTY_FUNCTION__, modules);

enabled = false;

for (auto it = modules.begin(), end = modules.end(); it != end; it++) {
Expand Down Expand Up @@ -660,6 +689,8 @@ namespace Core {
std::vector<std::string> modules;
client.Modules(modules);

PRINT_MODULES(__PRETTY_FUNCTION__, modules);

bool enabled = true;

for (auto it = modules.begin(), end = modules.end(); it != end; it++) {
Expand All @@ -685,6 +716,8 @@ namespace Core {
modules.clear();
client.Modules(modules);

PRINT_MODULES(__PRETTY_FUNCTION__, modules);

enabled = true;

for (auto it = modules.begin(), end = modules.end(); it != end; it++) {
Expand Down Expand Up @@ -723,6 +756,8 @@ namespace Core {
std::vector<std::string> modules;
client.Modules(modules);

PRINT_MODULES(__PRETTY_FUNCTION__, modules);

bool enabled = true;

for (auto it = modules.begin(), end = modules.end(); it != end; it++) {
Expand All @@ -748,6 +783,8 @@ namespace Core {
modules.clear();
client.Modules(modules);

PRINT_MODULES(__PRETTY_FUNCTION__, modules);

enabled = true;

for (auto it = modules.begin(), end = modules.end(); it != end; it++) {
Expand Down Expand Up @@ -829,6 +866,8 @@ namespace Core {
std::vector<std::string> modules;
client.Modules(modules);

PRINT_MODULES(__PRETTY_FUNCTION__, modules);

for (auto it = modules.begin(), end = modules.end(); it != end; it++) {
::Thunder::Messaging::MessageUnit::Iterator item;

Expand Down Expand Up @@ -862,6 +901,8 @@ namespace Core {
std::vector<std::string> modules;
client.Modules(modules);

PRINT_MODULES(__PRETTY_FUNCTION__, modules);

std::vector<uint8_t> buffer;

for (auto it = modules.begin(), end = modules.end(); it != end; it++) {
Expand All @@ -884,6 +925,8 @@ namespace Core {
modules.clear();
client.Modules(modules);

PRINT_MODULES(__PRETTY_FUNCTION__, modules);

for (auto it = modules.begin(), end = modules.end(); it != end; it++) {
::Thunder::Messaging::MessageUnit::Iterator item;

Expand Down Expand Up @@ -1036,7 +1079,7 @@ namespace Core {

// Code after this line is executed by both parent and child

// ::Thunder::Core::Singleton::Dispose();
::Thunder::Core::Singleton::Dispose();
}

} // Core
Expand Down

0 comments on commit c0fca0f

Please sign in to comment.