Skip to content

Commit c6e7ac0

Browse files
committed
Add FdbInfo tests
1 parent 7ed640d commit c6e7ac0

File tree

3 files changed

+198
-2
lines changed

3 files changed

+198
-2
lines changed

unittest/vslib/Makefile.am

+2-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ tests_SOURCES = main.cpp \
1212
TestCorePortIndexMapFileParser.cpp \
1313
TestEventPayloadNetLinkMsg.cpp \
1414
TestEventPayloadPacket.cpp \
15-
TestEventQueue.cpp
15+
TestEventQueue.cpp \
16+
TestFdbInfo.cpp
1617

1718
tests_CXXFLAGS = $(DBGFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS_COMMON)
1819
tests_LDADD = $(LDADD_GTEST) $(top_srcdir)/vslib/libSaiVS.a -lhiredis -lswsscommon -lpthread -L$(top_srcdir)/meta/.libs -lsaimetadata -lsaimeta -lzmq $(CODE_COVERAGE_LIBS)

unittest/vslib/TestFdbInfo.cpp

+194
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,194 @@
1+
#include "FdbInfo.h"
2+
3+
#include <linux/if.h>
4+
5+
#include <gtest/gtest.h>
6+
7+
using namespace saivs;
8+
9+
TEST(FdbInfo, getPortId)
10+
{
11+
FdbInfo fdb;
12+
13+
EXPECT_EQ(fdb.getPortId(), 0);
14+
}
15+
16+
TEST(FdbInfo, getVlanId)
17+
{
18+
FdbInfo fdb;
19+
20+
EXPECT_EQ(fdb.getVlanId(), 0);
21+
}
22+
23+
TEST(FdbInfo, getBridgePortId)
24+
{
25+
FdbInfo fdb;
26+
27+
EXPECT_EQ(fdb.getBridgePortId(), 0);
28+
}
29+
30+
TEST(FdbInfo, getFdbEntry)
31+
{
32+
FdbInfo fdb;
33+
34+
auto entry = fdb.getFdbEntry();
35+
36+
EXPECT_EQ(entry.switch_id, 0);
37+
}
38+
39+
TEST(FdbInfo, getTimestamp)
40+
{
41+
FdbInfo fdb;
42+
43+
EXPECT_EQ(fdb.getTimestamp(), 0);
44+
}
45+
46+
TEST(FdbInfo, serialize)
47+
{
48+
FdbInfo fdb;
49+
50+
auto str = fdb.serialize();
51+
52+
EXPECT_EQ(str,
53+
"{\"bridge_port_id\":\"oid:0x0\","
54+
"\"fdb_entry\":\"{\\\"bvid\\\":\\\"oid:0x0\\\",\\\"mac\\\":\\\"00:00:00:00:00:00\\\",\\\"switch_id\\\":\\\"oid:0x0\\\"}\","
55+
"\"port_id\":\"oid:0x0\","
56+
"\"timestamp\":\"0\","
57+
"\"vlan_id\":\"0\"}");
58+
}
59+
60+
TEST(FdbInfo, deserialize)
61+
{
62+
std::string str =
63+
"{\"bridge_port_id\":\"oid:0x1\","
64+
"\"fdb_entry\":\"{\\\"bvid\\\":\\\"oid:0x0\\\",\\\"mac\\\":\\\"00:00:00:00:00:00\\\",\\\"switch_id\\\":\\\"oid:0x0\\\"}\","
65+
"\"port_id\":\"oid:0x0\","
66+
"\"timestamp\":\"0\","
67+
"\"vlan_id\":\"0\"}";
68+
69+
auto fdb = FdbInfo::deserialize(str);
70+
71+
EXPECT_EQ(fdb.getBridgePortId(), 1);
72+
}
73+
74+
TEST(FdbInfo, setFdbEntry)
75+
{
76+
FdbInfo fdb;
77+
78+
sai_fdb_entry_t entry;
79+
80+
entry.switch_id = 2;
81+
82+
fdb.setFdbEntry(entry);
83+
84+
auto en = fdb.getFdbEntry();
85+
86+
EXPECT_EQ(en.switch_id, 2);
87+
}
88+
89+
TEST(FdbInfo, setVlanId)
90+
{
91+
FdbInfo info;
92+
93+
info.setVlanId(7);
94+
95+
EXPECT_EQ(info.getVlanId(), 7);
96+
}
97+
98+
TEST(FdbInfo, setPortId)
99+
{
100+
FdbInfo info;
101+
102+
info.setPortId(7);
103+
104+
EXPECT_EQ(info.getPortId(), 7);
105+
}
106+
107+
TEST(FdbInfo, setBridgePortId)
108+
{
109+
FdbInfo info;
110+
111+
info.setBridgePortId(7);
112+
113+
EXPECT_EQ(info.getBridgePortId(), 7);
114+
}
115+
116+
TEST(FdbInfo, setTimestamp)
117+
{
118+
FdbInfo info;
119+
120+
info.setTimestamp(7);
121+
122+
EXPECT_EQ(info.getTimestamp(), 7);
123+
}
124+
125+
TEST(FdbInfo, operator_bracket)
126+
{
127+
std::string strA =
128+
"{\"bridge_port_id\":\"oid:0x1\","
129+
"\"fdb_entry\":\"{\\\"bvid\\\":\\\"oid:0x0\\\",\\\"mac\\\":\\\"00:00:00:00:00:00\\\",\\\"switch_id\\\":\\\"oid:0x0\\\"}\","
130+
"\"port_id\":\"oid:0x0\","
131+
"\"timestamp\":\"0\","
132+
"\"vlan_id\":\"0\"}";
133+
134+
std::string strB =
135+
"{\"bridge_port_id\":\"oid:0x1\","
136+
"\"fdb_entry\":\"{\\\"bvid\\\":\\\"oid:0x0\\\",\\\"mac\\\":\\\"00:00:00:00:00:01\\\",\\\"switch_id\\\":\\\"oid:0x0\\\"}\","
137+
"\"port_id\":\"oid:0x0\","
138+
"\"timestamp\":\"0\","
139+
"\"vlan_id\":\"0\"}";
140+
141+
auto a = FdbInfo::deserialize(strA);
142+
auto b = FdbInfo::deserialize(strB);
143+
144+
EXPECT_EQ(a.operator()(a,b), true);
145+
EXPECT_EQ(a.operator()(b,a), false);
146+
}
147+
148+
TEST(FdbInfo, operator_lt)
149+
{
150+
std::string strA =
151+
"{\"bridge_port_id\":\"oid:0x1\","
152+
"\"fdb_entry\":\"{\\\"bvid\\\":\\\"oid:0x0\\\",\\\"mac\\\":\\\"00:00:00:00:00:00\\\",\\\"switch_id\\\":\\\"oid:0x0\\\"}\","
153+
"\"port_id\":\"oid:0x0\","
154+
"\"timestamp\":\"0\","
155+
"\"vlan_id\":\"0\"}";
156+
157+
std::string strB =
158+
"{\"bridge_port_id\":\"oid:0x1\","
159+
"\"fdb_entry\":\"{\\\"bvid\\\":\\\"oid:0x0\\\",\\\"mac\\\":\\\"00:00:00:00:00:01\\\",\\\"switch_id\\\":\\\"oid:0x0\\\"}\","
160+
"\"port_id\":\"oid:0x0\","
161+
"\"timestamp\":\"0\","
162+
"\"vlan_id\":\"0\"}";
163+
164+
auto a = FdbInfo::deserialize(strA);
165+
auto b = FdbInfo::deserialize(strB);
166+
167+
EXPECT_EQ(a < b, true);
168+
EXPECT_EQ(b < a, false);
169+
EXPECT_EQ(a < a, false);
170+
EXPECT_EQ(b < b, false);
171+
172+
std::string strC =
173+
"{\"bridge_port_id\":\"oid:0x1\","
174+
"\"fdb_entry\":\"{\\\"bvid\\\":\\\"oid:0x0\\\",\\\"mac\\\":\\\"00:00:00:00:00:00\\\",\\\"switch_id\\\":\\\"oid:0x0\\\"}\","
175+
"\"port_id\":\"oid:0x0\","
176+
"\"timestamp\":\"0\","
177+
"\"vlan_id\":\"1\"}";
178+
179+
std::string strD =
180+
"{\"bridge_port_id\":\"oid:0x1\","
181+
"\"fdb_entry\":\"{\\\"bvid\\\":\\\"oid:0x0\\\",\\\"mac\\\":\\\"00:00:00:00:00:00\\\",\\\"switch_id\\\":\\\"oid:0x0\\\"}\","
182+
"\"port_id\":\"oid:0x0\","
183+
"\"timestamp\":\"0\","
184+
"\"vlan_id\":\"2\"}";
185+
186+
auto c = FdbInfo::deserialize(strC);
187+
auto d = FdbInfo::deserialize(strD);
188+
189+
EXPECT_EQ(c < d, true);
190+
EXPECT_EQ(d < c, false);
191+
EXPECT_EQ(c < c, false);
192+
EXPECT_EQ(d < d, false);
193+
194+
}

vslib/FdbInfo.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ FdbInfo::FdbInfo()
2323

2424
m_bridgePortId = SAI_NULL_OBJECT_ID;
2525

26+
m_timestamp = 0;
27+
2628
memset(&m_fdbEntry, 0, sizeof(m_fdbEntry));
2729
}
2830

@@ -61,7 +63,6 @@ uint32_t FdbInfo::getTimestamp() const
6163
return m_timestamp;
6264
}
6365

64-
6566
// TODO move to meta serialize
6667
// requires to move FdbInfo to common
6768

0 commit comments

Comments
 (0)