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>
tests/regression/ust/linking/demo_static
tests/regression/ust/linking/demo
tests/regression/ust/daemon/daemon
+tests/regression/ust/exit-fast/exit-fast
benchmark/
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
regression/ust/test_event_wildcard
regression/ust/linking/test_linking
regression/ust/daemon/test_daemon
+regression/ust/exit-fast/test_exit-fast
regression/ust/test_event_wildcard
regression/ust/linking/test_linking
regression/ust/daemon/test_daemon
+regression/ust/exit-fast/test_exit-fast
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
--- /dev/null
+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
--- /dev/null
+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
--- /dev/null
+/* 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;
+}
--- /dev/null
+#!/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
--- /dev/null
+#!/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)
--- /dev/null
+/*
+ * 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 */