From: Francis Deslauriers Date: Tue, 16 Mar 2021 20:27:23 +0000 (-0400) Subject: Tests: add kernel --function basic test case X-Git-Tag: v2.13.0-rc1~205 X-Git-Url: https://git.lttng.org./?a=commitdiff_plain;h=b6d14cf333b2b06b4a42d97382c6d5dc3f371a3d;p=lttng-tools.git Tests: add kernel --function basic test case Signed-off-by: Francis Deslauriers Signed-off-by: Jérémie Galarneau Change-Id: I584be60bd7325433aa9c30338ceb652c48806ac6 --- diff --git a/tests/regression/kernel/Makefile.am b/tests/regression/kernel/Makefile.am index 8547efd67..f06f51528 100644 --- a/tests/regression/kernel/Makefile.am +++ b/tests/regression/kernel/Makefile.am @@ -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 index 000000000..3a7471c86 --- /dev/null +++ b/tests/regression/kernel/test_kernel_function @@ -0,0 +1,62 @@ +#!/bin/bash +# +# Copyright (C) 2021 Francis Deslauriers +# +# 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 +} diff --git a/tests/utils/utils.sh b/tests/utils/utils.sh index a1e142487..8e76ce497 100644 --- a/tests/utils/utils.sh +++ b/tests/utils/utils.sh @@ -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"