X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=blobdiff_plain;f=test%2Fsi95_test.c;h=fd6dd56dbc6264d2fb6f4578e74d30f70bcab132;hb=refs%2Fchanges%2F77%2F4177%2F1;hp=399ff781a660a4d8a6f6e4121699cce6035880d4;hpb=4d1f9bf4b14788f957964d93af940e84f8f01601;p=ric-plt%2Flib%2Frmr.git diff --git a/test/si95_test.c b/test/si95_test.c index 399ff78..fd6dd56 100644 --- a/test/si95_test.c +++ b/test/si95_test.c @@ -21,7 +21,7 @@ /* Mmemonic: si95_test.c Abstract: This is the main driver to test the si95 core functions - (within rmr/src/si/src/si95). + (within rmr/src/si/src/si95). Author: E. Scott Daniels Date: 6 March 2018 @@ -36,6 +36,12 @@ #include #include +#include // these four needed for si address tests +#include +#include +#include + + #include #include @@ -52,12 +58,13 @@ #define DEBUG 1 // specific test tools in this directory -#undef NNG_UNDER_TEST // NNG is NOT under test so undefine if set +#undef NNG_UNDER_TEST // NNG is NOT under test so undefine if set #define NO_EMULATION 1 // no emulation of transport functions #define NO_PRIVATE_HEADERS 1 // no rmr_si or rmr_nng headers #define NO_DUMMY_RMR 1 // no msg things -#include "test_support.c" // things like fail_if() +#include "test_support.c" // things like fail_if() +#include "test_transport_em.c" // system/transport emulation (open, close, connect, etc) /* #include "rmr.h" // things the users see @@ -67,18 +74,18 @@ #include #include -//#include +#include //#include //#include //#include //#include //#include -//#include -//#include +#include +#include //#include //#include #include -//#include +#include #include //#include //#include @@ -90,6 +97,11 @@ #include //#include +// --------------------------------------------------------------------- + +void* si_ctx = NULL; // a global context might be useful + +// --------------------------------------------------------------------- /* Memory allocation/free related tests @@ -106,25 +118,24 @@ static int memory( ) { iptr = SInew( IOQ_BLK ); errors += fail_if_nil( iptr, "memory: sinew returned nil when given ioq request" ); - iptr = SInew( IOQ_BLK ); SItrash( IOQ_BLK, iptr ); ptr = SInew( TP_BLK ); errors += fail_if_nil( ptr, "memory: sinew returned nil when given tpblk request" ); if( ptr ) { + iptr = SInew( IOQ_BLK ); ((struct tp_blk *)ptr)->squeue = iptr; SItrash( TP_BLK, ptr ); } - + ptr = SInew( GI_BLK ); errors += fail_if_nil( ptr, "memory: sinew returned nil when given giblk request" ); - SItrash( GI_BLK, ptr ); + SItrash( GI_BLK, ptr ); // GI block cannot be trashed, ensure this (valgind will complain about a leak) return errors; } -void* si_ctx = NULL; // a global context might be useful /* Test initialisation related things @@ -138,6 +149,107 @@ static int init() { SIclr_tflags( si_ctx, 0x00 ); // drive for coverage; no return value from these SIset_tflags( si_ctx, 0x03 ); + fprintf( stderr, " init module finished with %d errors\n", errors ); + return errors; +} + +static int cleanup() { + int errors = 0; + + if( ! si_ctx ) { + return 0; + } + + SItp_stats( si_ctx ); // drive for coverage only + SItp_stats( NULL ); + + SIconnect( si_ctx, "localhost:43086" ); // ensure context has a tp block to free on shutdown + SIshutdown( NULL ); + SIabort( si_ctx ); + + + fprintf( stderr, " cleanup module finished with %d errors\n", errors ); + return errors; +} + +/* + Address related tests. +*/ +static int addr() { + int errors = 0; + int l; + struct sockaddr* addr; + char buf1[4096]; + char buf2[4096]; + char* dest; + + addr = (struct sockaddr *) malloc( sizeof( struct sockaddr ) ); +/* + l = SIgenaddr( " [ff02::4]:4567", PF_INET6, IPPROTO_TCP, SOCK_STREAM, &addr ); + + SIgenaddr( " [ff02::4]:4567", PF_INET6, IPPROTO_TCP, SOCK_STREAM, &addr ); +*/ + + dest = NULL; + snprintf( buf1, sizeof( buf1 ), " [ff02::5:4001" ); // invalid address, drive leading space eater too + l = SIaddress( buf1, (void **) &dest, AC_TOADDR6 ); + errors += fail_if_true( l > 0, "to addr6 with bad addr convdersion returned valid len" ); + + snprintf( buf1, sizeof( buf1 ), "[ff02::5]:4002" ); // v6 might not be supported so failure is OK here; driving for coverage + l=SIaddress( buf1, (void **) &dest, AC_TOADDR6 ); + + snprintf( buf1, sizeof( buf1 ), "localhost:43086" ); + l = SIaddress( buf1, (void **) &dest, AC_TOADDR ); + errors += fail_if_true( l < 1, "to addr convdersion failed" ); + + snprintf( buf1, sizeof( buf1 ), "localhost:4004" ); + l = SIaddress( buf1, (void **) &dest, AC_TODOT ); + errors += fail_if_true( l < 1, "to dot convdersion failed" ); + + fprintf( stderr, " addr module finished with %d errors\n", errors ); + return errors; + +} + + +/* + Connection oriented tests. +*/ +static int conn( ) { + int errors = 0; + int state; + + state = SIconnect( si_ctx, "localhost:4567" ); // driver regular connect + errors += fail_if_true( state < 0, "connect to low port failed" ); + + state = SIconnect( si_ctx, "localhost:43086" ); // drive save connect with good return code + errors += fail_if_true( state < 0, "connect to high port failed" ); + + tpem_set_addr_dup_state( 1 ); // force get sockket name emulation to return a duplicate address + state = SIconnect( si_ctx, "localhost:43086" ); // drive save connect with good return code + errors += fail_if_true( state >= 0, "forced dup connect did not return error" ); + + tpem_set_addr_dup_state( 0 ); // force get sockket name emulation to return a duplicate address + tpem_set_conn_state( 1 ); + state = SIconnect( si_ctx, "localhost:4567" ); // driver regular connect + errors += fail_if_true( state >= 0, "connect to low port successful when failure expected" ); + + tpem_set_sock_state( 1 ); // make scoket calls fail + state = SIconnect( si_ctx, "localhost:4567" ); // driver regular connect + errors += fail_if_true( state >= 0, "connect to low port successful when socket based failure expected" ); + + tpem_set_sock_state( 0 ); + + state = SIlistener( si_ctx, TCP_DEVICE, "0.0.0.0:4567" ); + errors += fail_if_true( state < 0, "listen failed" ); + + tpem_set_bind_state( 1 ); + state = SIlistener( si_ctx, TCP_DEVICE, "0.0.0.0:4567" ); + errors += fail_if_true( state >= 0, "listen successful when bind error set" ); + tpem_set_bind_state( 0 ); + + + fprintf( stderr, " conn module finished with %d errors\n", errors ); return errors; } @@ -153,7 +265,11 @@ int main() { errors += init(); errors += memory(); + errors += addr(); + errors += conn(); + errors += cleanup(); + fprintf( stderr, " testing finished\n" ); if( errors == 0 ) { fprintf( stderr, " all tests were OK\n\n" ); } else {