Test scripts for HelloWorld Xapp 44/2944/1
authorsjana <sj492a@att.com>
Tue, 24 Mar 2020 14:12:41 +0000 (10:12 -0400)
committersjana <sj492a@att.com>
Tue, 24 Mar 2020 14:12:41 +0000 (10:12 -0400)
Issue-ID: RICAPP-63

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

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

diff --git a/test/Makefile b/test/Makefile
new file mode 100644 (file)
index 0000000..aad5855
--- /dev/null
@@ -0,0 +1,83 @@
+CXX:= g++ --std=c++14 -O2 -L/usr/local/lib
+CC:= gcc -O2 -L/usr/local/lib
+
+TEST:=./
+SRC:=../src
+UTILSRC=../src/xapp-utils
+MGMTSRC:=../src/xapp-mgmt
+
+ASNSRC:=../asn1c_defs
+E2APSRC:=../src/xapp-asn/e2ap
+E2SMSRC:=../src/xapp-asn/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
+GTEST_LIBS:= -lgtest -lgtest_main
+######## Keep include dirs separate so we have transparency
+
+
+BASEFLAGS=  -Wall -std=c++14 $(CLOGFLAGS) 
+C_BASEFLAGS= -Wall $(CLOGFLAGS) -DASN_DISABLE_OER_SUPPORT
+
+XAPPFLAGS= -I$(SRC)
+UTILFLAGS= -I$(UTILSRC)
+MGMTFLAGS= -I$(MGMTSRC)
+
+ASNFLAGS=-I$(ASNSRC) -DASN_DISABLE_OER_SUPPORT
+E2APFLAGS = -I$(E2APSRC)
+E2SMFLAGS = -I$(E2SMSRC)
+
+########libs
+
+LIBS= -lsdl -lrmr_nng  -lnng -lpthread -lm $(LOG_LIBS) $(CURL_LIBS) $(RNIB_LIBS) $(GTEST_LIBS)
+COV_FLAGS= -fprofile-arcs -ftest-coverage
+
+#######
+TEST_SRC= hw_unit_tests.cc
+XAPP_SRC= ../src/xapp.cc
+TEST_HDR=$(wildcard $(TEST)/*.h)
+UTIL_SRC= $(wildcard $(UTILSRC)/*.cc)
+MGMT_SRC= $(wildcard $(MGMTSRC)/*.cc)
+
+E2AP_SRC= $(wildcard $(E2APSRC)/*.cc)
+E2SM_SRC= $(wildcard $(E2SMSRC)/*.cc)
+ASN1C_SRC= $(wildcard $(ASNSRC)/*.c)
+
+##############Objects
+UTIL_OBJ=${UTIL_SRC:.cc=.o}
+MGMT_OBJ=${MGMT_SRC:.cc=.o}
+XAPP_OBJ=${XAPP_SRC:.cc=.o}
+TEST_OBJ=${TEST_SRC:.cc=.o} 
+
+E2AP_OBJ = $(E2AP_SRC:.cc=.o)
+E2SM_OBJ = $(E2SM_SRC:.cc=.o)
+
+ASN1C_MODULES = $(ASN1C_SRC:.c=.o)
+$(ASN1C_MODULES): export CFLAGS = $(C_BASEFLAGS) $(ASNFLAGS)
+
+$(UTIL_OBJ):export CPPFLAGS=$(BASEFLAGS) $(UTILFLAGS) $(MGMTFLAGS)
+$(MGMT_OBJ):export CPPFLAGS=$(BASEFLAGS) $(MGMTFLAGS) $(ASNFLAGS) $(E2APFLAGS) $(E2SMFLAGS)
+
+$(E2AP_OBJ): export CPPFLAGS = $(BASEFLAGS) $(ASNFLAGS) $(E2APFLAGS)
+$(E2SM_OBJ): export CPPFLAGS = $(BASEFLAGS) $(ASNFLAGS) $(E2SMFLAGS)
+$(XAPP_OBJ): export CPPFLAGS = $(BASEFLAGS) $(XAPPFLAGS) $(UTILFLAGS) $(MGMTFLAGS) $(E2APFLAGS) $(E2SMFLAGS) $(ASNFLAGS)
+
+$(TEST_OBJ):export CPPFLAGS=$(BASEFLAGS) $(XAPPFLAGS) $(UTILFLAGS) $(MGMTFLAGS) $(E2APFLAGS) $(E2SMFLAGS) $(ASNFLAGS)
+$(TEST_OBJ) = $(TEST_HDR) $(TEST_OBJ) 
+
+
+OBJ= $(TEST_OBJ) $(UTIL_OBJ) $(MGMT_OBJ)  $(ASN1C_MODULES) $(E2AP_OBJ) $(E2SM_OBJ) $(XAPP_OBJ)
+
+print-%  : ; @echo $* = $($*)
+
+hw_unit_tests: $(OBJ)
+       $(CXX) -o $@  $(OBJ) $(LIBS) $(RNIBFLAGS) $(CPPFLAGS) $(CLOGFLAGS)
+
+install: test_rnib
+       install  -D hw_unit_tests  /usr/local/bin/hw_unit_tests
+
+clean:
+       -rm *.o $(E2APSRC)/*.o $(UTILSRC)/*.o $(E2SMSRC)/*.o  $(MGMTSRC)/*.o $(SRC)/*.o hw_unit_tests 
diff --git a/test/hw_unit_tests.cc b/test/hw_unit_tests.cc
new file mode 100644 (file)
index 0000000..73a44d2
--- /dev/null
@@ -0,0 +1,42 @@
+/*
+==================================================================================
+
+        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.
+==================================================================================
+/*
+ * hw_unit_tests.cc
+ *
+ *  Created on: Mar, 2020
+ *  Author: Shraboni Jana
+ */
+
+#include<iostream>
+#include <stdlib.h>
+#include<gtest/gtest.h>
+
+#include "test_rmr.h"
+#include "test_rnib.h"
+#include "test_sdl.h"
+
+using namespace std;
+
+int main(int argc, char* argv[])
+{
+       char rmr_seed[80]="RMR_SEED_RT=../src/routes.txt";
+       putenv(rmr_seed);
+
+       testing::InitGoogleTest(&argc, argv);
+       return RUN_ALL_TESTS();
+}
diff --git a/test/test_rmr.h b/test/test_rmr.h
new file mode 100644 (file)
index 0000000..268ba7a
--- /dev/null
@@ -0,0 +1,119 @@
+/*
+==================================================================================
+
+        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_rmr_healthcheck.h
+ *
+ *  Created on: Mar, 2020
+ *  Author: Shraboni Jana
+ */
+
+#ifndef TEST_TEST_RMR_H_
+#define TEST_TEST_RMR_H_
+#include<iostream>
+#include<gtest/gtest.h>
+#include "xapp.hpp"
+
+#define HC_MSG_SIZE 512
+
+using namespace std;
+
+TEST(XappRmr, RMRSender){
+
+       int total_num_msgs = 10;
+       int num_attempts = 5;
+
+       std::unique_ptr<XappRmr> rmr;
+       rmr = std::make_unique<XappRmr>("4560",num_attempts);
+       rmr->xapp_rmr_init();
+
+       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);
+
+       bool res = rmr->xapp_rmr_send(&hdr,(void*)strMsg);
+       ASSERT_TRUE(res);
+
+       usleep(10);
+     }
+    delete strMsg;
+
+}
+ TEST(XappRmr, RMRReceiver){
+        //initialize rmr
+        std::unique_ptr<XappRmr> rmr;
+        rmr = std::make_unique<XappRmr>("5551");
+        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();
+
+        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_ */
diff --git a/test/test_rnib.h b/test/test_rnib.h
new file mode 100644 (file)
index 0000000..67d1094
--- /dev/null
@@ -0,0 +1,56 @@
+/*
+==================================================================================
+
+        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_RNIB_H_
+#define TEST_TEST_RNIB_H_
+
+#include<iostream>
+#include<gtest/gtest.h>
+#include "xapp.hpp"
+
+using namespace std;
+
+TEST(Xapp, getGNBlist)
+{
+       XappSettings config;
+       XappRmr rmr("4560");
+
+       Xapp hw_xapp(std::ref(config),std::ref(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;
+       }
+
+}
+
+
+
+
+
+#endif /* TEST_TEST_RNIB_H_ */
diff --git a/test/test_sdl.h b/test/test_sdl.h
new file mode 100644 (file)
index 0000000..3f6a4d3
--- /dev/null
@@ -0,0 +1,48 @@
+/*
+==================================================================================
+
+        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_sdl.h
+ *
+ *  Created on: Mar, 2020
+ *   Author: Shraboni Jana
+ */
+
+#ifndef TEST_TEST_SDL_H_
+#define TEST_TEST_SDL_H_
+#include<iostream>
+#include<gtest/gtest.h>
+#include "xapp_sdl.hpp"
+
+using namespace std;
+
+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_SDL_H_ */