blob: e7757caf084765658330de5306f9781f6afc761b [file] [log] [blame]
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +00001/*
2 Copyright (C) 2018 Open Networking Foundation
3
4 This program is free software: you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation, either version 3 of the License, or
7 (at your option) any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with this program. If not, see <http://www.gnu.org/licenses/>.
16*/
17#include "gtest/gtest.h"
18#include "bal_mocker.h"
19#include "core.h"
20
Jason Huangbf45ffb2019-10-30 17:29:02 +080021using namespace testing;
22
23class TestOltEnable : public Test {
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +000024 protected:
25 virtual void SetUp() {
26 }
27
28 virtual void TearDown() {
29 // Code here will be called immediately after each test
30 // (right before the destructor).
31 }
32};
33
Jason Huangbf45ffb2019-10-30 17:29:02 +080034// This is used to set custom bcmolt_cfg value to bcmolt_cfg pointer coming in
35// bcmolt_cfg_get_stub.
36ACTION_P(SetArg1ToBcmOltCfg, value) { *static_cast<bcmolt_olt_cfg*>(arg1) = value; };
37
38
39// Create a mock function for bcmolt_cfg_get_stub C++ function
40MOCK_GLOBAL_FUNC2(bcmolt_cfg_get_stub, bcmos_errno(bcmolt_oltid, void*));
41
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +000042
43// Test Fixture for OltEnable
44
45// Test 1: OltEnableSuccess case
46TEST_F(TestOltEnable, OltEnableSuccess){
Jason Huangbf45ffb2019-10-30 17:29:02 +080047 // NiceMock is used to suppress 'WillByDefault' return errors.
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +000048 // This is described in https://github.com/arangodb-helper/gtest/blob/master/googlemock/docs/CookBook.md
Jason Huangbf45ffb2019-10-30 17:29:02 +080049 NiceMock<BalMocker> balMock;
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +000050 bcmos_errno host_init_res = BCM_ERR_OK;
Jason Huangbf45ffb2019-10-30 17:29:02 +080051 bcmos_errno bal_cfg_get_stub_res = BCM_ERR_OK;
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +000052 bcmos_errno bal_cfg_get_res = BCM_ERR_NOT_CONNECTED;
53 bcmos_errno olt_oper_res = BCM_ERR_OK;
54
Jason Huangbf45ffb2019-10-30 17:29:02 +080055 bcmolt_olt_cfg olt_cfg = { };
56 bcmolt_olt_key olt_key = { };
57 BCMOLT_CFG_INIT(&olt_cfg, olt, olt_key);
58 olt_cfg.data.bal_state = BCMOLT_BAL_STATE_BAL_AND_SWITCH_READY;
59
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +000060 Status olt_enable_res;
61
Jason Huangbf45ffb2019-10-30 17:29:02 +080062 ON_CALL(balMock, bcmolt_host_init(_)).WillByDefault(Return(host_init_res));
63 EXPECT_GLOBAL_CALL(bcmolt_cfg_get_stub, bcmolt_cfg_get_stub(_, _))
64 .WillOnce(DoAll(SetArg1ToBcmOltCfg(olt_cfg), Return(bal_cfg_get_stub_res)));
65 EXPECT_CALL(balMock, bcmolt_cfg_get(_, _))
66 .Times(BCM_MAX_DEVS_PER_LINE_CARD)
67 .WillRepeatedly(Return(bal_cfg_get_res));
68 ON_CALL(balMock, bcmolt_oper_submit(_, _)).WillByDefault(Return(olt_oper_res));
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +000069
70 olt_enable_res = Enable_(1, NULL);
71 ASSERT_TRUE( olt_enable_res.error_message() == Status::OK.error_message() );
72}
73
74// Test 2: OltEnableFail_host_init_fail
75TEST_F(TestOltEnable, OltEnableFail_host_init_fail) {
Jason Huangbf45ffb2019-10-30 17:29:02 +080076 // NiceMock is used to suppress 'WillByDefault' return errors.
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +000077 // This is described in https://github.com/arangodb-helper/gtest/blob/master/googlemock/docs/CookBook.md
Jason Huangbf45ffb2019-10-30 17:29:02 +080078 NiceMock<BalMocker> balMock;
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +000079 bcmos_errno host_init_res = BCM_ERR_INTERNAL;
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +000080
81 Status olt_enable_res;
82
Jason Huangbf45ffb2019-10-30 17:29:02 +080083 // Ensure that the state of the OLT is in deactivated to start with..
84 state.deactivate();
85
86 ON_CALL(balMock, bcmolt_host_init(_)).WillByDefault(Return(host_init_res));
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +000087
88 olt_enable_res = Enable_(1, NULL);
89 ASSERT_TRUE( olt_enable_res.error_message() != Status::OK.error_message() );
90}
91
92// Test 3: OltEnableSuccess_PON_Device_Connected
93TEST_F(TestOltEnable, OltEnableSuccess_PON_Device_Connected) {
Jason Huangbf45ffb2019-10-30 17:29:02 +080094
95 // NiceMock is used to suppress 'WillByDefault' return errors.
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +000096 // This is described in https://github.com/arangodb-helper/gtest/blob/master/googlemock/docs/CookBook.md
Jason Huangbf45ffb2019-10-30 17:29:02 +080097 NiceMock<BalMocker> balMock;
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +000098 bcmos_errno host_init_res = BCM_ERR_OK;
Jason Huangbf45ffb2019-10-30 17:29:02 +080099 bcmos_errno bal_cfg_get_stub_res = BCM_ERR_OK;
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +0000100 bcmos_errno bal_cfg_get_res = BCM_ERR_OK;
Jason Huangbf45ffb2019-10-30 17:29:02 +0800101 bcmos_errno olt_oper_res = BCM_ERR_OK;
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +0000102
Jason Huangbf45ffb2019-10-30 17:29:02 +0800103 bcmolt_olt_cfg olt_cfg = { };
104 bcmolt_olt_key olt_key = { };
105 BCMOLT_CFG_INIT(&olt_cfg, olt, olt_key);
106 olt_cfg.data.bal_state = BCMOLT_BAL_STATE_BAL_AND_SWITCH_READY;
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +0000107
108 Status olt_enable_res;
109
110 // Ensure that the state of the OLT is in deactivated to start with..
111 state.deactivate();
112
Jason Huangbf45ffb2019-10-30 17:29:02 +0800113 ON_CALL(balMock, bcmolt_host_init(_)).WillByDefault(Return(host_init_res));
114 EXPECT_GLOBAL_CALL(bcmolt_cfg_get_stub, bcmolt_cfg_get_stub(_, _))
115 .WillOnce(DoAll(SetArg1ToBcmOltCfg(olt_cfg), Return(bal_cfg_get_stub_res)));
116 EXPECT_CALL(balMock, bcmolt_cfg_get(_, _))
117 .Times(BCM_MAX_DEVS_PER_LINE_CARD)
118 .WillRepeatedly(Return(bal_cfg_get_res));
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +0000119
120 olt_enable_res = Enable_(1, NULL);
Jason Huangbf45ffb2019-10-30 17:29:02 +0800121 ASSERT_TRUE( olt_enable_res.error_message() == Status::OK.error_message() );
122
123}
124
125// Test 4: OltEnableFail_All_PON_Enable_Fail
126TEST_F(TestOltEnable, OltEnableFail_All_PON_Enable_Fail) {
127
128 // NiceMock is used to suppress 'WillByDefault' return errors.
129 // This is described in https://github.com/arangodb-helper/gtest/blob/master/googlemock/docs/CookBook.md
130 NiceMock<BalMocker> balMock;
131 bcmos_errno host_init_res = BCM_ERR_OK;
132 bcmos_errno bal_cfg_get_stub_res = BCM_ERR_OK;
133 bcmos_errno bal_cfg_get_res = BCM_ERR_NOT_CONNECTED;
134 bcmos_errno olt_oper_res = BCM_ERR_INTERNAL;
135
136 bcmolt_olt_cfg olt_cfg = { };
137 bcmolt_olt_key olt_key = { };
138 BCMOLT_CFG_INIT(&olt_cfg, olt, olt_key);
139 olt_cfg.data.bal_state = BCMOLT_BAL_STATE_BAL_AND_SWITCH_READY;
140
141 Status olt_enable_res;
142
143 // Ensure that the state of the OLT is in deactivated to start with..
144 state.deactivate();
145
146 ON_CALL(balMock, bcmolt_host_init(_)).WillByDefault(Return(host_init_res));
147 EXPECT_GLOBAL_CALL(bcmolt_cfg_get_stub, bcmolt_cfg_get_stub(_, _))
148 .WillOnce(DoAll(SetArg1ToBcmOltCfg(olt_cfg), Return(bal_cfg_get_stub_res)));
149 EXPECT_CALL(balMock, bcmolt_cfg_get(_, _))
150 .Times(BCM_MAX_DEVS_PER_LINE_CARD)
151 .WillRepeatedly(Return(bal_cfg_get_res));
152 ON_CALL(balMock, bcmolt_oper_submit(_, _)).WillByDefault(Return(olt_oper_res));
153
154 olt_enable_res = Enable_(1, NULL);
155
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +0000156 ASSERT_TRUE( olt_enable_res.error_message() != Status::OK.error_message() );
157}
158
159// Test 5 OltEnableSuccess_One_PON_Enable_Fail : One PON device enable fails, but all others succeed.
160TEST_F(TestOltEnable, OltEnableSuccess_One_PON_Enable_Fail) {
Jason Huangbf45ffb2019-10-30 17:29:02 +0800161
162 // NiceMock is used to suppress 'WillByDefault' return errors.
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +0000163 // This is described in https://github.com/arangodb-helper/gtest/blob/master/googlemock/docs/CookBook.md
Jason Huangbf45ffb2019-10-30 17:29:02 +0800164 NiceMock<BalMocker> balMock;
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +0000165 bcmos_errno host_init_res = BCM_ERR_OK;
Jason Huangbf45ffb2019-10-30 17:29:02 +0800166 bcmos_errno bal_cfg_get_stub_res = BCM_ERR_OK;
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +0000167 bcmos_errno bal_cfg_get_res = BCM_ERR_NOT_CONNECTED;
168 bcmos_errno olt_oper_res_fail = BCM_ERR_INTERNAL;
169 bcmos_errno olt_oper_res_success = BCM_ERR_OK;
170
Jason Huangbf45ffb2019-10-30 17:29:02 +0800171 bcmolt_olt_cfg olt_cfg = { };
172 bcmolt_olt_key olt_key = { };
173 BCMOLT_CFG_INIT(&olt_cfg, olt, olt_key);
174 olt_cfg.data.bal_state = BCMOLT_BAL_STATE_BAL_AND_SWITCH_READY;
175
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +0000176 Status olt_enable_res;
177
178 // Ensure that the state of the OLT is in deactivated to start with..
179 state.deactivate();
180
Jason Huangbf45ffb2019-10-30 17:29:02 +0800181 ON_CALL(balMock, bcmolt_host_init(_)).WillByDefault(Return(host_init_res));
182 EXPECT_GLOBAL_CALL(bcmolt_cfg_get_stub, bcmolt_cfg_get_stub(_, _))
183 .WillOnce(DoAll(SetArg1ToBcmOltCfg(olt_cfg), Return(bal_cfg_get_stub_res)));
184 EXPECT_CALL(balMock, bcmolt_cfg_get(_, _))
185 .Times(BCM_MAX_DEVS_PER_LINE_CARD)
186 .WillRepeatedly(Return(bal_cfg_get_res));
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +0000187 // For the the first PON mac device, the activation result will fail, and will succeed for all other PON mac devices.
Jason Huangbf45ffb2019-10-30 17:29:02 +0800188 EXPECT_CALL(balMock, bcmolt_oper_submit(_, _))
189 .WillOnce(Return(olt_oper_res_fail))
190 .WillRepeatedly(Return(olt_oper_res_success));
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +0000191 olt_enable_res = Enable_(1, NULL);
Jason Huangbf45ffb2019-10-30 17:29:02 +0800192
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +0000193 ASSERT_TRUE( olt_enable_res.error_message() == Status::OK.error_message() );
194}