Commit | Line | Data |
---|---|---|
6ffce1f5 JR |
1 | #!/bin/bash |
2 | # | |
3 | # Copyright (C) 2020 Francis Deslauriers <francis.deslauriers@efficios.com> | |
4 | # | |
5 | # SPDX-License-Identifier: LGPL-2.1-only | |
6 | ||
7f4d5b07 | 7 | TEST_DESC="Triggers - rate policy notify" |
6ffce1f5 JR |
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 | NOTIFICATION_CLIENT_BIN="$CURDIR/../utils/notification-client" | |
19 | NUM_TESTS=19 | |
20 | ||
21 | NR_ITER=10 | |
22 | NR_USEC_WAIT=5 | |
23 | ||
7f4d5b07 | 24 | function test_rate_policy_every_n() |
6ffce1f5 JR |
25 | { |
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 | |
30 | ||
7539dcec | 31 | SYNC_AFTER_NOTIF_REGISTER_PATH=$(mktemp --tmpdir -u test-notif-register.XXXXXX) |
6ffce1f5 | 32 | |
7f4d5b07 | 33 | diag "Every N rate policy" |
6ffce1f5 JR |
34 | |
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 \ | |
38 | $TRIGGER_NAME \ | |
64c34630 | 39 | --condition event-rule-matches --domain=user --name="tp:tptest" \ |
6ffce1f5 | 40 | --action notify \ |
bbadb5e0 | 41 | --rate-policy=every:5 |
6ffce1f5 JR |
42 | |
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 \ | |
48 | $END_TRIGGER_NAME \ | |
64c34630 | 49 | --condition event-rule-matches --domain=user --name="tp:end" \ |
6ffce1f5 JR |
50 | --action notify |
51 | ||
52 | for i in $(seq 1 4); do | |
53 | diag "Iteration $i of 4" | |
54 | ## Phase 1 | |
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" \ | |
60 | --count 0 \ | |
61 | --end-trigger "$END_TRIGGER_NAME" & | |
62 | notif_client_pid=$! | |
63 | while [ ! -f "${SYNC_AFTER_NOTIF_REGISTER_PATH}" ]; do | |
64 | sleep 0.5 | |
65 | done | |
66 | ||
67 | $GEN_UST_EVENTS_TESTAPP_BIN -i 4 -w $NR_USEC_WAIT --emit-end-event > /dev/null 2>&1 | |
68 | ||
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 | |
73 | test "$?" -eq "0" | |
74 | ok $? "notification client exited successfully" | |
75 | ||
76 | ## Phase 2 | |
77 | # Hit the condition 1 time and validate that a notification is | |
78 | # received. | |
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" \ | |
83 | --count 1 \ | |
84 | --end-trigger "$END_TRIGGER_NAME" & | |
85 | notif_client_pid=$! | |
86 | while [ ! -f "${SYNC_AFTER_NOTIF_REGISTER_PATH}" ]; do | |
87 | sleep 0.5 | |
88 | done | |
89 | ||
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 | |
92 | ||
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 | |
97 | test "$?" -eq "0" | |
98 | ok $? "notification client exited successfully" | |
99 | ||
100 | rm -f "${SYNC_AFTER_NOTIF_REGISTER_PATH}" | |
101 | done | |
102 | ||
103 | # Tearing down. | |
104 | lttng_remove_trigger_ok $TRIGGER_NAME | |
105 | lttng_remove_trigger_ok $END_TRIGGER_NAME | |
106 | ||
107 | rm -f "$SYNC_AFTER_NOTIF_REGISTER_PATH" | |
108 | } | |
109 | ||
7f4d5b07 | 110 | function test_rate_policy_once_after_n() |
6ffce1f5 JR |
111 | { |
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 | |
116 | ||
7539dcec | 117 | SYNC_AFTER_NOTIF_REGISTER_PATH=$(mktemp --tmpdir -u test-notif-register.XXXXXX) |
6ffce1f5 | 118 | |
7f4d5b07 | 119 | diag "Once after N rate policy" |
6ffce1f5 JR |
120 | |
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 \ | |
124 | $TRIGGER_NAME \ | |
64c34630 | 125 | --condition event-rule-matches --domain=user --name="tp:tptest" \ |
6ffce1f5 | 126 | --action notify \ |
bbadb5e0 | 127 | --rate-policy=once-after:5 |
6ffce1f5 JR |
128 | |
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 \ | |
134 | $END_TRIGGER_NAME \ | |
64c34630 | 135 | --condition event-rule-matches --domain=user --name="tp:end" \ |
6ffce1f5 JR |
136 | --action notify |
137 | ||
138 | ## Phase 1 | |
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" \ | |
144 | --count 0 \ | |
145 | --end-trigger "$END_TRIGGER_NAME" & | |
146 | notif_client_pid=$! | |
147 | while [ ! -f "${SYNC_AFTER_NOTIF_REGISTER_PATH}" ]; do | |
148 | sleep 0.5 | |
149 | done | |
150 | ||
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 | |
153 | ||
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 | |
158 | test "$?" -eq "0" | |
159 | ok $? "notification client exited successfully" | |
160 | ||
161 | ## Phase 2 | |
162 | # Hit the condition 1 time and validate that a notification is | |
163 | # received. | |
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" \ | |
168 | --count 1 \ | |
169 | --end-trigger "$END_TRIGGER_NAME" & | |
170 | notif_client_pid=$! | |
171 | while [ ! -f "${SYNC_AFTER_NOTIF_REGISTER_PATH}" ]; do | |
172 | sleep 0.5 | |
173 | done | |
174 | ||
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 | |
177 | ||
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 | |
182 | test "$?" -eq "0" | |
183 | ok $? "notification client exited successfully" | |
184 | ||
185 | ## Phase 3 | |
186 | # Hit the condition N time and validate that no (0) notification is | |
187 | # received. | |
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" \ | |
192 | --count 0 \ | |
193 | --end-trigger "$END_TRIGGER_NAME" & | |
194 | notif_client_pid=$! | |
195 | while [ ! -f "${SYNC_AFTER_NOTIF_REGISTER_PATH}" ]; do | |
196 | sleep 0.5 | |
197 | done | |
198 | ||
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 | |
201 | ||
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 | |
206 | test "$?" -eq "0" | |
207 | ok $? "notification client exited successfully" | |
208 | ||
209 | # Tearing down. | |
210 | lttng_remove_trigger_ok $TRIGGER_NAME | |
211 | lttng_remove_trigger_ok $END_TRIGGER_NAME | |
212 | ||
213 | rm -f "$SYNC_AFTER_NOTIF_REGISTER_PATH" | |
214 | } | |
215 | ||
216 | # MUST set TESTDIR before calling those functions | |
217 | plan_tests $NUM_TESTS | |
218 | ||
219 | print_test_banner "$TEST_DESC" | |
220 | ||
221 | start_lttng_sessiond_notap | |
222 | ||
7f4d5b07 JR |
223 | test_rate_policy_every_n |
224 | test_rate_policy_once_after_n | |
6ffce1f5 JR |
225 | |
226 | stop_lttng_sessiond_notap |