[lttng-dev] [Patch LTTng-tools v2 5/5] Regression tests for global type declarations in UST

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


Signed-off-by: Geneviève Bastien <gbastien+lttng at versatic.net>
---
 configure.ac                                       |   1 +
 tests/fast_regression                              |   1 +
 tests/regression/test_list.py                      |   6 ++
 tests/regression/ust/Makefile.am                   |   2 +-
 .../ust/global-type-declarations/Makefile.am       |  29 ++++++
 .../regression/ust/global-type-declarations/README |  22 ++++
 .../global-type-declarations.c                     |  37 +++++++
 .../test_global_type_declarations                  |  37 +++++++
 .../test_global_type_declarations.py               | 114 +++++++++++++++++++++
 .../ust/global-type-declarations/ust_tests_gtd.h   |  67 ++++++++++++
 10 files changed, 315 insertions(+), 1 deletion(-)
 create mode 100644 tests/regression/ust/global-type-declarations/Makefile.am
 create mode 100644 tests/regression/ust/global-type-declarations/README
 create mode 100644 tests/regression/ust/global-type-declarations/global-type-declarations.c
 create mode 100755 tests/regression/ust/global-type-declarations/test_global_type_declarations
 create mode 100644 tests/regression/ust/global-type-declarations/test_global_type_declarations.py
 create mode 100644 tests/regression/ust/global-type-declarations/ust_tests_gtd.h

diff --git a/configure.ac b/configure.ac
index 65503a3..2f720da 100644
--- a/configure.ac
+++ b/configure.ac
@@ -437,6 +437,7 @@ AC_CONFIG_FILES([
 	tests/regression/ust/fork/Makefile
 	tests/regression/ust/libc-wrapper/Makefile
 	tests/regression/ust/java-jul/Makefile
+	tests/regression/ust/global-type-declarations/Makefile
 	tests/stress/Makefile
 	tests/unit/Makefile
 	tests/unit/ini_config/Makefile
diff --git a/tests/fast_regression b/tests/fast_regression
index 40acf5c..0331ace 100644
--- a/tests/fast_regression
+++ b/tests/fast_regression
@@ -19,3 +19,4 @@ regression/ust/overlap/test_overlap
 regression/ust/java-jul/test_java_jul
 regression/ust/test_event_basic
 regression/ust/test_event_wildcard
+regression/ust/global-type-declarations/test_global_type_declarations
diff --git a/tests/regression/test_list.py b/tests/regression/test_list.py
index 21afa1c..ff5b00a 100755
--- a/tests/regression/test_list.py
+++ b/tests/regression/test_list.py
@@ -77,6 +77,12 @@ Tests = \
     'desc': "Test tracing with 4 sessions for one application",
     'success': 0, 'enabled': True
     },
+    {
+    'bin': "ust/global_type_declarations/run", 'daemon': True, 'kern': False,
+    'name': "UST tracer - CTF global type declarations",
+    'desc': "Test tracepoints using CTF global type declarations",
+    'success': 0, 'enabled': True
+    },
 
     # Tools filtering tests
     {
diff --git a/tests/regression/ust/Makefile.am b/tests/regression/ust/Makefile.am
index a4e3455..de71b60 100644
--- a/tests/regression/ust/Makefile.am
+++ b/tests/regression/ust/Makefile.am
@@ -1,7 +1,7 @@
 if HAVE_LIBLTTNG_UST_CTL
 SUBDIRS = nprocesses high-throughput low-throughput before-after multi-session \
 		overlap buffers-pid linking daemon exit-fast fork libc-wrapper \
-		periodical-metadata-flush java-jul
+		periodical-metadata-flush java-jul global-type-declarations
 
 EXTRA_DIST = test_event_basic test_event_wildcard
 
diff --git a/tests/regression/ust/global-type-declarations/Makefile.am b/tests/regression/ust/global-type-declarations/Makefile.am
new file mode 100644
index 0000000..7346931
--- /dev/null
+++ b/tests/regression/ust/global-type-declarations/Makefile.am
@@ -0,0 +1,29 @@
+AM_CPPFLAGS = -I$(srcdir)
+
+noinst_PROGRAMS = global-type-declarations
+global_type_declarations_SOURCES = global-type-declarations.c ust_tests_gtd.h
+global_type_declarations_LDADD = -llttng-ust
+
+if LTTNG_TOOLS_BUILD_WITH_LIBDL
+global_type_declarations_LDADD += -ldl
+endif
+if LTTNG_TOOLS_BUILD_WITH_LIBC_DL
+global_type_declarations_LDADD += -lc
+endif
+
+noinst_SCRIPTS = test_global_type_declarations test_global_type_declarations.py
+EXTRA_DIST = test_global_type_declarations test_global_type_declarations.py
+
+all-local:
+	@if [ x"$(srcdir)" != x"$(builddir)" ]; then \
+		for script in $(EXTRA_DIST); do \
+			cp -f $(srcdir)/$$script $(builddir); \
+		done; \
+	fi
+
+clean-local:
+	@if [ x"$(srcdir)" != x"$(builddir)" ]; then \
+		for script in $(EXTRA_DIST); do \
+			rm -f $(builddir)/$$script; \
+		done; \
+	fi
diff --git a/tests/regression/ust/global-type-declarations/README b/tests/regression/ust/global-type-declarations/README
new file mode 100644
index 0000000..4523237
--- /dev/null
+++ b/tests/regression/ust/global-type-declarations/README
@@ -0,0 +1,22 @@
+Global type declarations test
+-----------------------------
+
+This test checks if tracepoints using global type declarations work correctly.
+
+DESCRIPTION
+-----------
+
+This test launches a process who generates events with fields using global type
+declarations. 
+
+The test makes sure the events are present and the fields have all the
+correct data. 
+
+DEPENDENCIES
+------------
+
+To run this test, you will need:
+
+  - lttng-tools (with python bindings)
+  - babeltrace
+  - python 3.0 or better
\ No newline at end of file
diff --git a/tests/regression/ust/global-type-declarations/global-type-declarations.c b/tests/regression/ust/global-type-declarations/global-type-declarations.c
new file mode 100644
index 0000000..edd6fc7
--- /dev/null
+++ b/tests/regression/ust/global-type-declarations/global-type-declarations.c
@@ -0,0 +1,37 @@
+/* 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; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * 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
+ */
+
+/* This test generates a single event and exits.
+ */
+
+#include <unistd.h>
+
+#define TRACEPOINT_DEFINE
+#define TRACEPOINT_CREATE_PROBES
+#include "ust_tests_gtd.h"
+
+int main(int argc, char *argv[])
+{
+	int i;
+
+	for (i = 0; i < 2; i++) {
+		tracepoint(ust_tests_gtd, tptest, i%2, (i+1)%2);
+		tracepoint(ust_tests_gtd, tptest_bis, i%2);
+	}
+
+	return 0;
+}
diff --git a/tests/regression/ust/global-type-declarations/test_global_type_declarations b/tests/regression/ust/global-type-declarations/test_global_type_declarations
new file mode 100755
index 0000000..cf22d0f
--- /dev/null
+++ b/tests/regression/ust/global-type-declarations/test_global_type_declarations
@@ -0,0 +1,37 @@
+#!/bin/bash
+#
+# 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
+TEST_DESC="UST tracer - Test tracepoints using ctf global type declarations"
+
+
+# Check for a running sessiond
+`pidof lt-lttng-sessiond`
+STOP_SESSIOND=$?
+
+CURDIR=$(dirname $0)
+TESTDIR=${CURDIR}/../../..
+
+# Try to launch a sessiond before invoking the python test script
+if [ $STOP_SESSIOND -ne 0 ]; then
+	DIR=$(readlink -f ${TESTDIR})
+	${DIR}/../src/bin/lttng-sessiond/lttng-sessiond --daemonize --quiet --consumerd32-path="$DIR/../src/bin/lttng-consumerd/lttng-consumerd" --consumerd64-path="$DIR/../src/bin/lttng-consumerd/lttng-consumerd"
+fi
+
+python3 ${CURDIR}/test_global_type_declarations.py
+
+if [ $STOP_SESSIOND -ne 0 ]; then
+    kill `pidof lt-lttng-sessiond`
+fi
diff --git a/tests/regression/ust/global-type-declarations/test_global_type_declarations.py b/tests/regression/ust/global-type-declarations/test_global_type_declarations.py
new file mode 100644
index 0000000..e7a7c22
--- /dev/null
+++ b/tests/regression/ust/global-type-declarations/test_global_type_declarations.py
@@ -0,0 +1,114 @@
+#!/usr/bin/env python3
+#
+# Copyright (C) - 2014 Geneviève Bastien <gbastien at versatic.net>
+#
+# This program is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License, version 2 only, as
+# published by the Free Software Foundation.
+#
+# This program 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 General Public License for
+# more details.
+#
+# You should have received a copy of the GNU General Public License along with
+# this program; if not, write to the Free Software Foundation, Inc., 51
+# Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+
+import os
+import subprocess
+import re
+import shutil
+import sys
+
+test_path = os.path.dirname(os.path.abspath(__file__)) + "/"
+test_utils_path = test_path
+for i in range(4):
+    test_utils_path = os.path.dirname(test_utils_path)
+test_utils_path = test_utils_path + "/utils"
+sys.path.append(test_utils_path)
+from test_utils import *
+
+NR_TESTS = 9
+current_test = 1
+print("1..{0}".format(NR_TESTS))
+
+# Check if a sessiond is running... bail out if none found.
+if session_daemon_alive() == 0:
+    bail("No sessiond running. Please make sure you are running this test with the \"run\" shell script and verify that the lttng tools are properly installed.")
+
+session_info = create_session()
+enable_ust_tracepoint_event(session_info, "ust_tests_gtd*")
+start_session(session_info)
+
+test_env = os.environ.copy()
+test_env["LTTNG_UST_REGISTER_TIMEOUT"] = "-1"
+
+gtd_process = subprocess.Popen(test_path + "global-type-declarations", stdout=subprocess.PIPE, stderr=subprocess.PIPE, env=test_env)
+
+if sys.version_info >= (3, 3):
+    try:
+        gtd_process.wait(5)
+    except TimeoutExpired:
+        gtd_process.kill()
+        bail("Failed to run global-type-declarations test application.")
+else:
+    gtd_process.wait()
+
+print_test_result(gtd_process.returncode == 0, current_test, "Test application exited normally")
+current_test += 1
+
+stop_session(session_info)
+
+# Check event fields using global type declarations are present
+try:
+    babeltrace_process = subprocess.Popen(["babeltrace", session_info.trace_path], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
+except FileNotFoundError:
+    bail("Could not open babeltrace. Please make sure it is installed.")
+
+event_lines = []
+for event_line in babeltrace_process.stdout:
+    event_line = event_line.decode('utf-8').replace("\n", "")
+    event_lines.append(event_line)
+babeltrace_process.wait()
+
+print_test_result(babeltrace_process.returncode == 0, current_test, "Resulting trace is readable")
+current_test += 1
+
+if babeltrace_process.returncode != 0:
+    bail("Unreadable trace; can't proceed with analysis.")
+
+print_test_result(len(event_lines) == 4, current_test, "Correct number of events found in resulting trace")
+current_test += 1
+
+if len(event_lines) != 4:
+    bail("Unexpected number of events found in resulting trace (" + session_info.trace_path + ")." )
+
+match = re.search(r".*ust_tests_gtd:(.*):.*enumfield = \( (.*) :.*enumfield_bis = \( (.*) :.*", event_lines[0])
+print_test_result(match is not None and match.group(1) == "tptest", current_test,\
+                      "First tracepoint is present")
+current_test += 1
+
+print_test_result(match is not None and match.group(2) == "zero", current_test,\
+                      "First tracepoint's enum value maps to zero")
+current_test += 1
+
+print_test_result(match is not None and match.group(3) == "one", current_test,\
+                      "First tracepoint's second enum value maps to one")
+current_test += 1
+
+match = re.search(r".*ust_tests_gtd:(.*):.*enumfield = \( (.*) :.*", event_lines[1])
+print_test_result(match is not None and match.group(1) == "tptest_bis", current_test,\
+                      "Second tracepoint is present")
+current_test += 1
+
+print_test_result(match is not None and match.group(2) == "zero", current_test,\
+                      "Second tracepoint's enum value maps to zero")
+current_test += 1
+
+match = re.search(r".*ust_tests_gtd:(.*):.*enumfield = \( (.*) :.*enumfield_bis = \( (.*) .*", event_lines[2])
+
+print_test_result(match is not None and match.group(2) == "one", current_test,\
+                      "Third tracepoint's enum value maps to one")
+
+shutil.rmtree(session_info.tmp_directory)
diff --git a/tests/regression/ust/global-type-declarations/ust_tests_gtd.h b/tests/regression/ust/global-type-declarations/ust_tests_gtd.h
new file mode 100644
index 0000000..186ffe9
--- /dev/null
+++ b/tests/regression/ust/global-type-declarations/ust_tests_gtd.h
@@ -0,0 +1,67 @@
+#undef TRACEPOINT_PROVIDER
+#define TRACEPOINT_PROVIDER ust_tests_gtd
+
+#if !defined(_TRACEPOINT_UST_TESTS_GLOBAL_TYPE_DECLARATIONS_H) || defined(TRACEPOINT_HEADER_MULTI_READ)
+#define _TRACEPOINT_UST_TESTS_GLOBAL_TYPE_DECLARATIONS_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_gtd, testenum, int,
+	TP_ENUM_VALUES(
+		ctf_enum_value("zero", 0)
+		ctf_enum_value("one", 1)
+	)
+)
+
+/*
+ * Enumeration field is used twice to make sure the global type declaration
+ * is entered only once in the metadata file.
+ */
+TRACEPOINT_EVENT(ust_tests_gtd, tptest,
+	TP_ARGS(int, enumval, int, enumval2),
+	TP_FIELDS(
+		ctf_enum(ust_tests_gtd, testenum, enumfield, enumval)
+		ctf_enum(ust_tests_gtd, testenum, enumfield_bis, enumval2)
+	)
+)
+
+/*
+ * Another tracepoint using the global types to make sure each global type is
+ * entered only once in the metadata file.
+ */
+TRACEPOINT_EVENT(ust_tests_gtd, tptest_bis,
+	TP_ARGS(int, enumval),
+	TP_FIELDS(
+		ctf_enum(ust_tests_gtd, testenum, enumfield, enumval)
+	)
+)
+
+#endif /* _TRACEPOINT_UST_TESTS_GLOBAL_TYPE_DECLARATIONS_H */
+
+#undef TRACEPOINT_INCLUDE
+#define TRACEPOINT_INCLUDE "./ust_tests_gtd.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