tests: invoke full_cleanup from script trap handlers, use modprobe -r
[lttng-tools.git] / tests / regression / tools / notification / test_notification_kernel
CommitLineData
854382b8
JR
1#!/bin/bash
2#
3# Copyright (C) - 2017 Jonathan Rajotte-Julien <jonathan.rajotte-julien@efficios.com>
4#
5# This library is free software; you can redistribute it and/or modify it under
6# the terms of the GNU Lesser General Public License as published by the Free
7# Software Foundation; version 2.1 of the License.
8#
9# This library is distributed in the hope that it will be useful, but WITHOUT
10# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11# FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
12# details.
13#
14# You should have received a copy of the GNU Lesser General Public License
15# along with this library; if not, write to the Free Software Foundation, Inc.,
16# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17
18CURDIR=$(dirname $0)/
19TESTDIR=$CURDIR/../../../
20
345ed219
JR
21TMPDIR=$(mktemp -d)
22
854382b8 23#This is needed since the testpoint create a pipe with the consumerd type suffixed
345ed219 24TESTPOINT_BASE_PATH=$(readlink -f "$TMPDIR/lttng.t_p_n")
854382b8
JR
25TESTPOINT_PIPE_PATH=$(mktemp -u "${TESTPOINT_BASE_PATH}.XXXXXX")
26TESTPOIT_ARGS="CONSUMER_PAUSE_PIPE_PATH=${TESTPOINT_PIPE_PATH} LTTNG_TESTPOINT_ENABLE=1"
27TESTPOINT=$(readlink -f ${CURDIR}/.libs/libpause_consumer.so)
28
29
30TESTAPP_PATH="$TESTDIR/utils/testapp"
31TESTAPP_NAME="gen-ust-events"
32TESTAPP_BIN="$TESTAPP_PATH/$TESTAPP_NAME/$TESTAPP_NAME"
345ed219 33TESTAPP_STATE_PATH=$(mktemp -u "$TMPDIR/application_state.XXXXXXXXXX")
854382b8
JR
34
35NR_ITER=-1
36NR_USEC_WAIT=5
37
38SESSION_NAME="my_session"
39CHANNEL_NAME="my_channel"
40
41TRACE_PATH=$(mktemp -d)
42PAGE_SIZE=$(getconf PAGE_SIZE)
43
44DIR=$(readlink -f $TESTDIR)
45NUM_TESTS=104
46
47source $TESTDIR/utils/utils.sh
48
49function kernel_event_generator_toogle_state
50{
51 kernel_event_generator_suspended=$((kernel_event_generator_suspended==0))
52
53}
54function kernel_event_generator
55{
56 state_file=$1
57 kernel_event_generator_suspended=0
58 trap kernel_event_generator_toogle_state SIGUSR1
3be453c9 59
854382b8
JR
60 while (true); do
61 if [[ $kernel_event_generator_suspended -eq "1" ]]; then
62 touch $state_file
63 sleep 0.5
64 else
65 if [[ -f $state_file ]]; then
66 rm $state_file 2> /dev/null
67 fi
68 echo -n "1000" > /proc/lttng-test-filter-event 2> /dev/null
69 fi
70 done
71}
72
73function kernel_test
74{
75 local consumerd_pipe=()
76 local event_name="lttng_test_filter_event"
77
78 modprobe lttng-test
79
80 LTTNG_SESSIOND_ENV_VARS="LTTNG_TESTPOINT_ENABLE=1 CONSUMER_PAUSE_PIPE_PATH=${TESTPOINT_PIPE_PATH} LD_PRELOAD=${TESTPOINT}"
81 start_lttng_sessiond_notap
82
83 create_lttng_session_notap $SESSION_NAME $TRACE_PATH
84
85 lttng_enable_kernel_channel_notap $SESSION_NAME $CHANNEL_NAME --subbuf-size=$PAGE_SIZE
86 enable_kernel_lttng_event_notap $SESSION_NAME $event_name $CHANNEL_NAME
87
88 #This is needed since the testpoint create a pipe with the consumer type suffixed
89 for f in "$TESTPOINT_BASE_PATH"*; do
90 consumerd_pipe+=("$f")
91 done
92
93 kernel_event_generator $TESTAPP_STATE_PATH &
94 APP_PID=$!
95
96 $CURDIR/notification LTTNG_DOMAIN_KERNEL $SESSION_NAME $CHANNEL_NAME $APP_PID $TESTAPP_STATE_PATH ${consumerd_pipe[@]}
97
98 destroy_lttng_session_notap $SESSION_NAME
99 stop_lttng_sessiond_notap
100
101 kill -9 $APP_PID
102 wait $APP_PID 2> /dev/null
103
104
105 rmmod lttng-test
106
345ed219 107 rm -rf ${consumerd_pipe[@]} 2> /dev/null
854382b8
JR
108}
109
110if [ "$(id -u)" == "0" ]; then
5da3fc85 111 validate_lttng_modules_present
854382b8
JR
112 kernel_test
113else
114 # Kernel tests are skipped.
115 plan_tests $NUM_TESTS
116 skip 0 "Root access is needed. Skipping all kernel notification tests." $NUM_TESTS
117fi
118
119# Just in case cleanup
120rm -rf $TRACE_PATH
345ed219 121rm -rf $TMPDIR
This page took 0.051696 seconds and 5 git commands to generate.