Girish Gowdra | a707e7c | 2019-11-07 11:36:13 +0530 | [diff] [blame] | 1 | # Copyright 2018-present Open Networking Foundation |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 2 | # |
Girish Gowdra | a707e7c | 2019-11-07 11:36:13 +0530 | [diff] [blame] | 3 | # 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 Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 6 | # |
Girish Gowdra | a707e7c | 2019-11-07 11:36:13 +0530 | [diff] [blame] | 7 | # http://www.apache.org/licenses/LICENSE-2.0 |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 8 | # |
Girish Gowdra | a707e7c | 2019-11-07 11:36:13 +0530 | [diff] [blame] | 9 | # 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 Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 14 | |
| 15 | ######################################################################## |
| 16 | ## |
| 17 | ## |
| 18 | ## Config |
| 19 | ## |
| 20 | ## |
| 21 | TOP_DIR=`pwd` |
| 22 | OPENOLTDEVICE ?= 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 |
| 28 | OPENOLT_PROTO_VER ?= v1.0.3 |
| 29 | |
Girish Gowdra | ddf9a16 | 2020-01-27 12:56:27 +0530 | [diff] [blame] | 30 | GTEST_VER ?= release-1.8.0 |
| 31 | gtest-target = $(HOME)/openolt-agent-test-lib/gtest/$(GTEST_VER)/lib/libgtest.a |
| 32 | |
| 33 | CMOCK_VER ?= 0207b30 |
| 34 | cmock-target = $(HOME)/openolt-agent-test-lib/cmock/$(CMOCK_VER)/include/cmock.h |
| 35 | |
| 36 | GMOCK_GLOBAL_VER ?= 1.0.2 |
| 37 | gmock-global-target = $(HOME)/openolt-agent-test-lib/gmock-global/$(GMOCK_GLOBAL_VER)/gmock-global/gmock-global.h |
| 38 | |
| 39 | |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 40 | # GRPC installation |
| 41 | GRPC_ADDR = https://github.com/grpc/grpc |
| 42 | GRPC_DST = /tmp/grpc |
| 43 | GRPC_VER = v1.10.x |
Girish Gowdra | ddf9a16 | 2020-01-27 12:56:27 +0530 | [diff] [blame] | 44 | grpc-cpp-plugin-bin = $(HOME)/openolt-agent-test-lib/grpc/$(GRPC_VER)/bin/grpc_cpp_plugin |
| 45 | |
| 46 | # Protobuf installation |
| 47 | PROTOBUF_VER = 3.5.0 |
| 48 | PROTOBUF_ADDR = https://github.com/protocolbuffers/protobuf/releases/download/v$(PROTOBUF_VER)/protobuf-cpp-$(PROTOBUF_VER).tar.gz |
| 49 | PROTOBUF_DST = /tmp/protobuf-$(PROTOBUF_VER) |
| 50 | protoc-bin = $(HOME)/openolt-agent-test-lib/grpc/$(GRPC_VER)/bin/protoc |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 51 | |
| 52 | USER := $(shell echo $(USER)) |
| 53 | # |
| 54 | ######################################################################## |
| 55 | ## |
| 56 | ## |
| 57 | ## Install prerequisites |
| 58 | ## |
| 59 | ## |
| 60 | |
| 61 | CXX = g++-4.9 |
| 62 | CXXFLAGS += -g -O2 |
Girish Gowdra | ddf9a16 | 2020-01-27 12:56:27 +0530 | [diff] [blame] | 63 | CXXFLAGS += $(shell PKG_CONFIG_PATH=$(HOME)/openolt-agent-test-lib/grpc/$(GRPC_VER)/lib/pkgconfig pkg-config --cflags-only-I grpc++) |
| 64 | CPPFLAGS += `PKG_CONFIG_PATH=$(HOME)/openolt-agent-test-lib/grpc/$(GRPC_VER)/lib/pkgconfig pkg-config --cflags protobuf grpc` |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 65 | CXXFLAGS += -std=c++11 -fpermissive -Wno-literal-suffix |
| 66 | CXXFLAGS += -DTEST_MODE -DENABLE_LOG |
| 67 | LDFLAGS += |
Girish Gowdra | ddf9a16 | 2020-01-27 12:56:27 +0530 | [diff] [blame] | 68 | LDFLAGS += `PKG_CONFIG_PATH=$(HOME)/openolt-agent-test-lib/grpc/$(GRPC_VER)/lib/pkgconfig pkg-config --libs protobuf grpc++ grpc` -ldl -lgpr |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 69 | CXXFLAGSDEVICE = -I../device -I../device/$(OPENOLTDEVICE) -I../device/generic |
| 70 | |
| 71 | export CXX CXXFLAGS OPENOLT_PROTO_VER |
| 72 | |
Girish Gowdra | ddf9a16 | 2020-01-27 12:56:27 +0530 | [diff] [blame] | 73 | BAL_API_VER=bal-api-3.2.3.2 |
| 74 | BAL_API_DIR=$(BAL_API_VER) |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 75 | BALLIBNAME=bcm_host_api_stubs |
| 76 | BALLIBDIR=$(BAL_API_DIR)/stubs |
| 77 | BAL_INC = -I$(BAL_API_DIR)/include \ |
| 78 | -I$(BAL_API_DIR)/include/object_model |
Girish Gowdra | ddf9a16 | 2020-01-27 12:56:27 +0530 | [diff] [blame] | 79 | TEST_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) |
| 82 | CXXFLAGS += $(BAL_INC) $(TEST_LIB_INC) |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 83 | |
| 84 | |
Girish Gowdra | ddf9a16 | 2020-01-27 12:56:27 +0530 | [diff] [blame] | 85 | prereqs-system: |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 86 | 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 Gowdra | ddf9a16 | 2020-01-27 12:56:27 +0530 | [diff] [blame] | 89 | prereqs-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 Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 104 | rm -rf $(GRPC_DST) |
Girish Gowdra | ddf9a16 | 2020-01-27 12:56:27 +0530 | [diff] [blame] | 105 | cd /tmp && git clone -b $(GRPC_VER) $(GRPC_ADDR) $(GRPC_DST) |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 106 | cd $(GRPC_DST) && git submodule update --init |
Girish Gowdra | ddf9a16 | 2020-01-27 12:56:27 +0530 | [diff] [blame] | 107 | mkdir -p $(HOME)/openolt-agent-test-lib/grpc/$(GRPC_VER) |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 108 | make -C $(GRPC_DST) |
Girish Gowdra | ddf9a16 | 2020-01-27 12:56:27 +0530 | [diff] [blame] | 109 | make -C $(GRPC_DST) install prefix=$(HOME)/openolt-agent-test-lib/grpc/$(GRPC_VER) |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 110 | |
Girish Gowdra | ddf9a16 | 2020-01-27 12:56:27 +0530 | [diff] [blame] | 111 | prereqs-test-lib: $(gtest-target) $(cmock-target) $(gmock-global-target) |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 112 | |
Girish Gowdra | ddf9a16 | 2020-01-27 12:56:27 +0530 | [diff] [blame] | 113 | $(gtest-target): |
| 114 | # Install gtest |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 115 | rm -rf /tmp/googletest && cd /tmp && git clone https://github.com/google/googletest.git |
Girish Gowdra | ddf9a16 | 2020-01-27 12:56:27 +0530 | [diff] [blame] | 116 | 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 Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 119 | make -C /tmp/googletest |
Girish Gowdra | ddf9a16 | 2020-01-27 12:56:27 +0530 | [diff] [blame] | 120 | make -C /tmp/googletest install |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 121 | |
Girish Gowdra | ddf9a16 | 2020-01-27 12:56:27 +0530 | [diff] [blame] | 122 | $(cmock-target): |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 123 | # Install c-mock |
| 124 | rm -rf /tmp/C-Mock && cd /tmp && git clone https://github.com/hjagodzinski/C-Mock.git |
Girish Gowdra | ddf9a16 | 2020-01-27 12:56:27 +0530 | [diff] [blame] | 125 | 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 Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 128 | |
Girish Gowdra | ddf9a16 | 2020-01-27 12:56:27 +0530 | [diff] [blame] | 129 | $(gmock-global-target): |
Jason Huang | bf45ffb | 2019-10-30 17:29:02 +0800 | [diff] [blame] | 130 | # Install gmock-global |
| 131 | rm -rf /tmp/gmock-global && cd /tmp && git clone https://github.com/apriorit/gmock-global.git |
Girish Gowdra | ddf9a16 | 2020-01-27 12:56:27 +0530 | [diff] [blame] | 132 | 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 Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 136 | ######################################################################## |
| 137 | ## |
| 138 | ## |
| 139 | ## build |
| 140 | ## |
| 141 | ## |
| 142 | |
| 143 | .DEFAULT_GOAL := all |
| 144 | |
Girish Gowdra | ddf9a16 | 2020-01-27 12:56:27 +0530 | [diff] [blame] | 145 | .PHONY = bcm_host_api_stubs libopenoltapi.a libopenolt.a build clean prereqs-system prereqs-local |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 146 | |
| 147 | all: bcm_host_api_stubs libopenoltapi.a libopenolt.a build |
| 148 | |
| 149 | # test |
| 150 | TEST_OPENOLT_LIB_DIR=./lib |
| 151 | TEST_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 Ghosh | fcad4d3 | 2019-11-13 10:24:55 +0000 | [diff] [blame] | 154 | TEST_SRCS = src/main_test.cc src/bal_mocker.cc src/test_core.cc |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 155 | TEST_OBJS = $(TEST_SRCS:.cc=.o) |
Girish Gowdra | ddf9a16 | 2020-01-27 12:56:27 +0530 | [diff] [blame] | 156 | |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 157 | build: $(TEST_OBJS) |
Girish Gowdra | ddf9a16 | 2020-01-27 12:56:27 +0530 | [diff] [blame] | 158 | $(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 Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 159 | src/%.o: src/%.cc |
Girish Gowdra | ddf9a16 | 2020-01-27 12:56:27 +0530 | [diff] [blame] | 160 | $(CXX) $(CXXFLAGS) $(CXXFLAGSDEVICE) $(TEST_LIB_INC) -I./inc -I../common -I../src -I/usr/include -c $< -o $@ |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 161 | |
| 162 | |
| 163 | # bcm_host_api_stubs |
Chaitrashree G S | fd15c8c | 2019-09-09 18:46:15 -0400 | [diff] [blame] | 164 | bcm_host_api_stubs: |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 165 | # TODO: There is temporary hack below to introduce the definition of bcmos_mutex. |
Girish Gowdra | ddf9a16 | 2020-01-27 12:56:27 +0530 | [diff] [blame] | 166 | # This should ideally come as part of bal-api-x.x.x.x |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 167 | if [ -d $(BAL_API_DIR) ]; then \ |
| 168 | echo "$(BAL_API_DIR) exists"; \ |
| 169 | else \ |
Girish Gowdra | ddf9a16 | 2020-01-27 12:56:27 +0530 | [diff] [blame] | 170 | 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 Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 176 | fi |
| 177 | |
| 178 | # openoltapi |
| 179 | OPENOLT_PROTOS_DIR = ../../protos |
| 180 | OPENOLT_API_LIB = $(OPENOLT_PROTOS_DIR)/libopenoltapi.a |
| 181 | CXXFLAGS += -I$(OPENOLT_PROTOS_DIR) -I$(OPENOLT_PROTOS_DIR)/googleapis/gens |
| 182 | libopenoltapi.a: |
| 183 | make -C $(OPENOLT_PROTOS_DIR) all |
| 184 | mkdir -p lib |
| 185 | cp $(OPENOLT_PROTOS_DIR)/$@ lib/ |
| 186 | libproto-clean: |
| 187 | make -C $(OPENOLT_PROTOS_DIR) clean |
| 188 | |
| 189 | # openolt |
| 190 | OPENOLT_SRCS = $(wildcard ../src/*.cc) ../common/server.cc $(wildcard ../device/$(OPENOLTDEVICE)/*.cc) src/bal_stub.cc |
| 191 | OPENOLT_OBJS = $(OPENOLT_SRCS:.cc=.o) |
| 192 | libopenolt.a: $(OPENOLT_OBJS) |
| 193 | mkdir -p lib |
| 194 | ar cr lib/$@ $^ |
| 195 | ranlib lib/$@ |
| 196 | ../common/%.o: ../common/%.cc |
Girish Gowdra | ddf9a16 | 2020-01-27 12:56:27 +0530 | [diff] [blame] | 197 | $(CXX) $(CXXFLAGS) $(CXXFLAGSDEVICE) -I../common -I./inc -I../src -c $< -o $@ |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 198 | ../src/%.o: ../src/%.cc |
Girish Gowdra | ddf9a16 | 2020-01-27 12:56:27 +0530 | [diff] [blame] | 199 | $(CXX) $(CXXFLAGS) $(CXXFLAGSDEVICE) -I../common -I./inc -I../src -c $< -o $@ |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 200 | src/%.o: src/%.cc |
Girish Gowdra | ddf9a16 | 2020-01-27 12:56:27 +0530 | [diff] [blame] | 201 | $(CXX) $(CXXFLAGS) $(CXXFLAGSDEVICE) -I../common -I./inc -I../src -c $< -o $@ |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 202 | ../device/$(OPENOLTDEVICE)/%.o: ../device/$(OPENOLTDEVICE)/%.cc |
Girish Gowdra | ddf9a16 | 2020-01-27 12:56:27 +0530 | [diff] [blame] | 203 | $(CXX) $(CXXFLAGS) $(CXXFLAGSDEVICE) -I../common -I./inc -I../src -c $< -o $@ |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 204 | |
| 205 | test: all |
Girish Gowdra | ddf9a16 | 2020-01-27 12:56:27 +0530 | [diff] [blame] | 206 | ./test_openolt --gtest_output="xml:./test_openolt_report_xunit.xml" |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 207 | |
| 208 | clean: |
Girish Gowdra | ddf9a16 | 2020-01-27 12:56:27 +0530 | [diff] [blame] | 209 | rm -f src/*.o lib/*.a ../src/*.o ../common/*.o ./test_openolt ./test_openolt_report_xunit.xml |