Tests: add kernel --function basic test case
authorFrancis Deslauriers <francis.deslauriers@efficios.com>
Tue, 16 Mar 2021 20:27:23 +0000 (16:27 -0400)
committerJérémie Galarneau <jeremie.galarneau@efficios.com>
Thu, 18 Mar 2021 15:31:22 +0000 (11:31 -0400)
Signed-off-by: Francis Deslauriers <francis.deslauriers@efficios.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
Change-Id: I584be60bd7325433aa9c30338ceb652c48806ac6

tests/regression/kernel/Makefile.am
tests/regression/kernel/test_kernel_function [new file with mode: 0755]
tests/utils/utils.sh

index 8547efd675b937e72ba5509b3d7bb89ee26266d8..f06f51528fb75b093238caeacb6589d9af34e7b9 100644 (file)
@@ -1,11 +1,18 @@
 # SPDX-License-Identifier: GPL-2.0-only
 
-EXTRA_DIST = test_event_basic test_all_events test_syscall \
-               test_clock_override test_rotation_destroy_flush \
-               test_select_poll_epoll test_lttng_logger \
-               test_userspace_probe test_callstack \
-               test_syscall validate_select_poll_epoll.py \
-               test_ns_contexts test_ns_contexts_change
+EXTRA_DIST = test_all_events test_syscall \
+                                                test_callstack \
+                                                test_clock_override \
+                                                test_event_basic \
+                                                test_kernel_function \
+                                                test_lttng_logger \
+                                                test_ns_contexts \
+                                                test_ns_contexts_change
+                                                test_rotation_destroy_flush \
+                                                test_select_poll_epoll \
+                                                test_syscall \
+                                                test_userspace_probe \
+                                                validate_select_poll_epoll.py
 
 noinst_PROGRAMS = select_poll_epoll
 select_poll_epoll_SOURCES = select_poll_epoll.c
diff --git a/tests/regression/kernel/test_kernel_function b/tests/regression/kernel/test_kernel_function
new file mode 100755 (executable)
index 0000000..3a7471c
--- /dev/null
@@ -0,0 +1,62 @@
+#!/bin/bash
+#
+# Copyright (C) 2021 Francis Deslauriers <francis.deslauriers@efficios.com>
+#
+# SPDX-License-Identifier: GPL-2.0-only
+#
+
+TEST_DESC="Kernel tracer - function event"
+
+CURDIR=$(dirname $0)/
+TESTDIR=$CURDIR/../..
+NUM_TESTS=6
+
+source $TESTDIR/utils/utils.sh
+
+function test_kernel_function_basic()
+{
+       local TRACE_PATH=$(mktemp -d)
+       local SESSION_NAME="kernel_function_basic"
+       local EVENT_NAME="my_event_name"
+       local TARGET_SYMBOL="lttng_test_filter_event_write"
+
+       create_lttng_session_ok $SESSION_NAME $TRACE_PATH
+
+       lttng_enable_kernel_function_event_ok $SESSION_NAME "$TARGET_SYMBOL" "$EVENT_NAME"
+
+       start_lttng_tracing_ok
+
+       echo 1 > /proc/lttng-test-filter-event
+
+       stop_lttng_tracing_ok
+
+       validate_trace "${EVENT_NAME}_entry" $TRACE_PATH
+       validate_trace "${EVENT_NAME}_return" $TRACE_PATH
+
+       destroy_lttng_session_ok $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_notap
+       validate_lttng_modules_present
+       modprobe lttng-test
+
+       test_kernel_function_basic
+
+       modprobe --remove lttng-test
+       stop_lttng_sessiond_notap
+}
index a1e142487024b8a6966321a8aba87e04f4a685eb..8e76ce4976413ec2e50e6eac9e971cf72b7818d5 100644 (file)
@@ -325,6 +325,28 @@ function lttng_disable_kernel_syscall_fail()
        lttng_disable_kernel_syscall 1 "$@"
 }
 
+function lttng_enable_kernel_function_event ()
+{
+       local expected_to_fail="$1"
+       local sess_name="$2"
+       local target="$3"
+       local event_name="$4"
+
+       "$TESTDIR/../src/bin/lttng/$LTTNG_BIN" enable-event --kernel --function="$target" "$event_name" -s "$sess_name" > "$OUTPUT_DEST" 2> "$ERROR_OUTPUT_DEST"
+       ret=$?
+       if [[ $expected_to_fail -eq "1" ]]; then
+               test $ret -ne "0"
+               ok $? "Enable kernel function event for session $sess_name failed as expected"
+       else
+               ok $ret "Enable kernel function event for session $sess_name"
+       fi
+}
+
+function lttng_enable_kernel_function_event_ok ()
+{
+       lttng_enable_kernel_function_event 0 "$@"
+}
+
 function lttng_enable_kernel_userspace_probe_event ()
 {
        local expected_to_fail="$1"
This page took 0.034778 seconds and 4 git commands to generate.