Skip to content

Commit

Permalink
[mux_rollback_ut.cpp] fixing mux_rollback_ut tests for bulk switchover
Browse files Browse the repository at this point in the history
bulk switchover feature chages the sai_api calls in switchover flow.
Because of this mux_rollback_ut tests fail. This PR adds bulk operations
to mock_sai_neighbor and mock_sai_api, and adjusts the expected function
calls in mux_rollback_ut.

Signed-off-by: Nikola Dancejic <ndancejic@microsoft.com>
  • Loading branch information
Ndancejic committed May 27, 2024
1 parent 2b3240b commit f259759
Show file tree
Hide file tree
Showing 5 changed files with 193 additions and 127 deletions.
3 changes: 1 addition & 2 deletions orchagent/muxorch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -978,7 +978,7 @@ bool MuxNbrHandler::createBulkRouteEntries(std::list<MuxRouteBulkContext>& bulk_
count++;
}

SWSS_LOG_INFO("Successfully created %d bulk neighbor entries", count);
SWSS_LOG_INFO("Successfully created %d bulk route entries", count);
return true;
}

Expand Down Expand Up @@ -1043,7 +1043,6 @@ bool MuxNbrHandler::processBulkRouteEntries(std::list<MuxRouteBulkContext>& bulk
}

SWSS_LOG_NOTICE("Removed tunnel route to %s ", ctx->pfx.to_string().c_str());
return status;
}
}
return true;
Expand Down
18 changes: 18 additions & 0 deletions orchagent/p4orch/tests/mock_sai_neighbor.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@ class MockSaiNeighbor

MOCK_METHOD1(remove_neighbor_entry, sai_status_t(_In_ const sai_neighbor_entry_t *neighbor_entry));

MOCK_METHOD6(create_neighbor_entries, sai_status_t(_In_ uint32_t object_count, _In_ const sai_neighbor_entry_t *neighbor_entry, _In_ const uint32_t *attr_count,
_In_ const sai_attribute_t **attr_list, _In_ sai_bulk_op_error_mode_t mode, _Out_ sai_status_t *object_statuses));

MOCK_METHOD4(remove_neighbor_entries, sai_status_t(_In_ uint32_t object_count, _In_ const sai_neighbor_entry_t *neighbor_entry, _In_ sai_bulk_op_error_mode_t mode,
_Out_ sai_status_t *object_statuses));

MOCK_METHOD2(set_neighbor_entry_attribute,
sai_status_t(_In_ const sai_neighbor_entry_t *neighbor_entry, _In_ const sai_attribute_t *attr));

Expand All @@ -37,6 +43,18 @@ sai_status_t mock_remove_neighbor_entry(_In_ const sai_neighbor_entry_t *neighbo
return mock_sai_neighbor->remove_neighbor_entry(neighbor_entry);
}

sai_status_t mock_create_neighbor_entries(_In_ uint32_t object_count, _In_ const sai_neighbor_entry_t *neighbor_entry, _In_ const uint32_t *attr_count,
_In_ const sai_attribute_t **attr_list, _In_ sai_bulk_op_error_mode_t mode, _Out_ sai_status_t *object_statuses)
{
return mock_sai_neighbor->create_neighbor_entries(object_count, neighbor_entry, attr_count, attr_list, mode, object_statuses);
}

sai_status_t mock_remove_neighbor_entries(_In_ uint32_t object_count, _In_ const sai_neighbor_entry_t *neighbor_entry, _In_ sai_bulk_op_error_mode_t mode,
_Out_ sai_status_t *object_statuses)
{
return mock_sai_neighbor->remove_neighbor_entries(object_count, neighbor_entry, mode, object_statuses);
}

sai_status_t mock_set_neighbor_entry_attribute(_In_ const sai_neighbor_entry_t *neighbor_entry,
_In_ const sai_attribute_t *attr)
{
Expand Down
2 changes: 2 additions & 0 deletions orchagent/p4orch/tests/neighbor_manager_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,8 @@ class NeighborManagerTest : public ::testing::Test
mock_sai_neighbor = &mock_sai_neighbor_;
sai_neighbor_api->create_neighbor_entry = mock_create_neighbor_entry;
sai_neighbor_api->remove_neighbor_entry = mock_remove_neighbor_entry;
sai_neighbor_api->create_neighbor_entries = mock_create_neighbor_entries;
sai_neighbor_api->remove_neighbor_entries = mock_remove_neighbor_entries;
sai_neighbor_api->set_neighbor_entry_attribute = mock_set_neighbor_entry_attribute;
sai_neighbor_api->get_neighbor_entry_attribute = mock_get_neighbor_entry_attribute;
}
Expand Down
54 changes: 40 additions & 14 deletions tests/mock_tests/mock_sai_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,12 @@ EXTERN_MOCK_FNS

#define CREATE_PARAMS(sai_object_type) _In_ const sai_##sai_object_type##_entry_t *sai_object_type##_entry, _In_ uint32_t attr_count, _In_ const sai_attribute_t *attr_list
#define REMOVE_PARAMS(sai_object_type) _In_ const sai_##sai_object_type##_entry_t *sai_object_type##_entry
#define CREATE_BULK_PARAMS(sai_object_type) _In_ uint32_t object_count, _In_ const sai_##sai_object_type##_entry_t *sai_object_type##_entry, _In_ const uint32_t *attr_count, _In_ const sai_attribute_t **attr_list, _In_ sai_bulk_op_error_mode_t mode, _Out_ sai_status_t *object_statuses
#define REMOVE_BULK_PARAMS(sai_object_type) _In_ uint32_t object_count, _In_ const sai_##sai_object_type##_entry_t *sai_object_type##_entry, _In_ sai_bulk_op_error_mode_t mode, _In_ sai_status_t *object_statuses
#define CREATE_ARGS(sai_object_type) sai_object_type##_entry, attr_count, attr_list
#define REMOVE_ARGS(sai_object_type) sai_object_type##_entry
#define CREATE_BULK_ARGS(sai_object_type) object_count, sai_object_type##_entry, attr_count, attr_list, mode, object_statuses
#define REMOVE_BULK_ARGS(sai_object_type) object_count, sai_object_type##_entry, mode, object_statuses
#define GENERIC_CREATE_PARAMS(sai_object_type) _Out_ sai_object_id_t *sai_object_type##_id, _In_ sai_object_id_t switch_id, _In_ uint32_t attr_count, _In_ const sai_attribute_t *attr_list
#define GENERIC_REMOVE_PARAMS(sai_object_type) _In_ sai_object_id_t sai_object_type##_id
#define GENERIC_CREATE_ARGS(sai_object_type) sai_object_type##_id, switch_id, attr_count, attr_list
Expand All @@ -42,8 +46,8 @@ The macro DEFINE_SAI_API_MOCK will perform the steps to mock the SAI API for the
7. Define a method to remove the mock
*/
#define DEFINE_SAI_API_MOCK(sai_object_type) \
static sai_##sai_object_type##_api_t *old_sai_##sai_object_type##_api; \
static sai_##sai_object_type##_api_t ut_sai_##sai_object_type##_api; \
static sai_##sai_object_type##_api_t *old_sai_##sai_object_type##_api; \
static sai_##sai_object_type##_api_t ut_sai_##sai_object_type##_api; \
class mock_sai_##sai_object_type##_api_t \
{ \
public: \
Expand All @@ -59,20 +63,40 @@ The macro DEFINE_SAI_API_MOCK will perform the steps to mock the SAI API for the
[this](REMOVE_PARAMS(sai_object_type)) { \
return old_sai_##sai_object_type##_api->remove_##sai_object_type##_entry(REMOVE_ARGS(sai_object_type)); \
}); \
ON_CALL(*this, create_##sai_object_type##_entries) \
.WillByDefault( \
[this](CREATE_BULK_PARAMS(sai_object_type)) { \
return old_sai_##sai_object_type##_api->create_##sai_object_type##_entries(CREATE_BULK_ARGS(sai_object_type)); \
}); \
ON_CALL(*this, remove_##sai_object_type##_entries) \
.WillByDefault( \
[this](REMOVE_BULK_PARAMS(sai_object_type)) { \
return old_sai_##sai_object_type##_api->remove_##sai_object_type##_entries(REMOVE_BULK_ARGS(sai_object_type)); \
}); \
} \
MOCK_METHOD3(create_##sai_object_type##_entry, sai_status_t(CREATE_PARAMS(sai_object_type))); \
MOCK_METHOD1(remove_##sai_object_type##_entry, sai_status_t(REMOVE_PARAMS(sai_object_type))); \
MOCK_METHOD6(create_##sai_object_type##_entries, sai_status_t(CREATE_BULK_PARAMS(sai_object_type))); \
MOCK_METHOD4(remove_##sai_object_type##_entries, sai_status_t(REMOVE_BULK_PARAMS(sai_object_type))); \
}; \
static mock_sai_##sai_object_type##_api_t *mock_sai_##sai_object_type##_api; \
inline sai_status_t mock_create_##sai_object_type##_entry(CREATE_PARAMS(sai_object_type)) \
static mock_sai_##sai_object_type##_api_t *mock_sai_##sai_object_type##_api; \
inline sai_status_t mock_create_##sai_object_type##_entry(CREATE_PARAMS(sai_object_type)) \
{ \
return mock_sai_##sai_object_type##_api->create_##sai_object_type##_entry(CREATE_ARGS(sai_object_type)); \
} \
inline sai_status_t mock_remove_##sai_object_type##_entry(REMOVE_PARAMS(sai_object_type)) \
inline sai_status_t mock_remove_##sai_object_type##_entry(REMOVE_PARAMS(sai_object_type)) \
{ \
return mock_sai_##sai_object_type##_api->remove_##sai_object_type##_entry(REMOVE_ARGS(sai_object_type)); \
} \
inline void apply_sai_##sai_object_type##_api_mock() \
inline sai_status_t mock_create_##sai_object_type##_entries(CREATE_BULK_PARAMS(sai_object_type)) \
{ \
return mock_sai_##sai_object_type##_api->create_##sai_object_type##_entries(CREATE_BULK_ARGS(sai_object_type)); \
} \
inline sai_status_t mock_remove_##sai_object_type##_entries(REMOVE_BULK_PARAMS(sai_object_type)) \
{ \
return mock_sai_##sai_object_type##_api->remove_##sai_object_type##_entries(REMOVE_BULK_ARGS(sai_object_type)); \
} \
inline void apply_sai_##sai_object_type##_api_mock() \
{ \
mock_sai_##sai_object_type##_api = new NiceMock<mock_sai_##sai_object_type##_api_t>(); \
\
Expand All @@ -82,16 +106,18 @@ The macro DEFINE_SAI_API_MOCK will perform the steps to mock the SAI API for the
\
sai_##sai_object_type##_api->create_##sai_object_type##_entry = mock_create_##sai_object_type##_entry; \
sai_##sai_object_type##_api->remove_##sai_object_type##_entry = mock_remove_##sai_object_type##_entry; \
sai_##sai_object_type##_api->create_##sai_object_type##_entries = mock_create_##sai_object_type##_entries; \
sai_##sai_object_type##_api->remove_##sai_object_type##_entries = mock_remove_##sai_object_type##_entries; \
} \
inline void remove_sai_##sai_object_type##_api_mock() \
inline void remove_sai_##sai_object_type##_api_mock() \
{ \
sai_##sai_object_type##_api = old_sai_##sai_object_type##_api; \
delete mock_sai_##sai_object_type##_api; \
}

#define DEFINE_SAI_GENERIC_API_MOCK(sai_api_name, sai_object_type) \
static sai_##sai_api_name##_api_t *old_sai_##sai_api_name##_api; \
static sai_##sai_api_name##_api_t ut_sai_##sai_api_name##_api; \
static sai_##sai_api_name##_api_t *old_sai_##sai_api_name##_api; \
static sai_##sai_api_name##_api_t ut_sai_##sai_api_name##_api; \
class mock_sai_##sai_api_name##_api_t \
{ \
public: \
Expand All @@ -111,16 +137,16 @@ The macro DEFINE_SAI_API_MOCK will perform the steps to mock the SAI API for the
MOCK_METHOD4(create_##sai_object_type, sai_status_t(GENERIC_CREATE_PARAMS(sai_object_type))); \
MOCK_METHOD1(remove_##sai_object_type, sai_status_t(GENERIC_REMOVE_PARAMS(sai_object_type))); \
}; \
static mock_sai_##sai_api_name##_api_t *mock_sai_##sai_api_name##_api; \
inline sai_status_t mock_create_##sai_object_type(GENERIC_CREATE_PARAMS(sai_object_type)) \
static mock_sai_##sai_api_name##_api_t *mock_sai_##sai_api_name##_api; \
inline sai_status_t mock_create_##sai_object_type(GENERIC_CREATE_PARAMS(sai_object_type)) \
{ \
return mock_sai_##sai_api_name##_api->create_##sai_object_type(GENERIC_CREATE_ARGS(sai_object_type)); \
} \
inline sai_status_t mock_remove_##sai_object_type(GENERIC_REMOVE_PARAMS(sai_object_type)) \
inline sai_status_t mock_remove_##sai_object_type(GENERIC_REMOVE_PARAMS(sai_object_type)) \
{ \
return mock_sai_##sai_api_name##_api->remove_##sai_object_type(GENERIC_REMOVE_ARGS(sai_object_type)); \
} \
inline void apply_sai_##sai_api_name##_api_mock() \
inline void apply_sai_##sai_api_name##_api_mock() \
{ \
mock_sai_##sai_api_name##_api = new NiceMock<mock_sai_##sai_api_name##_api_t>(); \
\
Expand All @@ -131,7 +157,7 @@ The macro DEFINE_SAI_API_MOCK will perform the steps to mock the SAI API for the
sai_##sai_api_name##_api->create_##sai_object_type = mock_create_##sai_object_type; \
sai_##sai_api_name##_api->remove_##sai_object_type = mock_remove_##sai_object_type; \
} \
inline void remove_sai_##sai_api_name##_api_mock() \
inline void remove_sai_##sai_api_name##_api_mock() \
{ \
sai_##sai_api_name##_api = old_sai_##sai_api_name##_api; \
delete mock_sai_##sai_api_name##_api; \
Expand Down
Loading

0 comments on commit f259759

Please sign in to comment.