From d63f834656922171ffa04347e34c7bce8a0d41be Mon Sep 17 00:00:00 2001 From: sjana Date: Tue, 24 Mar 2020 10:12:41 -0400 Subject: [PATCH] Test scripts for HelloWorld Xapp Issue-ID: RICAPP-63 Signed-off-by: sjana Change-Id: I59d9fe3547337fbd97cdfa026054c215fd0f528e --- test/Makefile | 83 +++++++++++++++++++++++++++++++++++ test/hw_unit_tests.cc | 42 ++++++++++++++++++ test/test_rmr.h | 119 ++++++++++++++++++++++++++++++++++++++++++++++++++ test/test_rnib.h | 56 ++++++++++++++++++++++++ test/test_sdl.h | 48 ++++++++++++++++++++ 5 files changed, 348 insertions(+) create mode 100644 test/Makefile create mode 100644 test/hw_unit_tests.cc create mode 100644 test/test_rmr.h create mode 100644 test/test_rnib.h create mode 100644 test/test_sdl.h diff --git a/test/Makefile b/test/Makefile new file mode 100644 index 0000000..aad5855 --- /dev/null +++ b/test/Makefile @@ -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 index 0000000..73a44d2 --- /dev/null +++ b/test/hw_unit_tests.cc @@ -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 +#include +#include + +#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 index 0000000..268ba7a --- /dev/null +++ b/test/test_rmr.h @@ -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 +#include +#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 rmr; + rmr = std::make_unique("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 rmr; + rmr = std::make_unique("5551"); + rmr->xapp_rmr_init(); + + XappSettings config; + + std::unique_ptr hw_xapp = std::make_unique(std::ref(config),std::ref(*rmr)); + + std::unique_ptr mp_handler = std::make_unique(); + + 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 rmr; + rmr = std::make_unique("4560",num_attempts); + rmr->xapp_rmr_init(); + + XappSettings config; + + std::unique_ptr hw_xapp = std::make_unique(std::ref(config),std::ref(*rmr)); + + std::unique_ptr mp_handler = std::make_unique(); + + 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 index 0000000..67d1094 --- /dev/null +++ b/test/test_rnib.h @@ -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 +#include +#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 +#include +#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 sdl(shareddatalayer::SyncStorage::create()); + bool res = xappsdl.set_data(sdl.get()); + ASSERT_TRUE(res); + + xappsdl.get_data(sdl.get()); + +} + + +#endif /* TEST_TEST_SDL_H_ */ -- 2.16.6