Browse Source

server object, some error in namespace

Leon Urbas 11 years ago
parent
commit
462bb405db

+ 5 - 0
Makefile.am

@@ -5,6 +5,11 @@ else
 AM_CFLAGS += -O2 
 endif
 
+if COVERAGE
+AM_CFLAGS += --coverage
+AM_LDFLAGS = --coverage
+endif
+
 export GLOBAL_AM_CFLAGS = $(AM_CFLAGS)
 
 SUBS=tool include src

+ 29 - 17
configure.ac

@@ -31,12 +31,12 @@ AM_COND_IF([TARGET_LINUX],
 AC_ARG_ENABLE(debug,
 AS_HELP_STRING([--enable-debug],
                [enable debugging, default: no]),
-			   [case "${enableval}" in
-               		 yes) debug=true, verbose=false ;;
-             		 no)  debug=false, verbose=false ;;
-             		 verbose) debug=true, verbose=true;;
-             		 *)   AC_MSG_ERROR([bad value ${enableval} for --enable-debug]) ;; esac],
-				[debug=false])
+	[case "${enableval}" in
+        	yes) debug=true, verbose=false ;;
+             	no)  debug=false, verbose=false ;;
+             	verbose) debug=true, verbose=true ;;
+             	*)   AC_MSG_ERROR([bad value ${enableval} for --enable-debug]) ;; 
+	esac],[debug=false])
 AM_CONDITIONAL(DEBUG, test x"$debug" = x"true")
 AM_COND_IF([DEBUG],
     AC_DEFINE([DEBUG])) #define DEBUG is accessible from pre-processor
@@ -48,23 +48,35 @@ AM_COND_IF([VERBOSE],
 AC_ARG_ENABLE(multithreading,
 AS_HELP_STRING([--enable-multithreading],
                [enable multithreading, default: yes]),
-			   [case "${enableval}" in
-               		 yes) multithreading=true ;;
-             		 no)  multithreading=false ;;
-             		 *)   AC_MSG_ERROR([bad value ${enableval} for --enable-multithreading]) ;; esac],
-[multithreading=false])
+	[case "${enableval}" in
+		yes) multithreading=true ;;
+		no)  multithreading=false ;;
+		*)   AC_MSG_ERROR([bad value ${enableval} for --enable-multithreading]) ;; 
+	esac],[multithreading=false])
 AM_CONDITIONAL(MULTITHREADING, test x"$multithreading" = x"true")
 AM_COND_IF([MULTITHREADING],
     AC_DEFINE([MULTITHREADING])) #define MULTITHREADING is accessible from pre-processor
 
+AC_ARG_ENABLE(coverage,
+AS_HELP_STRING([--enable-coverage],
+               [enable coverage, default: no]),
+	[case "${enableval}" in
+		yes) coverage=true ;;
+		no)  coverag=false ;;
+		*)   AC_MSG_ERROR([bad value ${enableval} for --enable-coverage]) ;; 
+	esac],[coverage=false])
+AM_CONDITIONAL(COVERAGE, test x"$coverage" = x"true")
+AM_COND_IF([COVERAGE],
+    AC_DEFINE([COVERAGE])) #define MULTITHREADING is accessible from pre-processor
+
 AC_ARG_ENABLE(doxygen,
-	AS_HELP_STRING([--enable-doxygen],
+AS_HELP_STRING([--enable-doxygen],
                [enable doxygen, default: no]),
-			   [case "${enableval}" in
-               		 yes) enabledoxygen=true ;;
-             		 no)  enabledoxygen=false ;;
-             		 *)   AC_MSG_ERROR([bad value ${enableval} for --enable-doxygen]) ;; esac],
-[enabledoxygen=false])
+	[case "${enableval}" in
+		yes) enabledoxygen=true ;;
+		no)  enabledoxygen=false ;;
+             	*)   AC_MSG_ERROR([bad value ${enableval} for --enable-doxygen]) ;; 
+	esac],[enabledoxygen=false])
 
 AM_CONDITIONAL(ENABLE_DOXYGEN, test x"$enabledoxygen" = x"true")
 AC_CHECK_PROGS([DOXYGEN], [doxygen])

+ 8 - 0
examples/src/Makefile.am

@@ -3,19 +3,27 @@ MT_LDADD = -lpthread
 else
 MT_LDADD =
 endif
+if COVERAGE
+COV_LDFLAGS = --coverage
+else
+COV_LDFLAGS = 
+endif
 
 bin_PROGRAMS= $(top_builddir)/bin/exampleServer $(top_builddir)/bin/exampleServerMT $(top_builddir)/bin/exampleServerACPLT
 #__top_builddir__bin_exampleServer_LDFLAGS = -all-static
 __top_builddir__bin_exampleServer_CFLAGS = -I$(top_builddir)/src -I$(top_builddir)/include
 __top_builddir__bin_exampleServer_SOURCES = opcuaServer.c networklayer.c
 __top_builddir__bin_exampleServer_LDADD= $(top_builddir)/lib/libopen62541.a $(MT_LDADD)
+__top_builddir__bin_exampleServer_LDFLAGS= $(COV_LDFLAGS)
 
 __top_builddir__bin_exampleServerMT_CFLAGS = -I$(top_builddir)/src -I$(top_builddir)/include
 __top_builddir__bin_exampleServerMT_SOURCES = opcuaServerMT.c networklayer.c
 __top_builddir__bin_exampleServerMT_LDADD= $(top_builddir)/lib/libopen62541.a $(MT_LDADD)
+__top_builddir__bin_exampleServerMT_LDFLAGS= $(COV_LDFLAGS)
 
 __top_builddir__bin_exampleServerACPLT_CFLAGS = -I$(top_builddir)/src -I$(top_builddir)/include
 __top_builddir__bin_exampleServerACPLT_SOURCES = opcuaServerACPLT.c 
 __top_builddir__bin_exampleServerACPLT_LDADD= $(top_builddir)/lib/libopen62541.a $(MT_LDADD)
+__top_builddir__bin_exampleServerACPLT_LDFLAGS= $(COV_LDFLAGS)
 
 AM_CFLAGS = $(GLOBAL_AM_CFLAGS)

+ 3 - 1
examples/src/opcuaServer.c

@@ -4,7 +4,7 @@
  Author      :
  Version     :
  Copyright   : Your copyright notice
- Description :
+ Description : lala
  ============================================================================
  */
 
@@ -27,6 +27,8 @@ int pthread_create(pthread_t* newthread, const pthread_attr_t* attr, void *(*sta
 
 int main(int argc, char** argv) {
 	NL_data* nl = NL_init(&NL_Description_TcpBinary,16664,NL_THREADINGTYPE_SINGLE);
+	appMockup_init();
+
 	struct timeval tv = {2, 0}; // 2 seconds
 	NL_msgLoop(nl, &tv,serverCallback,argv[0]);
 }

+ 2 - 1
src/Makefile.am

@@ -64,7 +64,8 @@ libopen62541_la_SOURCES = opcua.c\
 						util/ua_indexedList.c\
 						ua_namespace.c\
 						ua_services_attribute.c\
-						ua_services_session.c
+						ua_services_session.c\
+						ua_application.c
 
 #bin_PROGRAMS= $(top_builddir)/bin/open62541.out
 #__top_builddir__bin_libOpen62541_out_SOURCES = opcuaServer.c

+ 1 - 0
src/ua_application.h

@@ -11,4 +11,5 @@ typedef struct UA_Application_T {
 	UA_indexedList_List *namespaces; // each entry is a namespace
 } UA_Application;
 
+extern UA_Application appMockup;
 #endif

+ 3 - 0
src/ua_services_attribute.c

@@ -33,6 +33,7 @@ static UA_DataValue * service_read_node(UA_Application *app, UA_ReadValueId *id)
 	namespace *ns = UA_indexedList_findValue(app->namespaces, nodeid->namespace);
 
 	if (ns == UA_NULL) {
+		DBG_VERBOSE(printf("service_read_node - unknown namespace %d\n",nodeid->namespace));
 		v->encodingMask = UA_DATAVALUE_ENCODINGMASK_STATUSCODE;
 		v->status = UA_STATUSCODE_BADNODEIDUNKNOWN;
 		return v;
@@ -161,6 +162,8 @@ UA_Int32 service_read(UA_Application *app, UA_ReadRequest *request, UA_ReadRespo
 	response->resultsSize = readsize;
 	UA_alloc((void **)&response->results, sizeof(void *)*readsize);
 	for(int i=0;i<readsize;i++) {
+		DBG_VERBOSE(printf("service_read - attributeId=%d\n",request->nodesToRead[i]->attributeId));
+		DBG_VERBOSE(UA_NodeId_printf("service_read - nodeId=",&(request->nodesToRead[i]->nodeId)));
 		response->results[i] = service_read_node(app, request->nodesToRead[i]);
 	}
 	response->diagnosticInfosSize = -1;

+ 8 - 2
src/ua_services_session.c

@@ -1,4 +1,10 @@
 #include "ua_services.h"
+#include "ua_application.h"
+
+UA_Session sessionMockup = {
+		(UA_Int32) 0,
+		&appMockup
+};
 
 UA_Int32 service_createsession(UA_SL_Channel *channel, UA_CreateSessionRequest *request, UA_CreateSessionResponse *response) {
 	UA_String_printf("CreateSession Service - endpointUrl=", &(request->endpointUrl));
@@ -16,8 +22,8 @@ UA_Int32 service_activatesession(UA_SL_Channel *channel, UA_ActivateSessionReque
 	UA_NodeId_printf("ActivateSession - uIdToken.type=", &(request->userIdentityToken.typeId));
 	UA_ByteString_printx_hex("ActivateSession - uIdToken.body=", &(request->userIdentityToken.body));
 
-	// FIXME: channel->application = <Application Ptr>
-	
+	// FIXME: channel->session->application = <Application Ptr>
+	channel->session = &sessionMockup;
 	return UA_SUCCESS;
 }
 

+ 17 - 4
tests/Makefile.am

@@ -9,18 +9,31 @@ check_PROGRAMS += $(UNIT_TESTS)
 
 TESTS_ENVIRONMENT_MEM="libtool --mode=execute valgrind --leak-check=full --quiet --suppressions=suppressions --gen-suppressions=no --error-exitcode=666"
 
+cov-report:
+	mkdir -p coverage
+	lcov --compat-libtool --directory . --directory ../src --capture --output-file coverage/app.info  
+	genhtml -o coverage/ coverage/app.info 
+
 .PHONY: check-mem
 check-mem:
 	$(MAKE) $(AM_MAKEFLAGS) check TESTS="$(UNIT_TESTS)" TESTS_ENVIRONMENT=$(TESTS_ENVIRONMENT_MEM)
-
+if COVERAGE
+	$(MAKE) cov-report
+endif
+	
 clean-local:
-	rm -rf *.gcda *.gcdo *.gcno 
 	rm -rf coverage || true;
+	rm -rf *.gcda *.gcdo *.gcno 
+	lcov --directory . --zerocounters
+	
 # --- no changes beyond this line needed ---
 INCLUDE = @CHECK_CFLAGS@ -I$(top_builddir)/src -I$(top_builddir)/include
 LDADD = $(top_builddir)/lib/libopen62541.a @CHECK_LIBS@
 
-AM_LDFLAGS = $(LDADD)  --coverage
+AM_LDFLAGS = $(LDADD)
+if COVERAGE
+AM_LDFLAGS += --coverage
+endif
 
-AM_CFLAGS = $(GLOBAL_AM_CFLAGS) $(INCLUDE) --coverage
+AM_CFLAGS = $(GLOBAL_AM_CFLAGS) $(INCLUDE)
 

+ 50 - 4
tests/check_namespace.c

@@ -24,6 +24,48 @@ START_TEST(test_Namespace) {
 }
 END_TEST
 
+START_TEST(findNodeInNamespaceWithSingleEntry) {
+	// given
+	namespace *ns;
+	create_ns(&ns, 512);
+	UA_Node n1 = { (UA_NodeId) { UA_NODEIDTYPE_FOURBYTE, 0, { 2253 }}, 0 };
+	insert_node(ns,&n1);
+	UA_Node* nr = UA_NULL;
+	ns_lock* nl = UA_NULL;
+	UA_Int32 retval;
+	// when
+	UA_NodeId nid1 = { UA_NODEIDTYPE_FOURBYTE, 0, { 2253 }};
+	retval = get_node(ns,&nid1,&nr,&nl);
+	// then
+	ck_assert_int_eq(retval, UA_SUCCESS);
+	ck_assert_ptr_eq(nr,&n1);
+	// finally
+	delete_ns(ns);
+}
+END_TEST
+
+START_TEST(findNodeInNamespaceWithTwoEntries) {
+	// given
+	namespace *ns;
+	create_ns(&ns, 512);
+	UA_Node n1 = { (UA_NodeId) { UA_NODEIDTYPE_FOURBYTE, 0, { 2253 }}, 0 };
+	UA_Node n2 = { (UA_NodeId) { UA_NODEIDTYPE_FOURBYTE, 0, { 2255 }}, 0 };
+	insert_node(ns,&n1);
+	insert_node(ns,&n2);
+	UA_Node* nr = UA_NULL;
+	ns_lock* nl = UA_NULL;
+	UA_Int32 retval;
+	// when
+	UA_NodeId nid1 = { UA_NODEIDTYPE_FOURBYTE, 0, { 2255 }};
+	retval = get_node(ns,&nid1,&nr,&nl);
+	// then
+	ck_assert_int_eq(retval, UA_SUCCESS);
+	ck_assert_ptr_eq(nr,&n1);
+	// finally
+	delete_ns(ns);
+}
+END_TEST
+
 Suite * namespace_suite (void) {
 	Suite *s = suite_create ("Namespace");
 
@@ -31,17 +73,21 @@ Suite * namespace_suite (void) {
 	tcase_add_test (tc_cd, test_Namespace);
 	suite_add_tcase (s, tc_cd);
 
+	TCase* tc_find = tcase_create ("Find");
+	tcase_add_test (tc_find, findNodeInNamespaceWithSingleEntry);
+	tcase_add_test (tc_find, findNodeInNamespaceWithTwoEntries);
+	suite_add_tcase (s, tc_find);
+
 	return s;
 }
 
 int main (void) {
-	return 0;
-	int number_failed;
+	int number_failed =0;
 	Suite *s = namespace_suite ();
 	SRunner *sr = srunner_create (s);
+	srunner_set_fork_status(sr,CK_NOFORK);
 	srunner_run_all (sr, CK_NORMAL);
-	number_failed = srunner_ntests_failed (sr);
+	number_failed += srunner_ntests_failed (sr);
 	srunner_free (sr);
-	number_failed = 1;
 	return (number_failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE;
 }