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