Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into feature/685-refacto…
Browse files Browse the repository at this point in the history
…r-manifest-format
  • Loading branch information
pnoltes committed Jul 22, 2024
2 parents 26d14ff + 81d3b6b commit 203cbfc
Show file tree
Hide file tree
Showing 32 changed files with 546 additions and 259 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/conan_create.yml
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ jobs:
conan remove -c celix/*
mac-build:
runs-on: macOS-11
runs-on: macOS-12
timeout-minutes: 120
steps:
- name: Checkout source code
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/macos.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ env:
jobs:

macos-build-conan:
runs-on: macOS-11
runs-on: macOS-12
timeout-minutes: 120
steps:
- name: Checkout source code
Expand Down
4 changes: 3 additions & 1 deletion .github/workflows/ubuntu.yml
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ jobs:
sudo apt-get update
sudo apt-get install -yq --no-install-recommends \
build-essential \
ninja-build \
curl \
uuid-dev \
libzip-dev \
Expand Down Expand Up @@ -145,11 +146,12 @@ jobs:
-DENABLE_TESTING_ON_CI=ON
-DCMAKE_BUILD_TYPE=${{ matrix.type }}
-DENABLE_CCACHE=ON
-G Ninja
run: |
mkdir build install
cd build
cmake ${BUILD_OPTIONS} -DCMAKE_INSTALL_PREFIX=../install ..
make -j $(nproc) && make install
ninja && ninja install
- name: Test
run: |
cd $GITHUB_WORKSPACE/build
Expand Down
5 changes: 0 additions & 5 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,6 @@ list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
set(THREADS_PREFER_PTHREAD_FLAG ON)
find_package(Threads REQUIRED)

# see https://public.kitware.com/Bug/view.php?id=15696
IF (${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION} EQUAL 3.3 AND ${CMAKE_GENERATOR} STREQUAL "Unix Makefiles")
message( FATAL_ERROR "Building Celix using CMake 3.3 and makefiles is not supported due to a bug in the Makefile Generator (see Bug 15696). Please change the used CMake version - both, CMake 3.2 and CMake 3.4 are working fine. Or use a different generator (e.g. Ninja)." )
ENDIF()

# Options
option(ENABLE_TESTING "Enables unit/bundle testing" FALSE)
if (ENABLE_TESTING)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include <unistd.h>
#include <semaphore.h>
#include <cstdlib>
#include <future>

#include <gtest/gtest.h>
#include "CelixEventAdminTestSuiteBaseClass.h"
Expand Down Expand Up @@ -605,36 +606,50 @@ TEST_F(CelixEventAdminTestSuite, PostEventWithInvalidArgumentsTest) {
});
}

static bool g_blockingHandlerCalled = false;
TEST_F(CelixEventAdminTestSuite, AsyncEventQueueFullTest) {
g_blockingHandlerCalled = true;
TestPublishEvent("org/celix/test", nullptr, [](celix_event_admin_t *ea) {
for (int i = 0; i < 512 + 1/*handling event*/; ++i) {
std::promise<void> promise1;
auto future1 = promise1.get_future();
std::promise<void> promise2;
auto future2 = promise2.get_future();
TestPublishEvent("org/celix/test", nullptr, [&promise2, &future1](celix_event_admin_t *ea) {
for (int i = 0; i < 512; ++i) {
auto status = celix_eventAdmin_postEvent(ea, "org/celix/test", nullptr);
EXPECT_EQ(CELIX_SUCCESS, status);
}
usleep(30000);
future1.get();
auto status = celix_eventAdmin_postEvent(ea, "org/celix/test", nullptr);
EXPECT_EQ(CELIX_SUCCESS, status);
status = celix_eventAdmin_postEvent(ea, "org/celix/test", nullptr);
EXPECT_EQ(CELIX_ILLEGAL_STATE, status);
g_blockingHandlerCalled = false;
}, [](void *handle, const char *topic, const celix_properties_t *props) {
promise2.set_value();
}, [&promise1, &future2](void *handle, const char *topic, const celix_properties_t *props) {
(void)handle;
(void)props;
(void)topic;
while (g_blockingHandlerCalled) usleep(1000);
static bool firstCalled{true};
if (firstCalled) {
promise1.set_value();
future2.get();
firstCalled = false;
}
return CELIX_SUCCESS;
});
}

TEST_F(CelixEventAdminTestSuite, RemoveEventHandlerAfterEventAdminStopTest) {
g_blockingHandlerCalled = true;
std::promise<void> promise;
auto future = promise.get_future();
celix_event_handler_service_t handler;
handler.handle = nullptr;
handler.handle = &future;
handler.handleEvent = [](void *handle, const char *topic, const celix_properties_t *props) {
(void)handle;
auto feature = static_cast<std::future<void>*>(handle);
(void)topic;
(void)props;
while (g_blockingHandlerCalled) usleep(1000);
static bool firstCalled{true};
if (firstCalled) {
feature->get();
firstCalled = false;
}
return CELIX_SUCCESS;
};
auto props = celix_properties_create();
Expand Down Expand Up @@ -669,7 +684,7 @@ TEST_F(CelixEventAdminTestSuite, RemoveEventHandlerAfterEventAdminStopTest) {
EXPECT_EQ(CELIX_SUCCESS, status);
}

g_blockingHandlerCalled = false;
promise.set_value();
status = celix_eventAdmin_stop(ea);
EXPECT_EQ(CELIX_SUCCESS, status);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#ifndef CELIX_CELIX_EVENT_ADMIN_TEST_SUITE_BASE_CLASS_H
#define CELIX_CELIX_EVENT_ADMIN_TEST_SUITE_BASE_CLASS_H

#include <functional>

#include "celix_event_admin.h"
#include "celix_event_handler_service.h"
Expand Down Expand Up @@ -137,16 +138,22 @@ class CelixEventAdminTestSuiteBaseClass : public ::testing::Test {
celix_eventAdmin_destroy(ea);
}

void TestPublishEvent(const char *handlerTopics, const char *eventFilter, void (*testBody)(celix_event_admin_t *ea),
celix_status_t (*onHandleEvent)(void *handle, const char *topic, const celix_properties_t *props), bool asyncUnordered = false) {
void TestPublishEvent(const char *handlerTopics, const char *eventFilter, std::function<void(celix_event_admin_t*)> testBody,
std::function<celix_status_t (void*, const char*, const celix_properties_t*)> onHandleEvent, bool asyncUnordered = false) {
auto ea = celix_eventAdmin_create(ctx.get());
EXPECT_TRUE(ea != nullptr);
auto status = celix_eventAdmin_start(ea);
EXPECT_EQ(CELIX_SUCCESS, status);

struct celix_handle_event_callback_data {
std::function<celix_status_t (void*, const char*, const celix_properties_t*)> onHandleEvent;
void* handle;
} data{onHandleEvent, ea};
celix_event_handler_service_t handler;
handler.handle = ea;
handler.handleEvent = onHandleEvent;
handler.handle = &data;
handler.handleEvent = [](void *handle, const char *topic, const celix_properties_t *props) {
auto data = static_cast<celix_handle_event_callback_data*>(handle);
return data->onHandleEvent(data->handle, topic, props);
};
auto props = celix_properties_create();
celix_properties_set(props, CELIX_FRAMEWORK_SERVICE_VERSION, CELIX_EVENT_HANDLER_SERVICE_VERSION);
celix_properties_set(props, CELIX_EVENT_TOPIC, handlerTopics);
Expand Down
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 @@ -36,6 +36,7 @@
#include <sys/param.h>
#include <assert.h>
#include <stdbool.h>
#include <string.h>
#include <errno.h>


Expand Down Expand Up @@ -280,6 +281,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
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
#include <assert.h>
#include <stdbool.h>
#include <stddef.h>
#include <string.h>
#include <errno.h>

#define MAX_RSA_SHM_SERVER_HANDLE_MSG_THREADS_NUM 5
Expand Down
2 changes: 0 additions & 2 deletions bundles/shell/remote_shell/src/shell_mediator.c
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,6 @@ celix_status_t shellMediator_stop(shell_mediator_pt instance) {
celix_status_t shellMediator_destroy(shell_mediator_pt instance) {
celix_status_t status = CELIX_SUCCESS;

celixThreadMutex_lock(&instance->mutex);

instance->shellService = NULL;
serviceTracker_destroy(instance->tracker);
celix_logHelper_destroy(instance->loghelper);
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
10 changes: 9 additions & 1 deletion libs/framework/gtest/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ celix_bundle_description(simple_test_bundle1 "Test Description")
celix_bundle_headers(simple_test_bundle1 "Extra-Header1: value1" "Extra-Header2: value2")
celix_bundle_headers(simple_test_bundle1 "Extra-Header3: value3")

add_celix_bundle(dup_symbolic_name_bundle NO_ACTIVATOR VERSION 1.0.0 SYMBOLIC_NAME simple_test_bundle1)

add_celix_bundle(simple_test_bundle2 NO_ACTIVATOR VERSION 1.0.0)
add_celix_bundle(simple_test_bundle3 NO_ACTIVATOR VERSION 1.0.0)
add_celix_bundle(bundle_with_exception SOURCES src/activator_with_exception.c VERSION 1.0.0)
Expand All @@ -34,6 +36,7 @@ add_celix_bundle(cmp_test_bundle SOURCES src/CmpTestBundleActivator.cc VERSION 1
add_celix_bundle(cond_test_bundle SOURCES src/CondTestBundleActivator.cc VERSION 1.0.0)
add_subdirectory(subdir) #simple_test_bundle4, simple_test_bundle5 and sublib
add_celix_bundle(celix_err_test_bundle SOURCES src/activator_with_celix_err.c VERSION 1.0.0)
add_celix_bundle(immediate_stop_bundle SOURCES src/activator_stop.c VERSION 1.0.0)

add_celix_bundle(unresolvable_bundle SOURCES src/activator_with_exception.c VERSION 1.0.0)
if (CMAKE_BUILD_TYPE STREQUAL "Debug")
Expand Down Expand Up @@ -81,17 +84,19 @@ add_celix_bundle_dependencies(test_framework
simple_test_bundle2 simple_test_bundle3 simple_test_bundle4
simple_test_bundle5 bundle_with_exception bundle_with_bad_export
unresolvable_bundle simple_cxx_bundle simple_cxx_dep_man_bundle cmp_test_bundle
celix_err_test_bundle)
celix_err_test_bundle dup_symbolic_name_bundle immediate_stop_bundle)
target_include_directories(test_framework PRIVATE ../src)
celix_deprecated_utils_headers(test_framework)

celix_get_bundle_file(simple_test_bundle1 SIMPLE_TEST_BUNDLE1)
celix_get_bundle_file(dup_symbolic_name_bundle DUP_SYMBOLIC_NAME_BUNDLE)
celix_get_bundle_file(simple_test_bundle2 SIMPLE_TEST_BUNDLE2)
celix_get_bundle_file(simple_test_bundle3 SIMPLE_TEST_BUNDLE3)
celix_get_bundle_file(simple_test_bundle4 SIMPLE_TEST_BUNDLE4)
celix_get_bundle_file(simple_test_bundle5 SIMPLE_TEST_BUNDLE5)
celix_get_bundle_filename(simple_test_bundle4 SIMPLE_TEST_BUNDLE4_FILENAME)
celix_get_bundle_filename(simple_test_bundle5 SIMPLE_TEST_BUNDLE5_FILENAME)
celix_get_bundle_file(immediate_stop_bundle IMMEDIATE_STOP_BUNDLE)

celix_get_bundle_filename(bundle_with_exception BUNDLE_WITH_EXCEPTION)
celix_get_bundle_file(bundle_with_bad_export BUNDLE_WITH_BAD_EXPORT)
Expand All @@ -116,6 +121,7 @@ target_compile_definitions(test_framework PRIVATE
SIMPLE_TEST_BUNDLE3_LOCATION="${SIMPLE_TEST_BUNDLE3}"
SIMPLE_TEST_BUNDLE4_LOCATION="${SIMPLE_TEST_BUNDLE4_FILENAME}"
SIMPLE_TEST_BUNDLE5_LOCATION="${SIMPLE_TEST_BUNDLE5_FILENAME}"
DUP_SYMBOLIC_NAME_BUNDLE_LOCATION="${DUP_SYMBOLIC_NAME_BUNDLE}"
TEST_BUNDLE_WITH_EXCEPTION_LOCATION="${BUNDLE_WITH_EXCEPTION}"
BUNDLE_WITH_BAD_EXPORT_LOCATION="${BUNDLE_WITH_BAD_EXPORT}"
TEST_BUNDLE_UNRESOLVABLE_LOCATION="${UNRESOLVABLE_BUNDLE}"
Expand All @@ -125,7 +131,9 @@ target_compile_definitions(test_framework PRIVATE
CMP_TEST_BUNDLE_LOC="${CMP_TEST_BUNDLE_LOC}"
COND_TEST_BUNDLE_LOC="${COND_TEST_BUNDLE_LOC}"
INSTALL_AND_START_BUNDLES_CONFIG_PROPERTIES_FILE="${CMAKE_CURRENT_BINARY_DIR}/install_and_start_bundles.properties"
IMMEDIATE_STOP_BUNDLE_LOCATION="${IMMEDIATE_STOP_BUNDLE}"
)

if (ENABLE_TESTING_ON_CI)
target_compile_definitions(test_framework PRIVATE TESTING_ON_CI=1)
endif ()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ TEST_F(CelixBundleArchiveErrorInjectionTestSuite, ArchiveCreateErrorTest) {
EXPECT_EQ(CELIX_SUCCESS, celix_utils_extractZipFile(SIMPLE_TEST_BUNDLE1_LOCATION, testExtractDir, nullptr));
EXPECT_EQ(CELIX_SUCCESS,
celix_bundleArchive_create(&fw, TEST_ARCHIVE_ROOT, 2, testExtractDir, &archive));
bundleArchive_destroy(archive);
celix_bundleArchive_destroy(archive);
archive = nullptr;
std::this_thread::sleep_for(std::chrono::milliseconds(10));
celix_utils_touch(SIMPLE_TEST_BUNDLE1_LOCATION);
Expand All @@ -223,7 +223,7 @@ TEST_F(CelixBundleArchiveErrorInjectionTestSuite, ArchiveCreateErrorTest) {

EXPECT_EQ(CELIX_SUCCESS,
celix_bundleArchive_create(&fw, TEST_ARCHIVE_ROOT, 1, SIMPLE_TEST_BUNDLE1_LOCATION, &archive));
bundleArchive_destroy(archive);
celix_bundleArchive_destroy(archive);
archive = nullptr;
std::this_thread::sleep_for(std::chrono::milliseconds(10));
celix_utils_touch(SIMPLE_TEST_BUNDLE1_LOCATION);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ class CelixBundleContextBundlesTestSuite : public ::testing::Test {
const char * const TEST_BND5_LOC = "" SIMPLE_TEST_BUNDLE5_LOCATION "";
const char * const TEST_BND_WITH_EXCEPTION_LOC = "" TEST_BUNDLE_WITH_EXCEPTION_LOCATION "";
const char * const TEST_BND_UNRESOLVABLE_LOC = "" TEST_BUNDLE_UNRESOLVABLE_LOCATION "";
const char * const DUP_SYMBOLIC_NAME_BUNDLE_LOC = "" DUP_SYMBOLIC_NAME_BUNDLE_LOCATION "";

CelixBundleContextBundlesTestSuite() {
properties = celix_properties_create();
Expand Down Expand Up @@ -79,6 +80,14 @@ TEST_F(CelixBundleContextBundlesTestSuite, InstallABundleTest) {
ASSERT_TRUE(bndId >= 0);
}

TEST_F(CelixBundleContextBundlesTestSuite, InstallBundleWithDuplicatedSymbolicNameTest) {
long bndId1 = celix_bundleContext_installBundle(ctx, TEST_BND1_LOC, true);
ASSERT_TRUE(bndId1 >= 0);

long bndId2 = celix_bundleContext_installBundle(ctx, DUP_SYMBOLIC_NAME_BUNDLE_LOC, true);
ASSERT_TRUE(bndId2 < 0);
}

//TEST_F(CelixBundleContextBundlesTestSuite, InstallBundleWithBadExport) {
// long bndId = celix_bundleContext_installBundle(ctx, BUNDLE_WITH_BAD_EXPORT_LOCATION, true);
// ASSERT_TRUE(bndId >= 0);
Expand Down
Loading

0 comments on commit 203cbfc

Please sign in to comment.