2 ==================================================================================
4 Copyright (c) 2018-2019 AT&T Intellectual Property.
6 Licensed under the Apache License, Version 2.0 (the "License");
7 you may not use this file except in compliance with the License.
8 You may obtain a copy of the License at
10 http://www.apache.org/licenses/LICENSE-2.0
12 Unless required by applicable law or agreed to in writing, software
13 distributed under the License is distributed on an "AS IS" BASIS,
14 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 See the License for the specific language governing permissions and
16 limitations under the License.
17 ==================================================================================
20 /* Author : Ashwin Sridharan
24 #define CATCH_CONFIG_MAIN
25 #include <catch2/catch.hpp>
28 #include <xapp_utils.hpp>
30 #define RMR_RT_FILE "/home/asridharan/projects/ric-xapp-dev/ric-app/adm-ctrl-xapp/test/uta_rtg.rt"
31 #define MESSAGE_SIZE 512
33 int num_recv_pkts = 0;
35 int num_dropped_pkts = 0;
37 int num_ping_pkts = 0;
38 int num_pong_pkts = 0;
39 uint32_t NumPkts=1000;
40 unsigned char meid[32];
44 char payload[MESSAGE_SIZE];
47 bool rcvd_pkts(rmr_mbuf_t *rcv_msg){
49 rmr_get_meid(rcv_msg, meid);
54 bool echo_into_space_pkts(rmr_mbuf_t *rcv_msg){
55 rcv_msg->mtype = 100; // some invalid type
60 void dropped_pkts(rmr_mbuf_t *send_msg){
61 std::cout <<"Error handler triggered " << std::endl;
65 bool ping_x(rmr_mbuf_t *rcv_msg){
66 rcv_msg->mtype = 101; //pong
71 bool pong_x(rmr_mbuf_t *rcv_msg){
77 TEST_CASE("Test xapp functionality", "[xapp]"){
80 char app_name[128] = "Test App";
81 char port[16] = "tcp:4999";
86 mdclog_attr_init(&attr);
87 mdclog_attr_set_ident(attr, "UNIT TEST XAPP FRAMEWORK");
89 mdclog_level_set(MDCLOG_INFO);
90 mdclog_attr_destroy(attr);
92 SECTION("RMR illegal options"){
93 char illegal_port [] = "udp:-1";
94 REQUIRE_THROWS(XaPP(app_name, illegal_port, sizeof(Test_message), 1));
95 REQUIRE_THROWS(XaPP(app_name, port, RMR_BUFFER_SIZE + 1, 1));
99 REQUIRE_NOTHROW(XaPP(app_name, port, sizeof(Test_message), 1));
102 SECTION("Simple + memory"){
103 XaPP check_xapp = XaPP(app_name, port, sizeof(Test_message), 1);
104 REQUIRE(check_xapp.getName() == std::string(app_name));
107 SECTION("Configuration test"){
108 XaPP test_xapp = XaPP(app_name, port, sizeof(Test_message) , 1);
109 test_xapp.set_num_retries(num_retries);
111 REQUIRE(test_xapp.get_num_retries() == num_retries);
112 REQUIRE(test_xapp.getStatus() == 1);
113 REQUIRE(test_xapp.get_num_retries() != 2);
114 REQUIRE(test_xapp.getStatus() == true);
115 REQUIRE(test_xapp.get_rmr_context() != NULL);
120 SECTION("Transmission test with start"){
122 num_dropped_pkts = 0;
125 // Instantiate and configure xAPP
126 XaPP test_xapp = XaPP(app_name, port, sizeof(Test_message) , 1);
127 test_xapp.set_num_retries(num_retries);
129 // Start receiver for test
130 test_xapp.Start(&rcvd_pkts);
133 // Test Send normal message
134 Test_message my_message;
136 for(i = 0; i < NumPkts; i++){
137 clock_gettime(CLOCK_REALTIME, &(my_message.ts));
138 snprintf(my_message.payload, MESSAGE_SIZE, "hello world %d", i);
139 bool res = test_xapp.Send(0, sizeof(Test_message), (void *) (&my_message));
149 std::cout <<"Num Packets Sent = " << NumPkts << " Received packets = " << num_recv_pkts << " Dropped packets = " << num_dropped_pkts << " Failed sends = "<< failed_tx << std::endl;
150 std::cout <<"Num attempts = " << test_xapp.get_Send_attempts() << " Num failed = " << test_xapp.get_Send_fails() << std::endl;
152 REQUIRE(num_recv_pkts > 0);
153 REQUIRE(num_dropped_pkts == 0);
154 REQUIRE(failed_tx == 0);
155 REQUIRE(num_recv_pkts == NumPkts);
158 // SECTION("Transmission test with start specific thread"){
159 // num_recv_pkts = 0;
160 // num_dropped_pkts = 0;
163 // // Instantiate and configure xAPP
164 // XaPP test_xapp = XaPP(app_name, port, sizeof(Test_message) , 1);
165 // test_xapp.set_num_retries(num_retries);
167 // // Start receiver for test
168 // test_xapp.StartThread(&rcvd_pkts);
171 // // Test Send normal message
172 // Test_message my_message;
174 // for(i = 0; i < NumPkts; i++){
175 // clock_gettime(CLOCK_REALTIME, &(my_message.ts));
176 // snprintf(my_message.payload, MESSAGE_SIZE, "hello world %d", i);
177 // bool res = test_xapp.Send(0, sizeof(Test_message), (void *) (&my_message));
187 // std::cout <<"Num Packets Sent = " << NumPkts << " Received packets = " << num_recv_pkts << " Dropped packets = " << num_dropped_pkts << " Failed sends = "<< failed_tx << std::endl;
188 // std::cout <<"Num attempts = " << test_xapp.get_Send_attempts() << " Num failed = " << test_xapp.get_Send_fails() << std::endl;
190 // REQUIRE(num_recv_pkts > 0);
191 // REQUIRE(num_dropped_pkts == 0);
192 // REQUIRE(failed_tx == 0);
193 // REQUIRE(num_recv_pkts == NumPkts);
196 // SECTION("Transmission test error handler with start"){
198 // num_recv_pkts = 0;
199 // num_dropped_pkts = 0;
202 // // Instantiate and configure xAPP
203 // XaPP test_xapp = XaPP(app_name, port, sizeof(Test_message) , 1);
204 // test_xapp.set_num_retries(num_retries);
206 // // Start receiver for test
207 // test_xapp.Start(&echo_into_space_pkts, &dropped_pkts);
210 // // Test Send normal message
211 // Test_message my_message;
213 // for(i = 0; i < NumPkts; i++){
214 // clock_gettime(CLOCK_REALTIME, &(my_message.ts));
215 // snprintf(my_message.payload, MESSAGE_SIZE, "hello world %d", i);
216 // bool res = test_xapp.Send(0, sizeof(Test_message), (void *) (&my_message));
226 // std::cout <<"Num Packets Sent = " << NumPkts << " Received packets = " << num_recv_pkts << " Dropped packets = " << num_dropped_pkts << " Failed sends = "<< failed_tx << std::endl;
227 // std::cout <<"Num attempts = " << test_xapp.get_Send_attempts() << " Num failed = " << test_xapp.get_Send_fails() << std::endl;
229 // REQUIRE(num_recv_pkts == NumPkts);
230 // REQUIRE(num_dropped_pkts == NumPkts);
231 // REQUIRE(failed_tx == 0);
235 // SECTION("Transmission test error handler with start thread"){
237 // num_recv_pkts = 0;
238 // num_dropped_pkts = 0;
241 // // Instantiate and configure xAPP
242 // XaPP test_xapp = XaPP(app_name, port, sizeof(Test_message) , 1);
243 // test_xapp.set_num_retries(num_retries);
245 // // Start receiver for test
246 // test_xapp.StartThread(&echo_into_space_pkts, &dropped_pkts);
249 // // Test Send normal message
250 // Test_message my_message;
252 // for(i = 0; i < NumPkts; i++){
253 // clock_gettime(CLOCK_REALTIME, &(my_message.ts));
254 // snprintf(my_message.payload, MESSAGE_SIZE, "hello world %d", i);
255 // bool res = test_xapp.Send(0, sizeof(Test_message), (void *) (&my_message));
265 // std::cout <<"Num Packets Sent = " << NumPkts << " Received packets = " << num_recv_pkts << " Dropped packets = " << num_dropped_pkts << " Failed sends = "<< failed_tx << std::endl;
266 // std::cout <<"Num attempts = " << test_xapp.get_Send_attempts() << " Num failed = " << test_xapp.get_Send_fails() << std::endl;
268 // REQUIRE(num_recv_pkts == NumPkts);
269 // REQUIRE(num_dropped_pkts == NumPkts);
270 // REQUIRE(failed_tx == 0);
275 // SECTION("Test ping pong : two xapps send to each other. "){
277 // char ping_name[] = "ping";
278 // char pong_name[] = "pong";
279 // char ping_port[] = "tcp:4999";
280 // char pong_port[] = "tcp:4998";
282 // // Instantiate ping xAPP
283 // XaPP ping_xapp = XaPP(ping_name, ping_port, sizeof(Test_message) , 1);
286 // // Instantiate pong xapp
287 // XaPP pong_xapp = XaPP(pong_name, pong_port, sizeof(Test_message) , 1);
289 // // Start receiver on ping
290 // ping_xapp.StartThread(ping_x);
293 // // Start receiver on pong
294 // pong_xapp.StartThread(&pong_x);
296 // // send messages to ping
297 // Test_message my_message;
299 // for(i = 0; i < NumPkts; i++){
300 // clock_gettime(CLOCK_REALTIME, &(my_message.ts));
301 // snprintf(my_message.payload, MESSAGE_SIZE, "hello world %d", i);
302 // bool res = ping_xapp.Send(0, sizeof(Test_message), (void *) (&my_message));
312 // REQUIRE(failed_tx == 0);
313 // REQUIRE(num_ping_pkts == NumPkts);
314 // REQUIRE(num_pong_pkts == NumPkts);
320 // TEST_CASE(" Test out various transmission methods ..", "1"){
322 // // Test parameters
323 // char app_name[128] = "Test App";
324 // char port[16] = "tcp:4999";
327 // mdclog_attr_t *attr;
328 // mdclog_attr_init(&attr);
329 // mdclog_attr_set_ident(attr, "UNIT TEST XAPP FRAMEWORK");
330 // mdclog_init(attr);
331 // mdclog_level_set(MDCLOG_INFO);
332 // mdclog_attr_destroy(attr);
334 // unsigned char my_meid[32] = "ABC123";
335 // Test_message my_message;
337 // SECTION("Test if message larger than allowed"){
338 // num_recv_pkts = 0;
339 // num_dropped_pkts = 0;
342 // // Instantiate and configure xAPP
343 // XaPP test_xapp = XaPP(app_name, port, sizeof(Test_message) , 1);
345 // // Start receiver for test
346 // test_xapp.StartThread(&rcvd_pkts);
349 // // Test sending a message of size larger than allowed
350 // res = test_xapp.Send(0, RMR_BUFFER_SIZE + 100, (void *)(&my_message));
353 // REQUIRE(res == false);
356 // SECTION("Test with tlv"){
357 // num_recv_pkts = 0;
358 // num_dropped_pkts = 0;
361 // // Instantiate and configure xAPP
362 // XaPP test_xapp = XaPP(app_name, port, sizeof(Test_message) , 1);
364 // // Start receiver for test
365 // test_xapp.StartThread(&rcvd_pkts);
368 // // Test Send with tlv
369 // clock_gettime(CLOCK_REALTIME, &(my_message.ts));
370 // snprintf(my_message.payload, MESSAGE_SIZE, "hello world");
371 // res = test_xapp.Send(0, sizeof(Test_message), (void *) (&my_message));
374 // // Test send with tlv and meid
375 // res = test_xapp.Send(0, sizeof(Test_message), (void *) (&my_message), my_meid);
380 // REQUIRE(num_recv_pkts == 2);
381 // REQUIRE(!strcmp((const char *)meid, (const char *)my_meid));