From 9224e13166c5801d3880154ca771f89c9aebcc6b Mon Sep 17 00:00:00 2001 From: kcudnik Date: Tue, 17 Aug 2021 09:37:20 +0200 Subject: [PATCH] Add switch tests --- unittest/vslib/Makefile.am | 1 + unittest/vslib/test_sai_vs_switch.cpp | 35 +++++++++++++++++++++++++++ vslib/sai_vs_switch.cpp | 8 +++--- 3 files changed, 40 insertions(+), 4 deletions(-) create mode 100644 unittest/vslib/test_sai_vs_switch.cpp diff --git a/unittest/vslib/Makefile.am b/unittest/vslib/Makefile.am index 04009aad276e..f3bd1d1bea26 100644 --- a/unittest/vslib/Makefile.am +++ b/unittest/vslib/Makefile.am @@ -46,6 +46,7 @@ testslibsaivs_SOURCES = main_libsaivs.cpp \ test_sai_vs_schedulergroup.cpp \ test_sai_vs_scheduler.cpp \ test_sai_vs_segmentroute.cpp \ + test_sai_vs_switch.cpp \ test_sai_vs_stp.cpp \ test_sai_vs_vlan.cpp \ test_sai_vs_hostif.cpp \ diff --git a/unittest/vslib/test_sai_vs_switch.cpp b/unittest/vslib/test_sai_vs_switch.cpp new file mode 100644 index 000000000000..6335a9a4dc2f --- /dev/null +++ b/unittest/vslib/test_sai_vs_switch.cpp @@ -0,0 +1,35 @@ +#include + +extern "C" { +#include "sai.h" +} + +#include "swss/logger.h" + +TEST(libsaivs, switch) +{ + sai_switch_api_t *api = nullptr; + + sai_api_query(SAI_API_SWITCH, (void**)&api); + + EXPECT_NE(api, nullptr); + + sai_object_id_t id; + + EXPECT_NE(SAI_STATUS_SUCCESS, api->create_switch(&id,0,0)); + EXPECT_NE(SAI_STATUS_SUCCESS, api->remove_switch(0)); + EXPECT_NE(SAI_STATUS_SUCCESS, api->set_switch_attribute(0,0)); + EXPECT_NE(SAI_STATUS_SUCCESS, api->get_switch_attribute(0,0,0)); + + EXPECT_NE(SAI_STATUS_SUCCESS, api->get_switch_stats(0,0,0,0)); + EXPECT_NE(SAI_STATUS_SUCCESS, api->get_switch_stats_ext(0,0,0,SAI_STATS_MODE_READ,0)); + EXPECT_NE(SAI_STATUS_SUCCESS, api->clear_switch_stats(0,0,0)); + + EXPECT_EQ(SAI_STATUS_NOT_IMPLEMENTED, api->switch_mdio_read(0,0,0,0,0)); + EXPECT_EQ(SAI_STATUS_NOT_IMPLEMENTED, api->switch_mdio_write(0,0,0,0,0)); + + EXPECT_NE(SAI_STATUS_SUCCESS, api->create_switch_tunnel(&id,0,0,0)); + EXPECT_NE(SAI_STATUS_SUCCESS, api->remove_switch_tunnel(0)); + EXPECT_NE(SAI_STATUS_SUCCESS, api->set_switch_tunnel_attribute(0,0)); + EXPECT_NE(SAI_STATUS_SUCCESS, api->get_switch_tunnel_attribute(0,0,0)); +} diff --git a/vslib/sai_vs_switch.cpp b/vslib/sai_vs_switch.cpp index e16b8fb51af0..e0be09d09703 100644 --- a/vslib/sai_vs_switch.cpp +++ b/vslib/sai_vs_switch.cpp @@ -18,7 +18,7 @@ static sai_status_t vs_create_switch_uniq( attr_list); } -static sai_status_t vs_mdio_read( +static sai_status_t vs_switch_mdio_read( _In_ sai_object_id_t switch_id, _In_ uint32_t device_addr, _In_ uint32_t start_reg_addr, @@ -30,7 +30,7 @@ static sai_status_t vs_mdio_read( return SAI_STATUS_NOT_IMPLEMENTED; } -static sai_status_t vs_mdio_write( +static sai_status_t vs_switch_mdio_write( _In_ sai_object_id_t switch_id, _In_ uint32_t device_addr, _In_ uint32_t start_reg_addr, @@ -51,8 +51,8 @@ const sai_switch_api_t vs_switch_api = { VS_GENERIC_STATS_API(switch) - vs_mdio_read, - vs_mdio_write, + vs_switch_mdio_read, + vs_switch_mdio_write, VS_GENERIC_QUAD_API(switch_tunnel)