1 // : vi ts=4 sw=4 noet :
3 ==================================================================================
4 Copyright (c) 2019-2020 Nokia
5 Copyright (c) 2018-2020 AT&T Intellectual Property.
7 Licensed under the Apache License, Version 2.0 (the "License");
8 you may not use this file except in compliance with the License.
9 You may obtain a copy of the License at
11 http://www.apache.org/licenses/LICENSE-2.0
13 Unless required by applicable law or agreed to in writing, software
14 distributed under the License is distributed on an "AS IS" BASIS,
15 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 See the License for the specific language governing permissions and
17 limitations under the License.
18 ==================================================================================
22 Mmemonic: rmr_si_api_static_test.c
23 Abstract: Specific tests related to the API functions in rmr_si.c.
24 This should be included by a driver which invokes the 'main'
25 test function here: rmr_api_test.
27 This test set applies only to the outward facting API functions
28 in the rmr_si.c module (mostly because the context for SI is
31 The message buffer specific API tests are in a different static
32 module. API functions tested here are:
48 Author: E. Scott Daniels
49 Date: 14 April 2020 (AKD)
62 #include <semaphore.h>
65 #include "rmr_agnostic.h"
67 static int rmr_rcv_test( ) {
69 void* rmc; // route manager context
70 void* rmc2; // second context for non-listener init
71 rmr_mbuf_t* msg; // message buffers
73 int v = 0; // some value
77 int max_tries; // prevent a sticking in any loop
79 v = rmr_ready( NULL );
80 errors += fail_if( v != 0, "rmr_ready returned true before initialisation " );
82 em_set_long_hostname( 1 );
83 if( (rmc = rmr_init( "4560", 1024, FL_NOTHREAD )) == NULL ) {
84 fail_if_nil( rmc, "rmr_init returned a nil pointer " );
88 msg = rmr_alloc_msg( NULL, 1024 ); // should return nil pointer
89 errors += fail_not_nil( msg, "rmr_alloc_msg didn't return nil when given nil context " );
90 gen_rt( rmc ); // gen dummy route table
92 if( ! rmr_ready( rmc ) ) {
93 fprintf( stderr, "\nPANIC! rmr isn't showing ready after loading a rt table\n\n" );
97 msg = rmr_alloc_msg( rmc, 2048 ); // get a buffer with a transport header
103 snprintf( msg->payload, 500, "Stand up and cheer from OU to Oh yea! (5)" );
105 msg = rmr_send_msg( rmc, msg );
106 errors += fail_if_nil( msg, "send_msg_ did not return a message on send " );
108 errors += fail_not_equal( msg->state, RMR_OK, "send_msg returned bad status for send that should work " );
109 errors += fail_if( errno != 0, "send_msg set errno for send that should work " );
110 v = rmr_payload_size( msg );
111 errors += fail_if( v != 2048, "send_msg did not allocate new buffer with correct size " );
112 errors += fail_if( msg->tp_state == 999, "send_msg did not set tp_state (2)" );
115 rmr_set_stimeout( NULL, 0 ); // not supported, but funciton exists, so drive away
116 rmr_set_stimeout( rmc, 20 );
117 rmr_set_stimeout( rmc, -1 );
118 rmr_set_rtimeout( NULL, 0 );
119 rmr_set_rtimeout( rmc, 20 );
120 rmr_set_rtimeout( rmc, -1 );
122 max_tries = 10; // there shouldn't be more than 10 queued at this point
123 while( (msg2 = rmr_torcv_msg( rmc, msg2, 200 )) != NULL ) {
124 if( msg2->state != RMR_OK || max_tries <= 0 ) {
131 msg2 = rmr_rcv_msg( NULL, NULL );
132 errors += fail_if( msg2 != NULL, "rmr_rcv_msg returned msg when given nil context and msg " );
134 send_n_msgs( rmc, 1 ); // ensure there is a message to read
135 msg2 = rmr_rcv_msg( rmc, NULL );
136 errors += fail_if( msg2 == NULL, "rmr_rcv_msg returned nil msg when given nil msg " );
138 if( msg2->state != RMR_ERR_EMPTY ) {
139 errors += fail_not_equal( msg2->state, RMR_OK, "receive given nil message did not return msg with good state (not empty) " );
143 send_n_msgs( rmc, 1 ); // ensure there is a message to read (len is set to 100)
144 msg = rmr_rcv_msg( rmc, msg );
146 errors += fail_not_equal( msg->state, RMR_OK, "rmr_rcv_msg did not return an ok state " );
147 errors += fail_not_equal( msg->len, 100, "rmr_rcv_msg returned message with invalid len " );
149 errors += fail_if_nil( msg, "rmr_rcv_msg returned a nil pointer " );
152 rmr_rts_msg( NULL, NULL ); // drive for coverage
153 rmr_rts_msg( rmc, NULL );
154 errors += fail_if( errno == 0, "rmr_rts_msg did not set errno when given a nil message " );
157 msg = rmr_rts_msg( NULL, msg ); // should set state in msg
159 errors += fail_if_equal( msg->state, 0, "rmr_rts_msg did not set state when given valid message but no context " );
161 errors += fail_if_nil( msg, "rmr_rts_msg returned a nil msg when given a good one" );
164 msg = rmr_rts_msg( rmc, msg ); // return the buffer to the sender
165 errors += fail_if_nil( msg, "rmr_rts_msg did not return a message pointer " );
166 errors += fail_not_equal( msg->state, 0, "rts_msg did not return a good state (a) when expected" );
167 errors += fail_not_equal( errno, 0, "rmr_rts_msg did not reset errno (a) expected (b)" );
170 msg = rmr_call( NULL, msg );
171 errors += fail_if( msg->state == 0, "rmr_call did not set message state when given message with nil context " );
173 em_set_rcvcount( 0 ); // reset message counter
174 em_set_rcvdelay( 1 ); // force slow msg rate during mt testing
175 em_disable_call_flg(); // cause reflected message to appear to be a response
177 snprintf( msg->xaction, 17, "%015d", 16 );
181 msg = rmr_call( rmc, msg );
182 errors += fail_if_nil( msg, "rmr_call returned a nil message on call expected to succeed " );
184 errors += fail_not_equal( msg->state, RMR_OK, "rmr_call did not properly set state on successful return " );
185 errors += fail_not_equal( errno, 0, "rmr_call did not properly set errno (a) on successful return " );
189 msg = rmr_alloc_msg( rmc, 2048 ); // something buggered above; get a new one
192 em_allow_call_flg(); // cause reflected message to appear to be a call
193 snprintf( msg->xaction, 17, "%015d", 16 ); // ensure there is an xaction id
197 msg = rmr_call( rmc, msg ); // make a call that we never expect a response on (nil pointer back)
198 errors += fail_not_nil( msg, "rmr_call returned message on call expected not to receive a response " );
199 errors += fail_if( errno == 0, "rmr_call did not set errno on failure " );
201 rmr_free_msg( NULL ); // drive for coverage; nothing to check
202 rmr_free_msg( msg2 );
204 msg2 = rmr_torcv_msg( NULL, NULL, 10 );
205 errors += fail_not_nil( msg2, "rmr_torcv_msg returned a pointer when given nil information " );
206 msg2 = rmr_torcv_msg( rmc, NULL, 10 );
207 errors += fail_if_nil( msg2, "rmr_torcv_msg did not return a message pointer when given a nil old msg " );
209 // --- test timeout receive; our dummy epoll function will return 1 ready on first call and 0 ready (timeout emulation) on second
210 // however we must drain the swamp (queue) first, so run until we get a timeout error, or 20 and report error if we get to 20.
212 for( i = 0; i < 40; i++ ) {
213 msg = rmr_torcv_msg( rmc, msg, 10 );
214 errors += fail_if_nil( msg, "torcv_msg returned nil msg when message expected " );
216 if( msg->state == RMR_ERR_TIMEOUT || msg->state == RMR_ERR_EMPTY ) { // queue drained and we've seen both states from poll if we get a timeout
221 errors += fail_if( i >= 40, "torcv_msg never returned a timeout " );
223 ((uta_ctx_t *)rmc)->shutdown = 1;
224 rmr_close( NULL ); // drive for coverage
225 rmr_close( rmc ); // no return to check; drive for coverage
228 // --------------- phew, done ------------------------------------------------------------------------------
231 fprintf( stderr, "<INFO> all RMR receive tests pass\n" );
233 fprintf( stderr, "<INFO> receive tests failures noticed \n" );