From 96bb1ae87edd50f631cc845c76ca08cedae8c59f Mon Sep 17 00:00:00 2001 From: Francis Deslauriers Date: Wed, 14 Apr 2021 13:09:15 -0400 Subject: [PATCH] Tests: event-notifier: multi UID error accounting support MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit The new test case adds one root trigger and one regular user trigger as well as apps from both of these users. The test then confirm that the error accounting of the root trigger reports what is happening on the regular user's app as well as its own app. Signed-off-by: Francis Deslauriers Signed-off-by: Jérémie Galarneau Change-Id: Iaec231863de98b14891602bdae010449989de6f9 --- ...test_notification_notifier_discarded_count | 188 ++++++++++++------ tests/utils/utils.sh | 3 +- 2 files changed, 131 insertions(+), 60 deletions(-) diff --git a/tests/regression/tools/notification/test_notification_notifier_discarded_count b/tests/regression/tools/notification/test_notification_notifier_discarded_count index b0fce8aa8..2186bfb2c 100755 --- a/tests/regression/tools/notification/test_notification_notifier_discarded_count +++ b/tests/regression/tools/notification/test_notification_notifier_discarded_count @@ -27,12 +27,35 @@ 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=18 -KERNEL_NUM_TESTS=17 +UST_NUM_TESTS=15 +DESTRUCTIVE_TESTS_NUM=8 +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" | tail -1 | grep --quiet "errors: none" + ret=$? + + if [ "$ret" -eq "0" ]; then + notif_nb="0" + else + notif_nb=$(cat "$list_triggers_stdout" | grep -a8 "$trigger_name" | tail -1 | grep "discarded tracer messages" | cut -d' ' -f8) + 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=() @@ -58,14 +81,8 @@ function test_kernel_notifier_discarded_count --condition on-event --kernel lttng_test_filter_event \ --action notify - "$FULL_LTTNG_BIN" list-triggers > "$list_triggers_stdout" - - # Confirm that the discarded notification line is not present. - cat "$list_triggers_stdout" | grep -v --quiet "discarded tracer messages" - ok $? "No discarded tracer notification message" - - tail -n 1 "$list_triggers_stdout" | grep --quiet "errors: none" - ok $? "Trigger 'errors: none' notification message" + 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" @@ -78,16 +95,9 @@ function test_kernel_notifier_discarded_count # is lost in subbuffer boundaries. echo -n "2000" > /proc/lttng-test-filter-event - "$FULL_LTTNG_BIN" list-triggers > "$list_triggers_stdout" - - # Confirm that the discarded notification line is present. To avoid - # false positives. - cat "$list_triggers_stdout" | grep --quiet "discarded tracer messages" - ok $? "Tracer notification discarded line printed" - - # Confirm that the number of dicarded tracer messages is not zero. - cat "$list_triggers_stdout" | grep --quiet "discarded tracer messages: 0" - isnt $? 0 "Discarded tracer notification number non-zero as expected" + # 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" @@ -100,14 +110,8 @@ function test_kernel_notifier_discarded_count --condition on-event --kernel lttng_test_filter_event \ --action notify - "$FULL_LTTNG_BIN" list-triggers > "$list_triggers_stdout" - - # Confirm that the discarded notification line is not present. - cat "$list_triggers_stdout" | grep -v --quiet "discarded tracer messages" - ok $? "No discarded tracer notification message" - - tail -n 1 "$list_triggers_stdout" | grep --quiet "errors: none" - ok $? "Trigger 'errors: none' notification message" + 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" @@ -142,7 +146,6 @@ function test_ust_notifier_discarded_count { local sessiond_pipe=() local trigger_name="my_trigger" - local list_triggers_stdout=$(mktemp -t list_triggers_stdout.XXXXXX) local NR_USEC_WAIT=0 local PIPE_SIZE local NR_ITER @@ -180,14 +183,8 @@ function test_ust_notifier_discarded_count --condition on-event --userspace tp:tptest \ --action notify - "$FULL_LTTNG_BIN" list-triggers > "$list_triggers_stdout" - - # Confirm that the discarded notification line is not present. - cat "$list_triggers_stdout" | grep -v --quiet "discarded tracer messages" - ok $? "No discarded tracer notification message" - - tail -n 1 "$list_triggers_stdout" | grep --quiet "errors: none" - ok $? "Trigger 'errors: none' notification message" + 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" @@ -196,16 +193,9 @@ function test_ust_notifier_discarded_count $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 "discarded tracer messages" - ok $? "Tracer notification discarded line printed" - - # Confirm that the number of discarded tracer messages is not zero. - cat "$list_triggers_stdout" | grep --quiet "discarded tracer messages: 0" - isnt $? 0 "Discarded tracer notification number non-zero as expected" + # 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" @@ -219,24 +209,16 @@ function test_ust_notifier_discarded_count --condition on-event --userspace tp:tptest \ --action notify - # Confirm that the discarded notification line is not present. - "$FULL_LTTNG_BIN" list-triggers > "$list_triggers_stdout" - - # Confirm that the discarded notification line is not present. - cat "$list_triggers_stdout" | grep -v --quiet "discarded tracer messages" - ok $? "No discarded tracer notification message" - - tail -n 1 "$list_triggers_stdout" | grep --quiet "errors: none" - ok $? "Trigger 'errors: none' notification message" + 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_ust_notifier_discarded_count_max_bucket { start_lttng_sessiond "" "--event-notifier-error-buffer-size-userspace=3" @@ -257,6 +239,86 @@ function test_ust_notifier_discarded_count_max_bucket 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=$("$CURDIR"/default_pipe_size_getter) + if [ $? -ne 0 ]; then + BAIL_OUT "Failed to get system default pipe size" + else + diag "Default system pipe size: $PIPE_SIZE bytes" + fi + + # 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 on-event --userspace tp:tptest \ + --action notify + + lttng_add_trigger_ok "$user_trigger_name" --user-id "$new_uid" \ + --condition on-event --userspace 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 discard notifications number ($root_trigger_discarded_nb) is non-zero" + isnt $user_trigger_discarded_nb 0 \ + "User trigger discard notifications number ($user_trigger_discarded_nb) is non-zero" + + lttng_remove_trigger_ok "$root_trigger_name" + lttng_remove_trigger_ok "$user_trigger_name" --user-id "$new_uid" + + 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 @@ -267,9 +329,17 @@ if [ "$(id -u)" == "0" ]; then modprobe lttng-test test_kernel_notifier_discarded_count - test_kernel_notifier_discarded_count_max_bucket + if destructive_tests_enabled ; then + # This test adds 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 + 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 diff --git a/tests/utils/utils.sh b/tests/utils/utils.sh index d57cb3f34..c81cc2d1a 100644 --- a/tests/utils/utils.sh +++ b/tests/utils/utils.sh @@ -2212,8 +2212,9 @@ function lttng_remove_trigger() { local expected_to_fail="$1" local trigger_name="$2" + shift 2 - $TESTDIR/../src/bin/lttng/$LTTNG_BIN remove-trigger "$trigger_name" 1> /dev/null 2> /dev/null + $TESTDIR/../src/bin/lttng/$LTTNG_BIN remove-trigger "$trigger_name" "$@" 1> /dev/null 2> /dev/null ret=$? if [[ $expected_to_fail -eq "1" ]]; then test "$ret" -ne "0" -- 2.34.1