[lttng-dev] [Patch LTTng-ust v2 3/7] Add an example using CTF global type enumerations

Geneviève Bastien gbastien+lttng at versatic.net
Tue Feb 11 16:35:32 EST 2014


A new test example is introduced in tests/ctf-global-types. This test
application will be used to test the support of CTF global type declarations.
For now, it contains two tracepoints that use a global enumeration.

Signed-off-by: Geneviève Bastien <gbastien+lttng at versatic.net>
---
 configure.ac                                       |  1 +
 tests/Makefile.am                                  |  2 +-
 tests/ctf-global-types/Makefile.am                 | 13 ++++
 tests/ctf-global-types/README                      |  3 +
 tests/ctf-global-types/ctf-global-types.c          | 46 ++++++++++++++
 tests/ctf-global-types/tp.c                        | 26 ++++++++
 .../ctf-global-types/ust_tests_ctf_global_types.h  | 71 ++++++++++++++++++++++
 7 files changed, 161 insertions(+), 1 deletion(-)
 create mode 100644 tests/ctf-global-types/Makefile.am
 create mode 100644 tests/ctf-global-types/README
 create mode 100644 tests/ctf-global-types/ctf-global-types.c
 create mode 100644 tests/ctf-global-types/tp.c
 create mode 100644 tests/ctf-global-types/ust_tests_ctf_global_types.h

diff --git a/configure.ac b/configure.ac
index 72a0314..710a390 100644
--- a/configure.ac
+++ b/configure.ac
@@ -295,6 +295,7 @@ AC_CONFIG_FILES([
 	liblttng-ust-cyg-profile/Makefile
 	tools/Makefile
 	tests/Makefile
+	tests/ctf-global-types/Makefile
 	tests/hello/Makefile
 	tests/hello.cxx/Makefile
 	tests/same_line_tracepoint/Makefile
diff --git a/tests/Makefile.am b/tests/Makefile.am
index b5166f9..c3f9e71 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -1,4 +1,4 @@
-SUBDIRS = utils hello same_line_tracepoint snprintf benchmark
+SUBDIRS = utils hello same_line_tracepoint snprintf benchmark ctf-global-types
 
 if CXX_WORKS
 SUBDIRS += hello.cxx
diff --git a/tests/ctf-global-types/Makefile.am b/tests/ctf-global-types/Makefile.am
new file mode 100644
index 0000000..2ae0b54
--- /dev/null
+++ b/tests/ctf-global-types/Makefile.am
@@ -0,0 +1,13 @@
+AM_CPPFLAGS = -I$(top_srcdir)/include -I$(top_builddir)/include -Wsystem-headers
+
+noinst_PROGRAMS = ctf-global-types
+ctf_global_types_SOURCES = ctf-global-types.c tp.c ust_tests_ctf_global_types.h
+ctf_global_types_LDADD = $(top_builddir)/liblttng-ust/liblttng-ust.la
+ctf_global_types_CFLAGS = -Werror=old-style-definition
+
+if LTTNG_UST_BUILD_WITH_LIBDL
+ctf_global_types_LDADD += -ldl
+endif
+if LTTNG_UST_BUILD_WITH_LIBC_DL
+ctf_global_types_LDADD += -lc
+endif
diff --git a/tests/ctf-global-types/README b/tests/ctf-global-types/README
new file mode 100644
index 0000000..0544476
--- /dev/null
+++ b/tests/ctf-global-types/README
@@ -0,0 +1,3 @@
+This is a "hello world" application used to verify that an instrumented program
+with tracepoints using global type declarations in CTF metadata can be built
+successfully.
diff --git a/tests/ctf-global-types/ctf-global-types.c b/tests/ctf-global-types/ctf-global-types.c
new file mode 100644
index 0000000..81b69e1
--- /dev/null
+++ b/tests/ctf-global-types/ctf-global-types.c
@@ -0,0 +1,46 @@
+/*
+ * Copyright (C) 2014  Geneviève Bastien <gbastien at versatic.net>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; version 2.1 of
+ * the License.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301 USA
+ */
+
+#include <unistd.h>
+
+#define TRACEPOINT_DEFINE
+#include "ust_tests_ctf_global_types.h"
+
+int main(int argc, char **argv)
+{
+	int i;
+	int delay = 0;
+
+	if (argc == 2)
+		delay = atoi(argv[1]);
+
+	fprintf(stderr, "Hello, World!\n");
+
+	sleep(delay);
+
+	fprintf(stderr, "Tracing... ");
+	for (i = 0; i < 100; i++) {
+		tracepoint(ust_tests_ctf_global_types, tptest, i, (i % 6));
+	}
+
+	for (i = 0; i < 10; i++) {
+		tracepoint(ust_tests_ctf_global_types, tptest_bis, i, (i % 5));
+	}
+	fprintf(stderr, " done.\n");
+	return 0;
+}
diff --git a/tests/ctf-global-types/tp.c b/tests/ctf-global-types/tp.c
new file mode 100644
index 0000000..581e9e7
--- /dev/null
+++ b/tests/ctf-global-types/tp.c
@@ -0,0 +1,26 @@
+/*
+ * tp.c
+ *
+ * Copyright (c) 2014 Geneviève Bastien <gbastien at versatic.net>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+#define TRACEPOINT_CREATE_PROBES
+#include "ust_tests_ctf_global_types.h"
diff --git a/tests/ctf-global-types/ust_tests_ctf_global_types.h b/tests/ctf-global-types/ust_tests_ctf_global_types.h
new file mode 100644
index 0000000..a1c0527
--- /dev/null
+++ b/tests/ctf-global-types/ust_tests_ctf_global_types.h
@@ -0,0 +1,71 @@
+#undef TRACEPOINT_PROVIDER
+#define TRACEPOINT_PROVIDER ust_tests_ctf_global_types
+
+#if !defined(_TRACEPOINT_UST_TESTS_CTF_GLOBAL_TYPES_H) || defined(TRACEPOINT_HEADER_MULTI_READ)
+#define _TRACEPOINT_UST_TESTS_CTF_GLOBAL_TYPES_H
+
+/*
+ * Copyright (C) 2014 Geneviève Bastien <gbastien at versatic.net>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+#include <lttng/tracepoint.h>
+
+TRACEPOINT_ENUM(ust_tests_ctf_global_types, testenum, int,
+	TP_ENUM_VALUES(
+		ctf_enum_value("even", 0)
+		ctf_enum_value("uneven", 1)
+		ctf_enum_range("twoto4", 2, 4)
+		ctf_enum_value("five", 5)
+	)
+)
+
+/*
+ * Enumeration field is used twice to make sure the global type declaration
+ * is entered only once in the metadata file.
+ */
+TRACEPOINT_EVENT(ust_tests_ctf_global_types, tptest,
+	TP_ARGS(int, anint, int, enumval),
+	TP_FIELDS(
+		ctf_integer(int, intfield, anint)
+		ctf_enum(ust_tests_ctf_global_types, testenum, enumfield, enumval)
+		ctf_enum(ust_tests_ctf_global_types, testenum, enumfield_bis, enumval)
+	)
+)
+
+/*
+ * Another tracepoint using the global types to make sure each global type is
+ * entered only once in the metadata file.
+ */
+TRACEPOINT_EVENT(ust_tests_ctf_global_types, tptest_bis,
+	TP_ARGS(int, anint, int, enumval),
+	TP_FIELDS(
+		ctf_integer(int, intfield, anint)
+		ctf_enum(ust_tests_ctf_global_types, testenum, enumfield, enumval)
+	)
+)
+
+#endif /* _TRACEPOINT_UST_TESTS_CTF_GLOBAL_TYPES_H */
+
+#undef TRACEPOINT_INCLUDE
+#define TRACEPOINT_INCLUDE "./ust_tests_ctf_global_types.h"
+
+/* This part must be outside ifdef protection */
+#include <lttng/tracepoint-event.h>
-- 
1.8.5.4




More information about the lttng-dev mailing list