From commits-return-5476-apmail-celix-commits-archive=celix.apache.org@celix.apache.org Mon Sep 16 13:00:54 2019 Return-Path: X-Original-To: apmail-celix-commits-archive@www.apache.org Delivered-To: apmail-celix-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [207.244.88.153]) by minotaur.apache.org (Postfix) with SMTP id 5C80A19171 for ; Mon, 16 Sep 2019 13:00:54 +0000 (UTC) Received: (qmail 70147 invoked by uid 500); 16 Sep 2019 13:00:53 -0000 Delivered-To: apmail-celix-commits-archive@celix.apache.org Received: (qmail 70131 invoked by uid 500); 16 Sep 2019 13:00:53 -0000 Mailing-List: contact commits-help@celix.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@celix.apache.org Delivered-To: mailing list commits@celix.apache.org Received: (qmail 70122 invoked by uid 99); 16 Sep 2019 13:00:53 -0000 Received: from ec2-52-202-80-70.compute-1.amazonaws.com (HELO gitbox.apache.org) (52.202.80.70) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 16 Sep 2019 13:00:53 +0000 Received: by gitbox.apache.org (ASF Mail Server at gitbox.apache.org, from userid 33) id 8E76180932; Mon, 16 Sep 2019 13:00:53 +0000 (UTC) Date: Mon, 16 Sep 2019 13:00:53 +0000 To: "commits@celix.apache.org" Subject: [celix] branch feature/handle_hooks_in_registry updated: Refactors pubsub test to use a service instead of global. MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Message-ID: <156863885352.6276.506444324209585125@gitbox.apache.org> From: pnoltes@apache.org X-Git-Host: gitbox.apache.org X-Git-Repo: celix X-Git-Refname: refs/heads/feature/handle_hooks_in_registry X-Git-Reftype: branch X-Git-Oldrev: 311d93690952aa7fb72d8e3049d1aa1fb01b2e4b X-Git-Newrev: 6fe7eecd11f904c32e76df63db5a08919672b094 X-Git-Rev: 6fe7eecd11f904c32e76df63db5a08919672b094 X-Git-NotificationType: ref_changed_plus_diff X-Git-Multimail-Version: 1.5.dev Auto-Submitted: auto-generated This is an automated email from the ASF dual-hosted git repository. pnoltes pushed a commit to branch feature/handle_hooks_in_registry in repository https://gitbox.apache.org/repos/asf/celix.git The following commit(s) were added to refs/heads/feature/handle_hooks_in_registry by this push: new 6fe7eec Refactors pubsub test to use a service instead of global. 6fe7eec is described below commit 6fe7eecd11f904c32e76df63db5a08919672b094 Author: Pepijn Noltes AuthorDate: Mon Sep 16 15:00:00 2019 +0200 Refactors pubsub test to use a service instead of global. Maybe this solve the problem of unstable pubsub test (global with possible race condition) --- bundles/pubsub/test/CMakeLists.txt | 16 ++--- .../{test_runner.cc => receive_count_service.h} | 23 +++---- bundles/pubsub/test/test/test_runner.cc | 50 +++++++++++--- .../test/{tst_activator.cc => tst_activator.c} | 79 ++++++++------------- ...point_activator.cc => tst_endpoint_activator.c} | 80 +++++++++------------- 5 files changed, 118 insertions(+), 130 deletions(-) diff --git a/bundles/pubsub/test/CMakeLists.txt b/bundles/pubsub/test/CMakeLists.txt index f2f9374..7820dfa 100644 --- a/bundles/pubsub/test/CMakeLists.txt +++ b/bundles/pubsub/test/CMakeLists.txt @@ -38,7 +38,7 @@ celix_bundle_files(pubsub_endpoint_sut add_celix_bundle(pubsub_endpoint_tst #Test bundle containing cpputests and uses celix_test_runner launcher instead of the celix launcher SOURCES - test/tst_endpoint_activator.cc + test/tst_endpoint_activator.c VERSION 1.0.0 ) target_link_libraries(pubsub_endpoint_tst PRIVATE Celix::framework Celix::pubsub_api) @@ -93,7 +93,7 @@ celix_bundle_files(pubsub_sut add_celix_bundle(pubsub_tst #Test bundle containing cpputests and uses celix_test_runner launcher instead of the celix launcher SOURCES - test/tst_activator.cc + test/tst_activator.c VERSION 1.0.0 ) target_link_libraries(pubsub_tst PRIVATE Celix::framework Celix::pubsub_api) @@ -121,7 +121,7 @@ add_celix_container(pubsub_udpmc_tests pubsub_tst ) target_link_libraries(pubsub_udpmc_tests PRIVATE Celix::pubsub_api ${CPPUTEST_LIBRARIES} ${JANSSON_LIBRARIES} Celix::dfi) -target_include_directories(pubsub_udpmc_tests PRIVATE ${CPPUTEST_INCLUDE_DIR}) +target_include_directories(pubsub_udpmc_tests PRIVATE ${CPPUTEST_INCLUDE_DIR} test) message(WARNING "TODO fix issues with UDPMC and reanble test again") #add_test(NAME pubsub_udpmc_tests COMMAND pubsub_udpmc_tests WORKING_DIRECTORY $) #SETUP_TARGET_FOR_COVERAGE(pubsub_udpmc_tests_cov pubsub_udpmc_tests ${CMAKE_BINARY_DIR}/coverage/pubsub_udpmc_tests/pubsub_udpmc_tests ..) @@ -142,7 +142,7 @@ add_celix_container(pubsub_tcp_tests pubsub_tst ) target_link_libraries(pubsub_tcp_tests PRIVATE Celix::pubsub_api ${CPPUTEST_LIBRARIES} ${JANSSON_LIBRARIES} Celix::dfi) -target_include_directories(pubsub_tcp_tests PRIVATE ${CPPUTEST_INCLUDE_DIR}) +target_include_directories(pubsub_tcp_tests PRIVATE ${CPPUTEST_INCLUDE_DIR} test) add_test(NAME pubsub_tcp_tests COMMAND pubsub_tcp_tests WORKING_DIRECTORY $) SETUP_TARGET_FOR_COVERAGE(pubsub_tcp_tests_cov pubsub_tcp_tests ${CMAKE_BINARY_DIR}/coverage/pubsub_tcp_tests/pubsub_tcp_tests ..) @@ -164,7 +164,7 @@ add_celix_container(pubsub_tcp_endpoint_tests pubsub_endpoint_tst ) target_link_libraries(pubsub_tcp_endpoint_tests PRIVATE Celix::pubsub_api ${CPPUTEST_LIBRARIES} ${JANSSON_LIBRARIES} Celix::dfi) -target_include_directories(pubsub_tcp_endpoint_tests PRIVATE ${CPPUTEST_INCLUDE_DIR}) +target_include_directories(pubsub_tcp_endpoint_tests PRIVATE ${CPPUTEST_INCLUDE_DIR} test) #TCP Endpoint test is disabled because the test is not stable when running on Travis if (ENABLE_PUBSUB_PSA_TCP_ENDPOINT_TEST) @@ -189,7 +189,7 @@ add_celix_container(pubsub_websocket_tests pubsub_tst ) target_link_libraries(pubsub_websocket_tests PRIVATE Celix::pubsub_api ${CPPUTEST_LIBRARIES} ${JANSSON_LIBRARIES} Celix::dfi) -target_include_directories(pubsub_websocket_tests PRIVATE ${CPPUTEST_INCLUDE_DIR}) +target_include_directories(pubsub_websocket_tests PRIVATE ${CPPUTEST_INCLUDE_DIR} test) add_test(NAME pubsub_websocket_tests COMMAND pubsub_websocket_tests WORKING_DIRECTORY $) SETUP_TARGET_FOR_COVERAGE(pubsub_websocket_tests_cov pubsub_websocket_tests ${CMAKE_BINARY_DIR}/coverage/pubsub_websocket_tests/pubsub_websocket_tests ..) @@ -209,7 +209,7 @@ if (BUILD_PUBSUB_PSA_ZMQ) ) target_link_libraries(pubsub_zmq_tests PRIVATE Celix::pubsub_api ${CPPUTEST_LIBRARIES} ${JANSSON_LIBRARIES} Celix::dfi) - target_include_directories(pubsub_zmq_tests PRIVATE ${CPPUTEST_INCLUDE_DIR}) + target_include_directories(pubsub_zmq_tests PRIVATE ${CPPUTEST_INCLUDE_DIR} test) add_test(NAME pubsub_zmq_tests COMMAND pubsub_zmq_tests WORKING_DIRECTORY $) SETUP_TARGET_FOR_COVERAGE(pubsub_zmq_tests_cov pubsub_zmq_tests ${CMAKE_BINARY_DIR}/coverage/pubsub_zmq_tests/pubsub_zmq_tests ..) @@ -229,7 +229,7 @@ if (BUILD_PUBSUB_PSA_ZMQ) pubsub_tst ) target_link_libraries(pubsub_zmq_zerocopy_tests PRIVATE Celix::pubsub_api ${CPPUTEST_LIBRARIES} ${JANSSON_LIBRARIES} Celix::dfi) - target_include_directories(pubsub_zmq_zerocopy_tests PRIVATE ${CPPUTEST_INCLUDE_DIR}) + target_include_directories(pubsub_zmq_zerocopy_tests PRIVATE ${CPPUTEST_INCLUDE_DIR} test) add_test(NAME pubsub_zmq_zerocopy_tests COMMAND pubsub_zmq_zerocopy_tests WORKING_DIRECTORY $) SETUP_TARGET_FOR_COVERAGE(pubsub_zmq_zerocopy_tests_cov pubsub_zmq_zerocopy_tests ${CMAKE_BINARY_DIR}/coverage/pubsub_zmq_tests/pubsub_zmq_zerocopy_tests ..) endif () diff --git a/bundles/pubsub/test/test/test_runner.cc b/bundles/pubsub/test/test/receive_count_service.h similarity index 65% copy from bundles/pubsub/test/test/test_runner.cc copy to bundles/pubsub/test/test/receive_count_service.h index 693c400..8f86c80 100644 --- a/bundles/pubsub/test/test/test_runner.cc +++ b/bundles/pubsub/test/test/receive_count_service.h @@ -17,21 +17,14 @@ * under the License. */ -#include "celix_api.h" +#ifndef CELIX_RECEIVE_COUNT_SERVICE_H +#define CELIX_RECEIVE_COUNT_SERVICE_H -#include -#include +#define CELIX_RECEIVE_COUNT_SERVICE_NAME "celix_receive_count_service" -int main(int argc, char **argv) { - celix_framework_t *fw = NULL; - celixLauncher_launch("config.properties", &fw); +typedef struct celix_receive_count_service { + void *handle; + size_t (*receiveCount)(void *handle); +} celix_receive_count_service_t; - MemoryLeakWarningPlugin::turnOffNewDeleteOverloads(); - int rc = RUN_ALL_TESTS(argc, argv); - - celixLauncher_stop(fw); - celixLauncher_waitForShutdown(fw); - celixLauncher_destroy(fw); - - return rc; -} +#endif //CELIX_RECEIVE_COUNT_SERVICE_H diff --git a/bundles/pubsub/test/test/test_runner.cc b/bundles/pubsub/test/test/test_runner.cc index 693c400..9846d02 100644 --- a/bundles/pubsub/test/test/test_runner.cc +++ b/bundles/pubsub/test/test/test_runner.cc @@ -18,20 +18,54 @@ */ #include "celix_api.h" +#include +#include "receive_count_service.h" #include #include int main(int argc, char **argv) { - celix_framework_t *fw = NULL; - celixLauncher_launch("config.properties", &fw); - MemoryLeakWarningPlugin::turnOffNewDeleteOverloads(); int rc = RUN_ALL_TESTS(argc, argv); - - celixLauncher_stop(fw); - celixLauncher_waitForShutdown(fw); - celixLauncher_destroy(fw); - return rc; } + +TEST_GROUP(PUBSUB_INT_GROUP) { + celix_framework_t *fw = NULL; + celix_bundle_context_t *ctx = NULL; + void setup() { + celixLauncher_launch("config.properties", &fw); + ctx = celix_framework_getFrameworkContext(fw); + } + + void teardown() { + celixLauncher_stop(fw); + celixLauncher_waitForShutdown(fw); + celixLauncher_destroy(fw); + ctx = NULL; + fw = NULL; + } + }; + +TEST(PUBSUB_INT_GROUP, recvTest) { + constexpr int TRIES = 25; + constexpr int TIMEOUT = 250000; + constexpr int MSG_COUNT = 100; + + int count = 0; + + for (int i = 0; i < TRIES; ++i) { + count = 0; + celix_bundleContext_useService(ctx, CELIX_RECEIVE_COUNT_SERVICE_NAME, &count, [](void *handle, void *svc) { + auto* count_ptr = static_cast(handle); + auto* count = static_cast(svc); + *count_ptr = count->receiveCount(count->handle); + }); + printf("Current msg count is %i, waiting for at least %i\n", count, MSG_COUNT); + if (count >= MSG_COUNT) { + break; + } + usleep(TIMEOUT); + } + CHECK(count >= MSG_COUNT); +} \ No newline at end of file diff --git a/bundles/pubsub/test/test/tst_activator.cc b/bundles/pubsub/test/test/tst_activator.c similarity index 58% rename from bundles/pubsub/test/test/tst_activator.cc rename to bundles/pubsub/test/test/tst_activator.c index 4430adb..5a2ca21 100644 --- a/bundles/pubsub/test/test/tst_activator.cc +++ b/bundles/pubsub/test/test/tst_activator.c @@ -26,41 +26,45 @@ #include "pubsub/api.h" #include "msg.h" - -#include -#include -#include - -extern "C" { +#include "receive_count_service.h" static int tst_receive(void *handle, const char *msgType, unsigned int msgTypeId, void *msg, bool *release); +static size_t tst_count(void *handle); struct activator { pubsub_subscriber_t subSvc; long subSvcId; + celix_receive_count_service_t countSvc; + long countSvcId; + pthread_mutex_t mutex; - unsigned int count = 0; + unsigned int count; }; -static struct activator *g_act = NULL; //global - celix_status_t bnd_start(struct activator *act, celix_bundle_context_t *ctx) { pthread_mutex_init(&act->mutex, NULL); - celix_properties_t *props = celix_properties_create(); - celix_properties_set(props, PUBSUB_SUBSCRIBER_TOPIC, "ping"); - act->subSvc.handle = act; - act->subSvc.receive = tst_receive; - act->subSvcId = celix_bundleContext_registerService(ctx, &act->subSvc, PUBSUB_SUBSCRIBER_SERVICE_NAME, props); + { + celix_properties_t *props = celix_properties_create(); + celix_properties_set(props, PUBSUB_SUBSCRIBER_TOPIC, "ping"); + act->subSvc.handle = act; + act->subSvc.receive = tst_receive; + act->subSvcId = celix_bundleContext_registerService(ctx, &act->subSvc, PUBSUB_SUBSCRIBER_SERVICE_NAME, props); + } - g_act = act; + { + act->countSvc.handle = act; + act->countSvc.receiveCount = tst_count; + act->countSvcId = celix_bundleContext_registerService(ctx, &act->countSvc, CELIX_RECEIVE_COUNT_SERVICE_NAME, NULL); + } return CELIX_SUCCESS; } celix_status_t bnd_stop(struct activator *act, celix_bundle_context_t *ctx) { celix_bundleContext_unregisterService(ctx, act->subSvcId); + celix_bundleContext_unregisterService(ctx, act->countSvcId); pthread_mutex_destroy(&act->mutex); return CELIX_SUCCESS; } @@ -68,10 +72,10 @@ celix_status_t bnd_stop(struct activator *act, celix_bundle_context_t *ctx) { CELIX_GEN_BUNDLE_ACTIVATOR(struct activator, bnd_start, bnd_stop) ; -static int tst_receive(void *handle, const char * /*msgType*/, unsigned int /*msgTypeId*/, void * voidMsg, bool */*release*/) { - struct activator *act = static_cast(handle); +static int tst_receive(void *handle, const char * msgType __attribute__((unused)), unsigned int msgTypeId __attribute__((unused)), void * voidMsg, bool *release __attribute__((unused))) { + struct activator *act = handle; - msg_t *msg = static_cast(voidMsg); + msg_t *msg = voidMsg; static int prevSeqNr = 0; int delta = msg->seqNr - prevSeqNr; if (delta != 1) { @@ -85,36 +89,11 @@ static int tst_receive(void *handle, const char * /*msgType*/, unsigned int /*ms return CELIX_SUCCESS; } -} //end extern C - -TEST_GROUP(PUBSUB_INT_GROUP) -{ - void setup() { - //nop - } - - void teardown() { - //nop - } -}; - -TEST(PUBSUB_INT_GROUP, recvTest) { - constexpr int TRIES = 25; - constexpr int TIMEOUT = 250000; - constexpr int MSG_COUNT = 100; - - int count = 0; - - for (int i = 0; i < TRIES; ++i) { - pthread_mutex_lock(&g_act->mutex); - count = g_act->count; - pthread_mutex_unlock(&g_act->mutex); - printf("Current msg count is %i, waiting for at least %i\n", count, MSG_COUNT); - if (count >= MSG_COUNT) { - break; - } - usleep(TIMEOUT); - } - CHECK(count >= MSG_COUNT); - +static size_t tst_count(void *handle) { + struct activator *act = handle; + size_t count; + pthread_mutex_lock(&act->mutex); + count = act->count; + pthread_mutex_unlock(&act->mutex); + return count; } diff --git a/bundles/pubsub/test/test/tst_endpoint_activator.cc b/bundles/pubsub/test/test/tst_endpoint_activator.c similarity index 58% rename from bundles/pubsub/test/test/tst_endpoint_activator.cc rename to bundles/pubsub/test/test/tst_endpoint_activator.c index 652a9af..cf9f6cb 100644 --- a/bundles/pubsub/test/test/tst_endpoint_activator.cc +++ b/bundles/pubsub/test/test/tst_endpoint_activator.c @@ -26,41 +26,48 @@ #include "pubsub/api.h" #include "msg.h" +#include "receive_count_service.h" -#include -#include -#include - -extern "C" { static int tst_receive(void *handle, const char *msgType, unsigned int msgTypeId, void *msg, bool *release); +static size_t tst_count(void *handle); struct activator { pubsub_subscriber_t subSvc; long subSvcId; + celix_receive_count_service_t countSvc; + long countSvcId; + pthread_mutex_t mutex; - unsigned int count = 0; + unsigned int count; }; -static struct activator *g_act = NULL; //global - celix_status_t bnd_start(struct activator *act, celix_bundle_context_t *ctx) { pthread_mutex_init(&act->mutex, NULL); - celix_properties_t *props = celix_properties_create(); - celix_properties_set(props, PUBSUB_SUBSCRIBER_TOPIC, "ping2"); - act->subSvc.handle = act; - act->subSvc.receive = tst_receive; - act->subSvcId = celix_bundleContext_registerService(ctx, &act->subSvc, PUBSUB_SUBSCRIBER_SERVICE_NAME, props); + { + celix_properties_t *props = celix_properties_create(); + celix_properties_set(props, PUBSUB_SUBSCRIBER_TOPIC, "ping2"); + act->subSvc.handle = act; + act->subSvc.receive = tst_receive; + act->subSvcId = celix_bundleContext_registerService(ctx, &act->subSvc, PUBSUB_SUBSCRIBER_SERVICE_NAME, props); + } + + + { + act->countSvc.handle = act; + act->countSvc.receiveCount = tst_count; + act->countSvcId = celix_bundleContext_registerService(ctx, &act->countSvc, CELIX_RECEIVE_COUNT_SERVICE_NAME, NULL); + } - g_act = act; return CELIX_SUCCESS; } celix_status_t bnd_stop(struct activator *act, celix_bundle_context_t *ctx) { celix_bundleContext_unregisterService(ctx, act->subSvcId); + celix_bundleContext_unregisterService(ctx, act->countSvcId); pthread_mutex_destroy(&act->mutex); return CELIX_SUCCESS; } @@ -68,10 +75,10 @@ celix_status_t bnd_stop(struct activator *act, celix_bundle_context_t *ctx) { CELIX_GEN_BUNDLE_ACTIVATOR(struct activator, bnd_start, bnd_stop) ; -static int tst_receive(void *handle, const char * /*msgType*/, unsigned int /*msgTypeId*/, void * voidMsg, bool */*release*/) { - struct activator *act = static_cast(handle); +static int tst_receive(void *handle, const char * msgType __attribute__((unused)), unsigned int msgTypeId __attribute__((unused)), void * voidMsg, bool *release __attribute__((unused))) { + struct activator *act = handle; - msg_t *msg = static_cast(voidMsg); + msg_t *msg = voidMsg; static int prevSeqNr = 0; int delta = msg->seqNr - prevSeqNr; if (delta != 1) { @@ -85,36 +92,11 @@ static int tst_receive(void *handle, const char * /*msgType*/, unsigned int /*ms return CELIX_SUCCESS; } -} //end extern C - -TEST_GROUP(PUBSUB_INT_GROUP) -{ - void setup() { - //nop - } - - void teardown() { - //nop - } -}; - -TEST(PUBSUB_INT_GROUP, recvTest) { - constexpr int TRIES = 25; - constexpr int TIMEOUT = 250000; - constexpr int MSG_COUNT = 100; - - int count = 0; - - for (int i = 0; i < TRIES; ++i) { - pthread_mutex_lock(&g_act->mutex); - count = g_act->count; - pthread_mutex_unlock(&g_act->mutex); - printf("Current msg count is %i, waiting for at least %i\n", count, MSG_COUNT); - if (count >= MSG_COUNT) { - break; - } - usleep(TIMEOUT); - } - CHECK(count >= MSG_COUNT); - +static size_t tst_count(void *handle) { + struct activator *act = handle; + size_t count; + pthread_mutex_lock(&act->mutex); + count = act->count; + pthread_mutex_unlock(&act->mutex); + return count; }