X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=blobdiff_plain;f=test%2Frt_static_test.c;h=6973a7992c94974bcf884a3806f1e666cc13a925;hb=11838bcf76f3614384459cb56e2ce80dea788cef;hp=1647993a7d2697f12a5e6bc3e307a49da9802c38;hpb=9c923bcc9322c22220b574671c7b46f10008c614;p=ric-plt%2Flib%2Frmr.git diff --git a/test/rt_static_test.c b/test/rt_static_test.c index 1647993..6973a79 100644 --- a/test/rt_static_test.c +++ b/test/rt_static_test.c @@ -1,8 +1,9 @@ + // : 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. @@ -87,10 +88,37 @@ static uint64_t build_key( uint32_t mtype, uint32_t sid ) { k = (uint64_t) sid << 32; k += mtype; -fprintf( stderr, " build key: %x %x --> %llx\n", (int) mtype, (int) sid, (long long) k ); + fprintf( stderr, " 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 @@ -123,9 +151,11 @@ static int rt_test( ) { 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 + void* p; // generic pointer #ifndef NNG_UNDER_TEST si_ctx_t* si_ctx = NULL; @@ -192,7 +222,11 @@ static int rt_test( ) { 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, " abort: cannot continue without a route table\n" ); exit( 1 ); @@ -224,7 +258,7 @@ static int rt_test( ) { // ----- 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 ); @@ -233,12 +267,14 @@ static int rt_test( ) { 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 ); @@ -248,6 +284,8 @@ static int rt_test( ) { 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 ); } @@ -274,7 +312,7 @@ static int rt_test( ) { #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" ); @@ -285,16 +323,24 @@ 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" ); - 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 @@ -371,7 +417,7 @@ static int rt_test( ) { 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 @@ -404,18 +450,61 @@ static int rt_test( ) { free( buf ); } + fprintf( stderr, " test is overtly dropping rt table at %p\n", rt ); + ctx->rtable = NULL; uta_rt_drop( rt ); rt = NULL; + // --- force the load of a RT which has some edge case forcing issues if( ctx ) { - if( (seed_fname = getenv( "RMR_SEED_RT" )) != NULL ) { - read_static_rt( ctx, 0 ); - rt = ctx->rtable; - errors += fail_if_nil( rt, "read seed table didn't generate a rtable pointer in context" ); - unsetenv( "RMR_SEED_RT" ); // remove for next test + char* rt_stuff = + "newrt | start | dummy-seed\n" + "mse | 1 | -1 | localhost:84306\n" + "mse | 10 | -1 | localhost:84306\n" + "mse | 10 | 1 | localhost:84306\n" + "# should cause failure because there aren't 10 entries above\n" + "newrt | end | 10\n" + + "# this table has no end\n" + "newrt | start | dummy-seed\n" + "mse | 1 | -1 | localhost:84306\n" + "mse | 10 | -1 | localhost:84306\n" + "mse | 10 | 1 | localhost:84306\n" + + "# this table should be ok\n" + "newrt | start | dummy-seed\n" + "mse | 1 | -1 | localhost:84306\n" + "mse | 10 | -1 | localhost:84306\n" + "mse | 10 | 1 | localhost:84306\n" + "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 | 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" + "del | 10 | 1\n" + "update | end | 2\n"; + + fprintf( stderr, " loading RT from edge case static table\n" ); + fprintf( stderr, " %s\n", rt_stuff ); + gen_custom_rt( ctx, rt_stuff ); + fprintf( stderr, " 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 } @@ -487,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 @@ -530,6 +623,36 @@ static int rt_test( ) { 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" ); @@ -578,5 +701,18 @@ static int rt_test( ) { errors += fail_not_nil( ep, "fd2ep delete returned a pointer for unknown mapping" ); #endif - return !!errors; // 1 or 0 regardless of count + // ---------------- 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 ); + + 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 }