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
65 #include "test_support.c" // things like fail_if()
69 #include "rmr.h" // things the users see
70 #include "rmr_symtab.h"
71 #include "rmr_agnostic.h" // transport agnostic header
73 #include <rmr_logging.h>
76 #include <si95/siaddress.c>
77 //#include <si95/sialloc.c>
78 //#include <si95/sibldpoll.c>
79 //#include <si95/sicbreg.c>
80 //#include <si95/sicbstat.c>
81 //#include <si95/siclose.c>
82 #include <si95/siconnect.c>
83 #include <si95/siestablish.c>
84 //#include <si95/sigetadd.c>
85 //#include <si95/sigetname.c>
86 #include <si95/siinit.c>
87 //#include <si95/silisten.c>
88 #include <si95/sinew.c>
89 //#include <si95/sinewses.c>
90 //#include <si95/sipoll.c>
91 //#include <si95/sircv.c>
92 //#include <si95/sisend.c>
93 //#include <si95/sisendt.c>
94 #include <si95/sishutdown.c>
95 #include <si95/siterm.c>
96 #include <si95/sitrash.c>
97 //#include <si95/siwait.c>
99 // ---------------------------------------------------------------------
101 void* si_ctx = NULL; // a global context might be useful
103 // ---------------------------------------------------------------------
106 Memory allocation/free related tests
108 static int memory( ) {
113 // ---- SInew ----------------
114 ptr = SInew( 100 ); // invalid block type should return nil
115 errors += fail_not_nil( ptr, "memory: sinew did not return nil when given a valid struct type" );
116 SItrash( 100, NULL ); // drive trash for coverage
118 iptr = SInew( IOQ_BLK );
119 errors += fail_if_nil( iptr, "memory: sinew returned nil when given ioq request" );
120 SItrash( IOQ_BLK, iptr );
122 ptr = SInew( TP_BLK );
123 errors += fail_if_nil( ptr, "memory: sinew returned nil when given tpblk request" );
125 iptr = SInew( IOQ_BLK );
126 ((struct tp_blk *)ptr)->squeue = iptr;
127 SItrash( TP_BLK, ptr );
130 ptr = SInew( GI_BLK );
131 errors += fail_if_nil( ptr, "memory: sinew returned nil when given giblk request" );
132 SItrash( GI_BLK, ptr ); // GI block cannot be trashed, ensure this (valgind will complain about a leak)
140 Test initialisation related things
145 si_ctx = SIinitialise( 0 );
146 errors += fail_if_nil( si_ctx, "init: siinit returned a nil pointer" );
148 SIclr_tflags( si_ctx, 0x00 ); // drive for coverage; no return value from these
149 SIset_tflags( si_ctx, 0x03 );
154 static int cleanup() {
161 SIconnect( si_ctx, "localhost:43086" ); // ensure context has a tp block to free on shutdown
162 SIshutdown( si_ctx );
168 Address related tests.
173 struct sockaddr* addr;
178 addr = (struct sockaddr *) malloc( sizeof( struct sockaddr ) );
180 l = SIgenaddr( " [ff02::4]:4567", PF_INET6, IPPROTO_TCP, SOCK_STREAM, &addr );
182 SIgenaddr( " [ff02::4]:4567", PF_INET6, IPPROTO_TCP, SOCK_STREAM, &addr );
186 snprintf( buf1, sizeof( buf1 ), " [ff02::5:4001" ); // invalid address, drive leading space eater too
187 l = SIaddress( buf1, &dest, AC_TOADDR6 );
188 errors += fail_if_true( l > 0, "to addr6 with bad addr convdersion returned valid len" );
190 snprintf( buf1, sizeof( buf1 ), "[ff02::5]:4002" ); // v6 might not be supported so failure is OK here
191 l=SIaddress( buf1, &dest, AC_TOADDR6 );
192 errors += fail_if_true( l < 1, "to addr convdersion failed" );
194 snprintf( buf1, sizeof( buf1 ), "localhost:43086" );
195 l = SIaddress( buf1, (void **) &dest, AC_TOADDR );
196 errors += fail_if_true( l < 1, "to addr convdersion failed" );
198 snprintf( buf1, sizeof( buf1 ), "localhost:4004" );
199 l = SIaddress( buf1, &dest, AC_TODOT );
200 errors += fail_if_true( l < 1, "to dot convdersion failed" );
212 rmr_set_vlevel( 5 ); // enable all debugging
214 fprintf( stderr, "\n<INFO> starting SI95 tests\n" );
219 fprintf( stderr, ">>> cleaning\n" );
222 fprintf( stderr, "<INFO> testing finished\n" );
224 fprintf( stderr, "<PASS> all tests were OK\n\n" );
226 fprintf( stderr, "<FAIL> %d errors in SI95 core code\n\n", errors );