celix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pnol...@apache.org
Subject [44/50] [abbrv] celix git commit: CELIX-237: Fixed an issue in the dyn_type, added some extra tests and improved some logging handling in the framework
Date Tue, 13 Oct 2015 10:22:12 GMT
CELIX-237: Fixed an issue in the dyn_type, added some extra tests and improved some logging
handling in the framework


Project: http://git-wip-us.apache.org/repos/asf/celix/repo
Commit: http://git-wip-us.apache.org/repos/asf/celix/commit/f3ae660e
Tree: http://git-wip-us.apache.org/repos/asf/celix/tree/f3ae660e
Diff: http://git-wip-us.apache.org/repos/asf/celix/diff/f3ae660e

Branch: refs/heads/develop
Commit: f3ae660e980859ffa29bbcfa829c4db591791f9f
Parents: 3f71ac4
Author: Pepijn Noltes <pepijnnoltes@gmail.com>
Authored: Wed Oct 7 14:30:51 2015 +0200
Committer: Pepijn Noltes <pepijnnoltes@gmail.com>
Committed: Wed Oct 7 14:30:51 2015 +0200

----------------------------------------------------------------------
 framework/private/src/celix_log.c                |  5 ++++-
 framework/private/src/framework.c                | 12 ++++++------
 .../dynamic_function_interface/dyn_type.c        |  3 ++-
 .../dynamic_function_interface/json_rpc.c        |  2 +-
 .../descriptors/example3.descriptor              | 11 +++++++++++
 .../dyn_interface_tests.cpp                      | 16 ++++++++++++++++
 .../dyn_type_tests.cpp                           | 19 ++++++++++++++++++-
 .../json_rpc_tests.cpp                           | 11 ++++++++++-
 .../rsa/private/src/export_registration_dfi.c    |  2 ++
 .../rsa/private/src/import_registration_dfi.c    |  2 +-
 10 files changed, 71 insertions(+), 12 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/celix/blob/f3ae660e/framework/private/src/celix_log.c
----------------------------------------------------------------------
diff --git a/framework/private/src/celix_log.c b/framework/private/src/celix_log.c
index 404c02f..d2e222e 100644
--- a/framework/private/src/celix_log.c
+++ b/framework/private/src/celix_log.c
@@ -34,7 +34,10 @@ void framework_log(framework_logger_pt logger, framework_log_level_t level,
cons
     va_start(listPointer, fmsg);
     vsprintf(msg, fmsg, listPointer);
 
-    logger->logFunction(level, func, file, line, msg);
+    //FIXME logger and/or logger->logFucntion can be null. But this solution is not thread
safe!
+    if (logger != NULL && logger->logFunction != NULL) {
+        logger->logFunction(level, func, file, line, msg);
+    }
 }
 
 void framework_logCode(framework_logger_pt logger, framework_log_level_t level, const char
*func, const char *file, int line, celix_status_t code, char *fmsg, ...) {

http://git-wip-us.apache.org/repos/asf/celix/blob/f3ae660e/framework/private/src/framework.c
----------------------------------------------------------------------
diff --git a/framework/private/src/framework.c b/framework/private/src/framework.c
index 17cfdba..22abc43 100644
--- a/framework/private/src/framework.c
+++ b/framework/private/src/framework.c
@@ -322,11 +322,6 @@ celix_status_t framework_destroy(framework_pt framework) {
 
 	unsetenv(OSGI_FRAMEWORK_FRAMEWORK_UUID);
 
-	logger = hashMap_get(framework->configurationMap, "logger");
-	if (logger == NULL) {
-		free(framework->logger);
-	}
-
 	celixThreadCondition_destroy(&framework->dispatcher);
 	celixThreadMutex_destroy(&framework->bundleListenerLock);
 	celixThreadMutex_destroy(&framework->dispatcherLock);
@@ -335,9 +330,14 @@ celix_status_t framework_destroy(framework_pt framework) {
 	celixThreadMutex_destroy(&framework->mutex);
 	celixThreadCondition_destroy(&framework->condition);
 
+    logger = hashMap_get(framework->configurationMap, "logger");
+    if (logger == NULL) {
+        free(framework->logger);
+    }
+
     properties_destroy(framework->configurationMap);
 
-	free(framework);
+    free(framework);
 
 	return status;
 }

http://git-wip-us.apache.org/repos/asf/celix/blob/f3ae660e/remote_services/remote_service_admin_dfi/dynamic_function_interface/dyn_type.c
----------------------------------------------------------------------
diff --git a/remote_services/remote_service_admin_dfi/dynamic_function_interface/dyn_type.c
b/remote_services/remote_service_admin_dfi/dynamic_function_interface/dyn_type.c
index 88f8766..972278d 100644
--- a/remote_services/remote_service_admin_dfi/dynamic_function_interface/dyn_type.c
+++ b/remote_services/remote_service_admin_dfi/dynamic_function_interface/dyn_type.c
@@ -301,7 +301,7 @@ static int dynType_parseComplex(FILE *stream, dyn_type *type) {
         if (type->complex.structType.elements != NULL) {
             int index = 0;
             TAILQ_FOREACH(entry, &type->complex.entriesHead, entries) {
-                type->complex.structType.elements[index++] = entry->type->ffiType;
+                type->complex.structType.elements[index++] = dynType_ffiType(entry->type);
             }
         } else {
             status = MEM_ERROR;
@@ -576,6 +576,7 @@ static void dynType_clearTypedPointer(dyn_type *type) {
 
 int dynType_alloc(dyn_type *type, void **bufLoc) {
     assert(type->type != DYN_TYPE_REF);
+    assert(type->ffiType->size != 0);
     int status = OK;
 
     void *inst = calloc(1, type->ffiType->size);

http://git-wip-us.apache.org/repos/asf/celix/blob/f3ae660e/remote_services/remote_service_admin_dfi/dynamic_function_interface/json_rpc.c
----------------------------------------------------------------------
diff --git a/remote_services/remote_service_admin_dfi/dynamic_function_interface/json_rpc.c
b/remote_services/remote_service_admin_dfi/dynamic_function_interface/json_rpc.c
index 01dc6b5..756b24e 100644
--- a/remote_services/remote_service_admin_dfi/dynamic_function_interface/json_rpc.c
+++ b/remote_services/remote_service_admin_dfi/dynamic_function_interface/json_rpc.c
@@ -128,7 +128,7 @@ int jsonRpc_call(dyn_interface_type *intf, void *service, const char *request,
c
         dyn_type *argType = dynFunction_argumentTypeForIndex(func, i);
         enum dyn_function_argument_meta  meta = dynFunction_argumentMetaForIndex(func, i);
         if (meta == DYN_FUNCTION_ARGUMENT_META__STD) {
-            //TODO SOMETIMES segfault dynType_free(argType, args[i]);
+            dynType_free(argType, args[i]);
         }
     }
 

http://git-wip-us.apache.org/repos/asf/celix/blob/f3ae660e/remote_services/remote_service_admin_dfi/dynamic_function_interface_tst/descriptors/example3.descriptor
----------------------------------------------------------------------
diff --git a/remote_services/remote_service_admin_dfi/dynamic_function_interface_tst/descriptors/example3.descriptor
b/remote_services/remote_service_admin_dfi/dynamic_function_interface_tst/descriptors/example3.descriptor
new file mode 100644
index 0000000..c89d969
--- /dev/null
+++ b/remote_services/remote_service_admin_dfi/dynamic_function_interface_tst/descriptors/example3.descriptor
@@ -0,0 +1,11 @@
+:header
+type=interface
+name=detection_provider
+version=1.0.0
+:annotations
+:types
+location={DD lat lon}
+target={Jllocation;DDJ id location speed heading lastUpdated}
+detection={Jllocation;Dltarget; id center range simulated}
+:methods
+getDetections()Ljava/util/List;=getDetections(#am=handle;P#am=out;**[Ldetection;)N

http://git-wip-us.apache.org/repos/asf/celix/blob/f3ae660e/remote_services/remote_service_admin_dfi/dynamic_function_interface_tst/dyn_interface_tests.cpp
----------------------------------------------------------------------
diff --git a/remote_services/remote_service_admin_dfi/dynamic_function_interface_tst/dyn_interface_tests.cpp
b/remote_services/remote_service_admin_dfi/dynamic_function_interface_tst/dyn_interface_tests.cpp
index 679260f..f7cc370 100644
--- a/remote_services/remote_service_admin_dfi/dynamic_function_interface_tst/dyn_interface_tests.cpp
+++ b/remote_services/remote_service_admin_dfi/dynamic_function_interface_tst/dyn_interface_tests.cpp
@@ -69,6 +69,18 @@ extern "C" {
         dynInterface_destroy(dynIntf);
     }
 
+    static void test2(void) {
+        int status = 0;
+        dyn_interface_type *dynIntf = NULL;
+        FILE *desc = fopen("descriptors/example3.descriptor", "r");
+        assert(desc != NULL);
+        status = dynInterface_parse(desc, &dynIntf);
+        CHECK_EQUAL(0, status);
+        fclose(desc);
+
+        dynInterface_destroy(dynIntf);
+    }
+
 }
 
 
@@ -85,3 +97,7 @@ TEST_GROUP(DynInterfaceTests) {
 TEST(DynInterfaceTests, test1) {
     test1();
 }
+
+TEST(DynInterfaceTests, test2) {
+    test2();
+}

http://git-wip-us.apache.org/repos/asf/celix/blob/f3ae660e/remote_services/remote_service_admin_dfi/dynamic_function_interface_tst/dyn_type_tests.cpp
----------------------------------------------------------------------
diff --git a/remote_services/remote_service_admin_dfi/dynamic_function_interface_tst/dyn_type_tests.cpp
b/remote_services/remote_service_admin_dfi/dynamic_function_interface_tst/dyn_type_tests.cpp
index ae14c0f..57db391 100644
--- a/remote_services/remote_service_admin_dfi/dynamic_function_interface_tst/dyn_type_tests.cpp
+++ b/remote_services/remote_service_admin_dfi/dynamic_function_interface_tst/dyn_type_tests.cpp
@@ -22,12 +22,27 @@ extern "C" {
 
     static void runTest(const char *descriptorStr, const char *exName) {
         dyn_type *type;
-        int i;
         type = NULL;
         //printf("\n-- example %s with descriptor string '%s' --\n", exName, descriptorStr);
         int status = dynType_parseWithStr(descriptorStr, exName, NULL, &type);
         CHECK_EQUAL(0, status);
 
+        //MEM check, to try to ensure no mem leaks/corruptions occur.
+        int i;
+        int j;
+        int nrOfBurst = 10;
+        int burst = 50;
+        void *pointers[burst];
+        for (j = 0; j < nrOfBurst; j += 1) {
+            for (i = 0; i < burst ; i +=1 ) {
+                pointers[i] = NULL;
+                dynType_alloc(type, &pointers[i]);
+            }
+            for (i = 0; i < burst ; i +=1 ) {
+                dynType_free(type, pointers[i]);
+            }
+        }
+
         FILE *stream = fopen("/dev/null", "w");
         dynType_print(type, stream);
         fclose(stream);
@@ -56,6 +71,7 @@ TEST_GROUP(DynTypeTests) {
 #define EX12 "Tnode={Lnode;Lnode; left right};{Lnode; head}" //note recursive example
 #define EX13 "Ttype={DDDDD a b c d e};{ltype;Ltype;ltype;Ltype; byVal1 byRef1 byVal2 ByRef2}"

 #define EX14 "{DD{FF{JJ}{II*{ss}}}}"  //unnamed fields
+#define EX15 "Tsample={jDD time val1 val2};Tresult={jDlsample; time result sample};Lresult;"
 
 #define CREATE_EXAMPLES_TEST(DESC) \
     TEST(DynTypeTests, ParseTestExample ## DESC) { \
@@ -76,6 +92,7 @@ CREATE_EXAMPLES_TEST(EX11)
 CREATE_EXAMPLES_TEST(EX12)
 CREATE_EXAMPLES_TEST(EX13)
 CREATE_EXAMPLES_TEST(EX14)
+CREATE_EXAMPLES_TEST(EX15)
 
 TEST(DynTypeTests, ParseRandomGarbageTest) {
     /*

http://git-wip-us.apache.org/repos/asf/celix/blob/f3ae660e/remote_services/remote_service_admin_dfi/dynamic_function_interface_tst/json_rpc_tests.cpp
----------------------------------------------------------------------
diff --git a/remote_services/remote_service_admin_dfi/dynamic_function_interface_tst/json_rpc_tests.cpp
b/remote_services/remote_service_admin_dfi/dynamic_function_interface_tst/json_rpc_tests.cpp
index 6140bec..c7a3350 100644
--- a/remote_services/remote_service_admin_dfi/dynamic_function_interface_tst/json_rpc_tests.cpp
+++ b/remote_services/remote_service_admin_dfi/dynamic_function_interface_tst/json_rpc_tests.cpp
@@ -156,6 +156,7 @@ static void stdLog(void *handle, int level, const char *file, int line,
const ch
         CHECK(desc != NULL);
         int rc = dynInterface_parse(desc, &intf);
         CHECK_EQUAL(0, rc);
+        fclose(desc);
 
         char *result = NULL;
 
@@ -178,6 +179,7 @@ static void stdLog(void *handle, int level, const char *file, int line,
const ch
         CHECK(desc != NULL);
         int rc = dynInterface_parse(desc, &intf);
         CHECK_EQUAL(0, rc);
+        fclose(desc);
 
         char *result = NULL;
 
@@ -199,6 +201,7 @@ static void stdLog(void *handle, int level, const char *file, int line,
const ch
         CHECK(desc != NULL);
         int rc = dynInterface_parse(desc, &intf);
         CHECK_EQUAL(0, rc);
+        fclose(desc);
 
         struct methods_head *head;
         dynInterface_methods(intf, &head);
@@ -238,6 +241,7 @@ static void stdLog(void *handle, int level, const char *file, int line,
const ch
         CHECK(desc != NULL);
         int rc = dynInterface_parse(desc, &intf);
         CHECK_EQUAL(0, rc);
+        fclose(desc);
 
         struct methods_head *head;
         dynInterface_methods(intf, &head);
@@ -273,9 +277,14 @@ static void stdLog(void *handle, int level, const char *file, int line,
const ch
         CHECK_EQUAL(2.5, result->buf[1]->b);
 
 
+        int i;
+        for (i = 0; i < result->len; i +=1 ) {
+            free(result->buf[i]);
+        }
         free(result->buf);
         free(result);
-        dynInterface_destroy(intf);    }
+        dynInterface_destroy(intf);
+    }
 
 }
 

http://git-wip-us.apache.org/repos/asf/celix/blob/f3ae660e/remote_services/remote_service_admin_dfi/rsa/private/src/export_registration_dfi.c
----------------------------------------------------------------------
diff --git a/remote_services/remote_service_admin_dfi/rsa/private/src/export_registration_dfi.c
b/remote_services/remote_service_admin_dfi/rsa/private/src/export_registration_dfi.c
index edc085e..474749f 100644
--- a/remote_services/remote_service_admin_dfi/rsa/private/src/export_registration_dfi.c
+++ b/remote_services/remote_service_admin_dfi/rsa/private/src/export_registration_dfi.c
@@ -119,6 +119,8 @@ celix_status_t exportRegistration_create(log_helper_pt helper, service_reference
 celix_status_t exportRegistration_call(export_registration_pt export, char *data, int datalength,
char **responseOut, int *responseLength) {
     int status = CELIX_SUCCESS;
 
+    //printf("calling for '%s'\n");
+
     *responseLength = -1;
     celixThreadMutex_lock(&export->mutex);
     status = jsonRpc_call(export->intf, export->service, data, responseOut);

http://git-wip-us.apache.org/repos/asf/celix/blob/f3ae660e/remote_services/remote_service_admin_dfi/rsa/private/src/import_registration_dfi.c
----------------------------------------------------------------------
diff --git a/remote_services/remote_service_admin_dfi/rsa/private/src/import_registration_dfi.c
b/remote_services/remote_service_admin_dfi/rsa/private/src/import_registration_dfi.c
index 680a75a..fdc95df 100644
--- a/remote_services/remote_service_admin_dfi/rsa/private/src/import_registration_dfi.c
+++ b/remote_services/remote_service_admin_dfi/rsa/private/src/import_registration_dfi.c
@@ -249,7 +249,7 @@ static void importRegistration_proxyFunc(void *userData, void *args[],
void *ret
         //printf("request sended. got reply '%s' with status %i\n", reply, rc);
 
         if (rc == 0) {
-            //printf("Handling reply '%s'\n", reply);
+            //fjprintf("Handling reply '%s'\n", reply);
             status = jsonRpc_handleReply(entry->dynFunc, reply, args);
         }
 


Mime
View raw message