Ensure RT incremental update not applied early
[ric-plt/lib/rmr.git] / test / rt_static_test.c
index 8bd91df..3bdd312 100644 (file)
@@ -1,3 +1,4 @@
+
 // : vi ts=4 sw=4 noet :
 /*
 ==================================================================================
@@ -87,10 +88,37 @@ static uint64_t build_key( uint32_t mtype, uint32_t sid ) {
        k = (uint64_t) sid << 32;
        k += mtype;
 
-fprintf( stderr, "<INFO> build key: %x %x --> %llx\n", (int) mtype, (int) sid, (long long) k );
+       fprintf( stderr, "<INFO> build key: %x %x --> %llx\n", (int) mtype, (int) sid, (long long) k );
        return k;
 }
 
+/*
+       Create a very large set of things to clone and ensure that the colleciton
+       buffers are properly resized without errors.
+*/
+static int lg_clone_test( ) {
+       int             errors = 0;
+       uta_ctx_t*      ctx;
+       char*   old_env;
+       route_table_t*  p;
+
+       old_env = getenv( "RMR_SEED_RT" );
+       setenv( "RMR_SEED_RT", "./large_meid.rt", 1 );
+
+       ctx = mk_dummy_ctx();
+
+       read_static_rt( ctx, 0 );
+       p = uta_rt_clone( ctx, ctx->rtable, NULL, 1 );                                          // clone to force the copy from the existing table
+       errors += fail_if_nil( p, "clone of large table returned nil" );
+       if( p != NULL ) {
+               errors += fail_not_equal( p->error, 0, "clone of large table had error" );
+       }
+
+       setenv( "RMR_SEED_RT", old_env, 1 );
+
+       return errors;
+}
+
 /*
        This is the main route table test. It sets up a very specific table
        for testing (not via the generic setup function for other test
@@ -127,6 +155,7 @@ static int rt_test( ) {
        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
+       void*   p;                              // generic pointer
 
        #ifndef NNG_UNDER_TEST
                si_ctx_t* si_ctx = NULL;
@@ -294,6 +323,12 @@ static int rt_test( ) {
                state = uta_epsock_byname( NULL, "localhost:4561", &nn_sock, &ep );             // test coverage on nil checks
        #else
                state = uta_epsock_byname( NULL, "localhost:4561", &nn_sock, &ep );
+               errors += fail_not_equal( state, 0, "socket (by name) nil context check returned true" );
+
+               p = ctx->si_ctx;
+               ctx->si_ctx = NULL;             // set to drive second test
+               state = uta_epsock_byname( ctx, "localhost:4561", &nn_sock, &ep );
+               ctx->si_ctx = p;
        #endif
        errors += fail_not_equal( state, 0, "socket (by name) nil check returned true" );
 
@@ -436,9 +471,6 @@ static int rt_test( ) {
                                "mse | 1  | -1 | localhost:84306\n"
                                "mse | 10  | -1 | localhost:84306\n"
                                "mse | 10  | 1 | localhost:84306\n"
-                               "# short record to drive test\n"
-                               "del\n"
-                               "del | 12 | 12\n"
 
                                "# this table should be ok\n"
                                "newrt | start | dummy-seed\n"
@@ -448,24 +480,31 @@ static int rt_test( ) {
                                "newrt | end | 3\n"
 
                                "# for an update to the existing table\n"
-
                                "# not in progress; drive that exception check\n"
                                "update | end | 23\n"
 
                                "update | start | dummy-seed\n"
-                               "mse | 2 | 2 | localhost:2222\n"
+                               "mse | 3 | 2 | localhost:2222\n"
+                               "# short record to drive test\n"
+                               "del\n"
                                "# no table end for exception handling\n"
 
                                "update | start | dummy-seed\n"
                                "mse | 2 | 2 | localhost:2222\n"
-                               "update | end | 1\n";
+                               "del | 10 | 1\n"
+                               "update | end | 2\n";
 
                fprintf( stderr, "<INFO> loading RT from edge case static table\n" );
                fprintf( stderr, "<INFO> %s\n", rt_stuff );
                gen_custom_rt( ctx, rt_stuff );
+               fprintf( stderr, "<INFO> edge case load completed\n" );
                errors += fail_if_nil( ctx->rtable, "edge case route table didn't generate a pointer into the context" );
 
                unsetenv( "RMR_SEED_RT" );                      // remove for next read try
+               if( ctx && ctx->seed_rt_fname != NULL ) {
+                       free( ctx->seed_rt_fname );
+                       ctx->seed_rt_fname = NULL;
+               }
                read_static_rt( ctx, 0 );                       // drive for not there coverage
        }
 
@@ -537,6 +576,10 @@ static int rt_test( ) {
        ctx->rtable = NULL;
        ctx->my_name = strdup( "my_host_name" );                // set up to load a rtable
        ctx->my_ip = strdup( "192.168.1.30" );
+       if( ctx && ctx->seed_rt_fname != NULL ) {
+               free( ctx->seed_rt_fname );
+               ctx->seed_rt_fname = NULL;
+       }
        gen_rt( ctx );                                                                  // generate a route table with meid entries and hang off ctx
 
        mbuf = rmr_alloc_msg( ctx, 2048 );               //  buffer to play with
@@ -659,9 +702,17 @@ static int rt_test( ) {
        #endif
 
        // ---------------- misc coverage tests --------------------------------------------------------------------------
-               collect_things( NULL, NULL, NULL, NULL, NULL );                         // these both return null, these test NP checks
-               collect_things( NULL, NULL, NULL, NULL, (void *) 1234 );                // the last is an invalid pointer, but check needed to force check on previous param
-               del_rte( NULL, NULL, NULL, NULL, NULL );
+       collect_things( NULL, NULL, NULL, NULL, NULL );                         // these both return null, these test NP checks
+       collect_things( NULL, NULL, NULL, NULL, (void *) 1234 );                // the last is an invalid pointer, but check needed to force check on previous param
+       del_rte( NULL, NULL, NULL, NULL, NULL );
+
+       ctx = mk_dummy_ctx();
+       roll_tables( ctx );                             // drive nil rt check
+
+
+
+       // ------ specific edge case tests -------------------------------------------------------------------------------
+       errors += lg_clone_test( );
 
        return !!errors;                        // 1 or 0 regardless of count
 }