Tests: test_session: fix conditionally-supported offsetof warning
authorJérémie Galarneau <jeremie.galarneau@efficios.com>
Thu, 5 Sep 2024 19:25:34 +0000 (19:25 +0000)
committerJérémie Galarneau <jeremie.galarneau@efficios.com>
Thu, 5 Sep 2024 19:25:34 +0000 (19:25 +0000)
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 <jeremie.galarneau@efficios.com>
tests/unit/test_session.cpp

index 37de10d3bb097df97227aaaf4649063381d03cd5..3c7e0b3fb9ca877e60f2d76adce97f3b6e5c67d9 100644 (file)
@@ -8,6 +8,7 @@
 #include <common/common.hpp>
 #include <common/compat/errno.hpp>
 #include <common/sessiond-comm/sessiond-comm.hpp>
+#include <common/urcu.hpp>
 
 #include <bin/lttng-sessiond/health-sessiond.hpp>
 #include <bin/lttng-sessiond/session.hpp>
@@ -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<ltt_session, &ltt_session::list>(
+                    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<ltt_session, &ltt_session::list>(
+                    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<ltt_session, &ltt_session::list>(
+                    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<ltt_session, &ltt_session::list>(
+                            session_list->head)) {
+                       ret = destroy_one_session([session]() {
+                               session_get(session);
+                               return ltt_session::make_ref(*session);
                        }());
 
                        if (ret < 0) {
This page took 0.027267 seconds and 4 git commands to generate.