X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=blobdiff_plain;f=test%2Ftest_support.c;h=1e5e6572d62257084239d8434fd17c3f4b93dbf2;hb=8c6756d9d6f94beca0bc382f97383ca5e79d16c7;hp=9f8f00f9b0220ab9c353d69742a00a2fd676408b;hpb=e15b1382dc618f6832957e67dc638b5e8f3f414d;p=ric-plt%2Flib%2Frmr.git diff --git a/test/test_support.c b/test/test_support.c index 9f8f00f..1e5e657 100644 --- a/test/test_support.c +++ b/test/test_support.c @@ -69,6 +69,27 @@ #define GOOD 0 #endif +// ----------- a couple of globals make it easier --------------------------------------- +static int ts_tests_driven = 0; // number of fail_if calls made == numer of tests driven + +// --------------------------------------------------------------------------------------- + +/* + Support test counting, reset and summary. +*/ +static int test_get_attempted() { + return ts_tests_driven; +} + +static void test_reset_attempted() { + ts_tests_driven = 0; +} + +static void test_summary( int ecount, char* tag ) { + fprintf( stderr, " %s completed; %d total tests, %d passed, %d failed\n", + tag, ts_tests_driven, ts_tests_driven - ecount, ecount ); +} + /* Snag the optional positional parameter at pp, return defval if not there. */ @@ -111,7 +132,13 @@ static void set_signals( void ) { } +/* + Assert like logic except these just record the test and return state so that we + can attempt all tests and not abort on the first failure as an assert would do. +*/ static int fail_if_nil( void* p, char* what ) { + ts_tests_driven++; + if( !p ) { fprintf( stderr, " %s: pointer was nil\n", what ); } @@ -119,6 +146,8 @@ static int fail_if_nil( void* p, char* what ) { } static int fail_not_nil( void* p, char* what ) { + ts_tests_driven++; + if( p ) { fprintf( stderr, " %s: pointer was not nil\n", what ); } @@ -126,6 +155,8 @@ static int fail_not_nil( void* p, char* what ) { } static int fail_if_false( int bv, char* what ) { + ts_tests_driven++; + if( !bv ) { fprintf( stderr, " %s: expected true, boolean test was false (%d)\n", what, bv ); } @@ -134,6 +165,8 @@ static int fail_if_false( int bv, char* what ) { } static int fail_if_true( int bv, char* what ) { + ts_tests_driven++; + if( bv ) { fprintf( stderr, " %s: expected false, boolean test was true (%d)\n", what, bv ); } @@ -144,6 +177,8 @@ static int fail_if_true( int bv, char* what ) { Same as fail_if_true(), but reads easier in the test code. */ static int fail_if( int bv, char* what ) { + ts_tests_driven++; + if( bv ) { fprintf( stderr, " %s: expected false, boolean test was true (%d)\n", what, bv ); @@ -151,7 +186,27 @@ static int fail_if( int bv, char* what ) { return bv ? BAD : GOOD; } +static int fail_pequal( void* a, void* b, char* what ) { + ts_tests_driven++; + + if( a == b ) { + fprintf( stderr, " %s: pointers were not equal a=%p b=%p\n", what, a, b ); + } + return a == b ? GOOD : BAD; // user may override good/bad so do NOT return a==b directly! +} + +static int fail_not_pequal( void* a, void* b, char* what ) { + ts_tests_driven++; + + if( a != b ) { + fprintf( stderr, " %s: pointers were not equal a=%p b=%p\n", what, a, b ); + } + return a == b ? GOOD : BAD; // user may override good/bad so do NOT return a==b directly! +} + static int fail_not_equal( int a, int b, char* what ) { + ts_tests_driven++; + if( a != b ) { fprintf( stderr, " %s: values were not equal a=%d b=%d\n", what, a, b ); } @@ -159,6 +214,8 @@ static int fail_not_equal( int a, int b, char* what ) { } static int fail_if_equal( int a, int b, char* what ) { + ts_tests_driven++; + if( a == b ) { fprintf( stderr, " %s values were equal a=%d b=%d\n", what, a, b ); } @@ -166,6 +223,8 @@ static int fail_if_equal( int a, int b, char* what ) { } static int fail_not_equalp( void* a, void* b, char* what ) { + ts_tests_driven++; + if( a != b ) { fprintf( stderr, " %s: pointers were not equal a=%p b=%p\n", what, a, b ); } @@ -173,6 +232,8 @@ static int fail_not_equalp( void* a, void* b, char* what ) { } static int fail_if_equalp( void* a, void* b, char* what ) { + ts_tests_driven++; + if( a == b ) { fprintf( stderr, " %s pointers were equal a=%p b=%p\n", what, a, b ); } @@ -197,6 +258,7 @@ static rmr_mbuf_t* test_mk_msg( int len, int tr_len ) { alen = sizeof( *hdr ) + tr_len + len + TP_HDR_LEN; // this does no support allocating len2 and len3 data fields new_msg = (rmr_mbuf_t *) malloc( sizeof *new_msg ); + memset( new_msg, 0, sizeof( *new_msg ) ); new_msg->tp_buf = (void *) malloc( alen ); memset( new_msg->tp_buf, 0, alen ); @@ -258,7 +320,7 @@ static void test_set_plen( rmr_mbuf_t* msg, int plen ) { /* Build a message and populate both the msg buffer and the tranport header - with mid, sid, and payload len. Tr_len causes that much space in the + with mid, sid, and payload len. Tr_len causes that much space in the header for trace info to be reserved. */ static rmr_mbuf_t* mk_populated_msg( int alloc_len, int tr_len, int mtype, int sid, int plen ) { @@ -274,6 +336,7 @@ static rmr_mbuf_t* mk_populated_msg( int alloc_len, int tr_len, int mtype, int s } +// end no dummy rmr #endif #endif