Skip to content

Commit

Permalink
[syncd] Move logSet logGet under mutex to prevent race condition
Browse files Browse the repository at this point in the history
  • Loading branch information
kcudnik committed Feb 5, 2025
1 parent cfd46c4 commit 1cc0489
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
2 changes: 2 additions & 0 deletions syncd/VendorSai.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1679,6 +1679,7 @@ sai_status_t VendorSai::logSet(
_In_ sai_api_t api,
_In_ sai_log_level_t log_level)
{
MUTEX();
SWSS_LOG_ENTER();

m_logLevelMap[api] = log_level;
Expand All @@ -1689,6 +1690,7 @@ sai_status_t VendorSai::logSet(
sai_log_level_t VendorSai::logGet(
_In_ sai_api_t api)
{
MUTEX();
SWSS_LOG_ENTER();

auto it = m_logLevelMap.find(api);
Expand Down
12 changes: 12 additions & 0 deletions unittest/syncd/TestVendorSai.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1405,3 +1405,15 @@ TEST(VendorSai, bulk_dash_outbound_ca_to_pa_entry)
remove_counter(sai, counter0);
remove_counter(sai, counter1);
}

TEST(VendorSai, logSet_logGet)
{
VendorSai sai;
sai.apiInitialize(0, &test_services);

EXPECT_EQ(SAI_STATUS_SUCCESS, sai.logSet(SAI_API_PORT, SAI_LOG_LEVEL_DEBUG));

EXPECT(SAI_LOG_LEVEL_DEBUG, sai.logGet(SAI_API_PORT));
EXPECT(SAI_LOG_LEVEL_NOTICE, sai.logGet(SAI_API_SWITCH));
}

0 comments on commit 1cc0489

Please sign in to comment.