Preparation for releasing 4.8.5
[ric-plt/lib/rmr.git] / test / rmr_si_api_static_test.c
index b7f97bf..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.
 #include "rmr.h"
 #include "rmr_agnostic.h"
 
+/*
+       Driving ep counts is tricky when trying to do it as a part of the rts function, so
+       we drive that code on it's own.
+*/
+static int test_ep_counts() {
+       int errors = 0;
+       struct endpoint ep;                     // need a dummy endpoint
+
+       memset( &ep, 0, sizeof( ep ) );
+
+       incr_ep_counts( RMR_OK, &ep );
+       errors += fail_if_false(  ep.scounts[EPSC_GOOD] == 1, "ep inc good counter had bad value" );
+
+       incr_ep_counts( RMR_ERR_RETRY, &ep );
+       errors += fail_if_false(  ep.scounts[EPSC_TRANS] == 1, "ep inc trans counter had bad value" );
+
+       incr_ep_counts( 99, &ep );                              // any non-retry/ok value
+       errors += fail_if_false(  ep.scounts[EPSC_FAIL] == 1, "ep inc fail counter had bad value" );
+
+       incr_ep_counts( RMR_OK, NULL );                 // ensure nil pointer doesn't crash us
+
+       return errors;
+}
+
 static int rmr_api_test( ) {
        int             errors = 0;
        void*   rmc;                            // route manager context
@@ -75,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 "  );
@@ -256,18 +282,75 @@ 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 );
        rmr_set_fack( NULL );
 
+
+       msg2 = rmr_alloc_msg( rmc,  1024 );
+       msg2 = rmr_rcv_msg( NULL, msg2 );
+       if( msg2 != NULL ) {
+               errors += fail_if( msg2->state == RMR_OK, "nil context check for rcv msg returned OK" );
+       }
+       msg2 = rmr_torcv_msg( NULL, msg2, 200 );
+       if( msg2 != NULL ) {
+               errors += fail_if( msg2->state == RMR_OK, "nil context check for torcv msg returned OK" );
+       }
+
+       //  ----- thread start coverage ---------------------------------------------------------------------------
+       setenv( "RMR_WARNINGS", "1", 1 );       // force non-default branches during these tests
+       setenv( "RMR_SRC_NAMEONLY", "1", 1 );
+
+       rmr_init( ":6789", 1024, 0 );           // threaded mode with defined/default RM target
+       setenv( "RMR_RTG_SVC", "-1", 1 );       // force into static table mode
+       rmr_init( ":6789", 1024, 0 );           // threaded mode with static table
+
+
+       // ---- some things must be pushed specifically for edge cases and such ------------------------------------
+       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;
 }