X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=blobdiff_plain;f=sidecars%2Flistener%2Funit_test.c;h=a946c8cbca19ceb03c30b801d9c26fdc4e26565e;hb=38f27842e94d88780e012e6145e7a62913a6a347;hp=9699f6cae430c7d815bba6fcc1e7d7a37ef712de;hpb=6c6ac644fc38772b343347cda37c884af8415cfb;p=ric-app%2Fmc.git diff --git a/sidecars/listener/unit_test.c b/sidecars/listener/unit_test.c index 9699f6c..a946c8c 100644 --- a/sidecars/listener/unit_test.c +++ b/sidecars/listener/unit_test.c @@ -37,6 +37,7 @@ #include #include +#define TEST_MTYPE 1000 // message type for testing #include "test_rmr_em.c" // emulated rmr functions (for receives) // this/these are what we are testing; include them directly (must be after forever def) @@ -89,14 +90,14 @@ int main( int argc, char** argv ) { mcl_set_sigh(); // prevent colobber from broken pipe - open_fifo( ctx, 100, WRITER ); // open dummy to prevent blocking reader - rfd = open_fifo( ctx, 100, READER ); // open a reader to check fanout output + open_fifo( ctx, TEST_MTYPE, WRITER ); // open dummy to prevent blocking reader + rfd = open_fifo( ctx, TEST_MTYPE, READER ); // open a reader to check fanout output if( rfd < 0 ) { fprintf( stderr, "[FAIL] unable to open a pipe reader for type == 100\n" ); errors++; } - fd = suss_fifo( ctx, 100, 1, &fref ); // should open the file for writing and return the fdes + fd = suss_fifo( ctx, TEST_MTYPE, WRITER, &fref ); // should open the file for writing and return the fdes if( fd < 0 ) { fprintf( stderr, "[FAIL] suss_fifo did not return a valid fd\n" ); errors++; @@ -110,7 +111,7 @@ int main( int argc, char** argv ) { chalk_error( fref ); } - fd2= suss_fifo( ctx, 100, 0, NULL ); // should open the file file for reading and return a different fd + fd2= suss_fifo( ctx, TEST_MTYPE, 0, NULL ); // should open the file file for reading and return a different fd if( fd < 0 ) { fprintf( stderr, "[FAIL] suss_fifo did not return a valid fd\n" ); errors++; @@ -122,25 +123,28 @@ int main( int argc, char** argv ) { mcl_start_listening( ctx, port, 0 ); // start the listener - // under test, the forever keeps fanout from blocking; drive for each of two cases: + // under test, the FOREVER = 0 keeps fanout from blocking; drive several times to cover all cases mcl_fifo_fanout( ctx, 5, 1 ); // first rmr receive call will simulate a timeout - mcl_fifo_fanout( ctx, 5, 1 ); // second receive call simualtes a message arriving - mcl_fifo_fanout( ctx, 5, 1 ); // another round so there are two to read + mcl_fifo_fanout( ctx, 5, 1 ); // second receive simulates a health check + mcl_fifo_fanout( ctx, 5, 1 ); // 3-n return alternating timeout messages; drive so that + mcl_fifo_fanout( ctx, 5, 1 ); // we will have several land in the FIFO + mcl_fifo_fanout( ctx, 5, 1 ); + mcl_fifo_fanout( ctx, 5, 1 ); mcl_fifo_fanout( ctx, 5, 1 ); *timestamp = 0; - state = mcl_fifo_read1( ctx, 100, payload, sizeof( payload ), TRUE ); + state = mcl_fifo_read1( ctx, TEST_MTYPE, payload, sizeof( payload ), TRUE ); if( state < 1 ) { fprintf( stderr, "[FAIL] fifo_read return positive value when expected to\n" ); errors++; } - state = mcl_fifo_tsread1( ctx, 100, payload, sizeof( payload ), TRUE, timestamp ); + state = mcl_fifo_tsread1( ctx, TEST_MTYPE, payload, sizeof( payload ), TRUE, timestamp ); if( state < 1 ) { fprintf( stderr, "[FAIL] fifo_read with timestamp return positive value when expected to\n" ); errors++; } - state = fifo_read1( NULL, 100, payload, sizeof( payload ), 1, timestamp ); // coverage error check + state = fifo_read1( NULL, TEST_MTYPE, payload, sizeof( payload ), 1, timestamp ); // coverage error check if( state != 0 ) { fprintf( stderr, "[FAIL] fifo_read didn't return 0 when given a nil context to\n" ); errors++; @@ -155,6 +159,7 @@ int main( int argc, char** argv ) { logit( LOG_WARN, "warning message" ); logit( LOG_STAT, "stats message" ); + fprintf( stderr, "[INFO] expected create fail message should follow\n" ); bad_ctx = mcl_mk_context( "/nosuchdirectoryinthesystem" ); // create a context where fifo opens should fail if( bad_ctx == NULL ) { fprintf( stderr, "[FAIL] couldn't make 'bad' context" ); @@ -162,7 +167,7 @@ int main( int argc, char** argv ) { } fref = NULL; - fd = suss_fifo( bad_ctx, 100, 1, &fref ); // should fail to open the file for writing beacuse directory is bad + fd = suss_fifo( bad_ctx, TEST_MTYPE, 1, &fref ); // should fail to open the file for writing beacuse directory is bad if( fd >= 0 ) { fprintf( stderr, "[FAIL] suss_fifo returned a valid fd when given a context with a bad directory path\n" ); errors++; @@ -172,7 +177,7 @@ int main( int argc, char** argv ) { errors++; } - fd = suss_fifo( NULL, 100, 1, &fref ); // coverage nil pointer check + fd = suss_fifo( NULL, TEST_MTYPE, 1, &fref ); // coverage nil pointer check if( fd >= 0 ) { fprintf( stderr, "[FAIL] suss_fifo returned a valid fd when given a nil context a bad directory path\n" ); errors++; @@ -231,14 +236,14 @@ int main( int argc, char** argv ) { build_hdr( 1024, wbuf, sizeof( wbuf ) ); bp = NULL; - bp = rdc_init_buf( 100, wbuf, 10, bp ); // set up for write + bp = rdc_init_buf( TEST_MTYPE, wbuf, 10, bp ); // set up for write rdc_write( ctx, bp, payload, sizeof( payload ) ); // write the raw data fprintf( stderr, "[INFO] pausing to test rdc file rolling\n" ); sleep( 15 ); build_hdr( 1024, wbuf, sizeof( wbuf ) ); bp = NULL; - bp = rdc_init_buf( 100, wbuf, 10, bp ); + bp = rdc_init_buf( TEST_MTYPE, wbuf, 10, bp ); rdc_write( ctx, bp, payload, sizeof( payload ) );