Commit | Line | Data |
---|---|---|
34497a63 CB |
1 | #!/bin/bash |
2 | # | |
9d16b343 | 3 | # Copyright (C) 2013 Christian Babeux <christian.babeux@efficios.com> |
34497a63 | 4 | # |
9d16b343 | 5 | # SPDX-License-Identifier: LGPL-2.1-only |
34497a63 CB |
6 | |
7 | TEST_DESC="Tracefile size limits" | |
8 | ||
9 | CURDIR=$(dirname $0)/ | |
10 | TESTDIR=$CURDIR/../../.. | |
11 | ||
12 | NR_ITER=1000 | |
13 | ||
034a7848 MJ |
14 | PAGE_SIZE=$(getconf PAGE_SIZE) |
15 | ||
34497a63 CB |
16 | TESTAPP_PATH="$TESTDIR/utils/testapp" |
17 | TESTAPP_NAME="gen-ust-events" | |
18 | TESTAPP_BIN="$TESTAPP_PATH/$TESTAPP_NAME/$TESTAPP_NAME" | |
19 | ||
ea263060 | 20 | NUM_TESTS=66 |
34497a63 CB |
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 | ||
34497a63 CB |
28 | function enable_lttng_channel_size_limit () |
29 | { | |
30 | sess_name="$1" | |
31 | channel_name="$2" | |
32 | tracefile_size_limit="$3" | |
33 | ||
34 | test_name="Enable channel $channel_name " | |
35 | test_name+="for session $sess_name: " | |
36 | test_name+="$tracefile_size_limit bytes tracefile limit" | |
37 | ||
38 | $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-channel \ | |
c1b8e6f8 | 39 | -u $channel_name -s $sess_name --buffers-pid \ |
88ec6b80 | 40 | --subbuf-size=$PAGE_SIZE \ |
34497a63 CB |
41 | -C $tracefile_size_limit >/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 check_file_size () | |
63 | { | |
64 | path="$1" | |
65 | file_pattern="$2" | |
66 | expected_max_size="$3" | |
67 | ||
68 | find $path -name "$file_pattern" -exec stat -c '%n %s' {} \; \ | |
69 | | while read file_info; | |
70 | do | |
71 | name=$(echo $file_info | cut -f1 -d ' ') | |
72 | size=$(echo $file_info | cut -f2 -d ' ') | |
73 | ||
74 | if [ "$size" -gt "$expected_max_size" ]; then | |
75 | diag_msg="file: $name size: $size" | |
76 | diag_msg+="expected maximum size: $expected_max_size" | |
77 | diag "$diag_msg" | |
78 | exit 1 | |
79 | fi | |
80 | done | |
81 | ||
82 | ok $? "File size validation" | |
83 | } | |
84 | ||
85 | function test_tracefile_size_limit () | |
86 | { | |
87 | size_limit="$1" | |
88 | trace_path=$(mktemp -d) | |
89 | session_name=$(randstring 16 0) | |
90 | channel_name="channel" | |
91 | event_name="tp:tptest" | |
92 | ||
93 | diag "Test tracefile size limit : $size_limit bytes" | |
94 | ||
bf6ae429 | 95 | create_lttng_session_ok $session_name $trace_path |
34497a63 CB |
96 | |
97 | enable_lttng_channel_size_limit \ | |
98 | $session_name $channel_name $size_limit | |
99 | ||
100 | enable_ust_lttng_event_per_channel \ | |
101 | $session_name $event_name $channel_name | |
102 | ||
e563bbdb | 103 | start_lttng_tracing_ok $session_name |
34497a63 | 104 | |
6c4a91d6 | 105 | $TESTAPP_BIN -i $NR_ITER >/dev/null 2>&1 |
34497a63 | 106 | |
96340a01 | 107 | stop_lttng_tracing_ok $session_name |
34497a63 | 108 | |
67b4c664 | 109 | destroy_lttng_session_ok $session_name |
34497a63 CB |
110 | |
111 | # Validate file size, each one shall be no larger than the | |
112 | # specified size limit | |
113 | ||
114 | check_file_size $trace_path "${channel_name}_*" $size_limit | |
115 | ||
116 | # Validate tracing data, we should at least have some events | |
117 | ||
118 | validate_trace $event_name $trace_path | |
119 | ||
120 | rm -rf $trace_path | |
121 | } | |
122 | ||
034a7848 MJ |
123 | function test_tracefile_size_limit_pagesize () |
124 | { | |
125 | # Set a size limit lower than the page_size | |
126 | size_limit="$(($PAGE_SIZE-2))" | |
127 | trace_path=$(mktemp -d) | |
128 | session_name=$(randstring 16 0) | |
129 | channel_name="channel" | |
130 | event_name="tp:tptest" | |
131 | ||
132 | diag "Test tracefile size limit lower than PAGE_SIZE : $size_limit bytes" | |
133 | ||
134 | create_lttng_session_ok $session_name $trace_path | |
135 | ||
136 | enable_lttng_channel_size_limit \ | |
137 | $session_name $channel_name $size_limit | |
138 | ||
139 | enable_ust_lttng_event_per_channel \ | |
140 | $session_name $event_name $channel_name | |
141 | ||
142 | start_lttng_tracing_ok $session_name | |
143 | ||
6c4a91d6 | 144 | $TESTAPP_BIN -i $NR_ITER >/dev/null 2>&1 |
034a7848 MJ |
145 | |
146 | stop_lttng_tracing_ok $session_name | |
147 | ||
148 | destroy_lttng_session_ok $session_name | |
149 | ||
150 | # Validate file size, expect file size to be equal to the page size | |
151 | ||
152 | check_file_size $trace_path "${channel_name}_*" $PAGE_SIZE | |
153 | ||
154 | # Validate tracing data, we should at least have some events | |
155 | ||
156 | validate_trace $event_name $trace_path | |
157 | ||
158 | rm -rf $trace_path | |
159 | } | |
160 | ||
34497a63 CB |
161 | plan_tests $NUM_TESTS |
162 | ||
163 | print_test_banner "$TEST_DESC" | |
164 | ||
165 | start_lttng_sessiond | |
166 | ||
034a7848 MJ |
167 | # Test with multiples of PAGE_SIZE |
168 | LIMITS=("$(($PAGE_SIZE))" | |
169 | "$(($PAGE_SIZE*2))" | |
170 | "$(($PAGE_SIZE*4))" | |
171 | "$(($PAGE_SIZE*8))" | |
172 | "$(($PAGE_SIZE*16))" | |
173 | "$(($PAGE_SIZE*32))") | |
34497a63 CB |
174 | |
175 | for limit in ${LIMITS[@]}; | |
176 | do | |
177 | test_tracefile_size_limit $limit | |
178 | done | |
179 | ||
034a7848 MJ |
180 | # Test with a value that is not a multiple of PAGE_SIZE |
181 | test_tracefile_size_limit "$(($PAGE_SIZE+1024))" | |
182 | ||
183 | # Test that a value lower than the PAGE_SIZE is rounded to it | |
184 | test_tracefile_size_limit_pagesize | |
185 | ||
34497a63 | 186 | stop_lttng_sessiond |