#!/bin/bash # # Copyright (C) 2020 Francis Deslauriers # # SPDX-License-Identifier: LGPL-2.1-only CURDIR=$(dirname "$0")/ TESTDIR=$CURDIR/../../../ TMPDIR=$(mktemp -d) TESTAPP_PATH="$TESTDIR/utils/testapp" TESTAPP_NAME="gen-ust-events" TESTAPP_BIN="$TESTAPP_PATH/$TESTAPP_NAME/$TESTAPP_NAME" TESTPOINT_BASE_PATH=$(readlink -f "$TMPDIR/lttng.t_p_n") TESTPOINT_PIPE_PATH=$(mktemp -u "${TESTPOINT_BASE_PATH}.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 KERNEL_NUM_TESTS=14 NUM_TESTS=$(($UST_NUM_TESTS + $KERNEL_NUM_TESTS)) plan_tests $NUM_TESTS function test_kernel_trigger_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 \ TRIGGER_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 "$FULL_LTTNG_BIN" add-trigger --id "$trigger_name" \ --condition on-event --kernel lttng_test_filter_event \ --action notify > /dev/null > /dev/null ok $? "Adding \`on-event\` kernel trigger successful" "$FULL_LTTNG_BIN" list-triggers > "$list_triggers_stdout" # Confirm that the discarded notification line is present. cat "$list_triggers_stdout" | grep --quiet "tracer notifications discarded: 0" ok $? "No discarded tracer notification" # Stop consumption of trigger tracer notifications. echo -n 1 > $sessiond_pipe # The trigger 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 "200000" > /proc/lttng-test-filter-event "$FULL_LTTNG_BIN" list-triggers > "$list_triggers_stdout" # Confirm that the discarded notification line is present. To avoid # false positive. cat "$list_triggers_stdout" | grep --quiet "tracer notifications discarded" ok $? "Tracer notification discarded line printed" # Confirm that the number of tracer notifications discarded is not zero. cat "$list_triggers_stdout" | grep --quiet "tracer notifications discarded: 0" isnt $? 0 "Discarded tracer notification number non-zero as expected" "$FULL_LTTNG_BIN" remove-trigger "$trigger_name" > /dev/null ok $? "Removing \`on-event\` kernel trigger successful" # Confirm that no trigger is enabled. list_triggers_line_count=$("$FULL_LTTNG_BIN" list-triggers | wc -l) is "$list_triggers_line_count" "0" "No \`on-event\` kernel trigger enabled as expected" # Enable another trigger and list it to confirm the counter was cleared. "$FULL_LTTNG_BIN" add-trigger --id "$trigger_name" \ --condition on-event --kernel lttng_test_filter_event \ --action notify > /dev/null ok $? "Adding another \`on-event\` kernel trigger successful" # Confirm that the discarded notification line is present. "$FULL_LTTNG_BIN" list-triggers > "$list_triggers_stdout" cat "$list_triggers_stdout" | grep --quiet "tracer notifications discarded: 0" ok $? "No discarded tracer notification" "$FULL_LTTNG_BIN" remove-trigger "$trigger_name" > /dev/null ok $? "Removing \`on-event\` kernel trigger successful" stop_lttng_sessiond_notap unset LTTNG_SESSIOND_ENV_VARS rm -f "$list_triggers_stdout" } function test_kernel_trigger_discarded_count_max_bucket { "$FULL_LTTNG_SESSIOND_BIN" -d --trigger-error-number-of-bucket=3 for i in $(seq 3); do "$FULL_LTTNG_BIN" add-trigger --id "$i" \ --condition on-event --kernel my_event_that_doesnt_need_to_really_exist_$i \ --action notify > /dev/null ok $? "Enabling \`on-event\` kernel trigger $i succeeds" done for i in $(seq 4 5); do "$FULL_LTTNG_BIN" add-trigger --id "$i" \ --condition on-event --kernel my_event_that_doesnt_need_to_really_exist_$i \ --action notify > /dev/null 2>&1 isnt $? 0 "Enabling \`on-event\` kernel trigger $i fails as expected" done stop_lttng_sessiond_notap } function test_ust_trigger_discarded_count { local sessiond_pipe=() local trigger_name="my_trigger" local list_triggers_stdout=$(mktemp -t list_triggers_stdout.XXXXXX) local NR_ITER=2000 local NR_USEC_WAIT=0 # Used on sessiond launch. LTTNG_SESSIOND_ENV_VARS="LTTNG_TESTPOINT_ENABLE=1 \ TRIGGER_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 "$FULL_LTTNG_BIN" add-trigger --id "$trigger_name" \ --condition on-event --userspace tp:tptest \ --action notify > /dev/null ok $? "Adding \`on-event\` userspace trigger successful" "$FULL_LTTNG_BIN" list-triggers > "$list_triggers_stdout" # Confirm that the discarded notification line is present. cat "$list_triggers_stdout" | grep --quiet "tracer notifications discarded: 0" ok $? "No discarded tracer notification" # Stop consumption of trigger tracer notifications. echo -n 1 > $sessiond_pipe # The trigger ring buffer configuration is currently made of 16 4096 # bytes subbuffers. Each userspace 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. $TESTAPP_BIN -i $NR_ITER -w $NR_USEC_WAIT ok $? "Generating $NR_ITER tracer notifications" "$FULL_LTTNG_BIN" list-triggers > "$list_triggers_stdout" # Confirm that the discarded notification line is present. To avoid # false positive. cat "$list_triggers_stdout" | grep --quiet "tracer notifications discarded" ok $? "Tracer notification discarded line printed" # Confirm that the number of tracer notifications discarded is not zero. cat "$list_triggers_stdout" | grep --quiet "tracer notifications discarded: 0" isnt $? 0 "Discarded tracer notification number non-zero as expected" # Remove the trigger. "$FULL_LTTNG_BIN" remove-trigger "$trigger_name" > /dev/null ok $? "Removing \`on-event\` userspace trigger successful" # Confirm that no trigger is enabled. list_triggers_line_count=$("$FULL_LTTNG_BIN" list-triggers | wc -l) is "$list_triggers_line_count" "0" "No \`on-event\` userspace trigger enabled as expected" # Enable another trigger and list it to confirm the counter was cleared. "$FULL_LTTNG_BIN" add-trigger --id "$trigger_name" \ --condition on-event --userspace tp:tptest \ --action notify > /dev/null ok $? "Adding another \`on-event\` userspace trigger successful" # Confirm that the discarded notification line is present. "$FULL_LTTNG_BIN" list-triggers > "$list_triggers_stdout" cat "$list_triggers_stdout" | grep --quiet "tracer notifications discarded: 0" ok $? "No discarded tracer notification" "$FULL_LTTNG_BIN" remove-trigger "$trigger_name" > /dev/null ok $? "Removing \`on-event\` userspace trigger successful" stop_lttng_sessiond_notap unset LTTNG_SESSIOND_ENV_VARS rm -f "$list_triggers_stdout" } function test_ust_trigger_discarded_count_max_bucket { "$FULL_LTTNG_SESSIOND_BIN" -d --trigger-error-number-of-bucket=3 for i in $(seq 3); do "$FULL_LTTNG_BIN" add-trigger --id "$i" \ --condition on-event --userspace my_event_that_doesnt_need_to_really_exist_$i \ --action notify > /dev/null ok $? "Enabling \`on-event\` userspace trigger $i succeeds" done for i in $(seq 4 5); do "$FULL_LTTNG_BIN" add-trigger --id "$i" \ --condition on-event --userspace my_event_that_doesnt_need_to_really_exist_$i \ --action notify > /dev/null 2>&1 isnt $? 0 "Enabling \`on-event\` userspace trigger $i fails as expected" done stop_lttng_sessiond_notap } test_ust_trigger_discarded_count test_ust_trigger_discarded_count_max_bucket if [ "$(id -u)" == "0" ]; then validate_lttng_modules_present modprobe lttng-test test_kernel_trigger_discarded_count test_kernel_trigger_discarded_count_max_bucket modprobe --remove lttng-test rm -rf "${sessiond_pipe[@]}" 2> /dev/null else # Kernel tests are skipped. skip 0 "Root access is needed. Skipping all kernel notification tests." $KERNEL_NUM_TESTS fi rm -rf "$TMPDIR"