3 ==================================================================================
4 Copyright (c) 2020 Nokia
5 Copyright (c) 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 ==================================================================================
23 Abstract: This is the main driver to test the si95 core functions
24 (within rmr/src/si/src/si95).
26 Author: E. Scott Daniels
39 #include <netdb.h> // these four needed for si address tests
42 #include <netinet/in.h>
54 #include <sys/epoll.h>
56 #include <semaphore.h>
60 // specific test tools in this directory
61 #undef NNG_UNDER_TEST // NNG is NOT under test so undefine if set
62 #define NO_EMULATION 1 // no emulation of transport functions
63 #define NO_PRIVATE_HEADERS 1 // no rmr_si or rmr_nng headers
64 #define NO_DUMMY_RMR 1 // no msg things
66 #include "test_support.c" // things like fail_if()
67 #include "test_transport_em.c" // system/transport emulation (open, close, connect, etc)
70 #include "rmr.h" // things the users see
71 #include "rmr_symtab.h"
72 #include "rmr_agnostic.h" // transport agnostic header
74 #include <rmr_logging.h>
77 #include <si95/siaddress.c>
78 //#include <si95/sialloc.c>
79 //#include <si95/sibldpoll.c>
80 //#include <si95/sicbreg.c>
81 //#include <si95/sicbstat.c>
82 //#include <si95/siclose.c>
83 #include <si95/siconnect.c>
84 #include <si95/siestablish.c>
85 //#include <si95/sigetadd.c>
86 //#include <si95/sigetname.c>
87 #include <si95/siinit.c>
88 #include <si95/silisten.c>
89 #include <si95/sinew.c>
90 //#include <si95/sinewses.c>
91 //#include <si95/sipoll.c>
92 //#include <si95/sircv.c>
93 //#include <si95/sisend.c>
94 //#include <si95/sisendt.c>
95 #include <si95/sishutdown.c>
96 #include <si95/siterm.c>
97 #include <si95/sitrash.c>
98 //#include <si95/siwait.c>
100 // ---------------------------------------------------------------------
102 void* si_ctx = NULL; // a global context might be useful
104 // ---------------------------------------------------------------------
107 Memory allocation/free related tests
109 static int memory( ) {
114 // ---- SInew ----------------
115 ptr = SInew( 100 ); // invalid block type should return nil
116 errors += fail_not_nil( ptr, "memory: sinew did not return nil when given a valid struct type" );
117 SItrash( 100, NULL ); // drive trash for coverage
119 iptr = SInew( IOQ_BLK );
120 errors += fail_if_nil( iptr, "memory: sinew returned nil when given ioq request" );
121 SItrash( IOQ_BLK, iptr );
123 ptr = SInew( TP_BLK );
124 errors += fail_if_nil( ptr, "memory: sinew returned nil when given tpblk request" );
126 iptr = SInew( IOQ_BLK );
127 ((struct tp_blk *)ptr)->squeue = iptr;
128 SItrash( TP_BLK, ptr );
131 ptr = SInew( GI_BLK );
132 errors += fail_if_nil( ptr, "memory: sinew returned nil when given giblk request" );
133 SItrash( GI_BLK, ptr ); // GI block cannot be trashed, ensure this (valgind will complain about a leak)
141 Test initialisation related things
146 si_ctx = SIinitialise( 0 );
147 errors += fail_if_nil( si_ctx, "init: siinit returned a nil pointer" );
149 SIclr_tflags( si_ctx, 0x00 ); // drive for coverage; no return value from these
150 SIset_tflags( si_ctx, 0x03 );
152 fprintf( stderr, "<INFO> init module finished with %d errors\n", errors );
156 static int cleanup() {
163 SItp_stats( si_ctx ); // drive for coverage only
166 SIconnect( si_ctx, "localhost:43086" ); // ensure context has a tp block to free on shutdown
171 fprintf( stderr, "<INFO> cleanup module finished with %d errors\n", errors );
176 Address related tests.
181 struct sockaddr* addr;
186 addr = (struct sockaddr *) malloc( sizeof( struct sockaddr ) );
188 l = SIgenaddr( " [ff02::4]:4567", PF_INET6, IPPROTO_TCP, SOCK_STREAM, &addr );
190 SIgenaddr( " [ff02::4]:4567", PF_INET6, IPPROTO_TCP, SOCK_STREAM, &addr );
194 snprintf( buf1, sizeof( buf1 ), " [ff02::5:4001" ); // invalid address, drive leading space eater too
195 l = SIaddress( buf1, (void **) &dest, AC_TOADDR6 );
196 errors += fail_if_true( l > 0, "to addr6 with bad addr convdersion returned valid len" );
198 snprintf( buf1, sizeof( buf1 ), "[ff02::5]:4002" ); // v6 might not be supported so failure is OK here; driving for coverage
199 l=SIaddress( buf1, (void **) &dest, AC_TOADDR6 );
201 snprintf( buf1, sizeof( buf1 ), "localhost:43086" );
202 l = SIaddress( buf1, (void **) &dest, AC_TOADDR );
203 errors += fail_if_true( l < 1, "to addr convdersion failed" );
205 snprintf( buf1, sizeof( buf1 ), "localhost:4004" );
206 l = SIaddress( buf1, (void **) &dest, AC_TODOT );
207 errors += fail_if_true( l < 1, "to dot convdersion failed" );
209 fprintf( stderr, "<INFO> addr module finished with %d errors\n", errors );
216 Connection oriented tests.
222 state = SIconnect( si_ctx, "localhost:4567" ); // driver regular connect
223 errors += fail_if_true( state < 0, "connect to low port failed" );
225 state = SIconnect( si_ctx, "localhost:43086" ); // drive save connect with good return code
226 errors += fail_if_true( state < 0, "connect to high port failed" );
228 tpem_set_addr_dup_state( 1 ); // force get sockket name emulation to return a duplicate address
229 state = SIconnect( si_ctx, "localhost:43086" ); // drive save connect with good return code
230 errors += fail_if_true( state >= 0, "forced dup connect did not return error" );
232 tpem_set_addr_dup_state( 0 ); // force get sockket name emulation to return a duplicate address
233 tpem_set_conn_state( 1 );
234 state = SIconnect( si_ctx, "localhost:4567" ); // driver regular connect
235 errors += fail_if_true( state >= 0, "connect to low port successful when failure expected" );
237 tpem_set_sock_state( 1 ); // make scoket calls fail
238 state = SIconnect( si_ctx, "localhost:4567" ); // driver regular connect
239 errors += fail_if_true( state >= 0, "connect to low port successful when socket based failure expected" );
241 tpem_set_sock_state( 0 );
243 state = SIlistener( si_ctx, TCP_DEVICE, "0.0.0.0:4567" );
244 errors += fail_if_true( state < 0, "listen failed" );
246 tpem_set_bind_state( 1 );
247 state = SIlistener( si_ctx, TCP_DEVICE, "0.0.0.0:4567" );
248 errors += fail_if_true( state >= 0, "listen successful when bind error set" );
249 tpem_set_bind_state( 0 );
252 fprintf( stderr, "<INFO> conn module finished with %d errors\n", errors );
262 rmr_set_vlevel( 5 ); // enable all debugging
264 fprintf( stderr, "\n<INFO> starting SI95 tests\n" );
272 fprintf( stderr, "<INFO> testing finished\n" );
274 fprintf( stderr, "<PASS> all tests were OK\n\n" );
276 fprintf( stderr, "<FAIL> %d errors in SI95 core code\n\n", errors );