blob: c4e60e7fb8004b5f655904b74a4f23e2a77d98eb [file] [log] [blame]
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +00001/*
Girish Gowdraa707e7c2019-11-07 11:36:13 +05302 * Copyright 2018-present Open Networking Foundation
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +00003
Girish Gowdraa707e7c2019-11-07 11:36:13 +05304 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +00007
Girish Gowdraa707e7c2019-11-07 11:36:13 +05308 * http://www.apache.org/licenses/LICENSE-2.0
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +00009
Girish Gowdraa707e7c2019-11-07 11:36:13 +053010 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +000016#include "gtest/gtest.h"
17#include "bal_mocker.h"
18#include "core.h"
19
Jason Huangbf45ffb2019-10-30 17:29:02 +080020using namespace testing;
21
22class TestOltEnable : public Test {
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +000023 protected:
24 virtual void SetUp() {
25 }
26
27 virtual void TearDown() {
28 // Code here will be called immediately after each test
29 // (right before the destructor).
30 }
31};
32
Jason Huangbf45ffb2019-10-30 17:29:02 +080033// This is used to set custom bcmolt_cfg value to bcmolt_cfg pointer coming in
Chaitrashree G Sfd15c8c2019-09-09 18:46:15 -040034// bcmolt_cfg_get__bal_state_stub.
Jason Huangbf45ffb2019-10-30 17:29:02 +080035ACTION_P(SetArg1ToBcmOltCfg, value) { *static_cast<bcmolt_olt_cfg*>(arg1) = value; };
36
37
Chaitrashree G Sfd15c8c2019-09-09 18:46:15 -040038// Create a mock function for bcmolt_cfg_get__bal_state_stub C++ function
39MOCK_GLOBAL_FUNC2(bcmolt_cfg_get__bal_state_stub, bcmos_errno(bcmolt_oltid, void*));
Jason Huangbf45ffb2019-10-30 17:29:02 +080040
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +000041
42// Test Fixture for OltEnable
43
44// Test 1: OltEnableSuccess case
45TEST_F(TestOltEnable, OltEnableSuccess){
Jason Huangbf45ffb2019-10-30 17:29:02 +080046 // NiceMock is used to suppress 'WillByDefault' return errors.
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +000047 // This is described in https://github.com/arangodb-helper/gtest/blob/master/googlemock/docs/CookBook.md
Jason Huangbf45ffb2019-10-30 17:29:02 +080048 NiceMock<BalMocker> balMock;
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +000049 bcmos_errno host_init_res = BCM_ERR_OK;
Jason Huangbf45ffb2019-10-30 17:29:02 +080050 bcmos_errno bal_cfg_get_stub_res = BCM_ERR_OK;
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +000051 bcmos_errno bal_cfg_get_res = BCM_ERR_NOT_CONNECTED;
52 bcmos_errno olt_oper_res = BCM_ERR_OK;
53
Jason Huangbf45ffb2019-10-30 17:29:02 +080054 bcmolt_olt_cfg olt_cfg = { };
55 bcmolt_olt_key olt_key = { };
56 BCMOLT_CFG_INIT(&olt_cfg, olt, olt_key);
57 olt_cfg.data.bal_state = BCMOLT_BAL_STATE_BAL_AND_SWITCH_READY;
58
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +000059 Status olt_enable_res;
60
Jason Huangbf45ffb2019-10-30 17:29:02 +080061 ON_CALL(balMock, bcmolt_host_init(_)).WillByDefault(Return(host_init_res));
Chaitrashree G Sfd15c8c2019-09-09 18:46:15 -040062 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__bal_state_stub, bcmolt_cfg_get__bal_state_stub(_, _))
Jason Huangbf45ffb2019-10-30 17:29:02 +080063 .WillOnce(DoAll(SetArg1ToBcmOltCfg(olt_cfg), Return(bal_cfg_get_stub_res)));
64 EXPECT_CALL(balMock, bcmolt_cfg_get(_, _))
65 .Times(BCM_MAX_DEVS_PER_LINE_CARD)
66 .WillRepeatedly(Return(bal_cfg_get_res));
67 ON_CALL(balMock, bcmolt_oper_submit(_, _)).WillByDefault(Return(olt_oper_res));
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +000068
69 olt_enable_res = Enable_(1, NULL);
70 ASSERT_TRUE( olt_enable_res.error_message() == Status::OK.error_message() );
71}
72
73// Test 2: OltEnableFail_host_init_fail
74TEST_F(TestOltEnable, OltEnableFail_host_init_fail) {
Jason Huangbf45ffb2019-10-30 17:29:02 +080075 // NiceMock is used to suppress 'WillByDefault' return errors.
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +000076 // This is described in https://github.com/arangodb-helper/gtest/blob/master/googlemock/docs/CookBook.md
Jason Huangbf45ffb2019-10-30 17:29:02 +080077 NiceMock<BalMocker> balMock;
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +000078 bcmos_errno host_init_res = BCM_ERR_INTERNAL;
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +000079
80 Status olt_enable_res;
81
Jason Huangbf45ffb2019-10-30 17:29:02 +080082 // Ensure that the state of the OLT is in deactivated to start with..
83 state.deactivate();
84
85 ON_CALL(balMock, bcmolt_host_init(_)).WillByDefault(Return(host_init_res));
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +000086
87 olt_enable_res = Enable_(1, NULL);
88 ASSERT_TRUE( olt_enable_res.error_message() != Status::OK.error_message() );
89}
90
91// Test 3: OltEnableSuccess_PON_Device_Connected
92TEST_F(TestOltEnable, OltEnableSuccess_PON_Device_Connected) {
Jason Huangbf45ffb2019-10-30 17:29:02 +080093
94 // NiceMock is used to suppress 'WillByDefault' return errors.
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +000095 // This is described in https://github.com/arangodb-helper/gtest/blob/master/googlemock/docs/CookBook.md
Jason Huangbf45ffb2019-10-30 17:29:02 +080096 NiceMock<BalMocker> balMock;
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +000097 bcmos_errno host_init_res = BCM_ERR_OK;
Jason Huangbf45ffb2019-10-30 17:29:02 +080098 bcmos_errno bal_cfg_get_stub_res = BCM_ERR_OK;
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +000099 bcmos_errno bal_cfg_get_res = BCM_ERR_OK;
Jason Huangbf45ffb2019-10-30 17:29:02 +0800100 bcmos_errno olt_oper_res = BCM_ERR_OK;
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +0000101
Jason Huangbf45ffb2019-10-30 17:29:02 +0800102 bcmolt_olt_cfg olt_cfg = { };
103 bcmolt_olt_key olt_key = { };
104 BCMOLT_CFG_INIT(&olt_cfg, olt, olt_key);
105 olt_cfg.data.bal_state = BCMOLT_BAL_STATE_BAL_AND_SWITCH_READY;
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +0000106
107 Status olt_enable_res;
108
109 // Ensure that the state of the OLT is in deactivated to start with..
110 state.deactivate();
111
Jason Huangbf45ffb2019-10-30 17:29:02 +0800112 ON_CALL(balMock, bcmolt_host_init(_)).WillByDefault(Return(host_init_res));
Chaitrashree G Sfd15c8c2019-09-09 18:46:15 -0400113 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__bal_state_stub, bcmolt_cfg_get__bal_state_stub(_, _))
Jason Huangbf45ffb2019-10-30 17:29:02 +0800114 .WillOnce(DoAll(SetArg1ToBcmOltCfg(olt_cfg), Return(bal_cfg_get_stub_res)));
115 EXPECT_CALL(balMock, bcmolt_cfg_get(_, _))
116 .Times(BCM_MAX_DEVS_PER_LINE_CARD)
117 .WillRepeatedly(Return(bal_cfg_get_res));
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +0000118
119 olt_enable_res = Enable_(1, NULL);
Jason Huangbf45ffb2019-10-30 17:29:02 +0800120 ASSERT_TRUE( olt_enable_res.error_message() == Status::OK.error_message() );
121
122}
123
124// Test 4: OltEnableFail_All_PON_Enable_Fail
125TEST_F(TestOltEnable, OltEnableFail_All_PON_Enable_Fail) {
126
127 // NiceMock is used to suppress 'WillByDefault' return errors.
128 // This is described in https://github.com/arangodb-helper/gtest/blob/master/googlemock/docs/CookBook.md
129 NiceMock<BalMocker> balMock;
130 bcmos_errno host_init_res = BCM_ERR_OK;
131 bcmos_errno bal_cfg_get_stub_res = BCM_ERR_OK;
132 bcmos_errno bal_cfg_get_res = BCM_ERR_NOT_CONNECTED;
133 bcmos_errno olt_oper_res = BCM_ERR_INTERNAL;
134
135 bcmolt_olt_cfg olt_cfg = { };
136 bcmolt_olt_key olt_key = { };
137 BCMOLT_CFG_INIT(&olt_cfg, olt, olt_key);
138 olt_cfg.data.bal_state = BCMOLT_BAL_STATE_BAL_AND_SWITCH_READY;
139
140 Status olt_enable_res;
141
142 // Ensure that the state of the OLT is in deactivated to start with..
143 state.deactivate();
144
145 ON_CALL(balMock, bcmolt_host_init(_)).WillByDefault(Return(host_init_res));
Chaitrashree G Sfd15c8c2019-09-09 18:46:15 -0400146 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__bal_state_stub, bcmolt_cfg_get__bal_state_stub(_, _))
Jason Huangbf45ffb2019-10-30 17:29:02 +0800147 .WillOnce(DoAll(SetArg1ToBcmOltCfg(olt_cfg), Return(bal_cfg_get_stub_res)));
148 EXPECT_CALL(balMock, bcmolt_cfg_get(_, _))
149 .Times(BCM_MAX_DEVS_PER_LINE_CARD)
150 .WillRepeatedly(Return(bal_cfg_get_res));
151 ON_CALL(balMock, bcmolt_oper_submit(_, _)).WillByDefault(Return(olt_oper_res));
152
153 olt_enable_res = Enable_(1, NULL);
154
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +0000155 ASSERT_TRUE( olt_enable_res.error_message() != Status::OK.error_message() );
156}
157
158// Test 5 OltEnableSuccess_One_PON_Enable_Fail : One PON device enable fails, but all others succeed.
159TEST_F(TestOltEnable, OltEnableSuccess_One_PON_Enable_Fail) {
Jason Huangbf45ffb2019-10-30 17:29:02 +0800160
161 // NiceMock is used to suppress 'WillByDefault' return errors.
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +0000162 // This is described in https://github.com/arangodb-helper/gtest/blob/master/googlemock/docs/CookBook.md
Jason Huangbf45ffb2019-10-30 17:29:02 +0800163 NiceMock<BalMocker> balMock;
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +0000164 bcmos_errno host_init_res = BCM_ERR_OK;
Jason Huangbf45ffb2019-10-30 17:29:02 +0800165 bcmos_errno bal_cfg_get_stub_res = BCM_ERR_OK;
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +0000166 bcmos_errno bal_cfg_get_res = BCM_ERR_NOT_CONNECTED;
167 bcmos_errno olt_oper_res_fail = BCM_ERR_INTERNAL;
168 bcmos_errno olt_oper_res_success = BCM_ERR_OK;
169
Jason Huangbf45ffb2019-10-30 17:29:02 +0800170 bcmolt_olt_cfg olt_cfg = { };
171 bcmolt_olt_key olt_key = { };
172 BCMOLT_CFG_INIT(&olt_cfg, olt, olt_key);
173 olt_cfg.data.bal_state = BCMOLT_BAL_STATE_BAL_AND_SWITCH_READY;
174
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +0000175 Status olt_enable_res;
176
177 // Ensure that the state of the OLT is in deactivated to start with..
178 state.deactivate();
179
Jason Huangbf45ffb2019-10-30 17:29:02 +0800180 ON_CALL(balMock, bcmolt_host_init(_)).WillByDefault(Return(host_init_res));
Chaitrashree G Sfd15c8c2019-09-09 18:46:15 -0400181 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__bal_state_stub, bcmolt_cfg_get__bal_state_stub(_, _))
Jason Huangbf45ffb2019-10-30 17:29:02 +0800182 .WillOnce(DoAll(SetArg1ToBcmOltCfg(olt_cfg), Return(bal_cfg_get_stub_res)));
183 EXPECT_CALL(balMock, bcmolt_cfg_get(_, _))
184 .Times(BCM_MAX_DEVS_PER_LINE_CARD)
185 .WillRepeatedly(Return(bal_cfg_get_res));
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +0000186 // 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 +0800187 EXPECT_CALL(balMock, bcmolt_oper_submit(_, _))
188 .WillOnce(Return(olt_oper_res_fail))
189 .WillRepeatedly(Return(olt_oper_res_success));
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +0000190 olt_enable_res = Enable_(1, NULL);
Jason Huangbf45ffb2019-10-30 17:29:02 +0800191
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +0000192 ASSERT_TRUE( olt_enable_res.error_message() == Status::OK.error_message() );
193}