Implement tests for kernel syscall tracing feature
authorMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Wed, 24 Sep 2014 01:19:07 +0000 (21:19 -0400)
committerDavid Goulet <dgoulet@efficios.com>
Thu, 25 Sep 2014 15:36:07 +0000 (11:36 -0400)
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
tests/regression/kernel/Makefile.am
tests/regression/kernel/test_syscall [new file with mode: 0755]
tests/root_regression
tests/utils/utils.sh

index a3afbf8ddbb4f67a6db6c458373542990e418de3..36ff6eeac41759807994776e35aec6e9d022afca 100644 (file)
@@ -1,4 +1,4 @@
-EXTRA_DIST = test_event_basic test_all_events
+EXTRA_DIST = test_event_basic test_all_events test_syscall
 
 all-local:
        @if [ x"$(srcdir)" != x"$(builddir)" ]; then \
diff --git a/tests/regression/kernel/test_syscall b/tests/regression/kernel/test_syscall
new file mode 100755 (executable)
index 0000000..5e6b746
--- /dev/null
@@ -0,0 +1,451 @@
+#!/bin/bash
+#
+# Copyright (C) - 2013 Christian Babeux <christian.babeux@efficios.com>
+# Copyright (C) - 2014 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="Kernel tracer - System calls"
+
+CURDIR=$(dirname $0)/
+TESTDIR=$CURDIR/../..
+NUM_TESTS=124
+
+# test command issues at least open and close system calls
+TESTCMD="cat /proc/cpuinfo > /dev/null"
+
+source $TESTDIR/utils/utils.sh
+
+function test_syscall_single()
+{
+       TRACE_PATH=$(mktemp -d)
+       SESSION_NAME="kernel_syscall_single"
+
+       create_lttng_session $SESSION_NAME $TRACE_PATH
+
+       lttng_enable_kernel_syscall_ok $SESSION_NAME "open"
+
+       start_lttng_tracing
+       eval ${TESTCMD}
+       stop_lttng_tracing
+
+       # ensure each is there.
+       validate_trace_exp "-e syscall_entry_open -e compat_syscall_entry_open" $TRACE_PATH
+       validate_trace_exp "-e syscall_exit_open -e compat_syscall_exit_open" $TRACE_PATH
+
+       # ensure trace only contains those.
+       validate_trace_only_exp "-e syscall_entry_open -e compat_syscall_entry_open -e syscall_exit_open -e compat_syscall_exit_open" $TRACE_PATH
+
+       destroy_lttng_session $SESSION_NAME
+
+       rm -rf $TRACE_PATH
+}
+
+function test_syscall_two()
+{
+       TRACE_PATH=$(mktemp -d)
+       SESSION_NAME="kernel_syscall_two"
+
+       create_lttng_session $SESSION_NAME $TRACE_PATH
+
+       lttng_enable_kernel_syscall_ok $SESSION_NAME "open"
+       lttng_enable_kernel_syscall_ok $SESSION_NAME "close"
+
+       start_lttng_tracing
+       eval ${TESTCMD}
+       stop_lttng_tracing
+
+       # ensure each is there.
+       validate_trace_exp "-e syscall_entry_open -e compat_syscall_entry_open" $TRACE_PATH
+       validate_trace_exp "-e syscall_exit_open -e compat_syscall_exit_open" $TRACE_PATH
+       validate_trace_exp "-e syscall_entry_close -e compat_syscall_entry_close" $TRACE_PATH
+       validate_trace_exp "-e syscall_exit_close -e compat_syscall_exit_close" $TRACE_PATH
+
+       # ensure trace only contains those.
+       validate_trace_only_exp "-e syscall_entry_open -e compat_syscall_entry_open -e syscall_exit_open -e compat_syscall_exit_open -e syscall_entry_close -e compat_syscall_entry_close -e syscall_exit_close -e compat_syscall_exit_close" $TRACE_PATH
+
+       destroy_lttng_session $SESSION_NAME
+
+       rm -rf $TRACE_PATH
+}
+
+function test_syscall_all()
+{
+       TRACE_PATH=$(mktemp -d)
+       SESSION_NAME="kernel_syscall_all"
+
+       create_lttng_session $SESSION_NAME $TRACE_PATH
+
+       # enable all syscalls
+       lttng_enable_kernel_syscall_ok $SESSION_NAME
+
+       start_lttng_tracing
+       eval ${TESTCMD}
+       stop_lttng_tracing
+
+       # ensure at least open and close are there.
+       validate_trace_exp "-e syscall_entry_open -e compat_syscall_entry_open" $TRACE_PATH
+       validate_trace_exp "-e syscall_exit_open -e compat_syscall_exit_open" $TRACE_PATH
+       validate_trace_exp "-e syscall_entry_close -e compat_syscall_entry_close" $TRACE_PATH
+       validate_trace_exp "-e syscall_exit_close -e compat_syscall_exit_close" $TRACE_PATH
+       # trace may contain other syscalls.
+
+       destroy_lttng_session $SESSION_NAME
+
+       rm -rf $TRACE_PATH
+}
+
+function test_syscall_all_disable_one()
+{
+       TRACE_PATH=$(mktemp -d)
+       SESSION_NAME="kernel_syscall_all_disable_one"
+
+       create_lttng_session $SESSION_NAME $TRACE_PATH
+
+       # enable all syscalls
+       lttng_enable_kernel_syscall_ok $SESSION_NAME
+       # disable open system call
+       lttng_disable_kernel_syscall_ok $SESSION_NAME "open"
+
+       start_lttng_tracing
+       eval ${TESTCMD}
+       stop_lttng_tracing
+
+       # ensure "open" syscall is not there.
+       validate_trace_only_exp "-v -e syscall_entry_open -e compat_syscall_entry_open -e syscall_exit_open -e compat_syscall_exit_open" $TRACE_PATH
+
+       # ensure "close" syscall is there.
+       validate_trace_exp "-e syscall_entry_close -e compat_syscall_entry_close" $TRACE_PATH
+       validate_trace_exp "-e syscall_exit_close -e compat_syscall_exit_close" $TRACE_PATH
+
+       destroy_lttng_session $SESSION_NAME
+
+       rm -rf $TRACE_PATH
+}
+
+function test_syscall_all_disable_two()
+{
+       TRACE_PATH=$(mktemp -d)
+       SESSION_NAME="kernel_syscall_all_disable_two"
+
+       create_lttng_session $SESSION_NAME $TRACE_PATH
+
+       # enable all syscalls
+       lttng_enable_kernel_syscall_ok $SESSION_NAME
+       # disable open system call
+       lttng_disable_kernel_syscall_ok $SESSION_NAME "open"
+       lttng_disable_kernel_syscall_ok $SESSION_NAME "close"
+
+       start_lttng_tracing
+       # generates open, close, execve (at least)
+       eval ${TESTCMD}
+       stop_lttng_tracing
+
+       # ensure "open" and "close" syscalls are not there.
+       validate_trace_only_exp "-v -e syscall_entry_open -e compat_syscall_entry_open -e syscall_exit_open -e compat_syscall_exit_open -e syscall_entry_close -e compat_syscall_entry_close -e syscall_exit_close -e compat_syscall_exit_close" $TRACE_PATH
+
+       # ensure "execve" syscall is there.
+       validate_trace_exp "-e syscall_entry_execve -e compat_syscall_entry_execve" $TRACE_PATH
+       validate_trace_exp "-e syscall_exit_execve -e compat_syscall_exit_execve" $TRACE_PATH
+
+       destroy_lttng_session $SESSION_NAME
+
+       rm -rf $TRACE_PATH
+}
+
+function test_syscall_enable_all_disable_all()
+{
+       TRACE_PATH=$(mktemp -d)
+       SESSION_NAME="kernel_syscall_enable_all_disable_all"
+
+       create_lttng_session $SESSION_NAME $TRACE_PATH
+
+       # enable all system calls
+       lttng_enable_kernel_syscall_ok $SESSION_NAME
+       # disable all system calls
+       lttng_disable_kernel_syscall_ok $SESSION_NAME
+
+       start_lttng_tracing
+       # generates open, close, execve (at least)
+       eval ${TESTCMD}
+       stop_lttng_tracing
+
+       # ensure nothing has been traced.
+       validate_trace_empty $TRACE_PATH
+
+       destroy_lttng_session $SESSION_NAME
+
+       rm -rf $TRACE_PATH
+}
+
+function test_syscall_enable_all_disable_all_enable_all()
+{
+       TRACE_PATH=$(mktemp -d)
+       SESSION_NAME="kernel_syscall_enable_all_disable_all_enable_all"
+
+       create_lttng_session $SESSION_NAME $TRACE_PATH
+
+       # enable all system calls
+       lttng_enable_kernel_syscall_ok $SESSION_NAME
+       # disable all system calls
+       lttng_disable_kernel_syscall_ok $SESSION_NAME
+       # enable all system calls
+       lttng_enable_kernel_syscall_ok $SESSION_NAME
+
+       start_lttng_tracing
+       # generates open, close, execve (at least)
+       eval ${TESTCMD}
+       stop_lttng_tracing
+
+       # ensure at least open and close are there.
+       validate_trace_exp "-e syscall_entry_open -e compat_syscall_entry_open" $TRACE_PATH
+       validate_trace_exp "-e syscall_exit_open -e compat_syscall_exit_open" $TRACE_PATH
+       validate_trace_exp "-e syscall_entry_close -e compat_syscall_entry_close" $TRACE_PATH
+       validate_trace_exp "-e syscall_exit_close -e compat_syscall_exit_close" $TRACE_PATH
+       # trace may contain other syscalls.
+
+       destroy_lttng_session $SESSION_NAME
+
+       rm -rf $TRACE_PATH
+}
+
+function test_syscall_enable_all_disable_all_twice()
+{
+       TRACE_PATH=$(mktemp -d)
+       SESSION_NAME="kernel_syscall_enable_all_disable_all_twice"
+
+       create_lttng_session $SESSION_NAME $TRACE_PATH
+
+       # enable all system calls
+       lttng_enable_kernel_syscall_ok $SESSION_NAME
+       # disable all system calls
+       lttng_disable_kernel_syscall_ok $SESSION_NAME
+       # enable all system calls
+       lttng_enable_kernel_syscall_ok $SESSION_NAME
+       # disable all system calls
+       lttng_disable_kernel_syscall_ok $SESSION_NAME
+
+       start_lttng_tracing
+       # generates open, close, execve (at least)
+       eval ${TESTCMD}
+       stop_lttng_tracing
+
+       # ensure nothing has been traced.
+       validate_trace_empty $TRACE_PATH
+
+       destroy_lttng_session $SESSION_NAME
+
+       rm -rf $TRACE_PATH
+}
+
+function test_syscall_enable_one_disable_one()
+{
+       TRACE_PATH=$(mktemp -d)
+       SESSION_NAME="kernel_syscall_enable_one_disable_one"
+
+       create_lttng_session $SESSION_NAME $TRACE_PATH
+
+       # enable open system call
+       lttng_enable_kernel_syscall_ok $SESSION_NAME "open"
+       # disable open system call
+       lttng_disable_kernel_syscall_ok $SESSION_NAME "open"
+
+       start_lttng_tracing
+       # generates open, close, execve (at least)
+       eval ${TESTCMD}
+       stop_lttng_tracing
+
+       # ensure nothing has been traced.
+       validate_trace_empty $TRACE_PATH
+
+       destroy_lttng_session $SESSION_NAME
+
+       rm -rf $TRACE_PATH
+}
+
+function test_syscall_enable_two_disable_two()
+{
+       TRACE_PATH=$(mktemp -d)
+       SESSION_NAME="kernel_syscall_enable_two_disable_two"
+
+       create_lttng_session $SESSION_NAME $TRACE_PATH
+
+       # enable open and close system calls
+       lttng_enable_kernel_syscall_ok $SESSION_NAME "open"
+       lttng_enable_kernel_syscall_ok $SESSION_NAME "close"
+       # disable open and close system calls
+       lttng_disable_kernel_syscall_ok $SESSION_NAME "open"
+       lttng_disable_kernel_syscall_ok $SESSION_NAME "close"
+
+       start_lttng_tracing
+       # generates open, close, execve (at least)
+       eval ${TESTCMD}
+       stop_lttng_tracing
+
+       # ensure nothing has been traced.
+       validate_trace_empty $TRACE_PATH
+
+       destroy_lttng_session $SESSION_NAME
+
+       rm -rf $TRACE_PATH
+}
+
+function test_syscall_enable_two_disable_one()
+{
+       TRACE_PATH=$(mktemp -d)
+       SESSION_NAME="kernel_syscall_enable_two_disable_one"
+
+       create_lttng_session $SESSION_NAME $TRACE_PATH
+
+       # enable open and close system calls
+       lttng_enable_kernel_syscall_ok $SESSION_NAME "open"
+       lttng_enable_kernel_syscall_ok $SESSION_NAME "close"
+       # disable close system call
+       lttng_disable_kernel_syscall_ok $SESSION_NAME "close"
+
+       start_lttng_tracing
+       # generates open, close, execve (at least)
+       eval ${TESTCMD}
+       stop_lttng_tracing
+
+       # ensure open is there.
+       validate_trace_exp "-e syscall_entry_open -e compat_syscall_entry_open" $TRACE_PATH
+       validate_trace_exp "-e syscall_exit_open -e compat_syscall_exit_open" $TRACE_PATH
+
+       # ensure trace only contains those.
+       validate_trace_only_exp "-e syscall_entry_open -e compat_syscall_entry_open -e syscall_exit_open -e compat_syscall_exit_open" $TRACE_PATH
+
+       destroy_lttng_session $SESSION_NAME
+
+       rm -rf $TRACE_PATH
+}
+
+function test_syscall_disable_twice()
+{
+       TRACE_PATH=$(mktemp -d)
+       SESSION_NAME="kernel_syscall_disable_twice"
+
+       create_lttng_session $SESSION_NAME $TRACE_PATH
+
+       lttng_enable_kernel_syscall_ok $SESSION_NAME "open"
+       # First disable will succeed
+       lttng_disable_kernel_syscall_ok $SESSION_NAME "open"
+       # Second disable will fail
+       lttng_disable_kernel_syscall_fail $SESSION_NAME "open"
+
+       destroy_lttng_session $SESSION_NAME
+
+       rm -rf $TRACE_PATH
+}
+
+function test_syscall_disable_all_twice()
+{
+       TRACE_PATH=$(mktemp -d)
+       SESSION_NAME="kernel_syscall_disable_all_twice"
+
+       create_lttng_session $SESSION_NAME $TRACE_PATH
+
+       lttng_enable_kernel_syscall_ok $SESSION_NAME
+       # First disable will succeed
+       lttng_disable_kernel_syscall_ok $SESSION_NAME
+       # Second disable will fail
+       lttng_disable_kernel_syscall_fail $SESSION_NAME
+
+       destroy_lttng_session $SESSION_NAME
+
+       rm -rf $TRACE_PATH
+}
+
+
+function test_syscall_enable_unknown()
+{
+       TRACE_PATH=$(mktemp -d)
+       SESSION_NAME="kernel_syscall_enable_unknown"
+
+       create_lttng_session $SESSION_NAME $TRACE_PATH
+
+       lttng_enable_kernel_syscall_fail $SESSION_NAME "thissyscallcannotexist"
+
+       destroy_lttng_session $SESSION_NAME
+
+       rm -rf $TRACE_PATH
+}
+
+function test_syscall_enable_all_enable_one()
+{
+       TRACE_PATH=$(mktemp -d)
+       SESSION_NAME="kernel_syscall_enable_all_enable_one"
+
+       create_lttng_session $SESSION_NAME $TRACE_PATH
+
+       lttng_enable_kernel_syscall_ok $SESSION_NAME
+       # Enabling an event already enabled fails.
+       lttng_enable_kernel_syscall_fail $SESSION_NAME "open"
+
+       destroy_lttng_session $SESSION_NAME
+
+       rm -rf $TRACE_PATH
+}
+
+function test_syscall_disable_all_disable_one()
+{
+       TRACE_PATH=$(mktemp -d)
+       SESSION_NAME="kernel_syscall_enable_all_enable_one"
+
+       create_lttng_session $SESSION_NAME $TRACE_PATH
+
+       lttng_enable_kernel_syscall_ok $SESSION_NAME
+       lttng_disable_kernel_syscall_ok $SESSION_NAME
+       # Disabling an event already disabled fails.
+       lttng_disable_kernel_syscall_fail $SESSION_NAME "open"
+
+       destroy_lttng_session $SESSION_NAME
+
+       rm -rf $TRACE_PATH
+}
+
+# MUST set TESTDIR before calling those functions
+plan_tests $NUM_TESTS
+
+print_test_banner "$TEST_DESC"
+
+if [ "$(id -u)" == "0" ]; then
+       isroot=1
+else
+       isroot=0
+fi
+
+skip $isroot "Root access is needed. Skipping all tests." $NUM_TESTS ||
+{
+       start_lttng_sessiond
+
+       test_syscall_single
+       test_syscall_two
+       test_syscall_all
+       test_syscall_all_disable_one
+       test_syscall_all_disable_two
+       test_syscall_enable_all_disable_all
+       test_syscall_enable_all_disable_all_enable_all
+       test_syscall_enable_all_disable_all_twice
+       test_syscall_enable_one_disable_one
+       test_syscall_enable_two_disable_two
+       test_syscall_enable_two_disable_one
+       test_syscall_disable_twice
+       test_syscall_disable_all_twice
+       test_syscall_enable_unknown
+       test_syscall_enable_all_enable_one
+       test_syscall_disable_all_disable_one
+
+       stop_lttng_sessiond
+}
index f585cddd13e18d2b2f6c77dfceba3be144bdc1d0..559870f100737b0397f374d2aafa509de132d27e 100644 (file)
@@ -1,5 +1,6 @@
 regression/kernel/test_all_events
 regression/kernel/test_event_basic
+regression/kernel/test_syscall
 regression/tools/live/test_kernel
 regression/tools/live/test_lttng_kernel
 regression/tools/streaming/test_high_throughput_limits
index 117f72f1f91cc4b75dd4fbb485c50e41fc447fc7..2647769f27106087ecf4f72e0c92d7590b652fa5 100644 (file)
@@ -102,6 +102,85 @@ function lttng_enable_kernel_event
        ok $? "Enable kernel event $event_name for session $sess_name"
 }
 
+function lttng_enable_kernel_syscall()
+{
+       local expected_to_fail=$1
+       local sess_name=$2
+       local syscall_name=$3
+       local channel_name=$4
+
+       if [ -z $syscall_name ]; then
+               # Enable all event if no syscall name specified
+               syscall_name="-a"
+       fi
+
+       if [ -z $channel_name ]; then
+               # default channel if none specified
+               chan=""
+       else
+               chan="-c $channel_name"
+       fi
+
+       $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-event --syscall "$syscall_name" $chan -s $sess_name -k >$OUTPUT_DEST
+       ret=$?
+       if [[ $expected_to_fail -eq "1" ]]; then
+               test $ret -ne "0"
+               ok $? "Enable kernel syscall $syscall_name for session $sess_name on channel $channel_name fail as expected"
+       else
+               ok $ret "Enable kernel syscall $syscall_name for session $sess_name on channel $channel_name"
+       fi
+}
+
+function lttng_enable_kernel_syscall_ok()
+{
+       lttng_enable_kernel_syscall 0 ${*}
+}
+
+function lttng_enable_kernel_syscall_fail()
+{
+       lttng_enable_kernel_syscall 1 ${*}
+}
+
+function lttng_disable_kernel_syscall()
+{
+       local expected_to_fail=$1
+       local sess_name=$2
+       local syscall_name=$3
+       local channel_name=$4
+
+       if [ -z $syscall_name ]; then
+               # Enable all event if no syscall name specified
+               syscall_name="-a"
+       fi
+
+       if [ -z $channel_name ]; then
+               # default channel if none specified
+               chan=""
+       else
+               chan="-c $channel_name"
+       fi
+
+       $TESTDIR/../src/bin/lttng/$LTTNG_BIN disable-event --syscall "$syscall_name" $chan -s $sess_name -k >$OUTPUT_DEST
+
+       ret=$?
+       if [[ $expected_to_fail -eq "1" ]]; then
+               test $ret -ne "0"
+               ok $? "Disable kernel syscall $syscall_name for session $sess_name on channel $channel_name fail as expected"
+       else
+               ok $ret "Disable kernel syscall $syscall_name for session $sess_name on channel $channel_name"
+       fi
+}
+
+function lttng_disable_kernel_syscall_ok()
+{
+       lttng_disable_kernel_syscall 0 ${*}
+}
+
+function lttng_disable_kernel_syscall_fail()
+{
+       lttng_disable_kernel_syscall 1 ${*}
+}
+
 function start_lttng_relayd
 {
        local opt=$1
@@ -628,3 +707,63 @@ function validate_trace
        IFS=$OLDIFS
        return $ret
 }
+
+function validate_trace_exp()
+{
+       local event_exp=$1
+       local trace_path=$2
+
+       which $BABELTRACE_BIN >/dev/null
+       skip $? -ne 0 "Babeltrace binary not found. Skipping trace validation"
+
+       traced=$($BABELTRACE_BIN $trace_path 2>/dev/null | grep ${event_exp} | wc -l)
+       if [ "$traced" -ne 0 ]; then
+               pass "Validate trace for expression '${event_exp}', $traced events"
+       else
+               fail "Validate trace for expression '${event_exp}'"
+               diag "Found $traced occurences of '${event_exp}'"
+       fi
+       ret=$?
+       return $ret
+}
+
+function validate_trace_only_exp()
+{
+       local event_exp=$1
+       local trace_path=$2
+
+       which $BABELTRACE_BIN >/dev/null
+       skip $? -ne 0 "Babeltrace binary not found. Skipping trace matches"
+
+       local count=$($BABELTRACE_BIN $trace_path | grep ${event_exp} | wc -l)
+       local total=$($BABELTRACE_BIN $trace_path | wc -l)
+
+       if [ "$count" -ne 0 ] && [ "$total" -eq "$count" ]; then
+               pass "Trace match with $total for expression '${event_exp}"
+       else
+               fail "Trace match"
+               diag "$total syscall event(s) found, only syscalls matching expression '${event_exp}' ($count occurrences) are expected"
+       fi
+       ret=$?
+       return $ret
+}
+
+function validate_trace_empty()
+{
+       local trace_path=$1
+
+       which $BABELTRACE_BIN >/dev/null
+       if [ $? -ne 0 ]; then
+           skip 0 "Babeltrace binary not found. Skipping trace validation"
+       fi
+
+       traced=$($BABELTRACE_BIN $trace_path 2>/dev/null | wc -l)
+       if [ "$traced" -eq 0 ]; then
+               pass "Validate empty trace"
+       else
+               fail "Validate empty trace"
+               diag "Found $traced events in trace"
+       fi
+       ret=$?
+       return $ret
+}
This page took 0.046626 seconds and 4 git commands to generate.