blob: 2d700cd3285033a9c201ec2b3995579244178b96 [file] [log] [blame]
Girish Gowdraa707e7c2019-11-07 11:36:13 +05301# Copyright 2018-present Open Networking Foundation
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +00002#
Girish Gowdraa707e7c2019-11-07 11:36:13 +05303# Licensed under the Apache License, Version 2.0 (the "License");
4# you may not use this file except in compliance with the License.
5# You may obtain a copy of the License at
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +00006#
Girish Gowdraa707e7c2019-11-07 11:36:13 +05307# http://www.apache.org/licenses/LICENSE-2.0
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +00008#
Girish Gowdraa707e7c2019-11-07 11:36:13 +05309# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS,
11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12# See the License for the specific language governing permissions and
13# limitations under the License.
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +000014
15########################################################################
16##
17##
18## Config
19##
20##
21TOP_DIR=`pwd`
22OPENOLTDEVICE ?= asfvolt16
23
24# OpenOLT Proto version.
25# This specifies the GIT tag in https://github.com/opencord/voltha-protos
26# repo that we need to refer to, to pick the right version of
27# openolt.proto and tech_profile.proto
28OPENOLT_PROTO_VER ?= v1.0.3
29
Girish Gowdraddf9a162020-01-27 12:56:27 +053030GTEST_VER ?= release-1.8.0
31gtest-target = $(HOME)/openolt-agent-test-lib/gtest/$(GTEST_VER)/lib/libgtest.a
32
33CMOCK_VER ?= 0207b30
34cmock-target = $(HOME)/openolt-agent-test-lib/cmock/$(CMOCK_VER)/include/cmock.h
35
36GMOCK_GLOBAL_VER ?= 1.0.2
37gmock-global-target = $(HOME)/openolt-agent-test-lib/gmock-global/$(GMOCK_GLOBAL_VER)/gmock-global/gmock-global.h
38
39
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +000040# GRPC installation
41GRPC_ADDR = https://github.com/grpc/grpc
42GRPC_DST = /tmp/grpc
43GRPC_VER = v1.10.x
Girish Gowdraddf9a162020-01-27 12:56:27 +053044grpc-cpp-plugin-bin = $(HOME)/openolt-agent-test-lib/grpc/$(GRPC_VER)/bin/grpc_cpp_plugin
45
46# Protobuf installation
47PROTOBUF_VER = 3.5.0
48PROTOBUF_ADDR = https://github.com/protocolbuffers/protobuf/releases/download/v$(PROTOBUF_VER)/protobuf-cpp-$(PROTOBUF_VER).tar.gz
49PROTOBUF_DST = /tmp/protobuf-$(PROTOBUF_VER)
50protoc-bin = $(HOME)/openolt-agent-test-lib/grpc/$(GRPC_VER)/bin/protoc
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +000051
52USER := $(shell echo $(USER))
53#
54########################################################################
55##
56##
57## Install prerequisites
58##
59##
60
61CXX = g++-4.9
62CXXFLAGS += -g -O2
Girish Gowdraddf9a162020-01-27 12:56:27 +053063CXXFLAGS += $(shell PKG_CONFIG_PATH=$(HOME)/openolt-agent-test-lib/grpc/$(GRPC_VER)/lib/pkgconfig pkg-config --cflags-only-I grpc++)
64CPPFLAGS += `PKG_CONFIG_PATH=$(HOME)/openolt-agent-test-lib/grpc/$(GRPC_VER)/lib/pkgconfig pkg-config --cflags protobuf grpc`
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +000065CXXFLAGS += -std=c++11 -fpermissive -Wno-literal-suffix
66CXXFLAGS += -DTEST_MODE -DENABLE_LOG
67LDFLAGS +=
Girish Gowdraddf9a162020-01-27 12:56:27 +053068LDFLAGS += `PKG_CONFIG_PATH=$(HOME)/openolt-agent-test-lib/grpc/$(GRPC_VER)/lib/pkgconfig pkg-config --libs protobuf grpc++ grpc` -ldl -lgpr
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +000069CXXFLAGSDEVICE = -I../device -I../device/$(OPENOLTDEVICE) -I../device/generic
70
71export CXX CXXFLAGS OPENOLT_PROTO_VER
72
Girish Gowdraddf9a162020-01-27 12:56:27 +053073BAL_API_VER=bal-api-3.2.3.2
74BAL_API_DIR=$(BAL_API_VER)
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +000075BALLIBNAME=bcm_host_api_stubs
76BALLIBDIR=$(BAL_API_DIR)/stubs
77BAL_INC = -I$(BAL_API_DIR)/include \
78 -I$(BAL_API_DIR)/include/object_model
Girish Gowdraddf9a162020-01-27 12:56:27 +053079TEST_LIB_INC = -I$(HOME)/openolt-agent-test-lib/gtest/$(GTEST_VER)/include \
80 -I$(HOME)/openolt-agent-test-lib/cmock/$(CMOCK_VER)/include \
81 -I$(HOME)/openolt-agent-test-lib/gmock-global/$(GMOCK_GLOBAL_VER)
82CXXFLAGS += $(BAL_INC) $(TEST_LIB_INC)
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +000083
84
Girish Gowdraddf9a162020-01-27 12:56:27 +053085prereqs-system:
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +000086 sudo apt-get -q -y install git pkg-config build-essential autoconf libtool libgflags-dev libgtest-dev clang libc++-dev unzip docker.io
87 sudo apt-get install -y build-essential autoconf libssl-dev gawk debhelper dh-systemd init-system-helpers curl cmake ccache g++-4.9
88
Girish Gowdraddf9a162020-01-27 12:56:27 +053089prereqs-local: $(protoc-bin) $(grpc-cpp-plugin-bin) prereqs-test-lib
90
91$(protoc-bin):
92 # Install protobuf
93 rm -rf $(PROTOBUF_DST)
94 cd /tmp && wget $(PROTOBUF_ADDR)
95 cd /tmp && tar -zxvf protobuf-cpp-$(PROTOBUF_VER).tar.gz
96 cd $(PROTOBUF_DST) && ./autogen.sh
97 mkdir -p $(HOME)/openolt-agent-test-lib/grpc/$(GRPC_VER)
98 cd $(PROTOBUF_DST) && ./configure --prefix=$(HOME)/openolt-agent-test-lib/grpc/$(GRPC_VER)
99 make -C $(PROTOBUF_DST)
100 make -C $(PROTOBUF_DST) install
101
102$(grpc-cpp-plugin-bin):
103 # Install GRPC, protoc
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +0000104 rm -rf $(GRPC_DST)
Girish Gowdraddf9a162020-01-27 12:56:27 +0530105 cd /tmp && git clone -b $(GRPC_VER) $(GRPC_ADDR) $(GRPC_DST)
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +0000106 cd $(GRPC_DST) && git submodule update --init
Girish Gowdraddf9a162020-01-27 12:56:27 +0530107 mkdir -p $(HOME)/openolt-agent-test-lib/grpc/$(GRPC_VER)
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +0000108 make -C $(GRPC_DST)
Girish Gowdraddf9a162020-01-27 12:56:27 +0530109 make -C $(GRPC_DST) install prefix=$(HOME)/openolt-agent-test-lib/grpc/$(GRPC_VER)
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +0000110
Girish Gowdraddf9a162020-01-27 12:56:27 +0530111prereqs-test-lib: $(gtest-target) $(cmock-target) $(gmock-global-target)
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +0000112
Girish Gowdraddf9a162020-01-27 12:56:27 +0530113$(gtest-target):
114 # Install gtest
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +0000115 rm -rf /tmp/googletest && cd /tmp && git clone https://github.com/google/googletest.git
Girish Gowdraddf9a162020-01-27 12:56:27 +0530116 cd /tmp/googletest && git checkout $(GTEST_VER)
117 mkdir -p $(HOME)/openolt-agent-test-lib/gtest/$(GTEST_VER)
118 cd /tmp/googletest && cmake CMakeLists.txt -DCMAKE_INSTALL_PREFIX=$(HOME)/openolt-agent-test-lib/gtest/$(GTEST_VER)
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +0000119 make -C /tmp/googletest
Girish Gowdraddf9a162020-01-27 12:56:27 +0530120 make -C /tmp/googletest install
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +0000121
Girish Gowdraddf9a162020-01-27 12:56:27 +0530122$(cmock-target):
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +0000123 # Install c-mock
124 rm -rf /tmp/C-Mock && cd /tmp && git clone https://github.com/hjagodzinski/C-Mock.git
Girish Gowdraddf9a162020-01-27 12:56:27 +0530125 cd /tmp/C-Mock && git checkout $(CMOCK_VER)
126 mkdir -p $(HOME)/openolt-agent-test-lib/cmock/$(CMOCK_VER)
127 make -C /tmp/C-Mock install PREFIX=$(HOME)/openolt-agent-test-lib/cmock/$(CMOCK_VER)
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +0000128
Girish Gowdraddf9a162020-01-27 12:56:27 +0530129$(gmock-global-target):
Jason Huangbf45ffb2019-10-30 17:29:02 +0800130 # Install gmock-global
131 rm -rf /tmp/gmock-global && cd /tmp && git clone https://github.com/apriorit/gmock-global.git
Girish Gowdraddf9a162020-01-27 12:56:27 +0530132 cd /tmp/gmock-global && git checkout $(GMOCK_GLOBAL_VER)
133 mkdir -p $(HOME)/openolt-agent-test-lib/gmock-global/$(GMOCK_GLOBAL_VER)
134 cp -rf /tmp/gmock-global/include/gmock-global $(HOME)/openolt-agent-test-lib/gmock-global/$(GMOCK_GLOBAL_VER)
135
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +0000136########################################################################
137##
138##
139## build
140##
141##
142
143.DEFAULT_GOAL := all
144
Girish Gowdraddf9a162020-01-27 12:56:27 +0530145.PHONY = bcm_host_api_stubs libopenoltapi.a libopenolt.a build clean prereqs-system prereqs-local
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +0000146
147all: bcm_host_api_stubs libopenoltapi.a libopenolt.a build
148
149# test
150TEST_OPENOLT_LIB_DIR=./lib
151TEST_BIN=test_openolt
152# The below way of getting source files is not working
153#TEST_SRCS = $($(filter-out src/bal_stub.cc, $(wildcard src/*.cc)))
Amit Ghoshfcad4d32019-11-13 10:24:55 +0000154TEST_SRCS = src/main_test.cc src/bal_mocker.cc src/test_core.cc
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +0000155TEST_OBJS = $(TEST_SRCS:.cc=.o)
Girish Gowdraddf9a162020-01-27 12:56:27 +0530156
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +0000157build: $(TEST_OBJS)
Girish Gowdraddf9a162020-01-27 12:56:27 +0530158 $(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)
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +0000159src/%.o: src/%.cc
Girish Gowdraddf9a162020-01-27 12:56:27 +0530160 $(CXX) $(CXXFLAGS) $(CXXFLAGSDEVICE) $(TEST_LIB_INC) -I./inc -I../common -I../src -I/usr/include -c $< -o $@
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +0000161
162
163# bcm_host_api_stubs
Chaitrashree G Sfd15c8c2019-09-09 18:46:15 -0400164bcm_host_api_stubs:
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +0000165 # TODO: There is temporary hack below to introduce the definition of bcmos_mutex.
Girish Gowdraddf9a162020-01-27 12:56:27 +0530166 # This should ideally come as part of bal-api-x.x.x.x
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +0000167 if [ -d $(BAL_API_DIR) ]; then \
168 echo "$(BAL_API_DIR) exists"; \
169 else \
Girish Gowdraddf9a162020-01-27 12:56:27 +0530170 git clone https://github.com/balapi/$(BAL_API_VER).git ;\
171 sed -i "\$$i #define BCMOLT_TM_QUEUE_KEY_TM_Q_SET_ID_DEFAULT 0" ./$(BAL_API_DIR)/include/bcmos_system.h; \
172 sed -i "\$$i struct bcmos_mutex \{ pthread_mutex_t m; };" ./$(BAL_API_DIR)/include/bcmos_system.h; \
173 sed -i "\$$i extern void* bcmos_calloc(uint32_t size);" ./$(BAL_API_DIR)/include/bcmos_common.h; \
174 sed -i "\$$i #define BCMOLT_INTERFACE_TYPE_EPON_1_G 3" ./$(BAL_API_DIR)/include/bcmos_common.h; \
175 sed -i "\$$i #define BCMOLT_INTERFACE_TYPE_EPON_10_G 4" ./$(BAL_API_DIR)/include/bcmos_common.h; \
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +0000176 fi
177
178# openoltapi
179OPENOLT_PROTOS_DIR = ../../protos
180OPENOLT_API_LIB = $(OPENOLT_PROTOS_DIR)/libopenoltapi.a
181CXXFLAGS += -I$(OPENOLT_PROTOS_DIR) -I$(OPENOLT_PROTOS_DIR)/googleapis/gens
182libopenoltapi.a:
183 make -C $(OPENOLT_PROTOS_DIR) all
184 mkdir -p lib
185 cp $(OPENOLT_PROTOS_DIR)/$@ lib/
186libproto-clean:
187 make -C $(OPENOLT_PROTOS_DIR) clean
188
189# openolt
190OPENOLT_SRCS = $(wildcard ../src/*.cc) ../common/server.cc $(wildcard ../device/$(OPENOLTDEVICE)/*.cc) src/bal_stub.cc
191OPENOLT_OBJS = $(OPENOLT_SRCS:.cc=.o)
192libopenolt.a: $(OPENOLT_OBJS)
193 mkdir -p lib
194 ar cr lib/$@ $^
195 ranlib lib/$@
196../common/%.o: ../common/%.cc
Girish Gowdraddf9a162020-01-27 12:56:27 +0530197 $(CXX) $(CXXFLAGS) $(CXXFLAGSDEVICE) -I../common -I./inc -I../src -c $< -o $@
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +0000198../src/%.o: ../src/%.cc
Girish Gowdraddf9a162020-01-27 12:56:27 +0530199 $(CXX) $(CXXFLAGS) $(CXXFLAGSDEVICE) -I../common -I./inc -I../src -c $< -o $@
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +0000200src/%.o: src/%.cc
Girish Gowdraddf9a162020-01-27 12:56:27 +0530201 $(CXX) $(CXXFLAGS) $(CXXFLAGSDEVICE) -I../common -I./inc -I../src -c $< -o $@
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +0000202../device/$(OPENOLTDEVICE)/%.o: ../device/$(OPENOLTDEVICE)/%.cc
Girish Gowdraddf9a162020-01-27 12:56:27 +0530203 $(CXX) $(CXXFLAGS) $(CXXFLAGSDEVICE) -I../common -I./inc -I../src -c $< -o $@
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +0000204
205test: all
Girish Gowdraddf9a162020-01-27 12:56:27 +0530206 ./test_openolt --gtest_output="xml:./test_openolt_report_xunit.xml"
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +0000207
208clean:
Girish Gowdraddf9a162020-01-27 12:56:27 +0530209 rm -f src/*.o lib/*.a ../src/*.o ../common/*.o ./test_openolt ./test_openolt_report_xunit.xml