Tests: triggers: `start-session` and `stop-session` actions
[lttng-tools.git] / tests / regression / tools / trigger / start-stop / test_start_stop
1 #!/bin/bash
2 #
3 # Copyright (C) 2020 Francis Deslauriers <francis.deslauriers@efficios.com>
4 #
5 # SPDX-License-Identifier: LGPL-2.1-only
6
7 TEST_DESC="Triggers - Start and stop actions"
8
9 CURDIR=$(dirname "$0")/
10 TESTDIR=${CURDIR}/../../../..
11
12 # shellcheck source=../../../../utils/utils.sh
13 source "$TESTDIR/utils/utils.sh"
14
15 TESTAPP_PATH="$TESTDIR/utils/testapp"
16 GEN_UST_EVENTS_TESTAPP_NAME="gen-ust-events"
17 GEN_UST_EVENTS_TESTAPP_BIN="$TESTAPP_PATH/$GEN_UST_EVENTS_TESTAPP_NAME/$GEN_UST_EVENTS_TESTAPP_NAME"
18 FULL_LTTNG_BIN="$TESTDIR/../src/bin/lttng/$LTTNG_BIN"
19 NOTIFICATION_CLIENT_BIN="$CURDIR/../utils/notification-client"
20 NUM_TESTS=18
21
22 NR_ITER=5
23 NR_USEC_WAIT=5
24
25 function lttng_add_trigger_ust()
26 {
27 local expected_to_fail="$1"
28 local trigger_name="$2"
29 shift 2
30
31 "$FULL_LTTNG_BIN" add-trigger --id "$trigger_name" "$@" 1> /dev/null 2> /dev/null
32 ret=$?
33 if [[ $expected_to_fail -eq "1" ]]; then
34 test "$ret" -ne "0"
35 ok $? "Add trigger $trigger_name failed as expected"
36 else
37 ok $ret "Add trigger $trigger_name"
38 fi
39 }
40
41 function lttng_remove_trigger_ust()
42 {
43 local expected_to_fail="$1"
44 local trigger_name="$2"
45
46 "$FULL_LTTNG_BIN" remove-trigger "$trigger_name" 1> /dev/null 2> /dev/null
47 ret=$?
48 if [[ $expected_to_fail -eq "1" ]]; then
49 test "$ret" -ne "0"
50 ok $? "Remove trigger $trigger_name failed as expected"
51 else
52 ok $ret "Remove trigger $trigger_name"
53 fi
54 }
55
56 function lttng_add_trigger_ust_ok()
57 {
58 lttng_add_trigger_ust 0 "$@"
59 }
60
61 function lttng_remove_trigger_ust_ok()
62 {
63 lttng_remove_trigger_ust 0 "$@"
64 }
65
66 function lttng_session_is_active()
67 {
68 local SESSION_NAME="$1"
69 "$FULL_LTTNG_BIN" list "$SESSION_NAME" | grep "Tracing session" | grep -q "\[active\]"
70
71 ok $ret "Session \"$SESSION_NAME\" is active"
72 }
73
74 function lttng_session_is_inactive()
75 {
76 local SESSION_NAME="$1"
77 "$FULL_LTTNG_BIN" list "$SESSION_NAME" | grep "Tracing session" | grep -q "\[inactive\]"
78
79 ok $ret "Session \"$SESSION_NAME\" is inactive"
80 }
81
82 function test_start_session_action()
83 {
84 local SESSION_NAME="my_triggered_session"
85 local TRIGGER_NAME="trigger1"
86 local TRACE_PATH=$(mktemp -d test-start-action-trace.XXXXXX)
87 local SYNC_AFTER_NOTIF_REGISTER_PATH=$(mktemp test-notif-register.XXXXXX)
88
89 diag "Start session action"
90
91 create_lttng_session_ok $SESSION_NAME "$TRACE_PATH"
92
93 enable_ust_lttng_event_ok $SESSION_NAME "tp:tptest"
94
95 lttng_session_is_inactive $SESSION_NAME
96
97 # Add `start-session` action to an event-rule condition _followed_ by
98 # a `notify` action.
99 lttng_add_trigger_ust_ok \
100 $TRIGGER_NAME \
101 --condition on-event -u "tp:tptest" \
102 --action start-session $SESSION_NAME \
103 --action notify
104
105 # Launch notification listener.
106 $NOTIFICATION_CLIENT_BIN \
107 --trigger $TRIGGER_NAME \
108 --sync-after-notif-register "$SYNC_AFTER_NOTIF_REGISTER_PATH"
109 notif_client_pid=$!
110
111 while [ ! -f "${SYNC_AFTER_NOTIF_REGISTER_PATH}" ]; do
112 sleep 0.5
113 done
114
115 # Artificially produce the desired event-rule condition.
116 $GEN_UST_EVENTS_TESTAPP_BIN -i $NR_ITER -w $NR_USEC_WAIT > /dev/null 2>&1
117
118 # notification-client will exit once it receives a notification.
119 wait $notif_client_pid
120 test "$?" -eq "0"
121 ok $? "notification client exited successfully"
122
123 # Test that the session has started.
124 lttng_session_is_active $SESSION_NAME
125
126 # Tearing down.
127 lttng_remove_trigger_ust_ok $TRIGGER_NAME
128 stop_lttng_tracing_ok $SESSION_NAME
129 destroy_lttng_session_ok $SESSION_NAME
130
131 rm -f "$SYNC_AFTER_NOTIF_REGISTER_PATH"
132 rm -rf "$TRACE_PATH"
133 }
134
135 function test_stop_session_action()
136 {
137 local SESSION_NAME="my_triggered_session"
138 local TRIGGER_NAME="trigger1"
139 local TRACE_PATH=$(mktemp -d test-stop-action-trace.XXXXXX)
140 local SYNC_AFTER_NOTIF_REGISTER_PATH=$(mktemp test-notif-register.XXXXXX)
141
142 diag "Stop session action"
143 create_lttng_session_ok $SESSION_NAME "$TRACE_PATH"
144
145 enable_ust_lttng_event_ok $SESSION_NAME "tp:tptest"
146
147 start_lttng_tracing_ok $SESSION_NAME
148
149 lttng_session_is_active $SESSION_NAME
150
151 # Add `stop-session` action to an event-rule condition _followed_ by
152 # a `notify` action.
153 lttng_add_trigger_ust_ok \
154 $TRIGGER_NAME \
155 --condition on-event -u "tp:tptest" \
156 --action stop-session $SESSION_NAME \
157 --action notify
158
159 # Launch notification listener.
160 $NOTIFICATION_CLIENT_BIN \
161 --trigger $TRIGGER_NAME \
162 --sync-after-notif-register "$SYNC_AFTER_NOTIF_REGISTER_PATH"
163 notif_client_pid=$!
164
165 while [ ! -f "${SYNC_AFTER_NOTIF_REGISTER_PATH}" ]; do
166 sleep 0.5
167 done
168
169 # Artificially produce the desired event-rule condition.
170 $GEN_UST_EVENTS_TESTAPP_BIN -i $NR_ITER -w $NR_USEC_WAIT > /dev/null 2>&1
171
172 # notification-client will exit once it receives a notification.
173 wait $notif_client_pid
174 test "$?" -eq "0"
175 ok $? "notification client exited successfully"
176
177 # Test that the session has been stopped.
178 lttng_session_is_inactive $SESSION_NAME
179
180 # Tearing down.
181 lttng_remove_trigger_ust_ok $TRIGGER_NAME
182 destroy_lttng_session_ok $SESSION_NAME
183
184 rm -f "$SYNC_AFTER_NOTIF_REGISTER_PATH"
185 rm -rf "$TRACE_PATH"
186 }
187
188 # MUST set TESTDIR before calling those functions
189 plan_tests $NUM_TESTS
190
191 print_test_banner "$TEST_DESC"
192
193 start_lttng_sessiond_notap
194
195 test_start_session_action
196 test_stop_session_action
197
198 stop_lttng_sessiond_notap
This page took 0.049616 seconds and 4 git commands to generate.