Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 1 | /* |
Girish Gowdra | a707e7c | 2019-11-07 11:36:13 +0530 | [diff] [blame] | 2 | * Copyright 2018-present Open Networking Foundation |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 3 | |
Girish Gowdra | a707e7c | 2019-11-07 11:36:13 +0530 | [diff] [blame] | 4 | * 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 Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 7 | |
Girish Gowdra | a707e7c | 2019-11-07 11:36:13 +0530 | [diff] [blame] | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 9 | |
Girish Gowdra | a707e7c | 2019-11-07 11:36:13 +0530 | [diff] [blame] | 10 | * 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 Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 16 | #include "gtest/gtest.h" |
| 17 | #include "bal_mocker.h" |
| 18 | #include "core.h" |
| 19 | |
Jason Huang | bf45ffb | 2019-10-30 17:29:02 +0800 | [diff] [blame] | 20 | using namespace testing; |
| 21 | |
| 22 | class TestOltEnable : public Test { |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 23 | 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 Huang | bf45ffb | 2019-10-30 17:29:02 +0800 | [diff] [blame] | 33 | // This is used to set custom bcmolt_cfg value to bcmolt_cfg pointer coming in |
Chaitrashree G S | fd15c8c | 2019-09-09 18:46:15 -0400 | [diff] [blame] | 34 | // bcmolt_cfg_get__bal_state_stub. |
Jason Huang | bf45ffb | 2019-10-30 17:29:02 +0800 | [diff] [blame] | 35 | ACTION_P(SetArg1ToBcmOltCfg, value) { *static_cast<bcmolt_olt_cfg*>(arg1) = value; }; |
| 36 | |
| 37 | |
Chaitrashree G S | fd15c8c | 2019-09-09 18:46:15 -0400 | [diff] [blame] | 38 | // Create a mock function for bcmolt_cfg_get__bal_state_stub C++ function |
| 39 | MOCK_GLOBAL_FUNC2(bcmolt_cfg_get__bal_state_stub, bcmos_errno(bcmolt_oltid, void*)); |
Jason Huang | bf45ffb | 2019-10-30 17:29:02 +0800 | [diff] [blame] | 40 | |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 41 | |
| 42 | // Test Fixture for OltEnable |
| 43 | |
| 44 | // Test 1: OltEnableSuccess case |
| 45 | TEST_F(TestOltEnable, OltEnableSuccess){ |
Jason Huang | bf45ffb | 2019-10-30 17:29:02 +0800 | [diff] [blame] | 46 | // NiceMock is used to suppress 'WillByDefault' return errors. |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 47 | // This is described in https://github.com/arangodb-helper/gtest/blob/master/googlemock/docs/CookBook.md |
Jason Huang | bf45ffb | 2019-10-30 17:29:02 +0800 | [diff] [blame] | 48 | NiceMock<BalMocker> balMock; |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 49 | bcmos_errno host_init_res = BCM_ERR_OK; |
Jason Huang | bf45ffb | 2019-10-30 17:29:02 +0800 | [diff] [blame] | 50 | bcmos_errno bal_cfg_get_stub_res = BCM_ERR_OK; |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 51 | bcmos_errno bal_cfg_get_res = BCM_ERR_NOT_CONNECTED; |
| 52 | bcmos_errno olt_oper_res = BCM_ERR_OK; |
| 53 | |
Jason Huang | bf45ffb | 2019-10-30 17:29:02 +0800 | [diff] [blame] | 54 | 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 Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 59 | Status olt_enable_res; |
| 60 | |
Jason Huang | bf45ffb | 2019-10-30 17:29:02 +0800 | [diff] [blame] | 61 | ON_CALL(balMock, bcmolt_host_init(_)).WillByDefault(Return(host_init_res)); |
Chaitrashree G S | fd15c8c | 2019-09-09 18:46:15 -0400 | [diff] [blame] | 62 | EXPECT_GLOBAL_CALL(bcmolt_cfg_get__bal_state_stub, bcmolt_cfg_get__bal_state_stub(_, _)) |
Jason Huang | bf45ffb | 2019-10-30 17:29:02 +0800 | [diff] [blame] | 63 | .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 Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 68 | |
| 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 |
| 74 | TEST_F(TestOltEnable, OltEnableFail_host_init_fail) { |
Jason Huang | bf45ffb | 2019-10-30 17:29:02 +0800 | [diff] [blame] | 75 | // NiceMock is used to suppress 'WillByDefault' return errors. |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 76 | // This is described in https://github.com/arangodb-helper/gtest/blob/master/googlemock/docs/CookBook.md |
Jason Huang | bf45ffb | 2019-10-30 17:29:02 +0800 | [diff] [blame] | 77 | NiceMock<BalMocker> balMock; |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 78 | bcmos_errno host_init_res = BCM_ERR_INTERNAL; |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 79 | |
| 80 | Status olt_enable_res; |
| 81 | |
Jason Huang | bf45ffb | 2019-10-30 17:29:02 +0800 | [diff] [blame] | 82 | // 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 Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 86 | |
| 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 |
| 92 | TEST_F(TestOltEnable, OltEnableSuccess_PON_Device_Connected) { |
Jason Huang | bf45ffb | 2019-10-30 17:29:02 +0800 | [diff] [blame] | 93 | |
| 94 | // NiceMock is used to suppress 'WillByDefault' return errors. |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 95 | // This is described in https://github.com/arangodb-helper/gtest/blob/master/googlemock/docs/CookBook.md |
Jason Huang | bf45ffb | 2019-10-30 17:29:02 +0800 | [diff] [blame] | 96 | NiceMock<BalMocker> balMock; |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 97 | bcmos_errno host_init_res = BCM_ERR_OK; |
Jason Huang | bf45ffb | 2019-10-30 17:29:02 +0800 | [diff] [blame] | 98 | bcmos_errno bal_cfg_get_stub_res = BCM_ERR_OK; |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 99 | bcmos_errno bal_cfg_get_res = BCM_ERR_OK; |
Jason Huang | bf45ffb | 2019-10-30 17:29:02 +0800 | [diff] [blame] | 100 | bcmos_errno olt_oper_res = BCM_ERR_OK; |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 101 | |
Jason Huang | bf45ffb | 2019-10-30 17:29:02 +0800 | [diff] [blame] | 102 | 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 Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 106 | |
| 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 Huang | bf45ffb | 2019-10-30 17:29:02 +0800 | [diff] [blame] | 112 | ON_CALL(balMock, bcmolt_host_init(_)).WillByDefault(Return(host_init_res)); |
Chaitrashree G S | fd15c8c | 2019-09-09 18:46:15 -0400 | [diff] [blame] | 113 | EXPECT_GLOBAL_CALL(bcmolt_cfg_get__bal_state_stub, bcmolt_cfg_get__bal_state_stub(_, _)) |
Jason Huang | bf45ffb | 2019-10-30 17:29:02 +0800 | [diff] [blame] | 114 | .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 Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 118 | |
| 119 | olt_enable_res = Enable_(1, NULL); |
Jason Huang | bf45ffb | 2019-10-30 17:29:02 +0800 | [diff] [blame] | 120 | ASSERT_TRUE( olt_enable_res.error_message() == Status::OK.error_message() ); |
| 121 | |
| 122 | } |
| 123 | |
| 124 | // Test 4: OltEnableFail_All_PON_Enable_Fail |
| 125 | TEST_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 S | fd15c8c | 2019-09-09 18:46:15 -0400 | [diff] [blame] | 146 | EXPECT_GLOBAL_CALL(bcmolt_cfg_get__bal_state_stub, bcmolt_cfg_get__bal_state_stub(_, _)) |
Jason Huang | bf45ffb | 2019-10-30 17:29:02 +0800 | [diff] [blame] | 147 | .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 Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 155 | 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. |
| 159 | TEST_F(TestOltEnable, OltEnableSuccess_One_PON_Enable_Fail) { |
Jason Huang | bf45ffb | 2019-10-30 17:29:02 +0800 | [diff] [blame] | 160 | |
| 161 | // NiceMock is used to suppress 'WillByDefault' return errors. |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 162 | // This is described in https://github.com/arangodb-helper/gtest/blob/master/googlemock/docs/CookBook.md |
Jason Huang | bf45ffb | 2019-10-30 17:29:02 +0800 | [diff] [blame] | 163 | NiceMock<BalMocker> balMock; |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 164 | bcmos_errno host_init_res = BCM_ERR_OK; |
Jason Huang | bf45ffb | 2019-10-30 17:29:02 +0800 | [diff] [blame] | 165 | bcmos_errno bal_cfg_get_stub_res = BCM_ERR_OK; |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 166 | 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 Huang | bf45ffb | 2019-10-30 17:29:02 +0800 | [diff] [blame] | 170 | 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 Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 175 | Status olt_enable_res; |
| 176 | |
| 177 | // Ensure that the state of the OLT is in deactivated to start with.. |
| 178 | state.deactivate(); |
| 179 | |
Jason Huang | bf45ffb | 2019-10-30 17:29:02 +0800 | [diff] [blame] | 180 | ON_CALL(balMock, bcmolt_host_init(_)).WillByDefault(Return(host_init_res)); |
Chaitrashree G S | fd15c8c | 2019-09-09 18:46:15 -0400 | [diff] [blame] | 181 | EXPECT_GLOBAL_CALL(bcmolt_cfg_get__bal_state_stub, bcmolt_cfg_get__bal_state_stub(_, _)) |
Jason Huang | bf45ffb | 2019-10-30 17:29:02 +0800 | [diff] [blame] | 182 | .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 Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 186 | // For the the first PON mac device, the activation result will fail, and will succeed for all other PON mac devices. |
Jason Huang | bf45ffb | 2019-10-30 17:29:02 +0800 | [diff] [blame] | 187 | EXPECT_CALL(balMock, bcmolt_oper_submit(_, _)) |
| 188 | .WillOnce(Return(olt_oper_res_fail)) |
| 189 | .WillRepeatedly(Return(olt_oper_res_success)); |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 190 | olt_enable_res = Enable_(1, NULL); |
Jason Huang | bf45ffb | 2019-10-30 17:29:02 +0800 | [diff] [blame] | 191 | |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 192 | ASSERT_TRUE( olt_enable_res.error_message() == Status::OK.error_message() ); |
| 193 | } |