1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408
|
#!/bin/bash
#
# SPDX-FileCopyrightText: 2020 Francis Deslauriers <francis.deslauriers@efficios.com>
#
# SPDX-License-Identifier: LGPL-2.1-only
CURDIR=$(dirname "$0")/
TESTDIR=$CURDIR/../../../
TEST_TMPDIR=$(mktemp -d -t tmp.test_notifier_discarded_count.XXXXXX)
# Set TMPDIR for further call to mktemp
export TMPDIR="$TEST_TMPDIR"
TESTAPP_PATH="$TESTDIR/utils/testapp"
TESTAPP_NAME="gen-ust-events"
TESTAPP_BIN="$TESTAPP_PATH/$TESTAPP_NAME/$TESTAPP_NAME"
TESTPOINT_BASE_PATH=$(readlink -f "$TEST_TMPDIR/lttng.t_p_n")
TESTPOINT_PIPE_PATH=$(mktemp -u -t "lttng.t_p_n.XXXXXX")
TESTPOINT=$(readlink -f "${CURDIR}/.libs/libpause_sessiond.so")
SH_TAP=1
# shellcheck source=../../../utils/utils.sh
source "$TESTDIR/utils/utils.sh"
# shellcheck source=./util_event_generator.sh
source "$CURDIR/util_event_generator.sh"
FULL_LTTNG_BIN="${TESTDIR}/../src/bin/lttng/${LTTNG_BIN}"
FULL_LTTNG_SESSIOND_BIN="${TESTDIR}/../src/bin/lttng-sessiond/lttng-sessiond"
UST_NUM_TESTS=15
DESTRUCTIVE_TESTS_NUM=12
KERNEL_NUM_TESTS=$((14 + $DESTRUCTIVE_TESTS_NUM))
NUM_TESTS=$(($UST_NUM_TESTS + $KERNEL_NUM_TESTS))
plan_tests $NUM_TESTS
function trigger_get_discarded_notif_number()
{
local trigger_name="$1"
local list_triggers_stdout=$(mktemp -t "list_triggers_stdout.XXXXXX")
"$FULL_LTTNG_BIN" list-triggers > "$list_triggers_stdout"
cat "$list_triggers_stdout" | grep -A7 "$trigger_name" | grep -A2 "event rule matches" | tail -1 | grep --quiet "errors: none"
ret=$?
if [ "$ret" -eq "0" ]; then
notif_nb="0"
else
notif_nb=$(cat "$list_triggers_stdout" | grep -A7 "$trigger_name" | grep "discarded tracer messages" | cut -d' ' -f10)
fi
rm -f "$list_triggers_stdout"
# Printing the value to that the caller can get it back.
echo "$notif_nb"
}
function test_kernel_notifier_discarded_count
{
local sessiond_pipe=()
local trigger_name="my_trigger"
local list_triggers_stdout=$(mktemp -t "list_triggers_stdout.XXXXXX")
# Used on sessiond launch.
LTTNG_SESSIOND_ENV_VARS="LTTNG_TESTPOINT_ENABLE=1 \
NOTIFIER_PAUSE_PIPE_PATH=${TESTPOINT_PIPE_PATH} \
LD_PRELOAD=${TESTPOINT}"
diag "Kernel event notifer error counter"
start_lttng_sessiond_notap
# This is needed since the testpoint creates a pipe with the sessiond
# type suffixed.
for f in "$TESTPOINT_BASE_PATH"*; do
sessiond_pipe+=("$f")
done
lttng_add_trigger_ok "$trigger_name" \
--condition event-rule-matches --type=kernel --name=lttng_test_filter_event \
--action notify
trigger_discarded_nb=$(trigger_get_discarded_notif_number "$trigger_name")
is $trigger_discarded_nb 0 "No discarded tracer notification"
# Stop consumption of notifier tracer notifications.
diag "Pause consumption of tracer messages"
echo -n 1 > $sessiond_pipe
# The notifier ring buffer configuration is currently made of 16 4096
# bytes subbuffers. Each kernel notification is at least 42 bytes long.
# To fill it, we need to generate (16 * 4096)/42 = 1561 notifications.
# That number is a bit larger than what we need since some of the space
# is lost in subbuffer boundaries.
echo -n "2000" > /proc/lttng-test-filter-event
# Confirm that the number of tracer notifications discarded is non-zero.
trigger_discarded_nb=$(trigger_get_discarded_notif_number "$trigger_name")
isnt $trigger_discarded_nb 0 "Discarded tracer notification number non-zero ($trigger_discarded_nb) as expected"
lttng_remove_trigger_ok "$trigger_name"
# Confirm that no notifier is enabled.
list_triggers_line_count=$("$FULL_LTTNG_BIN" list-triggers | wc -l)
is "$list_triggers_line_count" "0" "No \`event-rule-matches\` kernel notifier enabled as expected"
# Enable another notifier and list it to confirm the counter was cleared.
lttng_add_trigger_ok "$trigger_name" \
--condition event-rule-matches --type=kernel --name=lttng_test_filter_event \
--action notify
trigger_discarded_nb=$(trigger_get_discarded_notif_number "$trigger_name")
is $trigger_discarded_nb 0 "No discarded tracer notification"
lttng_remove_trigger_ok "$trigger_name"
stop_lttng_sessiond_notap
unset LTTNG_SESSIOND_ENV_VARS
rm -f "$list_triggers_stdout"
}
function test_kernel_notifier_discarded_count_max_bucket
{
start_lttng_sessiond "" "--event-notifier-error-buffer-size-kernel=3"
diag "Kernel event notifer error counter bucket limit"
for i in $(seq 3); do
lttng_add_trigger_ok "$i" \
--condition event-rule-matches --type=kernel --name=my_event_that_doesnt_need_to_really_exist_$i \
--action notify
done
for i in $(seq 4 5); do
lttng_add_trigger_fail "$i" \
--condition event-rule-matches --type=kernel --name=my_event_that_doesnt_need_to_really_exist_$i \
--action notify
done
stop_lttng_sessiond_notap
}
function test_ust_notifier_discarded_count
{
local sessiond_pipe=()
local trigger_name="my_trigger"
local NR_USEC_WAIT=0
local PIPE_SIZE
local NR_ITER
diag "UST event notifer error counter"
PIPE_SIZE=$(get_pipe_max_size)
# Find the number of events needed to overflow the event notification
# pipe buffer. Each LTTng-UST notification is at least 42 bytes long.
# Double that number to ensure enough events are created to overflow
# the buffer.
NR_ITER=$(( (PIPE_SIZE / 42) * 2 ))
diag "Test application will emit $NR_ITER events"
# Used on sessiond launch.
LTTNG_SESSIOND_ENV_VARS="LTTNG_TESTPOINT_ENABLE=1 \
NOTIFIER_PAUSE_PIPE_PATH=${TESTPOINT_PIPE_PATH} \
LD_PRELOAD=${TESTPOINT}"
start_lttng_sessiond_notap
# This is needed since the testpoint create a pipe with the sessiond
# type suffixed.
for f in "$TESTPOINT_BASE_PATH"*; do
sessiond_pipe+=("$f")
done
lttng_add_trigger_ok "$trigger_name" \
--condition event-rule-matches --type=user --name=tp:tptest \
--action notify
trigger_discarded_nb=$(trigger_get_discarded_notif_number "$trigger_name")
is $trigger_discarded_nb 0 "No discarded tracer notification"
# Stop consumption of notifier tracer notifications.
diag "Pause consumption of tracer messages"
echo -n 1 > $sessiond_pipe
$TESTAPP_BIN -i $NR_ITER -w $NR_USEC_WAIT
ok $? "Generating $NR_ITER tracer notifications"
# Confirm that the number of tracer notifications discarded is non-zero.
trigger_discarded_nb=$(trigger_get_discarded_notif_number "$trigger_name")
isnt $trigger_discarded_nb 0 "Discarded tracer notification number non-zero ($trigger_discarded_nb) as expected"
# Remove the notifier.
lttng_remove_trigger_ok "$trigger_name"
# Confirm that no trigger is enabled.
list_triggers_line_count=$("$FULL_LTTNG_BIN" list-triggers | wc -l)
is "$list_triggers_line_count" "0" "No \`event-rule-matches\` userspace notifier enabled as expected"
# Enable another notifier and list it to confirm the counter was cleared.
lttng_add_trigger_ok "$trigger_name" \
--condition event-rule-matches --type=user --name=tp:tptest \
--action notify
trigger_discarded_nb=$(trigger_get_discarded_notif_number "$trigger_name")
is $trigger_discarded_nb 0 "No discarded tracer notification"
lttng_remove_trigger_ok "$trigger_name"
stop_lttng_sessiond_notap
unset LTTNG_SESSIOND_ENV_VARS
}
function test_ust_notifier_discarded_count_max_bucket
{
start_lttng_sessiond "" "--event-notifier-error-buffer-size-userspace=3"
diag "UST event notifer error counter bucket limit"
for i in $(seq 3); do
lttng_add_trigger_ok "$i" \
--condition event-rule-matches --type=user --name=my_event_that_doesnt_need_to_really_exist_$i \
--action notify
done
for i in $(seq 4 5); do
lttng_add_trigger_fail "$i" \
--condition event-rule-matches --type=user --name=my_event_that_doesnt_need_to_really_exist_$i \
--action notify
done
stop_lttng_sessiond_notap
}
function test_ust_notifier_discarded_count_multi_uid
{
local sessiond_pipe=()
local root_trigger_name="root_trigger"
local user_trigger_name="user_trigger"
local list_triggers_stdout=$(mktemp -t "list_triggers_stdout.XXXXXX")
local NR_USEC_WAIT=0
local PIPE_SIZE
local NR_ITER
local new_user="dummy_lttng_test_user"
diag "UST event notifer error counter multiple UIDs"
# Create a dummy user to run test apps as.
useradd --no-create-home "$new_user"
new_uid=$(id -u "$new_user")
PIPE_SIZE=$(get_pipe_max_size)
# Find the number of events needed to overflow the event notification
# pipe buffer. Each LTTng-UST notification is at least 42 bytes long.
# Double that number to ensure enough events are created to overflow
# the buffer.
NR_ITER=$(( (PIPE_SIZE / 42) * 2 ))
diag "Test applications will emit $NR_ITER events"
# Used on sessiond launch.
LTTNG_SESSIOND_ENV_VARS="LTTNG_TESTPOINT_ENABLE=1 \
NOTIFIER_PAUSE_PIPE_PATH=${TESTPOINT_PIPE_PATH} \
LD_PRELOAD=${TESTPOINT}"
start_lttng_sessiond_notap
# This is needed since the testpoint create a pipe with the sessiond
# type suffixed.
for f in "$TESTPOINT_BASE_PATH"*; do
sessiond_pipe+=("$f")
done
lttng_add_trigger_ok "$root_trigger_name" \
--condition event-rule-matches --type=user --name tp:tptest \
--action notify
lttng_add_trigger_ok "$user_trigger_name" --owner-uid "$new_uid" \
--condition event-rule-matches --type=user --name tp:tptest \
--action notify
# Stop consumption of notifier tracer notifications.
echo -n 1 > $sessiond_pipe
$TESTAPP_BIN -i $NR_ITER -w $NR_USEC_WAIT
ok $? "Generating $NR_ITER tracer notifications as UID: $(id -u)"
su "$new_user" -c "$TESTAPP_BIN -i $NR_ITER -w $NR_USEC_WAIT"
ok $? "Generating $NR_ITER tracer notifications as UID: $new_uid"
root_trigger_discarded_nb=$(trigger_get_discarded_notif_number "$root_trigger_name")
user_trigger_discarded_nb=$(trigger_get_discarded_notif_number "$user_trigger_name")
isnt $root_trigger_discarded_nb 0 \
"Root trigger discarded notifications number ($root_trigger_discarded_nb) is non-zero"
isnt $user_trigger_discarded_nb 0 \
"User trigger discarded notifications number ($user_trigger_discarded_nb) is non-zero"
lttng_remove_trigger_ok "$root_trigger_name"
lttng_remove_trigger_ok "$user_trigger_name" --owner-uid "$new_uid"
stop_lttng_sessiond_notap
unset LTTNG_SESSIOND_ENV_VARS
userdel "$new_user"
rm -f "$list_triggers_stdout"
}
function test_ust_notifier_discarded_regardless_trigger_owner
{
local sessiond_pipe=()
local root_trigger_name="root_trigger"
local user_trigger_name="user_trigger"
local list_triggers_stdout=$(mktemp -t "list_triggers_stdout.XXXXXX")
local NR_USEC_WAIT=0
local PIPE_SIZE
local NR_ITER
local new_user="dummy_lttng_test_user"
PIPE_SIZE=$(get_pipe_max_size)
# Find the number of events needed to overflow the event notification
# pipe buffer. Each LTTng-UST notification is at least 42 bytes long.
# Double that number to ensure enough events are created to overflow
# the buffer.
NR_ITER=$(( (PIPE_SIZE / 42) * 2 ))
diag "Test applications will emit $NR_ITER events"
diag "UST event notifer error counter persists when a root trigger is present"
# Create a dummy user to run test apps as.
useradd --no-create-home "$new_user"
new_uid=$(id -u "$new_user")
# Used on sessiond launch.
LTTNG_SESSIOND_ENV_VARS="LTTNG_TESTPOINT_ENABLE=1 \
NOTIFIER_PAUSE_PIPE_PATH=${TESTPOINT_PIPE_PATH} \
LD_PRELOAD=${TESTPOINT}"
start_lttng_sessiond_notap
# This is needed since the testpoint create a pipe with the sessiond
# type suffixed.
for f in "$TESTPOINT_BASE_PATH"*; do
sessiond_pipe+=("$f")
done
lttng_add_trigger_ok "$root_trigger_name" \
--condition event-rule-matches --type=user --name tp:tptest \
--action notify
# Stop consumption of notifier tracer notifications.
echo -n 1 > $sessiond_pipe
su "$new_user" -c "$TESTAPP_BIN -i $NR_ITER -w $NR_USEC_WAIT"
ok $? "Generating $NR_ITER tracer notifications as UID: $new_uid"
root_trigger_discarded_nb=$(trigger_get_discarded_notif_number "$root_trigger_name")
isnt $root_trigger_discarded_nb 0 \
"Root trigger discarded notifications number ($root_trigger_discarded_nb) is non-zero"
lttng_remove_trigger_ok "$root_trigger_name"
stop_lttng_sessiond_notap
unset LTTNG_SESSIOND_ENV_VARS
userdel "$new_user"
rm -f "$list_triggers_stdout"
}
test_ust_notifier_discarded_count
test_ust_notifier_discarded_count_max_bucket
check_skip_kernel_test "$KERNEL_NUM_TESTS" "Skipping kernel notification tests." ||
{
validate_lttng_modules_present
modprobe lttng-test
test_kernel_notifier_discarded_count
test_kernel_notifier_discarded_count_max_bucket
if destructive_tests_enabled ; then
# Those tests add a new user on the system. Since it's a quite
# intrusive change to the system, we decide to only run it when
# the user knows what they are doing.
test_ust_notifier_discarded_count_multi_uid
test_ust_notifier_discarded_regardless_trigger_owner
else
skip 0 "You need to set the LTTNG_ENABLE_DESTRUCTIVE_TESTS environment variable to \"will-break-my-system\" to run this test" $DESTRUCTIVE_TESTS_NUM
fi
modprobe --remove lttng-test
rm -rf "${sessiond_pipe[@]}" 2> /dev/null
}
rm -rf "$TEST_TMPDIR"
|