3 # Copyright (C) 2013 Christian Babeux <christian.babeux@efficios.com>
5 # SPDX-License-Identifier: LGPL-2.1-only
7 TEST_DESC
="Tracefile size limits"
10 TESTDIR
=$CURDIR/..
/..
/..
14 PAGE_SIZE
=$
(getconf PAGE_SIZE
)
16 TESTAPP_PATH
="$TESTDIR/utils/testapp"
17 TESTAPP_NAME
="gen-ust-events"
18 TESTAPP_BIN
="$TESTAPP_PATH/$TESTAPP_NAME/$TESTAPP_NAME"
22 source $TESTDIR/utils
/utils.sh
24 if [ ! -x "$TESTAPP_BIN" ]; then
25 BAIL_OUT
"No UST events binary detected."
28 function enable_lttng_channel_size_limit
()
32 tracefile_size_limit
="$3"
34 test_name
="Enable channel $channel_name "
35 test_name
+="for session $sess_name: "
36 test_name
+="$tracefile_size_limit bytes tracefile limit"
38 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN enable-channel \
39 -u $channel_name -s $sess_name --buffers-pid \
40 --subbuf-size=$PAGE_SIZE \
41 -C $tracefile_size_limit >/dev
/null
2>&1
46 function enable_ust_lttng_event_per_channel
()
52 test_name
="Enable event $event_name "
53 test_name
+="for session $sess_name "
54 test_name
+="in channel $channel_name"
56 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN enable-event
"$event_name" \
57 -s $sess_name -u -c $channel_name >/dev
/null
2>&1
62 function check_file_size
()
66 expected_max_size
="$3"
68 find $path -name "$file_pattern" -exec stat
-c '%n %s' {} \
; \
69 |
while read file_info
;
71 name
=$
(echo $file_info | cut
-f1 -d ' ')
72 size
=$
(echo $file_info | cut
-f2 -d ' ')
74 if [ "$size" -gt "$expected_max_size" ]; then
75 diag_msg
="file: $name size: $size"
76 diag_msg
+="expected maximum size: $expected_max_size"
82 ok $?
"File size validation"
85 function test_tracefile_size_limit
()
88 local trace_path
=$
(mktemp
-d -t "tmp.${FUNCNAME[0]}_trace_path.XXXXXX")
89 local session_name
=$
(randstring
16 0)
90 local channel_name
="channel"
91 local event_name
="tp:tptest"
93 diag
"Test tracefile size limit : $size_limit bytes"
95 create_lttng_session_ok
$session_name $trace_path
97 enable_lttng_channel_size_limit \
98 $session_name $channel_name $size_limit
100 enable_ust_lttng_event_per_channel \
101 $session_name $event_name $channel_name
103 start_lttng_tracing_ok
$session_name
105 $TESTAPP_BIN -i $NR_ITER >/dev
/null
2>&1
107 stop_lttng_tracing_ok
$session_name
109 destroy_lttng_session_ok
$session_name
111 # Validate file size, each one shall be no larger than the
112 # specified size limit
114 check_file_size
$trace_path "${channel_name}_*" $size_limit
116 # Validate tracing data, we should at least have some events
118 validate_trace_path_ust_pid
"$trace_path" "" "gen-ust-events"
119 validate_trace
$event_name $trace_path
124 function test_tracefile_size_limit_pagesize
()
126 # Set a size limit lower than the page_size
127 local size_limit
="$(($PAGE_SIZE-2))"
128 local trace_path
=$
(mktemp
-d -t "tmp.${FUNCNAME[0]}_trace_path.XXXXXX")
129 local session_name
=$
(randstring
16 0)
130 local channel_name
="channel"
131 local event_name
="tp:tptest"
133 diag
"Test tracefile size limit lower than PAGE_SIZE : $size_limit bytes"
135 create_lttng_session_ok
$session_name $trace_path
137 enable_lttng_channel_size_limit \
138 $session_name $channel_name $size_limit
140 enable_ust_lttng_event_per_channel \
141 $session_name $event_name $channel_name
143 start_lttng_tracing_ok
$session_name
145 $TESTAPP_BIN -i $NR_ITER >/dev
/null
2>&1
147 stop_lttng_tracing_ok
$session_name
149 destroy_lttng_session_ok
$session_name
151 # Validate file size, expect file size to be equal to the page size
153 check_file_size
$trace_path "${channel_name}_*" $PAGE_SIZE
155 # Validate tracing data, we should at least have some events
157 validate_trace_path_ust_pid
"$trace_path" "" "gen-ust-events"
158 validate_trace
$event_name $trace_path
163 plan_tests
$NUM_TESTS
165 print_test_banner
"$TEST_DESC"
167 bail_out_if_no_babeltrace
171 # Test with multiples of PAGE_SIZE
172 LIMITS
=("$(($PAGE_SIZE))"
177 "$(($PAGE_SIZE*32))")
179 for limit
in ${LIMITS[@]};
181 test_tracefile_size_limit
$limit
184 # Test with a value that is not a multiple of PAGE_SIZE
185 test_tracefile_size_limit
"$(($PAGE_SIZE+1024))"
187 # Test that a value lower than the PAGE_SIZE is rounded to it
188 test_tracefile_size_limit_pagesize