celix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From griccia...@apache.org
Subject celix git commit: Fixed pubsub test CMake file. Fixed some Coverity issues
Date Fri, 16 Feb 2018 16:01:36 GMT
Repository: celix
Updated Branches:
  refs/heads/develop c31401633 -> a55fd1523


Fixed pubsub test CMake file. Fixed some Coverity issues


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

Branch: refs/heads/develop
Commit: a55fd1523832f5ef406acfcb13ee27a014f29350
Parents: c314016
Author: gricciardi <gricciardi@apache.org>
Authored: Fri Feb 16 17:01:21 2018 +0100
Committer: gricciardi <gricciardi@apache.org>
Committed: Fri Feb 16 17:01:21 2018 +0100

----------------------------------------------------------------------
 etcdlib/test/etcdlib_test.c                | 126 +++++++++++++-----------
 pubsub/pubsub_discovery/src/etcd_watcher.c |   2 +-
 pubsub/pubsub_spi/src/pubsub_endpoint.c    |   7 +-
 pubsub/pubsub_spi/src/pubsub_utils.c       |  12 ++-
 pubsub/test/CMakeLists.txt                 |  32 +++---
 5 files changed, 101 insertions(+), 78 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/celix/blob/a55fd152/etcdlib/test/etcdlib_test.c
----------------------------------------------------------------------
diff --git a/etcdlib/test/etcdlib_test.c b/etcdlib/test/etcdlib_test.c
index afd0e74..d4b34b9 100644
--- a/etcdlib/test/etcdlib_test.c
+++ b/etcdlib/test/etcdlib_test.c
@@ -32,73 +32,85 @@
 #include <pthread.h>
 
 int simplewritetest() {
-    int res = 0;
-    char*value = NULL;
-    etcd_set("simplekey", "testvalue", 5, false);
-    etcd_get("simplekey", &value, NULL);
-    if (value && strcmp(value, "testvalue")) {
-        printf("etcdlib test error: expected testvalue got %s\n", value);
-        res = -1;
-    }
-    free(value);
-    return res;
+	int res = 0;
+	char*value = NULL;
+	etcd_set("simplekey", "testvalue", 5, false);
+	etcd_get("simplekey", &value, NULL);
+	if (value && strcmp(value, "testvalue")) {
+		printf("etcdlib test error: expected testvalue got %s\n", value);
+		res = -1;
+	}
+	free(value);
+	return res;
 }
 
 void* waitForChange(void*arg) {
-    int *idx = (int*)arg;
-    char *action = NULL;
-    char *prevValue;
-    char *value;
-    char *rkey;
-    long long modifiedIndex;
-    printf("Watching for index %d\n", *idx);
-    etcd_watch("hier/ar", *idx, &action, &prevValue, &value, &rkey, &modifiedIndex);
-    printf(" New value from watch : [%s]%s => %s\n", rkey, prevValue, value);
-    free (action);
-    free(prevValue);
-    free(rkey);
-    free(value);
-    *idx = modifiedIndex+1;
-    etcd_watch("hier/ar", *idx, &action, &prevValue, &value, &rkey, &modifiedIndex);
-    printf(" New value from watch : [%s]%s => %s\n", rkey, prevValue, value);
-    free (action);
-    free(prevValue);
-    free(rkey);
-    return value;
+	int *idx = (int*)arg;
+	char *action = NULL;
+	char *prevValue = NULL;
+	char *value = NULL;
+	char *rkey = NULL;
+	long long modifiedIndex;
+
+	printf("Watching for index %d\n", *idx);
+
+	if(etcd_watch("hier/ar", *idx, &action, &prevValue, &value, &rkey, &modifiedIndex)
== 0){
+		printf(" New value from watch : [%s]%s => %s\n", rkey, prevValue, value);
+		if(action != NULL) free(action);
+		if(prevValue != NULL) free(prevValue);
+		if(rkey != NULL) free(rkey);
+		if(value != NULL) free(value);
+	}
+
+	*idx = modifiedIndex+1;
+
+	action = NULL;
+	prevValue = NULL;
+	value = NULL;
+	rkey = NULL;
+
+	if(etcd_watch("hier/ar", *idx, &action, &prevValue, &value, &rkey, &modifiedIndex)
== 0){
+		printf(" New value from watch : [%s]%s => %s\n", rkey, prevValue, value);
+		if(action != NULL) free(action);
+		if(prevValue != NULL) free(prevValue);
+		if(rkey != NULL) free(rkey);
+	}
+
+	return value;
 }
 
 int waitforchangetest() {
-    int res = 0;
-    char*value = NULL;
-
-    etcd_set("hier/ar/chi/cal", "testvalue1", 5, false);
-
-    int index;
-    etcd_get("hier/ar/chi/cal", &value, &index);
-    free(value);
-    pthread_t waitThread;
-    index++;
-    pthread_create(&waitThread, NULL, waitForChange, &index);
-    sleep(1);
-    etcd_set("hier/ar/chi/cal", "testvalue2", 5, false);
-    sleep(1);
-    etcd_set("hier/ar/chi/cal", "testvalue3", 5, false);
-    void *resVal;
-    pthread_join(waitThread, &resVal);
-    if(strcmp((char*)resVal,"testvalue3" )) {
-        printf("etcdtest::waitforchange1 expected testvalue3, got %s\n", (char*)resVal);
-        res = -1;
-    }
-    free(resVal);
-    return res;
+	int res = 0;
+	char*value = NULL;
+
+	etcd_set("hier/ar/chi/cal", "testvalue1", 5, false);
+
+	int index;
+	etcd_get("hier/ar/chi/cal", &value, &index);
+	free(value);
+	pthread_t waitThread;
+	index++;
+	pthread_create(&waitThread, NULL, waitForChange, &index);
+	sleep(1);
+	etcd_set("hier/ar/chi/cal", "testvalue2", 5, false);
+	sleep(1);
+	etcd_set("hier/ar/chi/cal", "testvalue3", 5, false);
+	void *resVal;
+	pthread_join(waitThread, &resVal);
+	if(strcmp((char*)resVal,"testvalue3" )) {
+		printf("etcdtest::waitforchange1 expected testvalue3, got %s\n", (char*)resVal);
+		res = -1;
+	}
+	free(resVal);
+	return res;
 }
 
 int main (void) {
-    etcd_init("localhost", 2379, 0);
+	etcd_init("localhost", 2379, 0);
 
-    int res = simplewritetest(); if(res) return res; else printf("simplewrite test success\n");
-    res = waitforchangetest(); if(res) return res;else printf("waitforchange1 test success\n");
+	int res = simplewritetest(); if(res) return res; else printf("simplewrite test success\n");
+	res = waitforchangetest(); if(res) return res;else printf("waitforchange1 test success\n");
 
-    return 0;
+	return 0;
 }
 

http://git-wip-us.apache.org/repos/asf/celix/blob/a55fd152/pubsub/pubsub_discovery/src/etcd_watcher.c
----------------------------------------------------------------------
diff --git a/pubsub/pubsub_discovery/src/etcd_watcher.c b/pubsub/pubsub_discovery/src/etcd_watcher.c
index 726269a..3dd5ad3 100644
--- a/pubsub/pubsub_discovery/src/etcd_watcher.c
+++ b/pubsub/pubsub_discovery/src/etcd_watcher.c
@@ -104,7 +104,7 @@ static void add_node(const char *key, const char *value, void* arg) {
 	pubsub_discovery_pt ps_discovery = (pubsub_discovery_pt) arg;
 	pubsub_endpoint_pt pubEP = NULL;
 	celix_status_t status = etcdWatcher_getPublisherEndpointFromKey(ps_discovery, key, value,
&pubEP);
-	if(!status && pubEP) {
+	if(status == CELIX_SUCCESS) {
 		pubsub_discovery_addNode(ps_discovery, pubEP);
 	}
 }

http://git-wip-us.apache.org/repos/asf/celix/blob/a55fd152/pubsub/pubsub_spi/src/pubsub_endpoint.c
----------------------------------------------------------------------
diff --git a/pubsub/pubsub_spi/src/pubsub_endpoint.c b/pubsub/pubsub_spi/src/pubsub_endpoint.c
index d3b746e..11041f2 100644
--- a/pubsub/pubsub_spi/src/pubsub_endpoint.c
+++ b/pubsub/pubsub_spi/src/pubsub_endpoint.c
@@ -134,7 +134,12 @@ celix_status_t pubsubEndpoint_create(const char* fwUUID, const char*
scope, cons
 
 	*psEp = calloc(1, sizeof(**psEp));
 
-	pubsubEndpoint_setFields(*psEp, fwUUID, scope, topic, serviceId, endpoint, topic_props,
true);
+	if(*psEp!=NULL){
+		pubsubEndpoint_setFields(*psEp, fwUUID, scope, topic, serviceId, endpoint, topic_props,
true);
+	}
+	else{
+		status = CELIX_ENOMEM;
+	}
 
 	return status;
 

http://git-wip-us.apache.org/repos/asf/celix/blob/a55fd152/pubsub/pubsub_spi/src/pubsub_utils.c
----------------------------------------------------------------------
diff --git a/pubsub/pubsub_spi/src/pubsub_utils.c b/pubsub/pubsub_spi/src/pubsub_utils.c
index 53bacb8..d1cd5ed 100644
--- a/pubsub/pubsub_spi/src/pubsub_utils.c
+++ b/pubsub/pubsub_spi/src/pubsub_utils.c
@@ -58,11 +58,14 @@ char* pubsub_getScopeFromFilter(const char* bundle_filter){
 
 				scopes+=strlen(PUBSUB_PUBLISHER_SCOPE)+1;
 				char* bottom=strchr(scopes,')');
-				*bottom='\0';
+
+				if(bottom!=NULL){
+					*bottom='\0';
+				}
 
 				scope=strdup(scopes);
 			} else {
-			    scope=strdup(PUBSUB_PUBLISHER_SCOPE_DEFAULT);
+				scope=strdup(PUBSUB_PUBLISHER_SCOPE_DEFAULT);
 			}
 		}
 	}
@@ -88,7 +91,10 @@ char* pubsub_getTopicFromFilter(const char* bundle_filter){
 
 				topics+=strlen(PUBSUB_PUBLISHER_TOPIC)+1;
 				char* bottom=strchr(topics,')');
-				*bottom='\0';
+
+				if(bottom!=NULL){
+					*bottom='\0';
+				}
 
 				topic=strdup(topics);
 

http://git-wip-us.apache.org/repos/asf/celix/blob/a55fd152/pubsub/test/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/pubsub/test/CMakeLists.txt b/pubsub/test/CMakeLists.txt
index 13e7d82..39e5575 100644
--- a/pubsub/test/CMakeLists.txt
+++ b/pubsub/test/CMakeLists.txt
@@ -38,20 +38,20 @@ celix_bundle_files(pubsub_sut
 add_celix_container(pubsub_udpmc_sut
     NAME deploy_sut
     BUNDLES
-        org.apache.celix.pubsub_serializer.PubSubSerializerJson
-        org.apache.celix.pubsub_discovery.etcd.PubsubDiscovery
-        org.apache.celix.pubsub_admin.PubSubAdminUdpMc
-        org.apache.celix.pubsub_topology_manager.PubSubTopologyManager
+        celix_pubsub_serializer_json
+        celix_pubsub_discovery_etcd
+        celix_pubsub_admin_udp_multicast
+        celix_pubsub_topology_manager
         pubsub_sut
     DIR ${PROJECT_BINARY_DIR}/runtimes/test/pubsub/udpmc
 )
 add_celix_container(pubsub_zmq_sut
     NAME deploy_sut
     BUNDLES
-        org.apache.celix.pubsub_serializer.PubSubSerializerJson
-        org.apache.celix.pubsub_discovery.etcd.PubsubDiscovery
-        org.apache.celix.pubsub_admin.PubSubAdminZmq
-        org.apache.celix.pubsub_topology_manager.PubSubTopologyManager
+        celix_pubsub_serializer_json
+        celix_pubsub_discovery_etcd
+        celix_pubsub_admin_zmq
+        celix_pubsub_topology_manager
         pubsub_sut
     DIR ${PROJECT_BINARY_DIR}/runtimes/test/pubsub/zmq
 )
@@ -77,10 +77,10 @@ celix_bundle_files(pubsub_tst
 add_celix_container(pubsub_udpmc_tst
     NAME deploy_tst
     BUNDLES
-        org.apache.celix.pubsub_serializer.PubSubSerializerJson
-        org.apache.celix.pubsub_topology_manager.PubSubTopologyManager
-        org.apache.celix.pubsub_discovery.etcd.PubsubDiscovery
-        org.apache.celix.pubsub_admin.PubSubAdminUdpMc
+        celix_pubsub_serializer_json
+        celix_pubsub_topology_manager
+        celix_pubsub_discovery_etcd
+        celix_pubsub_admin_udp_multicast
         pubsub_tst
     #NOTE using $<TARGET_PROPERTY:pubsub_test_udpmc_runtime,RUNTIME_DIR> in DIR not
(yet) possible
     DIR ${PROJECT_BINARY_DIR}/runtimes/test/pubsub/udpmc
@@ -89,10 +89,10 @@ add_celix_container(pubsub_udpmc_tst
 add_celix_container(pubsub_zmq_tst
     NAME deploy_tst
     BUNDLES
-        org.apache.celix.pubsub_serializer.PubSubSerializerJson
-        org.apache.celix.pubsub_topology_manager.PubSubTopologyManager
-        org.apache.celix.pubsub_discovery.etcd.PubsubDiscovery
-        org.apache.celix.pubsub_admin.PubSubAdminZmq
+        celix_pubsub_serializer_json
+        celix_pubsub_topology_manager
+        celix_pubsub_discovery_etcd
+        celix_pubsub_admin_zmq
         pubsub_tst
     DIR ${PROJECT_BINARY_DIR}/runtimes/test/pubsub/zmq
     LAUNCHER celix_test_runner


Mime
View raw message