VOL-2502: Update README.md for openolt agent after BAL3.2.3.2 migration
VOL-2503: Provides test target for openolt-agent for Jenkins CI Integration
VOL-2504: Reorganize openolt-agent core.cc file
Change-Id: Id22fb881fcb9cc19d1f2ba044716731157d3a64e
diff --git a/agent/test/Makefile.in b/agent/test/Makefile.in
index f3f0e5e..2d700cd 100644
--- a/agent/test/Makefile.in
+++ b/agent/test/Makefile.in
@@ -27,10 +27,27 @@
# openolt.proto and tech_profile.proto
OPENOLT_PROTO_VER ?= v1.0.3
+GTEST_VER ?= release-1.8.0
+gtest-target = $(HOME)/openolt-agent-test-lib/gtest/$(GTEST_VER)/lib/libgtest.a
+
+CMOCK_VER ?= 0207b30
+cmock-target = $(HOME)/openolt-agent-test-lib/cmock/$(CMOCK_VER)/include/cmock.h
+
+GMOCK_GLOBAL_VER ?= 1.0.2
+gmock-global-target = $(HOME)/openolt-agent-test-lib/gmock-global/$(GMOCK_GLOBAL_VER)/gmock-global/gmock-global.h
+
+
# GRPC installation
GRPC_ADDR = https://github.com/grpc/grpc
GRPC_DST = /tmp/grpc
GRPC_VER = v1.10.x
+grpc-cpp-plugin-bin = $(HOME)/openolt-agent-test-lib/grpc/$(GRPC_VER)/bin/grpc_cpp_plugin
+
+# Protobuf installation
+PROTOBUF_VER = 3.5.0
+PROTOBUF_ADDR = https://github.com/protocolbuffers/protobuf/releases/download/v$(PROTOBUF_VER)/protobuf-cpp-$(PROTOBUF_VER).tar.gz
+PROTOBUF_DST = /tmp/protobuf-$(PROTOBUF_VER)
+protoc-bin = $(HOME)/openolt-agent-test-lib/grpc/$(GRPC_VER)/bin/protoc
USER := $(shell echo $(USER))
#
@@ -43,63 +60,79 @@
CXX = g++-4.9
CXXFLAGS += -g -O2
-CXXFLAGS += $(shell pkg-config --cflags-only-I grpc++)
-CPPFLAGS += `pkg-config --cflags protobuf grpc`
+CXXFLAGS += $(shell PKG_CONFIG_PATH=$(HOME)/openolt-agent-test-lib/grpc/$(GRPC_VER)/lib/pkgconfig pkg-config --cflags-only-I grpc++)
+CPPFLAGS += `PKG_CONFIG_PATH=$(HOME)/openolt-agent-test-lib/grpc/$(GRPC_VER)/lib/pkgconfig pkg-config --cflags protobuf grpc`
CXXFLAGS += -std=c++11 -fpermissive -Wno-literal-suffix
CXXFLAGS += -DTEST_MODE -DENABLE_LOG
LDFLAGS +=
-LDFLAGS += `pkg-config --libs protobuf grpc++ grpc` -ldl -lgpr
+LDFLAGS += `PKG_CONFIG_PATH=$(HOME)/openolt-agent-test-lib/grpc/$(GRPC_VER)/lib/pkgconfig pkg-config --libs protobuf grpc++ grpc` -ldl -lgpr
CXXFLAGSDEVICE = -I../device -I../device/$(OPENOLTDEVICE) -I../device/generic
export CXX CXXFLAGS OPENOLT_PROTO_VER
-BAL_API_DIR=bal-api-3.2.3.2
+BAL_API_VER=bal-api-3.2.3.2
+BAL_API_DIR=$(BAL_API_VER)
BALLIBNAME=bcm_host_api_stubs
BALLIBDIR=$(BAL_API_DIR)/stubs
BAL_INC = -I$(BAL_API_DIR)/include \
-I$(BAL_API_DIR)/include/object_model
-CXXFLAGS += $(BAL_INC)
+TEST_LIB_INC = -I$(HOME)/openolt-agent-test-lib/gtest/$(GTEST_VER)/include \
+ -I$(HOME)/openolt-agent-test-lib/cmock/$(CMOCK_VER)/include \
+ -I$(HOME)/openolt-agent-test-lib/gmock-global/$(GMOCK_GLOBAL_VER)
+CXXFLAGS += $(BAL_INC) $(TEST_LIB_INC)
-
-prereq:
+prereqs-system:
sudo apt-get -q -y install git pkg-config build-essential autoconf libtool libgflags-dev libgtest-dev clang libc++-dev unzip docker.io
sudo apt-get install -y build-essential autoconf libssl-dev gawk debhelper dh-systemd init-system-helpers curl cmake ccache g++-4.9
- # Install GRPC, libprotobuf and protoc
+prereqs-local: $(protoc-bin) $(grpc-cpp-plugin-bin) prereqs-test-lib
+
+$(protoc-bin):
+ # Install protobuf
+ rm -rf $(PROTOBUF_DST)
+ cd /tmp && wget $(PROTOBUF_ADDR)
+ cd /tmp && tar -zxvf protobuf-cpp-$(PROTOBUF_VER).tar.gz
+ cd $(PROTOBUF_DST) && ./autogen.sh
+ mkdir -p $(HOME)/openolt-agent-test-lib/grpc/$(GRPC_VER)
+ cd $(PROTOBUF_DST) && ./configure --prefix=$(HOME)/openolt-agent-test-lib/grpc/$(GRPC_VER)
+ make -C $(PROTOBUF_DST)
+ make -C $(PROTOBUF_DST) install
+
+$(grpc-cpp-plugin-bin):
+ # Install GRPC, protoc
rm -rf $(GRPC_DST)
- git clone -b $(GRPC_VER) $(GRPC_ADDR) $(GRPC_DST)
+ cd /tmp && git clone -b $(GRPC_VER) $(GRPC_ADDR) $(GRPC_DST)
cd $(GRPC_DST) && git submodule update --init
- cd $(GRPC_DST)/third_party/protobuf && ./autogen.sh && ./configure
- make -C $(GRPC_DST)/third_party/protobuf
- sudo make -C $(GRPC_DST)/third_party/protobuf install
- sudo ldconfig
+ mkdir -p $(HOME)/openolt-agent-test-lib/grpc/$(GRPC_VER)
make -C $(GRPC_DST)
- sudo make -C $(GRPC_DST) install
- sudo ldconfig
+ make -C $(GRPC_DST) install prefix=$(HOME)/openolt-agent-test-lib/grpc/$(GRPC_VER)
-prereq-mock-lib: gtest cmock gmock-global
+prereqs-test-lib: $(gtest-target) $(cmock-target) $(gmock-global-target)
-gtest:
- # Install gtest and gmock
+$(gtest-target):
+ # Install gtest
rm -rf /tmp/googletest && cd /tmp && git clone https://github.com/google/googletest.git
- cd /tmp/googletest && git checkout release-1.8.0
- cd /tmp/googletest && cmake CMakeLists.txt
+ cd /tmp/googletest && git checkout $(GTEST_VER)
+ mkdir -p $(HOME)/openolt-agent-test-lib/gtest/$(GTEST_VER)
+ cd /tmp/googletest && cmake CMakeLists.txt -DCMAKE_INSTALL_PREFIX=$(HOME)/openolt-agent-test-lib/gtest/$(GTEST_VER)
make -C /tmp/googletest
- sudo make -C /tmp/googletest install
+ make -C /tmp/googletest install
-cmock:
+$(cmock-target):
# Install c-mock
rm -rf /tmp/C-Mock && cd /tmp && git clone https://github.com/hjagodzinski/C-Mock.git
- cd /tmp/C-Mock && git checkout 0207b3026f04bbdf0bd9d9f8dfd00945a4318251
- make -C /tmp/C-Mock
- sudo make -C /tmp/C-Mock install
+ cd /tmp/C-Mock && git checkout $(CMOCK_VER)
+ mkdir -p $(HOME)/openolt-agent-test-lib/cmock/$(CMOCK_VER)
+ make -C /tmp/C-Mock install PREFIX=$(HOME)/openolt-agent-test-lib/cmock/$(CMOCK_VER)
-gmock-global:
+$(gmock-global-target):
# Install gmock-global
rm -rf /tmp/gmock-global && cd /tmp && git clone https://github.com/apriorit/gmock-global.git
- cd /tmp/gmock-global && git checkout 1.0.2
- sudo cp -rf /tmp/gmock-global/include/gmock-global /usr/local/include/
+ cd /tmp/gmock-global && git checkout $(GMOCK_GLOBAL_VER)
+ mkdir -p $(HOME)/openolt-agent-test-lib/gmock-global/$(GMOCK_GLOBAL_VER)
+ cp -rf /tmp/gmock-global/include/gmock-global $(HOME)/openolt-agent-test-lib/gmock-global/$(GMOCK_GLOBAL_VER)
+
########################################################################
##
##
@@ -109,7 +142,7 @@
.DEFAULT_GOAL := all
-.PHONY = bcm_host_api_stubs libopenoltapi.a libopenolt.a build clean
+.PHONY = bcm_host_api_stubs libopenoltapi.a libopenolt.a build clean prereqs-system prereqs-local
all: bcm_host_api_stubs libopenoltapi.a libopenolt.a build
@@ -120,26 +153,26 @@
#TEST_SRCS = $($(filter-out src/bal_stub.cc, $(wildcard src/*.cc)))
TEST_SRCS = src/main_test.cc src/bal_mocker.cc src/test_core.cc
TEST_OBJS = $(TEST_SRCS:.cc=.o)
+
build: $(TEST_OBJS)
- $(CXX) $(shell cmock-config --libs) -L$(TEST_OPENOLT_LIB_DIR) -L/usr/lib/ -I/usr/include -I./inc -o $(TEST_BIN) $(TEST_OBJS) -lgmock -lgtest -lopenolt -lopenoltapi $(LDFLAGS)
+ $(CXX) $(shell cmock-config --libs $(HOME)/openolt-agent-test-lib/gtest/$(GTEST_VER)/lib) -L$(TEST_OPENOLT_LIB_DIR) -L/usr/lib/ -I/usr/include -I./inc -I../src -o $(TEST_BIN) $(TEST_OBJS) -lgmock -lgtest -lopenolt -lopenoltapi $(LDFLAGS)
src/%.o: src/%.cc
- $(CXX) $(CXXFLAGS) $(CXXFLAGSDEVICE) -I./inc -I../common -I/usr/include -c $< -o $@
+ $(CXX) $(CXXFLAGS) $(CXXFLAGSDEVICE) $(TEST_LIB_INC) -I./inc -I../common -I../src -I/usr/include -c $< -o $@
# bcm_host_api_stubs
-BAL_API_DIR=bal-api-3.2.3.2
bcm_host_api_stubs:
# TODO: There is temporary hack below to introduce the definition of bcmos_mutex.
- # This should ideally come as part of bal-api-3.2.3.2
+ # This should ideally come as part of bal-api-x.x.x.x
if [ -d $(BAL_API_DIR) ]; then \
echo "$(BAL_API_DIR) exists"; \
else \
- git clone https://github.com/balapi/bal-api-3.2.3.2.git ;\
- sed -i "\$$i #define BCMOLT_TM_QUEUE_KEY_TM_Q_SET_ID_DEFAULT 0" ./bal-api-3.2.3.2/include/bcmos_system.h; \
- sed -i "\$$i struct bcmos_mutex \{ pthread_mutex_t m; };" ./bal-api-3.2.3.2/include/bcmos_system.h; \
- sed -i "\$$i extern void* bcmos_calloc(uint32_t size);" ./bal-api-3.2.3.2/include/bcmos_common.h; \
- sed -i "\$$i #define BCMOLT_INTERFACE_TYPE_EPON_1_G 3" ./bal-api-3.2.3.2/include/bcmos_common.h; \
- sed -i "\$$i #define BCMOLT_INTERFACE_TYPE_EPON_10_G 4" ./bal-api-3.2.3.2/include/bcmos_common.h; \
+ git clone https://github.com/balapi/$(BAL_API_VER).git ;\
+ sed -i "\$$i #define BCMOLT_TM_QUEUE_KEY_TM_Q_SET_ID_DEFAULT 0" ./$(BAL_API_DIR)/include/bcmos_system.h; \
+ sed -i "\$$i struct bcmos_mutex \{ pthread_mutex_t m; };" ./$(BAL_API_DIR)/include/bcmos_system.h; \
+ sed -i "\$$i extern void* bcmos_calloc(uint32_t size);" ./$(BAL_API_DIR)/include/bcmos_common.h; \
+ sed -i "\$$i #define BCMOLT_INTERFACE_TYPE_EPON_1_G 3" ./$(BAL_API_DIR)/include/bcmos_common.h; \
+ sed -i "\$$i #define BCMOLT_INTERFACE_TYPE_EPON_10_G 4" ./$(BAL_API_DIR)/include/bcmos_common.h; \
fi
# openoltapi
@@ -161,16 +194,16 @@
ar cr lib/$@ $^
ranlib lib/$@
../common/%.o: ../common/%.cc
- $(CXX) $(CXXFLAGS) $(CXXFLAGSDEVICE) -I../common -I./inc -I./device/$(OPENOLTDEVICE) -c $< -o $@
+ $(CXX) $(CXXFLAGS) $(CXXFLAGSDEVICE) -I../common -I./inc -I../src -c $< -o $@
../src/%.o: ../src/%.cc
- $(CXX) $(CXXFLAGS) $(CXXFLAGSDEVICE) -I../common -I./inc -I./device/$(OPENOLTDEVICE) -c $< -o $@
+ $(CXX) $(CXXFLAGS) $(CXXFLAGSDEVICE) -I../common -I./inc -I../src -c $< -o $@
src/%.o: src/%.cc
- $(CXX) $(CXXFLAGS) $(CXXFLAGSDEVICE) -I../common -I./inc -I./device/$(OPENOLTDEVICE) -c $< -o $@
+ $(CXX) $(CXXFLAGS) $(CXXFLAGSDEVICE) -I../common -I./inc -I../src -c $< -o $@
../device/$(OPENOLTDEVICE)/%.o: ../device/$(OPENOLTDEVICE)/%.cc
- $(CXX) $(CXXFLAGS) $(CXXFLAGSDEVICE) -I../common -I./inc -I./device/$(OPENOLTDEVICE) -c $< -o $@
+ $(CXX) $(CXXFLAGS) $(CXXFLAGSDEVICE) -I../common -I./inc -I../src -c $< -o $@
test: all
- ./test_openolt --gtest_output="xml:./test_openolt_report.xml"
+ ./test_openolt --gtest_output="xml:./test_openolt_report_xunit.xml"
clean:
- rm -f src/*.o lib/*.a ../src/*.o ../common/*.o ./test_openolt ./test_openolt_report.xml
+ rm -f src/*.o lib/*.a ../src/*.o ../common/*.o ./test_openolt ./test_openolt_report_xunit.xml
diff --git a/agent/test/README.md b/agent/test/README.md
index 6a3b40a..8b34329 100644
--- a/agent/test/README.md
+++ b/agent/test/README.md
@@ -29,9 +29,7 @@
make OPENOLT_PROTO_VER=master test
```
-By default, the OPENOLT_PROTO_VER defaults to git tag *v1.0.3* of https://github.com/opencord/voltha-protos repo.
-
-Once you have successfully built and run the unit-test, the test report will be available in `test_openolt_report.xml` file in `agent/test`.
+Once you have successfully built and run the unit-test, the test report will be available in `test_openolt_report_xunit.xml` file in `agent/test`.
To clean all build artifacts and test reports, do `make clean` in `agent/test`.
## Adding new Unit Test Cases
diff --git a/agent/test/configure b/agent/test/configure
index 7c41265..f861fd7 100755
--- a/agent/test/configure
+++ b/agent/test/configure
@@ -574,8 +574,6 @@
LIBOBJS=
cross_compiling=no
subdirs=
-MFLAGS=
-MAKEFLAGS=
# Identity of this package.
PACKAGE_NAME='openolt'
diff --git a/agent/test/inc/bal_mocker.h b/agent/test/inc/bal_mocker.h
index f60c581..50b981d 100644
--- a/agent/test/inc/bal_mocker.h
+++ b/agent/test/inc/bal_mocker.h
@@ -15,7 +15,7 @@
*/
#ifndef __BAL_MOCKER_H__
#define __BAL_MOCKER_H__
-#include <cmock/cmock.h>
+#include <cmock.h>
#include <gmock-global/gmock-global.h>
#include <cstdlib>
#include <grpc++/grpc++.h>
diff --git a/agent/test/src/test_core.cc b/agent/test/src/test_core.cc
index 1d3c2ef..137faac 100644
--- a/agent/test/src/test_core.cc
+++ b/agent/test/src/test_core.cc
@@ -17,6 +17,7 @@
#include "Queue.h"
#include "bal_mocker.h"
#include "core.h"
+#include "core_data.h"
#include <future>
using namespace testing;
using namespace std;
@@ -227,7 +228,7 @@
// For testing Enable/Disable functionality
////////////////////////////////////////////////////////////////////////
-int num_of_pon_ports = 16;
+int num_of_pon_port = 16;
// Create a mock function for bcmolt_cfg_get__olt_topology_stub C++ function
MOCK_GLOBAL_FUNC2(bcmolt_cfg_get__olt_topology_stub, bcmos_errno(bcmolt_oltid, void*));
@@ -243,7 +244,7 @@
BCMOLT_CFG_INIT(&olt_cfg, olt, olt_key);
- olt_cfg.data.topology.topology_maps.len = num_of_pon_ports;
+ olt_cfg.data.topology.topology_maps.len = num_of_pon_port;
EXPECT_GLOBAL_CALL(bcmolt_cfg_get__olt_topology_stub, bcmolt_cfg_get__olt_topology_stub(_, _))
.WillOnce(DoAll(SetArg1ToBcmOltCfg(olt_cfg), Return(bal_cfg_get_stub_res)));
@@ -309,7 +310,7 @@
pon_cfg.data.state = BCMOLT_INTERFACE_STATE_INACTIVE;
EXPECT_GLOBAL_CALL(bcmolt_cfg_get__pon_intf_stub, bcmolt_cfg_get__pon_intf_stub(_, _))
- .Times(num_of_pon_ports)
+ .Times(num_of_pon_port)
.WillRepeatedly(DoAll(SetArg1ToBcmOltPonCfg(pon_cfg), Return(olt_cfg_get_pon_stub_res)));
bcmolt_tm_sched_cfg tm_sched_cfg;
@@ -318,7 +319,7 @@
tm_sched_cfg.data.state = BCMOLT_CONFIG_STATE_NOT_CONFIGURED;
EXPECT_GLOBAL_CALL(bcmolt_cfg_get__tm_sched_stub, bcmolt_cfg_get__tm_sched_stub(_, _))
- .Times(num_of_pon_ports)
+ .Times(num_of_pon_port)
.WillRepeatedly(DoAll(SetArg1ToBcmOltTmSchedCfg(tm_sched_cfg), Return(olt_cfg_get_tmstub_res)));
olt_reenable_res = Reenable_();
@@ -343,10 +344,10 @@
pon_cfg.data.state = BCMOLT_INTERFACE_STATE_INACTIVE;
EXPECT_GLOBAL_CALL(bcmolt_cfg_get__pon_intf_stub, bcmolt_cfg_get__pon_intf_stub(_, _))
- .Times(num_of_pon_ports)
+ .Times(num_of_pon_port)
.WillRepeatedly(DoAll(SetArg1ToBcmOltPonCfg(pon_cfg), Return(olt_cfg_get_pon_stub_res)));
EXPECT_CALL(balMock,bcmolt_oper_submit(_, _))
- .Times(num_of_pon_ports)
+ .Times(num_of_pon_port)
.WillRepeatedly(Return(olt_oper_res));
olt_reenable_res = Reenable_();
@@ -372,7 +373,7 @@
BCMOLT_CFG_INIT(&olt_cfg, olt, olt_key);
- olt_cfg.data.topology.topology_maps.len = num_of_pon_ports;
+ olt_cfg.data.topology.topology_maps.len = num_of_pon_port;
}
virtual void TearDown() {