From 7ebb538ebf54c561cddab53f5e6246219481022a Mon Sep 17 00:00:00 2001 From: Olof hagsand Date: Sat, 17 Apr 2021 14:52:42 +0200 Subject: [PATCH] - Changed master to 5.2.0.PRE - Modified Makefiles for static linkage and coverage - test namespace abstractions --- CHANGELOG.md | 4 ++ Makefile.in | 1 + apps/backend/Makefile.in | 12 ++--- apps/cli/Makefile.in | 12 ++--- apps/restconf/Makefile.in | 2 +- apps/restconf/restconf_main_native.c | 2 +- configure | 12 +++-- configure.ac | 12 +++-- doc/DEVELOP.md | 7 +++ example/main/Makefile.in | 39 +++++++++++++--- lib/src/Makefile.in | 7 ++- lib/src/clixon_plugin.c | 20 +++++++- lib/src/clixon_proc.c | 62 ------------------------- test/config.sh.in | 2 +- test/lib.sh | 7 ++- test/test_restconf_internal.sh | 8 ++-- test/test_restconf_internal_usecases.sh | 6 +-- test/test_transaction_restart.sh | 6 +-- 18 files changed, 112 insertions(+), 109 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 320d2d75..c8193af4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,6 @@ # Clixon Changelog +* [5.2.0](#520) Expected: June 2021 * [5.1.0](#510) 15 April 2021 * [5.0.0](#500) 27 February 2021 * [5.0.1](#501) 10 March 2021 @@ -28,6 +29,9 @@ * [3.3.2](#332) Aug 27 2017 * [3.3.1](#331) June 7 2017 +## 5.2.0 +Expected: June 2021 + ## 5.1.0 15 April 2021 diff --git a/Makefile.in b/Makefile.in index 1250be0e..69416a14 100644 --- a/Makefile.in +++ b/Makefile.in @@ -138,6 +138,7 @@ configure: configure.ac cd $(srcdir) && autoconf clean: + rm -f *.gcov for i in $(SUBDIRS) doc example util docker; \ do (cd $$i && $(MAKE) $(MFLAGS) $@); done; diff --git a/apps/backend/Makefile.in b/apps/backend/Makefile.in index b45d59fd..be2a7d15 100644 --- a/apps/backend/Makefile.in +++ b/apps/backend/Makefile.in @@ -39,13 +39,11 @@ top_srcdir = @top_srcdir@ CC = @CC@ CFLAGS = @CFLAGS@ LINKAGE = @LINKAGE@ -ifeq ($(LINKAGE),static) - CPPFLAGS = @CPPFLAGS@ - SH_SUFFIX = a -else - CPPFLAGS = @CPPFLAGS@ -fPIC - SH_SUFFIX = @SH_SUFFIX@ +CPPFLAGS = @CPPFLAGS@ +ifeq ($(LINKAGE),dynamic) +CPPFLAGS += -fPIC endif +SH_SUFFIX = @SH_SUFFIX@ INSTALLFLAGS = @INSTALLFLAGS@ LDFLAGS = @LDFLAGS@ @@ -65,7 +63,7 @@ CLIXON_MINOR = @CLIXON_VERSION_MINOR@ # Use this clixon lib for linking ifeq ($(LINKAGE),static) - CLIXON_LIB = libclixon.a + CLIXON_LIB = libclixon$(SH_SUFFIX) else CLIXON_LIB = libclixon$(SH_SUFFIX).$(CLIXON_MAJOR).$(CLIXON_MINOR) endif diff --git a/apps/cli/Makefile.in b/apps/cli/Makefile.in index bb2439c2..242f0bf2 100644 --- a/apps/cli/Makefile.in +++ b/apps/cli/Makefile.in @@ -39,17 +39,15 @@ top_srcdir = @top_srcdir@ CC = @CC@ CFLAGS = @CFLAGS@ LINKAGE = @LINKAGE@ +CPPFLAGS = @CPPFLAGS@ ifeq ($(LINKAGE),dynamic) - CPPFLAGS = @CPPFLAGS@ -fPIC -else - CPPFLAGS = @CPPFLAGS@ + CPPFLAGS += -fPIC endif SH_SUFFIX = @SH_SUFFIX@ INSTALLFLAGS = @INSTALLFLAGS@ -ifeq ($(LINKAGE),dynamic) - LDFLAGS = @LDFLAGS@ -else - LDFLAGS = @LDFLAGS@ -rdynamic -L. +LDFLAGS = @LDFLAGS@ +ifeq ($(LINKAGE),static) +LDFLAGS += -rdynamic -L. endif prefix = @prefix@ diff --git a/apps/restconf/Makefile.in b/apps/restconf/Makefile.in index 2bb71892..2613e287 100644 --- a/apps/restconf/Makefile.in +++ b/apps/restconf/Makefile.in @@ -92,7 +92,6 @@ APPL = clixon_restconf # Common source - not accessible from plugin - independent of restconf package (fcgi|native) APPSRC = APPSRC += restconf_api.c # maybe empty -APPSRC += restconf_api_$(with_restconf).c APPSRC += restconf_err.c APPSRC += restconf_methods.c APPSRC += restconf_methods_post.c @@ -114,6 +113,7 @@ APPOBJ = $(APPSRC:.c=.o) # are not in the lib. LIBSRC = restconf_lib.c LIBSRC += restconf_handle.c +LIBSRC += restconf_api_$(with_restconf).c LIBOBJ = $(LIBSRC:.c=.o) diff --git a/apps/restconf/restconf_main_native.c b/apps/restconf/restconf_main_native.c index 9cb6af8b..a8382d78 100644 --- a/apps/restconf/restconf_main_native.c +++ b/apps/restconf/restconf_main_native.c @@ -1773,7 +1773,7 @@ main(int argc, ) < 0) goto done; clicon_debug_init(dbg, NULL); - clicon_log(LOG_NOTICE, "%s openssl: %u Started", __PROGRAM__, getpid()); + clicon_log(LOG_NOTICE, "%s native %u Started", __PROGRAM__, getpid()); if (set_signal(SIGTERM, restconf_sig_term, NULL) < 0){ clicon_err(OE_DAEMON, errno, "Setting signal"); goto done; diff --git a/configure b/configure index 91196887..5bda2a0b 100755 --- a/configure +++ b/configure @@ -2259,9 +2259,9 @@ ac_configure="$SHELL $ac_aux_dir/configure" # Please don't use this var. CLIXON_VERSION_MAJOR="5" -CLIXON_VERSION_MINOR="1" +CLIXON_VERSION_MINOR="2" CLIXON_VERSION_PATCH="0" -CLIXON_VERSION="\"${CLIXON_VERSION_MAJOR}.${CLIXON_VERSION_MINOR}.${CLIXON_VERSION_PATCH}\"" +CLIXON_VERSION="\"${CLIXON_VERSION_MAJOR}.${CLIXON_VERSION_MINOR}.${CLIXON_VERSION_PATCH}.PRE\"" # Check CLIgen if test "$prefix" = "NONE"; then @@ -4547,7 +4547,13 @@ if test "$prefix" = "NONE"; then prefix=${ac_default_prefix} fi -SH_SUFFIX=".so" +if test "$LINKAGE" = "dynamic" ; then + SH_SUFFIX=".so" +elif test "$LINKAGE" = "static" ; then + SH_SUFFIX=".a" +else + as_fn_error $? "No such linkage: ${LINKAGE}" "$LINENO" 5 +fi # This is for cligen diff --git a/configure.ac b/configure.ac index 3df5709c..43f52c2d 100644 --- a/configure.ac +++ b/configure.ac @@ -49,9 +49,9 @@ AC_INIT(lib/clixon/clixon.h.in) AC_CONFIG_AUX_DIR(config-aux) CLIXON_VERSION_MAJOR="5" -CLIXON_VERSION_MINOR="1" +CLIXON_VERSION_MINOR="2" CLIXON_VERSION_PATCH="0" -CLIXON_VERSION="\"${CLIXON_VERSION_MAJOR}.${CLIXON_VERSION_MINOR}.${CLIXON_VERSION_PATCH}\"" +CLIXON_VERSION="\"${CLIXON_VERSION_MAJOR}.${CLIXON_VERSION_MINOR}.${CLIXON_VERSION_PATCH}.PRE\"" # Check CLIgen if test "$prefix" = "NONE"; then @@ -148,7 +148,13 @@ if test "$prefix" = "NONE"; then prefix=${ac_default_prefix} fi -SH_SUFFIX=".so" +if test "$LINKAGE" = "dynamic" ; then + SH_SUFFIX=".so" +elif test "$LINKAGE" = "static" ; then + SH_SUFFIX=".a" +else + AC_MSG_ERROR([No such linkage: ${LINKAGE}]) +fi # This is for cligen AC_ARG_WITH([cligen], AS_HELP_STRING([--with-cligen=dir],[Use CLIGEN installation in this dir])) diff --git a/doc/DEVELOP.md b/doc/DEVELOP.md index cd6f0330..3d11e232 100644 --- a/doc/DEVELOP.md +++ b/doc/DEVELOP.md @@ -194,3 +194,10 @@ Use MAXPATHLEN (not PATH_MAX) in sys/param.h socat PTY,link=/tmp/clixon-tty,rawer EXEC:"/usr/local/bin/clixon_cli -f /usr/local/etc/example.xml",pty,stderr & screen /tmp/clixon-tty + +## Coverage + +``` +LDFLAGS=-coverage LINKAGE=static CFLAGS="-O2 -Wall -coverage" ./configure +bash <(curl -s https://codecov.io/bash) -t +``` diff --git a/example/main/Makefile.in b/example/main/Makefile.in index c2ad1dd3..ad8aa6a9 100644 --- a/example/main/Makefile.in +++ b/example/main/Makefile.in @@ -51,12 +51,17 @@ YANG_INSTALLDIR = @YANG_INSTALLDIR@ CLIXON_DEFAULT_CONFIG = @CLIXON_DEFAULT_CONFIG@ CC = @CC@ -CFLAGS = @CFLAGS@ -fPIC +CFLAGS = @CFLAGS@ -fPIC INSTALLFLAGS = @INSTALLFLAGS@ with_restconf = @with_restconf@ INCLUDES = -I$(includedir) @INCLUDES@ -CPPFLAGS = @CPPFLAGS@ -fPIC +LDFLAGS = @LDFLAGS@ +CPPFLAGS = @CPPFLAGS@ +ifeq ($(LINKAGE),dynamic) +CPPFLAGS += -fPIC +endif +LINKAGE = @LINKAGE@ BE_PLUGIN = $(APPNAME)_backend.so BE2_PLUGIN = $(APPNAME)_backend_nacm.so @@ -87,32 +92,52 @@ YANGSPECS = clixon-example@2020-12-01.yang BE_SRC = $(APPNAME)_backend.c BE_OBJ = $(BE_SRC:%.c=%.o) $(BE_PLUGIN): $(BE_OBJ) - $(CC) -Wall -shared -o $@ -lc $< +ifeq ($(LINKAGE),static) + $(CC) -Wall -shared $(LDFLAGS) -o $@ -lc $< -lclixon -lclixon_backend +else + $(CC) -Wall -shared $(LDFLAGS) -o $@ -lc $< -lclixon -lclixon_backend +endif # Secondary NACM backend plugin BE2_SRC = $(APPNAME)_backend_nacm.c BE2_OBJ = $(BE2_SRC:%.c=%.o) $(BE2_PLUGIN): $(BE2_OBJ) - $(CC) -Wall -shared -o $@ -lc $< +ifeq ($(LINKAGE),static) + $(CC) -Wall -shared $(LDFLAGS) -o $@ -lc $< -lclixon -lclixon_backend +else + $(CC) -Wall -shared $(LDFLAGS) -o $@ -lc $< -lclixon -lclixon_backend +endif # CLI frontend plugin CLI_SRC = $(APPNAME)_cli.c CLI_OBJ = $(CLI_SRC:%.c=%.o) $(CLI_PLUGIN): $(CLI_OBJ) - $(CC) -Wall -shared -o $@ -lc $^ +ifeq ($(LINKAGE),static) + $(CC) -Wall -shared $(LDFLAGS) -o $@ -lc $^ -lclixon -L ../../apps/cli/ -lclixon_cli +else + $(CC) -Wall -shared $(LDFLAGS) -o $@ -lc $^ -lclixon -lclixon_cli +endif # NETCONF frontend plugin NETCONF_SRC = $(APPNAME)_netconf.c NETCONF_OBJ = $(NETCONF_SRC:%.c=%.o) $(NETCONF_PLUGIN): $(NETCONF_OBJ) - $(CC) -Wall -shared -o $@ -lc $^ +ifeq ($(LINKAGE),static) + $(CC) -Wall -shared $(LDFLAGS) -o $@ -lc $^ -lclixon -L ../../apps/netconf/ -lclixon_netconf +else + $(CC) -Wall -shared $(LDFLAGS) -o $@ -lc $^ -lclixon -lclixon_netconf +endif # See configure.ac # RESTCONF frontend plugin RESTCONF_SRC = $(APPNAME)_restconf.c RESTCONF_OBJ = $(RESTCONF_SRC:%.c=%.o) $(RESTCONF_PLUGIN): $(RESTCONF_OBJ) - $(CC) -Wall -shared -o $@ -lc $^ +ifeq ($(LINKAGE),static) + $(CC) -Wall -shared $(LDFLAGS) -o $@ -lc $^ -lclixon -L ../../apps/restconf/ -lclixon_restconf +else + $(CC) -Wall -shared $(LDFLAGS) -o $@ -lc $^ -lclixon -lclixon_restconf +endif SRC = $(BE_SRC) $(BE2_SRC) $(CLI_SRC) $(NETCONF_SRC) SRC += $(RESTCONF_SRC) diff --git a/lib/src/Makefile.in b/lib/src/Makefile.in index dd7c537d..fc097594 100644 --- a/lib/src/Makefile.in +++ b/lib/src/Makefile.in @@ -53,10 +53,9 @@ CLIXON_MINOR = @CLIXON_VERSION_MINOR@ VPATH = @srcdir@ CC = @CC@ LINKAGE = @LINKAGE@ -ifeq ($(LINKAGE),static) - CFLAGS = @CFLAGS@ -else - CFLAGS = -fPIC @CFLAGS@ +CFLAGS = @CFLAGS@ +ifeq ($(LINKAGE),dynamic) +CFLAGS += -fPIC endif SH_SUFFIX = @SH_SUFFIX@ INSTALL = @INSTALL@ diff --git a/lib/src/clixon_plugin.c b/lib/src/clixon_plugin.c index 6b2edf43..41a475db 100644 --- a/lib/src/clixon_plugin.c +++ b/lib/src/clixon_plugin.c @@ -209,7 +209,7 @@ plugin_load_one(clicon_handle h, dlerror(); /* Clear any existing error */ if ((handle = dlopen(file, dlflags)) == NULL) { error = (char*)dlerror(); - clicon_err(OE_PLUGIN, errno, "dlopen: %s", error ? error : "Unknown error"); + clicon_err(OE_PLUGIN, errno, "dlopen(%s): %s", file, error ? error : "Unknown error"); goto done; } /* call plugin_init() if defined, eg CLIXON_PLUGIN_INIT or CLIXON_BACKEND_INIT */ @@ -692,6 +692,24 @@ typedef struct { /* List of rpc callback entries XXX hang on handle */ static rpc_callback_t *rpc_cb_list = NULL; +#if 0 /* Debugging */ +static int +rpc_callback_dump(clicon_handle h, + FILE *f) +{ + rpc_callback_t *rc; + + if ((rc = rpc_cb_list) != NULL) + do { + fprintf(f, "%s %s\n", __FUNCTION__, rc->rc_name); + + rc = NEXTQ(rpc_callback_t *, rc); + } while (rc != rpc_cb_list); + fprintf(f, "%s--------------\n", __FUNCTION__); + return 0; +} +#endif + /*! Register a RPC callback by appending a new RPC to the list * * @param[in] h clicon handle diff --git a/lib/src/clixon_proc.c b/lib/src/clixon_proc.c index 61a5690a..100a7605 100644 --- a/lib/src/clixon_proc.c +++ b/lib/src/clixon_proc.c @@ -398,68 +398,6 @@ clixon_process_argv_get(clicon_handle h, return 0; } -#ifdef NYI -/*! Make a copy of process-entry struct - * - * @param[in] pe0 Original process-entry - * @param[in] pnew New copy of pe0 - */ -static int -clixon_process_register_dup(process_entry_t *pe0, - process_entry_t **pnew) -{ - int retval = -1; - process_entry_t *pe1 = NULL; - int i; - - if (pe0 == NULL){ - clicon_err(OE_DB, EINVAL, "pe0 is NULL"); - goto done; - } - if (pnew == NULL){ - clicon_err(OE_DB, EINVAL, "pnew is NULL"); - goto done; - } - if ((pe1 = malloc(sizeof(process_entry_t))) == NULL) { - clicon_err(OE_DB, errno, "malloc"); - goto done; - } - memset(pe1, 0, sizeof(*pe1)); - memcpy(pe1, pe0, sizeof(process_entry_t)); /* Note lots of malloced memory that needs to be handled after this copy*/ - pe1->pe_exiting = 0; - pe1->pe_clone = 0; - if ((pe1->pe_name = strdup(pe0->pe_name)) == NULL){ - clicon_err(OE_DB, errno, "strdup name"); - goto done; - } - if (pe0->pe_description && (pe1->pe_description = strdup(pe0->pe_description)) == NULL){ - clicon_err(OE_DB, errno, "strdup name"); - goto done; - } - if (pe0->pe_netns && (pe1->pe_netns = strdup(pe0->pe_netns)) == NULL){ - clicon_err(OE_DB, errno, "strdup netns"); - goto done; - } - if ((pe1->pe_argv = calloc(pe0->pe_argc, sizeof(char *))) == NULL){ - clicon_err(OE_UNIX, errno, "calloc"); - goto done; - } - for (i=0; ipe_argc; i++){ - if (pe0->pe_argv[i] != NULL && - (pe1->pe_argv[i] = strdup(pe0->pe_argv[i])) == NULL){ - clicon_err(OE_UNIX, errno, "strdup"); - goto done; - } - } - ADDQ(pe1, _proc_entry_list); - *pnew = pe1; - retval = 0; - done: - /* dealloc pe1 on error */ - return retval; -} -#endif - /*! Register an internal process * * @param[in] h Clixon handle diff --git a/test/config.sh.in b/test/config.sh.in index c1fee465..d9753130 100755 --- a/test/config.sh.in +++ b/test/config.sh.in @@ -69,7 +69,7 @@ DATASTORE_TOP="config" # clixon yang revisions occuring in tests CLIXON_LIB_REV="2021-03-08" CLIXON_CONFIG_REV="2021-03-08" -CLIXON_RESTCONF_REV="2020-12-30" +CLIXON_RESTCONF_REV="2021-03-08" CLIXON_EXAMPLE_REV="2020-12-01" # Length of TSL RSA key diff --git a/test/lib.sh b/test/lib.sh index 4c8fc2ed..3f3752e6 100755 --- a/test/lib.sh +++ b/test/lib.sh @@ -75,6 +75,9 @@ testname= # Namespace: netconf base BASENS='urn:ietf:params:xml:ns:netconf:base:1.0' +# Namespace: Clixon config +CONFNS='xmlns="http://clicon.org/config"' + # Namespace: Clixon lib LIBNS='xmlns="http://clicon.org/lib"' @@ -315,12 +318,12 @@ function stop_backend(){ # Wait for restconf to stop sending 502 Bad Gateway function wait_backend(){ - reply=$(echo ']]>]]>' | $clixon_netconf -qef $cfg 2> /dev/null) + reply=$(echo "]]>]]>" | $clixon_netconf -qef $cfg 2> /dev/null) let i=0; while [[ $reply != "]]>]]>' | clixon_netconf -qef $cfg 2> /dev/null) + reply=$(echo "]]>]]>" | clixon_netconf -qef $cfg 2> /dev/null) # echo "reply:$reply" let i++; # echo "wait_backend $i" diff --git a/test/test_restconf_internal.sh b/test/test_restconf_internal.sh index b335561b..ba53e94a 100755 --- a/test/test_restconf_internal.sh +++ b/test/test_restconf_internal.sh @@ -28,7 +28,7 @@ else EXTRACONF="" fi cat < $cfg - + $cfg ietf-netconf:startup clixon-restconf:allow-auth-none @@ -81,7 +81,7 @@ function rpcstatus() ret=$($clixon_netconf -qf $cfg< - + restconf status @@ -89,7 +89,7 @@ $DEFAULTHELLO EOF ) # Check pid - expect="[0-9]*" + expect="[0-9]*" match=$(echo "$ret" | grep --null -Go "$expect") if [ -z "$match" ]; then pid=0 @@ -120,7 +120,7 @@ function rpcoperation() sleep $DEMSLEEP new "send rpc $operation" - expecteof "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLOrestconf$operation]]>]]>" "^]]>]]>$" + expecteof "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLOrestconf$operation]]>]]>" "^]]>]]>$" sleep $DEMSLEEP } diff --git a/test/test_restconf_internal_usecases.sh b/test/test_restconf_internal_usecases.sh index fddd0cc0..8b364f2d 100755 --- a/test/test_restconf_internal_usecases.sh +++ b/test/test_restconf_internal_usecases.sh @@ -41,7 +41,7 @@ else fi cat < $cfg - + $cfg ietf-netconf:startup clixon-restconf:allow-auth-none @@ -95,7 +95,7 @@ function rpcstatus() ret=$($clixon_netconf -qf $cfg< - + restconf status @@ -103,7 +103,7 @@ $DEFAULTHELLO EOF ) # Check pid - expect="[0-9]*" + expect="[0-9]*" match=$(echo "$ret" | grep --null -Go "$expect") if [ -z "$match" ]; then pid=0 diff --git a/test/test_transaction_restart.sh b/test/test_transaction_restart.sh index 60157a46..24dc473c 100755 --- a/test/test_transaction_restart.sh +++ b/test/test_transaction_restart.sh @@ -38,7 +38,7 @@ module trans{ EOF cat < $cfg - + $cfg /usr/local/share/clixon $fyang @@ -115,7 +115,7 @@ xml="0example_backend_nacm]]>]]>" "^]]>]]>" +expecteof "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLOexample_backend_nacm]]>]]>" "^]]>]]>" # Now analyze log: # all transactions come from nacm plugin only. @@ -129,7 +129,7 @@ done # Negative test: restart a plugin that does not exist new "Send restart to nonexistatn plugin expect fail" -expecteof "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLOxxx]]>]]>" "^applicationbad-elementpluginerrorNo such plugin]]>]]>$" +expecteof "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLOxxx]]>]]>" "^applicationbad-elementpluginerrorNo such plugin]]>]]>$" if [ $BE -ne 0 ]; then new "Kill backend"