|
7 | 7 | #include "mock_orchagent_main.h"
|
8 | 8 | #include "mock_table.h"
|
9 | 9 | #include "notifier.h"
|
| 10 | +#include "mock_sai_bridge.h" |
10 | 11 | #define private public
|
11 | 12 | #include "pfcactionhandler.h"
|
12 | 13 | #include <sys/mman.h>
|
|
15 | 16 | #include <sstream>
|
16 | 17 |
|
17 | 18 | extern redisReply *mockReply;
|
| 19 | +using ::testing::_; |
| 20 | +using ::testing::StrictMock; |
18 | 21 |
|
19 | 22 | namespace portsorch_test
|
20 | 23 | {
|
@@ -151,6 +154,21 @@ namespace portsorch_test
|
151 | 154 | sai_queue_api = pold_sai_queue_api;
|
152 | 155 | }
|
153 | 156 |
|
| 157 | + sai_bridge_api_t ut_sai_bridge_api; |
| 158 | + sai_bridge_api_t *org_sai_bridge_api; |
| 159 | + |
| 160 | + void _hook_sai_bridge_api() |
| 161 | + { |
| 162 | + ut_sai_bridge_api = *sai_bridge_api; |
| 163 | + org_sai_bridge_api = sai_bridge_api; |
| 164 | + sai_bridge_api = &ut_sai_bridge_api; |
| 165 | + } |
| 166 | + |
| 167 | + void _unhook_sai_bridge_api() |
| 168 | + { |
| 169 | + sai_bridge_api = org_sai_bridge_api; |
| 170 | + } |
| 171 | + |
154 | 172 | struct PortsOrchTest : public ::testing::Test
|
155 | 173 | {
|
156 | 174 | shared_ptr<swss::DBConnector> m_app_db;
|
@@ -345,6 +363,48 @@ namespace portsorch_test
|
345 | 363 | ASSERT_FALSE(gPortsOrch->getPort(port.m_port_id, port));
|
346 | 364 | }
|
347 | 365 |
|
| 366 | + /** |
| 367 | + * Test case: PortsOrch::addBridgePort() does not add router port to .1Q bridge |
| 368 | + */ |
| 369 | + TEST_F(PortsOrchTest, addBridgePortOnRouterPort) |
| 370 | + { |
| 371 | + _hook_sai_bridge_api(); |
| 372 | + |
| 373 | + StrictMock<MockSaiBridge> mock_sai_bridge_; |
| 374 | + mock_sai_bridge = &mock_sai_bridge_; |
| 375 | + sai_bridge_api->create_bridge_port = mock_create_bridge_port; |
| 376 | + |
| 377 | + Table portTable = Table(m_app_db.get(), APP_PORT_TABLE_NAME); |
| 378 | + |
| 379 | + // Get SAI default ports to populate DB |
| 380 | + auto ports = ut_helper::getInitialSaiPorts(); |
| 381 | + |
| 382 | + // Populate port table with SAI ports |
| 383 | + for (const auto &it : ports) |
| 384 | + { |
| 385 | + portTable.set(it.first, it.second); |
| 386 | + } |
| 387 | + |
| 388 | + // Set PortConfigDone, PortInitDone |
| 389 | + portTable.set("PortConfigDone", { { "count", to_string(ports.size()) } }); |
| 390 | + portTable.set("PortInitDone", { { "lanes", "0" } }); |
| 391 | + |
| 392 | + // refill consumer |
| 393 | + gPortsOrch->addExistingData(&portTable); |
| 394 | + // Apply configuration : create ports |
| 395 | + static_cast<Orch *>(gPortsOrch)->doTask(); |
| 396 | + |
| 397 | + // Get first port and set its rif id to simulate it is router port |
| 398 | + Port port; |
| 399 | + gPortsOrch->getPort("Ethernet0", port); |
| 400 | + port.m_rif_id = 1; |
| 401 | + |
| 402 | + ASSERT_FALSE(gPortsOrch->addBridgePort(port)); |
| 403 | + EXPECT_CALL(mock_sai_bridge_, create_bridge_port(_, _, _, _)).Times(0); |
| 404 | + |
| 405 | + _unhook_sai_bridge_api(); |
| 406 | + } |
| 407 | + |
348 | 408 | TEST_F(PortsOrchTest, PortSupportedFecModes)
|
349 | 409 | {
|
350 | 410 | _hook_sai_port_api();
|
|
0 commit comments