1 // : vi ts=4 sw=4 noet :
3 ==================================================================================
4 Copyright (c) 2021 Nokia
5 Copyright (c) 2021 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 ==================================================================================
22 Mmemonic: alarm_test.c
23 Abstract: Unit test for common/src/alarm.c functions.
25 Author: E. Scott Daniels
26 Date: 22 February 2021
39 #include <semaphore.h>
50 //#include <sys/epoll.h>
51 //#include <pthread.h>
52 //#include <semaphore.h>
54 #define DEBUG 1 // must define before pulling in rmr header files
55 #define PARANOID_CHECKS 1 // must have parinoid testing on to not fail on nil pointer tests
58 // specific test tools in this directory
60 #include "test_support.c" // things like fail_if()
61 #include "test_msg_support.c"
62 #include "test_gen_rt.c"
65 #include "rmr.h" // things the users see
66 #include "rmr_agnostic.h" // rmr private things
68 #include "rmr_symtab.h" // must pull in for context setup
69 #include "rmr_agnostic.h" // transport agnostic header
72 #include "rt_generic_static.c"
73 #include "tools_static.c"
76 //#include "mbuf_api.c"
78 #include "test_ctx_support.c" // dummy context support (needs symtab defs, so not with others above)
81 //static void gen_rt( uta_ctx_t* ctx ); // defined in sr_si_static_test, but used by a few others (eliminate order requirement below)
83 // and finally.... the things under test
85 //#include "tools_static_test.c" // local test functions pulled directly because of static nature of things
86 //#include "symtab_static_test.c"
87 //#include "ring_static_test.c"
88 //#include "rt_static_test.c"
89 //#include "wormhole_static_test.c"
90 //#include "mbuf_api_static_test.c"
91 //#include "sr_si_static_test.c"
92 //#include "lg_buf_static_test.c"
93 // do NOT include the receive test static must be stand alone
99 These tests assume there is a dummy process listening on 127.0.0.1:1986; if it's not there
100 the tests still pass, but coverage is reduced because the sends never happen.
102 static int alarm_test( ) {
103 int errors = 0; // number errors found
107 ctx = mk_dummy_ctx();
110 ctx->my_name = strdup( "private" );
111 ctx->my_ip = strdup( "30.4.19.86:2750" );
113 endpt = uta_alarm_endpt(); // check defaults are generated
114 if( fail_if_nil( endpt, "alarm endpoint did not generate a string for defaults" ) ) {
117 errors += fail_if_false( strcmp( endpt, "service-ricplt-alarmmanager-rmr:4560" ) == 0, "alarm endpoint default string not expected" );
121 setenv( "ALARM_MGR_SERVICE_NAME", "127.0.0.1", 1 ); // test to ensure digging from env is good too
122 setenv( "ALARM_MGR_SERVICE_PORT", "999", 1 ); // connect should fail
123 endpt = uta_alarm_endpt(); // check defaults are generated
124 uta_alarm( ctx, ALARM_RAISE, 0, "some info for the alarm" ); // this should fail as the service isn't running
126 setenv( "ALARM_MGR_SERVICE_NAME", "127.0.0.1", 1 ); // test to ensure digging from env is good too
127 setenv( "ALARM_MGR_SERVICE_PORT", "1986", 1 );
128 endpt = uta_alarm_endpt(); // check defaults are generated
129 if( fail_if_nil( endpt, "alarm endpoint did not generate a string when name/port are set in env" ) ) {
132 errors += fail_if_false( strcmp( endpt, "127.0.0.1:1986" ) == 0, "alarm endpoint string not expected when values are in env" );
137 // these functions do not return values; driving for coverage and crash testing
138 uta_alarm( ctx, ALARM_RAISE, 0, "some info for the alarm" );
139 uta_alarm( ctx, ALARM_CLEAR, 0, NULL );
140 uta_alarm_send( ctx, NULL ); // ensure nil message doesn't crash us
144 free( ctx->my_name );
149 return !!errors; // 1 or 0 regardless of count
156 errors += alarm_test();