81035b83108cdfe7b5f86dc654d6362e7366c320
[lttng-tools.git] / tests / regression / tools / notification / test_notification_kernel
1 #!/bin/bash
2 #
3 # Copyright (C) 2017 Jonathan Rajotte-Julien <jonathan.rajotte-julien@efficios.com>
4 #
5 # SPDX-License-Identifier: LGPL-2.1-only
6
7 CURDIR=$(dirname $0)/
8 TESTDIR=$CURDIR/../../../
9
10 TMPDIR=$(mktemp -d)
11
12 #This is needed since the testpoint create a pipe with the consumerd type suffixed
13 TESTPOINT_BASE_PATH=$(readlink -f "$TMPDIR/lttng.t_p_n")
14 TESTPOINT_PIPE_PATH=$(mktemp -u "${TESTPOINT_BASE_PATH}.XXXXXX")
15 TESTPOINT=$(readlink -f ${CURDIR}/.libs/libpause_consumer.so)
16
17
18 TESTAPP_PATH="$TESTDIR/utils/testapp"
19 TESTAPP_NAME="gen-ust-events"
20 TESTAPP_BIN="$TESTAPP_PATH/$TESTAPP_NAME/$TESTAPP_NAME"
21 TESTAPP_STATE_PATH=$(mktemp -u "$TMPDIR/application_state.XXXXXXXXXX")
22
23 NR_ITER=-1
24 NR_USEC_WAIT=5
25
26 SESSION_NAME="my_session"
27 CHANNEL_NAME="my_channel"
28
29 TRACE_PATH=$(mktemp -d)
30 PAGE_SIZE=$(getconf PAGE_SIZE)
31
32 DIR=$(readlink -f $TESTDIR)
33 NUM_TESTS=104
34
35 source $TESTDIR/utils/utils.sh
36
37 function kernel_event_generator_toggle_state
38 {
39 kernel_event_generator_suspended=$((kernel_event_generator_suspended==0))
40
41 }
42 function kernel_event_generator
43 {
44 state_file=$1
45 kernel_event_generator_suspended=0
46 trap kernel_event_generator_toggle_state SIGUSR1
47
48 while (true); do
49 if [[ $kernel_event_generator_suspended -eq "1" ]]; then
50 touch $state_file
51 sleep 0.5
52 else
53 if [[ -f $state_file ]]; then
54 rm $state_file 2> /dev/null
55 fi
56 echo -n "1000" > /proc/lttng-test-filter-event 2> /dev/null
57 fi
58 done
59 }
60
61 function kernel_test
62 {
63 local consumerd_pipe=()
64 local event_name="lttng_test_filter_event"
65
66 modprobe lttng-test
67
68 LTTNG_SESSIOND_ENV_VARS="LTTNG_TESTPOINT_ENABLE=1 CONSUMER_PAUSE_PIPE_PATH=${TESTPOINT_PIPE_PATH} LD_PRELOAD=${TESTPOINT}"
69 start_lttng_sessiond_notap
70
71 create_lttng_session_notap $SESSION_NAME $TRACE_PATH
72
73 lttng_enable_kernel_channel_notap $SESSION_NAME $CHANNEL_NAME --subbuf-size=$PAGE_SIZE
74 enable_kernel_lttng_event_notap $SESSION_NAME $event_name $CHANNEL_NAME
75
76 #This is needed since the testpoint create a pipe with the consumer type suffixed
77 for f in "$TESTPOINT_BASE_PATH"*; do
78 consumerd_pipe+=("$f")
79 done
80
81 kernel_event_generator $TESTAPP_STATE_PATH &
82 APP_PID=$!
83
84 $CURDIR/notification LTTNG_DOMAIN_KERNEL $SESSION_NAME $CHANNEL_NAME $APP_PID $TESTAPP_STATE_PATH ${consumerd_pipe[@]}
85
86 destroy_lttng_session_notap $SESSION_NAME
87 stop_lttng_sessiond_notap
88
89 kill -9 $APP_PID
90 wait $APP_PID 2> /dev/null
91
92
93 rmmod lttng-test
94
95 rm -rf ${consumerd_pipe[@]} 2> /dev/null
96 }
97
98 if [ "$(id -u)" == "0" ]; then
99 validate_lttng_modules_present
100 kernel_test
101 else
102 # Kernel tests are skipped.
103 plan_tests $NUM_TESTS
104 skip 0 "Root access is needed. Skipping all kernel notification tests." $NUM_TESTS
105 fi
106
107 # Just in case cleanup
108 rm -rf $TRACE_PATH
109 rm -rf $TMPDIR
This page took 0.048144 seconds and 5 git commands to generate.