|
| 1 | +#include "fpmsyncd/fpmlink.h" |
| 2 | + |
| 3 | +#include <swss/netdispatcher.h> |
| 4 | + |
| 5 | +#include <gtest/gtest.h> |
| 6 | +#include <gmock/gmock.h> |
| 7 | + |
| 8 | +using namespace swss; |
| 9 | + |
| 10 | +using ::testing::_; |
| 11 | + |
| 12 | +class MockMsgHandler : public NetMsg |
| 13 | +{ |
| 14 | +public: |
| 15 | + MOCK_METHOD2(onMsg, void(int, nl_object*)); |
| 16 | +}; |
| 17 | + |
| 18 | +class FpmLinkTest : public ::testing::Test |
| 19 | +{ |
| 20 | +public: |
| 21 | + void SetUp() override |
| 22 | + { |
| 23 | + NetDispatcher::getInstance().registerMessageHandler(RTM_NEWROUTE, &m_mock); |
| 24 | + NetDispatcher::getInstance().registerMessageHandler(RTM_DELROUTE, &m_mock); |
| 25 | + } |
| 26 | + |
| 27 | + void TearDown() override |
| 28 | + { |
| 29 | + NetDispatcher::getInstance().unregisterMessageHandler(RTM_NEWROUTE); |
| 30 | + NetDispatcher::getInstance().unregisterMessageHandler(RTM_DELROUTE); |
| 31 | + } |
| 32 | + |
| 33 | + FpmLink m_fpm{nullptr}; |
| 34 | + MockMsgHandler m_mock; |
| 35 | +}; |
| 36 | + |
| 37 | +TEST_F(FpmLinkTest, SingleNlMessageInFpmMessage) |
| 38 | +{ |
| 39 | + // Single FPM message containing single RTM_NEWROUTE |
| 40 | + alignas(fpm_msg_hdr_t) unsigned char fpmMsgBuffer[] = { |
| 41 | + 0x01, 0x01, 0x00, 0x40, 0x3C, 0x00, 0x00, 0x00, 0x18, 0x00, 0x01, 0x05, 0x00, 0x00, 0x00, 0x00, 0xE0, |
| 42 | + 0x12, 0x6F, 0xC4, 0x02, 0x18, 0x00, 0x00, 0xFE, 0x02, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x08, 0x00, |
| 43 | + 0x01, 0x00, 0x01, 0x01, 0x01, 0x00, 0x08, 0x00, 0x06, 0x00, 0x14, 0x00, 0x00, 0x00, 0x08, 0x00, 0x05, |
| 44 | + 0x00, 0xAC, 0x1E, 0x38, 0xA6, 0x08, 0x00, 0x04, 0x00, 0x06, 0x00, 0x00, 0x00 |
| 45 | + }; |
| 46 | + |
| 47 | + EXPECT_CALL(m_mock, onMsg(_, _)).Times(1); |
| 48 | + |
| 49 | + m_fpm.processFpmMessage(reinterpret_cast<fpm_msg_hdr_t*>(static_cast<void*>(fpmMsgBuffer))); |
| 50 | +} |
| 51 | + |
| 52 | +TEST_F(FpmLinkTest, TwoNlMessagesInFpmMessage) |
| 53 | +{ |
| 54 | + // Single FPM message containing RTM_DELROUTE and RTM_NEWROUTE |
| 55 | + alignas(fpm_msg_hdr_t) unsigned char fpmMsgBuffer[] = { |
| 56 | + 0x01, 0x01, 0x00, 0x6C, 0x2C, 0x00, 0x00, 0x00, 0x19, 0x00, 0x01, 0x04, 0x00, 0x00, 0x00, 0x00, 0xE0, 0x12, |
| 57 | + 0x6F, 0xC4, 0x02, 0x18, 0x00, 0x00, 0xFE, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x01, 0x00, |
| 58 | + 0x01, 0x01, 0x01, 0x00, 0x08, 0x00, 0x06, 0x00, 0x14, 0x00, 0x00, 0x00, 0x3C, 0x00, 0x00, 0x00, 0x18, 0x00, |
| 59 | + 0x01, 0x05, 0x00, 0x00, 0x00, 0x00, 0xE0, 0x12, 0x6F, 0xC4, 0x02, 0x18, 0x00, 0x00, 0xFE, 0x02, 0x00, 0x01, |
| 60 | + 0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x01, 0x00, 0x01, 0x01, 0x01, 0x00, 0x08, 0x00, 0x06, 0x00, 0x14, 0x00, |
| 61 | + 0x00, 0x00, 0x08, 0x00, 0x05, 0x00, 0xAC, 0x1E, 0x38, 0xA7, 0x08, 0x00, 0x04, 0x00, 0x06, 0x00, 0x00, 0x00 |
| 62 | + }; |
| 63 | + |
| 64 | + EXPECT_CALL(m_mock, onMsg(_, _)).Times(2); |
| 65 | + |
| 66 | + m_fpm.processFpmMessage(reinterpret_cast<fpm_msg_hdr_t*>(static_cast<void*>(fpmMsgBuffer))); |
| 67 | +} |
| 68 | + |
0 commit comments