From ed1b6b66f5b5d319e86aa7522edbf7517c7ed25d Mon Sep 17 00:00:00 2001 From: Kienan Stewart Date: Thu, 8 Feb 2024 09:02:48 -0500 Subject: [PATCH] tests: test_ust_constructor: Use a C-compiled shared object MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Similar to the previous change, this change splits the c-style constructors for the shared object into a separate object which can be compiled with gcc instead of g++. This makes it possible to test the constructors are traced even if LTTng-UST uses the LTTNG_UST_ALLOCATE_COMPOUND_LITERAL_ON_HEAP build configuration. Change-Id: Icd96cb30cedc1615951a6fec3c72731776f95d81 Signed-off-by: Kienan Stewart Signed-off-by: Jérémie Galarneau --- .../ust-constructor/test_ust_constructor.py | 4 +-- .../gen-ust-events-constructor/Makefile.am | 13 ++++++++ .../gen-ust-events-constructor/main.cpp | 5 +-- .../gen-ust-events-constructor/tp-so.h | 4 --- .../tp-so_c-define.c | 7 ++++ .../tp-so_c-provider.c | 8 +++++ .../gen-ust-events-constructor/tp-so_c.h | 33 +++++++++++++++++++ 7 files changed, 66 insertions(+), 8 deletions(-) create mode 100644 tests/utils/testapp/gen-ust-events-constructor/tp-so_c-define.c create mode 100644 tests/utils/testapp/gen-ust-events-constructor/tp-so_c-provider.c create mode 100644 tests/utils/testapp/gen-ust-events-constructor/tp-so_c.h diff --git a/tests/regression/ust/ust-constructor/test_ust_constructor.py b/tests/regression/ust/ust-constructor/test_ust_constructor.py index f9d97e20b..8b1fc613f 100755 --- a/tests/regression/ust/ust-constructor/test_ust_constructor.py +++ b/tests/regression/ust/ust-constructor/test_ust_constructor.py @@ -47,7 +47,7 @@ if process.returncode == 0: compound_literal_on_heap = True expected_events = [ - {"name": "tp_so:constructor_c_provider_shared_library", "msg": None, "count": 0}, + {"name": "tp_so_c:constructor_c_provider_shared_library", "msg": None, "count": 0}, { "name": "tp_a:constructor_c_provider_static_archive", "msg": None, @@ -264,7 +264,7 @@ expected_events = [ "count": 0, "may_fail": compound_literal_on_heap, }, - {"name": "tp_so:destructor_c_provider_shared_library", "msg": None, "count": 0}, + {"name": "tp_so_c:destructor_c_provider_shared_library", "msg": None, "count": 0}, ] num_tests = 7 + len(expected_events) diff --git a/tests/utils/testapp/gen-ust-events-constructor/Makefile.am b/tests/utils/testapp/gen-ust-events-constructor/Makefile.am index a855b25fe..5e9fd90f0 100644 --- a/tests/utils/testapp/gen-ust-events-constructor/Makefile.am +++ b/tests/utils/testapp/gen-ust-events-constructor/Makefile.am @@ -24,6 +24,7 @@ FORCE_SHARED_LIB_OPTIONS = -module -shared -avoid-version \ endif noinst_LTLIBRARIES = libtp-so-provider.la libtp-so-define.la \ + libtp-so_c-provider.la libtp-so_c-define.la \ libtp-a-provider.la libtp-a-define.la \ libtp-a_c-provider.la libtp-a_c-define.la @@ -40,6 +41,16 @@ libtp_so_define_la_SOURCES = \ libtp_so_define_la_LDFLAGS = \ $(FORCE_SHARED_LIB_OPTIONS) +libtp_so_c_provider_la_SOURCES = \ + tp-so_c-provider.c \ + tp-so_c.h +libtp_so_c_provider_la_LDFLAGS = $(FORCE_SHARED_LIB_OPTIONS) + +libtp_so_c_define_la_SOURCES = \ + tp-so_c-define.c \ + tp-so_c.h +libtp_so_c_define_la_LDFLAGS = $(FORCE_SHARED_LIB_OPTIONS) + # static archives libtp_a_provider_la_SOURCES = \ tp-a-provider.cpp \ @@ -72,6 +83,8 @@ gen_ust_events_constructor_SOURCES = main.cpp \ gen_ust_events_constructor_LDADD = $(UST_LIBS) \ $(builddir)/libtp-so-define.la \ $(builddir)/libtp-so-provider.la \ + $(builddir)/libtp-so_c-define.la \ + $(builddir)/libtp-so_c-provider.la \ $(builddir)/libtp-a-define.la \ $(builddir)/libtp-a-provider.la \ $(builddir)/libtp-a_c-define.la \ diff --git a/tests/utils/testapp/gen-ust-events-constructor/main.cpp b/tests/utils/testapp/gen-ust-events-constructor/main.cpp index 9b754f61f..8f80fb092 100644 --- a/tests/utils/testapp/gen-ust-events-constructor/main.cpp +++ b/tests/utils/testapp/gen-ust-events-constructor/main.cpp @@ -7,6 +7,7 @@ #include "obj.h" #include "tp-a.h" #include "tp-a_c.h" +#include "tp-so_c.h" #include "tp-so.h" #include "tp.h" @@ -14,13 +15,13 @@ void test_constructor_so(void) __attribute__((constructor)); void test_constructor_so(void) { - tracepoint(tp_so, constructor_c_provider_shared_library); + tracepoint(tp_so_c, constructor_c_provider_shared_library); } void test_destructor_so(void) __attribute__((destructor)); void test_destructor_so(void) { - tracepoint(tp_so, destructor_c_provider_shared_library); + tracepoint(tp_so_c, destructor_c_provider_shared_library); } Objso g_objso_shared_library("global - shared library define and provider"); diff --git a/tests/utils/testapp/gen-ust-events-constructor/tp-so.h b/tests/utils/testapp/gen-ust-events-constructor/tp-so.h index 0bdc3ed2f..41faec7d7 100644 --- a/tests/utils/testapp/gen-ust-events-constructor/tp-so.h +++ b/tests/utils/testapp/gen-ust-events-constructor/tp-so.h @@ -15,10 +15,6 @@ #include -TRACEPOINT_EVENT(tp_so, constructor_c_provider_shared_library, TP_ARGS(), TP_FIELDS()) - -TRACEPOINT_EVENT(tp_so, destructor_c_provider_shared_library, TP_ARGS(), TP_FIELDS()) - TRACEPOINT_EVENT(tp_so, constructor_cplusplus_provider_shared_library, TP_ARGS(const char *, msg), diff --git a/tests/utils/testapp/gen-ust-events-constructor/tp-so_c-define.c b/tests/utils/testapp/gen-ust-events-constructor/tp-so_c-define.c new file mode 100644 index 000000000..e16bce082 --- /dev/null +++ b/tests/utils/testapp/gen-ust-events-constructor/tp-so_c-define.c @@ -0,0 +1,7 @@ +/* + * Copyright (C) 2024 Kienan Stewart + * + * SPDX-License-Identifier: LGPL-2.1-only + */ +#define TRACEPOINT_DEFINE +#include "tp-so_c.h" diff --git a/tests/utils/testapp/gen-ust-events-constructor/tp-so_c-provider.c b/tests/utils/testapp/gen-ust-events-constructor/tp-so_c-provider.c new file mode 100644 index 000000000..aae3196df --- /dev/null +++ b/tests/utils/testapp/gen-ust-events-constructor/tp-so_c-provider.c @@ -0,0 +1,8 @@ +/* + * Copyright (C) 2024 Kienan Stewart + * + * SPDX-License-Identifier: LGPL-2.1-only + */ + +#define TRACEPOINT_CREATE_PROBES +#include "tp-so_c.h" diff --git a/tests/utils/testapp/gen-ust-events-constructor/tp-so_c.h b/tests/utils/testapp/gen-ust-events-constructor/tp-so_c.h new file mode 100644 index 000000000..58d77cdcf --- /dev/null +++ b/tests/utils/testapp/gen-ust-events-constructor/tp-so_c.h @@ -0,0 +1,33 @@ +/* + * Copyright (C) 2024 Kienan Stewart + * + * SPDX-License-Identifier: LGPL-2.1-only + */ + +#ifdef _cplusplus +extern "C" { +#endif + +#undef TRACEPOINT_PROVIDER +#define TRACEPOINT_PROVIDER tp_so_c + +#if !defined(_TRACEPOINT_TP_SO_C_H) || defined(TRACEPOINT_HEADER_MULTI_READ) +#define _TRACEPOINT_TP_SO_C_H + +#include + +TRACEPOINT_EVENT(tp_so_c, constructor_c_provider_shared_library, TP_ARGS(), TP_FIELDS()) + +TRACEPOINT_EVENT(tp_so_c, destructor_c_provider_shared_library, TP_ARGS(), TP_FIELDS()) + +#endif /* _TRACEPOINT_TP_SO_C_H */ + +#undef TRACEPOINT_INCLUDE +#define TRACEPOINT_INCLUDE "./tp-so_c.h" + +/* This part must be outside ifdef protection */ +#include + +#ifdef _cplusplus +} +#endif -- 2.34.1