Beef up unit tests for SI95 code 25/5925/2 4.7.4
authorE. Scott Daniels <daniels@att.com>
Thu, 22 Apr 2021 20:34:08 +0000 (16:34 -0400)
committerE. Scott Daniels <daniels@att.com>
Fri, 23 Apr 2021 01:05:36 +0000 (21:05 -0400)
This changes adds some unit tests for SI95 modules which had none
prior, and extends some of the existing tests to improve coverage.

Issue-ID: RIC-777

Change-Id: I5d704776fd9094e8b17e35263cc4680bf822b38c
Signed-off-by: E. Scott Daniels <daniels@att.com>
29 files changed:
CHANGES_CORE.txt
CMakeLists.txt
docs/rel-notes.rst
src/rmr/common/src/mbuf_api.c
src/rmr/common/src/ring_static.c
src/rmr/common/src/rt_generic_static.c
src/rmr/common/src/symtab.c
src/rmr/si/src/mt_call_si_static.c
src/rmr/si/src/si95/sipoll.c
src/rmr/si/src/si95/sircv.c
src/rmr/si/src/si95/siwait.c
test/alarm_static_test.c
test/hdr_static_test.c
test/mbuf_api_test.c
test/rmr_nng_api_static_test.c
test/rmr_si_api_static_test.c
test/rmr_si_rcv_static_test.c
test/rmr_si_test.c
test/rt_nano_static_test.c
test/rt_static_test.c
test/si95_test.c
test/sr_nano_static_test.c
test/sr_nng_static_test.c
test/sr_si_static_test.c
test/symtab_static_test.c
test/symtab_test.c
test/tools_static_test.c
test/wormhole_static_test.c
test/wrapper_static_test.c

index d7590a4..83d26a5 100644 (file)
@@ -5,6 +5,10 @@
 # API and build change  and fix summaries. Doc corrections
 # and/or changes are not mentioned here; see the commit messages.
 
+2021 April 22; version 4.7.4
+       Beef up unit testing in SI package and fix a few static analysis
+       bugs. (RIC-777)
+
 2021 April 19; version 4.7.3
        Correct flag check bug in route table functions (RIC-777).
 
index 9f12da3..2d454c3 100644 (file)
@@ -42,7 +42,7 @@ cmake_minimum_required( VERSION 3.5 )
 
 set( major_version "4" )               # should be automatically populated from git tag later, but until CI process sets a tag we use this
 set( minor_version "7" )
-set( patch_level "3" )
+set( patch_level "4" )
 
 set( install_root "${CMAKE_INSTALL_PREFIX}" )
 set( install_inc "include/rmr" )
index b7c67b0..5bcd75f 100644 (file)
@@ -22,6 +22,14 @@ the need to leap frog versions ceased, and beginning with
 version 4.0.0, the RMR versions should no longer skip.
 
 
+2021 April 22; version 4.7.4
+----------------------------
+
+Beef up unit testing in SI package and fix a few static
+analysis bugs. (RIC-777)
+
+
+
 2021 April 19; version 4.7.3
 ----------------------------
 
index 58225c4..6abcf8b 100644 (file)
@@ -109,7 +109,7 @@ extern int rmr_str2meid( rmr_mbuf_t* mbuf, unsigned char const* str ) {
        }
 
        errno = 0;
-       if( (len = strlen( (char *) str )) > RMR_MAX_MEID-1 ) {
+       if( (len = strlen( (char const *) str )) > (size_t) (RMR_MAX_MEID-1) ) {                // cast keep sonar from twisting its knickers
                errno = EOVERFLOW;
                return RMR_ERR_OVERFLOW;
        }
@@ -148,7 +148,7 @@ extern void rmr_bytes2payload( rmr_mbuf_t* mbuf, unsigned char const* src, int l
        is set to the string length.
 */
 extern void rmr_str2payload( rmr_mbuf_t* mbuf, unsigned char const* str ) {
-       rmr_bytes2payload( mbuf, str, strlen( (char *) str ) + 1 );
+       rmr_bytes2payload( mbuf, str, strlen( (char const *) str ) + 1 );
 }
 
 
@@ -200,7 +200,7 @@ extern int rmr_str2xact( rmr_mbuf_t* mbuf, unsigned char const* str ) {
        }
 
        errno = 0;
-       if( (len = strlen( (char *) str )) > RMR_MAX_XID-1 ) {
+       if( (len = strlen( (char const *) str )) > RMR_MAX_XID-1 ) {
                errno = EOVERFLOW;
                return RMR_ERR_OVERFLOW;
        }
index 7170a9d..99fdea8 100644 (file)
@@ -71,7 +71,10 @@ static void* uta_mk_ring( int size ) {
        ring_t* r;
        uint16_t max;
 
-       if( size <= 0 || (r = (ring_t *) malloc( sizeof( *r ) )) == NULL ) {
+       if( size <= 0 ) {
+               return NULL;
+       }
+       if( (r = (ring_t *) malloc( sizeof( *r ) )) == NULL ) {
                return NULL;
        }
 
@@ -114,15 +117,13 @@ static int uta_ring_config( void* vr, int options ) {
                return 0;
        }
 
-       if( options & RING_WLOCK ) {
-               if( r->wgate == NULL ) {                // don't realloc
-                       r->wgate = (pthread_mutex_t *) malloc( sizeof( *r->wgate ) );
-                       if( r->wgate == NULL ) {
-                               return 0;
-                       }
-       
-                       pthread_mutex_init( r->wgate, NULL );
+       if( options & RING_WLOCK  &&  r->wgate == NULL ) {              // don't realloc if we have one
+               r->wgate = (pthread_mutex_t *) malloc( sizeof( *r->wgate ) );
+               if( r->wgate == NULL ) {
+                       return 0;
                }
+
+               pthread_mutex_init( r->wgate, NULL );
        }
 
        if( options & (RING_RLOCK | RING_FRLOCK) ) {                            // read locking
index a25a449..c2fd5f8 100644 (file)
@@ -1,4 +1,4 @@
-// :vi sw=4 ts=4 noet:
+ // :vi sw=4 ts=4 noet2
 /*
 ==================================================================================
        Copyright (c) 2019-2020 Nokia
@@ -361,7 +361,8 @@ static void alarm_if_drops( uta_ctx_t* uctx, uta_ctx_t* pctx ) {
                        if( time( NULL ) > ok2clear ) {                 // things still stable after expiry
                                rmr_vlog( RMR_VL_INFO, "drop alarm cleared\n" );
                                alarm_raised = 0;
-                               uta_alarm( pctx, ALARM_DROPS | ALARM_CLEAR, prob_id++, "RMR message dropping has stopped" );
+                               uta_alarm( pctx, ALARM_DROPS | ALARM_CLEAR, prob_id, "RMR message dropping has stopped" );
+                               prob_id++;
                        }
                }
        }
@@ -574,7 +575,6 @@ static void build_entry( uta_ctx_t* ctx, char* ts_field, uint32_t subid, char* r
        uint64_t key = 0;                       // the symtab key will be mtype or sub_id+mtype
        char*   tokens[128];
        char*   gtokens[64];
-       int             i;
        int             ngtoks;                         // number of tokens in the group list
        int             grp;                            // index into group list
        int             cgidx;                          // contiguous group index (prevents the addition of a contiguous group without ep)
@@ -599,6 +599,8 @@ static void build_entry( uta_ctx_t* ctx, char* ts_field, uint32_t subid, char* r
                        rte->mtype = atoi( ts_field );                                                                                                  // capture mtype for debugging
 
                        for( grp = 0, cgidx = 0; grp < ngtoks; grp++ ) {
+                               int             i;                                      // avoid sonar grumbling by defining this here
+
                                if( (ntoks = uta_rmip_tokenise( gtokens[grp], ctx->ip_list, tokens, 64, ',' )) > 0 ) {          // remove any references to our ip addrs
                                        for( i = 0; i < ntoks; i++ ) {
                                                if( strcmp( tokens[i], ctx->my_name ) != 0 ) {                                  // don't add if it is us -- cannot send to ourself
index c88c82c..9fb01bd 100644 (file)
@@ -85,8 +85,6 @@ static int sym_hash( const char *n, long size )
 {
        const char *p;
        long t = 0;
-       unsigned long tt = 0;
-       unsigned long x = 79;
 
        for( p = n; *p; p++ )      /* a bit of magic */
                t = (t * 79 ) + *p;
@@ -275,15 +273,14 @@ extern void rmr_sym_dump( void *vtable )
        table = (Sym_tab *) vtable;
        sym_tab = table->symlist;
 
-       for( i = 0; i < table->size; i++ )
-       {
-               if( sym_tab[i] )
-               for( eptr = sym_tab[i]; eptr; eptr = eptr->next )
-               {
-                       if( eptr->val && eptr->class ) {
-                               fprintf( stderr, "symtab dump: key=%s val@=%p\n", eptr->name, eptr->val );
-                       } else {
-                               fprintf( stderr, "symtab dump: nkey=%lu val@=%p\n", (unsigned long) eptr->nkey, eptr->val );
+       for( i = 0; i < table->size; i++ ) {
+               if( sym_tab[i] ) {
+                       for( eptr = sym_tab[i]; eptr; eptr = eptr->next ) {
+                               if( eptr->val && eptr->class ) {
+                                       fprintf( stderr, "symtab dump: key=%s val@=%p\n", eptr->name, eptr->val );
+                               } else {
+                                       fprintf( stderr, "symtab dump: nkey=%lu val@=%p\n", (unsigned long) eptr->nkey, eptr->val );
+                               }
                        }
                }
        }
@@ -295,7 +292,6 @@ extern void rmr_sym_dump( void *vtable )
 */
 extern void *rmr_sym_alloc( int size )
 {
-       int i;
        Sym_tab *table;
 
        if( size < 11 )     /* provide a bit of sanity */
@@ -505,9 +501,11 @@ extern void rmr_sym_foreach_class( void *vst, unsigned int class, void (* user_f
        Sym_ele *next;          /* allows user to delete the node(s) we return */
        int             i;
 
-       st = (Sym_tab *) vst;
+       if( (st = (Sym_tab *) vst) == NULL ) {
+               return;
+       }
 
-       if( st && (list = st->symlist) != NULL && user_fun != NULL ) {
+       if( (list = st->symlist) != NULL && user_fun != NULL ) {
                for( i = 0; i < st->size; i++ ) {
                        se = list[i];
                        while( se ) {
index c117a5c..73d776a 100644 (file)
@@ -1,8 +1,8 @@
-       // : vi ts=4 sw=4 noet2
+// : vi ts=4 sw=4 noet:
 /*
 ==================================================================================
-       Copyright (c) 2020 Nokia
-       Copyright (c) 2018-2020 AT&T Intellectual Property.
+       Copyright (c) 2020-2021 Nokia
+       Copyright (c) 2018-2021 AT&T Intellectual Property.
 
    Licensed under the Apache License, Version 2.0 (the "License");
    you may not use this file except in compliance with the License.
index 6c8915a..384eef2 100644 (file)
@@ -1,8 +1,8 @@
 // vim: noet sw=4 ts=4:
 /*
 ==================================================================================
-    Copyright (c) 2020 Nokia
-    Copyright (c) 2020 AT&T Intellectual Property.
+    Copyright (c) 2020-2021 Nokia
+    Copyright (c) 2020-2021 AT&T Intellectual Property.
 
    Licensed under the Apache License, Version 2.0 (the "License");
    you may not use this file except in compliance with the License.
index 5309dc5..00cb926 100644 (file)
@@ -1,8 +1,8 @@
                                // vim: noet sw=4 ts=4:
 /*
 ==================================================================================
-    Copyright (c) 2020 Nokia
-    Copyright (c) 2020 AT&T Intellectual Property.
+    Copyright (c) 2020-2021 Nokia
+    Copyright (c) 2020-2021 AT&T Intellectual Property.
 
    Licensed under the Apache License, Version 2.0 (the "License");
    you may not use this file except in compliance with the License.
index 291b8aa..3a9a8ed 100644 (file)
@@ -1,8 +1,8 @@
 // vim: noet sw=4 ts=4:
 /*
 ==================================================================================
-    Copyright (c) 2020 Nokia
-    Copyright (c) 2020 AT&T Intellectual Property.
+    Copyright (c) 2020-2021 Nokia
+    Copyright (c) 2020-2021 AT&T Intellectual Property.
 
    Licensed under the Apache License, Version 2.0 (the "License");
    you may not use this file except in compliance with the License.
@@ -45,7 +45,7 @@
 *                      31 Jul 2016 - Major formatting clean up in the main while loop.
 **************************************************************************
 */
-#include  "sisetup.h"     //  get the setup stuff 
+#include  "sisetup.h"     //  get the setup stuff
 #include "sitransport.h"
 #include       <sys/wait.h>
 
 */
 #define SI_SELECT_TIMEOUT 300000
 
-extern int SIwait( struct ginfo_blk *gptr ) {
-       int fd;                                                 //  file descriptor for use in this routine 
-       int ((*cbptr)());                               //  pointer to callback routine to call 
-       int status = SI_OK;                             //  return status 
-       int addrlen;                                    //  length of address from recvfrom call 
-       int i;                                                  //  loop index 
-       struct tp_blk *tpptr;                   //  pointer at tp stuff 
-       struct tp_blk *nextone;                 //  point at next block to process in loop 
-       int pstat;                                              //  poll status 
-       struct timeval  timeout;                //  delay to use on select call
-       char *buf;
-       char *ibuf;
+#ifndef SYSTEM_UNDER_TEST
+#      define SYSTEM_UNDER_TEST 0
+#endif
 
-       if( ( ibuf = (char *) malloc( 2048 ) ) == NULL ) {
-                       rmr_vlog( RMR_VL_WARN, "ibuf malloc fail\n" );
-                       return SI_ERROR;
+extern int SIwait( struct ginfo_blk *gptr ) {
+       int fd = -1;                                    //  file descriptor for use in this routine
+       int ((*cbptr)());                               //  pointer to callback routine to call
+       int status = SI_OK;                             //  return status
+       int addrlen = 0;                                //  length of address from recvfrom call
+       int i;                                                  //  loop index
+       struct tp_blk *tpptr = NULL;    //  pointer at tp stuff
+       struct tp_blk *nextone= NULL;   //  point at next block to process in loop
+       int pstat = 0;                                  //  poll status
+       struct timeval  timeout;                //  delay to use on select call
+       char *buf = NULL;
+       char *ibuf = NULL;
+
+       if( gptr->magicnum != MAGICNUM ) {                              //  if not a valid ginfo block
+               rmr_vlog( RMR_VL_CRIT, "SI95: wait: bad global info struct magic number is wrong\n" );
+               return SI_ERROR;
        }
 
-       if( gptr->flags & GIF_SHUTDOWN ) {                              //  cannot do if we should shutdown 
-               free( ibuf );
-               return SI_ERROR;                                                        //  so just get out 
+       if( gptr->flags & GIF_SHUTDOWN ) {                              //  cannot do if we should shutdown
+               return SI_ERROR;                                                        //  so just get out
        }
 
-       if( gptr->magicnum != MAGICNUM ) {                              //  if not a valid ginfo block 
-               rmr_vlog( RMR_VL_CRIT, "SI95: wait: bad global info struct magic number is wrong\n" );
-               free( ibuf );
-               return SI_ERROR;
+       if( ( ibuf = (char *) malloc( 2048 ) ) == NULL ) {
+                       rmr_vlog( RMR_VL_WARN, "ibuf malloc fail\n" );
+                       return SI_ERROR;
        }
 
        do {                                                                    // spin until a callback says to stop (likely never)
@@ -93,62 +95,66 @@ extern int SIwait( struct ginfo_blk *gptr ) {
                pstat = select( gptr->fdcount, &gptr->readfds, &gptr->writefds, &gptr->execpfds, &timeout );
 
                if( (pstat < 0 && errno != EINTR)  ) {
-                       gptr->fdcount = 0;                              //  prevent trying to look at a session 
-                       gptr->flags |= GIF_SHUTDOWN;    //  cause cleanup and exit at end 
+                       gptr->fdcount = 0;                              //  prevent trying to look at a session
+                       gptr->flags |= GIF_SHUTDOWN;    //  cause cleanup and exit at end
                }
 
                if( pstat > 0  &&  (! (gptr->flags & GIF_SHUTDOWN)) ) {
-                       tpptr = gptr->tplist; 
-                       while( tpptr != NULL ) { 
-                               nextone = tpptr->next;                          //  prevent issues if we delete the block during loop 
+                       tpptr = gptr->tplist;
+                       while( tpptr != NULL ) {
+                               nextone = tpptr->next;                          //  prevent issues if we delete the block during loop
 
                                if( tpptr->fd >= 0 ) {
                                        if( tpptr->squeue != NULL && (FD_ISSET( tpptr->fd, &gptr->writefds )) ) {
-                                               SIsend( gptr, tpptr );                  //  send if clear to send 
+                                               SIsend( gptr, tpptr );                  //  send if clear to send
                                        }
-       
+
                                        if( FD_ISSET( tpptr->fd, &gptr->execpfds ) ) {
-                                                       ;                               // sunos seems to set the except flag for unknown reasons; ignore it
+                                                       ;                               // sunos seems to set the except flag for unknown reasons; ignore it
                                        } else {
                                                if( FD_ISSET( tpptr->fd, &gptr->readfds ) ) {                   // ready to read
                                                        fd = tpptr->fd;
                                                        tpptr->rcvd++;
-       
+
                                                        if( tpptr->flags & TPF_LISTENFD ) {                                     // new session request
                                                                errno=0;
                                                                status = SInewsession( gptr, tpptr );                   // accept connection
                                                        } else  {                                                                                       //  data received on a regular port (we support just tcp now
-                                                               status = RECV( fd, gptr->rbuf, MAX_RBUF, 0 );   //  read data 
+                                                               status = RECV( fd, gptr->rbuf, MAX_RBUF, 0 );   //  read data
                                                                if( status > 0  &&  ! (tpptr->flags & TPF_DRAIN) ) {
                                                                        if( (cbptr = gptr->cbtab[SI_CB_CDATA].cbrtn) != NULL ) {
                                                                                status = (*cbptr)( gptr->cbtab[SI_CB_CDATA].cbdata, fd, gptr->rbuf, status );
-                                                                               SIcbstat( gptr, status, SI_CB_CDATA );  //  handle cb status 
+                                                                               SIcbstat( gptr, status, SI_CB_CDATA );  //  handle cb status
                                                                        }
-                                                               } else {                                                                                // no bites, but read flagged indicates disconnect
+                                                               } else {                                                                                // no bites, but read flagged indicates disconnect
                                                                        if( (cbptr = gptr->cbtab[SI_CB_DISC].cbrtn) != NULL ) {
                                                                                status = (*cbptr)( gptr->cbtab[SI_CB_DISC].cbdata, tpptr->fd );
-                                                                               SIcbstat( gptr, status, SI_CB_DISC );   //  handle status 
+                                                                               SIcbstat( gptr, status, SI_CB_DISC );   //  handle status
                                                                        }
                                                                        SIterm( gptr, tpptr );                  // close FD and mark block for deletion
                                                                }
                                                        }
                                                }
                                        }
-                               }                                                               //  if still good fd 
+                               }                                                               //  if still good fd
 
                                tpptr = nextone;
                        }
                }
+
+               if( SYSTEM_UNDER_TEST ) {                                // enabled only during uint testing to prevent blocking
+                       break;
+               }
        } while( gptr->tplist != NULL && !(gptr->flags & GIF_SHUTDOWN) );
 
        free( ibuf );
-       if( gptr->tplist == NULL )                                      //  indicate all fds closed 
+       if( gptr->tplist == NULL )                                      //  indicate all fds closed
 
-       if( gptr->flags & GIF_SHUTDOWN ) {                      //  we need to stop for some reason 
-               status = SI_ERROR;                                              //  status should indicate to user to die 
-               SIshutdown( gptr );                                             //  clean things up 
+       if( gptr->flags & GIF_SHUTDOWN ) {                      //  we need to stop for some reason
+               status = SI_ERROR;                                              //  status should indicate to user to die
+               SIshutdown( gptr );                                             //  clean things up
        } else {
-               status = SI_OK;                                                 //  user can continue to process 
+               status = SI_OK;                                                 //  user can continue to process
        }
 
        return status;
index a4008e3..783ce17 100644 (file)
        Date:           22 February 2021
 */
 
-#ifdef KEEP
-
-#include <unistd.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <strings.h>
-#include <errno.h>
-#include <string.h>
-#include <stdint.h>
-#include <pthread.h>
-#include <semaphore.h>
-
-
-#include <unistd.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <strings.h>
-#include <errno.h>
-#include <string.h>
-#include <stdint.h>
-#include <ctype.h>
-//#include <sys/epoll.h>
-//#include <pthread.h>
-//#include <semaphore.h>
-
-#define DEBUG 1                                                                // must define before pulling in rmr header files
-#define PARANOID_CHECKS        1                                       // must have parinoid testing on to not fail on nil pointer tests
-
-
-                                                                                       // specific test tools in this directory
-#undef NNG_UNDER_TEST
-#include "test_support.c"                                      // things like fail_if()
-#include "test_msg_support.c"
-#include "test_gen_rt.c"
-
-
-#include "rmr.h"                                       // things the users see
-#include "rmr_agnostic.h"                      // rmr private things
-
-#include "rmr_symtab.h"                                // must pull in for context setup
-#include "rmr_agnostic.h"                      // transport agnostic header
-
-#include "logging.c"
-#include "rt_generic_static.c"
-#include "tools_static.c"
-#include "symtab.c"
-//#include "rmr_si.c"
-//#include "mbuf_api.c"
-
-#include "test_ctx_support.c"                          // dummy context support (needs symtab defs, so not with others above)
-
-
-//static void gen_rt( uta_ctx_t* ctx );                // defined in sr_si_static_test, but used by a few others (eliminate order requirement below)
-
-                                                                                       // and finally.... the things under test
-#include "alarm.c"
-//#include "tools_static_test.c"                               // local test functions pulled directly because of static nature of things
-//#include "symtab_static_test.c"
-//#include "ring_static_test.c"
-//#include "rt_static_test.c"
-//#include "wormhole_static_test.c"
-//#include "mbuf_api_static_test.c"
-//#include "sr_si_static_test.c"
-//#include "lg_buf_static_test.c"
-// do NOT include the receive test static must be stand alone
-
-
-#endif
 
 /*
        These tests assume there is a dummy process listening on 127.0.0.1:1986; if it's not there
        the tests still pass, but coverage is reduced because the sends never happen.
 */
 static int alarm_test( ) {
-       int errors = 0;                 // number errors found
+       int errors = 0;                         // number errors found
        uta_ctx_t* ctx;
+       uta_ctx_t* pctx;                        // tests  into rtable functions need a second context
        char*   endpt = NULL;
 
        ctx = mk_dummy_ctx();
@@ -140,20 +73,42 @@ static int alarm_test( ) {
        uta_alarm_send( ctx, NULL );                                                                    // ensure nil message doesn't crash us
 
 
+       // ------ drive the alarm if dropping function in the route table code --------------------------------
+
+       pctx = mk_dummy_ctx();                          // grab a private context for rt to use
+
+       /*
+               These tests don't return anything that we can check; driving just to cover the lines and ensure
+               we don't segfault or something bad like that.
+       */
+       ctx->dcount - 0;
+       alarm_if_drops( ctx,  pctx );                   // should do nothing; no drops indicated
+
+       ctx->dcount = 1024;                                             // make it look like we dropped things
+       alarm_if_drops( ctx,  pctx );                   // should drive the code block to send alarm and put is in dropping mode
+
+       ctx->dcount = 1028;                                             // make it look like we are still  dropping
+       alarm_if_drops( ctx,  pctx );                   // drive the just reset time to clear block
+
+       alarm_if_drops( ctx,  pctx );                   // drive the check to see if past the clear time (it's not) to reset timer
+
+       fprintf( stderr, "<TEST> pausing 65 seconds before driving last alarm if drops call\n" );
+       sleep( 65 );                                                    // we must pause for longer than the timer so we can drive last block
+       alarm_if_drops( ctx,  pctx );                   // should appear that we're not dropping and reset the alarm
+
+
+       // -------------------------- tidy the house ---------------------------------------------------------
        if( ctx ) {
                free( ctx->my_name );
                free( ctx->my_ip );
                free( ctx );
        }
 
-       return !!errors;                        // 1 or 0 regardless of count
-}
-/*
-
-int main( ) {
-       int errors = 0;
+       if( pctx ) {
+               free( pctx->my_name );
+               free( pctx->my_ip );
+               free( pctx );
+       }
 
-       errors += alarm_test();
-       exit( !!errors );
+       return errors;
 }
-*/
index 1e30d86..3a555ce 100644 (file)
@@ -1,8 +1,8 @@
 // : vi ts=4 sw=4 noet :
 /*
 ==================================================================================
-           Copyright (c) 2019 Nokia
-           Copyright (c) 2018-2019 AT&T Intellectual Property.
+           Copyright (c) 2019-2021 Nokia
+           Copyright (c) 2018-2021 AT&T Intellectual Property.
 
    Licensed under the Apache License, Version 2.0 (the "License");
    you may not use this file except in compliance with the License.
@@ -105,9 +105,13 @@ static int hdr_test( ) {
        if( ! errors ) {
                fprintf( stderr, "<INFO> all msg header tests pass\n" );
        }
-       return !! errors;
+       return errors;
 }
 
 int main() {
-       return hdr_test();
+       int errors = 0;
+
+       errors +=  hdr_test();
+
+       return !! errors;
 }
index 75d8445..bbace51 100644 (file)
@@ -1,8 +1,8 @@
 // : vi ts=4 sw=4 noet :
 /*
 ==================================================================================
-           Copyright (c) 2019 Nokia
-           Copyright (c) 2018-2019 AT&T Intellectual Property.
+           Copyright (c) 2019-2021 Nokia
+           Copyright (c) 2018-2021 AT&T Intellectual Property.
 
    Licensed under the Apache License, Version 2.0 (the "License");
    you may not use this file except in compliance with the License.
@@ -108,5 +108,5 @@ int main( ) {
                fprintf( stderr, "<OK>   mbuf_api tests pass\n" );
        }
 
-       return errors;
+       return !! errors;
 }
index 6588907..b7cc5eb 100644 (file)
@@ -1,8 +1,8 @@
 // : vi ts=4 sw=4 noet :
 /*
 ==================================================================================
-           Copyright (c) 2019 Nokia
-           Copyright (c) 2018-2019 AT&T Intellectual Property.
+           Copyright (c) 2019-2021 Nokia
+           Copyright (c) 2018-2021 AT&T Intellectual Property.
 
    Licensed under the Apache License, Version 2.0 (the "License");
    you may not use this file except in compliance with the License.
@@ -463,5 +463,5 @@ static int rmr_api_test( ) {
        if( ! errors ) {
                fprintf( stderr, "<INFO> all RMr API tests pass\n" );
        }
-       return !!errors;
+       return errors;
 }
index 5f0a4f4..2e2b7c7 100644 (file)
@@ -1,8 +1,8 @@
 // : vi ts=4 sw=4 noet :
 /*
 ==================================================================================
-           Copyright (c) 2019-2020 Nokia
-           Copyright (c) 2018-2020 AT&T Intellectual Property.
+           Copyright (c) 2019-2021 Nokia
+           Copyright (c) 2018-2021 AT&T Intellectual Property.
 
    Licensed under the Apache License, Version 2.0 (the "License");
    you may not use this file except in compliance with the License.
@@ -99,8 +99,10 @@ static int rmr_api_test( ) {
        int             v = 0;                                  // some value
        char    wbuf[128];
        int             i;
+       void*   p;                                      // generic pointer to test return value
        int             state;
        int             max_tries;                      // prevent a sticking in any loop
+       uta_ctx_t* ctx;
 
        v = rmr_ready( NULL );
        errors += fail_if( v != 0, "rmr_ready returned true before initialisation "  );
@@ -280,9 +282,20 @@ static int rmr_api_test( ) {
        rmr_close( rmc );                       // no return to check; drive for coverage
 
 
-       // --------------- nil pointer exception checks
+       // ----- mt_rcv edge cases -------------------------------------------------------------------------------------
+       ctx = mk_dummy_ctx();
+       p = rmr_mt_rcv( NULL, msg, 0 );                         // give a valid message to cover additional lines
+       errors += fail_if_nil( p, "rmr_rt_rcv did not pointer when given a message with a nil context" );
+       if( msg ) {
+               errors += fail_if_equal( msg->state, RMR_OK, "rmr_mt_rcv returned OK state when given nil context" );
+       }
+
+       p = rmr_mt_rcv( ctx, msg, 0 );                          // one shot receive "poll" case
+       errors += fail_if_nil( p, "mt_rcv with one shot time length did not return a pointer" );
+
+
+       // --------------- nil pointer exception checks ----------------------------------------------------------------
        rmr_rcv_specific( NULL, NULL, "foo", 0 );
-       rmr_mt_rcv( NULL, NULL, 0 );
        mt_call( NULL, NULL, 0, 1, NULL );
        rmr_mt_call( NULL, NULL, 0, 1 );
        rmr_set_low_latency( NULL );
@@ -312,10 +325,32 @@ static int rmr_api_test( ) {
        errors += test_ep_counts();
        init_err( "test error message", rmc, rmc2, ENOMEM );            // drive for coverage
 
+       ctx = mk_dummy_ctx();
+       ctx->river_hash = rmr_sym_alloc( 129 );
+
+       buf2mbuf( NULL, NULL, 0, 0 );                                                           // things in mt_call_si_static
+
+       state = mt_data_cb( NULL, 0, "123", 3 );
+       errors += fail_not_equal( state, 0, "mt_data_cb didn't respond correctly when ctx is nil" );
+
+       state = mt_data_cb( ctx, -1, "123", 3 );
+       errors += fail_not_equal( state, 0, "mt_data_cb didn't respond correctly when ctx is nil" );
+
+       ctx->nrivers = 1;
+       state = mt_data_cb( ctx, 23, "123", 3 );                                        // force add river to hash reference
+       errors += fail_not_equal( state, 0, "mt_data_cb didn't respond correctly when ctx is nil" );
+
+       mt_disc_cb( NULL, 0 );
+       mt_disc_cb( ctx, 128 );                                 // for a FD we know isn't there
+
+
+       p = mt_receive( NULL );
+       errors += fail_not_nil( p, "mt_receive returned non-nil pointer when given nil context" );
+
        // --------------- phew, done ------------------------------------------------------------------------------
 
        if( ! errors ) {
                fprintf( stderr, "<INFO> all RMr API tests pass\n" );
        }
-       return !!errors;
+       return errors;
 }
index 57313f8..b040359 100644 (file)
@@ -1,8 +1,8 @@
 // : vi ts=4 sw=4 noet :
 /*
 ==================================================================================
-           Copyright (c) 2019-2020 Nokia
-           Copyright (c) 2018-2020 AT&T Intellectual Property.
+           Copyright (c) 2019-2021 Nokia
+           Copyright (c) 2018-2021 AT&T Intellectual Property.
 
    Licensed under the Apache License, Version 2.0 (the "License");
    you may not use this file except in compliance with the License.
@@ -270,5 +270,5 @@ static int rmr_rcv_test( ) {
                fprintf( stderr, "<INFO> receive tests failures noticed \n" );
        }
 
-       return !!errors;
+       return errors;
 }
index 491242d..256e2bd 100644 (file)
@@ -1,8 +1,8 @@
 // :vi sw=4 ts=4 noet:
 /*
 ==================================================================================
-       Copyright (c) 2020 Nokia
-       Copyright (c) 2020 AT&T Intellectual Property.
+       Copyright (c) 2020-2021 Nokia
+       Copyright (c) 2020-2021 AT&T Intellectual Property.
 
    Licensed under the Apache License, Version 2.0 (the "License");
    you may not use this file except in compliance with the License.
@@ -142,13 +142,10 @@ int main() {
        fprintf( stderr, "\n<INFO> starting RMr API tests\n" );
        errors += rmr_api_test();
 
-/// ---- all ok above here
-/*
        fprintf( stderr, "\n<INFO> run RMr API tests with src name only env var set\n" );
        setenv( "RMR_SRC_NAMEONLY", "1", 1 );
        errors += rmr_api_test();
        fprintf( stderr, "<INFO> error count: %d\n", errors );
-*/
 
        test_summary( errors, "rmr_si tests" );
        if( errors == 0 ) {
index d56f01f..3e66638 100644 (file)
@@ -1,8 +1,8 @@
 // : vi ts=4 sw=4 noet :
 /*
 ==================================================================================
-           Copyright (c) 2019 Nokia
-           Copyright (c) 2018-2019 AT&T Intellectual Property.
+           Copyright (c) 2019-2021 Nokia
+           Copyright (c) 2018-2021 AT&T Intellectual Property.
 
    Licensed under the Apache License, Version 2.0 (the "License");
    you may not use this file except in compliance with the License.
@@ -261,5 +261,5 @@ static int rt_test( ) {
        errors += fail_if_equal( state, -1, "call to link2_ep with nil ep returned true when false expected" );
 
 
-       return !!errors;                        // 1 or 0 regardless of count
+       return errors;
 }
index 3bdd312..6973a79 100644 (file)
@@ -2,8 +2,8 @@
 // : vi ts=4 sw=4 noet :
 /*
 ==================================================================================
-           Copyright (c) 2019 Nokia
-           Copyright (c) 2018-2019 AT&T Intellectual Property.
+           Copyright (c) 2019-2021 Nokia
+           Copyright (c) 2018-2021 AT&T Intellectual Property.
 
    Licensed under the Apache License, Version 2.0 (the "License");
    you may not use this file except in compliance with the License.
@@ -714,5 +714,5 @@ static int rt_test( ) {
        // ------ specific edge case tests -------------------------------------------------------------------------------
        errors += lg_clone_test( );
 
-       return !!errors;                        // 1 or 0 regardless of count
+       return errors;                  // 1 or 0 regardless of count
 }
index 809d9a1..8e9ee50 100644 (file)
@@ -1,8 +1,8 @@
 // :vi sw=4 ts=4 noet:
 /*
 ==================================================================================
-       Copyright (c) 2020 Nokia
-       Copyright (c) 2020 AT&T Intellectual Property.
+       Copyright (c) 2020-2021 Nokia
+       Copyright (c) 2020-2021 AT&T Intellectual Property.
 
    Licensed under the Apache License, Version 2.0 (the "License");
    you may not use this file except in compliance with the License.
 #include <errno.h>
 #include <pthread.h>
 #include <ctype.h>
-
-#include <netdb.h>             // these four needed for si address tests
-#include <stdio.h>
-#include <ctype.h>
-#include <netinet/in.h>
-
-
-
 #include <unistd.h>
-#include <stdio.h>
-#include <stdlib.h>
 #include <strings.h>
-#include <errno.h>
-#include <string.h>
 #include <stdint.h>
-#include <ctype.h>
 #include <sys/epoll.h>
-#include <pthread.h>
 #include <semaphore.h>
 
+
+#include <netdb.h>             // these four needed for si address tests
+#include <stdio.h>
+#include <ctype.h>
+#include <netinet/in.h>
+
 #define DEBUG 1
 
                                                                                        // specific test tools in this directory
 #include "test_support.c"                                      // things like fail_if()
 #include "test_transport_em.c"                         // system/transport emulation (open, close, connect, etc)
 
-/*
-#include "rmr.h"                                       // things the users see
-#include "rmr_symtab.h"
-#include "rmr_agnostic.h"                      // transport agnostic header
-*/
 #include <rmr_logging.h>
 #include <logging.c>
 
+
+// ------------- dummy functions to force edge cases when we can ---------------------------------------
+
+#define SYSTEM_UNDER_TEST      1                               // for conditional code
+
+/*
+       These are global so they can be reset for individual tests.
+*/
+static int good_mallocs = 0;           // number of initial good malocs before failurs
+static int bad_mallocs = 1;                    // number of failed mallocs (consecutive)
+
+static void* test_malloc( size_t n ) {
+
+fprintf( stderr, ">>>> test malloc: %d %d\n", good_mallocs, bad_mallocs );
+       if( good_mallocs ) {
+               good_mallocs--;
+               return malloc( n );
+       }
+
+       if( bad_mallocs ) {
+               bad_mallocs--;
+               errno = ENOMEM;
+               return NULL;
+       }
+
+       return malloc( n );
+}
+
+// -----------------------------------------------------------------------------------------------------
+
 #include <si95/siaddress.c>
 //#include <si95/sialloc.c>
 #include <si95/sibldpoll.c>
 #include <si95/sishutdown.c>
 #include <si95/siterm.c>
 #include <si95/sitrash.c>
-//#include <si95/siwait.c>
+#define malloc test_malloc
+#include <si95/siwait.c>
+#undef malloc
 
 // ---------------------------------------------------------------------
 
@@ -270,6 +289,15 @@ static int prep() {
 static int poll() {
        int errors  = 0;
        int status;
+       struct ginfo_blk* dummy;
+
+
+       dummy = SIinitialise( 0 );                              // get one to fiddle to drive edge cases
+       dummy->flags |= GIF_SHUTDOWN;                   // shutdown edge condition
+       SIpoll( dummy, 1 );
+
+       memset( dummy, 0, sizeof( *dummy ) );   // force bad cookie check code to drive
+       SIpoll( dummy, 1 );
 
        status = SIpoll( si_ctx, 1 );
        errors += fail_if_true( status != 0, "poll failed" );
@@ -436,6 +464,29 @@ static int send_tests( ) {
 }
 
 
+/*
+       Wait testing.  This is tricky because we don't have any sessions and thus it's difficult
+       to drive much of SIwait().
+*/
+static int wait_tests() {
+       int errors = 0;
+       struct ginfo_blk* dummy;
+
+
+       dummy = SIinitialise( 0 );                              // get one to fiddle to drive edge cases
+       SIwait( dummy );                                                // malloc should "fail"
+
+       dummy->flags |= GIF_SHUTDOWN;
+       SIwait( dummy );
+
+       memset( dummy, 0, sizeof( *dummy ) );   // force bad cookie check code to drive
+       SIwait( dummy );
+
+       SIwait( si_ctx );                                               // should drive once through the loop
+
+       return errors;
+}
+
 // ----------------------------------------------------------------------------------------
 
 /*
@@ -459,6 +510,7 @@ int main() {
        errors += send_tests();
 
        errors += poll();
+       errors += wait_tests();
 
        errors += cleanup();
 
index 9f88562..815f68b 100644 (file)
@@ -1,8 +1,8 @@
 // : vi ts=4 sw=4 noet :
 /*
 ==================================================================================
-           Copyright (c) 2019 Nokia
-           Copyright (c) 2018-2019 AT&T Intellectual Property.
+           Copyright (c) 2019-2021 Nokia
+           Copyright (c) 2018-2021 AT&T Intellectual Property.
 
    Licensed under the Apache License, Version 2.0 (the "License");
    you may not use this file except in compliance with the License.
@@ -269,7 +269,5 @@ static int sr_nano_test() {
        rtc( ctx );
 
 
-       // --- drive the route table things which are nanomsg specific ------
-
-       return !!errors;
+       return errors;
 }
index b11934d..9597c20 100644 (file)
@@ -1,8 +1,8 @@
 // : vi ts=4 sw=4 noet :
 /*
 ==================================================================================
-           Copyright (c) 2019 Nokia
-           Copyright (c) 2018-2019 AT&T Intellectual Property.
+           Copyright (c) 2019-2021 Nokia
+           Copyright (c) 2018-2021 AT&T Intellectual Property.
 
    Licensed under the Apache License, Version 2.0 (the "License");
    you may not use this file except in compliance with the License.
@@ -278,5 +278,5 @@ static int sr_nng_test() {
        errors += fail_not_equal( strncmp( payload_str, mbuf->payload, strlen( payload_str )), 0, "realloc payload (clone+nocopy) validation of unchanged payload fails" );
 
 
-       return !!errors;
+       return errors;
 }
index 213a08b..b86ab89 100644 (file)
@@ -1,8 +1,8 @@
 // : vi ts=4 sw=4 noet :
 /*
 ==================================================================================
-           Copyright (c) 2020 Nokia
-           Copyright (c) 2020 AT&T Intellectual Property.
+           Copyright (c) 2020-2021 Nokia
+           Copyright (c) 2020-2021 AT&T Intellectual Property.
 
    Licensed under the Apache License, Version 2.0 (the "License");
    you may not use this file except in compliance with the License.
@@ -277,6 +277,6 @@ static int sr_si_test() {
        dump_n( payload_str, "A dump", strlen( payload_str ) );
        dump_40( payload_str, "another dump" );
 
-       return !!errors;
+       return errors;
 
 }
index c512966..5bf2985 100644 (file)
@@ -1,7 +1,7 @@
 /*
 ==================================================================================
-           Copyright (c) 2019 Nokia
-           Copyright (c) 2018-2019 AT&T Intellectual Property.
+           Copyright (c) 2019-2021 Nokia
+           Copyright (c) 2018-2021 AT&T Intellectual Property.
 
    Licensed under the Apache License, Version 2.0 (the "License");
    you may not use this file except in compliance with the License.
@@ -136,6 +136,6 @@ static int symtab_test( ) {
        rmr_sym_free( NULL );                   // ensure it doesn't barf when given a nil pointer
        rmr_sym_free( st );
 
-       return !!( errors + symtab_state );
+       return  errors + (!!symtab_state );
 }
 
index 8cb8b15..9beae8d 100644 (file)
@@ -1,7 +1,7 @@
 /*
 ==================================================================================
-           Copyright (c) 2019 Nokia
-           Copyright (c) 2018-2019 AT&T Intellectual Property.
+           Copyright (c) 2019-2021 Nokia
+           Copyright (c) 2018-2021 AT&T Intellectual Property.
 
    Licensed under the Apache License, Version 2.0 (the "License");
    you may not use this file except in compliance with the License.
@@ -247,6 +247,8 @@ int main( ) {
        rmr_sym_free( NULL );                   // ensure it doesn't barf when given a nil pointer
        rmr_sym_free( st );
 
+       errors += thread_test();                // test as best we can for race issues
+
        test_summary( errors, "symtab tests" );
        if( state + errors == 0 ) {
                fprintf( stderr, "<PASS> all symtab tests were OK\n\n" );
@@ -254,7 +256,6 @@ int main( ) {
                fprintf( stderr, "<FAIL> %d errors in symtab code\n\n", errors );
        }
 
-       errors += thread_test();
 
        return !!(state + errors);
 }
index c6e4e8b..b914c38 100644 (file)
@@ -1,4 +1,3 @@
-       if_addrs_t*     ifl;                    // interface lis2
 // : vi ts=4 sw=4 noet :
 /*
 ==================================================================================
@@ -333,5 +332,5 @@ static int tools_test( ) {
        errors += ztbf_test();
 
        test_summary( errors, "tools" );
-       return !!errors;                        // 1 or 0 regardless of count
+       return errors;
 }
index 9d5fd58..cbca81d 100644 (file)
@@ -1,8 +1,8 @@
 // : vi ts=4 sw=4 noet :
 /*
 ==================================================================================
-           Copyright (c) 2019 Nokia
-           Copyright (c) 2018-2019 AT&T Intellectual Property.
+           Copyright (c) 2019-2021 Nokia
+           Copyright (c) 2018-2021 AT&T Intellectual Property.
 
    Licensed under the Apache License, Version 2.0 (the "License");
    you may not use this file except in compliance with the License.
@@ -218,5 +218,5 @@ static int worm_test( ) {
                free( ctx );
        }
 
-       return !!errors;                        // 1 or 0 regardless of count
+       return errors;
 }
index 3ca71ba..8f7d1ca 100644 (file)
@@ -59,5 +59,5 @@ static int wrapper_test( ) {
 
        // -------------------------------------------------------------------------------------------------
 
-       return !!errors;                        // 1 or 0 regardless of count
+       return errors;
 }