X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=blobdiff_plain;f=test%2Fsr_nano_static_test.c;h=9f88562c802e2aadd4f518587d08f9d6bbcef607;hb=353bafbe34c601eda6649ea7dcfdcf285d796d5a;hp=1eae96dc9492dd6474f2d1b1923d963195addf94;hpb=68d09fa5028e47e763c44c30647da31e77eda64a;p=ric-plt%2Flib%2Frmr.git diff --git a/test/sr_nano_static_test.c b/test/sr_nano_static_test.c index 1eae96d..9f88562 100644 --- a/test/sr_nano_static_test.c +++ b/test/sr_nano_static_test.c @@ -50,6 +50,7 @@ static void gen_rt( uta_ctx_t* ctx ) { char* rt_stuff; // strings for the route table rt_stuff = + "\r" // ensure we are not screwed by broken OSes that insist on using \r "newrt|end\n" // end of table check before start of table found "# comment to drive full comment test\n" "\n" // handle blank lines @@ -59,6 +60,37 @@ static void gen_rt( uta_ctx_t* ctx ) { "newrt|start\n" // false start to drive detection "xxx|badentry to drive default case" "newrt|start\n" + "rte|0|localhost:4560,localhost:4562,dummy-test:1111\n" // these are legitimate entries for our testing + "rte|1|localhost:4562;localhost:4561,localhost:4569,10.7.9.86:4560\n" + "rte|2|localhost:4562| 10\n" // new subid at end + "mse|4|10|localhost:4561\n" // new msg/subid specifier rec + "mse|4|localhost:4561\n" // new mse entry with less than needed fields + " rte| 5 |localhost:4563 #garbage comment\n" // tests white space cleanup + "rte|6|localhost:4562\n" + "newrt|end\n"; + + fd = open( "utesting.rt", O_WRONLY | O_CREAT, 0600 ); + if( fd < 0 ) { + fprintf( stderr, " unable to open file for testing route table gen\n" ); + return; + } + + setenv( "RMR_SEED_RT", "utesting.rt", 1 ); + write( fd, rt_stuff, strlen( rt_stuff ) ); + close( fd ); + read_static_rt( ctx, 0 ); + unlink( "utesting.rt" ); +} + +/* + Generates a legitimate table but with a missing newline on the last record. +*/ +static void gen_mlnl_rt( uta_ctx_t* ctx ) { + int fd; + char* rt_stuff; // strings for the route table + + rt_stuff = + "newrt|start\n" "rte|0|localhost:4560,localhost:4562\n" // these are legitimate entries for our testing "rte|1|localhost:4562;localhost:4561,localhost:4569\n" "rte|2|localhost:4562| 10\n" // new subid at end @@ -66,7 +98,7 @@ static void gen_rt( uta_ctx_t* ctx ) { "mse|4|localhost:4561\n" // new mse entry with less than needed fields " rte| 5 |localhost:4563 #garbage comment\n" // tests white space cleanup "rte|6|localhost:4562\n" - "newrt|end\n"; + "newrt|end"; // should not affect the loader fd = open( "utesting.rt", O_WRONLY | O_CREAT, 0600 ); if( fd < 0 ) { @@ -81,6 +113,44 @@ static void gen_rt( uta_ctx_t* ctx ) { unlink( "utesting.rt" ); } +/* + Generate an empty route table to test edge case. +*/ +static void gen_empty_rt( uta_ctx_t* ctx ) { + int fd; + + fd = open( "utesting.rt", O_WRONLY | O_CREAT | O_TRUNC, 0600 ); + if( fd < 0 ) { + fprintf( stderr, " unable to open file for testing route table gen\n" ); + return; + } + + setenv( "RMR_SEED_RT", "utesting.rt", 1 ); + //write( fd, "", 0 ); + close( fd ); + read_static_rt( ctx, 0 ); + unlink( "utesting.rt" ); +} + +/* + Generate an single byte route table to drive an edge handling case. +*/ +static void gen_sb_rt( uta_ctx_t* ctx ) { + int fd; + + fd = open( "utesting.rt", O_WRONLY | O_CREAT | O_TRUNC, 0600 ); + if( fd < 0 ) { + fprintf( stderr, " unable to open file for testing route table gen\n" ); + return; + } + + setenv( "RMR_SEED_RT", "utesting.rt", 1 ); + write( fd, " ", 1 ); + close( fd ); + read_static_rt( ctx, 0 ); + unlink( "utesting.rt" ); +} + /* Drive the send and receive functions. We also drive as much of the route @@ -113,12 +183,27 @@ static int sr_nano_test() { ctx->mring = NULL; //uta_mk_ring( 128 ); ctx->max_plen = RMR_MAX_RCV_BYTES + sizeof( uta_mhdr_t ); ctx->max_mlen = ctx->max_plen + sizeof( uta_mhdr_t ); - ctx->my_name = strdup( "dummy-test" ); + ctx->my_name = strdup( "dummy-test:1111" ); ctx->my_ip = strdup( "30.4.19.86:1111" ); uta_lookup_rtg( ctx ); + ctx->rtable = NULL; + gen_sb_rt( ctx ); // generate and read a file with a sinle byte to test edge case + errors += fail_not_nil( ctx->rtable, "read single byte route table produced a table" ); + + ctx->rtable = NULL; + gen_empty_rt( ctx ); // generate and read an empty rt file to test edge case + errors += fail_not_nil( ctx->rtable, "read empty route table file produced a table" ); + + ctx->rtable = NULL; + gen_mlnl_rt( ctx ); // ensure that a file with missing last new line does not trip us up + errors += fail_if_nil( ctx->rtable, "read route table file with missing last newline did not produce a table" ); + + ctx->rtable = NULL; gen_rt( ctx ); // forces a static load with some known info since we don't start the rtc() + errors += fail_if_nil( ctx->rtable, "read multi test route table file did not produce a table" ); gen_rt( ctx ); // force a second load to test cloning + errors += fail_if_nil( ctx->rtable, "read multi test route table file to test clone did not produce a table" ); p = rt_ensure_ep( NULL, "foo" ); // drive for coverage errors += fail_not_nil( p, "rt_ensure_ep did not return nil when given nil route table" );