All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH lttng-tools 2/7] Tests: Add "linking" ust regression test
       [not found] <1364257716-5739-1-git-send-email-jeremie.galarneau@efficios.com>
@ 2013-03-26  0:28 ` Jérémie Galarneau
  2013-03-26  0:28 ` [PATCH lttng-tools 3/7] Tests: Add "daemon" " Jérémie Galarneau
                   ` (5 subsequent siblings)
  6 siblings, 0 replies; 7+ messages in thread
From: Jérémie Galarneau @ 2013-03-26  0:28 UTC (permalink / raw)
  To: lttng-dev

Based on the "demo" test formerly part of lttng-ust.
Tests userspace tracing with directly, statically and dynamically linked
providers. Also meant as an exemple of building and tracing an application
with all types of provider linking.

Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
---
 .gitignore                                     |   3 +
 configure.ac                                   |   1 +
 tests/fast_regression                          |   1 +
 tests/long_regression                          |   1 +
 tests/regression/ust/Makefile.am               |   2 +-
 tests/regression/ust/linking/Makefile.am       |  85 +++++++++++
 tests/regression/ust/linking/README            |  29 ++++
 tests/regression/ust/linking/demo.c            |  69 +++++++++
 tests/regression/ust/linking/demo_preload      |   4 +
 tests/regression/ust/linking/test_linking      |  35 +++++
 tests/regression/ust/linking/test_linking.py   | 199 +++++++++++++++++++++++++
 tests/regression/ust/linking/tp.c              |  26 ++++
 tests/regression/ust/linking/tp2.c             |  26 ++++
 tests/regression/ust/linking/tp3.c             |  26 ++++
 tests/regression/ust/linking/ust_tests_demo.h  |  61 ++++++++
 tests/regression/ust/linking/ust_tests_demo2.h |  68 +++++++++
 tests/regression/ust/linking/ust_tests_demo3.h |  53 +++++++
 17 files changed, 688 insertions(+), 1 deletion(-)
 create mode 100644 tests/regression/ust/linking/Makefile.am
 create mode 100644 tests/regression/ust/linking/README
 create mode 100644 tests/regression/ust/linking/demo.c
 create mode 100755 tests/regression/ust/linking/demo_preload
 create mode 100755 tests/regression/ust/linking/test_linking
 create mode 100644 tests/regression/ust/linking/test_linking.py
 create mode 100644 tests/regression/ust/linking/tp.c
 create mode 100644 tests/regression/ust/linking/tp2.c
 create mode 100644 tests/regression/ust/linking/tp3.c
 create mode 100644 tests/regression/ust/linking/ust_tests_demo.h
 create mode 100644 tests/regression/ust/linking/ust_tests_demo2.h
 create mode 100644 tests/regression/ust/linking/ust_tests_demo3.h

diff --git a/.gitignore b/.gitignore
index ee58252..b9c3ec8 100644
--- a/.gitignore
+++ b/.gitignore
@@ -64,5 +64,8 @@ gen-events
 gen-ust-events
 health_check
 tests/regression/ust/overlap/demo/demo
+tests/regression/ust/linking/demo_builtin
+tests/regression/ust/linking/demo_static
+tests/regression/ust/linking/demo
 
 benchmark/
diff --git a/configure.ac b/configure.ac
index 9f120f2..5494cd8 100644
--- a/configure.ac
+++ b/configure.ac
@@ -332,6 +332,7 @@ AC_CONFIG_FILES([
 	tests/regression/ust/multi-session/Makefile
 	tests/regression/ust/overlap/Makefile
 	tests/regression/ust/overlap/demo/Makefile
+	tests/regression/ust/linking/Makefile
 	tests/unit/Makefile
 	tests/utils/Makefile
 	tests/utils/tap/Makefile
diff --git a/tests/fast_regression b/tests/fast_regression
index fb4ac60..b700fa5 100644
--- a/tests/fast_regression
+++ b/tests/fast_regression
@@ -12,3 +12,4 @@ regression/ust/nprocesses/test_nprocesses
 regression/ust/overlap/test_overlap
 regression/ust/test_event_basic
 regression/ust/test_event_wildcard
+regression/ust/linking/test_linking
diff --git a/tests/long_regression b/tests/long_regression
index c198178..1fb68c3 100644
--- a/tests/long_regression
+++ b/tests/long_regression
@@ -14,3 +14,4 @@ regression/ust/nprocesses/test_nprocesses
 regression/ust/overlap/test_overlap
 regression/ust/test_event_basic
 regression/ust/test_event_wildcard
+regression/ust/linking/test_linking
diff --git a/tests/regression/ust/Makefile.am b/tests/regression/ust/Makefile.am
index 78a5aab..74db00b 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
+		overlap buffers-uid linking
 
 EXTRA_DIST = test_event_basic test_event_wildcard
 
diff --git a/tests/regression/ust/linking/Makefile.am b/tests/regression/ust/linking/Makefile.am
new file mode 100644
index 0000000..d2c4eca
--- /dev/null
+++ b/tests/regression/ust/linking/Makefile.am
@@ -0,0 +1,85 @@
+# -Wsystem-headers is needed to print warnings in the tracepoint
+# description file.
+AM_CPPFLAGS = -I$(srcdir) -I$(top_builddir)/include -Wsystem-headers
+
+# Set LIBS to nothing so the application does not link on useless
+# libraries.
+LIBS =
+
+# Build a version of the test app with built-in tracepoints
+demo_builtin_SOURCES = demo.c tp.c tp2.c tp3.c ust_tests_demo.h \
+	ust_tests_demo2.h ust_tests_demo3.h
+demo_builtin_LDADD = -llttng-ust
+demo_builtin_CFLAGS = -Werror=old-style-definition
+
+# Build a version statically linked to the providers
+# contains ust_tests_demo.h and ust_tests_demo2.h provider probes
+noinst_LTLIBRARIES = liblttng-ust-provider-ust-tests-demo-static.la \
+	liblttng-ust-provider-ust-tests-demo3-static.la
+
+liblttng_ust_provider_ust_tests_demo_static_la_SOURCES = \
+	tp.c ust_tests_demo.h \
+	tp2.c ust_tests_demo2.h
+liblttng_ust_provider_ust_tests_demo_static_la_LIBADD = \
+	-llttng-ust
+
+# contains ust_tests_demo3.h provider probes
+liblttng_ust_provider_ust_tests_demo3_static_la_SOURCES = \
+	tp3.c ust_tests_demo3.h
+liblttng_ust_provider_ust_tests_demo3_static_la_LIBADD = \
+	-llttng-ust
+
+demo_static_SOURCES = demo.c
+demo_static_LDADD = liblttng-ust-provider-ust-tests-demo-static.la \
+	liblttng-ust-provider-ust-tests-demo3-static.la
+
+if LTTNG_TOOLS_BUILD_WITH_LIBDL
+demo_builtin_LDADD += -ldl
+demo_static_LDADD += -ldl
+endif
+if LTTNG_TOOLS_BUILD_WITH_LIBC_DL
+demo_builtin_LDADD += -lc
+demo_static_LDADD += -lc
+endif
+
+noinst_PROGRAMS = demo_builtin demo_static
+
+if !NO_SHARED
+# Force the shared flag on the noinst libraries since they are
+# only built static by default
+FORCE_SHARED_LIB_OPTIONS = -module -shared -avoid-version \
+			   -rpath $(abs_builddir)
+
+noinst_LTLIBRARIES += liblttng-ust-provider-ust-tests-demo.la \
+	liblttng-ust-provider-ust-tests-demo3.la
+
+#contains ust_tests_demo.h and ust_tests_demo2.h provider probes
+liblttng_ust_provider_ust_tests_demo_la_SOURCES = \
+	tp.c ust_tests_demo.h \
+	tp2.c ust_tests_demo2.h
+liblttng_ust_provider_ust_tests_demo_la_LIBADD = -llttng-ust
+liblttng_ust_provider_ust_tests_demo_la_LDFLAGS = \
+	$(FORCE_SHARED_LIB_OPTIONS)
+
+#contains ust_tests_demo3.h provider probes
+liblttng_ust_provider_ust_tests_demo3_la_SOURCES = \
+	tp3.c ust_tests_demo3.h
+liblttng_ust_provider_ust_tests_demo3_la_LIBADD = -llttng-ust
+liblttng_ust_provider_ust_tests_demo3_la_LDFLAGS = \
+	$(FORCE_SHARED_LIB_OPTIONS)
+
+noinst_PROGRAMS += demo
+demo_SOURCES = demo.c ust_tests_demo.h
+demo_CFLAGS = -DTEST_DYNAMIC_LINKAGE
+
+if LTTNG_TOOLS_BUILD_WITH_LIBDL
+demo_LDADD = -ldl
+endif
+if LTTNG_TOOLS_BUILD_WITH_LIBC_DL
+demo_LDADD = -lc
+endif
+
+endif
+
+noinst_SCRIPTS = test_linking test_linking.py demo_preload
+EXTRA_DIST = test_linking test_linking.py demo_preload
diff --git a/tests/regression/ust/linking/README b/tests/regression/ust/linking/README
new file mode 100644
index 0000000..bbf3a4d
--- /dev/null
+++ b/tests/regression/ust/linking/README
@@ -0,0 +1,29 @@
+UST linking test
+----------------
+
+Tests userspace tracing with directly, statically and dynamically linked
+providers.
+
+DESCRIPTION
+-----------
+
+This test checks that tracepoints can be enabled by using LD_PRELOAD inside a
+launcher script. The test application is also compiled with tracepoint
+providers linked directly and statically. The same test suite is executed
+for every version of the binary.
+
+The resulting trace is verified to make sure it is valid and contains the
+expected valuess. This test also verifies that the execution of the demo test
+without LD_PRELOAD has not produced any logged events.
+
+Also serves as an example of building and tracing an application with all types
+of provider linking.
+
+DEPENDENCIES
+------------
+
+To run this test, you will need:
+
+  - lttng-tools
+  - babeltrace
+  - python 3.0 or better
diff --git a/tests/regression/ust/linking/demo.c b/tests/regression/ust/linking/demo.c
new file mode 100644
index 0000000..a02ee80
--- /dev/null
+++ b/tests/regression/ust/linking/demo.c
@@ -0,0 +1,69 @@
+/*
+ * Copyright (C) 2009  Pierre-Marc Fournier
+ * Copyright (C) 2011  Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
+ *
+ * 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 <stdio.h>
+#include <unistd.h>
+#include <sys/mman.h>
+#include <stdarg.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <signal.h>
+#include <string.h>
+#include <arpa/inet.h>
+#include <stdlib.h>
+
+#define TRACEPOINT_DEFINE
+
+#if TEST_DYNAMIC_LINKAGE
+#define TRACEPOINT_PROBE_DYNAMIC_LINKAGE
+#endif
+
+#include "ust_tests_demo.h"
+#include "ust_tests_demo2.h"
+#include "ust_tests_demo3.h"
+
+int main(int argc, char **argv)
+{
+	int i, netint;
+	long values[] = { 1, 2, 3 };
+	char text[10] = "test";
+	double dbl = 2.0;
+	float flt = 2222.0;
+	int delay = 0;
+
+	if (argc == 2)
+		delay = atoi(argv[1]);
+
+	fprintf(stderr, "Demo program starting.\n");
+
+	sleep(delay);
+
+	fprintf(stderr, "Tracing... ");
+	tracepoint(ust_tests_demo, starting, 123);
+	for (i = 0; i < 5; i++) {
+		netint = htonl(i);
+		tracepoint(ust_tests_demo2, loop, i, netint, values,
+			   text, strlen(text), dbl, flt);
+	}
+	tracepoint(ust_tests_demo, done, 456);
+	tracepoint(ust_tests_demo3, done, 42);
+	fprintf(stderr, " done.\n");
+	return 0;
+}
diff --git a/tests/regression/ust/linking/demo_preload b/tests/regression/ust/linking/demo_preload
new file mode 100755
index 0000000..1f68a68
--- /dev/null
+++ b/tests/regression/ust/linking/demo_preload
@@ -0,0 +1,4 @@
+#!/bin/sh
+
+CURDIR=$(dirname $0)
+LD_PRELOAD=${CURDIR}/.libs/liblttng-ust-provider-ust-tests-demo.so:${CURDIR}/.libs/liblttng-ust-provider-ust-tests-demo3.so ${CURDIR}/./demo ${*}
diff --git a/tests/regression/ust/linking/test_linking b/tests/regression/ust/linking/test_linking
new file mode 100755
index 0000000..77e0b82
--- /dev/null
+++ b/tests/regression/ust/linking/test_linking
@@ -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_linking.py
+
+if [ $STOP_SESSIOND -ne 0 ]; then
+    kill `pidof lt-lttng-sessiond`
+fi
diff --git a/tests/regression/ust/linking/test_linking.py b/tests/regression/ust/linking/test_linking.py
new file mode 100644
index 0000000..9591312
--- /dev/null
+++ b/tests/regression/ust/linking/test_linking.py
@@ -0,0 +1,199 @@
+#!/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 *
+
+
+def check_ust_test_demo2_event(event_line, expected_int_field_value):
+    match = re.search(r".*ust_tests_demo2:loop.*", event_line)
+    if match is None:
+        return False
+    match = re.search(r".*intfield = (\d+)", event_line)
+    if match is None or int(match.group(1)) != expected_int_field_value:
+        return False
+    match = re.search(r".*longfield = (\d+)", event_line)
+    if match is None or int(match.group(1)) != expected_int_field_value:
+        return False
+    match = re.search(r".*netintfield = (\d+)", event_line)
+    if match is None or int(match.group(1)) != expected_int_field_value:
+        return False
+    match = re.search(r".*intfield2 = 0x(\d+)", event_line)
+    if match is None or int(match.group(1)) != expected_int_field_value:
+        return False
+    match = re.search(r".*netintfieldhex = 0x(\d+)", event_line)
+    if match is None or int(match.group(1)) != expected_int_field_value:
+        return False
+    match = re.search(r".*floatfield = (\d+)", event_line)
+    if match is None or int(match.group(1)) != 2222:
+        return False
+    match = re.search(r".*doublefield = (\d+)", event_line)
+    if match is None or int(match.group(1)) != 2:
+        return False
+    match = re.search(r".*_seqfield1_length = (\d+)", event_line)
+    if match is None or int(match.group(1)) != 4:
+        return False
+    match = re.search(r".*seqfield1 = \[ \[0\] = (\d+), \[1\] = (\d+), \[2\] = (\d+), \[3\] = (\d+) \]", event_line)
+    if match is None or int(match.group(1)) != 116 or int(match.group(2)) != 101 or int(match.group(3)) != 115 or int(match.group(4)) != 116:
+        return False
+    match = re.search(r".*arrfield1 = \[ \[0\] = (\d), \[1\] = (\d), \[2\] = (\d) \]", event_line)
+    if match is None or int(match.group(1)) != 1 or int(match.group(2)) != 2 or int(match.group(3)) != 3:
+        return False
+    match = re.search(r".*arrfield2 = \"([a-z]*)\"", event_line)
+    if match is None or match.group(1) != "test":
+        return False
+    match = re.search(r".*_seqfield2_length = (\d+)", event_line)
+    if match is None or int(match.group(1)) != 4:
+        return False
+    match = re.search(r".*seqfield2 = \"([a-z]*)\"", event_line)
+    if match is None or match.group(1) != "test":
+        return False
+    match = re.search(r".*stringfield = \"([a-z]*)\"", event_line)
+    if match is None or match.group(1) != "test":
+        return False
+
+    return True
+
+NR_TESTS = 0
+DYNAMIC_TEST_ENABLED = False
+
+test_executables = [test_path + "demo_static", test_path + "demo_builtin"]
+if os.path.exists(test_path + "demo"):
+    test_executables.append(test_path + "demo_preload")
+    NR_TESTS = 2
+    DYNAMIC_TEST_ENABLED = True
+
+# Only enable tests that were compiled successfully
+test_executables = [executable for executable in test_executables if os.path.exists(executable)]
+
+NR_TESTS += len(test_executables) * 10
+
+current_test = 1
+print("1..{0}".format(NR_TESTS))
+
+if NR_TESTS == 0:
+    print("# No test binary found")
+    exit(-1)
+
+# 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.")
+
+if DYNAMIC_TEST_ENABLED:
+    session_info = create_session()
+    enable_ust_tracepoint_event(session_info, "ust_tests_demo*")
+    start_session(session_info)
+
+    # Dry run, no events should be logged
+    demo_process = subprocess.Popen(test_path + "demo", stdout=subprocess.PIPE, stderr=subprocess.PIPE)
+    if sys.version_info >= (3 ,3):
+        try:
+            demo_process.wait(5)
+        except TimeoutExpired:
+            demo_process.kill()
+            bail("Failed to run demo test application without preloading")
+    else:
+        demo_process.wait()
+    stop_session(session_info)
+
+    print_test_result(demo_process.returncode == 0, current_test,\
+                          "Running application dynamically linked to providers, no preload")
+    current_test += 1
+    print_test_result(not os.path.exists(session_info.trace_path), current_test,\
+                          "No events logged when running demo application without preloading providers")
+    current_test += 1
+
+    shutil.rmtree(session_info.tmp_directory)
+
+for executable in test_executables:
+    executable_name = os.path.basename(executable)
+    session_info = create_session()
+    enable_ust_tracepoint_event(session_info, "ust_tests_demo*")
+    start_session(session_info)
+
+    demo_process = subprocess.Popen(executable, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
+    if sys.version_info >= (3, 3):
+        try:
+            demo_process.wait(5)
+        except TimeoutExpired:
+            demo_process.kill()
+            bail("Failed to run {0} test application".format(executable_name))
+    else:
+        demo_process.wait()
+    stop_session(session_info)
+
+    trace_found = os.path.exists(session_info.trace_path)
+    print_test_result(trace_found, current_test,\
+                          "{0}, resulting trace found".format(executable_name))
+    current_test += 1
+
+    if not trace_found:
+        print("# Skipping " + executable_name + " trace verification tests")
+        continue
+
+    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.")
+
+    # We should find 8 events in the resulting trace
+    event_entries = []
+    for event_line in babeltrace_process.stdout:
+        event_line = event_line.decode('utf-8').replace("\n", "")
+        event_entries.append(event_line)
+
+    if len(event_entries) != 8:
+        bail("{0}, wrong number of events found in resulting trace.".format(executable_name))
+
+    shutil.rmtree(session_info.tmp_directory)
+
+    print_test_result(len(event_entries) == 8, current_test,\
+                          "{0}, total number of events logged is correct".format(executable_name))
+    current_test += 1
+
+    # Check each loop event
+    match = re.search(r".*ust_tests_demo:starting.*value = (\d+) ", event_entries[0])
+    print_test_result(match is not None and (int(match.group(1)) == 123), current_test,\
+                          "{0}, ust_tests_demo:starting event found in trace with a correct integer argument".format(executable_name))
+    current_test += 1
+
+    for i in range(5):
+        print_test_result(check_ust_test_demo2_event(event_entries[i+1], i), current_test,\
+                              "{0}, ust_tests_demo2:loop event found in trace and arguments are correct, iteration ".format(executable_name)\
+                              + str(i + 1))
+        current_test += 1
+
+    match = re.search(r".*ust_tests_demo:done.*value = (\d+)", event_entries[6])
+    print_test_result(match is not None and (int(match.group(1)) == 456), current_test,\
+                          "{0}, ust_tests_demo:done event found in resulting trace with a correct integer argument".format(executable_name))
+    current_test += 1
+
+    match = re.search(r".*ust_tests_demo3:done.*value = (\d+)", event_entries[7])
+    print_test_result(match is not None and (int(match.group(1)) == 42), current_test,\
+                          "{0}, ust_tests_demo3:done event found in resulting trace with a correct integer argument".format(executable_name))
+    current_test += 1
diff --git a/tests/regression/ust/linking/tp.c b/tests/regression/ust/linking/tp.c
new file mode 100644
index 0000000..8e44db4
--- /dev/null
+++ b/tests/regression/ust/linking/tp.c
@@ -0,0 +1,26 @@
+/*
+ * tp.c
+ *
+ * Copyright (c) 2011 Mathieu Desnoyers <mathieu.desnoyers@efficios.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.
+ */
+
+#define TRACEPOINT_CREATE_PROBES
+#include "ust_tests_demo.h"
diff --git a/tests/regression/ust/linking/tp2.c b/tests/regression/ust/linking/tp2.c
new file mode 100644
index 0000000..ba45c23
--- /dev/null
+++ b/tests/regression/ust/linking/tp2.c
@@ -0,0 +1,26 @@
+/*
+ * tp2.c
+ *
+ * Copyright (c) 2011 Mathieu Desnoyers <mathieu.desnoyers@efficios.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.
+ */
+
+#define TRACEPOINT_CREATE_PROBES
+#include "ust_tests_demo2.h"
diff --git a/tests/regression/ust/linking/tp3.c b/tests/regression/ust/linking/tp3.c
new file mode 100644
index 0000000..5f97651
--- /dev/null
+++ b/tests/regression/ust/linking/tp3.c
@@ -0,0 +1,26 @@
+/*
+ * tp3.c
+ *
+ * Copyright (c) 2011 Mathieu Desnoyers <mathieu.desnoyers@efficios.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.
+ */
+
+#define TRACEPOINT_CREATE_PROBES
+#include "ust_tests_demo3.h"
diff --git a/tests/regression/ust/linking/ust_tests_demo.h b/tests/regression/ust/linking/ust_tests_demo.h
new file mode 100644
index 0000000..d2492b8
--- /dev/null
+++ b/tests/regression/ust/linking/ust_tests_demo.h
@@ -0,0 +1,61 @@
+#undef TRACEPOINT_PROVIDER
+#define TRACEPOINT_PROVIDER ust_tests_demo
+
+#if !defined(_TRACEPOINT_UST_TESTS_DEMO_H) || defined(TRACEPOINT_HEADER_MULTI_READ)
+#define _TRACEPOINT_UST_TESTS_DEMO_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/*
+ * Copyright (C) 2011  Mathieu Desnoyers <mathieu.desnoyers@efficios.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.
+ */
+
+#include <lttng/tracepoint.h>
+
+TRACEPOINT_EVENT(ust_tests_demo, starting,
+	TP_ARGS(int, value),
+	TP_FIELDS(
+		ctf_integer(int, value, value)
+	)
+)
+TRACEPOINT_LOGLEVEL(ust_tests_demo, starting, TRACE_CRIT)
+
+TRACEPOINT_EVENT(ust_tests_demo, done,
+	TP_ARGS(int, value),
+	TP_FIELDS(
+		ctf_integer(int, value, value)
+	)
+)
+TRACEPOINT_LOGLEVEL(ust_tests_demo, done, TRACE_CRIT)
+
+#endif /* _TRACEPOINT_UST_TESTS_DEMO_H */
+
+#undef TRACEPOINT_INCLUDE
+#define TRACEPOINT_INCLUDE "./ust_tests_demo.h"
+
+/* This part must be outside ifdef protection */
+#include <lttng/tracepoint-event.h>
+
+#ifdef __cplusplus
+}
+#endif
diff --git a/tests/regression/ust/linking/ust_tests_demo2.h b/tests/regression/ust/linking/ust_tests_demo2.h
new file mode 100644
index 0000000..25d42ad
--- /dev/null
+++ b/tests/regression/ust/linking/ust_tests_demo2.h
@@ -0,0 +1,68 @@
+#undef TRACEPOINT_PROVIDER
+#define TRACEPOINT_PROVIDER ust_tests_demo2
+
+#if !defined(_TRACEPOINT_UST_TESTS_DEMO2_H) || defined(TRACEPOINT_HEADER_MULTI_READ)
+#define _TRACEPOINT_UST_TESTS_DEMO2_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/*
+ * Copyright (C) 2011  Mathieu Desnoyers <mathieu.desnoyers@efficios.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.
+ */
+
+#include <lttng/tracepoint.h>
+
+TRACEPOINT_EVENT(ust_tests_demo2, loop,
+	TP_ARGS(int, anint, int, netint, long *, values,
+		 char *, text, size_t, textlen,
+		 double, doublearg, float, floatarg),
+	TP_FIELDS(
+		ctf_integer(int, intfield, anint)
+		ctf_integer_hex(int, intfield2, anint)
+		ctf_integer(long, longfield, anint)
+		ctf_integer_network(int, netintfield, netint)
+		ctf_integer_network_hex(int, netintfieldhex, netint)
+		ctf_array(long, arrfield1, values, 3)
+		ctf_array_text(char, arrfield2, text, 10)
+		ctf_sequence(char, seqfield1, text,
+			     size_t, textlen)
+		ctf_sequence_text(char, seqfield2, text,
+			     size_t, textlen)
+		ctf_string(stringfield, text)
+		ctf_float(float, floatfield, floatarg)
+		ctf_float(double, doublefield, doublearg)
+	)
+)
+TRACEPOINT_LOGLEVEL(ust_tests_demo2, loop, TRACE_WARNING)
+
+#endif /* _TRACEPOINT_UST_TESTS_DEMO2_H */
+
+#undef TRACEPOINT_INCLUDE
+#define TRACEPOINT_INCLUDE "./ust_tests_demo2.h"
+
+/* This part must be outside ifdef protection */
+#include <lttng/tracepoint-event.h>
+
+#ifdef __cplusplus
+}
+#endif
diff --git a/tests/regression/ust/linking/ust_tests_demo3.h b/tests/regression/ust/linking/ust_tests_demo3.h
new file mode 100644
index 0000000..c7b63dd
--- /dev/null
+++ b/tests/regression/ust/linking/ust_tests_demo3.h
@@ -0,0 +1,53 @@
+#undef TRACEPOINT_PROVIDER
+#define TRACEPOINT_PROVIDER ust_tests_demo3
+
+#if !defined(_TRACEPOINT_UST_TESTS_DEMO3_H) || defined(TRACEPOINT_HEADER_MULTI_READ)
+#define _TRACEPOINT_UST_TESTS_DEMO3_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/*
+ * Copyright (C) 2011  Mathieu Desnoyers <mathieu.desnoyers@efficios.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.
+ */
+
+#include <lttng/tracepoint.h>
+
+TRACEPOINT_EVENT(ust_tests_demo3, done,
+	TP_ARGS(int, value),
+	TP_FIELDS(
+		ctf_integer(int, value, value)
+	)
+)
+TRACEPOINT_LOGLEVEL(ust_tests_demo3, done, TRACE_WARNING)
+
+#endif /* _TRACEPOINT_UST_TESTS_DEMO3_H */
+
+#undef TRACEPOINT_INCLUDE
+#define TRACEPOINT_INCLUDE "./ust_tests_demo3.h"
+
+/* This part must be outside ifdef protection */
+#include <lttng/tracepoint-event.h>
+
+#ifdef __cplusplus
+}
+#endif
-- 
1.8.2


_______________________________________________
lttng-dev mailing list
lttng-dev@lists.lttng.org
http://lists.lttng.org/cgi-bin/mailman/listinfo/lttng-dev

^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH lttng-tools 3/7] Tests: Add "daemon" ust regression test
       [not found] <1364257716-5739-1-git-send-email-jeremie.galarneau@efficios.com>
  2013-03-26  0:28 ` [PATCH lttng-tools 2/7] Tests: Add "linking" ust regression test Jérémie Galarneau
@ 2013-03-26  0:28 ` Jérémie Galarneau
  2013-03-26  0:28 ` [PATCH lttng-tools 4/7] Tests: Add "exit-fast" " Jérémie Galarneau
                   ` (4 subsequent siblings)
  6 siblings, 0 replies; 7+ messages in thread
From: Jérémie Galarneau @ 2013-03-26  0:28 UTC (permalink / raw)
  To: lttng-dev

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

Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
---
 .gitignore                                     |   1 +
 configure.ac                                   |   1 +
 tests/fast_regression                          |   1 +
 tests/long_regression                          |   1 +
 tests/regression/ust/Makefile.am               |   2 +-
 tests/regression/ust/daemon/Makefile.am        |  15 ++++
 tests/regression/ust/daemon/README             |  27 ++++++
 tests/regression/ust/daemon/daemon.c           |  54 +++++++++++
 tests/regression/ust/daemon/test_daemon        |  35 ++++++++
 tests/regression/ust/daemon/test_daemon.py     | 120 +++++++++++++++++++++++++
 tests/regression/ust/daemon/ust_tests_daemon.h |  57 ++++++++++++
 11 files changed, 313 insertions(+), 1 deletion(-)
 create mode 100644 tests/regression/ust/daemon/Makefile.am
 create mode 100644 tests/regression/ust/daemon/README
 create mode 100644 tests/regression/ust/daemon/daemon.c
 create mode 100755 tests/regression/ust/daemon/test_daemon
 create mode 100644 tests/regression/ust/daemon/test_daemon.py
 create mode 100644 tests/regression/ust/daemon/ust_tests_daemon.h

diff --git a/.gitignore b/.gitignore
index b9c3ec8..5ea488e 100644
--- a/.gitignore
+++ b/.gitignore
@@ -67,5 +67,6 @@ tests/regression/ust/overlap/demo/demo
 tests/regression/ust/linking/demo_builtin
 tests/regression/ust/linking/demo_static
 tests/regression/ust/linking/demo
+tests/regression/ust/daemon/daemon
 
 benchmark/
diff --git a/configure.ac b/configure.ac
index 5494cd8..109e4fc 100644
--- a/configure.ac
+++ b/configure.ac
@@ -333,6 +333,7 @@ AC_CONFIG_FILES([
 	tests/regression/ust/overlap/Makefile
 	tests/regression/ust/overlap/demo/Makefile
 	tests/regression/ust/linking/Makefile
+	tests/regression/ust/daemon/Makefile
 	tests/unit/Makefile
 	tests/utils/Makefile
 	tests/utils/tap/Makefile
diff --git a/tests/fast_regression b/tests/fast_regression
index b700fa5..394dbfd 100644
--- a/tests/fast_regression
+++ b/tests/fast_regression
@@ -13,3 +13,4 @@ regression/ust/overlap/test_overlap
 regression/ust/test_event_basic
 regression/ust/test_event_wildcard
 regression/ust/linking/test_linking
+regression/ust/daemon/test_daemon
diff --git a/tests/long_regression b/tests/long_regression
index 1fb68c3..1187270 100644
--- a/tests/long_regression
+++ b/tests/long_regression
@@ -15,3 +15,4 @@ regression/ust/overlap/test_overlap
 regression/ust/test_event_basic
 regression/ust/test_event_wildcard
 regression/ust/linking/test_linking
+regression/ust/daemon/test_daemon
diff --git a/tests/regression/ust/Makefile.am b/tests/regression/ust/Makefile.am
index 74db00b..2dd6fe9 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
+		overlap buffers-uid linking daemon
 
 EXTRA_DIST = test_event_basic test_event_wildcard
 
diff --git a/tests/regression/ust/daemon/Makefile.am b/tests/regression/ust/daemon/Makefile.am
new file mode 100644
index 0000000..d457c06
--- /dev/null
+++ b/tests/regression/ust/daemon/Makefile.am
@@ -0,0 +1,15 @@
+AM_CPPFLAGS = -I$(srcdir)
+
+noinst_PROGRAMS = daemon
+daemon_SOURCES = daemon.c ust_tests_daemon.h
+daemon_LDADD = -llttng-ust -llttng-ust-fork
+
+if LTTNG_TOOLS_BUILD_WITH_LIBDL
+daemon_LDADD += -ldl
+endif
+if LTTNG_TOOLS_BUILD_WITH_LIBC_DL
+daemon_LDADD += -lc
+endif
+
+noinst_SCRIPTS = test_daemon test_daemon.py
+EXTRA_DIST = test_daemon test_daemon.py
diff --git a/tests/regression/ust/daemon/README b/tests/regression/ust/daemon/README
new file mode 100644
index 0000000..64659c6
--- /dev/null
+++ b/tests/regression/ust/daemon/README
@@ -0,0 +1,27 @@
+Daemon tracing test
+-------------------
+
+This test checks if tracing works correctly in a child process created by a
+call to daemon().
+
+DESCRIPTION
+-----------
+
+A session daemon is launched if none are found to be running. The test_daemon
+script then creates a session, enables all events from the userspace domain,
+starts the session and launches the daemon binary.
+
+The daemon binary, in turn, triggers tracepoints both from the original and
+resulting daemon process.
+
+The test_daemon script then parses the resulting trace and ensures that the
+events were correctly recorded and were logged with the right PIDs.
+
+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/daemon/daemon.c b/tests/regression/ust/daemon/daemon.c
new file mode 100644
index 0000000..477e1a6
--- /dev/null
+++ b/tests/regression/ust/daemon/daemon.c
@@ -0,0 +1,54 @@
+/*
+ * Copyright (C) 2009  Pierre-Marc Fournier
+ * Copyright (C) 2011-2012  Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
+ *
+ * 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 <stdio.h>
+#include <unistd.h>
+#include <sys/types.h>
+#include <stdlib.h>
+
+#define TRACEPOINT_DEFINE
+#define TRACEPOINT_CREATE_PROBES
+#include "ust_tests_daemon.h"
+
+int main(int argc, char **argv, char *env[])
+{
+	int result;
+
+	if (argc < 1) {
+		fprintf(stderr, "usage: daemon\n");
+		exit(1);
+	}
+
+	pid_t parent_pid = getpid();
+	printf("parent_pid %d\n", parent_pid);
+	tracepoint(ust_tests_daemon, before_daemon, parent_pid);
+
+	result = daemon(0, 1);
+	if (result == 0) {
+		printf("child_pid %d\n", getpid());
+
+		tracepoint(ust_tests_daemon, after_daemon_child, getpid());
+	} else {
+		tracepoint(ust_tests_daemon, after_daemon_parent);
+		perror("daemon");
+		exit(1);
+	}
+
+	return 0;
+}
diff --git a/tests/regression/ust/daemon/test_daemon b/tests/regression/ust/daemon/test_daemon
new file mode 100755
index 0000000..54afd0c
--- /dev/null
+++ b/tests/regression/ust/daemon/test_daemon
@@ -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_daemon.py
+
+if [ $STOP_SESSIOND -ne 0 ]; then
+    kill `pidof lt-lttng-sessiond`
+fi
diff --git a/tests/regression/ust/daemon/test_daemon.py b/tests/regression/ust/daemon/test_daemon.py
new file mode 100644
index 0000000..c9a9bff
--- /dev/null
+++ b/tests/regression/ust/daemon/test_daemon.py
@@ -0,0 +1,120 @@
+#!/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 uuid
+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 = 6
+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, "*")
+start_session(session_info)
+
+daemon_process = subprocess.Popen(test_path + "daemon", stdout=subprocess.PIPE)
+if sys.version_info >= (3, 3):
+    try:
+        daemon_process_return_code = daemon_process.wait(5)
+    except TimeoutExpired:
+        daemon_process.kill()
+        daemon_process_return_code = -1
+else:
+    daemon_process_return_code = daemon_process.wait()
+
+daemon_process_output = daemon_process.communicate()[0]
+daemon_process_output = daemon_process_output.decode('utf-8').splitlines()
+
+print_test_result(daemon_process_return_code == 0, current_test, "Successful call to daemon() and normal exit")
+current_test += 1
+
+if daemon_process_return_code != 0:
+    bail("Could not trigger tracepoints successfully. Abondoning test.")
+
+stop_session(session_info)
+
+if len(daemon_process_output) != 2:
+    bail("Unexpected output received from daemon test executable." + str(daemon_process_output))
+
+parent_pid = re.search(r"\d+", daemon_process_output[0]).group(0)
+daemon_pid = re.search(r"\d+", daemon_process_output[1]).group(0)
+
+try:
+    babeltrace_process = subprocess.Popen(["babeltrace", session_info.trace_path], stdout=subprocess.PIPE)
+except FileNotFoundError:
+    bail("Could not open babeltrace. Please make sure it is installed.")
+
+before_daemon_event_found = False
+before_daemon_event_pid = -1
+after_daemon_event_found = False
+after_daemon_event_pid = -1
+
+for event_line in babeltrace_process.stdout:
+    event_line = event_line.decode('utf-8').replace("\n", "")
+
+    if re.search(r"before_daemon", event_line) is not None:
+        if before_daemon_event_found:
+            bail("Multiple instances of the before_daemon event found. Please make sure only one instance of this test is runnning.")
+        before_daemon_event_found = True
+        match = re.search(r"(?<=pid = )\d+", event_line)
+
+        if match is not None:
+            before_daemon_event_pid = match.group(0)
+
+    if re.search(r"after_daemon", event_line) is not None:
+        if after_daemon_event_found:
+            bail("Multiple instances of the after_daemon event found. Please make sure only one instance of this test is runnning.")
+        after_daemon_event_found = True
+        match = re.search(r"(?<=pid = )\d+", event_line)
+
+        if match is not None:
+            after_daemon_event_pid = match.group(0)
+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(before_daemon_event_found, current_test, "before_daemon event found in resulting trace")
+current_test += 1
+print_test_result(before_daemon_event_pid == parent_pid, current_test, "Parent pid reported in trace is correct")
+current_test += 1
+print_test_result(before_daemon_event_found, current_test, "after_daemon event found in resulting trace")
+current_test += 1
+print_test_result(after_daemon_event_pid == daemon_pid, current_test, "Daemon pid reported in trace is correct")
+current_test += 1
+
+shutil.rmtree(session_info.tmp_directory)
diff --git a/tests/regression/ust/daemon/ust_tests_daemon.h b/tests/regression/ust/daemon/ust_tests_daemon.h
new file mode 100644
index 0000000..0025a54
--- /dev/null
+++ b/tests/regression/ust/daemon/ust_tests_daemon.h
@@ -0,0 +1,57 @@
+#undef TRACEPOINT_PROVIDER
+#define TRACEPOINT_PROVIDER ust_tests_daemon
+
+#if !defined(_TRACEPOINT_UST_TESTS_DAEMON_H) || defined(TRACEPOINT_HEADER_MULTI_READ)
+#define _TRACEPOINT_UST_TESTS_DAEMON_H
+
+/*
+ * Copyright (C) 2012  Mathieu Desnoyers <mathieu.desnoyers@efficios.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.
+ */
+
+#include <lttng/tracepoint.h>
+#include <sys/types.h>
+
+TRACEPOINT_EVENT(ust_tests_daemon, before_daemon,
+	TP_ARGS(pid_t, pid),
+	TP_FIELDS(
+		ctf_integer(pid_t, pid, pid)
+	)
+)
+
+TRACEPOINT_EVENT(ust_tests_daemon, after_daemon_child,
+	TP_ARGS(pid_t, pid),
+	TP_FIELDS(
+		ctf_integer(pid_t, pid, pid)
+	)
+)
+
+TRACEPOINT_EVENT(ust_tests_daemon, after_daemon_parent,
+	TP_ARGS(),
+	TP_FIELDS()
+)
+
+#endif /* _TRACEPOINT_UST_TESTS_DAEMON_H */
+
+#undef TRACEPOINT_INCLUDE
+#define TRACEPOINT_INCLUDE "./ust_tests_daemon.h"
+
+/* This part must be outside ifdef protection */
+#include <lttng/tracepoint-event.h>
-- 
1.8.2


_______________________________________________
lttng-dev mailing list
lttng-dev@lists.lttng.org
http://lists.lttng.org/cgi-bin/mailman/listinfo/lttng-dev

^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH lttng-tools 4/7] Tests: Add "exit-fast" ust regression test
       [not found] <1364257716-5739-1-git-send-email-jeremie.galarneau@efficios.com>
  2013-03-26  0:28 ` [PATCH lttng-tools 2/7] Tests: Add "linking" ust regression test Jérémie Galarneau
  2013-03-26  0:28 ` [PATCH lttng-tools 3/7] Tests: Add "daemon" " Jérémie Galarneau
@ 2013-03-26  0:28 ` Jérémie Galarneau
  2013-03-26  0:28 ` [PATCH lttng-tools 5/7] Tests: Add "fork" " Jérémie Galarneau
                   ` (3 subsequent siblings)
  6 siblings, 0 replies; 7+ messages in thread
From: Jérémie Galarneau @ 2013-03-26  0:28 UTC (permalink / raw)
  To: lttng-dev

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

Signed-off-by: Jérémie Galarneau <jeremie.galarneau@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@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@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@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 */
-- 
1.8.2


_______________________________________________
lttng-dev mailing list
lttng-dev@lists.lttng.org
http://lists.lttng.org/cgi-bin/mailman/listinfo/lttng-dev

^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH lttng-tools 5/7] Tests: Add "fork" ust regression test
       [not found] <1364257716-5739-1-git-send-email-jeremie.galarneau@efficios.com>
                   ` (2 preceding siblings ...)
  2013-03-26  0:28 ` [PATCH lttng-tools 4/7] Tests: Add "exit-fast" " Jérémie Galarneau
@ 2013-03-26  0:28 ` Jérémie Galarneau
  2013-03-26  0:28 ` [PATCH lttng-tools 6/7] Tests: Add "libc-wrapper" " Jérémie Galarneau
                   ` (2 subsequent siblings)
  6 siblings, 0 replies; 7+ messages in thread
From: Jérémie Galarneau @ 2013-03-26  0:28 UTC (permalink / raw)
  To: lttng-dev

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

Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
---
 .gitignore                                 |   2 +
 configure.ac                               |   1 +
 tests/fast_regression                      |   1 +
 tests/long_regression                      |   1 +
 tests/regression/ust/Makefile.am           |   2 +-
 tests/regression/ust/fork/Makefile.am      |  20 +++++
 tests/regression/ust/fork/README           |  26 ++++++
 tests/regression/ust/fork/fork.c           |  62 +++++++++++++++
 tests/regression/ust/fork/fork2.c          |  32 ++++++++
 tests/regression/ust/fork/test_fork        |  35 ++++++++
 tests/regression/ust/fork/test_fork.py     | 124 +++++++++++++++++++++++++++++
 tests/regression/ust/fork/ust_tests_fork.h |  66 +++++++++++++++
 12 files changed, 371 insertions(+), 1 deletion(-)
 create mode 100644 tests/regression/ust/fork/Makefile.am
 create mode 100644 tests/regression/ust/fork/README
 create mode 100644 tests/regression/ust/fork/fork.c
 create mode 100644 tests/regression/ust/fork/fork2.c
 create mode 100755 tests/regression/ust/fork/test_fork
 create mode 100644 tests/regression/ust/fork/test_fork.py
 create mode 100644 tests/regression/ust/fork/ust_tests_fork.h

diff --git a/.gitignore b/.gitignore
index 4c186d2..533973a 100644
--- a/.gitignore
+++ b/.gitignore
@@ -69,5 +69,7 @@ tests/regression/ust/linking/demo_static
 tests/regression/ust/linking/demo
 tests/regression/ust/daemon/daemon
 tests/regression/ust/exit-fast/exit-fast
+tests/regression/ust/fork/fork
+tests/regression/ust/fork/fork2
 
 benchmark/
diff --git a/configure.ac b/configure.ac
index 88d8a33..d7ca253 100644
--- a/configure.ac
+++ b/configure.ac
@@ -335,6 +335,7 @@ AC_CONFIG_FILES([
 	tests/regression/ust/linking/Makefile
 	tests/regression/ust/daemon/Makefile
 	tests/regression/ust/exit-fast/Makefile
+	tests/regression/ust/fork/Makefile
 	tests/unit/Makefile
 	tests/utils/Makefile
 	tests/utils/tap/Makefile
diff --git a/tests/fast_regression b/tests/fast_regression
index e588661..cc561fb 100644
--- a/tests/fast_regression
+++ b/tests/fast_regression
@@ -15,3 +15,4 @@ regression/ust/test_event_wildcard
 regression/ust/linking/test_linking
 regression/ust/daemon/test_daemon
 regression/ust/exit-fast/test_exit-fast
+regression/ust/fork/test_fork
diff --git a/tests/long_regression b/tests/long_regression
index a81d094..810b661 100644
--- a/tests/long_regression
+++ b/tests/long_regression
@@ -17,3 +17,4 @@ regression/ust/test_event_wildcard
 regression/ust/linking/test_linking
 regression/ust/daemon/test_daemon
 regression/ust/exit-fast/test_exit-fast
+regression/ust/fork/test_fork
diff --git a/tests/regression/ust/Makefile.am b/tests/regression/ust/Makefile.am
index 1631ba6..23613bd 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 exit-fast
+		overlap buffers-uid linking daemon exit-fast fork
 
 EXTRA_DIST = test_event_basic test_event_wildcard
 
diff --git a/tests/regression/ust/fork/Makefile.am b/tests/regression/ust/fork/Makefile.am
new file mode 100644
index 0000000..97f134f
--- /dev/null
+++ b/tests/regression/ust/fork/Makefile.am
@@ -0,0 +1,20 @@
+AM_CPPFLAGS = -I$(srcdir)
+
+noinst_PROGRAMS = fork fork2
+fork_SOURCES = fork.c ust_tests_fork.h
+fork_LDADD = -llttng-ust -llttng-ust-fork
+
+fork2_SOURCES = fork2.c
+fork2_LDADD = -llttng-ust -llttng-ust-fork
+
+if LTTNG_TOOLS_BUILD_WITH_LIBDL
+fork_LDADD += -ldl
+fork2_LDADD += -ldl
+endif
+if LTTNG_TOOLS_BUILD_WITH_LIBC_DL
+fork_LDADD += -lc
+fork2_LDADD += -lc
+endif
+
+noinst_SCRIPTS = test_fork test_fork.py
+EXTRA_DIST = test_fork test_fork.py
diff --git a/tests/regression/ust/fork/README b/tests/regression/ust/fork/README
new file mode 100644
index 0000000..eb36100
--- /dev/null
+++ b/tests/regression/ust/fork/README
@@ -0,0 +1,26 @@
+Fork tracing test
+-------------------
+
+This test checks if tracing works correctly in a child process created by a
+fork() call, as well as after an exec() call.
+
+DESCRIPTION
+-----------
+
+The test_fork script launches a binary that forks and calls exec() with
+the command provided as the argument. Tracepoints are placed before and
+after these calls to verify tracing remains operational at all times.
+
+The binary loaded as the new process image also logs an event.
+
+The resulting trace is parsed to make sure the every event was logged
+successfully with the correct PIDs.
+
+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/fork/fork.c b/tests/regression/ust/fork/fork.c
new file mode 100644
index 0000000..744e920
--- /dev/null
+++ b/tests/regression/ust/fork/fork.c
@@ -0,0 +1,62 @@
+/*
+ * Copyright (C) 2009  Pierre-Marc Fournier
+ * Copyright (C) 2011  Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
+ *
+ * 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 <stdio.h>
+#include <unistd.h>
+#include <sys/types.h>
+#include <stdlib.h>
+
+#define TRACEPOINT_DEFINE
+#define TRACEPOINT_CREATE_PROBES
+#include "ust_tests_fork.h"
+
+int main(int argc, char **argv, char *env[])
+{
+	int result;
+
+	if (argc < 2) {
+		fprintf(stderr, "usage: fork PROG_TO_EXEC\n");
+		exit(1);
+	}
+
+	printf("parent_pid %d\n", getpid());
+	tracepoint(ust_tests_fork, before_fork, getpid());
+
+	result = fork();
+	if (result == -1) {
+		perror("fork");
+		return 1;
+	}
+	if (result == 0) {
+		char *args[] = { "fork2", NULL };
+
+		tracepoint(ust_tests_fork, after_fork_child, getpid());
+
+		result = execve(argv[1], args, env);
+		if (result == -1) {
+			perror("execve");
+			return 1;
+		}
+	} else {
+		printf("child_pid %d\n", result);
+		tracepoint(ust_tests_fork, after_fork_parent, getpid());
+	}
+
+	return 0;
+}
diff --git a/tests/regression/ust/fork/fork2.c b/tests/regression/ust/fork/fork2.c
new file mode 100644
index 0000000..ee0f36b
--- /dev/null
+++ b/tests/regression/ust/fork/fork2.c
@@ -0,0 +1,32 @@
+/* Copyright (C) 2009  Pierre-Marc Fournier
+ *
+ * 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
+ */
+
+#include <stdio.h>
+#include <unistd.h>
+
+#define TRACEPOINT_DEFINE
+#define TRACEPOINT_CREATE_PROBES
+#include "ust_tests_fork.h"
+
+int main()
+{
+	printf("IN FORK2\n");
+
+	tracepoint(ust_tests_fork, after_exec, getpid());
+
+	return 0;
+}
diff --git a/tests/regression/ust/fork/test_fork b/tests/regression/ust/fork/test_fork
new file mode 100755
index 0000000..e05b556
--- /dev/null
+++ b/tests/regression/ust/fork/test_fork
@@ -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_fork.py
+
+if [ $STOP_SESSIOND -ne 0 ]; then
+    kill `pidof lt-lttng-sessiond`
+fi
diff --git a/tests/regression/ust/fork/test_fork.py b/tests/regression/ust/fork/test_fork.py
new file mode 100644
index 0000000..62faf71
--- /dev/null
+++ b/tests/regression/ust/fork/test_fork.py
@@ -0,0 +1,124 @@
+#!/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 *
+
+
+NR_TESTS = 6
+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_fork*")
+start_session(session_info)
+
+fork_process = subprocess.Popen([test_path + "fork", test_path + "fork2"], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
+
+if sys.version_info >= (3, 3):
+    try:
+        fork_process.wait(5)
+    except TimeoutExpired:
+        fork_process.kill()
+        bail("Failed to run fork test application (time out)", session_info)
+else:
+    fork_process.wait()
+
+parent_pid = -1
+child_pid = -1
+for line in fork_process.stdout:
+    line = line.decode('utf-8').replace("\n", "")
+    match = re.search(r"child_pid (\d+)", line)
+    if match:
+        child_pid = match.group(1)
+    match = re.search(r"parent_pid (\d+)", line)
+    if match:
+        parent_pid = match.group(1)
+
+print_test_result(fork_process.returncode == 0, current_test, "Fork test application exited normally")
+current_test += 1
+
+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.", session_info)
+
+event_lines = []
+for event_line in babeltrace_process.stdout:
+    event_line = event_line.decode('utf-8').replace("\n", "")
+    if re.search(r"warning", event_line) is not None or re.search(r"error", event_line) is not None:
+        print( "# " + event_line )
+    else:
+        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.", session_info)
+
+event_before_fork = False
+event_after_fork_parent = False
+event_after_fork_child = False
+event_after_exec = False
+
+for event_line in event_lines:
+    match = re.search(r".*pid = (\d+)", event_line)
+    if match is not None:
+        event_pid = match.group(1)
+    else:
+        continue
+
+    if re.search(r"before_fork", event_line):
+        event_before_fork = (event_pid == parent_pid)
+    if re.search(r"after_fork_parent", event_line):
+        event_after_fork_parent = (event_pid == parent_pid)
+    if re.search(r"after_fork_child", event_line):
+        event_after_fork_child = (event_pid == child_pid)
+    if re.search(r"after_exec", event_line):
+        event_after_exec = (event_pid == child_pid)
+
+print_test_result(event_before_fork, current_test, "before_fork event logged by parent process found in trace")
+current_test += 1
+print_test_result(event_after_fork_parent, current_test, "after_fork_parent event logged by parent process found in trace")
+current_test += 1
+print_test_result(event_after_fork_child, current_test, "after_fork_child event logged by child process found in trace")
+current_test += 1
+print_test_result(event_after_exec, current_test, "after_exec event logged by child process found in trace")
+current_test += 1
+
+shutil.rmtree(session_info.tmp_directory)
diff --git a/tests/regression/ust/fork/ust_tests_fork.h b/tests/regression/ust/fork/ust_tests_fork.h
new file mode 100644
index 0000000..b034f9f
--- /dev/null
+++ b/tests/regression/ust/fork/ust_tests_fork.h
@@ -0,0 +1,66 @@
+#undef TRACEPOINT_PROVIDER
+#define TRACEPOINT_PROVIDER ust_tests_fork
+
+#if !defined(_TRACEPOINT_UST_TESTS_FORK_H) || defined(TRACEPOINT_HEADER_MULTI_READ)
+#define _TRACEPOINT_UST_TESTS_FORK_H
+
+/*
+ * Copyright (C) 2011  Mathieu Desnoyers <mathieu.desnoyers@efficios.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.
+ */
+
+#include <lttng/tracepoint.h>
+#include <sys/types.h>
+
+TRACEPOINT_EVENT(ust_tests_fork, before_fork,
+	TP_ARGS(pid_t, pid),
+	TP_FIELDS(
+		ctf_integer(pid_t, pid, pid)
+	)
+)
+
+TRACEPOINT_EVENT(ust_tests_fork, after_fork_child,
+	TP_ARGS(pid_t, pid),
+	TP_FIELDS(
+		ctf_integer(pid_t, pid, pid)
+	)
+)
+
+TRACEPOINT_EVENT(ust_tests_fork, after_fork_parent,
+	TP_ARGS(pid_t, pid),
+	TP_FIELDS(
+		ctf_integer(pid_t, pid, pid)
+	)
+)
+
+TRACEPOINT_EVENT(ust_tests_fork, after_exec,
+	TP_ARGS(pid_t, pid),
+	TP_FIELDS(
+		ctf_integer(pid_t, pid, pid)
+	)
+)
+
+#endif /* _TRACEPOINT_UST_TESTS_FORK_H */
+
+#undef TRACEPOINT_INCLUDE
+#define TRACEPOINT_INCLUDE "./ust_tests_fork.h"
+
+/* This part must be outside ifdef protection */
+#include <lttng/tracepoint-event.h>
-- 
1.8.2


_______________________________________________
lttng-dev mailing list
lttng-dev@lists.lttng.org
http://lists.lttng.org/cgi-bin/mailman/listinfo/lttng-dev

^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH lttng-tools 6/7] Tests: Add "libc-wrapper" ust regression test
       [not found] <1364257716-5739-1-git-send-email-jeremie.galarneau@efficios.com>
                   ` (3 preceding siblings ...)
  2013-03-26  0:28 ` [PATCH lttng-tools 5/7] Tests: Add "fork" " Jérémie Galarneau
@ 2013-03-26  0:28 ` Jérémie Galarneau
  2013-03-26  0:28 ` [PATCH lttng-tools 7/7] Add optional Python >= 3.0 dependency to README Jérémie Galarneau
  2013-03-27 14:38 ` [PATCH lttng-tools 1/7] Tests: Add Python test_utils module David Goulet
  6 siblings, 0 replies; 7+ messages in thread
From: Jérémie Galarneau @ 2013-03-26  0:28 UTC (permalink / raw)
  To: lttng-dev

Based on the "test-libustinstr-malloc" test formerly part of lttng-ust.

Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
---
 .gitignore                                         |  1 +
 configure.ac                                       |  1 +
 tests/fast_regression                              |  1 +
 tests/long_regression                              |  1 +
 tests/regression/ust/Makefile.am                   |  2 +-
 tests/regression/ust/libc-wrapper/Makefile.am      |  8 ++
 tests/regression/ust/libc-wrapper/README           | 22 ++++++
 tests/regression/ust/libc-wrapper/prog.c           | 48 +++++++++++
 .../regression/ust/libc-wrapper/test_libc-wrapper  | 35 ++++++++
 .../ust/libc-wrapper/test_libc-wrapper.py          | 92 ++++++++++++++++++++++
 10 files changed, 210 insertions(+), 1 deletion(-)
 create mode 100644 tests/regression/ust/libc-wrapper/Makefile.am
 create mode 100644 tests/regression/ust/libc-wrapper/README
 create mode 100644 tests/regression/ust/libc-wrapper/prog.c
 create mode 100755 tests/regression/ust/libc-wrapper/test_libc-wrapper
 create mode 100644 tests/regression/ust/libc-wrapper/test_libc-wrapper.py

diff --git a/.gitignore b/.gitignore
index 533973a..8e2e63d 100644
--- a/.gitignore
+++ b/.gitignore
@@ -71,5 +71,6 @@ tests/regression/ust/daemon/daemon
 tests/regression/ust/exit-fast/exit-fast
 tests/regression/ust/fork/fork
 tests/regression/ust/fork/fork2
+tests/regression/ust/libc-wrapper/prog
 
 benchmark/
diff --git a/configure.ac b/configure.ac
index d7ca253..e2c2a4f 100644
--- a/configure.ac
+++ b/configure.ac
@@ -336,6 +336,7 @@ AC_CONFIG_FILES([
 	tests/regression/ust/daemon/Makefile
 	tests/regression/ust/exit-fast/Makefile
 	tests/regression/ust/fork/Makefile
+	tests/regression/ust/libc-wrapper/Makefile
 	tests/unit/Makefile
 	tests/utils/Makefile
 	tests/utils/tap/Makefile
diff --git a/tests/fast_regression b/tests/fast_regression
index cc561fb..175bb03 100644
--- a/tests/fast_regression
+++ b/tests/fast_regression
@@ -16,3 +16,4 @@ regression/ust/linking/test_linking
 regression/ust/daemon/test_daemon
 regression/ust/exit-fast/test_exit-fast
 regression/ust/fork/test_fork
+regression/ust/libc-wrapper/test_libc-wrapper
diff --git a/tests/long_regression b/tests/long_regression
index 810b661..8b1cbfc 100644
--- a/tests/long_regression
+++ b/tests/long_regression
@@ -18,3 +18,4 @@ regression/ust/linking/test_linking
 regression/ust/daemon/test_daemon
 regression/ust/exit-fast/test_exit-fast
 regression/ust/fork/test_fork
+regression/ust/libc-wrapper/test_libc-wrapper
diff --git a/tests/regression/ust/Makefile.am b/tests/regression/ust/Makefile.am
index 23613bd..e622544 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 exit-fast fork
+		overlap buffers-uid linking daemon exit-fast fork libc-wrapper
 
 EXTRA_DIST = test_event_basic test_event_wildcard
 
diff --git a/tests/regression/ust/libc-wrapper/Makefile.am b/tests/regression/ust/libc-wrapper/Makefile.am
new file mode 100644
index 0000000..af12d31
--- /dev/null
+++ b/tests/regression/ust/libc-wrapper/Makefile.am
@@ -0,0 +1,8 @@
+AM_CPPFLAGS = -I$(srcdir)
+
+noinst_PROGRAMS = prog
+prog_SOURCES = prog.c
+prog_LDADD = -llttng-ust -llttng-ust-libc-wrapper
+
+noinst_SCRIPTS = test_libc-wrapper test_libc-wrapper.py
+EXTRA_DIST = test_libc-wrapper test_libc-wrapper.py
diff --git a/tests/regression/ust/libc-wrapper/README b/tests/regression/ust/libc-wrapper/README
new file mode 100644
index 0000000..adcd425
--- /dev/null
+++ b/tests/regression/ust/libc-wrapper/README
@@ -0,0 +1,22 @@
+libc-wrapper malloc/free tracing test
+-------------------------------------
+
+This test checks if tracing works correctly when applications are linked against
+the UST libc wrapper which provides tracepoints in the malloc and free libc
+functions.
+
+DESCRIPTION
+-----------
+
+The test application performs a series of calls to malloc()/free() and the
+resulting trace is checked for the presence of ust-libc:malloc and ust-libc:free
+events.
+
+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/libc-wrapper/prog.c b/tests/regression/ust/libc-wrapper/prog.c
new file mode 100644
index 0000000..3068257
--- /dev/null
+++ b/tests/regression/ust/libc-wrapper/prog.c
@@ -0,0 +1,48 @@
+/* Copyright (C) 2009  Pierre-Marc Fournier
+ *
+ * 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 program is used to test malloc instrumentation with libustinstr-malloc.
+ */
+
+#include <string.h>
+#include <stdlib.h>
+
+#define N_ITER 1000
+
+int main()
+{
+	int i;
+	const char teststr[] = "Hello World! 1234567890abc";
+	void *ptrs[N_ITER];
+
+	for (i = 0; i < N_ITER; i++) {
+		ptrs[i] = malloc(i+1000);
+
+		memcpy(ptrs[i], teststr, sizeof(teststr));
+
+		if (i % 2 == 0) {
+			free(ptrs[i]);
+		}
+	}
+
+	for (i = 0; i < N_ITER; i++) {
+		if (i % 2 == 1)
+			free(ptrs[i]);
+	}
+
+	return 0;
+}
diff --git a/tests/regression/ust/libc-wrapper/test_libc-wrapper b/tests/regression/ust/libc-wrapper/test_libc-wrapper
new file mode 100755
index 0000000..8c6b128
--- /dev/null
+++ b/tests/regression/ust/libc-wrapper/test_libc-wrapper
@@ -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_libc-wrapper.py
+
+if [ $STOP_SESSIOND -ne 0 ]; then
+    kill `pidof lt-lttng-sessiond`
+fi
diff --git a/tests/regression/ust/libc-wrapper/test_libc-wrapper.py b/tests/regression/ust/libc-wrapper/test_libc-wrapper.py
new file mode 100644
index 0000000..d45b71a
--- /dev/null
+++ b/tests/regression/ust/libc-wrapper/test_libc-wrapper.py
@@ -0,0 +1,92 @@
+#!/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 *
+
+
+NR_TESTS = 4
+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_libc*")
+start_session(session_info)
+
+malloc_process = subprocess.Popen(test_path + "prog", stdout=subprocess.PIPE, stderr=subprocess.PIPE)
+if sys.version_info >= (3, 3):
+    try:
+        malloc_process.wait(5)
+    except TimeoutExpired:
+        malloc_process.kill()
+        bail("Failed to run libustinstr-malloc test application.", session_info)
+else:
+    malloc_process.wait()
+
+print_test_result(malloc_process.returncode == 0, current_test, "Test application exited normally")
+current_test += 1
+
+stop_session(session_info)
+
+# Check for malloc events 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.", session_info)
+
+malloc_event_found = False
+free_event_found = False
+
+for event_line in babeltrace_process.stdout:
+    # Let babeltrace finish to get the return code
+    if malloc_event_found and free_event_found:
+        continue
+
+    event_line = event_line.decode('utf-8').replace("\n", "")
+    if re.search(r".*ust_libc:malloc.*", event_line) is not None:
+        malloc_event_found = True
+
+    if re.search(r".*ust_libc:free.*", event_line) is not None:
+        free_event_found = True
+
+babeltrace_process.wait()
+
+print_test_result(babeltrace_process.returncode == 0, current_test, "Resulting trace is readable")
+current_test += 1
+
+print_test_result(free_event_found, current_test, "ust_libc:malloc event found in resulting trace")
+current_test += 1
+
+print_test_result(free_event_found, current_test, "ust_libc:free event found in resulting trace")
+current_test += 1
+
+shutil.rmtree(session_info.tmp_directory)
-- 
1.8.2


_______________________________________________
lttng-dev mailing list
lttng-dev@lists.lttng.org
http://lists.lttng.org/cgi-bin/mailman/listinfo/lttng-dev

^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH lttng-tools 7/7] Add optional Python >= 3.0 dependency to README
       [not found] <1364257716-5739-1-git-send-email-jeremie.galarneau@efficios.com>
                   ` (4 preceding siblings ...)
  2013-03-26  0:28 ` [PATCH lttng-tools 6/7] Tests: Add "libc-wrapper" " Jérémie Galarneau
@ 2013-03-26  0:28 ` Jérémie Galarneau
  2013-03-27 14:38 ` [PATCH lttng-tools 1/7] Tests: Add Python test_utils module David Goulet
  6 siblings, 0 replies; 7+ messages in thread
From: Jérémie Galarneau @ 2013-03-26  0:28 UTC (permalink / raw)
  To: lttng-dev


Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
---
 README | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/README b/README
index cfbf1ac..9aab80f 100644
--- a/README
+++ b/README
@@ -31,6 +31,11 @@ REQUIREMENTS:
     - Perl (optional)
       Needed for make check and tests.
 
+    - Python >= 3.0 (optional)
+      Needed for make check and tests.
+
+      * Debian/Ubuntu package: python3
+
     - SWIG >= 2.0 (optional)
       Needed for Python bindings (--enable-python-bindings).
 
-- 
1.8.2


_______________________________________________
lttng-dev mailing list
lttng-dev@lists.lttng.org
http://lists.lttng.org/cgi-bin/mailman/listinfo/lttng-dev

^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [PATCH lttng-tools 1/7] Tests: Add Python test_utils module
       [not found] <1364257716-5739-1-git-send-email-jeremie.galarneau@efficios.com>
                   ` (5 preceding siblings ...)
  2013-03-26  0:28 ` [PATCH lttng-tools 7/7] Add optional Python >= 3.0 dependency to README Jérémie Galarneau
@ 2013-03-27 14:38 ` David Goulet
  6 siblings, 0 replies; 7+ messages in thread
From: David Goulet @ 2013-03-27 14:38 UTC (permalink / raw)
  To: Jérémie Galarneau; +Cc: lttng-dev

Merged!

Thanks!

Jérémie Galarneau:
> Basic Python test framework based on the lttng-tools Python bindings
> that facilitates the creation of a tracing session saving its trace in
> a temporary location, the activation of events in the UST domain and
> clean teardown of the test session.
> 
> Also provides basic TAP output facilities.
> 
> Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
> ---
>  tests/utils/test_utils.py | 111 ++++++++++++++++++++++++++++++++++++++++++++++
>  1 file changed, 111 insertions(+)
>  create mode 100644 tests/utils/test_utils.py
> 
> diff --git a/tests/utils/test_utils.py b/tests/utils/test_utils.py
> new file mode 100644
> index 0000000..5e00de4
> --- /dev/null
> +++ b/tests/utils/test_utils.py
> @@ -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 uuid
> +import os
> +import subprocess
> +import shutil
> +import sys
> +import tempfile
> +
> +# Import lttng bindings generated in the current tree
> +lttng_bindings_path = os.path.dirname(os.path.abspath(__file__)) + "/"
> +for i in range(3):
> +    lttng_bindings_path = os.path.dirname(lttng_bindings_path)
> +lttng_bindings_path = lttng_bindings_path + "/extras/bindings/swig/python"
> +lttng_bindings_libs_path = lttng_bindings_path + "/.libs"
> +sys.path.append(lttng_bindings_path)
> +sys.path.append(lttng_bindings_libs_path)
> +from lttng import *
> +
> +
> +class SessionInfo:
> +    def __init__(self, handle, session_name, tmp_directory, channel_name):
> +        self.handle = handle
> +        self.name = session_name
> +        self.tmp_directory = tmp_directory
> +        self.trace_path = tmp_directory + "/" + session_name
> +        self.channel_name = channel_name
> +
> +def bail(diag, session_info = None):
> +    print("Bail out!")
> +    print("#", diag)
> +
> +    if session_info is not None:
> +        stop_session(session_info, True)
> +
> +        if os.path.exists(session_info.trace_path):
> +            shutil.rmtree(session_info.trace_path)
> +    exit(-1)
> +
> +def print_test_result(result, number, description):
> +    result_string = None
> +    if result is True:
> +        result_string = "ok"
> +    else:
> +        result_string = "not ok"
> +
> +    result_string += " {0} - {1}".format(number, description)
> +    print(result_string)
> +
> +def enable_ust_tracepoint_event(session_info, event_name):
> +    event = Event()
> +    event.name = event_name
> +    event.type = EVENT_TRACEPOINT
> +    event.loglevel = EVENT_LOGLEVEL_ALL
> +    res = enable_event(session_info.handle, event, session_info.channel_name)
> +    if res < 0:
> +        bail("Failed to enable userspace event " + event_name, session_info)
> +
> +def create_session():
> +    dom = Domain()
> +    dom.type = DOMAIN_UST
> +
> +    session_name = str(uuid.uuid1())
> +    tmp_directory = tempfile.mkdtemp()
> +    trace_path = tmp_directory + "/" + session_name
> +
> +    res = create(session_name, trace_path)
> +    if res < 0:
> +        bail("Failed to create tracing session.")
> +
> +    channel = Channel()
> +    channel.name = "channel0"
> +    channel_set_default_attr(dom, channel.attr)
> +
> +    han = Handle(session_name, dom)
> +    res = enable_channel(han, channel)
> +
> +    session_info = SessionInfo(han, session_name, tmp_directory, channel.name)
> +    if res < 0:
> +        bail("Failed to enable channel " + channel.name, session_info)
> +    return session_info
> +
> +def start_session(session_info):
> +    start(session_info.name)
> +
> +def stop_session(session_info, bailing = False):
> +    # Workaround lttng-ctl outputing directly to stdout by spawning a subprocess.
> +    lttng_binary_path = os.path.dirname(os.path.abspath(__file__)) + "/"
> +    for i in range(3):
> +        lttng_binary_path = os.path.dirname(lttng_binary_path)
> +    lttng_binary_path = lttng_binary_path + "/src/bin/lttng/lttng"
> +
> +    retcode = subprocess.call([lttng_binary_path, "stop", session_info.name], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
> +    if retcode != 0 and not bailing:
> +        bail("Unable to stop session " + session_info.name, session_info)
> +    destroy(session_info.name)

_______________________________________________
lttng-dev mailing list
lttng-dev@lists.lttng.org
http://lists.lttng.org/cgi-bin/mailman/listinfo/lttng-dev

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2013-03-27 14:38 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <1364257716-5739-1-git-send-email-jeremie.galarneau@efficios.com>
2013-03-26  0:28 ` [PATCH lttng-tools 2/7] Tests: Add "linking" ust regression test Jérémie Galarneau
2013-03-26  0:28 ` [PATCH lttng-tools 3/7] Tests: Add "daemon" " Jérémie Galarneau
2013-03-26  0:28 ` [PATCH lttng-tools 4/7] Tests: Add "exit-fast" " Jérémie Galarneau
2013-03-26  0:28 ` [PATCH lttng-tools 5/7] Tests: Add "fork" " Jérémie Galarneau
2013-03-26  0:28 ` [PATCH lttng-tools 6/7] Tests: Add "libc-wrapper" " Jérémie Galarneau
2013-03-26  0:28 ` [PATCH lttng-tools 7/7] Add optional Python >= 3.0 dependency to README Jérémie Galarneau
2013-03-27 14:38 ` [PATCH lttng-tools 1/7] Tests: Add Python test_utils module David Goulet

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.