X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=blobdiff_plain;f=test%2Fring_static_test.c;h=5bf6795ace0f42a7aaa09f0f40824611e53cd4ba;hb=2bd8785ce17397e6f8e686be421c5a6c860a0b8c;hp=482244cc1a4cfcae2595a4261bbc1ab9cc426fdd;hpb=8dd46415b94b33fa960bdd5732e909ffc4859520;p=ric-plt%2Flib%2Frmr.git diff --git a/test/ring_static_test.c b/test/ring_static_test.c index 482244c..5bf6795 100644 --- a/test/ring_static_test.c +++ b/test/ring_static_test.c @@ -1,14 +1,14 @@ // : 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 - 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, @@ -21,7 +21,7 @@ /* 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 @@ -34,16 +34,13 @@ #include #include #include - -#include "../src/common/include/rmr.h" -#include "../src/common/include/rmr_agnostic.h" -//#include "../src/common/src/ring_static.c" - +#include +#include /* - 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 - 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 ) { @@ -77,23 +74,23 @@ static int ring_test( ) { 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 ) { - fprintf( stderr, " attempt to make a ring with size 0 returned a pointer\n" ); - return 1; - } + errors += fail_not_nil( r, "attempt to make a ring with size 0 returned a pointer" ); + r = uta_mk_ring( -1 ); // should also return nil - if( r != NULL ) { - fprintf( stderr, " attempt to make a ring with size <0 returned a pointer\n" ); - return 1; - } + errors += fail_not_nil( r, "attempt to make a ring with negative size returned a pointer" ); r = uta_mk_ring( 18 ); - if( r == NULL ) { - fprintf( stderr, " unable to make ring with 17 entries\n" ); - return 1; - } + errors += fail_if_nil( r, "attempt to make a ring with valid size returned a nil pointer" ); + + pfd = uta_ring_getpfd( r ); // get pollable file descriptor + errors += fail_if_true( pfd < 0, "pollable file descriptor returned was bad" ); + + pfd = uta_ring_config( r, 0x03 ); // turn on locking for reads and writes + errors += fail_if_true( pfd != 1, "attempt to enable locking failed" ); for( i = 0; i < 20; i++ ) { // test to ensure it reports full when head/tail start at 0 data[i] = i; @@ -102,63 +99,41 @@ static int ring_test( ) { } } - if( i > size ) { - fprintf( stderr, " didn not report table full: i=%d\n", i ); - return 1; - } - - fprintf( stderr, " reported table full at i=%d as expected\n", i ); - + errors += fail_if_true( i > size, "ring insert did not report full table" ); for( i = 0; i < size + 3; i++ ) { // ensure they all come back in order, and we don't get 'extras' if( (dp = uta_ring_extract( r )) == NULL ) { - if( i < size-1 ) { - fprintf( stderr, " nil pointer at i=%d\n", i ); - return 1; - } else { - break; - } - } + errors += fail_if_true( i < size-1, "nil pointer on extract from full table" ); + break; + } - if( *dp != i ) { + if( fail_if_true( *dp != i, "extracted data is incorrect; see details below" )) { fprintf( stderr, " data at i=% isnt right; expected %d got %d\n", i, i, *dp ); + errors++; } } - if( i > size ) { - fprintf( stderr, " got too many values on extract: %d\n", i ); - return 1; - } - fprintf( stderr, " extracted values were sane, got: %d\n", i-1 ); - + fail_if_true( i > size, "got too many values from extract loop" ); + uta_ring_free( NULL ); // ensure this doesn't blow up uta_ring_free( r ); for( i = 2; i < 15; i++ ) { r = uta_mk_ring( 16 ); - if( ie_test( r, i, 101 ) != 0 ) { // modest number of inserts - fprintf( stderr, " ie test for 101 inserts didn't return 0\n" ); - return 1; - } + errors += fail_not_equal( ie_test( r, i, 101 ), 0, "ie test for 101 inserts didn't return 0" ); uta_ring_free( r ); } - fprintf( stderr, " all modest insert/exctract tests pass\n" ); size = 5; for( j = 0; j < 20; j++ ) { for( i = 2; i < size - 2; i++ ) { r = uta_mk_ring( size ); - if( ie_test( r, i, 66000 ) != 0 ) { // should force the 16bit head/tail indexes to roll over - fprintf( stderr, " ie test for 66K inserts didn't return 0\n" ); - return 1; - } - + errors += fail_not_equal( ie_test( r, i, 66000 ), 0, "ie test for 66K inserts didn't return 0" ); + uta_ring_free( r ); } - fprintf( stderr, " all large insert/exctract tests pass ring size=%d\n", size ); size++; } - fprintf( stderr, " all ring tests pass\n" ); - return 0; + return errors; }