3 # Copyright (C) 2017 Julien Desfossez <jdesfossez@efficios.com>
5 # SPDX-License-Identifier: LGPL-2.1-only
7 # Clean everything under directory but keep directory
11 # Use -u from bash top prevent empty expansion of variable yielding a
12 # list of current directory from find.
14 find $path -mindepth 1 -maxdepth 1 -exec rm -rf '{}' \
;
18 # The extglob shell option must be enabled to use the pattern generated by this
19 # function (shopt -s extglob/ shopt -u extglob).
20 # The pattern returned by this function is to validate the form:
21 # YYYYMMDDTHHMMSS[+-]HHMM-YYYYMMDDTHHMMSS[+-]HHMM
23 # Where YYYYMMDD is today or tomorrow. Tomorrow must be supported in case where
24 # the chunks are generated close to midnight and one ends up the following day.
25 function get_chunk_pattern
()
28 tommorow
=$
(date +%Y
%m
%d
-d "${today}+1days")
29 pattern_hour_min
="[0-9][0-9][0-9][0-9]"
30 pattern_hour_min_sec
="${pattern_hour_min}[0-9][0-9]"
32 base_pattern
="@(${today}|${tommorow})T${pattern_hour_min_sec}[+-]${pattern_hour_min}"
35 # YYYYMMDDTHHMMSS[+-]HHMM-YYYYMMDDTHHMMSS[+-]HHMM
36 echo "${base_pattern}-${base_pattern}"
39 function validate_test_chunks
()
48 local chunk_pattern
=$
(get_chunk_pattern
${today})
50 # Enable extglob for the use of chunk_pattern
53 # Validate that only 2 chunks are present
54 nb_chunk
=$
(ls -A $local_path |
wc -l)
56 ok $?
"${local_path} contains 2 chunks only"
58 # Check if the first and second chunk folders exist and they contain a ${app_path}/metadata file.
59 for chunk
in $
(seq 0 1); do
60 path
=$
(ls $local_path/${chunk_pattern}-${chunk}/${app_path}/metadata
)
61 ok $?
"Chunk ${chunk} exists based on path $path"
64 # Make sure we don't have anything else in the first 2 chunk directories
65 # besides the kernel folder.
66 for chunk
in $
(seq 0 1); do
69 stale_files
=$
(ls -A $local_path/${chunk_pattern}-${chunk})
70 for domain
in "${domains[@]}"; do
71 stale_files
=$
(echo "$stale_files" |
grep -v $domain)
73 nr_stale
=$
(echo -n "$stale_files" |
wc -l)
74 ok
"$nr_stale" "No stale folders in chunk ${chunk} directory"
77 # We expect a complete session of 30 events
78 validate_trace_count
$EVENT_NAME $local_path 30
81 validate_trace_count
$EVENT_NAME $local_path/${chunk_pattern}-0 10
84 validate_trace_count
$EVENT_NAME $local_path/${chunk_pattern}-1 20
89 function rotate_timer_test
()
99 # Wait for the "archives" folder to appear after the first rotation
100 until [ -d $local_path ]; do
104 # Wait for $expected_chunks to be generated, timeout after
105 # 3 * $expected_chunks * 0.5s.
106 # On a laptop with an empty session, a local rotation takes about 200ms,
107 # and a remote rotation takes about 600ms.
108 # We currently set the timeout to 6 seconds for 3 rotations, if we get
109 # errors, we can bump this value.
111 until [ $nr -ge $expected_chunks ] ||
[ $nr_iter -ge $
(($expected_chunks * 2 )) ]; do
112 nr
=$
(ls $local_path |
wc -l)
113 nr_iter
=$
(($nr_iter+1))
116 test $nr -ge $expected_chunks
117 ok $?
"Generated at least $nr chunks in $(($nr_iter))s"
118 stop_lttng_tracing_ok
$SESSION_NAME
119 destroy_lttng_session_ok
$SESSION_NAME
122 local chunk_pattern
=$
(get_chunk_pattern
${today})
124 # Enable extglob for the use of chunk_pattern
127 # In a per-pid setup, only the first chunk is a valid trace, the other
128 # chunks should be empty folders
129 if test $per_pid = 1; then
130 validate_trace_empty
$local_path/${chunk_pattern}-0
131 nr
=$
(find $local_path/${chunk_pattern}-1/ |
wc -l)
132 # contains self and may contain ust/ subdir (local) or not (remote).
134 ok $?
"Chunk 2 is empty"
135 nr
=$
(find $local_path/${chunk_pattern}-2/ |
wc -l)
136 # contains self and may contain ust/ subdir (local) or not (remote).
138 ok $?
"Chunk 3 is empty"
140 while [ $i -le $expected_chunks ]; do
141 validate_trace_empty
$local_path/${chunk_pattern}-$i
148 function wait_for_archives
()
151 local target_archive_count
=$2
152 local archive_count
=0
154 diag
"Waiting for $target_archive_count size-based rotations to occur"
155 while [[ archive_count
-lt $target_archive_count ]]
157 archive_count
=$
(find "$TRACE_PATH" -mindepth 2 -maxdepth 2 -type d
-path "*archives*" |
wc -l)
158 $TESTAPP_BIN -i 2000 -w 0 > /dev
/null
2>&1
161 [[ $archive_count -eq $target_archive_count ]]
162 ok $?
"Found $target_archive_count trace archives resulting from trace archive rotations"
This page took 0.033658 seconds and 5 git commands to generate.