From 9e0f2f64da1331fe8a4b15ee9637590a665ddd68 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=A9mie=20Galarneau?= Date: Thu, 5 Sep 2024 19:25:34 +0000 Subject: [PATCH] Tests: test_session: fix conditionally-supported offsetof warning MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit g++ produces the following warning when building test_session on the CI: /home/jenkins/workspace/dev_review_lttng-tools_master_linuxbuild/babeltrace_version/stable-2.0/build/std/conf/std/liburcu_version/stable-0.14/platform/deb12-amd64/deps/build/include/urcu/list.h:160:49: warning: ‘offsetof’ within non-standard-layout type ‘ltt_session’ is conditionally-supported [-Winvalid-offsetof] 160 | for (pos = cds_list_entry((head)->next, __typeof__(*(pos)), member); \ /home/jenkins/workspace/dev_review_lttng-tools_master_linuxbuild/babeltrace_version/stable-2.0/build/std/conf/std/liburcu_version/stable-0.14/platform/deb12-amd64/deps/build/include/urcu/list.h:126:49: note: in expansion of macro ‘caa_container_of’ 126 | #define cds_list_entry(ptr, type, member) caa_container_of(ptr, type, member) | ^~~~~~~~~~~~~~~~ Replace the problematic liburcu macros with the C++-ified internal replacement wrappers. Change-Id: I1396e9f6e1d99710150e03cabc33d07df3d8558a Signed-off-by: Jérémie Galarneau --- tests/unit/test_session.cpp | 32 +++++++++++++++++--------------- 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/tests/unit/test_session.cpp b/tests/unit/test_session.cpp index 37de10d3b..3c7e0b3fb 100644 --- a/tests/unit/test_session.cpp +++ b/tests/unit/test_session.cpp @@ -8,6 +8,7 @@ #include #include #include +#include #include #include @@ -59,10 +60,9 @@ static char *get_random_string() */ static int find_session_name(const char *name) { - struct ltt_session *iter; - - cds_list_for_each_entry (iter, &session_list->head, list) { - if (strcmp(iter->name, name) == 0) { + for (auto *session : lttng::urcu::list_iteration_adapter( + session_list->head)) { + if (strcmp(session->name, name) == 0) { return 0; } } @@ -73,11 +73,13 @@ static int find_session_name(const char *name) static int session_list_count() { int count = 0; - struct ltt_session *iter; - cds_list_for_each_entry (iter, &session_list->head, list) { + for (auto *session [[maybe_unused]] : + lttng::urcu::list_iteration_adapter( + session_list->head)) { count++; } + return count; } @@ -86,11 +88,10 @@ static int session_list_count() */ static void empty_session_list() { - struct ltt_session *iter, *tmp; - const auto list_lock = lttng::sessiond::lock_session_list(); - cds_list_for_each_entry_safe (iter, tmp, &session_list->head, list) { - session_destroy(iter); + for (auto *session : lttng::urcu::list_iteration_adapter( + session_list->head)) { + session_destroy(session); } /* Session list must be 0 */ @@ -288,7 +289,6 @@ end: static void test_large_session_number() { int ret, i, failed = 0; - struct ltt_session *iter, *tmp; for (i = 0; i < MAX_SESSIONS; i++) { char *tmp_name = get_random_string(); @@ -305,10 +305,12 @@ static void test_large_session_number() const auto list_lock = lttng::sessiond::lock_session_list(); for (i = 0; i < MAX_SESSIONS; i++) { - cds_list_for_each_entry_safe (iter, tmp, &session_list->head, list) { - ret = destroy_one_session([iter]() { - session_get(iter); - return ltt_session::make_ref(*iter); + for (auto *session : + lttng::urcu::list_iteration_adapter( + session_list->head)) { + ret = destroy_one_session([session]() { + session_get(session); + return ltt_session::make_ref(*session); }()); if (ret < 0) { -- 2.39.5