Add SI95 transport support
[ric-plt/lib/rmr.git] / test / app_test / sender.c
index 015b943..994c591 100644 (file)
@@ -68,6 +68,9 @@
 
 #include <rmr/rmr.h>
 
+#define WBUF_SIZE      1024
+#define TRACE_SIZE     1024
+
 static int sum( char* str ) {
        int sum = 0;
        int     i = 0;
@@ -112,9 +115,9 @@ int main( int argc, char** argv ) {
        int             mtype = 0;
        int             stats_freq = 100;
        int             successful = 0;                                 // set to true after we have a successful send
-       char    wbuf[1024];
+       char*   wbuf = NULL;                                    // working buffer
        char    me[128];                                                // who I am to vet rts was actually from me
-       char    trace[1024];
+       char*   trace = NULL;                                   // area to build trace data in
        long    timeout = 0;
        int             delay = 100000;                                 // usec between send attempts
        int             nmsgs = 10;                                             // number of messages to send
@@ -122,6 +125,9 @@ int main( int argc, char** argv ) {
        int             start_mt = 0;
        int             pass = 1;
 
+       wbuf = (char *) malloc( sizeof( char ) * WBUF_SIZE );
+       trace = (char *) malloc( sizeof( char ) * TRACE_SIZE );
+
        if( argc > 1 ) {
                nmsgs = atoi( argv[1] );
        }
@@ -187,7 +193,7 @@ int main( int argc, char** argv ) {
 
        timeout = time( NULL ) + 20;
 
-       gethostname( wbuf, sizeof( wbuf ) );
+       gethostname( wbuf, WBUF_SIZE );
        snprintf( me, sizeof( me ), "%s-%d", wbuf, getpid( ) );
 
        while( count < nmsgs ) {                                                                // we send n messages after the first message is successful
@@ -214,10 +220,15 @@ int main( int argc, char** argv ) {
                                        sbuf = rmr_send_msg( mrc, sbuf );                       // retry send until it's good (simple test; real programmes should do better)
                                }
                                if( sbuf->state == RMR_OK ) {
+                                       if( successful == 0 ) {
+                                               fail_count = 0;                                                 // count only after first message goes through
+                                       }
                                        successful = 1;                                                         // indicates only that we sent one successful message, not the current state
                                } else {
-                                       if( successful ) {
-                                               fail_count++;                                                   // count failures after first successful message
+                                       fail_count++;                                                   // count failures after first successful message
+                                       if( !successful && fail_count > 30 ) {
+                                               fprintf( stderr, "[FAIL] too many send errors for this test\n" );
+                                               exit( 1 );
                                        }
                                }
                                break;
@@ -273,8 +284,9 @@ int main( int argc, char** argv ) {
                }
        }
 
-       timeout = time( NULL ) + 2;                             // allow 2 seconds for the pipe to drain from the receiver
-       while( time( NULL ) < timeout );
+       fprintf( stderr, "<SNDR> draining begins\n" );
+       timeout = time( NULL ) + 20;                            // allow 20 seconds for the pipe to drain from the receiver
+       while( time( NULL ) < timeout ) {
                if( rcv_fd >= 0 ) {
                        while( (nready = epoll_wait( ep_fd, events, 1, 100 )) > 0 ) {                   // if something ready to receive (non-blocking check)
                                if( events[0].data.fd == rcv_fd ) {                                             // we only are waiting on 1 thing, so [0] is ok
@@ -283,7 +295,7 @@ int main( int argc, char** argv ) {
                                        if( rbuf ) {
                                                rcvd_count++;
                                                rts_ok += vet_received( me, rbuf->payload );
-                                               timeout = time( NULL ) + 2;
+                                               timeout = time( NULL ) + 10;                                                    // break 10s after last received message
                                        }
                                }
                        }
@@ -295,6 +307,8 @@ int main( int argc, char** argv ) {
                                }
                        }
                }
+       }
+       fprintf( stderr, "<SNDR> draining finishes\n" );
 
        if( rcvd_count != rts_ok || count != nmsgs ) {
                pass = 0;