3 # Copyright (C) 2020 Francis Deslauriers <francis.deslauriers@efficios.com>
5 # SPDX-License-Identifier: LGPL-2.1-only
7 TEST_DESC
="Triggers - Start and stop actions"
9 CURDIR
=$
(dirname "$0")/
10 TESTDIR
=${CURDIR}/..
/..
/..
/..
12 # shellcheck source=../../../../utils/utils.sh
13 source "$TESTDIR/utils/utils.sh"
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"
25 function lttng_session_is_active
()
27 local SESSION_NAME
="$1"
28 "$FULL_LTTNG_BIN" list
"$SESSION_NAME" |
grep "Tracing session" |
grep -q "\[active\]"
30 ok
$ret "Session \"$SESSION_NAME\" is active"
33 function lttng_session_is_inactive
()
35 local SESSION_NAME
="$1"
36 "$FULL_LTTNG_BIN" list
"$SESSION_NAME" |
grep "Tracing session" |
grep -q "\[inactive\]"
38 ok
$ret "Session \"$SESSION_NAME\" is inactive"
41 function test_start_session_action
()
43 local SESSION_NAME
="my_triggered_session"
44 local TRIGGER_NAME
="trigger1"
45 local TRACE_PATH
=$
(mktemp
--tmpdir -d test-start-action-trace.XXXXXX
)
46 local SYNC_AFTER_NOTIF_REGISTER_PATH
=$
(mktemp
--tmpdir -u test-notif-register.XXXXXX
)
48 diag
"Start session action"
50 create_lttng_session_ok
$SESSION_NAME "$TRACE_PATH"
52 enable_ust_lttng_event_ok
$SESSION_NAME "tp:tptest"
54 lttng_session_is_inactive
$SESSION_NAME
56 # Add `start-session` action to an event-rule condition _followed_ by
58 lttng_add_trigger_ok \
60 --condition event-rule-matches
--type=user
--name=tp
:tptest \
61 --action start-session
$SESSION_NAME \
64 # Launch notification listener.
65 $NOTIFICATION_CLIENT_BIN \
66 --trigger $TRIGGER_NAME \
67 --sync-after-notif-register "$SYNC_AFTER_NOTIF_REGISTER_PATH" &
70 while [ ! -f "${SYNC_AFTER_NOTIF_REGISTER_PATH}" ]; do
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
77 # notification-client will exit once it receives a notification.
78 wait $notif_client_pid
80 ok $?
"notification client exited successfully"
82 # Test that the session has started.
83 lttng_session_is_active
$SESSION_NAME
86 lttng_remove_trigger_ok
$TRIGGER_NAME
87 stop_lttng_tracing_ok
$SESSION_NAME
88 destroy_lttng_session_ok
$SESSION_NAME
90 rm -f "$SYNC_AFTER_NOTIF_REGISTER_PATH"
94 function test_stop_session_action
()
96 local SESSION_NAME
="my_triggered_session"
97 local TRIGGER_NAME
="trigger1"
98 local TRACE_PATH
=$
(mktemp
--tmpdir -d test-stop-action-trace.XXXXXX
)
99 local SYNC_AFTER_NOTIF_REGISTER_PATH
=$
(mktemp
--tmpdir -u test-notif-register.XXXXXX
)
101 diag
"Stop session action"
102 create_lttng_session_ok
$SESSION_NAME "$TRACE_PATH"
104 enable_ust_lttng_event_ok
$SESSION_NAME "tp:tptest"
106 start_lttng_tracing_ok
$SESSION_NAME
108 lttng_session_is_active
$SESSION_NAME
110 # Add `stop-session` action to an event-rule condition _followed_ by
112 lttng_add_trigger_ok \
114 --condition event-rule-matches
--type=user
--name=tp
:tptest \
115 --action stop-session
$SESSION_NAME \
118 # Launch notification listener.
119 $NOTIFICATION_CLIENT_BIN \
120 --trigger $TRIGGER_NAME \
121 --sync-after-notif-register "$SYNC_AFTER_NOTIF_REGISTER_PATH" &
124 while [ ! -f "${SYNC_AFTER_NOTIF_REGISTER_PATH}" ]; do
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
131 # notification-client will exit once it receives a notification.
132 wait $notif_client_pid
134 ok $?
"notification client exited successfully"
136 # Test that the session has been stopped.
137 lttng_session_is_inactive
$SESSION_NAME
140 lttng_remove_trigger_ok
$TRIGGER_NAME
141 destroy_lttng_session_ok
$SESSION_NAME
143 rm -f "$SYNC_AFTER_NOTIF_REGISTER_PATH"
147 # MUST set TESTDIR before calling those functions
148 plan_tests
$NUM_TESTS
150 print_test_banner
"$TEST_DESC"
152 start_lttng_sessiond_notap
154 test_start_session_action
155 test_stop_session_action
157 stop_lttng_sessiond_notap