E. Scott Daniels | 8dd4641 | 2019-04-16 20:47:54 +0000 | [diff] [blame] | 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 | |
E. Scott Daniels | 8790bf0 | 2019-04-23 12:59:28 +0000 | [diff] [blame] | 11 | http://www.apache.org/licenses/LICENSE-2.0 |
E. Scott Daniels | 8dd4641 | 2019-04-16 20:47:54 +0000 | [diff] [blame] | 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> |
E. Scott Daniels | 412d53d | 2019-05-20 20:00:52 +0000 | [diff] [blame] | 54 | #include <pthread.h> |
| 55 | #include <semaphore.h> |
E. Scott Daniels | 8dd4641 | 2019-04-16 20:47:54 +0000 | [diff] [blame] | 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 | |
E. Scott Daniels | 412d53d | 2019-05-20 20:00:52 +0000 | [diff] [blame] | 69 | #include "rmr.h" // things the users see |
| 70 | #include "rmr_symtab.h" |
E. Scott Daniels | 0d4def6 | 2020-01-28 16:50:27 -0500 | [diff] [blame] | 71 | #include "rmr_logging.h" |
E. Scott Daniels | 412d53d | 2019-05-20 20:00:52 +0000 | [diff] [blame] | 72 | #include "rmr_agnostic.h" // transport agnostic header |
| 73 | #include "rmr_nng_private.h" // transport specific |
E. Scott Daniels | 8dd4641 | 2019-04-16 20:47:54 +0000 | [diff] [blame] | 74 | |
E. Scott Daniels | 412d53d | 2019-05-20 20:00:52 +0000 | [diff] [blame] | 75 | #include "symtab.c" |
E. Scott Daniels | 0d4def6 | 2020-01-28 16:50:27 -0500 | [diff] [blame] | 76 | #include "logging.c" |
E. Scott Daniels | 412d53d | 2019-05-20 20:00:52 +0000 | [diff] [blame] | 77 | #include "rmr_nng.c" |
| 78 | #include "mbuf_api.c" |
E. Scott Daniels | 8dd4641 | 2019-04-16 20:47:54 +0000 | [diff] [blame] | 79 | |
| 80 | static void gen_rt( uta_ctx_t* ctx ); // defined in sr_nng_static_test, but used by a few others (eliminate order requirement below) |
| 81 | |
| 82 | // specific test tools in this directory |
| 83 | #include "test_support.c" // things like fail_if() |
E. Scott Daniels | 0b79fc2 | 2019-12-04 15:20:16 -0500 | [diff] [blame] | 84 | #include "test_gen_rt.c" |
E. Scott Daniels | 8dd4641 | 2019-04-16 20:47:54 +0000 | [diff] [blame] | 85 | // and finally.... |
| 86 | #include "tools_static_test.c" // local test functions pulled directly because of static nature of things |
| 87 | #include "symtab_static_test.c" |
| 88 | #include "ring_static_test.c" |
| 89 | #include "rt_static_test.c" |
| 90 | #include "sr_nng_static_test.c" |
| 91 | #include "wormhole_static_test.c" |
| 92 | #include "rmr_nng_api_static_test.c" |
E. Scott Daniels | d710957 | 2019-04-18 14:01:16 +0000 | [diff] [blame] | 93 | #include "mbuf_api_static_test.c" |
E. Scott Daniels | 8dd4641 | 2019-04-16 20:47:54 +0000 | [diff] [blame] | 94 | |
| 95 | |
| 96 | /* |
| 97 | Drive each of the separate tests and report. |
| 98 | */ |
| 99 | int main() { |
| 100 | int errors = 0; |
| 101 | |
E. Scott Daniels | 6511ac7 | 2019-08-27 10:17:21 -0400 | [diff] [blame] | 102 | fprintf( stderr, "\n<INFO> starting tool tests\n" ); |
E. Scott Daniels | 8dd4641 | 2019-04-16 20:47:54 +0000 | [diff] [blame] | 103 | errors += tools_test(); |
| 104 | fprintf( stderr, "<INFO> error count: %d\n", errors ); |
| 105 | |
E. Scott Daniels | 6511ac7 | 2019-08-27 10:17:21 -0400 | [diff] [blame] | 106 | fprintf( stderr, "\n<INFO> starting ring tests (%d)\n", errors ); |
E. Scott Daniels | 8dd4641 | 2019-04-16 20:47:54 +0000 | [diff] [blame] | 107 | errors += ring_test(); |
| 108 | fprintf( stderr, "<INFO> error count: %d\n", errors ); |
| 109 | |
E. Scott Daniels | 6511ac7 | 2019-08-27 10:17:21 -0400 | [diff] [blame] | 110 | fprintf( stderr, "\n<INFO> starting symtab tests\n" ); |
E. Scott Daniels | 8dd4641 | 2019-04-16 20:47:54 +0000 | [diff] [blame] | 111 | errors += symtab_test( ); |
| 112 | fprintf( stderr, "<INFO> error count: %d\n", errors ); |
| 113 | |
E. Scott Daniels | 6511ac7 | 2019-08-27 10:17:21 -0400 | [diff] [blame] | 114 | fprintf( stderr, "\n<INFO> starting rtable tests\n" ); |
E. Scott Daniels | 8dd4641 | 2019-04-16 20:47:54 +0000 | [diff] [blame] | 115 | errors += rt_test(); // route table tests |
| 116 | fprintf( stderr, "<INFO> error count: %d\n", errors ); |
| 117 | |
E. Scott Daniels | 6511ac7 | 2019-08-27 10:17:21 -0400 | [diff] [blame] | 118 | fprintf( stderr, "\n<INFO> starting RMr API tests\n" ); |
E. Scott Daniels | 8dd4641 | 2019-04-16 20:47:54 +0000 | [diff] [blame] | 119 | errors += rmr_api_test(); |
E. Scott Daniels | 68d09fa | 2019-06-03 19:45:12 +0000 | [diff] [blame] | 120 | |
E. Scott Daniels | 6511ac7 | 2019-08-27 10:17:21 -0400 | [diff] [blame] | 121 | fprintf( stderr, "\n<INFO> run RMr API tests with src name only env var set\n" ); |
E. Scott Daniels | 68d09fa | 2019-06-03 19:45:12 +0000 | [diff] [blame] | 122 | setenv( "RMR_SRC_NAMEONLY", "1", 1 ); |
| 123 | errors += rmr_api_test(); |
E. Scott Daniels | 8dd4641 | 2019-04-16 20:47:54 +0000 | [diff] [blame] | 124 | fprintf( stderr, "<INFO> error count: %d\n", errors ); |
| 125 | |
E. Scott Daniels | 6511ac7 | 2019-08-27 10:17:21 -0400 | [diff] [blame] | 126 | fprintf( stderr, "\n<INFO> starting wormhole tests\n" ); |
E. Scott Daniels | 8dd4641 | 2019-04-16 20:47:54 +0000 | [diff] [blame] | 127 | errors += worm_test(); // test wormhole funcitons |
| 128 | fprintf( stderr, "<INFO> error count: %d\n", errors ); |
| 129 | |
E. Scott Daniels | 6511ac7 | 2019-08-27 10:17:21 -0400 | [diff] [blame] | 130 | fprintf( stderr, "\n<INFO> starting send/receive tests\n" ); |
E. Scott Daniels | 8dd4641 | 2019-04-16 20:47:54 +0000 | [diff] [blame] | 131 | errors += sr_nng_test(); // test the send/receive static functions |
| 132 | fprintf( stderr, "<INFO> error count: %d\n", errors ); |
| 133 | |
E. Scott Daniels | 6511ac7 | 2019-08-27 10:17:21 -0400 | [diff] [blame] | 134 | fprintf( stderr, "\n<INFO> starting mbuf api tests\n" ); |
E. Scott Daniels | d710957 | 2019-04-18 14:01:16 +0000 | [diff] [blame] | 135 | errors += mbuf_api_test( ); |
| 136 | fprintf( stderr, "<INFO> error count: %d\n", errors ); |
| 137 | |
E. Scott Daniels | 8dd4641 | 2019-04-16 20:47:54 +0000 | [diff] [blame] | 138 | if( errors == 0 ) { |
E. Scott Daniels | 6511ac7 | 2019-08-27 10:17:21 -0400 | [diff] [blame] | 139 | fprintf( stderr, "<PASS> all tests were OK\n\n" ); |
E. Scott Daniels | 8dd4641 | 2019-04-16 20:47:54 +0000 | [diff] [blame] | 140 | } else { |
E. Scott Daniels | 6511ac7 | 2019-08-27 10:17:21 -0400 | [diff] [blame] | 141 | fprintf( stderr, "<FAIL> %d modules reported errors\n\n", errors ); |
E. Scott Daniels | 8dd4641 | 2019-04-16 20:47:54 +0000 | [diff] [blame] | 142 | } |
| 143 | |
| 144 | return !!errors; |
| 145 | } |