Add transport provider status to message buffer
[ric-plt/lib/rmr.git] / test / rmr_nng_test.c
1 // :vi sw=4 ts=4 noet:
2 /*
3 ==================================================================================
4         Copyright (c) 2019 Nokia
5         Copyright (c) 2018-2019 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:       rmr_nng_test.c
23         Abstract:       This tests the whole rmr nng implementation. This driver
24                                 includes all of the module specific unit test static files
25                                 (e.g. wormhole_static_test.c) and drives the tests contained
26                                 there.   The individual modules allow them to be driven by
27                                 a standalone driver, and to be maintained separately. We must
28                                 test by inclusion because of the static nature of the internal
29                                 functions of the library.
30
31         Author:         E. Scott Daniels
32         Date:           18 January 2018         (IMO HRTL)
33 */
34
35 #include <stdio.h>
36 #include <stdlib.h>
37 #include <netdb.h>
38 #include <errno.h>
39 #include <string.h>
40 #include <errno.h>
41 #include <pthread.h>
42 #include <ctype.h>
43
44
45 #include <unistd.h>
46 #include <stdio.h>
47 #include <stdlib.h>
48 #include <strings.h>
49 #include <errno.h>
50 #include <string.h>
51 #include <stdint.h>
52 #include <ctype.h>
53 #include <sys/epoll.h>
54 #include <pthread.h>
55 #include <semaphore.h>
56
57 #define DEBUG 1
58
59 #include <nng/nng.h>
60 #include <nng/protocol/pubsub0/pub.h>
61 #include <nng/protocol/pubsub0/sub.h>
62 #include <nng/protocol/pipeline0/push.h>
63 #include <nng/protocol/pipeline0/pull.h>
64
65 #define EMULATE_NNG
66 #include "test_nng_em.c"                                                        // nng/nn emulation (before including things under test)
67
68
69 #include "rmr.h"                                        // things the users see
70 #include "rmr_symtab.h"
71 #include "rmr_agnostic.h"                       // transport agnostic header
72 #include "rmr_nng_private.h"                    // transport specific
73
74 #include "symtab.c"
75 #include "rmr_nng.c"
76 #include "mbuf_api.c"
77
78 static void gen_rt( uta_ctx_t* ctx );           // defined in sr_nng_static_test, but used by a few others (eliminate order requirement below)
79
80                                                                                         // specific test tools in this directory
81 #include "test_support.c"                                       // things like fail_if()
82                                                                                         // and finally....
83 #include "tools_static_test.c"                          // local test functions pulled directly because of static nature of things
84 #include "symtab_static_test.c"
85 #include "ring_static_test.c"
86 #include "rt_static_test.c"
87 #include "sr_nng_static_test.c"
88 #include "wormhole_static_test.c"
89 #include "rmr_nng_api_static_test.c"
90 #include "mbuf_api_static_test.c"
91
92
93 /*
94         Drive each of the separate tests and report.
95 */
96 int main() {
97         int errors = 0;
98
99         fprintf( stderr, "<INFO> starting tool tests\n" );
100         errors += tools_test();
101         fprintf( stderr, "<INFO> error count: %d\n", errors );
102
103         fprintf( stderr, "<INFO> starting ring tests (%d)\n", errors );
104         errors += ring_test();
105         fprintf( stderr, "<INFO> error count: %d\n", errors );
106
107         fprintf( stderr, "<INFO> starting symtab tests\n" );
108         errors += symtab_test( );
109         fprintf( stderr, "<INFO> error count: %d\n", errors );
110
111         fprintf( stderr, "<INFO> starting rtable tests\n" );
112         errors += rt_test();                            // route table tests
113         fprintf( stderr, "<INFO> error count: %d\n", errors );
114
115         fprintf( stderr, "<INFO> starting RMr API tests\n" );
116         errors += rmr_api_test();
117
118         fprintf( stderr, "<INFO> run RMr API tests with src name only env var set\n" );
119         setenv( "RMR_SRC_NAMEONLY", "1", 1 );
120         errors += rmr_api_test();
121         fprintf( stderr, "<INFO> error count: %d\n", errors );
122
123         fprintf( stderr, "<INFO> starting wormhole tests\n" );
124         errors += worm_test();                          // test wormhole funcitons
125         fprintf( stderr, "<INFO> error count: %d\n", errors );
126
127         fprintf( stderr, "<INFO> starting send/receive tests\n" );
128         errors += sr_nng_test();                                // test the send/receive static functions
129         fprintf( stderr, "<INFO> error count: %d\n", errors );
130
131         fprintf( stderr, "<INFO> starting mbuf api tests\n" );
132         errors +=  mbuf_api_test( );
133         fprintf( stderr, "<INFO> error count: %d\n", errors );
134
135         if( errors == 0 ) {
136                 fprintf( stderr, "<PASS> all tests were OK\n" );
137         } else {
138                 fprintf( stderr, "<FAIL> %d modules reported errors\n", errors );
139         }
140
141         return !!errors;
142 }