399ff781a660a4d8a6f6e4121699cce6035880d4
[ric-plt/lib/rmr.git] / test / si95_test.c
1 // :vi sw=4 ts=4 noet:
2 /*
3 ==================================================================================
4         Copyright (c) 2020 Nokia
5         Copyright (c) 2020 AT&T Intellectual Property.
6
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
10
11            http://www.apache.org/licenses/LICENSE-2.0
12
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 ==================================================================================
19 */
20
21 /*
22         Mmemonic:       si95_test.c
23         Abstract:       This is the main driver to test the si95 core functions
24                                 (within rmr/src/si/src/si95). 
25
26         Author:         E. Scott Daniels
27         Date:           6 March 2018
28 */
29
30 #include <stdio.h>
31 #include <stdlib.h>
32 #include <netdb.h>
33 #include <errno.h>
34 #include <string.h>
35 #include <errno.h>
36 #include <pthread.h>
37 #include <ctype.h>
38
39
40 #include <unistd.h>
41 #include <stdio.h>
42 #include <stdlib.h>
43 #include <strings.h>
44 #include <errno.h>
45 #include <string.h>
46 #include <stdint.h>
47 #include <ctype.h>
48 #include <sys/epoll.h>
49 #include <pthread.h>
50 #include <semaphore.h>
51
52 #define DEBUG 1
53
54                                                                                         // specific test tools in this directory
55 #undef NNG_UNDER_TEST                                           // NNG is NOT under test so undefine if set
56 #define NO_EMULATION 1                                          // no emulation of transport functions
57 #define NO_PRIVATE_HEADERS 1                            // no rmr_si or rmr_nng headers
58 #define NO_DUMMY_RMR 1                                          // no msg things
59 #include "test_support.c"                                       // things like fail_if()
60
61
62 /*
63 #include "rmr.h"                                        // things the users see
64 #include "rmr_symtab.h"
65 #include "rmr_agnostic.h"                       // transport agnostic header
66 */
67 #include <rmr_logging.h>
68 #include <logging.c>
69
70 //#include <si95/siaddress.c>
71 //#include <si95/sialloc.c>
72 //#include <si95/sibldpoll.c>
73 //#include <si95/sicbreg.c>
74 //#include <si95/sicbstat.c>
75 //#include <si95/siclose.c>
76 //#include <si95/siconnect.c>
77 //#include <si95/siestablish.c>
78 //#include <si95/sigetadd.c>
79 //#include <si95/sigetname.c>
80 #include <si95/siinit.c>
81 //#include <si95/silisten.c>
82 #include <si95/sinew.c>
83 //#include <si95/sinewses.c>
84 //#include <si95/sipoll.c>
85 //#include <si95/sircv.c>
86 //#include <si95/sisend.c>
87 //#include <si95/sisendt.c>
88 #include <si95/sishutdown.c>
89 #include <si95/siterm.c>
90 #include <si95/sitrash.c>
91 //#include <si95/siwait.c>
92
93
94 /*
95         Memory allocation/free related tests
96 */
97 static int memory( ) {
98         int             errors = 0;
99         void*   ptr;
100         void*   iptr;
101
102         // ---- SInew ----------------
103         ptr = SInew( 100 );                             // invalid block type should return nil
104         errors += fail_not_nil( ptr, "memory: sinew did not return nil when given a valid struct type" );
105         SItrash( 100, NULL );                           // drive trash for coverage
106
107         iptr = SInew( IOQ_BLK );
108         errors += fail_if_nil( iptr, "memory: sinew returned nil when given ioq request" );
109         iptr = SInew( IOQ_BLK );
110         SItrash(  IOQ_BLK, iptr );
111
112         ptr = SInew( TP_BLK );
113         errors += fail_if_nil( ptr, "memory: sinew returned nil when given tpblk request" );
114         if( ptr ) {
115                 ((struct tp_blk *)ptr)->squeue = iptr;
116                 SItrash(  TP_BLK, ptr );
117         }
118         
119         ptr = SInew( GI_BLK );
120         errors += fail_if_nil( ptr, "memory: sinew returned nil when given giblk request" );
121         SItrash(  GI_BLK, ptr );
122
123
124         return errors;
125 }
126
127 void*   si_ctx = NULL;                  // a global context might be useful
128
129 /*
130         Test initialisation related things
131 */
132 static int init() {
133         int             errors = 0;
134
135         si_ctx = SIinitialise( 0 );
136         errors += fail_if_nil( si_ctx, "init: siinit returned a nil pointer" );
137
138         SIclr_tflags( si_ctx, 0x00 );           // drive for coverage; no return value from these
139         SIset_tflags( si_ctx, 0x03 );
140
141         return errors;
142 }
143
144 /*
145         Drive tests...
146 */
147 int main() {
148         int errors = 0;
149
150         rmr_set_vlevel( 5 );                    // enable all debugging
151
152         fprintf( stderr, "\n<INFO> starting SI95 tests\n" );
153
154         errors += init();
155         errors += memory();
156
157         if( errors == 0 ) {
158                 fprintf( stderr, "<PASS> all tests were OK\n\n" );
159         } else {
160                 fprintf( stderr, "<FAIL> %d errors in SI95 core code\n\n", errors );
161         }
162
163         return !!errors;
164 }