Tests: Add "exit-fast" ust regression test
authorJérémie Galarneau <jeremie.galarneau@efficios.com>
Tue, 26 Mar 2013 00:28:33 +0000 (20:28 -0400)
committerDavid Goulet <dgoulet@efficios.com>
Wed, 27 Mar 2013 14:33:46 +0000 (10:33 -0400)
Based on the "exit-fast" test formerly part of lttng-ust.

Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
Signed-off-by: David Goulet <dgoulet@efficios.com>
.gitignore
configure.ac
tests/fast_regression
tests/long_regression
tests/regression/ust/Makefile.am
tests/regression/ust/exit-fast/Makefile.am [new file with mode: 0644]
tests/regression/ust/exit-fast/README [new file with mode: 0644]
tests/regression/ust/exit-fast/exit-fast.c [new file with mode: 0644]
tests/regression/ust/exit-fast/test_exit-fast [new file with mode: 0755]
tests/regression/ust/exit-fast/test_exit-fast.py [new file with mode: 0644]
tests/regression/ust/exit-fast/ust_tests_exitfast.h [new file with mode: 0644]

index 5ea488e26c2c4f07c1ad6824dce1a9482efed7ee..4c186d2e42c768e8d9322f43af800a03807ca9b7 100644 (file)
@@ -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/
index 109e4fcb5c8dfd8fb58c9aaa814a051c2ffb5ba9..88d8a33afe1ef859f0ec34e69f40d45ed98a1387 100644 (file)
@@ -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
index 394dbfdd2900e405f4f003238a5d1db4972176b1..e5886615bc3a124ffedbe366101da9d3d67f253d 100644 (file)
@@ -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
index 11872706cb87f8fc3dba297296a46a6ac0c01239..a81d094cd9d75098d9d1f56bddcac6fbc850f0be 100644 (file)
@@ -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
index 2dd6fe9b4fd0b01d3b0f0c932533cdaa17fbf720..1631ba66c94e2092fc8dc568156c76db8c692ece 100644 (file)
@@ -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 (file)
index 0000000..ff47cd9
--- /dev/null
@@ -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 (file)
index 0000000..87340dd
--- /dev/null
@@ -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 (file)
index 0000000..8642656
--- /dev/null
@@ -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 (executable)
index 0000000..e8a0bd6
--- /dev/null
@@ -0,0 +1,35 @@
+#!/bin/sh
+#
+# Copyright (C) - 2013 Jérémie Galarneau <jeremie.galarneau@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 (file)
index 0000000..71ae7d3
--- /dev/null
@@ -0,0 +1,111 @@
+#!/usr/bin/env python3
+#
+# Copyright (C) - 2013 Jérémie Galarneau <jeremie.galarneau@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 (file)
index 0000000..71d81f7
--- /dev/null
@@ -0,0 +1,52 @@
+/*
+ * Copyright (C) 2011-2012  Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
+ * Copyright (C) 2011-2012  Matthew Khouzam <matthew.khouzam@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 */
This page took 0.044379 seconds and 4 git commands to generate.