Tests: fix: log level rule: leak of rule after test
[lttng-tools.git] / tests / regression / tools / trigger / start-stop / test_start_stop
... / ...
CommitLineData
1#!/bin/bash
2#
3# Copyright (C) 2020 Francis Deslauriers <francis.deslauriers@efficios.com>
4#
5# SPDX-License-Identifier: LGPL-2.1-only
6
7TEST_DESC="Triggers - Start and stop actions"
8
9CURDIR=$(dirname "$0")/
10TESTDIR=${CURDIR}/../../../..
11
12# shellcheck source=../../../../utils/utils.sh
13source "$TESTDIR/utils/utils.sh"
14
15TESTAPP_PATH="$TESTDIR/utils/testapp"
16GEN_UST_EVENTS_TESTAPP_NAME="gen-ust-events"
17GEN_UST_EVENTS_TESTAPP_BIN="$TESTAPP_PATH/$GEN_UST_EVENTS_TESTAPP_NAME/$GEN_UST_EVENTS_TESTAPP_NAME"
18FULL_LTTNG_BIN="$TESTDIR/../src/bin/lttng/$LTTNG_BIN"
19NOTIFICATION_CLIENT_BIN="$CURDIR/../utils/notification-client"
20NUM_TESTS=18
21
22NR_ITER=5
23NR_USEC_WAIT=5
24
25function 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
41function 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
56function lttng_add_trigger_ust_ok()
57{
58 lttng_add_trigger_ust 0 "$@"
59}
60
61function lttng_remove_trigger_ust_ok()
62{
63 lttng_remove_trigger_ust 0 "$@"
64}
65
66function 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
74function 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
82function 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
135function 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
189plan_tests $NUM_TESTS
190
191print_test_banner "$TEST_DESC"
192
193start_lttng_sessiond_notap
194
195test_start_session_action
196test_stop_session_action
197
198stop_lttng_sessiond_notap
This page took 0.025166 seconds and 4 git commands to generate.