# 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).
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" )
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
----------------------------
}
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;
}
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 );
}
}
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;
}
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;
}
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
-// :vi sw=4 ts=4 noet:
+ // :vi sw=4 ts=4 noet2
/*
==================================================================================
Copyright (c) 2019-2020 Nokia
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++;
}
}
}
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)
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
{
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;
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 );
+ }
}
}
}
*/
extern void *rmr_sym_alloc( int size )
{
- int i;
Sym_tab *table;
if( size < 11 ) /* provide a bit of sanity */
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 ) {
- // : 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.
// 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.
// 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.
// 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.
* 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)
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;
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();
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;
}
-*/
// : 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.
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;
}
// : 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.
fprintf( stderr, "<OK> mbuf_api tests pass\n" );
}
- return errors;
+ return !! errors;
}
// : 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.
if( ! errors ) {
fprintf( stderr, "<INFO> all RMr API tests pass\n" );
}
- return !!errors;
+ return errors;
}
// : 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.
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 " );
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 );
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;
}
// : 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.
fprintf( stderr, "<INFO> receive tests failures noticed \n" );
}
- return !!errors;
+ return errors;
}
// :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.
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 ) {
// : 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.
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;
}
// : 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.
// ------ specific edge case tests -------------------------------------------------------------------------------
errors += lg_clone_test( );
- return !!errors; // 1 or 0 regardless of count
+ return errors; // 1 or 0 regardless of count
}
// :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
// ---------------------------------------------------------------------
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" );
}
+/*
+ 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;
+}
+
// ----------------------------------------------------------------------------------------
/*
errors += send_tests();
errors += poll();
+ errors += wait_tests();
errors += cleanup();
// : 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.
rtc( ctx );
- // --- drive the route table things which are nanomsg specific ------
-
- return !!errors;
+ return errors;
}
// : 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.
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;
}
// : 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.
dump_n( payload_str, "A dump", strlen( payload_str ) );
dump_40( payload_str, "another dump" );
- return !!errors;
+ return errors;
}
/*
==================================================================================
- 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.
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 );
}
/*
==================================================================================
- 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.
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" );
fprintf( stderr, "<FAIL> %d errors in symtab code\n\n", errors );
}
- errors += thread_test();
return !!(state + errors);
}
- if_addrs_t* ifl; // interface lis2
// : vi ts=4 sw=4 noet :
/*
==================================================================================
errors += ztbf_test();
test_summary( errors, "tools" );
- return !!errors; // 1 or 0 regardless of count
+ return errors;
}
// : 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.
free( ctx );
}
- return !!errors; // 1 or 0 regardless of count
+ return errors;
}
// -------------------------------------------------------------------------------------------------
- return !!errors; // 1 or 0 regardless of count
+ return errors;
}