Skip to content

Commit e9984d8

Browse files
authored
Enable p4orch unit test for test workflow. (sonic-net#2375)
* Enable p4orch unit test for test workflow. * Add unit test coverage into coverage report. * Remove unit test files from coverage report.
1 parent 33c420d commit e9984d8

File tree

10 files changed

+277
-51
lines changed

10 files changed

+277
-51
lines changed

.azure-pipelines/gcov.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ parameters:
1414

1515
- name: timeout
1616
type: number
17-
default: 180
17+
default: 240
1818

1919
- name: sonic_slave
2020
type: string

orchagent/Makefile.am

+5-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ INCLUDES = -I $(top_srcdir)/lib \
66
-I pbh \
77
-I nhg
88

9+
if GCOV_ENABLED
10+
SUBDIRS = p4orch/tests
11+
endif
12+
913
CFLAGS_SAI = -I /usr/include/sai
1014

1115
swssdir = $(datadir)/swss
@@ -18,7 +22,7 @@ dist_swss_DATA = \
1822
pfc_detect_barefoot.lua \
1923
pfc_detect_nephos.lua \
2024
pfc_detect_cisco-8000.lua \
21-
pfc_detect_vs.lua \
25+
pfc_detect_vs.lua \
2226
pfc_restore.lua \
2327
pfc_restore_cisco-8000.lua \
2428
port_rates.lua \

orchagent/flex_counter/flex_counter_manager.cpp

+4-1
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,10 @@ FlexCounterManager::~FlexCounterManager()
128128
flex_counter_table->del(getFlexCounterTableKey(group_name, counter));
129129
}
130130

131-
flex_counter_group_table->del(group_name);
131+
if (flex_counter_group_table != nullptr)
132+
{
133+
flex_counter_group_table->del(group_name);
134+
}
132135

133136
SWSS_LOG_DEBUG("Deleted flex counter group '%s'.", group_name.c_str());
134137
}

orchagent/flexcounterorch.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ class FlexCounterOrch: public Orch
2626
std::shared_ptr<swss::DBConnector> m_flexCounterDb = nullptr;
2727
std::shared_ptr<swss::ProducerTable> m_flexCounterGroupTable = nullptr;
2828
std::shared_ptr<swss::DBConnector> m_gbflexCounterDb = nullptr;
29-
shared_ptr<ProducerTable> m_gbflexCounterGroupTable = nullptr;
29+
std::shared_ptr<ProducerTable> m_gbflexCounterGroupTable = nullptr;
3030
bool m_port_counter_enabled = false;
3131
bool m_port_buffer_drop_counter_enabled = false;
3232
bool m_hostif_trap_counter_enabled = false;

orchagent/p4orch/tests/Makefile.am

+7-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@ INCLUDES = -I $(top_srcdir) -I $(ORCHAGENT_DIR) -I $(P4ORCH_DIR) -I $(top_srcdir
44

55
CFLAGS_SAI = -I /usr/include/sai
66

7-
bin_PROGRAMS = p4orch_tests p4orch_tests_asan p4orch_tests_tsan p4orch_tests_usan
7+
TESTS = p4orch_tests p4orch_tests_asan p4orch_tests_tsan p4orch_tests_usan
8+
9+
noinst_PROGRAMS = p4orch_tests p4orch_tests_asan p4orch_tests_tsan p4orch_tests_usan
810

911
if DEBUG
1012
DBGFLAGS = -ggdb -DDEBUG
@@ -27,6 +29,7 @@ p4orch_tests_SOURCES = $(ORCHAGENT_DIR)/orch.cpp \
2729
$(ORCHAGENT_DIR)/switchorch.cpp \
2830
$(ORCHAGENT_DIR)/request_parser.cpp \
2931
$(ORCHAGENT_DIR)/flex_counter/flex_counter_manager.cpp \
32+
$(ORCHAGENT_DIR)/flex_counter/flow_counter_handler.cpp \
3033
$(P4ORCH_DIR)/p4oidmapper.cpp \
3134
$(P4ORCH_DIR)/p4orch.cpp \
3235
$(P4ORCH_DIR)/p4orch_util.cpp \
@@ -39,9 +42,11 @@ p4orch_tests_SOURCES = $(ORCHAGENT_DIR)/orch.cpp \
3942
$(P4ORCH_DIR)/acl_rule_manager.cpp \
4043
$(P4ORCH_DIR)/wcmp_manager.cpp \
4144
$(P4ORCH_DIR)/mirror_session_manager.cpp \
42-
$(top_srcdir)/tests/mock_tests/fake_response_publisher.cpp \
45+
$(top_srcdir)/tests/mock_tests/fake_response_publisher.cpp \
4346
fake_portorch.cpp \
4447
fake_crmorch.cpp \
48+
fake_flexcounterorch.cpp \
49+
fake_flowcounterrouteorch.cpp \
4550
fake_dbconnector.cpp \
4651
fake_producertable.cpp \
4752
fake_consumerstatetable.cpp \
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#include "copporch.h"
2+
#include "flexcounterorch.h"
3+
4+
FlexCounterOrch::FlexCounterOrch(swss::DBConnector *db, std::vector<std::string> &tableNames)
5+
: Orch(db, tableNames), m_flexCounterConfigTable(db, CFG_FLEX_COUNTER_TABLE_NAME)
6+
{
7+
}
8+
9+
FlexCounterOrch::~FlexCounterOrch(void)
10+
{
11+
}
12+
13+
void FlexCounterOrch::doTask(Consumer &consumer)
14+
{
15+
}
16+
17+
bool FlexCounterOrch::getPortCountersState() const
18+
{
19+
return true;
20+
}
21+
22+
bool FlexCounterOrch::getPortBufferDropCountersState() const
23+
{
24+
return true;
25+
}
26+
27+
bool FlexCounterOrch::bake()
28+
{
29+
return true;
30+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,178 @@
1+
#include "copporch.h"
2+
#include "flowcounterrouteorch.h"
3+
4+
extern size_t gMaxBulkSize;
5+
extern sai_route_api_t *sai_route_api;
6+
7+
#define ROUTE_FLOW_COUNTER_POLLING_INTERVAL_MS 10000
8+
9+
FlowCounterRouteOrch::FlowCounterRouteOrch(swss::DBConnector *db, const std::vector<std::string> &tableNames)
10+
: Orch(db, tableNames), mRouteFlowCounterMgr(ROUTE_FLOW_COUNTER_FLEX_COUNTER_GROUP, StatsMode::READ,
11+
ROUTE_FLOW_COUNTER_POLLING_INTERVAL_MS, false),
12+
gRouteBulker(sai_route_api, gMaxBulkSize)
13+
{
14+
}
15+
16+
FlowCounterRouteOrch::~FlowCounterRouteOrch(void)
17+
{
18+
}
19+
20+
void FlowCounterRouteOrch::generateRouteFlowStats()
21+
{
22+
}
23+
24+
void FlowCounterRouteOrch::clearRouteFlowStats()
25+
{
26+
}
27+
28+
void FlowCounterRouteOrch::addRoutePattern(const std::string &pattern, size_t)
29+
{
30+
}
31+
32+
void FlowCounterRouteOrch::removeRoutePattern(const std::string &pattern)
33+
{
34+
}
35+
36+
void FlowCounterRouteOrch::onAddMiscRouteEntry(sai_object_id_t vrf_id, const IpPrefix &ip_prefix, bool add_to_cache)
37+
{
38+
}
39+
40+
void FlowCounterRouteOrch::onAddMiscRouteEntry(sai_object_id_t vrf_id, const sai_ip_prefix_t &ip_pfx, bool add_to_cache)
41+
{
42+
}
43+
44+
void FlowCounterRouteOrch::onRemoveMiscRouteEntry(sai_object_id_t vrf_id, const IpPrefix &ip_prefix,
45+
bool remove_from_cache)
46+
{
47+
}
48+
49+
void FlowCounterRouteOrch::onRemoveMiscRouteEntry(sai_object_id_t vrf_id, const sai_ip_prefix_t &ip_pfx,
50+
bool remove_from_cache)
51+
{
52+
}
53+
54+
void FlowCounterRouteOrch::onAddVR(sai_object_id_t vrf_id)
55+
{
56+
}
57+
58+
void FlowCounterRouteOrch::onRemoveVR(sai_object_id_t vrf_id)
59+
{
60+
}
61+
62+
void FlowCounterRouteOrch::handleRouteAdd(sai_object_id_t vrf_id, const IpPrefix &ip_prefix)
63+
{
64+
}
65+
66+
void FlowCounterRouteOrch::handleRouteRemove(sai_object_id_t vrf_id, const IpPrefix &ip_prefix)
67+
{
68+
}
69+
70+
void FlowCounterRouteOrch::processRouteFlowCounterBinding()
71+
{
72+
}
73+
74+
void FlowCounterRouteOrch::doTask(Consumer &consumer)
75+
{
76+
}
77+
78+
void FlowCounterRouteOrch::doTask(SelectableTimer &timer)
79+
{
80+
}
81+
82+
void FlowCounterRouteOrch::initRouteFlowCounterCapability()
83+
{
84+
}
85+
86+
void FlowCounterRouteOrch::removeRoutePattern(const RoutePattern &route_pattern)
87+
{
88+
}
89+
90+
void FlowCounterRouteOrch::removeRouteFlowCounterFromDB(sai_object_id_t vrf_id, const IpPrefix &ip_prefix,
91+
sai_object_id_t counter_oid)
92+
{
93+
}
94+
95+
bool FlowCounterRouteOrch::bindFlowCounter(const RoutePattern &route_pattern, sai_object_id_t vrf_id,
96+
const IpPrefix &ip_prefix)
97+
{
98+
return true;
99+
}
100+
101+
void FlowCounterRouteOrch::unbindFlowCounter(const RoutePattern &route_pattern, sai_object_id_t vrf_id,
102+
const IpPrefix &ip_prefix, sai_object_id_t counter_oid)
103+
{
104+
}
105+
106+
void FlowCounterRouteOrch::pendingUpdateFlexDb(const RoutePattern &route_pattern, const IpPrefix &ip_prefix,
107+
sai_object_id_t counter_oid)
108+
{
109+
}
110+
111+
void FlowCounterRouteOrch::updateRouterFlowCounterCache(const RoutePattern &route_pattern, const IpPrefix &ip_prefix,
112+
sai_object_id_t counter_oid, RouterFlowCounterCache &cache)
113+
{
114+
}
115+
116+
bool FlowCounterRouteOrch::validateRoutePattern(const RoutePattern &route_pattern) const
117+
{
118+
return true;
119+
}
120+
121+
void FlowCounterRouteOrch::onRoutePatternMaxMatchCountChange(RoutePattern &route_pattern, size_t new_max_match_count)
122+
{
123+
}
124+
125+
bool FlowCounterRouteOrch::isRouteAlreadyBound(const RoutePattern &route_pattern, const IpPrefix &ip_prefix) const
126+
{
127+
return true;
128+
}
129+
130+
void FlowCounterRouteOrch::createRouteFlowCounterByPattern(const RoutePattern &route_pattern, size_t currentBoundCount)
131+
{
132+
}
133+
134+
bool FlowCounterRouteOrch::removeRouteFlowCounter(const RoutePattern &route_pattern, sai_object_id_t vrf_id,
135+
const IpPrefix &ip_prefix)
136+
{
137+
return true;
138+
}
139+
140+
void FlowCounterRouteOrch::createRouteFlowCounterFromVnetRoutes(const RoutePattern &route_pattern,
141+
size_t &current_bound_count)
142+
{
143+
}
144+
145+
void FlowCounterRouteOrch::reapRouteFlowCounterByPattern(const RoutePattern &route_pattern, size_t currentBoundCount)
146+
{
147+
}
148+
149+
bool FlowCounterRouteOrch::isRouteFlowCounterEnabled() const
150+
{
151+
return true;
152+
}
153+
154+
void FlowCounterRouteOrch::getRouteFlowCounterNameMapKey(sai_object_id_t vrf_id, const IpPrefix &ip_prefix,
155+
std::string &key)
156+
{
157+
}
158+
159+
size_t FlowCounterRouteOrch::getRouteFlowCounterSizeByPattern(const RoutePattern &route_pattern) const
160+
{
161+
return 0;
162+
}
163+
164+
bool FlowCounterRouteOrch::parseRouteKeyForRoutePattern(const std::string &key, char sep, sai_object_id_t &vrf_id,
165+
IpPrefix &ip_prefix, std::string &vrf_name)
166+
{
167+
return true;
168+
}
169+
170+
bool FlowCounterRouteOrch::getVrfIdByVnetName(const std::string &vnet_name, sai_object_id_t &vrf_id)
171+
{
172+
return true;
173+
}
174+
175+
bool FlowCounterRouteOrch::getVnetNameByVrfId(sai_object_id_t vrf_id, std::string &vnet_name)
176+
{
177+
return true;
178+
}

orchagent/p4orch/tests/fake_portorch.cpp

+4-3
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,8 @@ bool PortsOrch::removeAclTableGroup(const Port &p)
206206
return true;
207207
}
208208

209-
bool PortsOrch::addSubPort(Port &port, const string &alias, const bool &adminUp, const uint32_t &mtu)
209+
bool PortsOrch::addSubPort(Port &port, const string &alias, const string &vlan, const bool &adminUp,
210+
const uint32_t &mtu)
210211
{
211212
return true;
212213
}
@@ -400,7 +401,7 @@ void PortsOrch::initializePriorityGroups(Port &port)
400401
{
401402
}
402403

403-
void PortsOrch::initializePortMaximumHeadroom(Port &port)
404+
void PortsOrch::initializePortBufferMaximumParameters(Port &port)
404405
{
405406
}
406407

@@ -685,7 +686,7 @@ void PortsOrch::voqSyncDelLagMember(Port &lag, Port &port)
685686
{
686687
}
687688

688-
std::unordered_set<std::string> PortsOrch::generateCounterStats(const string &type)
689+
std::unordered_set<std::string> PortsOrch::generateCounterStats(const string &type, bool gearbox)
689690
{
690691
return {};
691692
}

orchagent/p4orch/tests/test_main.cpp

+16
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ extern "C"
1111
#include "crmorch.h"
1212
#include "dbconnector.h"
1313
#include "directory.h"
14+
#include "flowcounterrouteorch.h"
1415
#include "mock_sai_virtual_router.h"
1516
#include "p4orch.h"
1617
#include "portsorch.h"
@@ -37,6 +38,8 @@ sai_object_id_t gUnderlayIfId;
3738

3839
#define DEFAULT_BATCH_SIZE 128
3940
int gBatchSize = DEFAULT_BATCH_SIZE;
41+
#define DEFAULT_MAX_BULK_SIZE 1000
42+
size_t gMaxBulkSize = DEFAULT_MAX_BULK_SIZE;
4043
bool gSairedisRecord = true;
4144
bool gSwssRecord = true;
4245
bool gLogRotate = false;
@@ -50,6 +53,7 @@ PortsOrch *gPortsOrch;
5053
CrmOrch *gCrmOrch;
5154
P4Orch *gP4Orch;
5255
VRFOrch *gVrfOrch;
56+
FlowCounterRouteOrch *gFlowCounterRouteOrch;
5357
SwitchOrch *gSwitchOrch;
5458
Directory<Orch *> gDirectory;
5559
ofstream gRecordOfs;
@@ -73,6 +77,8 @@ sai_switch_api_t *sai_switch_api;
7377
sai_mirror_api_t *sai_mirror_api;
7478
sai_udf_api_t *sai_udf_api;
7579
sai_tunnel_api_t *sai_tunnel_api;
80+
sai_my_mac_api_t *sai_my_mac_api;
81+
sai_counter_api_t *sai_counter_api;
7682

7783
namespace
7884
{
@@ -162,6 +168,9 @@ int main(int argc, char *argv[])
162168
sai_switch_api_t switch_api;
163169
sai_mirror_api_t mirror_api;
164170
sai_udf_api_t udf_api;
171+
sai_my_mac_api_t my_mac_api;
172+
sai_tunnel_api_t tunnel_api;
173+
sai_counter_api_t counter_api;
165174
sai_router_intfs_api = &router_intfs_api;
166175
sai_neighbor_api = &neighbor_api;
167176
sai_next_hop_api = &next_hop_api;
@@ -174,6 +183,9 @@ int main(int argc, char *argv[])
174183
sai_switch_api = &switch_api;
175184
sai_mirror_api = &mirror_api;
176185
sai_udf_api = &udf_api;
186+
sai_my_mac_api = &my_mac_api;
187+
sai_tunnel_api = &tunnel_api;
188+
sai_counter_api = &counter_api;
177189

178190
swss::DBConnector appl_db("APPL_DB", 0);
179191
swss::DBConnector state_db("STATE_DB", 0);
@@ -193,6 +205,10 @@ int main(int argc, char *argv[])
193205
gVrfOrch = &vrf_orch;
194206
gDirectory.set(static_cast<VRFOrch *>(&vrf_orch));
195207

208+
FlowCounterRouteOrch flow_counter_route_orch(gConfigDb, std::vector<std::string>{});
209+
gFlowCounterRouteOrch = &flow_counter_route_orch;
210+
gDirectory.set(static_cast<FlowCounterRouteOrch *>(&flow_counter_route_orch));
211+
196212
// Setup ports for all tests.
197213
SetupPorts();
198214
AddVrf();

0 commit comments

Comments
 (0)