*/
static int rt_test( ) {
uta_ctx_t* ctx; // context needed to test load static rt
+ uta_ctx_t* pctx; // "private" context for route manager communication tests
route_table_t* rt; // route table
route_table_t* crt; // cloned route table
rtable_ent_t* rte; // route table entries from table
int enu = 0;
int state;
char *buf;
+ char *buf2;
char* seed_fname; // seed file
SOCKET_TYPE nn_sock; // differnt in each transport (nng == struct, SI/Nano == int)
rmr_mbuf_t* mbuf; // message for meid route testing
entries[enu].group = 0; entries[enu].ep_name = "localhost:5512"; enu++;
- rt = uta_rt_init( ); // get us a route table
+ rt = uta_rt_init( NULL );
+ errors += fail_if_false( rt == NULL, "rt_init given a nil context didn't return nil" );
+
+ ctx = mk_dummy_ctx(); // make a dummy with rtgate mutex
+ rt = uta_rt_init( ctx ); // get us a route table
if( (errors += fail_if_nil( rt, "pointer to route table" )) ) {
fprintf( stderr, "<FAIL> abort: cannot continue without a route table\n" );
exit( 1 );
// ----- end hacking together a route table ---------------------------------------------------
- crt = uta_rt_clone( rt ); // clone only the endpoint entries
+ crt = uta_rt_clone( ctx, rt, NULL, 0 ); // create a new rt and clone only the me entries
errors += fail_if_nil( crt, "cloned route table" );
if( crt ) {
c1 = count_entries( rt, 1 );
c2 = count_entries( crt, 0 );
errors += fail_not_equal( c2, 0, "cloned (endpoints) table entries space 0 count (a) was not zero as expected" );
+
+ errors += fail_if_false( crt->ephash == rt->ephash, "ephash pointer in cloned table is not right" );
uta_rt_drop( crt );
}
- crt = uta_rt_clone_all( rt ); // clone all entries
- errors += fail_if_nil( crt, "cloned all route table" );
+ crt = uta_rt_clone( ctx, rt, NULL, 1 ); // clone all entries (MT and ME)
+ errors += fail_if_nil( crt, "cloned (all) route table" );
if( crt ) {
c1 = count_entries( rt, 0 );
c1 = count_entries( rt, 1 );
c2 = count_entries( crt, 1 );
errors += fail_not_equal( c1, c2, "cloned (all) table entries space 1 count (b) did not match original table count (a)" );
+
+ errors += fail_if_false( crt->ephash == rt->ephash, "ephash pointer in cloned table (all) is not right" );
uta_rt_drop( crt );
}
#ifdef NNG_UNDER_TEST
state = uta_epsock_byname( rt, "localhost:4561", &nn_sock, &ep ); // this should be found
#else
- state = uta_epsock_byname( ctx, "localhost:4561", &nn_sock, &ep ); // this should be found
+ state = uta_epsock_byname( ctx, "localhost:4561", &nn_sock, &ep ); // this should be found
#endif
errors += fail_if_equal( state, 0, "socket (by name)" );
errors += fail_if_nil( ep, "epsock_byname did not populate endpoint pointer when expected to" );
#endif
errors += fail_not_equal( state, 0, "socket (by name) nil check returned true" );
- ep->open = 1;
- #if NNG_UNDER_TEST
- state = uta_epsock_byname( rt, "localhost:4561", &nn_sock, NULL ); // test coverage on nil checks
- #else
- state = uta_epsock_byname( ctx, "localhost:4561", &nn_sock, NULL );
- #endif
- errors += fail_if_equal( state, 0, "socket (by name) open ep check returned false" );
+ if( ep ) { // if previous test fails, cant run this
+ ep->open = 1;
+ #if NNG_UNDER_TEST
+ state = uta_epsock_byname( rt, "localhost:4561", &nn_sock, NULL ); // test coverage on nil checks
+ #else
+ state = uta_epsock_byname( ctx, "localhost:4561", &nn_sock, NULL );
+ #endif
+ errors += fail_if_equal( state, 0, "socket (by name) open ep check returned false" );
+ }
// --- test that the get_rte function finds expected keys, and retries to find 'bad' sid attempts for valid mtypes with no sid
errors += fail_if_true( state, "uta_epsock_rr returned bad (non-zero) state when given nil socket pointer" );
- uta_rt_clone( NULL ); // verify null parms don't crash things
+ uta_rt_clone( ctx, NULL, NULL, 0 ); // verify null parms don't crash things
uta_rt_drop( NULL );
#ifdef NNG_UNDER_TEST
uta_epsock_rr( NULL, 0, &more, &nn_sock, &ep ); // drive null case for coverage
free( buf );
}
+fprintf( stderr, ">>>>>> test is overtly dropping rt table at %p\n", rt );
uta_rt_drop( rt );
rt = NULL;
ep = (endpoint_t *) malloc( sizeof( *ep ) );
+ memset( ep, 0, sizeof( ep ) );
pthread_mutex_init( &ep->gate, NULL );
ep->name = strdup( "worm" );
ep->addr = NULL;
+ ep->notify = 1;
#ifdef NNG_UNDER_TEST
state = uta_link2( ep );
#else
#ifndef NNG_UNDER_TEST
ep->open = 0; // context is used only if ep not open, so to check this test close the ep
+ ep->notify = 1;
state = rt_link2_ep( NULL, ep );
errors += fail_if_true( state, "rt_link2_ep returned true when given bad context" );
errors += fail_not_equal( state, 0, "epsock_meid returned true when given nil socket pointer" );
#endif
+ // ------------ debugging and such; coverage only calls ----------------------------------------------------------
+ ep_stats( ctx->rtable, NULL, "name", NULL, NULL ); // ensure no crash when given nil pointer
+ rt_epcounts( ctx->rtable, "testing" );
+ rt_epcounts( NULL, "testing" );
+
+ buf = ensure_nlterm( NULL );
+ errors += fail_if_nil( buf, "ensure nlterm returned null pointer when given nil ptr" );
+ if( buf ) {
+ errors += fail_not_equal( strlen( buf ), 1, "ensure nlterm returned incorrect length string when given nil pointer" );
+ free( buf );
+ }
+
+ buf = ensure_nlterm( strdup( "x" ) ); // should return "x\n"
+ errors += fail_if_nil( buf, "ensure nlterm returned null pointer when given single char string" );
+ if( buf ) {
+ errors += fail_not_equal( strlen( buf ), 2, "ensure nlterm returned incorrect length string when given single char string" );
+ free( buf );
+ }
+
+ buf = strdup( "x\n" );
+ buf2 = ensure_nlterm( buf ); // buffer returned should be the same
+ if( fail_not_pequal( buf, buf2, "ensure nlterm returned new buffer for one char string with newline" ) ) {
+ errors++;
+ free( buf2 );
+ }
+ free( buf );
+
+ buf = strdup( "Missing our trips to Gloria's for papossas.\n" );
+ buf2 = ensure_nlterm( buf ); // buffer returned should be the same
+ if( fail_not_pequal( buf, buf2, "ensure nlterm returned new buffer for string with newline" ) ) {
+ errors++;
+ free( buf2 );
+ }
+ free( buf );
+
+ buf = ensure_nlterm( strdup( "Stand up and cheer!" ) ); // force addition of newline
+ if( buf ) {
+ errors += fail_not_equal( strcmp( buf, "Stand up and cheer!\n" ), 0, "ensure nlterm didn't add newline" );
+ free( buf );
+ buf = NULL;
+ }
+
+
+ // ------------- route manager request/response funcitons -------------------------------------------------------
+ {
+ rmr_mbuf_t* smsg;
+
+ smsg = rmr_alloc_msg( ctx, 1024 );
+ send_rt_ack( ctx, smsg, "123456", 0, "no reason" );
+
+ pctx = mk_dummy_ctx();
+ ctx->rtg_whid = -1;
+ state = send_update_req( pctx, ctx );
+ errors += fail_not_equal( state, 0, "send_update_req did not return 0" );
+
+ ctx->rtg_whid = rmr_wh_open( ctx, "localhost:19289" );
+ state = send_update_req( pctx, ctx );
+ errors += fail_if_equal( state, 0, "send_update_req to an open whid did not return 0" );
+ }
+
// ------------- si only; fd to ep conversion functions ---------------------------------------------------------
#ifndef NNG_UNDER_TEST