3 # Copyright (C) 2020 Francis Deslauriers <francis.deslauriers@efficios.com>
5 # SPDX-License-Identifier: LGPL-2.1-only
7 TEST_DESC
="Triggers - rate policy notify"
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 NOTIFICATION_CLIENT_BIN
="$CURDIR/../utils/notification-client"
24 function test_rate_policy_every_n
()
26 local SESSION_NAME
="my_triggered_session"
27 local TRIGGER_NAME
="trigger1"
28 local END_TRIGGER_NAME
="end-trigger1"
29 local SYNC_AFTER_NOTIF_REGISTER_PATH
31 SYNC_AFTER_NOTIF_REGISTER_PATH
=$
(mktemp
--tmpdir -u test-notif-register.XXXXXX
)
33 diag
"Every N rate policy"
35 # Add a trigger with a notify action with a policy to fire it every 5
36 # time the condition is met.
37 lttng_add_trigger_ok \
39 --condition event-rule-matches
--type=user
--name="tp:tptest" \
43 # Add a trigger with a notify action for the tp:end event of the test
44 # application. This allow us to "delimit" the reception loop for the
45 # notification client ensuring that all events were hit and passed into
46 # the notification subsystem.
47 lttng_add_trigger_ok \
49 --condition event-rule-matches
--type=user
--name="tp:end" \
52 for i
in $
(seq 1 4); do
53 diag
"Iteration $i of 4"
55 # Hit the trigger condition 4 time and validate that no (0)
56 # notification for that condition was received.
57 $NOTIFICATION_CLIENT_BIN \
58 --trigger $TRIGGER_NAME \
59 --sync-after-notif-register "$SYNC_AFTER_NOTIF_REGISTER_PATH" \
61 --end-trigger "$END_TRIGGER_NAME" &
63 while [ ! -f "${SYNC_AFTER_NOTIF_REGISTER_PATH}" ]; do
67 $GEN_UST_EVENTS_TESTAPP_BIN -i 4 -w $NR_USEC_WAIT --emit-end-event > /dev
/null
2>&1
69 # notification-client will exit once it receives the end-trigger notification.
70 # Validation of the number of received notification is done by the
71 # notification client. Here it validate that it received 0 notifications.
72 wait $notif_client_pid
74 ok $?
"notification client exited successfully"
77 # Hit the condition 1 time and validate that a notification is
79 rm -f "${SYNC_AFTER_NOTIF_REGISTER_PATH}"
80 $NOTIFICATION_CLIENT_BIN \
81 --trigger $TRIGGER_NAME \
82 --sync-after-notif-register "$SYNC_AFTER_NOTIF_REGISTER_PATH" \
84 --end-trigger "$END_TRIGGER_NAME" &
86 while [ ! -f "${SYNC_AFTER_NOTIF_REGISTER_PATH}" ]; do
90 # Artificially produce the desired event-rule condition.
91 $GEN_UST_EVENTS_TESTAPP_BIN -i 1 -w $NR_USEC_WAIT --emit-end-event > /dev
/null
2>&1
93 # notification-client will exit once it receives the end-trigger notification.
94 # Validation of the number of received notification is done by the
95 # notification client. Here it validate that it received 1 notifications.
96 wait $notif_client_pid
98 ok $?
"notification client exited successfully"
100 rm -f "${SYNC_AFTER_NOTIF_REGISTER_PATH}"
104 lttng_remove_trigger_ok
$TRIGGER_NAME
105 lttng_remove_trigger_ok
$END_TRIGGER_NAME
107 rm -f "$SYNC_AFTER_NOTIF_REGISTER_PATH"
110 function test_rate_policy_once_after_n
()
112 local SESSION_NAME
="my_triggered_session"
113 local TRIGGER_NAME
="trigger1"
114 local END_TRIGGER_NAME
="end-trigger1"
115 local SYNC_AFTER_NOTIF_REGISTER_PATH
117 SYNC_AFTER_NOTIF_REGISTER_PATH
=$
(mktemp
--tmpdir -u test-notif-register.XXXXXX
)
119 diag
"Once after N rate policy"
121 # Add a trigger with a notify action with a policy to fire it every 5
122 # time the condition is met.
123 lttng_add_trigger_ok \
125 --condition event-rule-matches
--type=user
--name="tp:tptest" \
127 --rate-policy=once-after
:5
129 # Add a trigger with a notify action for the tp:end event of the test
130 # application. This allow us to "delimit" the reception loop for the
131 # notification client ensuring that all events were hit and passed into
132 # the notification subsystem.
133 lttng_add_trigger_ok \
135 --condition event-rule-matches
--type=user
--name="tp:end" \
139 # Hit the trigger condition 4 time and validate that no (0)
140 # notification for that condition was received.
141 $NOTIFICATION_CLIENT_BIN \
142 --trigger $TRIGGER_NAME \
143 --sync-after-notif-register "$SYNC_AFTER_NOTIF_REGISTER_PATH" \
145 --end-trigger "$END_TRIGGER_NAME" &
147 while [ ! -f "${SYNC_AFTER_NOTIF_REGISTER_PATH}" ]; do
151 # Artificially produce the desired event-rule condition.
152 $GEN_UST_EVENTS_TESTAPP_BIN -i 4 -w $NR_USEC_WAIT --emit-end-event > /dev
/null
2>&1
154 # notification-client will exit once it receives the end-trigger notification.
155 # Validation of the number of received notification is done by the
156 # notification client. Here it validate that it received 0 notifications.
157 wait $notif_client_pid
159 ok $?
"notification client exited successfully"
162 # Hit the condition 1 time and validate that a notification is
164 rm -f "${SYNC_AFTER_NOTIF_REGISTER_PATH}"
165 $NOTIFICATION_CLIENT_BIN \
166 --trigger $TRIGGER_NAME \
167 --sync-after-notif-register "$SYNC_AFTER_NOTIF_REGISTER_PATH" \
169 --end-trigger "$END_TRIGGER_NAME" &
171 while [ ! -f "${SYNC_AFTER_NOTIF_REGISTER_PATH}" ]; do
175 # Artificially produce the desired event-rule condition.
176 $GEN_UST_EVENTS_TESTAPP_BIN -i 1 -w $NR_USEC_WAIT --emit-end-event > /dev
/null
2>&1
178 # notification-client will exit once it receives the end-trigger notification.
179 # Validation of the number of received notification is done by the
180 # notification client. Here it validate that it received 1 notifications.
181 wait $notif_client_pid
183 ok $?
"notification client exited successfully"
186 # Hit the condition N time and validate that no (0) notification is
188 rm -f "${SYNC_AFTER_NOTIF_REGISTER_PATH}"
189 $NOTIFICATION_CLIENT_BIN \
190 --trigger $TRIGGER_NAME \
191 --sync-after-notif-register "$SYNC_AFTER_NOTIF_REGISTER_PATH" \
193 --end-trigger "$END_TRIGGER_NAME" &
195 while [ ! -f "${SYNC_AFTER_NOTIF_REGISTER_PATH}" ]; do
199 # Artificially produce the desired event-rule condition.
200 $GEN_UST_EVENTS_TESTAPP_BIN -i $NR_ITER -w $NR_USEC_WAIT --emit-end-event > /dev
/null
2>&1
202 # notification-client will exit once it receives the end-trigger notification.
203 # Validation of the number of received notification is done by the
204 # notification client. Here it validate that it received 0 notifications.
205 wait $notif_client_pid
207 ok $?
"notification client exited successfully"
210 lttng_remove_trigger_ok
$TRIGGER_NAME
211 lttng_remove_trigger_ok
$END_TRIGGER_NAME
213 rm -f "$SYNC_AFTER_NOTIF_REGISTER_PATH"
216 # MUST set TESTDIR before calling those functions
217 plan_tests
$NUM_TESTS
219 print_test_banner
"$TEST_DESC"
221 start_lttng_sessiond_notap
223 test_rate_policy_every_n
224 test_rate_policy_once_after_n
226 stop_lttng_sessiond_notap