SoW-2019-0002: Dynamic Snapshot
[lttng-tools.git] / tests / regression / tools / notification / test_notification_kernel_userspace_probe
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 SYSCALL_TESTAPP_NAME="gen-syscall-events"
24 SYSCALL_TESTAPP_BIN="$TESTAPP_PATH/$SYSCALL_TESTAPP_NAME/$SYSCALL_TESTAPP_NAME"
25
26 USERSPACE_PROBE_ELF_TESTAPP_NAME="userspace-probe-elf-binary"
27 USERSPACE_PROBE_ELF_TESTAPP_BIN="$TESTAPP_PATH/$USERSPACE_PROBE_ELF_TESTAPP_NAME/.libs/$USERSPACE_PROBE_ELF_TESTAPP_NAME"
28
29 SESSION_NAME="my_session"
30 CHANNEL_NAME="my_channel"
31
32 TRACE_PATH=$(mktemp -d)
33 PAGE_SIZE=$(getconf PAGE_SIZE)
34
35 DIR=$(readlink -f $TESTDIR)
36 NUM_TESTS=104
37
38 source $TESTDIR/utils/utils.sh
39
40 function kernel_event_generator_toggle_state
41 {
42 kernel_event_generator_suspended=$((kernel_event_generator_suspended==0))
43 }
44
45 function userspace_probe_testapp
46 {
47 $USERSPACE_PROBE_ELF_TESTAPP_BIN
48 }
49
50 function kernel_event_generator
51 {
52 command_to_run=$1
53 state_file=$2
54 kernel_event_generator_suspended=0
55 trap kernel_event_generator_toggle_state SIGUSR1
56
57 while (true); do
58 if [[ $kernel_event_generator_suspended -eq "1" ]]; then
59 touch $state_file
60 sleep 0.5
61 else
62 if [[ -f $state_file ]]; then
63 rm $state_file 2> /dev/null
64 fi
65 $command_to_run
66 fi
67 done
68 }
69
70 function test_kernel_userspace_probe_notification
71 {
72 kernel_event_generator userspace_probe_testapp $TESTAPP_STATE_PATH &
73 APP_PID=$!
74
75 $CURDIR/notification 6 LTTNG_DOMAIN_KERNEL \
76 $APP_PID $TESTAPP_STATE_PATH \
77 $USERSPACE_PROBE_ELF_TESTAPP_BIN "test_function"
78
79 kill -9 $APP_PID
80 wait $APP_PID 2> /dev/null
81 }
82
83 if [ "$(id -u)" == "0" ]; then
84 consumerd_pipe=()
85
86 validate_lttng_modules_present
87
88 # This is needed since the testpoint create a pipe with the consumer
89 # type suffixed.
90 for f in "$TESTPOINT_BASE_PATH"*; do
91 consumerd_pipe+=("$f")
92 done
93
94 modprobe lttng-test
95
96 LTTNG_SESSIOND_ENV_VARS="LTTNG_TESTPOINT_ENABLE=1 \
97 CONSUMER_PAUSE_PIPE_PATH=${TESTPOINT_PIPE_PATH} \
98 LD_PRELOAD=${TESTPOINT}"
99
100 start_lttng_sessiond_notap
101
102 test_kernel_userspace_probe_notification
103
104 stop_lttng_sessiond_notap
105 rmmod lttng-test
106
107 rm -rf ${consumerd_pipe[@]} 2> /dev/null
108 else
109 # Kernel tests are skipped.
110 plan_tests $NUM_TESTS
111 skip 0 "Root access is needed. Skipping all kernel notification tests." $NUM_TESTS
112 fi
113
114 # Just in case cleanup
115 rm -rf $TRACE_PATH
116 rm -rf $TMPDIR
This page took 0.046291 seconds and 5 git commands to generate.