| 1 | #!/bin/bash |
| 2 | # |
| 3 | # Copyright (C) 2020 Francis Deslauriers <francis.deslauriers@efficios.com> |
| 4 | # |
| 5 | # SPDX-License-Identifier: LGPL-2.1-only |
| 6 | |
| 7 | CURDIR=$(dirname "$0")/ |
| 8 | TESTDIR=$CURDIR/../../../ |
| 9 | |
| 10 | TMPDIR=$(mktemp -d) |
| 11 | |
| 12 | TESTAPP_PATH="$TESTDIR/utils/testapp" |
| 13 | TESTAPP_NAME="gen-ust-events" |
| 14 | TESTAPP_BIN="$TESTAPP_PATH/$TESTAPP_NAME/$TESTAPP_NAME" |
| 15 | |
| 16 | TESTPOINT_BASE_PATH=$(readlink -f "$TMPDIR/lttng.t_p_n") |
| 17 | TESTPOINT_PIPE_PATH=$(mktemp -u "${TESTPOINT_BASE_PATH}.XXXXXX") |
| 18 | TESTPOINT=$(readlink -f "${CURDIR}/.libs/libpause_sessiond.so") |
| 19 | |
| 20 | SH_TAP=1 |
| 21 | |
| 22 | # shellcheck source=../../../utils/utils.sh |
| 23 | source "$TESTDIR/utils/utils.sh" |
| 24 | # shellcheck source=./util_event_generator.sh |
| 25 | source "$CURDIR/util_event_generator.sh" |
| 26 | |
| 27 | FULL_LTTNG_BIN="${TESTDIR}/../src/bin/lttng/${LTTNG_BIN}" |
| 28 | FULL_LTTNG_SESSIOND_BIN="${TESTDIR}/../src/bin/lttng-sessiond/lttng-sessiond" |
| 29 | |
| 30 | UST_NUM_TESTS=16 |
| 31 | KERNEL_NUM_TESTS=15 |
| 32 | NUM_TESTS=$(($UST_NUM_TESTS + $KERNEL_NUM_TESTS)) |
| 33 | |
| 34 | plan_tests $NUM_TESTS |
| 35 | |
| 36 | function test_kernel_notifier_discarded_count |
| 37 | { |
| 38 | local sessiond_pipe=() |
| 39 | local trigger_name="my_trigger" |
| 40 | local list_triggers_stdout=$(mktemp -t list_triggers_stdout.XXXXXX) |
| 41 | |
| 42 | # Used on sessiond launch. |
| 43 | LTTNG_SESSIOND_ENV_VARS="LTTNG_TESTPOINT_ENABLE=1 \ |
| 44 | NOTIFIER_PAUSE_PIPE_PATH=${TESTPOINT_PIPE_PATH} \ |
| 45 | LD_PRELOAD=${TESTPOINT}" |
| 46 | |
| 47 | diag "Kernel event notifer error counter" |
| 48 | |
| 49 | start_lttng_sessiond_notap |
| 50 | |
| 51 | # This is needed since the testpoint creates a pipe with the sessiond |
| 52 | # type suffixed. |
| 53 | for f in "$TESTPOINT_BASE_PATH"*; do |
| 54 | sessiond_pipe+=("$f") |
| 55 | done |
| 56 | |
| 57 | lttng_add_trigger_ok "$trigger_name" \ |
| 58 | --condition on-event --kernel lttng_test_filter_event \ |
| 59 | --action notify |
| 60 | |
| 61 | "$FULL_LTTNG_BIN" list-triggers > "$list_triggers_stdout" |
| 62 | |
| 63 | # Confirm that the discarded notification line is present. |
| 64 | cat "$list_triggers_stdout" | grep --quiet "tracer notifications discarded: 0" |
| 65 | ok $? "No discarded tracer notification" |
| 66 | |
| 67 | # Stop consumption of notifier tracer notifications. |
| 68 | echo -n 1 > $sessiond_pipe |
| 69 | |
| 70 | # The notifier ring buffer configuration is currently made of 16 4096 |
| 71 | # bytes subbuffers. Each kernel notification is at least 42 bytes long. |
| 72 | # To fill it, we need to generate (16 * 4096)/42 = 1561 notifications. |
| 73 | # That number is a bit larger than what we need since some of the space |
| 74 | # is lost in subbuffer boundaries. |
| 75 | echo -n "200000" > /proc/lttng-test-filter-event |
| 76 | |
| 77 | "$FULL_LTTNG_BIN" list-triggers > "$list_triggers_stdout" |
| 78 | |
| 79 | # Confirm that the discarded notification line is present. To avoid |
| 80 | # false positives. |
| 81 | cat "$list_triggers_stdout" | grep --quiet "tracer notifications discarded" |
| 82 | ok $? "Tracer notification discarded line printed" |
| 83 | |
| 84 | # Confirm that the number of tracer notifications discarded is not zero. |
| 85 | cat "$list_triggers_stdout" | grep --quiet "tracer notifications discarded: 0" |
| 86 | isnt $? 0 "Discarded tracer notification number non-zero as expected" |
| 87 | |
| 88 | lttng_remove_trigger_ok "$trigger_name" |
| 89 | |
| 90 | # Confirm that no notifier is enabled. |
| 91 | list_triggers_line_count=$("$FULL_LTTNG_BIN" list-triggers | wc -l) |
| 92 | is "$list_triggers_line_count" "0" "No \`on-event\` kernel notifier enabled as expected" |
| 93 | |
| 94 | # Enable another notifier and list it to confirm the counter was cleared. |
| 95 | lttng_add_trigger_ok "$trigger_name" \ |
| 96 | --condition on-event --kernel lttng_test_filter_event \ |
| 97 | --action notify |
| 98 | |
| 99 | # Confirm that the discarded notification line is present. |
| 100 | "$FULL_LTTNG_BIN" list-triggers > "$list_triggers_stdout" |
| 101 | cat "$list_triggers_stdout" | grep --quiet "tracer notifications discarded: 0" |
| 102 | ok $? "No discarded tracer notification" |
| 103 | |
| 104 | lttng_remove_trigger_ok "$trigger_name" |
| 105 | |
| 106 | stop_lttng_sessiond_notap |
| 107 | |
| 108 | unset LTTNG_SESSIOND_ENV_VARS |
| 109 | |
| 110 | rm -f "$list_triggers_stdout" |
| 111 | } |
| 112 | |
| 113 | function test_kernel_notifier_discarded_count_max_bucket |
| 114 | { |
| 115 | start_lttng_sessiond "" "--event-notifier-error-number-of-bucket=3" |
| 116 | |
| 117 | diag "Kernel event notifer error counter bucket limit" |
| 118 | for i in $(seq 3); do |
| 119 | lttng_add_trigger_ok "$i" \ |
| 120 | --condition on-event --kernel my_event_that_doesnt_need_to_really_exist_$i \ |
| 121 | --action notify |
| 122 | done |
| 123 | |
| 124 | for i in $(seq 4 5); do |
| 125 | lttng_add_trigger_fail "$i" \ |
| 126 | --condition on-event --kernel my_event_that_doesnt_need_to_really_exist_$i \ |
| 127 | --action notify |
| 128 | done |
| 129 | |
| 130 | stop_lttng_sessiond_notap |
| 131 | } |
| 132 | |
| 133 | function test_ust_notifier_discarded_count |
| 134 | { |
| 135 | local sessiond_pipe=() |
| 136 | local trigger_name="my_trigger" |
| 137 | local list_triggers_stdout=$(mktemp -t list_triggers_stdout.XXXXXX) |
| 138 | local NR_USEC_WAIT=0 |
| 139 | local PIPE_SIZE |
| 140 | local NR_ITER |
| 141 | |
| 142 | diag "UST event notifer error counter" |
| 143 | |
| 144 | PIPE_SIZE=$("$CURDIR"/default_pipe_size_getter) |
| 145 | if [ $? -ne 0 ]; then |
| 146 | BAIL_OUT "Failed to get system default pipe size" |
| 147 | else |
| 148 | diag "Default system pipe size: $PIPE_SIZE bytes" |
| 149 | fi |
| 150 | |
| 151 | # Find the number of events needed to overflow the event notification |
| 152 | # pipe buffer. Each LTTng-UST notification is at least 42 bytes long. |
| 153 | # Double that number to ensure enough events are created to overflow |
| 154 | # the buffer. |
| 155 | NR_ITER=$(( (PIPE_SIZE / 42) * 2 )) |
| 156 | diag "Test application will emit $NR_ITER events" |
| 157 | |
| 158 | # Used on sessiond launch. |
| 159 | LTTNG_SESSIOND_ENV_VARS="LTTNG_TESTPOINT_ENABLE=1 \ |
| 160 | NOTIFIER_PAUSE_PIPE_PATH=${TESTPOINT_PIPE_PATH} \ |
| 161 | LD_PRELOAD=${TESTPOINT}" |
| 162 | |
| 163 | start_lttng_sessiond_notap |
| 164 | |
| 165 | # This is needed since the testpoint create a pipe with the sessiond |
| 166 | # type suffixed. |
| 167 | for f in "$TESTPOINT_BASE_PATH"*; do |
| 168 | sessiond_pipe+=("$f") |
| 169 | done |
| 170 | |
| 171 | lttng_add_trigger_ok "$trigger_name" \ |
| 172 | --condition on-event --userspace tp:tptest \ |
| 173 | --action notify |
| 174 | |
| 175 | "$FULL_LTTNG_BIN" list-triggers > "$list_triggers_stdout" |
| 176 | |
| 177 | # Confirm that the discarded notification line is present. |
| 178 | cat "$list_triggers_stdout" | grep --quiet "tracer notifications discarded: 0" |
| 179 | ok $? "No discarded tracer notification" |
| 180 | |
| 181 | # Stop consumption of notifier tracer notifications. |
| 182 | echo -n 1 > $sessiond_pipe |
| 183 | |
| 184 | $TESTAPP_BIN -i $NR_ITER -w $NR_USEC_WAIT |
| 185 | ok $? "Generating $NR_ITER tracer notifications" |
| 186 | |
| 187 | "$FULL_LTTNG_BIN" list-triggers > "$list_triggers_stdout" |
| 188 | |
| 189 | # Confirm that the discarded notification line is present. To avoid |
| 190 | # false positive. |
| 191 | cat "$list_triggers_stdout" | grep --quiet "tracer notifications discarded" |
| 192 | ok $? "Tracer notification discarded line printed" |
| 193 | |
| 194 | # Confirm that the number of tracer notifications discarded is not zero. |
| 195 | cat "$list_triggers_stdout" | grep --quiet "tracer notifications discarded: 0" |
| 196 | isnt $? 0 "Discarded tracer notification number non-zero as expected" |
| 197 | |
| 198 | # Remove the notifier. |
| 199 | lttng_remove_trigger_ok "$trigger_name" |
| 200 | |
| 201 | # Confirm that no notifier is enabled. |
| 202 | list_triggers_line_count=$("$FULL_LTTNG_BIN" list-triggers | wc -l) |
| 203 | is "$list_triggers_line_count" "0" "No \`on-event\` userspace notifier enabled as expected" |
| 204 | |
| 205 | # Enable another notifier and list it to confirm the counter was cleared. |
| 206 | lttng_add_trigger_ok "$trigger_name" \ |
| 207 | --condition on-event --userspace tp:tptest \ |
| 208 | --action notify |
| 209 | |
| 210 | # Confirm that the discarded notification line is present. |
| 211 | "$FULL_LTTNG_BIN" list-triggers > "$list_triggers_stdout" |
| 212 | cat "$list_triggers_stdout" | grep --quiet "tracer notifications discarded: 0" |
| 213 | ok $? "No discarded tracer notification" |
| 214 | |
| 215 | lttng_remove_trigger_ok "$trigger_name" |
| 216 | |
| 217 | stop_lttng_sessiond_notap |
| 218 | |
| 219 | unset LTTNG_SESSIOND_ENV_VARS |
| 220 | |
| 221 | rm -f "$list_triggers_stdout" |
| 222 | } |
| 223 | function test_ust_notifier_discarded_count_max_bucket |
| 224 | { |
| 225 | start_lttng_sessiond "" "--event-notifier-error-number-of-bucket=3" |
| 226 | |
| 227 | diag "UST event notifer error counter bucket limit" |
| 228 | for i in $(seq 3); do |
| 229 | lttng_add_trigger_ok "$i" \ |
| 230 | --condition on-event --userspace my_event_that_doesnt_need_to_really_exist_$i \ |
| 231 | --action notify |
| 232 | done |
| 233 | |
| 234 | for i in $(seq 4 5); do |
| 235 | lttng_add_trigger_fail "$i" \ |
| 236 | --condition on-event --userspace my_event_that_doesnt_need_to_really_exist_$i \ |
| 237 | --action notify |
| 238 | done |
| 239 | |
| 240 | stop_lttng_sessiond_notap |
| 241 | } |
| 242 | |
| 243 | test_ust_notifier_discarded_count |
| 244 | test_ust_notifier_discarded_count_max_bucket |
| 245 | |
| 246 | if [ "$(id -u)" == "0" ]; then |
| 247 | |
| 248 | validate_lttng_modules_present |
| 249 | |
| 250 | modprobe lttng-test |
| 251 | |
| 252 | test_kernel_notifier_discarded_count |
| 253 | |
| 254 | test_kernel_notifier_discarded_count_max_bucket |
| 255 | |
| 256 | modprobe --remove lttng-test |
| 257 | |
| 258 | rm -rf "${sessiond_pipe[@]}" 2> /dev/null |
| 259 | else |
| 260 | # Kernel tests are skipped. |
| 261 | skip 0 "Root access is needed. Skipping all kernel notification tests." $KERNEL_NUM_TESTS |
| 262 | fi |
| 263 | |
| 264 | rm -rf "$TMPDIR" |