SoW-2019-0002: Dynamic Snapshot
[lttng-tools.git] / tests / regression / tools / notification / test_notification_kernel_syscall
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 generate_filter_events
46 {
47 /bin/echo -n "10" > /proc/lttng-test-filter-event 2> /dev/null
48 }
49
50 function generate_syscalls
51 {
52 # Pass /dev/null so to generate the syscall right away.
53 $SYSCALL_TESTAPP_BIN /dev/null
54 }
55
56 function userspace_probe_testapp
57 {
58 $USERSPACE_PROBE_ELF_TESTAPP_BIN
59 }
60
61 function kernel_event_generator
62 {
63 command_to_run=$1
64 state_file=$2
65 kernel_event_generator_suspended=0
66 trap kernel_event_generator_toggle_state SIGUSR1
67
68 while (true); do
69 if [[ $kernel_event_generator_suspended -eq "1" ]]; then
70 touch $state_file
71 sleep 0.5
72 else
73 if [[ -f $state_file ]]; then
74 rm $state_file 2> /dev/null
75 fi
76 $command_to_run
77 fi
78 done
79 }
80
81 function test_kernel_syscall_notification
82 {
83 kernel_event_generator generate_syscalls $TESTAPP_STATE_PATH &
84 APP_PID=$!
85
86 $CURDIR/notification 5 LTTNG_DOMAIN_KERNEL $APP_PID $TESTAPP_STATE_PATH
87
88 kill -9 $APP_PID
89 wait $APP_PID 2> /dev/null
90 }
91
92 if [ "$(id -u)" == "0" ]; then
93 consumerd_pipe=()
94
95 validate_lttng_modules_present
96
97 # This is needed since the testpoint create a pipe with the consumer
98 # type suffixed.
99 for f in "$TESTPOINT_BASE_PATH"*; do
100 consumerd_pipe+=("$f")
101 done
102
103 modprobe lttng-test
104
105 LTTNG_SESSIOND_ENV_VARS="LTTNG_TESTPOINT_ENABLE=1 \
106 CONSUMER_PAUSE_PIPE_PATH=${TESTPOINT_PIPE_PATH} \
107 LD_PRELOAD=${TESTPOINT}"
108
109 start_lttng_sessiond_notap
110
111 test_kernel_syscall_notification
112
113 stop_lttng_sessiond_notap
114 rmmod lttng-test
115
116 rm -rf ${consumerd_pipe[@]} 2> /dev/null
117 else
118 # Kernel tests are skipped.
119 plan_tests $NUM_TESTS
120 skip 0 "Root access is needed. Skipping all kernel notification tests." $NUM_TESTS
121 fi
122
123 # Just in case cleanup
124 rm -rf $TRACE_PATH
125 rm -rf $TMPDIR
This page took 0.046597 seconds and 5 git commands to generate.