tests: Add C versions of gen-ust-events-constructor
authorKienan Stewart <kstewart@efficios.com>
Fri, 9 Feb 2024 15:23:39 +0000 (10:23 -0500)
committerJérémie Galarneau <jeremie.galarneau@efficios.com>
Thu, 7 Mar 2024 17:21:23 +0000 (12:21 -0500)
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 <kstewart@efficios.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
.gitignore
tests/regression/ust/ust-constructor/test_ust_constructor.py
tests/utils/testapp/gen-ust-events-constructor/01-c-tp-before-define.c [new file with mode: 0644]
tests/utils/testapp/gen-ust-events-constructor/02-c-define-tp.c [new file with mode: 0644]
tests/utils/testapp/gen-ust-events-constructor/03-c-tp-after-define.c [new file with mode: 0644]
tests/utils/testapp/gen-ust-events-constructor/04-c-tp-provider.c [new file with mode: 0644]
tests/utils/testapp/gen-ust-events-constructor/05-c-tp-after-provider.c [new file with mode: 0644]
tests/utils/testapp/gen-ust-events-constructor/Makefile.am
tests/utils/testapp/gen-ust-events-constructor/main_c-a.c [new file with mode: 0644]
tests/utils/testapp/gen-ust-events-constructor/main_c-so.c [new file with mode: 0644]

index 97694519e028386d4ad1f70dfb85d06665325294..4c5a4e5e9999f9b0dbf86be3eb07f51df7a0983d 100644 (file)
@@ -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
index 5446fb3ec08ef1636c39cdd371e064fc13abbc3f..130d0657da35a988148142d8a7071601629b26aa 100755 (executable)
@@ -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 (file)
index 0000000..6b1d9ed
--- /dev/null
@@ -0,0 +1,19 @@
+/*
+ * Copyright (C) 2024 Kienan Stewart <kstewart@efficios.com>
+ *
+ * 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 (file)
index 0000000..117ffba
--- /dev/null
@@ -0,0 +1,45 @@
+/*
+ * Copyright (C) 2024 Kienan Stewart <kstewart@efficios.com>
+ *
+ * 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 (file)
index 0000000..2be0b77
--- /dev/null
@@ -0,0 +1,19 @@
+/*
+ * Copyright (C) 2024 Kienan Stewart <kstewart@efficios.com>
+ *
+ * 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 (file)
index 0000000..51b47e1
--- /dev/null
@@ -0,0 +1,45 @@
+/*
+ * Copyright (C) 2024 Kienan Stewart <kstewart@efficios.com>
+ *
+ * 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 (file)
index 0000000..4bc566d
--- /dev/null
@@ -0,0 +1,19 @@
+/*
+ * Copyright (C) 2024 Kienan Stewart <kstewart@efficios.com>
+ *
+ * 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);
+}
index b68602b348a05f9f8c7fc0f2bcfc22aea5652e04..6c09cf58575cb5ec9be7d6fc76a663fbbb521229 100644 (file)
@@ -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 (file)
index 0000000..0a7d1f0
--- /dev/null
@@ -0,0 +1,27 @@
+/*
+ * Copyright (C) 2024 Kienan Stewart <kstewart@efficios.com>
+ *
+ * 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 (file)
index 0000000..70ee49b
--- /dev/null
@@ -0,0 +1,27 @@
+/*
+ * Copyright (C) 2024 Kienan Stewart <kstewart@efficios.com>
+ *
+ * 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;
+}
This page took 0.032392 seconds and 4 git commands to generate.