celix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pnol...@apache.org
Subject [2/2] celix git commit: CELIX-237: Updated avro translator, added test for avro translator and removed mem bugs in avro translator
Date Wed, 08 Jul 2015 20:34:19 GMT
CELIX-237: Updated avro translator, added test for avro translator and removed mem bugs in
avro translator


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

Branch: refs/heads/feature/CELIX-237_rsa-ffi
Commit: dcbdd97dd3b246c4bec439e6fac3f941060efd5f
Parents: 4c62532
Author: Pepijn Noltes <pepijnnoltes@gmail.com>
Authored: Wed Jul 8 22:32:35 2015 +0200
Committer: Pepijn Noltes <pepijnnoltes@gmail.com>
Committed: Wed Jul 8 22:32:35 2015 +0200

----------------------------------------------------------------------
 .../avro_descriptor_translator.c                | 23 ++++----
 .../dynamic_function_interface/dfi_log_util.h   |  8 +--
 .../dynamic_function_interface/dyn_interface.c  | 49 ++++++++++++++---
 .../schemas/invalid1.avpr                       | 29 ++++++++++
 .../schemas/invalid2.avpr                       | 31 +++++++++++
 .../tst/avro_descriptor_translator_tests.cpp    | 56 ++++++++++++++------
 .../tst/dyn_closure_tests.cpp                   |  3 +-
 .../tst/dyn_function_tests.cpp                  |  4 +-
 .../tst/dyn_type_tests.cpp                      |  2 +-
 .../tst/json_serializer_tests.cpp               |  1 +
 10 files changed, 163 insertions(+), 43 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/celix/blob/dcbdd97d/remote_services/dynamic_function_interface/avro_descriptor_translator.c
----------------------------------------------------------------------
diff --git a/remote_services/dynamic_function_interface/avro_descriptor_translator.c b/remote_services/dynamic_function_interface/avro_descriptor_translator.c
index cc7b3e6..a9fea1d 100644
--- a/remote_services/dynamic_function_interface/avro_descriptor_translator.c
+++ b/remote_services/dynamic_function_interface/avro_descriptor_translator.c
@@ -32,7 +32,7 @@ int descriptorTranslator_translate(const char *schemaStr, dyn_interface_type
**o
     int status = OK;
 
     dyn_interface_type *intf = NULL;
-    status = dynInterface_create("TODO", &intf);
+    status = dynInterface_create("TODO", &intf); //TODO parse json first retreive 'Protocol'
string value
     if (status == 0) {
         json_error_t error;
         json_t *schema = json_loads(schemaStr, JSON_DECODE_ANY, &error);
@@ -43,24 +43,25 @@ int descriptorTranslator_translate(const char *schemaStr, dyn_interface_type
**o
                 json_t *type = NULL;
                 int index = 0;
                 json_array_foreach(types, index, type) {
-                    descriptorTranslator_parseType(intf, type);
+                    status = descriptorTranslator_parseType(intf, type);
+                    if (status != OK) { 
+                        break;
+                    }
                 }
-
             }
             json_t *messages = json_object_get(schema, "messages");
-            if (messages != NULL) {
+            if (status == OK && messages != NULL) {
                 const char *name;
                 json_t *message;
-                int rc = 0;
                 int index = 0;
                 json_object_foreach(messages, name, message) {
-                   rc = descriptorTranslator_createMethodInfo(intf, schema, name, index++,
message); 
-                   if (rc != OK) {
+                   status = descriptorTranslator_createMethodInfo(intf, schema, name, index++,
message); 
+                   if (status != OK) {
                        break;
                    }
                 }
             }
-            //json_decref(schema);
+            json_decref(schema);
         } else {
             status = PARSE_ERROR;
             printf("AVRO_DESCRIPTOR_TRANSLATOR: error parsing json input '%s'. Error is %s\n",
schemaStr, error.text);
@@ -143,7 +144,7 @@ static int descriptorTranslator_parseMessage(json_t *schema, const char
*name, j
                 if (type != NULL) {
                     status = descriptorTranslator_parseArgument(memStream, type);
                 } else {
-                    printf("expected type for request argument %zu for message %s\n", index,
name);
+                    LOG_ERROR("expected json object with name value for request argument
%zu for message/method %s\n", index, name);
                     status = PARSE_ERROR;
                 }
                 if (status != OK) { 
@@ -152,7 +153,7 @@ static int descriptorTranslator_parseMessage(json_t *schema, const char
*name, j
             }
         } else {
             status = PARSE_ERROR;
-            printf("Expected request for message %s\n", name);    
+            LOG_ERROR("Expected request for message %s\n", name);    
         }
 
         json_t *response = json_object_get(message, "response");
@@ -229,7 +230,7 @@ static int descriptorTranslator_parseArgument(FILE *stream, json_t *type)
{
             fputc('[', stream);
             descriptorTranslator_parseArgument(stream, items);
         } else {
-            printf("sub type %s not supported\n", json_string_value(subType));
+            LOG_ERROR("sub type %s not supported\n", json_string_value(subType));
             status = PARSE_ERROR;
         }
     }

http://git-wip-us.apache.org/repos/asf/celix/blob/dcbdd97d/remote_services/dynamic_function_interface/dfi_log_util.h
----------------------------------------------------------------------
diff --git a/remote_services/dynamic_function_interface/dfi_log_util.h b/remote_services/dynamic_function_interface/dfi_log_util.h
index 80fecfb..8dfd9bd 100644
--- a/remote_services/dynamic_function_interface/dfi_log_util.h
+++ b/remote_services/dynamic_function_interface/dfi_log_util.h
@@ -26,22 +26,22 @@ typedef void (*logf_ft)(void *handle, int level, const char *file, int
line, con
 #define LOG_LVL_DEBUG    4
 
 #define LOG_ERROR(msg, ...) \
-    if (g_logf != NULL && g_currentLogLevel <= LOG_LVL_ERROR) { \
+    if (g_logf != NULL && g_currentLogLevel >= LOG_LVL_ERROR) { \
         g_logf(g_logHandle, LOG_LVL_ERROR, __FILE__, __LINE__, (msg), ##__VA_ARGS__); \
     } 
 
 #define LOG_WARNING(msg, ...) \
-    if (g_logf != NULL && g_currentLogLevel <= LOG_LVL_WARNING) { \
+    if (g_logf != NULL && g_currentLogLevel >= LOG_LVL_WARNING) { \
         g_logf(g_logHandle, LOG_LVL_WARNING, __FILE__, __LINE__, (msg), ##__VA_ARGS__); \
     } 
 
 #define LOG_INFO(msg, ...) \
-    if (g_logf != NULL && g_currentLogLevel <= LOG_LVL_INFO) { \
+    if (g_logf != NULL && g_currentLogLevel >= LOG_LVL_INFO) { \
         g_logf(g_logHandle, LOG_LVL_INFO, __FILE__, __LINE__, (msg), ##__VA_ARGS__); \
     } 
 
 #define LOG_DEBUG(msg, ...) \
-    if (g_logf != NULL && g_currentLogLevel <= LOG_LVL_DEBUG) { \
+    if (g_logf != NULL && g_currentLogLevel >= LOG_LVL_DEBUG) { \
         g_logf(g_logHandle, LOG_LVL_DEBUG, __FILE__, __LINE__, (msg), ##__VA_ARGS__); \
     } 
 

http://git-wip-us.apache.org/repos/asf/celix/blob/dcbdd97d/remote_services/dynamic_function_interface/dyn_interface.c
----------------------------------------------------------------------
diff --git a/remote_services/dynamic_function_interface/dyn_interface.c b/remote_services/dynamic_function_interface/dyn_interface.c
index bb0b525..601669c 100644
--- a/remote_services/dynamic_function_interface/dyn_interface.c
+++ b/remote_services/dynamic_function_interface/dyn_interface.c
@@ -32,16 +32,49 @@ void dynInterface_destroy(dyn_interface_type *intf) {
         if (intf->name != NULL) {
             free(intf->name);
         }
-        type_info_type *tInfo = NULL;
-        TAILQ_FOREACH(tInfo, &intf->typeInfos, entries) {
-            LOG_WARNING("TODO");
-            //TODO add destroy func for type_info
+
+        type_info_type *tmp = NULL;
+        type_info_type *tInfo = TAILQ_FIRST(&intf->typeInfos);
+        while (tInfo != NULL) {
+            tmp = tInfo;
+            tInfo = TAILQ_NEXT(tInfo, entries);
+
+            if (tmp->name != NULL) {
+                free(tmp->name);
+            }
+            if (tmp->descriptor != NULL) {
+                free(tmp->descriptor);
+            }
+
+            free(tmp);
         }
-        method_info_type *mInfo = NULL;
-        TAILQ_FOREACH(mInfo, &intf->typeInfos, entries) {
-            LOG_WARNING("TODO");
-            //TODO add destroy func for method
+
+        method_info_type *mTmp = NULL;
+        method_info_type *mInfo = TAILQ_FIRST(&intf->methodInfos);
+        while (mInfo != NULL) {
+            mTmp = mInfo;
+            mInfo = TAILQ_NEXT(mInfo, entries);
+            
+            if (mTmp->strIdentifier != NULL) {
+                free(mTmp->strIdentifier);
+            }
+            if (mTmp->descriptor != NULL) {
+                free(mTmp->descriptor);
+            }
+            if (mTmp->name != NULL) {
+                free(mTmp->name);
+            }
+            if (mTmp->dynFunc != NULL) {
+                dynFunction_destroy(mTmp->dynFunc);
+            }
+            if (mTmp->dynClosure != NULL) {
+                dynClosure_destroy(mTmp->dynClosure);
+            }
+
+            free(mTmp);
         }
+
+        free(intf);
     } 
 }
 

http://git-wip-us.apache.org/repos/asf/celix/blob/dcbdd97d/remote_services/dynamic_function_interface/schemas/invalid1.avpr
----------------------------------------------------------------------
diff --git a/remote_services/dynamic_function_interface/schemas/invalid1.avpr b/remote_services/dynamic_function_interface/schemas/invalid1.avpr
new file mode 100644
index 0000000..c968c61
--- /dev/null
+++ b/remote_services/dynamic_function_interface/schemas/invalid1.avpr
@@ -0,0 +1,29 @@
+{
+  "protocol" : "Complex",
+  "namespace" : null,
+  "types" : [ {
+    "type" : "record",
+    "name" : "StatResult",
+    "fields" : [ {
+      "name" : "sum",
+      "type" : "double"
+    }, {
+      "name" : "min",
+      "type" : "double"
+    }, {
+      "name" : "max",
+      "type" : "double"
+    }, {
+      "name" : "input",
+      "type" : {
+        "type" : "array",
+        "items" : "double"
+      }
+    } ]
+  } ],
+  "messages" : {
+    "stats" : {
+      "response" : "StatResult"
+    }
+  }
+}

http://git-wip-us.apache.org/repos/asf/celix/blob/dcbdd97d/remote_services/dynamic_function_interface/schemas/invalid2.avpr
----------------------------------------------------------------------
diff --git a/remote_services/dynamic_function_interface/schemas/invalid2.avpr b/remote_services/dynamic_function_interface/schemas/invalid2.avpr
new file mode 100644
index 0000000..fc48ca9
--- /dev/null
+++ b/remote_services/dynamic_function_interface/schemas/invalid2.avpr
@@ -0,0 +1,31 @@
+{
+  "protocol" : "Simple",
+  "types" : [ ],
+  "messages" : {
+    "sum" : {
+      "request" : [ {
+        "name" : "a"
+      }, {
+        "name" : "b",
+        "type" : "double"
+      } ],
+      "response" : "double"
+    },
+    "sub" : {
+      "request" : [ {
+        "name" : "a",
+        "type" : "double"
+      }, {
+        "name" : "b",
+        "type" : "double"
+      } ],
+      "response" : "double"
+    },
+    "sqrt" : {
+      "request" : [ {
+        "name" : "a"
+      } ],
+      "response" : "double"
+    }
+  }
+}

http://git-wip-us.apache.org/repos/asf/celix/blob/dcbdd97d/remote_services/dynamic_function_interface/tst/avro_descriptor_translator_tests.cpp
----------------------------------------------------------------------
diff --git a/remote_services/dynamic_function_interface/tst/avro_descriptor_translator_tests.cpp
b/remote_services/dynamic_function_interface/tst/avro_descriptor_translator_tests.cpp
index 87fd76a..8f8dbc8 100644
--- a/remote_services/dynamic_function_interface/tst/avro_descriptor_translator_tests.cpp
+++ b/remote_services/dynamic_function_interface/tst/avro_descriptor_translator_tests.cpp
@@ -78,22 +78,22 @@ extern "C" {
         return count;
     }
 
-    static void test1(void) {
+    static void simple(void) {
         //first argument void *handle, last argument output pointer for result and return
int with status for exception handling
         //sum(DD)D -> sum(PDD*D)N 
         //sub(DD)D -> sub(PDD*D)N
         //sqrt(D)D -> sqrt(PD*D)N
 
-        dyn_interface_type *ift = createInterfaceInfo("schemas/simple.avpr");
+        dyn_interface_type *intf = createInterfaceInfo("schemas/simple.avpr");
 
-        int count = countMethodInfos(ift);
+        int count = countMethodInfos(intf);
         CHECK_EQUAL(3, count);
 
-        count = countTypeInfos(ift);
+        count = countTypeInfos(intf);
         CHECK_EQUAL(0, count);
 
         method_info_type *mInfo = NULL;
-        TAILQ_FOREACH(mInfo, &ift->methodInfos, entries) {
+        TAILQ_FOREACH(mInfo, &intf->methodInfos, entries) {
             if (strcmp("sum", mInfo->name) == 0) {
                 STRCMP_EQUAL("sum(PDD*D)N", mInfo->descriptor);
             } else if (strcmp("add", mInfo->name) == 0) {
@@ -102,37 +102,61 @@ extern "C" {
                 STRCMP_EQUAL("sqrt(PD*D)N", mInfo->descriptor);
             }
         }
+
+        dynInterface_destroy(intf);
     }
 
-    static void test2(void) {
-        dyn_interface_type *ift = createInterfaceInfo("schemas/complex.avpr");
+    static void complex(void) {
+        dyn_interface_type *intf = createInterfaceInfo("schemas/complex.avpr");
 
-        int count = countMethodInfos(ift);
+        int count = countMethodInfos(intf);
         CHECK_EQUAL(1, count);
 
-        method_info_type *mInfo = TAILQ_FIRST(&ift->methodInfos);
+        method_info_type *mInfo = TAILQ_FIRST(&intf->methodInfos);
+        STRCMP_EQUAL("stats", mInfo->name);
         STRCMP_EQUAL("stats(P[D*LStatResult;)N", mInfo->descriptor);
 
-        count = countTypeInfos(ift);
+        count = countTypeInfos(intf);
         CHECK_EQUAL(1, count);
 
-        type_info_type *tInfo = TAILQ_FIRST(&ift->typeInfos);
+        type_info_type *tInfo = TAILQ_FIRST(&intf->typeInfos);
         STRCMP_EQUAL("StatResult", tInfo->name);
         STRCMP_EQUAL("{DDD[D sum min max input}", tInfo->descriptor);
+
+        dynInterface_destroy(intf);
     }
 
+    static void invalid(const char *file) {
+        char *schema = readSchema(file);
+        dyn_interface_type *ift= NULL;
+
+        int status = descriptorTranslator_translate(schema, &ift);
+        CHECK(status != 0);
+        
+        free(schema);
+    }
 }
 
 TEST_GROUP(AvroDescTranslatorTest) {
     void setup() {
-        descriptorTranslator_logSetup(stdLog, NULL, 4);
+        descriptorTranslator_logSetup(stdLog, NULL, 3);
+        dynInterface_logSetup(stdLog, NULL, 3);
+        dynType_logSetup(stdLog, NULL, 3);
     }
 };
 
-TEST(AvroDescTranslatorTest, Test1) {
-    test1();
+TEST(AvroDescTranslatorTest, simple) {
+    simple();
+}
+
+TEST(AvroDescTranslatorTest, complex) {
+    complex();
+}
+
+TEST(AvroDescTranslatorTest, invalid1) {
+    invalid("schemas/invalid1.avpr");
 }
 
-TEST(AvroDescTranslatorTest, Test2) {
-    test2();
+TEST(AvroDescTranslatorTest, invalid2) {
+    invalid("schemas/invalid2.avpr");
 }

http://git-wip-us.apache.org/repos/asf/celix/blob/dcbdd97d/remote_services/dynamic_function_interface/tst/dyn_closure_tests.cpp
----------------------------------------------------------------------
diff --git a/remote_services/dynamic_function_interface/tst/dyn_closure_tests.cpp b/remote_services/dynamic_function_interface/tst/dyn_closure_tests.cpp
index 94808d9..ac0566b 100644
--- a/remote_services/dynamic_function_interface/tst/dyn_closure_tests.cpp
+++ b/remote_services/dynamic_function_interface/tst/dyn_closure_tests.cpp
@@ -127,7 +127,8 @@ static void tests() {
 
 TEST_GROUP(DynClosureTests) {
     void setup() {
-        dynFunction_logSetup(stdLog, NULL, 4);
+        dynFunction_logSetup(stdLog, NULL, 3);
+        dynType_logSetup(stdLog, NULL, 3);
         //TODO dynType_logSetup(stdLog, NULL, 4);
         g_count = 0;
     }

http://git-wip-us.apache.org/repos/asf/celix/blob/dcbdd97d/remote_services/dynamic_function_interface/tst/dyn_function_tests.cpp
----------------------------------------------------------------------
diff --git a/remote_services/dynamic_function_interface/tst/dyn_function_tests.cpp b/remote_services/dynamic_function_interface/tst/dyn_function_tests.cpp
index 714b4b5..c7b5679 100644
--- a/remote_services/dynamic_function_interface/tst/dyn_function_tests.cpp
+++ b/remote_services/dynamic_function_interface/tst/dyn_function_tests.cpp
@@ -98,8 +98,8 @@ extern "C" {
 
 TEST_GROUP(DynFunctionTests) {
     void setup() {
-        dynFunction_logSetup(stdLog, NULL, 4);
-        //TODO dynType_logSetup(stdLog, NULL, 4);
+        dynFunction_logSetup(stdLog, NULL, 3);
+        dynType_logSetup(stdLog, NULL, 3);
     }
 };
 

http://git-wip-us.apache.org/repos/asf/celix/blob/dcbdd97d/remote_services/dynamic_function_interface/tst/dyn_type_tests.cpp
----------------------------------------------------------------------
diff --git a/remote_services/dynamic_function_interface/tst/dyn_type_tests.cpp b/remote_services/dynamic_function_interface/tst/dyn_type_tests.cpp
index 1b011c3..046c757 100644
--- a/remote_services/dynamic_function_interface/tst/dyn_type_tests.cpp
+++ b/remote_services/dynamic_function_interface/tst/dyn_type_tests.cpp
@@ -36,7 +36,7 @@ extern "C" {
 
 TEST_GROUP(DynTypeTests) {
 	void setup() {
-	    dynType_logSetup(stdLog, NULL, 4);
+	    dynType_logSetup(stdLog, NULL, 3);
 	}
 };
 

http://git-wip-us.apache.org/repos/asf/celix/blob/dcbdd97d/remote_services/dynamic_function_interface/tst/json_serializer_tests.cpp
----------------------------------------------------------------------
diff --git a/remote_services/dynamic_function_interface/tst/json_serializer_tests.cpp b/remote_services/dynamic_function_interface/tst/json_serializer_tests.cpp
index 30d3e71..ee6d4d9 100644
--- a/remote_services/dynamic_function_interface/tst/json_serializer_tests.cpp
+++ b/remote_services/dynamic_function_interface/tst/json_serializer_tests.cpp
@@ -173,6 +173,7 @@ static void tests() {
 
 TEST_GROUP(JsonSerializerTests) {
     void setup() {
+        dynType_logSetup(stdLog, NULL, 3);
     }
 };
 


Mime
View raw message