Tests: Cleanup: add `lttng_{add, remove}_trigger_ok()` bash functions
[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_session_is_active()
26 {
27 local SESSION_NAME="$1"
28 "$FULL_LTTNG_BIN" list "$SESSION_NAME" | grep "Tracing session" | grep -q "\[active\]"
29
30 ok $ret "Session \"$SESSION_NAME\" is active"
31 }
32
33 function lttng_session_is_inactive()
34 {
35 local SESSION_NAME="$1"
36 "$FULL_LTTNG_BIN" list "$SESSION_NAME" | grep "Tracing session" | grep -q "\[inactive\]"
37
38 ok $ret "Session \"$SESSION_NAME\" is inactive"
39 }
40
41 function test_start_session_action()
42 {
43 local SESSION_NAME="my_triggered_session"
44 local TRIGGER_NAME="trigger1"
45 local TRACE_PATH=$(mktemp -d test-start-action-trace.XXXXXX)
46 local SYNC_AFTER_NOTIF_REGISTER_PATH=$(mktemp test-notif-register.XXXXXX)
47
48 diag "Start session action"
49
50 create_lttng_session_ok $SESSION_NAME "$TRACE_PATH"
51
52 enable_ust_lttng_event_ok $SESSION_NAME "tp:tptest"
53
54 lttng_session_is_inactive $SESSION_NAME
55
56 # Add `start-session` action to an event-rule condition _followed_ by
57 # a `notify` action.
58 lttng_add_trigger_ok \
59 $TRIGGER_NAME \
60 --condition on-event -u "tp:tptest" \
61 --action start-session $SESSION_NAME \
62 --action notify
63
64 # Launch notification listener.
65 $NOTIFICATION_CLIENT_BIN \
66 --trigger $TRIGGER_NAME \
67 --sync-after-notif-register "$SYNC_AFTER_NOTIF_REGISTER_PATH"
68 notif_client_pid=$!
69
70 while [ ! -f "${SYNC_AFTER_NOTIF_REGISTER_PATH}" ]; do
71 sleep 0.5
72 done
73
74 # Artificially produce the desired event-rule condition.
75 $GEN_UST_EVENTS_TESTAPP_BIN -i $NR_ITER -w $NR_USEC_WAIT > /dev/null 2>&1
76
77 # notification-client will exit once it receives a notification.
78 wait $notif_client_pid
79 test "$?" -eq "0"
80 ok $? "notification client exited successfully"
81
82 # Test that the session has started.
83 lttng_session_is_active $SESSION_NAME
84
85 # Tearing down.
86 lttng_remove_trigger_ok $TRIGGER_NAME
87 stop_lttng_tracing_ok $SESSION_NAME
88 destroy_lttng_session_ok $SESSION_NAME
89
90 rm -f "$SYNC_AFTER_NOTIF_REGISTER_PATH"
91 rm -rf "$TRACE_PATH"
92 }
93
94 function test_stop_session_action()
95 {
96 local SESSION_NAME="my_triggered_session"
97 local TRIGGER_NAME="trigger1"
98 local TRACE_PATH=$(mktemp -d test-stop-action-trace.XXXXXX)
99 local SYNC_AFTER_NOTIF_REGISTER_PATH=$(mktemp test-notif-register.XXXXXX)
100
101 diag "Stop session action"
102 create_lttng_session_ok $SESSION_NAME "$TRACE_PATH"
103
104 enable_ust_lttng_event_ok $SESSION_NAME "tp:tptest"
105
106 start_lttng_tracing_ok $SESSION_NAME
107
108 lttng_session_is_active $SESSION_NAME
109
110 # Add `stop-session` action to an event-rule condition _followed_ by
111 # a `notify` action.
112 lttng_add_trigger_ok \
113 $TRIGGER_NAME \
114 --condition on-event -u "tp:tptest" \
115 --action stop-session $SESSION_NAME \
116 --action notify
117
118 # Launch notification listener.
119 $NOTIFICATION_CLIENT_BIN \
120 --trigger $TRIGGER_NAME \
121 --sync-after-notif-register "$SYNC_AFTER_NOTIF_REGISTER_PATH"
122 notif_client_pid=$!
123
124 while [ ! -f "${SYNC_AFTER_NOTIF_REGISTER_PATH}" ]; do
125 sleep 0.5
126 done
127
128 # Artificially produce the desired event-rule condition.
129 $GEN_UST_EVENTS_TESTAPP_BIN -i $NR_ITER -w $NR_USEC_WAIT > /dev/null 2>&1
130
131 # notification-client will exit once it receives a notification.
132 wait $notif_client_pid
133 test "$?" -eq "0"
134 ok $? "notification client exited successfully"
135
136 # Test that the session has been stopped.
137 lttng_session_is_inactive $SESSION_NAME
138
139 # Tearing down.
140 lttng_remove_trigger_ok $TRIGGER_NAME
141 destroy_lttng_session_ok $SESSION_NAME
142
143 rm -f "$SYNC_AFTER_NOTIF_REGISTER_PATH"
144 rm -rf "$TRACE_PATH"
145 }
146
147 # MUST set TESTDIR before calling those functions
148 plan_tests $NUM_TESTS
149
150 print_test_banner "$TEST_DESC"
151
152 start_lttng_sessiond_notap
153
154 test_start_session_action
155 test_stop_session_action
156
157 stop_lttng_sessiond_notap
This page took 0.036516 seconds and 6 git commands to generate.