+ mcl_start_listening( ctx, port, 0 ); // start the listener
+
+ // under test, the forever keeps fanout from blocking; drive for each of two 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 );
+
+ *timestamp = 0;
+ state = mcl_fifo_read1( ctx, 100, 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 );
+ 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
+ if( state != 0 ) {
+ fprintf( stderr, "[FAIL] fifo_read didn't return 0 when given a nil context to\n" );
+ errors++;
+ }
+
+ mcl_fifo_fanout( ctx, 5, 0 ); // test with writing short header
+ mcl_fifo_fanout( ctx, 5, 0 );
+
+ // ------ some error/coverage testing ---------------------------
+ logit( LOG_CRIT, "critical message" );
+ logit( LOG_ERR, "error message" );
+ logit( LOG_WARN, "warning message" );
+ logit( LOG_STAT, "stats message" );
+
+ 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" );
+ exit( 1 );
+ }
+
+ fref = NULL;
+ fd = suss_fifo( bad_ctx, 100, 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++;
+ }
+ if( fref != NULL ) {
+ fprintf( stderr, "[FAIL] suss_fifo returned an fref pointer when given a bad context\n" );
+ errors++;
+ }
+
+ fd = suss_fifo( NULL, 100, 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++;
+ }
+
+ fd = suss_fifo( ctx, -1, 1, &fref ); // mad message type check
+ if( fd >= 0 ) {
+ fprintf( stderr, "[FAIL] suss_fifo returned a valid fd when given a bad message type\n" );
+ errors++;
+ }
+
+ // -- buffer testing ------------------------------------------------------
+ bp = build_hdr( 1024, wbuf, 0 );
+ bp = build_hdr( 1024, NULL, 0 );
+ if( bp == NULL ) {
+ fprintf( stderr, "[FAIL] build_hdr didn't return a buffer pointer when given a nil buffer\n" );
+ errors++;
+ }
+ free( bp );
+
+ bp = build_hdr( 1024, wbuf, sizeof( wbuf ) );
+ if( bp == NULL ) {
+ fprintf( stderr, "[FAIL] build_hdr didn't return a buffer pointer\n" );
+ errors++;
+ }
+
+
+ // ----- msg receive testing ----------------------------------------------------
+ buf = mcl_get_msg( NULL, NULL, 1 ); // drive nil pointer checks
+ if( buf != NULL ) {
+ errors++;
+ fprintf( stderr, "[FAIL], get_msg call with nil context returned a buffer pointer\n" );
+ }
+
+ buf = mcl_get_msg( ctx, NULL, 1 ); // drive to force coverage; nothing is sent, so we can't validate buffer
+
+
+ mcl_fifo_one( NULL, NULL, 1, 1 );
+ mcl_fifo_one( ctx, NULL, 1, 1 );
+ mcl_fifo_one( ctx, wbuf, 0, 1 );
+ mcl_fifo_one( ctx, wbuf, 10, 100 );
+
+
+ // --- some rdc testing as best as we can without message generators --------
+ rdc_init( NULL, NULL, ".foo", ".bar" ); // coverage testing
+
+ ctx = setup_rdc(); // coverage test to ensure that it generates a context
+ if( ctx == NULL ) {
+ fprintf( stderr, "[FAIL] setup_rdc did not return a context pointer\n" );
+ errors++;
+ }
+
+ rdc_set_freq( NULL, 0 ); // error/nil test
+ rdc_set_freq( ctx, 0 ); // error/nil test
+ rdc_set_freq( ctx, 10 ); // roll after 10seconds to test that
+
+ build_hdr( 1024, wbuf, sizeof( wbuf ) );
+ bp = NULL;
+ bp = rdc_init_buf( 100, 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 );
+ rdc_write( ctx, bp, payload, sizeof( payload ) );
+
+
+ // CAUTION: filenames need to match those expected in the run script as it creates src, and will validate, destination files
+ state = copy_unlink( "/tmp/mc_listener_test/no-such-copy_src", "/tmp/mc_listener_test/copy_dest", 0664 ); // first couple drive for error and coverage
+ if( state >= 0 ) {
+ fprintf( stderr, "[FAIL] copy-unlink of bad file didn't return bad state\n" );
+ errors++;
+ }
+ state = copy_unlink( "/tmp/mc_listener_test/copy_src", "/tmp/mc_listener_test-nodir/copy_dest", 0664 );
+ if( state >= 0 ) {
+ fprintf( stderr, "[FAIL] copy-unlink of bad target didn't return bad state\n" );
+ errors++;
+ }
+ state = copy_unlink( "/tmp/mc_listener_test/copy_src", "/tmp/mc_listener_test/copy_dest", 0664 ); // drive for coverage; setup script can check contents
+ if( state < 0 ) {
+ fprintf( stderr, "[FAIL] copy-unlink expected success but failed\n" );
+ errors++;
+ }
+ state = mvocp( "/tmp/mc_listener_test/bad-src-mv_src", "/tmp/mc_listener_test/mv_dest" );
+ if( state >= 0 ) {
+ fprintf( stderr, "[FAIL] mv or copy expected failure didn't set bad state\n" );
+ errors++;
+ }
+ state = mvocp( "/tmp/mc_listener_test/mv_src", "/tmp/mc_listener_test/mv_dest" );
+ if( state < 0 ) {
+ fprintf( stderr, "[FAIL] mv or copy expected to succeed didn't set good state\n" );
+ errors++;
+ }
+