From d1aa4a36b77f240a5a0185d1caf7696c6afb2416 Mon Sep 17 00:00:00 2001 From: r12f Date: Tue, 18 Apr 2023 15:49:00 -0700 Subject: [PATCH 1/6] Fix minor build errors, such as unnecessary copies from range enumeration. --- common/events.cpp | 6 +++--- tests/events_ut.cpp | 2 +- tests/stringutility_ut.cpp | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/common/events.cpp b/common/events.cpp index 7c4f4eddd..c6140021c 100644 --- a/common/events.cpp +++ b/common/events.cpp @@ -365,7 +365,7 @@ EventSubscriber::init(bool use_cache, int recv_timeout, RET_ON_ERR(rc == 0, "Fails to set option rc=%d", rc); } else { - for (const auto e: *subs_sources) { + for (const auto &e: *subs_sources) { rc = zmq_setsockopt(sock, ZMQ_SUBSCRIBE, e.c_str(), e.size()); RET_ON_ERR(rc == 0, "Fails to set option rc=%d", rc); } @@ -400,14 +400,14 @@ EventSubscriber::prune_track() map > lst; /* Sort entries by last touched time */ - for(const auto e: m_track) { + for(const auto &e: m_track) { lst[e.second.epoch_secs].push_back(e.first); } /* By default it walks from lowest value / earliest timestamp */ map >::const_iterator itc = lst.begin(); for(; (itc != lst.end()) && (m_track.size() > MAX_PUBLISHERS_COUNT); ++itc) { - for (const auto r: itc->second) { + for (const auto &r: itc->second) { m_track.erase(r); } } diff --git a/tests/events_ut.cpp b/tests/events_ut.cpp index ae9c684bc..91c8504c7 100644 --- a/tests/events_ut.cpp +++ b/tests/events_ut.cpp @@ -137,7 +137,7 @@ parse_read_evt(string &source, internal_event_t &evt, EXPECT_FALSE(source.empty()); EXPECT_EQ(4, evt.size()); - for (const auto e: evt) { + for (const auto &e: evt) { if (e.first == EVENT_STR_DATA) { EXPECT_EQ(0, convert_from_json(e.second, key, params)); // cout << "EVENT_STR_DATA: " << e.second << "\n"; diff --git a/tests/stringutility_ut.cpp b/tests/stringutility_ut.cpp index 209392592..9f2a5a5b9 100644 --- a/tests/stringutility_ut.cpp +++ b/tests/stringutility_ut.cpp @@ -74,7 +74,7 @@ TEST(STRINGUTILITY, join) TEST(STRINGUTILITY, hex_to_binary) { - std::array a; + std::array a = {0}; EXPECT_TRUE(swss::hex_to_binary("01020aff05", a.data(), a.size())); EXPECT_EQ(a, (std::array{0x1, 0x2, 0x0a, 0xff, 0x5})); From 60c045412715d6153426618b661d763f426a01aa Mon Sep 17 00:00:00 2001 From: r12f Date: Fri, 9 Jun 2023 02:51:32 +0000 Subject: [PATCH 2/6] Postpone changes in prune_track() due to lacking of test coverage. --- common/events.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/common/events.cpp b/common/events.cpp index c6140021c..a1b11acef 100644 --- a/common/events.cpp +++ b/common/events.cpp @@ -400,14 +400,14 @@ EventSubscriber::prune_track() map > lst; /* Sort entries by last touched time */ - for(const auto &e: m_track) { + for(const auto e: m_track) { lst[e.second.epoch_secs].push_back(e.first); } /* By default it walks from lowest value / earliest timestamp */ map >::const_iterator itc = lst.begin(); for(; (itc != lst.end()) && (m_track.size() > MAX_PUBLISHERS_COUNT); ++itc) { - for (const auto &r: itc->second) { + for (const auto r: itc->second) { m_track.erase(r); } } From f819f30a14b1d26e965020c87d8a590dfb2f334a Mon Sep 17 00:00:00 2001 From: r12f Date: Fri, 9 Jun 2023 03:24:44 +0000 Subject: [PATCH 3/6] Update init event source to get the updated code covered. --- tests/events_ut.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/events_ut.cpp b/tests/events_ut.cpp index 91c8504c7..413ff8e91 100644 --- a/tests/events_ut.cpp +++ b/tests/events_ut.cpp @@ -590,7 +590,8 @@ void do_test_subscribe(bool wrap) hsub = events_init_subscriber_wrap(true, 100); } else { - hsub = events_init_subscriber(true, 100); + std::vector sources = {""}; + hsub = events_init_subscriber(true, 100, &sources); } EXPECT_TRUE(NULL != hsub); EXPECT_EQ(last_svc_code, EVENT_CACHE_STOP); From 96d96bfb5b3cc3a62e3e0e14e5700f920d679bc9 Mon Sep 17 00:00:00 2001 From: r12f Date: Sun, 11 Jun 2023 15:09:59 +0000 Subject: [PATCH 4/6] Fix event epoch being 0 randomly. --- .gitignore | 5 +++++ tests/events_ut.cpp | 1 + 2 files changed, 6 insertions(+) diff --git a/.gitignore b/.gitignore index 7b8277a5e..031db0e11 100644 --- a/.gitignore +++ b/.gitignore @@ -57,6 +57,7 @@ stamp-h1 **/.deps/ **/.libs/ **/Makefile +aminclude_static.am # Executables # ############### @@ -66,3 +67,7 @@ sonic-db-cli/sonic-db-cli # Bazel Build System # /bazel-* + +# Unit test generated files # +############### +ut_dump_file.txt \ No newline at end of file diff --git a/tests/events_ut.cpp b/tests/events_ut.cpp index 413ff8e91..34d1e11d2 100644 --- a/tests/events_ut.cpp +++ b/tests/events_ut.cpp @@ -344,6 +344,7 @@ internal_event_t create_ev(const test_data_t &data) event_data[EVENT_RUNTIME_ID] = data.rid; event_data[EVENT_SEQUENCE] = data.seq; + event_data[EVENT_EPOCH] = "1"; return event_data; } From 584206b2aaff6b511413939294cbd38bc698998e Mon Sep 17 00:00:00 2001 From: r12f Date: Sun, 11 Jun 2023 15:11:19 +0000 Subject: [PATCH 5/6] Minor style fix. --- .gitignore | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 031db0e11..a97301458 100644 --- a/.gitignore +++ b/.gitignore @@ -69,5 +69,5 @@ sonic-db-cli/sonic-db-cli /bazel-* # Unit test generated files # -############### +############################# ut_dump_file.txt \ No newline at end of file From 74a47310e5e78cd0614088a6f3436b7975696e4b Mon Sep 17 00:00:00 2001 From: r12f Date: Thu, 15 Jun 2023 17:46:43 +0000 Subject: [PATCH 6/6] Fix comments. --- .gitignore | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index a97301458..7345204ce 100644 --- a/.gitignore +++ b/.gitignore @@ -70,4 +70,4 @@ sonic-db-cli/sonic-db-cli # Unit test generated files # ############################# -ut_dump_file.txt \ No newline at end of file +ut_dump_file.txt