celix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pnol...@apache.org
Subject [celix] branch feature/gh-142-rsa-issues updated: gh-142: Adds test for ffi and string as input argument handling.
Date Tue, 21 Jan 2020 20:49:18 GMT
This is an automated email from the ASF dual-hosted git repository.

pnoltes pushed a commit to branch feature/gh-142-rsa-issues
in repository https://gitbox.apache.org/repos/asf/celix.git


The following commit(s) were added to refs/heads/feature/gh-142-rsa-issues by this push:
     new f6a4baf  gh-142: Adds test for ffi and string as input argument handling.
f6a4baf is described below

commit f6a4baf3a5c1b483852d6bcea59c4d87c773e2e2
Author: Pepijn Noltes <pepijnnoltes@gmail.com>
AuthorDate: Tue Jan 21 21:48:45 2020 +0100

    gh-142: Adds test for ffi and string as input argument handling.
---
 .../examples/remote_example_api/CMakeLists.txt     |  4 +-
 .../org.apache.celix.RemoteExample.avdl            | 11 ++---
 .../org.apache.celix.RemoteExample.avpr            |  5 +++
 .../org.apache.celix.RemoteExample.descriptor      | 12 +++++
 .../src/remote_example_activator.c                 |  6 +--
 .../src/remote_example_impl.c                      |  9 ++--
 .../src/remote_service_admin_dfi.c                 |  2 +-
 .../test/src/rsa_client_server_tests.cpp           | 14 +++---
 .../test/src/tst_activator.c                       | 51 ++++++++++++++++++++--
 libs/dfi/src/json_serializer.c                     |  6 +--
 libs/dfi/test/dyn_avpr_function_tests.cpp          | 43 +++++++++++++++++-
 11 files changed, 134 insertions(+), 29 deletions(-)

diff --git a/bundles/remote_services/examples/remote_example_api/CMakeLists.txt b/bundles/remote_services/examples/remote_example_api/CMakeLists.txt
index 1a3a3bb..6a0db33 100644
--- a/bundles/remote_services/examples/remote_example_api/CMakeLists.txt
+++ b/bundles/remote_services/examples/remote_example_api/CMakeLists.txt
@@ -23,4 +23,6 @@ add_library(remote_example_api INTERFACE)
 target_include_directories(remote_example_api INTERFACE include)
 set_target_properties(remote_example_api PROPERTIES
     "INTERFACE_DESCRIPTOR"
-    "${CMAKE_CURRENT_LIST_DIR}/org.apache.celix.RemoteExample.avpr")
+    "${CMAKE_CURRENT_LIST_DIR}/org.apache.celix.RemoteExample.descriptor")
+
+#TODO use avpr instead of descriptor
diff --git a/bundles/remote_services/examples/remote_example_api/org.apache.celix.RemoteExample.avdl
b/bundles/remote_services/examples/remote_example_api/org.apache.celix.RemoteExample.avdl
index 417c8b2..abdcf82 100644
--- a/bundles/remote_services/examples/remote_example_api/org.apache.celix.RemoteExample.avdl
+++ b/bundles/remote_services/examples/remote_example_api/org.apache.celix.RemoteExample.avdl
@@ -1,13 +1,14 @@
 @namespace("org.apache.celix")
+@version("1.0.0")
 protocol RemoteExample {
 
   //simple input
-  double pow(double a, double b);
-  int fib(int n);
+  @index(0) double pow(double a, double b);
+  @index(1) int fib(int n);
 
   //string input
-  string setName1(string n); //callee takes ownership of string n
-  string setName2(string @const(true) n); //caller keeps ownership of string n
+  @index(2) string setName1(string n); //callee takes ownership of string n
+  @index(3) string setName2(string @const(true) n); //caller keeps ownership of string n
 
   record Complex {
       double a;
@@ -15,5 +16,5 @@ protocol RemoteExample {
       array<string> names;
   }
 
-  //Complex updateComplex(Complex c);
+  //@index(4) Complex updateComplex(Complex c);
 }
\ No newline at end of file
diff --git a/bundles/remote_services/examples/remote_example_api/org.apache.celix.RemoteExample.avpr
b/bundles/remote_services/examples/remote_example_api/org.apache.celix.RemoteExample.avpr
index 54c32ac..2d5887b 100644
--- a/bundles/remote_services/examples/remote_example_api/org.apache.celix.RemoteExample.avpr
+++ b/bundles/remote_services/examples/remote_example_api/org.apache.celix.RemoteExample.avpr
@@ -1,6 +1,7 @@
 {
   "protocol" : "RemoteExample",
   "namespace" : "org.apache.celix",
+  "version" : "1.0.0",
   "types" : [ {
     "type" : "record",
     "name" : "Complex",
@@ -20,6 +21,7 @@
   } ],
   "messages" : {
     "pow" : {
+      "index" : 0,
       "request" : [ {
         "name" : "a",
         "type" : "double"
@@ -30,6 +32,7 @@
       "response" : "double"
     },
     "fib" : {
+      "index" : 1,
       "request" : [ {
         "name" : "n",
         "type" : "int"
@@ -37,6 +40,7 @@
       "response" : "int"
     },
     "setName1" : {
+      "index" : 2,
       "request" : [ {
         "name" : "n",
         "type" : "string"
@@ -44,6 +48,7 @@
       "response" : "string"
     },
     "setName2" : {
+      "index" : 3,
       "request" : [ {
         "name" : "n",
         "type" : "string",
diff --git a/bundles/remote_services/examples/remote_example_api/org.apache.celix.RemoteExample.descriptor
b/bundles/remote_services/examples/remote_example_api/org.apache.celix.RemoteExample.descriptor
new file mode 100644
index 0000000..b6d7981
--- /dev/null
+++ b/bundles/remote_services/examples/remote_example_api/org.apache.celix.RemoteExample.descriptor
@@ -0,0 +1,12 @@
+:header
+type=interface
+name=org.apache.celix.RemoteExample
+version=1.3.0
+:annotations
+classname=org.apache.celix.RemoteExample
+:types
+:methods
+pow(DD)D=pow(#am=handle;PDD#am=pre;*D)N
+fib(I)I=fib(#am=handle;PI#am=pre;*I)N
+setName1=setName1(#am=handle;Pt#am=out;*t)N
+setName2=setName2(#am=handle;Pt#am=out;*t)N
diff --git a/bundles/remote_services/examples/remote_example_service/src/remote_example_activator.c
b/bundles/remote_services/examples/remote_example_service/src/remote_example_activator.c
index 98092e2..6f2bec3 100644
--- a/bundles/remote_services/examples/remote_example_service/src/remote_example_activator.c
+++ b/bundles/remote_services/examples/remote_example_service/src/remote_example_activator.c
@@ -36,10 +36,10 @@ celix_status_t remoteExampleBndStart(struct activator *act, celix_bundle_context
     act->impl = remoteExample_create();
     if (act->impl != NULL) {
         act->service.handle = act->impl;
-        act->service.pow = (void*)remoteExample_fib;
+        act->service.pow = (void*)remoteExample_pow;
         act->service.fib = (void*)remoteExample_fib;
-        act->service.setName1 = (void*)remoteExample_fib;
-        act->service.setName2 = (void*)remoteExample_fib;
+        act->service.setName1 = (void*)remoteExample_setName1;
+        act->service.setName2 = (void*)remoteExample_setName2;
         //TODO update complex
 
         celix_properties_t *properties = celix_properties_create();
diff --git a/bundles/remote_services/examples/remote_example_service/src/remote_example_impl.c
b/bundles/remote_services/examples/remote_example_service/src/remote_example_impl.c
index b1193b2..600f9dd 100644
--- a/bundles/remote_services/examples/remote_example_service/src/remote_example_impl.c
+++ b/bundles/remote_services/examples/remote_example_service/src/remote_example_impl.c
@@ -43,15 +43,18 @@ int remoteExample_pow(remote_example_impl_t* impl, double a, double b,
double *o
 
 static int fib_int(int n)
 {
-    if (n <= 1) {
-        return n;
+    if (n <= 0) {
+        return 0;
+    } else if (n <= 2) {
+        return 1;
     } else {
         return fib_int(n-1) + fib_int(n-2);
     }
 }
 
 int remoteExample_fib(remote_example_impl_t* impl, int32_t a, int32_t *out) {
-    *out = fib_int(a);
+    int r = fib_int(a);
+    *out = r;
     return 0;
 }
 
diff --git a/bundles/remote_services/remote_service_admin_dfi/src/remote_service_admin_dfi.c
b/bundles/remote_services/remote_service_admin_dfi/src/remote_service_admin_dfi.c
index 0ba4574..2d57df7 100644
--- a/bundles/remote_services/remote_service_admin_dfi/src/remote_service_admin_dfi.c
+++ b/bundles/remote_services/remote_service_admin_dfi/src/remote_service_admin_dfi.c
@@ -748,7 +748,7 @@ static celix_status_t remoteServiceAdmin_send(void *handle, endpoint_description
         curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, remoteServiceAdmin_write);
         curl_easy_setopt(curl, CURLOPT_WRITEDATA, (void *)&get);
         curl_easy_setopt(curl, CURLOPT_POSTFIELDSIZE, (curl_off_t)post.size);
-        logHelper_log(rsa->loghelper, OSGI_LOGSERVICE_DEBUG, "RSA: Performing curl post\n");
+        //logHelper_log(rsa->loghelper, OSGI_LOGSERVICE_DEBUG, "RSA: Performing curl post\n");
         res = curl_easy_perform(curl);
 
         *reply = get.writeptr;
diff --git a/bundles/remote_services/remote_service_admin_dfi/test/src/rsa_client_server_tests.cpp
b/bundles/remote_services/remote_service_admin_dfi/test/src/rsa_client_server_tests.cpp
index bef4301..9333f2e 100644
--- a/bundles/remote_services/remote_service_admin_dfi/test/src/rsa_client_server_tests.cpp
+++ b/bundles/remote_services/remote_service_admin_dfi/test/src/rsa_client_server_tests.cpp
@@ -107,17 +107,17 @@ extern "C" {
         CHECK_EQUAL(CELIX_SUCCESS, rc);
         CHECK(tst != NULL);
 
-        rc = tst->isCalcDiscovered(tst->handle);
-        CHECK_EQUAL(CELIX_SUCCESS, rc);
+        bool discovered = tst->isCalcDiscovered(tst->handle);
+        CHECK_TRUE(discovered);
 
         rc = tst->testCalculator(tst->handle);
         CHECK_EQUAL(CELIX_SUCCESS, rc);
 
-//        rc = tst->isRemoteExampleDiscovered(tst->handle);
-//        CHECK_EQUAL(CELIX_SUCCESS, rc);
-//
-//        rc = tst->testRemoteExample(tst->handle);
-//        CHECK_EQUAL(CELIX_SUCCESS, rc);
+        discovered = tst->isRemoteExampleDiscovered(tst->handle);
+        CHECK_TRUE(discovered);
+
+        rc = tst->testRemoteExample(tst->handle);
+        CHECK_EQUAL(CELIX_SUCCESS, rc);
 
         bool result;
         bundleContext_ungetService(clientContext, ref, &result);
diff --git a/bundles/remote_services/remote_service_admin_dfi/test/src/tst_activator.c b/bundles/remote_services/remote_service_admin_dfi/test/src/tst_activator.c
index ab84e22..a92e277 100644
--- a/bundles/remote_services/remote_service_admin_dfi/test/src/tst_activator.c
+++ b/bundles/remote_services/remote_service_admin_dfi/test/src/tst_activator.c
@@ -121,10 +121,53 @@ static int bndTestCalculator(void *handle) {
 }
 
 static int bndTestRemoteExample(void *handle) {
-    return 1;//TODO
-//    int status = 0;
-//    struct activator *act = handle;
-//    return status;
+    bool ok = true;
+    struct activator *act = handle;
+
+    pthread_mutex_lock(&act->mutex);
+    if (act->remoteExample != NULL) {
+
+        if (ok) {
+            //test pow
+            double p;
+            act->remoteExample->pow(act->remoteExample->handle, 2, 2, &p);
+            ok = (p == 4.0);
+        }
+
+        if (ok) {
+            //test fib
+            int32_t f;
+            act->remoteExample->fib(act->remoteExample->handle, 4, &f);
+            ok = (f == 3);
+        }
+
+        //TODO enable and fix segfault
+//        if (ok) {
+//            //test string call with taking ownership
+//            char *tmp = strndup("test1", 1024);
+//            char *result = NULL;
+//            act->remoteExample->setName1(act->remoteExample->handle, tmp, &result);
+//            free(tmp);
+//            ok = strncmp(tmp, result, 1024) == 0;
+//            free(result);
+//        }
+//
+//        if (ok) {
+//            //test string call with keeping ownership
+//            const char *tmp = "test2";
+//            char *result = NULL;
+//            act->remoteExample->setName2(act->remoteExample->handle, tmp, &result);
+//            ok = strncmp(tmp, result, 1024) == 0;
+//            free(result);
+//        }
+
+    } else {
+        fprintf(stderr, "remote example service not available");
+        ok  = false;
+    }
+    pthread_mutex_unlock(&act->mutex);
+
+    return ok ? 0 : 1;
 }
 
 static celix_status_t bndStart(struct activator *act, celix_bundle_context_t* ctx) {
diff --git a/libs/dfi/src/json_serializer.c b/libs/dfi/src/json_serializer.c
index b09635f..db3dd3a 100644
--- a/libs/dfi/src/json_serializer.c
+++ b/libs/dfi/src/json_serializer.c
@@ -77,7 +77,8 @@ static int jsonSerializer_createType(dyn_type *type, json_t *val, void **result)
 
     if (dynType_descriptorType(type) == 't') {
         if (json_typeof(val) == JSON_STRING) {
-            inst = strdup(json_string_value(val));
+            const char *s = json_string_value(val);
+            inst = strdup(s);
         } else {
             status = ERROR;
             LOG_ERROR("Expected json_string type got %i\n", json_typeof(val));
@@ -93,8 +94,7 @@ static int jsonSerializer_createType(dyn_type *type, json_t *val, void **result)
 
     if (status == OK) {
         *result = inst;
-    }
-    else{
+    } else {
     	dynType_free(type, inst);
     }
 
diff --git a/libs/dfi/test/dyn_avpr_function_tests.cpp b/libs/dfi/test/dyn_avpr_function_tests.cpp
index 6d8cb94..a745678 100644
--- a/libs/dfi/test/dyn_avpr_function_tests.cpp
+++ b/libs/dfi/test/dyn_avpr_function_tests.cpp
@@ -207,9 +207,16 @@ const char* theAvprFile = "{ \
                     \"structStringOutFunc\" : {\
                         \"request\" : [ ],\
                         \"response\" : \"StructString\" \
-                    } \
+                    }, \
+                    \"stringInFunc\" : {\
+                        \"request\" : [{\
+                            \"name\" : \"arg1\",\
+                            \"type\" : \"string\" \
+                        } ],\
+                        \"response\" : \"Void\"\
+                    }\
                 }\
-                }";
+            }";
 
 TEST_GROUP(DynAvprFunctionTests) {
     void setup() override {
@@ -618,3 +625,35 @@ TEST(DynAvprFunctionTests, Example10) {
     free(out.name);
     dynFunction_destroy(dynFunc);
 }
+
+
+static int avpr_example11(void *handle __attribute__((unused)), char *arg1) {
+    STRCMP_EQUAL("input string test", arg1);
+    return 0;
+}
+
+TEST(DynAvprFunctionTests, Example11) {
+    auto fp = (void(*)()) avpr_example11;
+    dyn_function_type * dynFunc = dynFunction_parseAvprWithStr(theAvprFile, "test.dt.stringInFunc");
+    CHECK(dynFunc != nullptr);
+
+    int handle = 0;
+    int* handle_ptr = &handle;
+
+    const char *input = "input string test";
+
+    void *args[2];
+    args[0] = &handle_ptr;
+    args[1]= &input;
+    int rVal = 1;
+
+    int rc = dynFunction_call(dynFunc, fp, &rVal, args);
+    CHECK_EQUAL(0, rc);
+    CHECK_EQUAL(0, rVal);
+
+    //NOTE removing this will lead to segfault!!!. Why optimization with pointers to different
segment?
+    char *input2 = strdup(input);
+    free(input2);
+
+    dynFunction_destroy(dynFunc);
+}


Mime
View raw message