From 443ad36c4a12bc98d3b82f16c4167f0122ca94b2 Mon Sep 17 00:00:00 2001 From: Kamil Cudnik Date: Thu, 1 Jul 2021 23:53:00 +0200 Subject: [PATCH] [sairedis] Style refactor cleanup (#850) --- lib/src/Recorder.cpp | 5 ++++- lib/src/tests.cpp | 38 ++++++++++++++++++++++++++------------ 2 files changed, 30 insertions(+), 13 deletions(-) diff --git a/lib/src/Recorder.cpp b/lib/src/Recorder.cpp index 5469492c9622..001130c7d9d9 100644 --- a/lib/src/Recorder.cpp +++ b/lib/src/Recorder.cpp @@ -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; } @@ -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); } diff --git a/lib/src/tests.cpp b/lib/src/tests.cpp index c3a8c494d14a..fe4f67fae953 100644 --- a/lib/src/tests.cpp +++ b/lib/src/tests.cpp @@ -771,9 +771,9 @@ static std::vector 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); @@ -781,28 +781,35 @@ static std::vector parseFirstRecordedAPI() std::vector 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& 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& 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, @@ -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 enumList, - const std::vector& expectedOutput) + _In_ sai_status_t status, + _In_ sai_object_type_t object_type, + _In_ sai_attr_id_t attr_id, + _In_ std::vector enumList, + _In_ const std::vector& 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(enumList.size()); enum_values_capability.list = enumList.data(); @@ -841,6 +851,7 @@ static void test_recorder_enum_value_capability_query_response( ); auto tokens = parseFirstRecordedAPI(); + ASSERT_EQ(tokens, expectedOutput); } @@ -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, @@ -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, @@ -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,