Tests: rotation: add a kernel size-based rotation test
[lttng-tools.git] / tests / regression / tools / rotation / rotate_utils.sh
CommitLineData
ef96836c
JR
1#!/bin/bash
2#
9d16b343 3# Copyright (C) 2017 Julien Desfossez <jdesfossez@efficios.com>
ef96836c 4#
9d16b343 5# SPDX-License-Identifier: LGPL-2.1-only
ef96836c 6
9dc506ae
JR
7# Clean everything under directory but keep directory
8function clean_path ()
9{
10 local path=$1
11 # Use -u from bash top prevent empty expansion of variable yielding a
12 # list of current directory from find.
13 set -u
14 find $path -mindepth 1 -maxdepth 1 -exec rm -rf '{}' \;
15 set +u
16}
17
36e66320
JR
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
22#
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.
25function get_chunk_pattern ()
e7716c6a 26{
36e66320
JR
27 local today=$1
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]"
31
32 base_pattern="@(${today}|${tommorow})T${pattern_hour_min_sec}[+-]${pattern_hour_min}"
e7716c6a 33
36e66320 34 # Return the pattern
fc58be13 35 # YYYYMMDDTHHMMSS[+-]HHMM-YYYYMMDDTHHMMSS[+-]HHMM
36e66320 36 echo "${base_pattern}-${base_pattern}"
e7716c6a
JD
37}
38
39function validate_test_chunks ()
40{
41 local_path=$1
42 today=$2
43 app_path=$3
6f7eb8e1
JG
44 shift 3
45 domains=("$@")
e7716c6a 46
c7f64337 47 local path=
36e66320
JR
48 local chunk_pattern=$(get_chunk_pattern ${today})
49
50 # Enable extglob for the use of chunk_pattern
51 shopt -s extglob
e7716c6a 52
7304cc2e 53 # Validate that only 2 chunks are present
c7f64337 54 nb_chunk=$(ls -A $local_path | wc -l)
7304cc2e
JG
55 test $nb_chunk -eq 2
56 ok $? "${local_path} contains 2 chunks only"
c7f64337
JR
57
58 # Check if the first and second chunk folders exist and they contain a ${app_path}/metadata file.
7304cc2e 59 for chunk in $(seq 0 1); do
c7f64337
JR
60 path=$(ls $local_path/${chunk_pattern}-${chunk}/${app_path}/metadata)
61 ok $? "Chunk ${chunk} exists based on path $path"
62 done
63
e7716c6a
JD
64 # Make sure we don't have anything else in the first 2 chunk directories
65 # besides the kernel folder.
7304cc2e 66 for chunk in $(seq 0 1); do
6f7eb8e1
JG
67 local stale_files
68
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)
72 done
73 nr_stale=$(echo -n "$stale_files" | wc -l)
74 ok "$nr_stale" "No stale folders in chunk ${chunk} directory"
3a9c3e86 75 done
e7716c6a 76
c7f64337 77 # We expect a complete session of 30 events
e7716c6a
JD
78 validate_trace_count $EVENT_NAME $local_path 30
79
80 # Chunk 1: 10 events
7304cc2e 81 validate_trace_count $EVENT_NAME $local_path/${chunk_pattern}-0 10
e7716c6a
JD
82
83 # Chunk 2: 20 events
7304cc2e
JG
84 validate_trace_count $EVENT_NAME $local_path/${chunk_pattern}-1 20
85
36e66320 86 shopt -u extglob
e7716c6a
JD
87}
88
89function rotate_timer_test ()
90{
91 local_path=$1
92 per_pid=$2
93
94 today=$(date +%Y%m%d)
95 nr=0
96 nr_iter=0
97 expected_chunks=3
98
3b33e9e7
JG
99 # Wait for the "archives" folder to appear after the first rotation
100 until [ -d $local_path ]; do
101 sleep 1
102 done
103
e7716c6a
JD
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.
110
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))
114 sleep 1
115 done
116 test $nr -ge $expected_chunks
9498e289 117 ok $? "Generated at least $nr chunks in $(($nr_iter))s"
e7716c6a
JD
118 stop_lttng_tracing_ok $SESSION_NAME
119 destroy_lttng_session_ok $SESSION_NAME
120
e7716c6a 121 i=1
36e66320
JR
122 local chunk_pattern=$(get_chunk_pattern ${today})
123
124 # Enable extglob for the use of chunk_pattern
125 shopt -s extglob
e7716c6a
JD
126
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
95a6e8d3 130 validate_trace_empty $local_path/${chunk_pattern}-0
f590975c
MD
131 nr=$(find $local_path/${chunk_pattern}-1/ | wc -l)
132 # contains self and may contain ust/ subdir (local) or not (remote).
133 test $nr -le 2
e7716c6a 134 ok $? "Chunk 2 is empty"
f590975c
MD
135 nr=$(find $local_path/${chunk_pattern}-2/ | wc -l)
136 # contains self and may contain ust/ subdir (local) or not (remote).
137 test $nr -le 2
e7716c6a
JD
138 ok $? "Chunk 3 is empty"
139 else
140 while [ $i -le $expected_chunks ]; do
141 validate_trace_empty $local_path/${chunk_pattern}-$i
142 i=$(($i+1))
9dc506ae
JR
143 done
144 fi
36e66320 145 shopt -u extglob
e7716c6a 146}
bf1e8411 147
34764ec8 148function trace_until_n_archives ()
bf1e8411 149{
34764ec8
JG
150 local produce_events=$1
151 local trace_path=$2
152 local target_archive_count=$3
bf1e8411
JG
153 local archive_count=0
154
155 diag "Waiting for $target_archive_count size-based rotations to occur"
156 while [[ archive_count -lt $target_archive_count ]]
157 do
34764ec8
JG
158 archive_count=$(find "$trace_path" -mindepth 2 -maxdepth 2 -type d -path "*archives*" | wc -l)
159 $produce_events 2000
bf1e8411
JG
160 done
161
162 [[ $archive_count -eq $target_archive_count ]]
163 ok $? "Found $target_archive_count trace archives resulting from trace archive rotations"
164}
This page took 0.044417 seconds and 4 git commands to generate.