Merge "Fix semaphore count bug in SI95 non-blocking rcv"
[ric-plt/lib/rmr.git] / test / ring_static_test.c
index 482244c..b194928 100644 (file)
@@ -1,14 +1,14 @@
 // : vi ts=4 sw=4 noet :
 /*
 ==================================================================================
 // : vi ts=4 sw=4 noet :
 /*
 ==================================================================================
-        Copyright (c) 2019 Nokia 
-        Copyright (c) 2018-2019 AT&T Intellectual Property.
+           Copyright (c) 2019 Nokia
+           Copyright (c) 2018-2019 AT&T Intellectual Property.
 
    Licensed under the Apache License, Version 2.0 (the "License");
    you may not use this file except in compliance with the License.
    You may obtain a copy of the License at
 
 
    Licensed under the Apache License, Version 2.0 (the "License");
    you may not use this file except in compliance with the License.
    You may obtain a copy of the License at
 
-       http://www.apache.org/licenses/LICENSE-2.0
+          http://www.apache.org/licenses/LICENSE-2.0
 
    Unless required by applicable law or agreed to in writing, software
    distributed under the License is distributed on an "AS IS" BASIS,
 
    Unless required by applicable law or agreed to in writing, software
    distributed under the License is distributed on an "AS IS" BASIS,
@@ -21,7 +21,7 @@
 /*
        Mmemonic:       ring_static_test.c
        Abstract:       Test the ring funcitons. These are meant to be included at compile
 /*
        Mmemonic:       ring_static_test.c
        Abstract:       Test the ring funcitons. These are meant to be included at compile
-                               time by the test driver.  
+                               time by the test driver.
 
        Author:         E. Scott Daniels
        Date:           3 April 2019
 
        Author:         E. Scott Daniels
        Date:           3 April 2019
 #include <errno.h>
 #include <string.h>
 #include <stdint.h>
 #include <errno.h>
 #include <string.h>
 #include <stdint.h>
+#include <pthread.h>
+#include <semaphore.h>
 
 
-#include "../src/common/include/rmr.h"
-#include "../src/common/include/rmr_agnostic.h"
-//#include "../src/common/src/ring_static.c"
+#include "rmr.h"
+#include "rmr_agnostic.h"
 
 
 /*
 
 
 /*
-       Conduct a series of interleaved tests inserting i-factor 
+       Conduct a series of interleaved tests inserting i-factor
        values before beginning to pull values (i-factor must be
        values before beginning to pull values (i-factor must be
-       size - 2 smaller than the ring. 
+       size - 2 smaller than the ring.
        Returns 0 on success, 1 on insert failure and 2 on pull failure.
 */
 static int ie_test( void* r, int i_factor, long inserts ) {
        Returns 0 on success, 1 on insert failure and 2 on pull failure.
 */
 static int ie_test( void* r, int i_factor, long inserts ) {
@@ -77,6 +78,8 @@ static int ring_test( ) {
        int     data[20];
        int*    dp;
        int size = 18;
        int     data[20];
        int*    dp;
        int size = 18;
+       int     pfd = -1;                                       // pollable file descriptor for the ring
+       int     errors = 0;
 
        r = uta_mk_ring( 0 );                   // should return nil
        if( r != NULL ) {
 
        r = uta_mk_ring( 0 );                   // should return nil
        if( r != NULL ) {
@@ -95,6 +98,19 @@ static int ring_test( ) {
                return 1;
        }
 
                return 1;
        }
 
+       pfd = uta_ring_getpfd( r );             // get pollable file descriptor
+       if( pfd < 0 ) {
+               fprintf( stderr, "<FAIL> expected a pollable file descriptor >= 0, but got: %d\n", pfd );
+               errors++;
+       }
+
+       pfd = uta_ring_config( r, 0x03 );               // turn on locking for reads and writes
+       if( pfd != 1 ) {
+               fprintf( stderr, "<FAIL> config attempt to enable locking failed\n" );
+               errors++;
+       }
+       
+
        for( i = 0; i < 20; i++ ) {             // test to ensure it reports full when head/tail start at 0
                data[i] = i;
                if( ! uta_ring_insert( r, &data[i] ) ) {
        for( i = 0; i < 20; i++ ) {             // test to ensure it reports full when head/tail start at 0
                data[i] = i;
                if( ! uta_ring_insert( r, &data[i] ) ) {
@@ -118,7 +134,7 @@ static int ring_test( ) {
                        } else {
                                break;
                        }
                        } else {
                                break;
                        }
-               }       
+               }
 
                if( *dp != i ) {
                        fprintf( stderr, "<FAIL> data at i=% isnt right; expected %d got %d\n", i, i, *dp );
 
                if( *dp != i ) {
                        fprintf( stderr, "<FAIL> data at i=% isnt right; expected %d got %d\n", i, i, *dp );
@@ -129,7 +145,7 @@ static int ring_test( ) {
                return 1;
        }
        fprintf( stderr, "<OK>   extracted values were sane, got: %d\n", i-1 );
                return 1;
        }
        fprintf( stderr, "<OK>   extracted values were sane, got: %d\n", i-1 );
-               
+
        uta_ring_free( NULL );                                                  // ensure this doesn't blow up
        uta_ring_free( r );
        for( i = 2; i < 15; i++ ) {
        uta_ring_free( NULL );                                                  // ensure this doesn't blow up
        uta_ring_free( r );
        for( i = 2; i < 15; i++ ) {
@@ -151,7 +167,7 @@ static int ring_test( ) {
                                fprintf( stderr, "<FAIL> ie test for 66K inserts didn't return 0\n" );
                                return 1;
                        }
                                fprintf( stderr, "<FAIL> ie test for 66K inserts didn't return 0\n" );
                                return 1;
                        }
-       
+
                        uta_ring_free( r );
                }
                fprintf( stderr, "<OK>   all large insert/exctract tests pass ring size=%d\n", size );
                        uta_ring_free( r );
                }
                fprintf( stderr, "<OK>   all large insert/exctract tests pass ring size=%d\n", size );
@@ -160,5 +176,5 @@ static int ring_test( ) {
        }
 
        fprintf( stderr, "<INFO> all ring tests pass\n" );
        }
 
        fprintf( stderr, "<INFO> all ring tests pass\n" );
-       return 0;
+       return errors;
 }
 }