Skip to content

Commit

Permalink
[sairedis] Style refactor cleanup (sonic-net#850)
Browse files Browse the repository at this point in the history
  • Loading branch information
kcudnik authored Jul 1, 2021
1 parent 3c485e5 commit 443ad36
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 13 deletions.
5 changes: 4 additions & 1 deletion lib/src/Recorder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1076,7 +1076,9 @@ void Recorder::recordQueryAattributeEnumValuesCapabilityResponse(
if (meta == NULL)
{
SWSS_LOG_ERROR("Failed to find attribute metadata: object type %s, attr id %d",
sai_serialize_object_type(objectType).c_str(), attrId);
sai_serialize_object_type(objectType).c_str(),
attrId);

return;
}

Expand All @@ -1092,6 +1094,7 @@ void Recorder::recordQueryAattributeEnumValuesCapabilityResponse(
{
auto str_attr_id = sai_serialize_attr_id(*meta);
auto str_enum_list = sai_serialize_enum_list(*enumValuesCapability, meta->enummetadata, countOnly);

values.emplace_back(str_attr_id, str_enum_list);
}

Expand Down
38 changes: 26 additions & 12 deletions lib/src/tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -771,38 +771,45 @@ static std::vector<std::string> parseFirstRecordedAPI()
{
SWSS_LOG_ENTER();

const auto delimiter = '|';
std::ifstream infile(SairedisRecFilename);
std::string line;

// skip first line
std::getline(infile, line);
std::getline(infile, line);

std::vector<std::string> tokens;
std::stringstream sstream(line);
std::string token;

const auto delimiter = '|';

// skip first, it is a timestamp
std::getline(sstream, token, delimiter);
while(std::getline(sstream, token, delimiter)) {

while(std::getline(sstream, token, delimiter))
{
tokens.push_back(token);
}

return tokens;
}

static void test_recorder_enum_value_capability_query_request(
sai_object_id_t switch_id,
sai_object_type_t object_type,
sai_attr_id_t attr_id,
const std::vector<std::string>& expectedOutput)
_In_ sai_object_id_t switch_id,
_In_ sai_object_type_t object_type,
_In_ sai_attr_id_t attr_id,
_In_ const std::vector<std::string>& expectedOutput)
{
SWSS_LOG_ENTER();

remove(SairedisRecFilename.c_str());

Recorder recorder;

recorder.enableRecording(true);

sai_s32_list_t enum_values_capability {.count = 0, .list = nullptr};
sai_s32_list_t enum_values_capability { .count = 0, .list = nullptr };

recorder.recordQueryAattributeEnumValuesCapability(
switch_id,
Expand All @@ -812,24 +819,27 @@ static void test_recorder_enum_value_capability_query_request(
);

auto tokens = parseFirstRecordedAPI();

ASSERT_EQ(tokens, expectedOutput);
}

static void test_recorder_enum_value_capability_query_response(
sai_status_t status,
sai_object_type_t object_type,
sai_attr_id_t attr_id,
std::vector<int32_t> enumList,
const std::vector<std::string>& expectedOutput)
_In_ sai_status_t status,
_In_ sai_object_type_t object_type,
_In_ sai_attr_id_t attr_id,
_In_ std::vector<int32_t> enumList,
_In_ const std::vector<std::string>& expectedOutput)
{
SWSS_LOG_ENTER();

remove(SairedisRecFilename.c_str());

Recorder recorder;

recorder.enableRecording(true);

sai_s32_list_t enum_values_capability;

enum_values_capability.count = static_cast<int32_t>(enumList.size());
enum_values_capability.list = enumList.data();

Expand All @@ -841,6 +851,7 @@ static void test_recorder_enum_value_capability_query_response(
);

auto tokens = parseFirstRecordedAPI();

ASSERT_EQ(tokens, expectedOutput);
}

Expand All @@ -859,6 +870,7 @@ static void test_recorder_enum_value_capability_query()
"SAI_DEBUG_COUNTER_ATTR_TYPE=0",
}
);

test_recorder_enum_value_capability_query_response(
SAI_STATUS_SUCCESS,
SAI_OBJECT_TYPE_DEBUG_COUNTER,
Expand All @@ -877,6 +889,7 @@ static void test_recorder_enum_value_capability_query()
"SAI_DEBUG_COUNTER_TYPE_SWITCH_IN_DROP_REASONS,SAI_DEBUG_COUNTER_TYPE_SWITCH_OUT_DROP_REASONS",
}
);

test_recorder_enum_value_capability_query_request(
1,
SAI_OBJECT_TYPE_DEBUG_COUNTER,
Expand All @@ -888,6 +901,7 @@ static void test_recorder_enum_value_capability_query()
"SAI_DEBUG_COUNTER_ATTR_IN_DROP_REASON_LIST=0",
}
);

test_recorder_enum_value_capability_query_response(
SAI_STATUS_SUCCESS,
SAI_OBJECT_TYPE_DEBUG_COUNTER,
Expand Down

0 comments on commit 443ad36

Please sign in to comment.