2 // basically just set size to be larger than allowed even if actual
4 ==================================================================================
6 Copyright (c) 2018-2019 AT&T Intellectual Property.
8 Licensed under the Apache License, Version 2.0 (the "License");
9 you may not use this file except in compliance with the License.
10 You may obtain a copy of the License at
12 http://www.apache.org/licenses/LICENSE-2.0
14 Unless required by applicable law or agreed to in writing, software
15 distributed under the License is distributed on an "AS IS" BASIS,
16 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 See the License for the specific language governing permissions and
18 limitations under the License.
19 ==================================================================================
22 /* Author : Ashwin Sridharan
26 #define CATCH_CONFIG_MAIN
27 #include <catch2/catch.hpp>
30 #include <xapp_utils.hpp>
32 #define MESSAGE_SIZE 512
34 int num_recv_pkts = 0;
36 int num_dropped_pkts = 0;
38 int num_ping_pkts = 0;
39 int num_pong_pkts = 0;
40 uint32_t NumPkts=1000;
41 unsigned char meid[32];
45 char payload[MESSAGE_SIZE];
48 bool rcvd_pkts(rmr_mbuf_t *rcv_msg){
50 rmr_get_meid(rcv_msg, meid);
55 bool echo_into_space_pkts(rmr_mbuf_t *rcv_msg){
56 rcv_msg->mtype = 100; // some invalid type
61 void dropped_pkts(rmr_mbuf_t *send_msg){
62 std::cout <<"Error handler triggered " << std::endl;
67 bool pong_x(rmr_mbuf_t *rcv_msg){
68 rcv_msg->mtype = 102; //ping port
73 bool ping_recv(rmr_mbuf_t * rcv_msg){
79 TEST_CASE("Test xapp functionality", "[xapp]"){
82 char app_name[128] = "Test App";
83 char port[16] = "tcp:4999";
85 init_logger("UNIT_TEST_XAPP", MDCLOG_INFO);
87 SECTION("Illegal buffer size"){
88 REQUIRE_THROWS(XaPP(app_name, port, RMR_BUFFER_SIZE + 1));
92 REQUIRE_NOTHROW(XaPP(app_name, port, sizeof(Test_message)));
95 SECTION("Simple + memory"){
96 XaPP check_xapp = XaPP(app_name, port, sizeof(Test_message));
97 REQUIRE(check_xapp.get_name() == std::string(app_name));
100 SECTION("Configuration test"){
101 XaPP test_xapp = XaPP(app_name, port, sizeof(Test_message));
102 REQUIRE(test_xapp.get_status() == true);
103 REQUIRE(test_xapp.get_rmr_context() != NULL);
108 SECTION("Transmission test with start"){
110 num_dropped_pkts = 0;
113 // Instantiate and configure xAPP
114 XaPP test_xapp = XaPP(app_name, port, sizeof(Test_message));
116 // Start receiver for test
117 test_xapp.StartThread(rcvd_pkts);
120 // Test Send normal message
121 Test_message my_message;
123 for(i = 0; i < NumPkts; i++){
124 clock_gettime(CLOCK_REALTIME, &(my_message.ts));
125 snprintf(my_message.payload, MESSAGE_SIZE, "hello world %d", i);
126 bool res = test_xapp.Send(102, sizeof(Test_message), (void *) (&my_message));
134 REQUIRE(test_xapp.get_num_active_threads() == 1);
136 REQUIRE(test_xapp.get_num_active_threads() == 0);
138 std::cout <<"Num Packets Sent = " << NumPkts << " Received packets = " << num_recv_pkts << " Dropped packets = " << num_dropped_pkts << " Failed sends = "<< failed_tx << std::endl;
141 REQUIRE(num_recv_pkts > 0);
142 REQUIRE(num_dropped_pkts == 0);
143 REQUIRE(failed_tx == 0);
144 REQUIRE(num_recv_pkts == NumPkts);
147 SECTION("Transmission test error handler with start"){
150 num_dropped_pkts = 0;
153 // Instantiate and configure xAPP
154 XaPP test_xapp = XaPP(app_name, port, sizeof(Test_message) );
157 // Start receiver for test
158 test_xapp.StartThread(&echo_into_space_pkts, &dropped_pkts);
161 // Test Send normal message
162 Test_message my_message;
164 for(i = 0; i < NumPkts; i++){
165 clock_gettime(CLOCK_REALTIME, &(my_message.ts));
166 snprintf(my_message.payload, MESSAGE_SIZE, "hello world %d", i);
167 bool res = test_xapp.Send(102, sizeof(Test_message), (void *) (&my_message));
177 std::cout <<"Num Packets Sent = " << NumPkts << " Received packets = " << num_recv_pkts << " Dropped packets = " << num_dropped_pkts << " Failed sends = "<< failed_tx << std::endl;
180 REQUIRE(num_recv_pkts == NumPkts);
181 REQUIRE(num_dropped_pkts == NumPkts);
182 REQUIRE(failed_tx == 0);
186 SECTION("Transmission test error handler with start thread"){
189 num_dropped_pkts = 0;
192 // Instantiate and configure xAPP
193 XaPP test_xapp = XaPP(app_name, port, sizeof(Test_message) );
196 // Start receiver for test
197 test_xapp.StartThread(&echo_into_space_pkts, &dropped_pkts);
200 // Test Send normal message
201 Test_message my_message;
203 for(i = 0; i < NumPkts; i++){
204 clock_gettime(CLOCK_REALTIME, &(my_message.ts));
205 snprintf(my_message.payload, MESSAGE_SIZE, "hello world %d", i);
206 bool res = test_xapp.Send(102, sizeof(Test_message), (void *) (&my_message));
216 std::cout <<"Num Packets Sent = " << NumPkts << " Received packets = " << num_recv_pkts << " Dropped packets = " << num_dropped_pkts << " Failed sends = "<< failed_tx << std::endl;
219 REQUIRE(num_recv_pkts == NumPkts);
220 REQUIRE(num_dropped_pkts == NumPkts);
221 REQUIRE(failed_tx == 0);
226 SECTION("Test ping pong : two xapps send to each other. "){
228 char ping_name[] = "ping";
229 char pong_name[] = "pong";
230 char ping_port[] = "tcp:4999";
231 char pong_port[] = "tcp:4998";
233 // Instantiate ping xAPP
234 XaPP ping_xapp = XaPP(ping_name, ping_port, sizeof(Test_message) );
237 // Instantiate pong xapp
238 XaPP pong_xapp = XaPP(pong_name, pong_port, sizeof(Test_message) );
240 // Start receiver on ping
241 ping_xapp.StartThread(ping_recv);
244 // Start receiver on pong
245 pong_xapp.StartThread(pong_x);
247 // send messages from ping to pong
248 Test_message my_message;
250 for(i = 0; i < NumPkts; i++){
251 clock_gettime(CLOCK_REALTIME, &(my_message.ts));
252 snprintf(my_message.payload, MESSAGE_SIZE, "hello world %d", i);
253 bool res = ping_xapp.Send(101, sizeof(Test_message), (void *) (&my_message));
262 REQUIRE(failed_tx == 0);
263 REQUIRE(num_ping_pkts == NumPkts);
264 REQUIRE(num_pong_pkts == NumPkts);
273 TEST_CASE(" Test out various transmission methods ..", "1"){
276 char app_name[128] = "Test App";
277 char port[16] = "tcp:4999";
279 init_logger("UNIT_TEST_XAPP", MDCLOG_INFO);
282 unsigned char my_meid[32] = "ABC123";
283 Test_message my_message;
285 SECTION("Test if message larger than allowed"){
287 num_dropped_pkts = 0;
290 // Instantiate and configure xAPP
291 XaPP test_xapp = XaPP(app_name, port, sizeof(Test_message) );
293 // Start receiver for test
294 test_xapp.StartThread(&rcvd_pkts);
297 // Test sending a message of size larger than allowed
298 // basically just set size to be larger than allowed even if actual
300 res = test_xapp.Send(102, RMR_BUFFER_SIZE + 100, (void *)(&my_message));
301 REQUIRE(res == false);
303 res = test_xapp.Send(102, RMR_BUFFER_SIZE + 100, (void *)(&my_message), my_meid);
304 REQUIRE(res == false);
310 SECTION("Test with tlv"){
312 num_dropped_pkts = 0;
315 // Instantiate and configure xAPP
316 XaPP test_xapp = XaPP(app_name, port, sizeof(Test_message) );
318 // Start receiver for test
319 test_xapp.StartThread(&rcvd_pkts);
322 // Test Send with tlv
323 clock_gettime(CLOCK_REALTIME, &(my_message.ts));
324 snprintf(my_message.payload, MESSAGE_SIZE, "hello world");
325 res = test_xapp.Send(102, sizeof(Test_message), (void *) (&my_message));
328 // Test send with tlv and meid
329 res = test_xapp.Send(102, sizeof(Test_message), (void *) (&my_message), my_meid);
334 REQUIRE(num_recv_pkts == 2);
335 REQUIRE(!strcmp((const char *)meid, (const char *)my_meid));