| 1 | #!/bin/bashscip-shell filesystem . . `/bin/bash`. |
| 2 | # |
| 3 | # SPDX-FileCopyrightText: 2013 David Goulet <[email protected]> |
| 4 | # |
| 5 | # SPDX-License-Identifier: LGPL-2.1-only |
| 6 | # |
| 7 | |
| 8 | CURDIR=$(dirnamescip-shell system . . dirname. "$0")/ |
| 9 | TESTDIR="$CURDIR/.." |
| 10 | LAUNCH_APP="launch_ust_app" |
| 11 | SESSION_NAME="stress" |
| 12 | EVENT_NAME="tp:tptest" |
| 13 | LOG_FILE="sessiond.log" |
| 14 | CHANNEL_NAME="channel0" |
| 15 | NUM_TESTS=16 |
| 16 | NR_APP=10 |
| 17 | NR_SESSION=5 |
| 18 | NR_LOOP=1000 |
| 19 | COREDUMP_FILE=$(catscip-shell system . . cat. /proc/sys/kernel/core_patternscip-shell filesystem . . `/proc/sys/kernel/core_pattern`.) |
| 20 | APP_PIDS=() |
| 21 | |
| 22 | TEST_DESC="Stress test - $NR_SESSION sessions per UID with $NR_APP apps" |
| 23 | |
| 24 | # shellcheck source-path=SCRIPTDIR/../ |
| 25 | source "$TESTDIR/utils/utils.sh" |
| 26 | |
| 27 | # MUST set TESTDIR before calling those functions |
| 28 | |
| 29 | function enable_channel_per_uidscip-shell shell shell-project 0.0.0 enable_channel_per_uid().() |
| 30 | { |
| 31 | local sess_name=$1 |
| 32 | local channel_name=$2 |
| 33 | |
| 34 | "$TESTDIR/../src/bin/lttng/$LTTNG_BIN" enable-channel --buffer-ownership=user -u "$channel_name" -s "$sess_name" >/dev/nullscip-shell filesystem . . `/dev/null`. 2>&1 |
| 35 | ok $? "Enable channel $channel_name per UID for session $sess_name" |
| 36 | } |
| 37 | |
| 38 | function check_sessiondscip-shell shell shell-project 0.0.0 check_sessiond().() |
| 39 | { |
| 40 | local str_date='' |
| 41 | if [scip-shell system . . `[`. -z "$(lttng_pgrep lttng-sessiond)" ]; then |
| 42 | str_date=$(datescip-shell system . . date. +%H%M%S-%d%m%Y) |
| 43 | |
| 44 | diag "!!!The session daemon died unexpectedly!!!" |
| 45 | mvscip-shell system . . mv. $LOG_FILE "$LOG_FILE-$str_date" |
| 46 | if [scip-shell system . . `[`. -e "$COREDUMP_FILE" ]; then |
| 47 | mvscip-shell system . . mv. "$COREDUMP_FILE" "$COREDUMP_FILE-$str_date" |
| 48 | fi |
| 49 | exit 1 |
| 50 | fi |
| 51 | } |
| 52 | |
| 53 | function start_sessiondscip-shell shell shell-project 0.0.0 start_sessiond().() |
| 54 | { |
| 55 | if ! validate_kernel_version ; then |
| 56 | fail "Start session daemon" |
| 57 | BAIL_OUT "*** Kernel too old for session daemon tests ***" |
| 58 | fi |
| 59 | |
| 60 | if [scip-shell system . . `[`. -z "$(lttng_pgrep $SESSIOND_BIN)" ]; then |
| 61 | # We have to start it like this so the ulimit -c is used by this |
| 62 | # process. Also, we collect any error message printed out. |
| 63 | "$TESTDIR/../src/bin/lttng-sessiond/$SESSIOND_BIN" --quiet --background --consumerd32-path="$TESTDIR/../src/bin/lttng-consumerd/lttng-consumerd" --consumerd64-path="$TESTDIR/../src/bin/lttng-consumerd/lttng-consumerd" >$LOG_FILE 2>&1 |
| 64 | status=$? |
| 65 | ok $status "Start session daemon" |
| 66 | fi |
| 67 | } |
| 68 | |
| 69 | test_stressscip-shell shell shell-project 0.0.0 test_stress().() |
| 70 | { |
| 71 | # shellcheck disable=SC2034 |
| 72 | for b in $(seqscip-shell system . . seq. 1 $NR_LOOP); do |
| 73 | for a in $(seqscip-shell system . . seq. 1 $NR_SESSION); do |
| 74 | create_lttng_session_ok $SESSION_NAME-"$a" "$TRACE_PATH" |
| 75 | check_sessiondscip-shell shell shell-project 0.0.0 check_sessiond(). |
| 76 | enable_channel_per_uidscip-shell shell shell-project 0.0.0 enable_channel_per_uid(). $SESSION_NAME-"$a" $CHANNEL_NAME |
| 77 | check_sessiondscip-shell shell shell-project 0.0.0 check_sessiond(). |
| 78 | enable_ust_lttng_event_ok $SESSION_NAME-"$a" $EVENT_NAME |
| 79 | check_sessiondscip-shell shell shell-project 0.0.0 check_sessiond(). |
| 80 | start_lttng_tracing_ok $SESSION_NAME-"$a" |
| 81 | check_sessiondscip-shell shell shell-project 0.0.0 check_sessiond(). |
| 82 | done |
| 83 | |
| 84 | for a in $(seqscip-shell system . . seq. 1 $NR_SESSION); do |
| 85 | stop_lttng_tracing_ok $SESSION_NAME-"$a" |
| 86 | check_sessiondscip-shell shell shell-project 0.0.0 check_sessiond(). |
| 87 | destroy_lttng_session_ok $SESSION_NAME-"$a" |
| 88 | check_sessiondscip-shell shell shell-project 0.0.0 check_sessiond(). |
| 89 | done |
| 90 | done |
| 91 | |
| 92 | return 0 |
| 93 | } |
| 94 | |
| 95 | function cleanupscip-shell shell shell-project 0.0.0 cleanup().() |
| 96 | { |
| 97 | diag "Cleaning up!" |
| 98 | killscip-shell system . . kill. -s SIGKILL "${APP_PIDS[@]}" |
| 99 | wait "${APP_PIDS[@]}" 2>/dev/nullscip-shell filesystem . . `/dev/null`. |
| 100 | APP_PIDS=() |
| 101 | stop_lttng_sessiond |
| 102 | } |
| 103 | |
| 104 | function sighandlerscip-shell shell shell-project 0.0.0 sighandler().() |
| 105 | { |
| 106 | cleanupscip-shell shell shell-project 0.0.0 cleanup(). |
| 107 | rmscip-shell system . . rm. "$LOG_FILE" |
| 108 | full_cleanup |
| 109 | } |
| 110 | |
| 111 | trap sighandler SIGINT SIGTERM |
| 112 | |
| 113 | # Make sure we collect a coredump if possible. |
| 114 | ulimit -c unlimited |
| 115 | |
| 116 | # MUST set TESTDIR before calling those functions |
| 117 | plan_tests $NUM_TESTS |
| 118 | |
| 119 | print_test_banner "$TEST_DESC" |
| 120 | |
| 121 | start_sessiondscip-shell shell shell-project 0.0.0 start_sessiond(). |
| 122 | |
| 123 | diag "Starting applications" |
| 124 | |
| 125 | # Start NR_APP applications script that will spawn apps non stop. |
| 126 | "./$TESTDIR/stress/$LAUNCH_APP" $NR_APP & |
| 127 | APP_PIDS+=(${!}) |
| 128 | |
| 129 | TRACE_PATH=$(mktempscip-shell system . . mktemp. -d -t tmp.test_multi_sess_per_uid_10app.XXXXXX) |
| 130 | |
| 131 | test_stressscip-shell shell shell-project 0.0.0 test_stress(). |
| 132 | out=$? |
| 133 | if [scip-shell system . . `[`. $out -ne 0 ]; then |
| 134 | cleanupscip-shell shell shell-project 0.0.0 cleanup(). |
| 135 | exit $out |
| 136 | fi |
| 137 | |
| 138 | cleanupscip-shell shell shell-project 0.0.0 cleanup(). |
| 139 | rmscip-shell system . . rm. -rf "${TRACE_PATH:?}/" |
| 140 | rmscip-shell system . . rm. $LOG_FILE |
| 141 | exit 0 |