From 21b65d7fb06219571f42159b3667454c3104a8b7 Mon Sep 17 00:00:00 2001 From: Kienan Stewart Date: Fri, 9 Feb 2024 10:23:39 -0500 Subject: [PATCH] tests: Add C versions of gen-ust-events-constructor MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Observed issue ============== The constructor tests exercise only the case where C++ applications are built. Solution ======== Adding C test applications allows us the reuse the existing test infrastructure to cover these cases. Known drawbacks =============== None. Change-Id: Ib178dfd33cce0f1d0aa125aaee078c2dcb84ecb9 Signed-off-by: Kienan Stewart Signed-off-by: Jérémie Galarneau --- .gitignore | 2 + .../ust-constructor/test_ust_constructor.py | 123 +++++++++++------- .../01-c-tp-before-define.c | 19 +++ .../02-c-define-tp.c | 45 +++++++ .../03-c-tp-after-define.c | 19 +++ .../04-c-tp-provider.c | 45 +++++++ .../05-c-tp-after-provider.c | 19 +++ .../gen-ust-events-constructor/Makefile.am | 32 ++++- .../gen-ust-events-constructor/main_c-a.c | 27 ++++ .../gen-ust-events-constructor/main_c-so.c | 27 ++++ 10 files changed, 313 insertions(+), 45 deletions(-) create mode 100644 tests/utils/testapp/gen-ust-events-constructor/01-c-tp-before-define.c create mode 100644 tests/utils/testapp/gen-ust-events-constructor/02-c-define-tp.c create mode 100644 tests/utils/testapp/gen-ust-events-constructor/03-c-tp-after-define.c create mode 100644 tests/utils/testapp/gen-ust-events-constructor/04-c-tp-provider.c create mode 100644 tests/utils/testapp/gen-ust-events-constructor/05-c-tp-after-provider.c create mode 100644 tests/utils/testapp/gen-ust-events-constructor/main_c-a.c create mode 100644 tests/utils/testapp/gen-ust-events-constructor/main_c-so.c diff --git a/.gitignore b/.gitignore index 97694519e..4c5a4e5e9 100644 --- a/.gitignore +++ b/.gitignore @@ -102,6 +102,8 @@ compile_commands.json /tests/utils/testapp/gen-ust-events/gen-ust-events /tests/utils/testapp/gen-ust-events-constructor/gen-ust-events-constructor-a /tests/utils/testapp/gen-ust-events-constructor/gen-ust-events-constructor-so +/tests/utils/testapp/gen-ust-events-constructor/gen-ust-events-c-constructor-a +/tests/utils/testapp/gen-ust-events-constructor/gen-ust-events-c-constructor-so /tests/utils/testapp/gen-ust-events-constructor/uses_heap /tests/utils/testapp/gen-ust-events-ns/gen-ust-events-ns /tests/regression/tools/health/health_check diff --git a/tests/regression/ust/ust-constructor/test_ust_constructor.py b/tests/regression/ust/ust-constructor/test_ust_constructor.py index 5446fb3ec..130d0657d 100755 --- a/tests/regression/ust/ust-constructor/test_ust_constructor.py +++ b/tests/regression/ust/ust-constructor/test_ust_constructor.py @@ -47,31 +47,13 @@ process.wait() if process.returncode == 0: compound_literal_on_heap = True -expected_events_common = [ - { - "name": "tp:constructor_c_across_units_before_define", - "msg": None, - "count": 0, - "may_fail": compound_literal_on_heap, - }, +expected_events_common_cpp = [ { "name": "tp:constructor_cplusplus", "msg": "global - across units before define", "count": 0, "may_fail": compound_literal_on_heap, }, - { - "name": "tp:constructor_c_same_unit_before_define", - "msg": None, - "count": 0, - "may_fail": compound_literal_on_heap, - }, - { - "name": "tp:constructor_c_same_unit_after_define", - "msg": None, - "count": 0, - "may_fail": compound_literal_on_heap, - }, { "name": "tp:constructor_cplusplus", "msg": "global - same unit before define", @@ -84,30 +66,12 @@ expected_events_common = [ "count": 0, "may_fail": compound_literal_on_heap, }, - { - "name": "tp:constructor_c_across_units_after_define", - "msg": None, - "count": 0, - "may_fail": compound_literal_on_heap, - }, { "name": "tp:constructor_cplusplus", "msg": "global - across units after define", "count": 0, "may_fail": compound_literal_on_heap, }, - { - "name": "tp:constructor_c_same_unit_before_provider", - "msg": None, - "count": 0, - "may_fail": compound_literal_on_heap, - }, - { - "name": "tp:constructor_c_same_unit_after_provider", - "msg": None, - "count": 0, - "may_fail": compound_literal_on_heap, - }, { "name": "tp:constructor_cplusplus", "msg": "global - same unit before provider", @@ -119,7 +83,6 @@ expected_events_common = [ "msg": "global - same unit after provider", "count": 0, }, - {"name": "tp:constructor_c_across_units_after_provider", "msg": None, "count": 0}, { "name": "tp:constructor_cplusplus", "msg": "global - across units after provider", @@ -127,7 +90,6 @@ expected_events_common = [ }, {"name": "tp:constructor_cplusplus", "msg": "main() local", "count": 0}, {"name": "tp:destructor_cplusplus", "msg": "main() local", "count": 0}, - {"name": "tp:main", "msg": None, "count": 0}, { "name": "tp:destructor_cplusplus", "msg": "global - across units after provider", @@ -168,6 +130,47 @@ expected_events_common = [ "count": 0, "may_fail": compound_literal_on_heap, }, +] + +expected_events_common = [ + { + "name": "tp:constructor_c_across_units_before_define", + "msg": None, + "count": 0, + "may_fail": compound_literal_on_heap, + }, + { + "name": "tp:constructor_c_same_unit_before_define", + "msg": None, + "count": 0, + "may_fail": compound_literal_on_heap, + }, + { + "name": "tp:constructor_c_same_unit_after_define", + "msg": None, + "count": 0, + "may_fail": compound_literal_on_heap, + }, + { + "name": "tp:constructor_c_across_units_after_define", + "msg": None, + "count": 0, + "may_fail": compound_literal_on_heap, + }, + { + "name": "tp:constructor_c_same_unit_before_provider", + "msg": None, + "count": 0, + "may_fail": compound_literal_on_heap, + }, + { + "name": "tp:constructor_c_same_unit_after_provider", + "msg": None, + "count": 0, + "may_fail": compound_literal_on_heap, + }, + {"name": "tp:constructor_c_across_units_after_provider", "msg": None, "count": 0}, + {"name": "tp:main", "msg": None, "count": 0}, { "name": "tp:destructor_c_across_units_after_provider", "msg": None, @@ -211,8 +214,8 @@ expected_events_common = [ "may_fail": compound_literal_on_heap, }, ] -expected_events_tp_so = [ - {"name": "tp_so_c:constructor_c_provider_shared_library", "msg": None, "count": 0}, + +expected_events_tp_so_cpp = [ { "name": "tp_so:constructor_cplusplus_provider_shared_library", "msg": "global - shared library define and provider", @@ -233,10 +236,14 @@ expected_events_tp_so = [ "msg": "global - shared library define and provider", "count": 0, }, +] + +expected_events_tp_so = [ + {"name": "tp_so_c:constructor_c_provider_shared_library", "msg": None, "count": 0}, {"name": "tp_so_c:destructor_c_provider_shared_library", "msg": None, "count": 0}, ] -expected_events_tp_a = [ - {"name": "tp_a_c:constructor_c_provider_static_archive", "msg": None, "count": 0}, + +expected_events_tp_a_cpp = [ { "name": "tp_a:constructor_cplusplus_provider_static_archive", "msg": "global - static archive define and provider", @@ -259,6 +266,10 @@ expected_events_tp_a = [ "count": 0, "may_fail": compound_literal_on_heap, }, +] + +expected_events_tp_a = [ + {"name": "tp_a_c:constructor_c_provider_static_archive", "msg": None, "count": 0}, {"name": "tp_a_c:destructor_c_provider_static_archive", "msg": None, "count": 0}, ] @@ -364,12 +375,36 @@ tests = [ { "description": "Test user space constructor/destructor instrumentation coverage (C++ w/ static archive)", "application": "gen-ust-events-constructor/gen-ust-events-constructor-a", - "expected_events": copy.deepcopy(expected_events_common + expected_events_tp_a), + "expected_events": copy.deepcopy( + expected_events_common + + expected_events_common_cpp + + expected_events_tp_a + + expected_events_tp_a_cpp + ), "skip_if_application_not_present": False, }, { "description": "Test user space constructor/destructor instrumentation coverage (C++ w/ dynamic object", "application": "gen-ust-events-constructor/gen-ust-events-constructor-so", + "expected_events": copy.deepcopy( + expected_events_common + + expected_events_common_cpp + + expected_events_tp_so + + expected_events_tp_so_cpp + ), + # This application is not be built when `NO_SHARED` is set in the + # configuration options. + "skip_if_application_not_present": True, + }, + { + "description": "Test user space constructor/destructor instrumentation coverage (C w/ static archive)", + "application": "gen-ust-events-constructor/gen-ust-events-c-constructor-a", + "expected_events": copy.deepcopy(expected_events_common + expected_events_tp_a), + "skip_if_application_not_present": False, + }, + { + "description": "Test user space constructor/destructor instrumentation coverage (C w/ dynamic object", + "application": "gen-ust-events-constructor/gen-ust-events-c-constructor-so", "expected_events": copy.deepcopy( expected_events_common + expected_events_tp_so ), diff --git a/tests/utils/testapp/gen-ust-events-constructor/01-c-tp-before-define.c b/tests/utils/testapp/gen-ust-events-constructor/01-c-tp-before-define.c new file mode 100644 index 000000000..6b1d9edad --- /dev/null +++ b/tests/utils/testapp/gen-ust-events-constructor/01-c-tp-before-define.c @@ -0,0 +1,19 @@ +/* + * Copyright (C) 2024 Kienan Stewart + * + * SPDX-License-Identifier: LGPL-2.1-only + */ + +#include "tp.h" + +void test_constructor1(void) __attribute__((constructor)); +void test_constructor1(void) +{ + tracepoint(tp, constructor_c_across_units_before_define); +} + +void test_destructor1(void) __attribute__((destructor)); +void test_destructor1(void) +{ + tracepoint(tp, destructor_c_across_units_before_define); +} diff --git a/tests/utils/testapp/gen-ust-events-constructor/02-c-define-tp.c b/tests/utils/testapp/gen-ust-events-constructor/02-c-define-tp.c new file mode 100644 index 000000000..117ffbad3 --- /dev/null +++ b/tests/utils/testapp/gen-ust-events-constructor/02-c-define-tp.c @@ -0,0 +1,45 @@ +/* + * Copyright (C) 2024 Kienan Stewart + * + * SPDX-License-Identifier: LGPL-2.1-only + */ + +static void fct_constructor2(void); +static void fct_destructor2(void); + +void test_constructor2_same_unit_before(void) __attribute__((constructor)); +void test_constructor2_same_unit_before(void) +{ + fct_constructor2(); +} + +void test_destructor2_same_unit_before(void) __attribute__((destructor)); +void test_destructor2_same_unit_before(void) +{ + fct_destructor2(); +} + +#define TRACEPOINT_DEFINE +#include "tp.h" + +static void fct_constructor2(void) +{ + tracepoint(tp, constructor_c_same_unit_before_define); +} + +static void fct_destructor2(void) +{ + tracepoint(tp, destructor_c_same_unit_before_define); +} + +void test_constructor2_same_unit_after(void) __attribute__((constructor)); +void test_constructor2_same_unit_after(void) +{ + tracepoint(tp, constructor_c_same_unit_after_define); +} + +void test_destructor2_same_unit_after(void) __attribute__((destructor)); +void test_destructor2_same_unit_after(void) +{ + tracepoint(tp, destructor_c_same_unit_after_define); +} diff --git a/tests/utils/testapp/gen-ust-events-constructor/03-c-tp-after-define.c b/tests/utils/testapp/gen-ust-events-constructor/03-c-tp-after-define.c new file mode 100644 index 000000000..2be0b7701 --- /dev/null +++ b/tests/utils/testapp/gen-ust-events-constructor/03-c-tp-after-define.c @@ -0,0 +1,19 @@ +/* + * Copyright (C) 2024 Kienan Stewart + * + * SPDX-License-Identifier: LGPL-2.1-only + */ + +#include "tp.h" + +void test_constructor3(void) __attribute__((constructor)); +void test_constructor3(void) +{ + tracepoint(tp, constructor_c_across_units_after_define); +} + +void test_destructor3(void) __attribute__((destructor)); +void test_destructor3(void) +{ + tracepoint(tp, destructor_c_across_units_after_define); +} diff --git a/tests/utils/testapp/gen-ust-events-constructor/04-c-tp-provider.c b/tests/utils/testapp/gen-ust-events-constructor/04-c-tp-provider.c new file mode 100644 index 000000000..51b47e13a --- /dev/null +++ b/tests/utils/testapp/gen-ust-events-constructor/04-c-tp-provider.c @@ -0,0 +1,45 @@ +/* + * Copyright (C) 2024 Kienan Stewart + * + * SPDX-License-Identifier: LGPL-2.1-only + */ + +static void fct_constructor4(void); +static void fct_destructor4(void); + +void test_constructor4_same_unit_before(void) __attribute__((constructor)); +void test_constructor4_same_unit_before(void) +{ + fct_constructor4(); +} + +void test_destructor4_same_unit_before(void) __attribute__((destructor)); +void test_destructor4_same_unit_before(void) +{ + fct_destructor4(); +} + +#define TRACEPOINT_CREATE_PROBES +#include "tp.h" + +static void fct_constructor4(void) +{ + tracepoint(tp, constructor_c_same_unit_before_provider); +} + +static void fct_destructor4(void) +{ + tracepoint(tp, destructor_c_same_unit_before_provider); +} + +void test_constructor4_same_unit_after(void) __attribute__((constructor)); +void test_constructor4_same_unit_after(void) +{ + tracepoint(tp, constructor_c_same_unit_after_provider); +} + +void test_destructor4_same_unit_after(void) __attribute__((destructor)); +void test_destructor4_same_unit_after(void) +{ + tracepoint(tp, destructor_c_same_unit_after_provider); +} diff --git a/tests/utils/testapp/gen-ust-events-constructor/05-c-tp-after-provider.c b/tests/utils/testapp/gen-ust-events-constructor/05-c-tp-after-provider.c new file mode 100644 index 000000000..4bc566d96 --- /dev/null +++ b/tests/utils/testapp/gen-ust-events-constructor/05-c-tp-after-provider.c @@ -0,0 +1,19 @@ +/* + * Copyright (C) 2024 Kienan Stewart + * + * SPDX-License-Identifier: LGPL-2.1-only + */ + +#include "tp.h" + +void test_constructor5(void) __attribute__((constructor)); +void test_constructor5(void) +{ + tracepoint(tp, constructor_c_across_units_after_provider); +} + +void test_destructor5(void) __attribute__((destructor)); +void test_destructor5(void) +{ + tracepoint(tp, destructor_c_across_units_after_provider); +} diff --git a/tests/utils/testapp/gen-ust-events-constructor/Makefile.am b/tests/utils/testapp/gen-ust-events-constructor/Makefile.am index b68602b34..6c09cf585 100644 --- a/tests/utils/testapp/gen-ust-events-constructor/Makefile.am +++ b/tests/utils/testapp/gen-ust-events-constructor/Makefile.am @@ -15,6 +15,7 @@ AM_CXXFLAGS += $(WARN_FLAGS) noinst_LTLIBRARIES = libtp-a-provider.la libtp-a-define.la \ libtp-a_c-provider.la libtp-a_c-define.la noinst_PROGRAMS = gen-ust-events-constructor-a \ + gen-ust-events-c-constructor-a \ uses_heap if NO_SHARED @@ -29,7 +30,8 @@ FORCE_SHARED_LIB_OPTIONS = -module -shared -avoid-version \ noinst_LTLIBRARIES += libtp-so-provider.la libtp-so-define.la \ libtp-so_c-provider.la libtp-so_c-define.la -noinst_PROGRAMS += gen-ust-events-constructor-so +noinst_PROGRAMS += gen-ust-events-constructor-so \ + gen-ust-events-c-constructor-so endif @@ -91,6 +93,21 @@ gen_ust_events_constructor_so_LDADD = $(UST_LIBS) \ $(top_builddir)/tests/utils/libtestutils.la \ $(DL_LIBS) +gen_ust_events_c_constructor_so_SOURCES = main_c-so.c \ + 01-c-tp-before-define.c \ + 02-c-define-tp.c \ + 03-c-tp-after-define.c \ + 04-c-tp-provider.c \ + 05-c-tp-after-provider.c \ + tp.h +gen_ust_events_c_constructor_so_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 \ + $(top_builddir)/tests/utils/libtestutils.la \ + $(DL_LIBS) + gen_ust_events_constructor_a_SOURCES = main-a.cpp \ 01-tp-before-define.cpp \ 02-define-tp.cpp \ @@ -108,6 +125,19 @@ gen_ust_events_constructor_a_LDADD = $(UST_LIBS) \ $(top_builddir)/tests/utils/libtestutils.la \ $(DL_LIBS) +gen_ust_events_c_constructor_a_SOURCES = main_c-a.c \ + 01-c-tp-before-define.c \ + 02-c-define-tp.c \ + 03-c-tp-after-define.c \ + 04-c-tp-provider.c \ + 05-c-tp-after-provider.c \ + tp.h +gen_ust_events_c_constructor_a_LDADD = $(UST_LIBS) \ + $(builddir)/libtp-a_c-define.la \ + $(builddir)/libtp-a_c-provider.la \ + $(top_builddir)/tests/utils/libtestutils.la \ + $(DL_LIBS) + uses_heap_SOURCES = uses_heap.cpp endif diff --git a/tests/utils/testapp/gen-ust-events-constructor/main_c-a.c b/tests/utils/testapp/gen-ust-events-constructor/main_c-a.c new file mode 100644 index 000000000..0a7d1f0b6 --- /dev/null +++ b/tests/utils/testapp/gen-ust-events-constructor/main_c-a.c @@ -0,0 +1,27 @@ +/* + * Copyright (C) 2024 Kienan Stewart + * + * SPDX-License-Identifier: LGPL-2.1-only + */ + +#include "tp-a_c.h" +#include "tp.h" + +/* Use tracepoints defined and provided by static archive. */ +void test_constructor_a(void) __attribute__((constructor)); +void test_constructor_a(void) +{ + tracepoint(tp_a_c, constructor_c_provider_static_archive); +} + +void test_destructor_a(void) __attribute__((destructor)); +void test_destructor_a(void) +{ + tracepoint(tp_a_c, destructor_c_provider_static_archive); +} + +int main(void) +{ + tracepoint(tp, main); + return 0; +} diff --git a/tests/utils/testapp/gen-ust-events-constructor/main_c-so.c b/tests/utils/testapp/gen-ust-events-constructor/main_c-so.c new file mode 100644 index 000000000..70ee49b19 --- /dev/null +++ b/tests/utils/testapp/gen-ust-events-constructor/main_c-so.c @@ -0,0 +1,27 @@ +/* + * Copyright (C) 2024 Kienan Stewart + * + * SPDX-LIcense-Identifier: LGPL-2.1-only + */ + +#include "tp-so_c.h" +#include "tp.h" + +/* Use tracepoints defined and provided by shared libraries. */ +void test_constructor_so(void) __attribute__((constructor)); +void test_constructor_so(void) +{ + tracepoint(tp_so_c, constructor_c_provider_shared_library); +} + +void test_destructor_so(void) __attribute__((destructor)); +void test_destructor_so(void) +{ + tracepoint(tp_so_c, destructor_c_provider_shared_library); +} + +int main(void) +{ + tracepoint(tp, main); + return 0; +} -- 2.34.1