| 1 | #!/bin/bash |
| 2 | # |
| 3 | # Copyright (C) 2013 Christian Babeux <christian.babeux@efficios.com> |
| 4 | # |
| 5 | # SPDX-License-Identifier: LGPL-2.1-only |
| 6 | |
| 7 | TEST_DESC="Tracefile count limits" |
| 8 | |
| 9 | CURDIR=$(dirname $0)/ |
| 10 | TESTDIR=$CURDIR/../../.. |
| 11 | |
| 12 | TESTAPP_PATH="$TESTDIR/utils/testapp" |
| 13 | TESTAPP_NAME="gen-ust-events" |
| 14 | TESTAPP_BIN="$TESTAPP_PATH/$TESTAPP_NAME/$TESTAPP_NAME" |
| 15 | |
| 16 | STATS_BIN="$TESTDIR/utils/babelstats.pl" |
| 17 | NUM_TESTS=74 |
| 18 | |
| 19 | NUM_CPUS=`nproc` |
| 20 | PAGE_SIZE=$(getconf PAGE_SIZE) |
| 21 | |
| 22 | source $TESTDIR/utils/utils.sh |
| 23 | |
| 24 | if [ ! -x "$TESTAPP_BIN" ]; then |
| 25 | BAIL_OUT "No UST events binary detected." |
| 26 | fi |
| 27 | |
| 28 | function enable_lttng_channel_count_limit () |
| 29 | { |
| 30 | sess_name="$1" |
| 31 | channel_name="$2" |
| 32 | tracefile_count_limit="$3" |
| 33 | |
| 34 | test_name="Enable channel $channel_name " |
| 35 | test_name+="for session $sess_name: " |
| 36 | test_name+="$tracefile_count_limit tracefiles" |
| 37 | |
| 38 | $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-channel \ |
| 39 | -u $channel_name -s $sess_name \ |
| 40 | -C $(($PAGE_SIZE*3)) -W $tracefile_count_limit \ |
| 41 | --overwrite >/dev/null 2>&1 |
| 42 | |
| 43 | ok $? "$test_name" |
| 44 | } |
| 45 | |
| 46 | function enable_ust_lttng_event_per_channel () |
| 47 | { |
| 48 | sess_name="$1" |
| 49 | event_name="$2" |
| 50 | channel_name="$3" |
| 51 | |
| 52 | test_name="Enable event $event_name " |
| 53 | test_name+="for session $sess_name " |
| 54 | test_name+="in channel $channel_name" |
| 55 | |
| 56 | $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-event "$event_name" \ |
| 57 | -s $sess_name -u -c $channel_name >/dev/null 2>&1 |
| 58 | |
| 59 | ok $? "$test_name" |
| 60 | } |
| 61 | |
| 62 | function validate_min_max |
| 63 | { |
| 64 | stats="$1" |
| 65 | field="$2" |
| 66 | expected_min="$3" |
| 67 | expected_max="$4" |
| 68 | |
| 69 | echo $stats | grep -q -E "$field $expected_min $expected_max" |
| 70 | return $? |
| 71 | } |
| 72 | |
| 73 | function validate_file_count |
| 74 | { |
| 75 | path="$1" |
| 76 | file_pattern="$2" |
| 77 | expected_max_count="$3" |
| 78 | |
| 79 | count=`find $path -name "$file_pattern" -type f \( ! -iname "*.idx" \) | wc -l` |
| 80 | |
| 81 | if [ "$count" -gt "$expected_max_count" ]; then |
| 82 | fail "Validate file count: $file_pattern" |
| 83 | diag "File count: $count expected: $expected_max_count" |
| 84 | else |
| 85 | pass "Validate file count: $file_pattern" |
| 86 | fi |
| 87 | } |
| 88 | |
| 89 | function test_tracefile_count_limit () |
| 90 | { |
| 91 | count_limit="$1" |
| 92 | trace_path=$(mktemp -d) |
| 93 | session_name=$(randstring 16 0) |
| 94 | channel_name="channel" |
| 95 | event_name="tp:tptest" |
| 96 | num_iter=100000 |
| 97 | expected_max=$(($num_iter - 1)) |
| 98 | |
| 99 | diag "Test tracefile count limit : $count_limit tracefiles" |
| 100 | |
| 101 | create_lttng_session_ok $session_name $trace_path |
| 102 | |
| 103 | enable_lttng_channel_count_limit \ |
| 104 | $session_name $channel_name $count_limit |
| 105 | |
| 106 | enable_ust_lttng_event_per_channel \ |
| 107 | $session_name $event_name $channel_name |
| 108 | |
| 109 | start_lttng_tracing_ok $session_name |
| 110 | |
| 111 | $TESTAPP_BIN -i $num_iter >/dev/null 2>&1 |
| 112 | |
| 113 | stop_lttng_tracing_ok $session_name |
| 114 | |
| 115 | destroy_lttng_session_ok $session_name |
| 116 | |
| 117 | # Validate tracing dir |
| 118 | |
| 119 | for cpuno in $(seq 0 $(($NUM_CPUS - 1))) |
| 120 | do |
| 121 | validate_file_count \ |
| 122 | $trace_path "${channel_name}_${cpuno}_*" $count_limit |
| 123 | done |
| 124 | |
| 125 | # Validate tracing data |
| 126 | |
| 127 | stats=`babeltrace $trace_path | $STATS_BIN --tracepoint $event_name` |
| 128 | |
| 129 | validate_min_max "$stats" "intfield" "[0-9]+" "$expected_max" |
| 130 | ok $? "Trace validation - intfield" |
| 131 | |
| 132 | validate_min_max "$stats" "netintfield" "[0-9]+" "$expected_max" |
| 133 | ok $? "Trace validation - netintfield" |
| 134 | |
| 135 | validate_min_max "$stats" "longfield" "[0-9]+" "$expected_max" |
| 136 | ok $? "Trace validation - longfield" |
| 137 | |
| 138 | rm -rf $trace_path |
| 139 | } |
| 140 | |
| 141 | LIMITS=("1" "2" "4" "8" "10" "16" "32" "64") |
| 142 | |
| 143 | # The file count validation depends on the number of streams (1 per cpu) |
| 144 | TOTAL_TESTS=$(($NUM_TESTS + (${#LIMITS[@]} * $NUM_CPUS))) |
| 145 | |
| 146 | plan_tests $TOTAL_TESTS |
| 147 | |
| 148 | print_test_banner "$TEST_DESC" |
| 149 | |
| 150 | start_lttng_sessiond |
| 151 | |
| 152 | for limit in ${LIMITS[@]}; |
| 153 | do |
| 154 | test_tracefile_count_limit $limit |
| 155 | done |
| 156 | |
| 157 | stop_lttng_sessiond |