Testcase for A1 Healthcheck added. 84/3084/1
authorsjana <sj492a@att.com>
Tue, 31 Mar 2020 16:20:25 +0000 (12:20 -0400)
committersjana <sj492a@att.com>
Tue, 31 Mar 2020 16:20:25 +0000 (12:20 -0400)
Issue-ID: RICAPP-65

Signed-off-by: sjana <sj492a@att.com>
Change-Id: I40cb9ad09205431ecdf333107ad08c6717522ce5

test/Makefile
test/hw_unit_tests.cc
test/test_db.h [new file with mode: 0644]
test/test_hc.h [new file with mode: 0644]
test/test_rmr.h

index aad5855..10089f7 100644 (file)
@@ -7,14 +7,14 @@ UTILSRC=../src/xapp-utils
 MGMTSRC:=../src/xapp-mgmt
 
 ASNSRC:=../asn1c_defs
-E2APSRC:=../src/xapp-asn/e2ap
-E2SMSRC:=../src/xapp-asn/e2sm
+E2APSRC:=../src/xapp-formats/e2ap
+E2SMSRC:=../src/xapp-formats/e2sm
 
 ####### Logging library and flags
 CLOGFLAGS:= `pkg-config mdclog --cflags`
 LOG_LIBS:= `pkg-config mdclog --libs`
 CURL_LIBS:= `pkg-config libcurl --libs`
-RNIB_LIBS:= -pthread /usr/local/lib/rnibreader.a
+RNIB_LIBS:= -pthread /usr/local/lib/rnibreader_old.a
 GTEST_LIBS:= -lgtest -lgtest_main
 ######## Keep include dirs separate so we have transparency
 
index 73a44d2..a1bd3ca 100644 (file)
  */
 
 #include<iostream>
-#include <stdlib.h>
+#include<stdlib.h>
 #include<gtest/gtest.h>
 
-#include "test_rmr.h"
-#include "test_rnib.h"
-#include "test_sdl.h"
+#include "test_db.h"
+//#include "test_rmr.h"
+#include "test_hc.h"
+
+#define HC_MSG_SIZE 512
 
 using namespace std;
 
+
 int main(int argc, char* argv[])
 {
        char rmr_seed[80]="RMR_SEED_RT=../src/routes.txt";
diff --git a/test/test_db.h b/test/test_db.h
new file mode 100644 (file)
index 0000000..e7716b4
--- /dev/null
@@ -0,0 +1,68 @@
+/*
+==================================================================================
+
+        Copyright (c) 2018-2019 AT&T Intellectual Property.
+
+   Licensed under the Apache License, Version 2.0 (the "License");
+   you may not use this file except in compliance with the License.
+   You may obtain a copy of the License at
+
+       http://www.apache.org/licenses/LICENSE-2.0
+
+   Unless required by applicable law or agreed to in writing, software
+   distributed under the License is distributed on an "AS IS" BASIS,
+   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+   See the License for the specific language governing permissions and
+   limitations under the License.
+==================================================================================
+/*
+ * test_rnib.h
+ *
+ *  Created on: Mar 23, 2020
+ *  Author: Shraboni Jana
+ */
+
+#ifndef TEST_TEST_DB_H_
+#define TEST_TEST_DB_H_
+
+#include<iostream>
+#include<gtest/gtest.h>
+#include "xapp.hpp"
+
+using namespace std;
+
+TEST(Xapp, getGNBlist)
+{
+       XappSettings config;
+       XappRmr rmr("7001");
+
+       Xapp hw_xapp(std::ref(config),rmr);
+       hw_xapp.set_rnib_gnblist();
+
+       auto gnblist = hw_xapp.get_rnib_gnblist();
+       int sz = gnblist.size();
+       EXPECT_GE(sz,0);
+       std::cout << "************gnb ids retrieved using R-NIB**************" << std::endl;
+       for(int i = 0; i<sz; i++){
+               std::cout << gnblist[i] << std::endl;
+       }
+
+}
+
+TEST(Xapp, SDLData){
+
+       //Xapp's SDL namespace.
+    std::string nmspace = "hw-xapp";
+       XappSDL xappsdl(nmspace);
+
+       std::unique_ptr<shareddatalayer::SyncStorage> sdl(shareddatalayer::SyncStorage::create());
+       bool res = xappsdl.set_data(sdl.get());
+       ASSERT_TRUE(res);
+
+       xappsdl.get_data(sdl.get());
+
+}
+
+
+
+#endif /* TEST_TEST_DB_H_ */
diff --git a/test/test_hc.h b/test/test_hc.h
new file mode 100644 (file)
index 0000000..cbb8726
--- /dev/null
@@ -0,0 +1,113 @@
+/*
+==================================================================================
+
+        Copyright (c) 2018-2019 AT&T Intellectual Property.
+
+   Licensed under the Apache License, Version 2.0 (the "License");
+   you may not use this file except in compliance with the License.
+   You may obtain a copy of the License at
+
+       http://www.apache.org/licenses/LICENSE-2.0
+
+   Unless required by applicable law or agreed to in writing, software
+   distributed under the License is distributed on an "AS IS" BASIS,
+   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+   See the License for the specific language governing permissions and
+   limitations under the License.
+==================================================================================
+/*
+ * test_a1.h
+ *
+ *  Created on: Mar, 2020
+ *  Author: Shraboni Jana
+ */
+
+#include<iostream>
+#include<gtest/gtest.h>
+#include<rapidjson/stringbuffer.h>
+#include<rapidjson/writer.h>
+#include<string.h>
+#include "xapp.hpp"
+#define HC_MSG_SIZE 512
+
+using namespace std;
+TEST(Xapp, RMRHealthCheck){
+
+        int total_num_msgs = 2;
+        int num_attempts = 10;
+
+        std::unique_ptr<XappRmr> rmr;
+        rmr = std::make_unique<XappRmr>("4560",num_attempts);
+        rmr->xapp_rmr_init();
+
+        XappSettings config;
+
+        std::unique_ptr<Xapp> hw_xapp = std::make_unique<Xapp>(std::ref(config),std::ref(*rmr));
+
+        std::unique_ptr<XappMsgHandler> mp_handler = std::make_unique<XappMsgHandler>("HW-Xapp-id");
+
+        hw_xapp->start_xapp_receiver(std::ref(*mp_handler));
+        sleep(5);
+
+        xapp_rmr_header hdr;
+        hdr.message_type = RIC_HEALTH_CHECK_REQ;
+        char strMsg[HC_MSG_SIZE];
+
+        for(int i = 0; i < total_num_msgs; i++){
+                snprintf(strMsg,HC_MSG_SIZE, "HelloWorld: RMR Health Check %d", i);
+                clock_gettime(CLOCK_REALTIME, &(hdr.ts));
+                hdr.payload_length = strlen(strMsg);
+
+                bool res = rmr->xapp_rmr_send(&hdr,(void*)strMsg);
+                usleep(1);
+        }
+        sleep(10);
+        hw_xapp->stop();
+        sleep(10);
+ };
+
+TEST(Xapp, A1HealthCheck){
+
+       //Read the json file and send it using rmr.
+       string json = "{\"policy_type_id\": \"1\",\"policy_instance_id\":\"3d2157af-6a8f-4a7c-810f-38c2f824bf12\",\"operation\": \"CREATE\"}";
+       int n = json.length();
+       char strMsg[n + 1];
+       strcpy(strMsg, json.c_str());
+       Document d;
+       d.Parse(strMsg);
+
+       int num_attempts = 5;
+
+       std::unique_ptr<XappRmr> rmr;
+       rmr = std::make_unique<XappRmr>("4560",num_attempts);
+       rmr->xapp_rmr_init();
+
+       XappSettings config;
+
+       std::unique_ptr<Xapp> hw_xapp = std::make_unique<Xapp>(std::ref(config),std::ref(*rmr));
+
+       std::unique_ptr<XappMsgHandler> mp_handler = std::make_unique<XappMsgHandler>("HW-Xapp-id");
+
+       hw_xapp->start_xapp_receiver(std::ref(*mp_handler));
+       sleep(5);
+
+       xapp_rmr_header hdr;
+       hdr.message_type = A1_POLICY_REQ;
+    clock_gettime(CLOCK_REALTIME, &(hdr.ts));
+
+
+       hdr.payload_length = strlen(strMsg);
+
+       bool res_msg1 = rmr->xapp_rmr_send(&hdr,(void*)strMsg);
+       ASSERT_TRUE(res_msg1);
+
+       usleep(1);
+
+       bool res_msg2 = rmr->xapp_rmr_send(&hdr,(void*)strMsg);
+       ASSERT_TRUE(res_msg2);
+
+       sleep(10);
+       hw_xapp->stop();
+       sleep(10);
+
+}
index 268ba7a..a85c8c5 100644 (file)
 
 using namespace std;
 
-TEST(XappRmr, RMRSender){
+TEST(RMR, Sender){
 
-       int total_num_msgs = 10;
-       int num_attempts = 5;
+       int total_num_msgs = 2;
+       int num_attempts = 10;
 
        std::unique_ptr<XappRmr> rmr;
        rmr = std::make_unique<XappRmr>("4560",num_attempts);
        rmr->xapp_rmr_init();
+       rmr->set_listen(false);
 
        xapp_rmr_header hdr;
        hdr.message_type = RIC_HEALTH_CHECK_REQ;
-    char *strMsg = (char*)malloc(HC_MSG_SIZE);
 
     for(int i = 0; i < total_num_msgs; i++){
-       snprintf(strMsg,HC_MSG_SIZE, "HelloWorld: RMR Health Check %d", i);
-       clock_gettime(CLOCK_REALTIME, &(hdr.ts));
-       hdr.payload_length = strlen(strMsg);
+       std::string temp="HelloWorld: RMR Health Check"+ std::to_string(i);
+       int n = temp.length();
+       char strMsg[n+1];
+        std::strcpy(strMsg,temp.c_str());
 
-       bool res = rmr->xapp_rmr_send(&hdr,(void*)strMsg);
-       ASSERT_TRUE(res);
+        clock_gettime(CLOCK_REALTIME, &(hdr.ts));
+        hdr.payload_length = n+1;
 
-       usleep(10);
+        bool res = rmr->xapp_rmr_send(&hdr,(void*)strMsg);
+        ASSERT_TRUE(res);
+        usleep(1);
      }
-    delete strMsg;
-
+    ASSERT_TRUE(true);
 }
- TEST(XappRmr, RMRReceiver){
+ TEST(RMR, Receiver){
         //initialize rmr
-        std::unique_ptr<XappRmr> rmr;
-        rmr = std::make_unique<XappRmr>("5551");
+        std::unique_ptr<XappMsgHandler> mp_handler = std::make_unique<XappMsgHandler>("HW-Xapp-id");
+        XappRmr *rmr = new XappRmr("4560");
         rmr->xapp_rmr_init();
-
-        XappSettings config;
-
-        std::unique_ptr<Xapp> hw_xapp = std::make_unique<Xapp>(std::ref(config),std::ref(*rmr));
-
-        std::unique_ptr<XappMsgHandler> mp_handler = std::make_unique<XappMsgHandler>();
-
-        rmr->set_listen(true);
-        hw_xapp->start_xapp_receiver(std::ref(*mp_handler));
-        sleep(2);
-        rmr->~XappRmr();
-
+        sleep(10);
+        rmr->set_listen(false);
+        rmr->xapp_rmr_receive(std::move(*mp_handler), rmr);
         ASSERT_TRUE(true);
  };
 
- TEST(XappRmr, HC_ReturnToSender){
-
-        int total_num_msgs = 2;
-        int num_attempts = 10;
-
-        std::unique_ptr<XappRmr> rmr;
-        rmr = std::make_unique<XappRmr>("4560",num_attempts);
-        rmr->xapp_rmr_init();
-
-        XappSettings config;
-
-        std::unique_ptr<Xapp> hw_xapp = std::make_unique<Xapp>(std::ref(config),std::ref(*rmr));
-
-        std::unique_ptr<XappMsgHandler> mp_handler = std::make_unique<XappMsgHandler>();
-
-        rmr->set_listen(true);
-        hw_xapp->start_xapp_receiver(std::ref(*mp_handler));
-        sleep(5);
-
-        xapp_rmr_header hdr;
-        hdr.message_type = RIC_HEALTH_CHECK_REQ;
-        char strMsg[HC_MSG_SIZE];
-
-        for(int i = 0; i < total_num_msgs; i++){
-                snprintf(strMsg,HC_MSG_SIZE, "HelloWorld: RMR Health Check %d", i);
-                clock_gettime(CLOCK_REALTIME, &(hdr.ts));
-                hdr.payload_length = strlen(strMsg);
-
-                bool res = rmr->xapp_rmr_send(&hdr,(void*)strMsg);
-                usleep(10);
-        }
-
-
- };
-
-
-
 
 #endif /* TEST_TEST_RMR_H_ */