tests: test uid/gid/pid/vuid/vgid/vpid trackers
authorMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Tue, 10 Jul 2018 18:12:07 +0000 (14:12 -0400)
committerJérémie Galarneau <jeremie.galarneau@efficios.com>
Fri, 20 Dec 2019 05:28:25 +0000 (00:28 -0500)
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Change-Id: I1b5ee95efc58a3969066e353cb30eeb3fd8eebb9
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
configure.ac
tests/regression/tools/Makefile.am
tests/regression/tools/tracker/Makefile.am [new file with mode: 0644]
tests/regression/tools/tracker/test_event_tracker [new file with mode: 0755]
tests/utils/testapp/Makefile.am
tests/utils/testapp/gen-kernel-test-events/Makefile.am [new file with mode: 0644]
tests/utils/testapp/gen-kernel-test-events/gen-kernel-test-events.c [new file with mode: 0644]
tests/utils/utils.sh

index a08055f34fd03e7cb6c42b53190e412b6dffe9a3..4e41487b0fb10ca2872b003b8f968b18d3fc15be 100644 (file)
@@ -1128,6 +1128,7 @@ AC_CONFIG_FILES([
        tests/regression/tools/rotation/Makefile
        tests/regression/tools/base-path/Makefile
        tests/regression/tools/metadata/Makefile
+       tests/regression/tools/tracker/Makefile
        tests/regression/tools/working-directory/Makefile
        tests/regression/tools/relayd-grouping/Makefile
        tests/regression/tools/clear/Makefile
@@ -1166,6 +1167,7 @@ AC_CONFIG_FILES([
        tests/utils/tap/Makefile
        tests/utils/testapp/Makefile
        tests/utils/testapp/gen-ns-events/Makefile
+       tests/utils/testapp/gen-kernel-test-events/Makefile
        tests/utils/testapp/gen-ust-events/Makefile
        tests/utils/testapp/gen-ust-events-ns/Makefile
        tests/utils/testapp/gen-syscall-events-callstack/Makefile
index 5acd34bc7102360fa0f4ec94070f39bbe979d396..e868804f9794ca974c2401dd6d3f4cd4dbbad8a6 100644 (file)
@@ -1,3 +1,3 @@
 SUBDIRS = streaming filtering health tracefile-limits snapshots live exclusion save-load mi \
                wildcard crash regen-metadata regen-statedump notification rotation \
-               base-path metadata working-directory relayd-grouping clear
+               base-path metadata working-directory relayd-grouping clear tracker
diff --git a/tests/regression/tools/tracker/Makefile.am b/tests/regression/tools/tracker/Makefile.am
new file mode 100644 (file)
index 0000000..dd5b923
--- /dev/null
@@ -0,0 +1,18 @@
+AM_CPPFLAGS += -I$(top_srcdir)/tests -I$(srcdir)
+
+noinst_SCRIPTS = test_event_tracker
+EXTRA_DIST = test_event_tracker
+
+all-local:
+       @if [ x"$(srcdir)" != x"$(builddir)" ]; then \
+               for script in $(EXTRA_DIST); do \
+                       cp -f $(srcdir)/$$script $(builddir); \
+               done; \
+       fi
+
+clean-local:
+       @if [ x"$(srcdir)" != x"$(builddir)" ]; then \
+               for script in $(EXTRA_DIST); do \
+                       rm -f $(builddir)/$$script; \
+               done; \
+       fi
diff --git a/tests/regression/tools/tracker/test_event_tracker b/tests/regression/tools/tracker/test_event_tracker
new file mode 100755 (executable)
index 0000000..0daa2f8
--- /dev/null
@@ -0,0 +1,517 @@
+#!/bin/bash
+#
+# Copyright (C) - 2013 Christian Babeux <christian.babeux@efficios.com>
+# Copyright (C) - 2015-2018 Mathieu Desnoyers <mathieu.desnoyers@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.
+
+TEST_DESC="LTTng - Event traker test"
+
+CURDIR=$(dirname "$0")/
+TESTDIR="$CURDIR/../../.."
+TESTAPP_PATH="$TESTDIR/utils/testapp"
+TESTAPP_NAME="gen-ust-events"
+TESTAPP_KERNEL_NAME="gen-kernel-test-events"
+TESTAPP_BIN="$TESTAPP_PATH/$TESTAPP_NAME/$TESTAPP_NAME"
+TESTAPP_KERNEL_BIN="$TESTAPP_PATH/$TESTAPP_KERNEL_NAME/$TESTAPP_KERNEL_NAME"
+SESSION_NAME="tracker"
+NR_ITER=100
+NUM_GLOBAL_TESTS=2
+NUM_UST_TESTS=256
+NUM_KERNEL_TESTS=462
+NUM_TESTS=$((NUM_UST_TESTS+NUM_KERNEL_TESTS+NUM_GLOBAL_TESTS))
+
+NR_USEC_WAIT=0 #for UST gen events
+
+SCRIPT_UID="$(id -u)"
+SCRIPT_GID="$(id -g)"
+SCRIPT_USERNAME="$(id -un)"
+SCRIPT_GROUPNAME="$(id -gn)"
+
+CHILD_PID=-1
+WAIT_PATH=
+AFTER_FIRST_PATH=
+BEFORE_LAST_PATH=
+
+source $TESTDIR/utils/utils.sh
+
+function prepare_ust_app
+{
+       AFTER_FIRST_PATH=$(mktemp -u)
+       BEFORE_LAST_PATH=$(mktemp -u)
+
+       $TESTAPP_BIN -i $NR_ITER -w $NR_USEC_WAIT -a "$AFTER_FIRST_PATH" -b "$BEFORE_LAST_PATH" &
+       CHILD_PID=$!
+}
+
+function trace_ust_app
+{
+       touch "$BEFORE_LAST_PATH"
+       wait
+       ok $? "Traced application stopped."
+       rm "$BEFORE_LAST_PATH"
+       rm "$AFTER_FIRST_PATH"
+}
+
+function prepare_kernel_app
+{
+       WAIT_PATH=$(mktemp -u)
+
+       "$TESTAPP_KERNEL_BIN" "$WAIT_PATH" $NR_ITER &
+       CHILD_PID=$!
+}
+
+function trace_kernel_app
+{
+       touch "$WAIT_PATH"
+       wait
+       ok $? "Traced application stopped."
+       rm "$WAIT_PATH"
+}
+
+function test_event_tracker()
+{
+       local trace_path
+       local domain="$1"
+       local expect_event="$2"
+       local wildcard="$3"
+       local tracker="$4"
+       local channel=''
+
+       trace_path=$(mktemp -d)
+
+       create_lttng_session_ok $SESSION_NAME "$trace_path"
+
+       if [ "$domain" = kernel ]; then
+               channel=chan
+               lttng_enable_kernel_channel 1 0 $SESSION_NAME $channel "--subbuf-size=8M --num-subbuf=4"
+       fi
+
+       enable_"$domain"_lttng_event_ok $SESSION_NAME "$wildcard" "$channel"
+
+       start_lttng_tracing_ok
+
+       lttng_track_"$domain"_ok "${tracker}"
+
+       prepare_"$domain"_app
+
+       trace_"$domain"_app
+
+       stop_lttng_tracing_ok
+       destroy_lttng_session_ok $SESSION_NAME
+
+       if [ "$expect_event" -eq 1 ]; then
+               trace_matches "$EVENT_NAME" $NR_ITER "$trace_path"
+       else
+               validate_trace_session_"$domain"_empty "$trace_path"
+       fi
+
+       rm -rf "$trace_path"
+}
+
+function test_event_vpid_tracker()
+{
+       local trace_path
+       local domain="$1"
+       local expect_event="$2"
+       local wildcard="$3"
+       local channel=''
+
+       trace_path=$(mktemp -d)
+
+       create_lttng_session_ok $SESSION_NAME "$trace_path"
+
+       if [ "$domain" = kernel ]; then
+               channel=chan
+               lttng_enable_kernel_channel 1 0 $SESSION_NAME $channel "--subbuf-size=8M --num-subbuf=4"
+       fi
+
+       enable_"$domain"_lttng_event_ok $SESSION_NAME "$wildcard" "$channel"
+
+       prepare_"$domain"_app
+
+       start_lttng_tracing_ok
+
+       if [ "$expect_event" -eq 1 ]; then
+               lttng_track_"$domain"_ok "--vpid ${CHILD_PID}"
+       else
+               lttng_track_"$domain"_ok "--vpid $((CHILD_PID+1))"
+       fi
+
+       trace_"$domain"_app
+
+       stop_lttng_tracing_ok
+       destroy_lttng_session_ok $SESSION_NAME
+
+       if [ "$expect_event" -eq 1 ]; then
+               validate_trace "$EVENT_NAME" "$trace_path"
+       else
+               validate_trace_empty "$trace_path"
+       fi
+
+       rm -rf "$trace_path"
+}
+
+function test_event_pid_tracker()
+{
+       local trace_path
+       local domain="$1"
+       local expect_event="$2"
+       local wildcard="$3"
+       local channel=''
+
+       trace_path=$(mktemp -d)
+
+       create_lttng_session_ok $SESSION_NAME "$trace_path"
+
+       if [ "$domain" = kernel ]; then
+               channel=chan
+               lttng_enable_kernel_channel 1 0 $SESSION_NAME $channel "--subbuf-size=8M --num-subbuf=4"
+       fi
+
+       enable_"$domain"_lttng_event_ok $SESSION_NAME "$wildcard" "$channel"
+
+       prepare_"$domain"_app
+
+       start_lttng_tracing_ok
+
+       if [ "$expect_event" -eq 1 ]; then
+               lttng_track_"$domain"_ok "--pid ${CHILD_PID}"
+       else
+               lttng_track_"$domain"_ok "--pid $((CHILD_PID+1))"
+       fi
+
+       trace_"$domain"_app
+
+       stop_lttng_tracing_ok
+       destroy_lttng_session_ok $SESSION_NAME
+
+       if [ "$expect_event" -eq 1 ]; then
+               validate_trace "$EVENT_NAME" "$trace_path"
+       else
+               validate_trace_empty "$trace_path"
+       fi
+
+       rm -rf "$trace_path"
+}
+
+
+function test_event_tracker_fail()
+{
+       local trace_path
+       local domain="$1"
+       local wildcard="$2"
+       local tracker="$3"
+
+       trace_path=$(mktemp -d)
+
+       create_lttng_session_ok $SESSION_NAME "$trace_path"
+       enable_"$domain"_lttng_event_ok $SESSION_NAME "$wildcard"
+       lttng_track_"$domain"_fail "${tracker}"
+       destroy_lttng_session_ok $SESSION_NAME
+
+       rm -rf "$trace_path"
+}
+
+function test_event_track_untrack()
+{
+       local trace_path
+       local domain="$1"
+       local expect_event="$2"
+       local wildcard="$3"
+       local tracker="$4"
+       local channel=''
+
+       trace_path=$(mktemp -d)
+
+       create_lttng_session_ok $SESSION_NAME "$trace_path"
+
+       if [ "$domain" = kernel ]; then
+               channel=chan
+               lttng_enable_kernel_channel 1 0 $SESSION_NAME $channel "--subbuf-size=8M --num-subbuf=4"
+       fi
+
+       enable_"$domain"_lttng_event_ok $SESSION_NAME "$wildcard" "$channel"
+
+       start_lttng_tracing_ok
+
+       lttng_track_"$domain"_ok "${tracker}"
+       lttng_untrack_"$domain"_ok "${tracker}"
+
+       prepare_"$domain"_app
+
+       trace_"$domain"_app
+
+       stop_lttng_tracing_ok
+       destroy_lttng_session_ok $SESSION_NAME
+
+       if [ "$expect_event" -eq 1 ]; then
+               trace_matches "$EVENT_NAME" $NR_ITER "$trace_path"
+       else
+               validate_trace_session_"$domain"_empty "$trace_path"
+       fi
+
+       rm -rf "$trace_path"
+}
+
+function test_event_vpid_track_untrack()
+{
+       local trace_path
+       local domain="$1"
+       local expect_event="$2"
+       local wildcard="$3"
+       local channel=''
+
+       trace_path=$(mktemp -d)
+
+       create_lttng_session_ok $SESSION_NAME "$trace_path"
+
+       if [ "$domain" = kernel ]; then
+               channel=chan
+               lttng_enable_kernel_channel 1 0 $SESSION_NAME $channel "--subbuf-size=8M --num-subbuf=4"
+       fi
+
+       enable_"$domain"_lttng_event_ok $SESSION_NAME "$wildcard" "$channel"
+
+       prepare_"$domain"_app
+
+       start_lttng_tracing_ok
+
+       lttng_track_"$domain"_ok "--vpid ${CHILD_PID}"
+       lttng_untrack_"$domain"_ok "--vpid ${CHILD_PID}"
+
+       trace_"$domain"_app
+
+       stop_lttng_tracing_ok
+       destroy_lttng_session_ok $SESSION_NAME
+
+       if [ "$expect_event" -eq 1 ]; then
+               validate_trace "$EVENT_NAME" "$trace_path"
+       else
+               validate_trace_empty "$trace_path"
+       fi
+
+       rm -rf "$trace_path"
+}
+
+function test_event_pid_track_untrack()
+{
+       local trace_path
+       local domain="$1"
+       local expect_event="$2"
+       local wildcard="$3"
+       local channel=''
+
+       trace_path=$(mktemp -d)
+
+       create_lttng_session_ok $SESSION_NAME "$trace_path"
+
+       if [ "$domain" = kernel ]; then
+               channel=chan
+               lttng_enable_kernel_channel 1 0 $SESSION_NAME $channel "--subbuf-size=8M --num-subbuf=4"
+       fi
+
+       enable_"$domain"_lttng_event_ok $SESSION_NAME "$wildcard" "$channel"
+
+       prepare_"$domain"_app
+
+       start_lttng_tracing_ok
+
+       lttng_track_"$domain"_ok "--pid ${CHILD_PID}"
+       lttng_untrack_"$domain"_ok "--pid ${CHILD_PID}"
+
+       trace_"$domain"_app
+
+       stop_lttng_tracing_ok
+       destroy_lttng_session_ok $SESSION_NAME
+
+       if [ "$expect_event" -eq 1 ]; then
+               validate_trace "$EVENT_NAME" "$trace_path"
+       else
+               validate_trace_empty "$trace_path"
+       fi
+
+       rm -rf "$trace_path"
+}
+
+# MUST set TESTDIR before calling those functions
+plan_tests $NUM_TESTS
+
+print_test_banner "$TEST_DESC"
+
+start_lttng_sessiond
+
+diag "Test UST tracker"
+
+if [ ! -x "$TESTAPP_BIN" ]; then
+       BAIL_OUT "No UST nevents binary detected."
+fi
+
+EVENT_NAME="tp:tptest"
+
+#vuid, vgid
+
+# non-matching
+test_event_tracker ust 0 "${EVENT_NAME}" "--vuid $((SCRIPT_UID+1))"
+test_event_tracker ust 0 "${EVENT_NAME}" "--vgid $((SCRIPT_GID+1))"
+test_event_tracker ust 0 "${EVENT_NAME}" "--vuid $((SCRIPT_UID+1)) --vgid $((SCRIPT_GID+1))"
+test_event_tracker ust 0 "${EVENT_NAME}" "--vuid $((SCRIPT_UID+1)) --vgid ${SCRIPT_GID}"
+test_event_tracker ust 0 "${EVENT_NAME}" "--vuid ${SCRIPT_UID} --vgid $((SCRIPT_GID+1))"
+test_event_track_untrack ust 0 "${EVENT_NAME}" "--vuid ${SCRIPT_UID}"
+test_event_track_untrack ust 0 "${EVENT_NAME}" "--vgid ${SCRIPT_GID}"
+test_event_track_untrack ust 0 "${EVENT_NAME}" "--vuid --all"
+test_event_track_untrack ust 0 "${EVENT_NAME}" "--vgid --all"
+
+# matching
+test_event_tracker ust 1 "${EVENT_NAME}" "--vuid ${SCRIPT_UID}"
+test_event_tracker ust 1 "${EVENT_NAME}" "--vgid ${SCRIPT_GID}"
+test_event_tracker ust 1 "${EVENT_NAME}" "--vuid ${SCRIPT_UID} --vgid ${SCRIPT_GID}"
+test_event_tracker ust 1 "${EVENT_NAME}" "--vuid ${SCRIPT_USERNAME}"
+test_event_tracker ust 1 "${EVENT_NAME}" "--vgid ${SCRIPT_GROUPNAME}"
+test_event_tracker ust 1 "${EVENT_NAME}" "--vuid ${SCRIPT_UID},$((SCRIPT_UID+1))"
+test_event_tracker ust 1 "${EVENT_NAME}" "--vgid ${SCRIPT_GID},$((SCRIPT_GID+1))"
+test_event_tracker ust 1 "${EVENT_NAME}" "--vuid ${SCRIPT_USERNAME},$((SCRIPT_UID+1))"
+test_event_tracker ust 1 "${EVENT_NAME}" "--vgid ${SCRIPT_GROUPNAME},$((SCRIPT_GID+1))"
+test_event_tracker ust 1 "${EVENT_NAME}" "--vuid --all"
+test_event_tracker ust 1 "${EVENT_NAME}" "--vgid --all"
+
+#fail
+test_event_tracker_fail ust "${EVENT_NAME}" "--vuid lttng_unexisting_user"
+test_event_tracker_fail ust "${EVENT_NAME}" "--vgid lttng_unexisting_group"
+
+
+#vpid
+
+#non-matching
+test_event_track_untrack ust 0 "${EVENT_NAME}" "--vpid --all"
+test_event_vpid_tracker ust 0 "${EVENT_NAME}"
+test_event_vpid_track_untrack ust 0 "${EVENT_NAME}"
+
+#matching
+test_event_tracker ust 1 "${EVENT_NAME}" "--vpid --all"
+test_event_vpid_tracker ust 1 "${EVENT_NAME}"
+
+#pid (backward compat)
+
+#non-matching
+test_event_pid_tracker ust 0 "${EVENT_NAME}"
+test_event_pid_track_untrack ust 0 "${EVENT_NAME}"
+test_event_track_untrack ust 0 "${EVENT_NAME}" "--pid --all"   # backward compat
+
+#matching
+test_event_tracker ust 1 "${EVENT_NAME}" "--pid --all" # backward compat
+test_event_pid_tracker ust 1 "${EVENT_NAME}"
+
+if [ "$(id -u)" == "0" ]; then
+       isroot=1
+else
+       isroot=0
+fi
+
+skip $isroot "Root access is needed. Skipping all kernel tracker tests." $NUM_KERNEL_TESTS ||
+{
+       diag "Test kernel tracker"
+
+       modprobe lttng-test
+       ok $? "Loading lttng-test module"
+
+       EVENT_NAME="lttng_test_filter_event"
+
+       # vuid, vgid, vpid
+
+       # non-matching
+       test_event_tracker kernel 0 "${EVENT_NAME}" "--vuid $((SCRIPT_UID+1))"
+       test_event_tracker kernel 0 "${EVENT_NAME}" "--vgid $((SCRIPT_GID+1))"
+       test_event_tracker kernel 0 "${EVENT_NAME}" "--vuid $((SCRIPT_UID+1)) --vgid $((SCRIPT_GID+1))"
+       test_event_tracker kernel 0 "${EVENT_NAME}" "--vuid $((SCRIPT_UID+1)) --vgid ${SCRIPT_GID}"
+       test_event_tracker kernel 0 "${EVENT_NAME}" "--vuid ${SCRIPT_UID} --vgid $((SCRIPT_GID+1))"
+       test_event_track_untrack kernel 0 "${EVENT_NAME}" "--vuid ${SCRIPT_UID}"
+       test_event_track_untrack kernel 0 "${EVENT_NAME}" "--vgid ${SCRIPT_GID}"
+       test_event_track_untrack kernel 0 "${EVENT_NAME}" "--vuid --all"
+       test_event_track_untrack kernel 0 "${EVENT_NAME}" "--vgid --all"
+
+       # matching
+       test_event_tracker kernel 1 "${EVENT_NAME}" "--vuid ${SCRIPT_UID}"
+       test_event_tracker kernel 1 "${EVENT_NAME}" "--vgid ${SCRIPT_GID}"
+       test_event_tracker kernel 1 "${EVENT_NAME}" "--vuid ${SCRIPT_UID} --vgid ${SCRIPT_GID}"
+       test_event_tracker kernel 1 "${EVENT_NAME}" "--vuid ${SCRIPT_USERNAME}"
+       test_event_tracker kernel 1 "${EVENT_NAME}" "--vgid ${SCRIPT_GROUPNAME}"
+       test_event_tracker kernel 1 "${EVENT_NAME}" "--vuid ${SCRIPT_UID},$((SCRIPT_UID+1))"
+       test_event_tracker kernel 1 "${EVENT_NAME}" "--vgid ${SCRIPT_GID},$((SCRIPT_GID+1))"
+       test_event_tracker kernel 1 "${EVENT_NAME}" "--vuid ${SCRIPT_USERNAME},$((SCRIPT_UID+1))"
+       test_event_tracker kernel 1 "${EVENT_NAME}" "--vgid ${SCRIPT_GROUPNAME},$((SCRIPT_GID+1))"
+       test_event_tracker kernel 1 "${EVENT_NAME}" "--vuid --all"
+       test_event_tracker kernel 1 "${EVENT_NAME}" "--vgid --all"
+
+       #fail
+       test_event_tracker_fail kernel "${EVENT_NAME}" "--vuid lttng_unexisting_user"
+       test_event_tracker_fail kernel "${EVENT_NAME}" "--vgid lttng_unexisting_group"
+
+
+       #uid, gid
+
+       # non-matching
+       test_event_tracker kernel 0 "${EVENT_NAME}" "--uid $((SCRIPT_UID+1))"
+       test_event_tracker kernel 0 "${EVENT_NAME}" "--gid $((SCRIPT_GID+1))"
+       test_event_tracker kernel 0 "${EVENT_NAME}" "--uid $((SCRIPT_UID+1)) --gid $((SCRIPT_GID+1))"
+       test_event_tracker kernel 0 "${EVENT_NAME}" "--uid $((SCRIPT_UID+1)) --gid ${SCRIPT_GID}"
+       test_event_tracker kernel 0 "${EVENT_NAME}" "--uid ${SCRIPT_UID} --gid $((SCRIPT_GID+1))"
+       test_event_track_untrack kernel 0 "${EVENT_NAME}" "--uid ${SCRIPT_UID}"
+       test_event_track_untrack kernel 0 "${EVENT_NAME}" "--gid ${SCRIPT_GID}"
+       test_event_track_untrack kernel 0 "${EVENT_NAME}" "--uid --all"
+       test_event_track_untrack kernel 0 "${EVENT_NAME}" "--gid --all"
+
+       # matching
+       test_event_tracker kernel 1 "${EVENT_NAME}" "--uid ${SCRIPT_UID}"
+       test_event_tracker kernel 1 "${EVENT_NAME}" "--gid ${SCRIPT_GID}"
+       test_event_tracker kernel 1 "${EVENT_NAME}" "--uid ${SCRIPT_UID} --gid ${SCRIPT_GID}"
+       test_event_tracker kernel 1 "${EVENT_NAME}" "--uid ${SCRIPT_USERNAME}"
+       test_event_tracker kernel 1 "${EVENT_NAME}" "--gid ${SCRIPT_GROUPNAME}"
+       test_event_tracker kernel 1 "${EVENT_NAME}" "--uid ${SCRIPT_UID},$((SCRIPT_UID+1))"
+       test_event_tracker kernel 1 "${EVENT_NAME}" "--gid ${SCRIPT_GID},$((SCRIPT_GID+1))"
+       test_event_tracker kernel 1 "${EVENT_NAME}" "--uid ${SCRIPT_USERNAME},$((SCRIPT_UID+1))"
+       test_event_tracker kernel 1 "${EVENT_NAME}" "--gid ${SCRIPT_GROUPNAME},$((SCRIPT_GID+1))"
+
+       #fail
+       test_event_tracker_fail kernel "${EVENT_NAME}" "--uid lttng_unexisting_user"
+       test_event_tracker_fail kernel "${EVENT_NAME}" "--gid lttng_unexisting_group"
+
+
+       #vpid
+
+       #non-matching
+       test_event_track_untrack kernel 0 "${EVENT_NAME}" "--vpid --all"
+       test_event_vpid_tracker kernel 0 "${EVENT_NAME}"
+       test_event_vpid_track_untrack kernel 0 "${EVENT_NAME}"
+
+       #matching
+       test_event_tracker kernel 1 "${EVENT_NAME}" "--vpid --all"
+       test_event_vpid_tracker kernel 1 "${EVENT_NAME}"
+
+       #pid
+
+       #non-matching
+       test_event_pid_tracker kernel 0 "${EVENT_NAME}"
+       test_event_pid_track_untrack kernel 0 "${EVENT_NAME}"
+       test_event_track_untrack kernel 0 "${EVENT_NAME}" "--pid --all"
+
+       #matching
+       test_event_tracker kernel 1 "${EVENT_NAME}" "--pid --all"
+       test_event_pid_tracker kernel 1 "${EVENT_NAME}"
+
+       rmmod lttng-test
+       ok $? "Unloading lttng-test module"
+}
+
+stop_lttng_sessiond
index e2ad1f2355f6c1f4a3c2fab8a8821d8a98526f5f..12a608ae9a4c94789313ccf9d1dc5c64913bb04e 100644 (file)
@@ -6,6 +6,7 @@ SUBDIRS = \
          gen-ust-nevents-str \
          gen-ust-tracef \
          gen-syscall-events \
+         gen-kernel-test-events \
          userspace-probe-elf-binary
 
 if CXX_WORKS
diff --git a/tests/utils/testapp/gen-kernel-test-events/Makefile.am b/tests/utils/testapp/gen-kernel-test-events/Makefile.am
new file mode 100644 (file)
index 0000000..765a448
--- /dev/null
@@ -0,0 +1,5 @@
+AM_CFLAGS += -I$(top_srcdir)/tests/utils/
+
+noinst_PROGRAMS = gen-kernel-test-events
+gen_kernel_test_events_SOURCES = gen-kernel-test-events.c
+gen_kernel_test_events_LDADD = $(top_builddir)/tests/utils/libtestutils.la
diff --git a/tests/utils/testapp/gen-kernel-test-events/gen-kernel-test-events.c b/tests/utils/testapp/gen-kernel-test-events/gen-kernel-test-events.c
new file mode 100644 (file)
index 0000000..8209379
--- /dev/null
@@ -0,0 +1,88 @@
+/*
+ * Copyright (C) - 2017 Francis Deslauriers <francis.deslauriers@efficios.com>
+ * Copyright (C) - 2018 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 <fcntl.h>
+#include <stdio.h>
+#include <string.h>
+#include <sys/stat.h>
+#include <sys/types.h>
+#include <unistd.h>
+
+#include "utils.h"
+
+#define LTTNG_MODULES_FILE "/proc/lttng-test-filter-event"
+
+/*
+ * The process waits for the creation of a file passed as argument from an
+ * external processes to execute a syscall and exiting. This is useful for tests
+ * in combinaison with LTTng's PID tracker feature where we can trace the kernel
+ * events generated by our test process only.
+ */
+int main(int argc, char **argv)
+{
+       int fd = -1, ret;
+       char *start_file, *nr_events_str;
+       ssize_t len;
+
+       if (argc != 3) {
+               fprintf(stderr, "Error: Missing argument\n");
+               fprintf(stderr, "USAGE: %s PATH_WAIT_FILE NR_EVENTS\n",
+                               argv[0]);
+               ret = -1;
+               goto end;
+       }
+
+       start_file = argv[1];
+       nr_events_str = argv[2];
+
+       /*
+        * Wait for the start_file to be created by an external process
+        * (typically the test script) before executing the syscalls.
+        */
+       ret = wait_on_file(start_file);
+       if (ret != 0) {
+               goto end;
+       }
+
+       /*
+        * Start generating events.
+        */
+       fd = open(LTTNG_MODULES_FILE, O_RDWR);
+       if (fd < 0) {
+               perror("open");
+               ret = -1;
+               goto end;
+       }
+
+       len = write(fd, nr_events_str, strlen(nr_events_str) + 1);
+       if (len != strlen(nr_events_str) + 1) {
+               perror("write");
+               ret = -1;
+       } else {
+               ret = 0;
+       }
+
+end:
+       if (fd >= 0) {
+               int closeret = close(fd);
+               if (closeret) {
+                       perror("close");
+               }
+       }
+       return ret;
+}
index 1525b7b2a400a4219b754e015493dbbfd7349493..1b2f71f183b764977acd05985b48966c8e9db56a 100644 (file)
@@ -1468,8 +1468,8 @@ function lttng_load_fail()
 
 function lttng_track()
 {
-       local expected_to_fail=$1
-       local opts=$2
+       local expected_to_fail="$1"
+       local opts="$@"
        $TESTDIR/../src/bin/lttng/$LTTNG_BIN track $opts >$OUTPUT_DEST
        ret=$?
        if [[ $expected_to_fail -eq "1" ]]; then
@@ -1492,8 +1492,8 @@ function lttng_track_fail()
 
 function lttng_untrack()
 {
-       local expected_to_fail=$1
-       local opts=$2
+       local expected_to_fail="$1"
+       local opts="$@"
        $TESTDIR/../src/bin/lttng/$LTTNG_BIN untrack $opts >$OUTPUT_DEST
        ret=$?
        if [[ $expected_to_fail -eq "1" ]]; then
@@ -1527,6 +1527,46 @@ function lttng_untrack_kernel_all_ok()
        ok $? "Lttng untrack all pid on the kernel domain"
 }
 
+function lttng_track_ust_ok()
+{
+       lttng_track_ok -u "$@"
+}
+
+function lttng_track_ust_fail()
+{
+       lttng_track_fail -u "$@"
+}
+
+function lttng_track_kernel_ok()
+{
+       lttng_track_ok -k "$@"
+}
+
+function lttng_track_kernel_fail()
+{
+       lttng_track_fail -k "$@"
+}
+
+function lttng_untrack_ust_ok()
+{
+       lttng_untrack_ok -u "$@"
+}
+
+function lttng_untrack_ust_fail()
+{
+       lttng_untrack_fail -u "$@"
+}
+
+function lttng_untrack_kernel_ok()
+{
+       lttng_untrack_ok -k "$@"
+}
+
+function lttng_untrack_kernel_fail()
+{
+       lttng_untrack_fail -k "$@"
+}
+
 function lttng_add_context_list()
 {
        $TESTDIR/../src/bin/lttng/$LTTNG_BIN add-context --list 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
@@ -1836,6 +1876,24 @@ function validate_trace_empty()
        return $ret
 }
 
+function validate_folder_is_empty()
+{
+       local folder=$1
+
+       test -z "$(ls -A "$folder")"
+       ok $? "Folder ${folder} is empty"
+}
+
+function validate_trace_session_ust_empty()
+{
+       validate_folder_is_empty "$1"/ust
+}
+
+function validate_trace_session_kernel_empty()
+{
+       validate_trace_empty "$1"/kernel
+}
+
 function regenerate_metadata ()
 {
        local expected_to_fail=$1
This page took 0.035164 seconds and 4 git commands to generate.