904212f396c0d7ef318a57c241ab468c084b886f
[lttng-tools.git] / tests / regression / tools / notification / test_notification_kernel_buffer_usage
1 #!/bin/bash
2 #
3 # Copyright (C) 2017 Jonathan Rajotte <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 TESTAPP_STATE_PATH=$(mktemp -u "$TMPDIR/application_state.XXXXXXXXXX")
17
18
19 SESSION_NAME="my_session"
20 CHANNEL_NAME="my_channel"
21
22 NUM_TESTS=104
23
24 # shellcheck source=../../../utils/utils.sh
25 source "$TESTDIR/utils/utils.sh"
26
27 function kernel_event_generator_toggle_state
28 {
29 kernel_event_generator_suspended=$((kernel_event_generator_suspended==0))
30 }
31
32 function generate_filter_events
33 {
34 /bin/echo -n "10" > /proc/lttng-test-filter-event 2> /dev/null
35 }
36
37 function kernel_event_generator
38 {
39 command_to_run=$1
40 state_file=$2
41 kernel_event_generator_suspended=0
42 trap kernel_event_generator_toggle_state SIGUSR1
43
44 while (true); do
45 if [[ $kernel_event_generator_suspended -eq "1" ]]; then
46 touch $state_file
47 sleep 0.5
48 else
49 if [[ -f $state_file ]]; then
50 rm $state_file 2> /dev/null
51 fi
52 $command_to_run
53 fi
54 done
55 }
56
57 function test_buffer_usage_notification
58 {
59 local event_name="lttng_test_filter_event"
60 local trace_path
61 local page_size
62 local consumerd_pipe=()
63
64 trace_path=$(mktemp -d)
65 page_size=$(getconf PAGE_SIZE)
66
67 create_lttng_session_notap $SESSION_NAME "$trace_path"
68
69 lttng_enable_kernel_channel_notap $SESSION_NAME $CHANNEL_NAME \
70 --subbuf-size="$page_size"
71 enable_kernel_lttng_event_notap $SESSION_NAME $event_name $CHANNEL_NAME
72
73 kernel_event_generator generate_filter_events "$TESTAPP_STATE_PATH" &
74 APP_PID=$!
75
76 # This is needed since the testpoint create a pipe with the consumer
77 # type suffixed.
78 for f in "$TESTPOINT_BASE_PATH"*; do
79 consumerd_pipe+=("$f")
80 done
81
82 "$CURDIR/notification" 2 LTTNG_DOMAIN_KERNEL $SESSION_NAME $CHANNEL_NAME \
83 $APP_PID $TESTAPP_STATE_PATH ${consumerd_pipe[@]}
84
85 destroy_lttng_session_notap $SESSION_NAME
86
87 kill -9 $APP_PID
88 wait $APP_PID 2> /dev/null
89 }
90
91 if [ "$(id -u)" == "0" ]; then
92
93 validate_lttng_modules_present
94
95
96 modprobe lttng-test
97
98 # Used on sessiond launch.
99 LTTNG_SESSIOND_ENV_VARS="LTTNG_TESTPOINT_ENABLE=1 \
100 CONSUMER_PAUSE_PIPE_PATH=${TESTPOINT_PIPE_PATH} \
101 LD_PRELOAD=${TESTPOINT}"
102 start_lttng_sessiond_notap
103
104 test_buffer_usage_notification
105
106 stop_lttng_sessiond_notap
107 rmmod lttng-test
108
109 rm -rf "${consumerd_pipe[@]}" 2> /dev/null
110 else
111 # Kernel tests are skipped.
112 plan_tests $NUM_TESTS
113 skip 0 "Root access is needed. Skipping all kernel notification tests." $NUM_TESTS
114 fi
115
116 rm -rf "$TMPDIR"
This page took 0.031971 seconds and 3 git commands to generate.