lttng add-trigger: replace domain options with single --domain
[lttng-tools.git] / tests / regression / tools / trigger / start-stop / test_start_stop
CommitLineData
6ba31891
FD
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
6ba31891
FD
25function 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
33function 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
41function 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)
7d59def2 46 local SYNC_AFTER_NOTIF_REGISTER_PATH=$(mktemp -u test-notif-register.XXXXXX)
6ba31891
FD
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.
70c766ac 58 lttng_add_trigger_ok \
6ba31891 59 $TRIGGER_NAME \
64c34630 60 --condition event-rule-matches --domain=user --name=tp:tptest \
6ba31891
FD
61 --action start-session $SESSION_NAME \
62 --action notify
63
64 # Launch notification listener.
65 $NOTIFICATION_CLIENT_BIN \
66 --trigger $TRIGGER_NAME \
7d59def2 67 --sync-after-notif-register "$SYNC_AFTER_NOTIF_REGISTER_PATH" &
6ba31891
FD
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.
70c766ac 86 lttng_remove_trigger_ok $TRIGGER_NAME
6ba31891
FD
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
94function 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)
7d59def2 99 local SYNC_AFTER_NOTIF_REGISTER_PATH=$(mktemp -u test-notif-register.XXXXXX)
6ba31891
FD
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.
70c766ac 112 lttng_add_trigger_ok \
6ba31891 113 $TRIGGER_NAME \
64c34630 114 --condition event-rule-matches --domain=user --name=tp:tptest \
6ba31891
FD
115 --action stop-session $SESSION_NAME \
116 --action notify
117
118 # Launch notification listener.
119 $NOTIFICATION_CLIENT_BIN \
120 --trigger $TRIGGER_NAME \
7d59def2 121 --sync-after-notif-register "$SYNC_AFTER_NOTIF_REGISTER_PATH" &
6ba31891
FD
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.
70c766ac 140 lttng_remove_trigger_ok $TRIGGER_NAME
6ba31891
FD
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
148plan_tests $NUM_TESTS
149
150print_test_banner "$TEST_DESC"
151
152start_lttng_sessiond_notap
153
154test_start_session_action
155test_stop_session_action
156
157stop_lttng_sessiond_notap
This page took 0.041949 seconds and 4 git commands to generate.