Skip to content

Commit

Permalink
gh-685: Add rsa shm test case
Browse files Browse the repository at this point in the history
And some small improvements based on review
comments
  • Loading branch information
pnoltes committed Jun 9, 2024
1 parent 8b0e0e0 commit f237f4b
Show file tree
Hide file tree
Showing 7 changed files with 54 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
#include "socket_ei.h"
#include "stdio_ei.h"
#include "pthread_ei.h"
#include "celix_properties_ei.h"
#include "thpool_ei.h"
#include "celix_errno.h"
#include <errno.h>
Expand Down Expand Up @@ -80,6 +81,7 @@ class RsaShmClientServerUnitTestSuite : public ::testing::Test {
celix_ei_expect_pthread_cond_timedwait(nullptr, 1, 0);
celix_ei_expect_thpool_init(nullptr, 0, nullptr);
celix_ei_expect_thpool_add_work(nullptr, 0, 0);
celix_ei_expect_celix_properties_saveToStream(nullptr, 0, CELIX_SUCCESS);
}


Expand Down Expand Up @@ -139,6 +141,44 @@ TEST_F(RsaShmClientServerUnitTestSuite, SendMsg) {
rsaShmServer_destroy(server);
}

TEST_F(RsaShmClientServerUnitTestSuite, SendMsgErrorEncodePropertiesTest) {
//Given a rsa shm server
rsa_shm_server_t *server = nullptr;
auto status = rsaShmServer_create(ctx.get(), "shm_test_server", logHelper.get(), ReceiveMsgCallback, nullptr, &server);
EXPECT_EQ(CELIX_SUCCESS, status);
EXPECT_NE(nullptr, server);

//And a rsa shm client
rsa_shm_client_manager_t *clientManager = nullptr;
status = rsaShmClientManager_create(ctx.get(), logHelper.get(), &clientManager);
EXPECT_EQ(CELIX_SUCCESS, status);
EXPECT_NE(nullptr, clientManager);

// And the client is attached to the server
long serverId = 100;//dummy id
status = rsaShmClientManager_createOrAttachClient(clientManager, "shm_test_server", serverId);
EXPECT_EQ(CELIX_SUCCESS, status);

//When an error is prepared for saveToStream
celix_ei_expect_celix_properties_saveToStream((void*)rsaShmClientManager_sendMsgTo, 0, ENOMEM);

//And a message is sent
celix_autoptr(celix_properties_t) metadata = celix_properties_create();
celix_properties_set(metadata, "CustomKey", "test");
struct iovec request = {.iov_base = (void*)"request", .iov_len = strlen("request")};
struct iovec response = {.iov_base = nullptr, .iov_len = 0};
status = rsaShmClientManager_sendMsgTo(clientManager, "shm_test_server", serverId, metadata, &request, &response);

//Then the injected error is returned
EXPECT_EQ(ENOMEM, status);

rsaShmClientManager_destroyOrDetachClient(clientManager, "shm_test_server", serverId);

rsaShmClientManager_destroy(clientManager);

rsaShmServer_destroy(server);
}

TEST_F(RsaShmClientServerUnitTestSuite, SendMsgWithNoServer) {
rsa_shm_client_manager_t *clientManager = nullptr;
auto status = rsaShmClientManager_create(ctx.get(), logHelper.get(), &clientManager);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,7 @@ celix_status_t rsaShmClientManager_sendMsgTo(rsa_shm_client_manager_t *clientMan
if (metadata != NULL) {
status = celix_properties_saveToStream(metadata, fp, 0);
if (status != CELIX_SUCCESS) {
fclose(fp);
celix_logHelper_error(
clientManager->logHelper, "RsaShmClient: Error encoding metadata to memory stream. %d.", status);
celix_logHelper_logTssErrors(clientManager->logHelper, CELIX_LOG_LEVEL_ERROR);
Expand Down
1 change: 0 additions & 1 deletion cmake/cmake_celix/ContainerPackaging.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,6 @@ function(add_celix_container)
file(GENERATE
OUTPUT "${STAGE1_LAUNCHER_SRC}"
CONTENT "#include <celix_launcher.h>
#include <celix_err.h>
#define CELIX_MULTI_LINE_STRING(...) #__VA_ARGS__
Expand Down
6 changes: 2 additions & 4 deletions libs/framework/src/framework.c
Original file line number Diff line number Diff line change
Expand Up @@ -574,11 +574,9 @@ static bool framework_autoStartConfiguredBundlesForList(celix_framework_t* fw,
}
} else {
fw_log(fw->logger,
CELIX_LOG_LEVEL_TRACE,
"Cannot start bundle %s (bnd id = %li), because it is already started\n",
bnd->symbolicName,
CELIX_LOG_LEVEL_WARNING,
"Cannot start bundle %s (bnd id = %li) again, already started\n", bnd->symbolicName,
bndId);
allStarted = false;
}
}
return allStarted;
Expand Down
1 change: 1 addition & 0 deletions libs/utils/error_injector/celix_properties/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ target_link_options(properties_ei INTERFACE
LINKER:--wrap,celix_properties_setVersion
LINKER:--wrap,celix_properties_setEntry
LINKER:--wrap,celix_properties_save
LINKER:--wrap,celix_properties_saveToStream
LINKER:--wrap,celix_properties_load
)
add_library(Celix::properties_ei ALIAS properties_ei)
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ CELIX_EI_DECLARE(celix_properties_setLong, celix_status_t);
CELIX_EI_DECLARE(celix_properties_setVersion, celix_status_t);
CELIX_EI_DECLARE(celix_properties_setEntry, celix_status_t);
CELIX_EI_DECLARE(celix_properties_save, celix_status_t);
CELIX_EI_DECLARE(celix_properties_saveToStream, celix_status_t);
CELIX_EI_DECLARE(celix_properties_load, celix_status_t);

#ifdef __cplusplus
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,15 @@ __wrap_celix_properties_save(const celix_properties_t* properties, const char* f
return __real_celix_properties_save(properties, filename, encodeFlags);
}

celix_status_t
__real_celix_properties_saveToStream(const celix_properties_t* properties, FILE* stream, int encodeFlags);
CELIX_EI_DEFINE(celix_properties_saveToStream, celix_status_t)
celix_status_t
__wrap_celix_properties_saveToStream(const celix_properties_t* properties, FILE* stream, int encodeFlags) {
CELIX_EI_IMPL(celix_properties_saveToStream);
return __real_celix_properties_saveToStream(properties, stream, encodeFlags);
}

celix_status_t
__real_celix_properties_load(const char* filename,
int decodeFlags,
Expand Down

0 comments on commit f237f4b

Please sign in to comment.