[lttng-dev] [PATCH lttng-tools 4/7] Tests: Add "exit-fast" ust regression test

Jérémie Galarneau jeremie.galarneau at efficios.com
Mon Mar 25 20:28:33 EDT 2013


Based on the "exit-fast" test formerly part of lttng-ust.

Signed-off-by: Jérémie Galarneau <jeremie.galarneau at efficios.com>
---
 .gitignore                                         |   1 +
 configure.ac                                       |   1 +
 tests/fast_regression                              |   1 +
 tests/long_regression                              |   1 +
 tests/regression/ust/Makefile.am                   |   2 +-
 tests/regression/ust/exit-fast/Makefile.am         |  15 +++
 tests/regression/ust/exit-fast/README              |  23 +++++
 tests/regression/ust/exit-fast/exit-fast.c         |  47 +++++++++
 tests/regression/ust/exit-fast/test_exit-fast      |  35 +++++++
 tests/regression/ust/exit-fast/test_exit-fast.py   | 111 +++++++++++++++++++++
 .../regression/ust/exit-fast/ust_tests_exitfast.h  |  52 ++++++++++
 11 files changed, 288 insertions(+), 1 deletion(-)
 create mode 100644 tests/regression/ust/exit-fast/Makefile.am
 create mode 100644 tests/regression/ust/exit-fast/README
 create mode 100644 tests/regression/ust/exit-fast/exit-fast.c
 create mode 100755 tests/regression/ust/exit-fast/test_exit-fast
 create mode 100644 tests/regression/ust/exit-fast/test_exit-fast.py
 create mode 100644 tests/regression/ust/exit-fast/ust_tests_exitfast.h

diff --git a/.gitignore b/.gitignore
index 5ea488e..4c186d2 100644
--- a/.gitignore
+++ b/.gitignore
@@ -68,5 +68,6 @@ tests/regression/ust/linking/demo_builtin
 tests/regression/ust/linking/demo_static
 tests/regression/ust/linking/demo
 tests/regression/ust/daemon/daemon
+tests/regression/ust/exit-fast/exit-fast
 
 benchmark/
diff --git a/configure.ac b/configure.ac
index 109e4fc..88d8a33 100644
--- a/configure.ac
+++ b/configure.ac
@@ -334,6 +334,7 @@ AC_CONFIG_FILES([
 	tests/regression/ust/overlap/demo/Makefile
 	tests/regression/ust/linking/Makefile
 	tests/regression/ust/daemon/Makefile
+	tests/regression/ust/exit-fast/Makefile
 	tests/unit/Makefile
 	tests/utils/Makefile
 	tests/utils/tap/Makefile
diff --git a/tests/fast_regression b/tests/fast_regression
index 394dbfd..e588661 100644
--- a/tests/fast_regression
+++ b/tests/fast_regression
@@ -14,3 +14,4 @@ regression/ust/test_event_basic
 regression/ust/test_event_wildcard
 regression/ust/linking/test_linking
 regression/ust/daemon/test_daemon
+regression/ust/exit-fast/test_exit-fast
diff --git a/tests/long_regression b/tests/long_regression
index 1187270..a81d094 100644
--- a/tests/long_regression
+++ b/tests/long_regression
@@ -16,3 +16,4 @@ regression/ust/test_event_basic
 regression/ust/test_event_wildcard
 regression/ust/linking/test_linking
 regression/ust/daemon/test_daemon
+regression/ust/exit-fast/test_exit-fast
diff --git a/tests/regression/ust/Makefile.am b/tests/regression/ust/Makefile.am
index 2dd6fe9..1631ba6 100644
--- a/tests/regression/ust/Makefile.am
+++ b/tests/regression/ust/Makefile.am
@@ -1,6 +1,6 @@
 if HAVE_LIBLTTNG_UST_CTL
 SUBDIRS = nprocesses high-throughput low-throughput before-after multi-session \
-		overlap buffers-uid linking daemon
+		overlap buffers-uid linking daemon exit-fast
 
 EXTRA_DIST = test_event_basic test_event_wildcard
 
diff --git a/tests/regression/ust/exit-fast/Makefile.am b/tests/regression/ust/exit-fast/Makefile.am
new file mode 100644
index 0000000..ff47cd9
--- /dev/null
+++ b/tests/regression/ust/exit-fast/Makefile.am
@@ -0,0 +1,15 @@
+AM_CPPFLAGS = -I$(srcdir)
+
+noinst_PROGRAMS = exit-fast
+exit_fast_SOURCES = exit-fast.c ust_tests_exitfast.h
+exit_fast_LDADD = -llttng-ust
+
+if LTTNG_TOOLS_BUILD_WITH_LIBDL
+exit_fast_LDADD += -ldl
+endif
+if LTTNG_TOOLS_BUILD_WITH_LIBC_DL
+exit_fast_LDADD += -lc
+endif
+
+noinst_SCRIPTS = test_exit-fast test_exit-fast.py
+EXTRA_DIST = test_exit-fast test_exit-fast.py
diff --git a/tests/regression/ust/exit-fast/README b/tests/regression/ust/exit-fast/README
new file mode 100644
index 0000000..87340dd
--- /dev/null
+++ b/tests/regression/ust/exit-fast/README
@@ -0,0 +1,23 @@
+exit-fast tracing test
+-------------------
+
+This test verifies that tracing works correctly when the traced process exits
+right after an event is logged.
+
+DESCRIPTION
+-----------
+
+This test launches a process that logs an event and returns directly after.
+It then launches it again in a mode that will trigger a SIGKILL right after
+the tracepoint is executed. The resulting trace is then checked for errors.
+
+The events must be present in the trace and contain the appropriate test string.
+
+DEPENDENCIES
+------------
+
+To run this test, you will need:
+
+  - lttng-tools (with python bindings)
+  - babeltrace
+  - python 3.0 or better
diff --git a/tests/regression/ust/exit-fast/exit-fast.c b/tests/regression/ust/exit-fast/exit-fast.c
new file mode 100644
index 0000000..8642656
--- /dev/null
+++ b/tests/regression/ust/exit-fast/exit-fast.c
@@ -0,0 +1,47 @@
+/* Copyright (C) 2011 Nils Carlson
+ *
+ * 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 <signal.h>
+#include <string.h>
+#include <sys/types.h>
+#include <unistd.h>
+
+#define TRACEPOINT_DEFINE
+#define TRACEPOINT_CREATE_PROBES
+#include "ust_tests_exitfast.h"
+
+int main(int argc, char *argv[])
+{
+	int suicide = 0;
+	char normal_exit_text[] = "exit-fast tracepoint normal exit";
+	char suicide_exit_text[] = "exit-fast tracepoint suicide";
+
+	if (argc > 1 && !strcmp(argv[1], "suicide")) {
+		suicide = 1;
+	}
+
+	if (suicide) {
+		tracepoint(ust_tests_exitfast, message, suicide_exit_text);
+		kill(getpid(), SIGKILL);
+	}
+
+	tracepoint(ust_tests_exitfast, message, normal_exit_text);
+	return 0;
+}
diff --git a/tests/regression/ust/exit-fast/test_exit-fast b/tests/regression/ust/exit-fast/test_exit-fast
new file mode 100755
index 0000000..e8a0bd6
--- /dev/null
+++ b/tests/regression/ust/exit-fast/test_exit-fast
@@ -0,0 +1,35 @@
+#!/bin/sh
+#
+# Copyright (C) - 2013 Jérémie Galarneau <jeremie.galarneau at efficios.com>
+#
+# 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.
+
+# 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_exit-fast.py
+
+if [ $STOP_SESSIOND -ne 0 ]; then
+    kill `pidof lt-lttng-sessiond`
+fi
diff --git a/tests/regression/ust/exit-fast/test_exit-fast.py b/tests/regression/ust/exit-fast/test_exit-fast.py
new file mode 100644
index 0000000..71ae7d3
--- /dev/null
+++ b/tests/regression/ust/exit-fast/test_exit-fast.py
@@ -0,0 +1,111 @@
+#!/usr/bin/env python3
+#
+# Copyright (C) - 2013 Jérémie Galarneau <jeremie.galarneau at efficios.com>
+#
+# 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 *
+
+
+normal_exit_message = "exit-fast tracepoint normal exit"
+suicide_exit_message = "exit-fast tracepoint suicide"
+NR_TESTS = 5
+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_exitfast*")
+start_session(session_info)
+
+test_env = os.environ.copy()
+test_env["LTTNG_UST_REGISTER_TIMEOUT"] = "-1"
+
+exit_fast_process = subprocess.Popen(test_path + "exit-fast", stdout=subprocess.PIPE, stderr=subprocess.PIPE, env=test_env)
+
+if sys.version_info >= (3, 3):
+    try:
+        exit_fast_process.wait(5)
+    except TimeoutExpired:
+        exit_fast_process.kill()
+        bail("Failed to run exit-fast test application.")
+else:
+    exit_fast_process.wait()
+
+print_test_result(exit_fast_process.returncode == 0, current_test, "Test application exited normally")
+current_test += 1
+
+exit_fast_process = subprocess.Popen([test_path + "exit-fast", "suicide"], stdout=subprocess.PIPE, stderr=subprocess.PIPE, env=test_env)
+
+if sys.version_info >= (3, 3):
+    try:
+        exit_fast_process.wait(5)
+    except TimeoutExpired:
+        exit_fast_process.kill()
+        bail("Failed to run exit-fast test application in suicide mode.")
+else:
+    exit_fast_process.wait()
+
+stop_session(session_info)
+
+# Check both events (normal exit and suicide messages) are present in the resulting trace
+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) == 2, current_test, "Correct number of events found in resulting trace")
+current_test += 1
+
+if len(event_lines) != 2:
+    bail("Unexpected number of events found in resulting trace (" + session_info.trace_path + ")." )
+
+match = re.search(r".*message = \"(.*)\"", event_lines[0])
+print_test_result(match is not None and match.group(1) == normal_exit_message, current_test,\
+                      "Tracepoint message generated during normal exit run is present in trace and has the expected value")
+current_test += 1
+
+match = re.search(r".*message = \"(.*)\"", event_lines[1])
+print_test_result(match is not None and match.group(1) == suicide_exit_message, current_test,\
+                      "Tracepoint message generated during suicide run is present in trace and has the expected value")
+current_test += 1
+
+shutil.rmtree(session_info.tmp_directory)
diff --git a/tests/regression/ust/exit-fast/ust_tests_exitfast.h b/tests/regression/ust/exit-fast/ust_tests_exitfast.h
new file mode 100644
index 0000000..71d81f7
--- /dev/null
+++ b/tests/regression/ust/exit-fast/ust_tests_exitfast.h
@@ -0,0 +1,52 @@
+/*
+ * Copyright (C) 2011-2012  Mathieu Desnoyers <mathieu.desnoyers at efficios.com>
+ * Copyright (C) 2011-2012  Matthew Khouzam <matthew.khouzam at ericsson.com>
+ *
+ * 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.
+ */
+
+#undef TRACEPOINT_PROVIDER
+#define TRACEPOINT_PROVIDER ust_tests_exitfast
+
+#ifdef __cplusplus
+extern "C" {
+#endif /* __cplusplus */
+
+#if !defined(_TRACEPOINT_UST_TESTS_EXITFAST_H) || defined(TRACEPOINT_HEADER_MULTI_READ)
+#define _TRACEPOINT_UST_TESTS_EXITFAST_H
+
+#include <lttng/tracepoint.h>
+
+TRACEPOINT_EVENT(ust_tests_exitfast, message,
+		TP_ARGS(char *, text),
+		TP_FIELDS(ctf_string(message, text))
+)
+
+TRACEPOINT_LOGLEVEL(ust_tests_exitfast, message, TRACE_INFO)
+
+#endif /* _TRACEPOINT_UST_TESTS_EXITFAST_H */
+
+#undef TRACEPOINT_INCLUDE
+#define TRACEPOINT_INCLUDE "./ust_tests_exitfast.h"
+
+#include <lttng/tracepoint-event.h>
+
+#ifdef __cplusplus
+}
+#endif /* __cplusplus */
-- 
1.8.2




More information about the lttng-dev mailing list