Commit | Line | Data |
---|---|---|
ef96836c JR |
1 | #!/bin/bash |
2 | # | |
3 | # Copyright (C) - 2017 Julien Desfossez <jdesfossez@efficios.com> | |
4 | # | |
5 | # This library is free software; you can redistribute it and/or modify it under | |
6 | # the terms of the GNU Lesser General Public License as published by the Free | |
7 | # Software Foundation; version 2.1 of the License. | |
8 | # | |
9 | # This library is distributed in the hope that it will be useful, but WITHOUT | |
10 | # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS | |
11 | # FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more | |
12 | # details. | |
13 | # | |
14 | # You should have received a copy of the GNU Lesser General Public License | |
15 | # along with this library; if not, write to the Free Software Foundation, Inc., | |
16 | # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | |
17 | ||
9dc506ae JR |
18 | # Clean everything under directory but keep directory |
19 | function clean_path () | |
20 | { | |
21 | local path=$1 | |
22 | # Use -u from bash top prevent empty expansion of variable yielding a | |
23 | # list of current directory from find. | |
24 | set -u | |
25 | find $path -mindepth 1 -maxdepth 1 -exec rm -rf '{}' \; | |
26 | set +u | |
27 | } | |
28 | ||
36e66320 JR |
29 | # The extglob shell option must be enabled to use the pattern generated by this |
30 | # function (shopt -s extglob/ shopt -u extglob). | |
31 | # The pattern returned by this function is to validate the form: | |
32 | # YYYYMMDDTHHMMSS[+-]HHMM-YYYYMMDDTHHMMSS[+-]HHMM | |
33 | # | |
34 | # Where YYYYMMDD is today or tomorrow. Tomorrow must be supported in case where | |
35 | # the chunks are generated close to midnight and one ends up the following day. | |
36 | function get_chunk_pattern () | |
e7716c6a | 37 | { |
36e66320 JR |
38 | local today=$1 |
39 | tommorow=$(date +%Y%m%d -d "${today}+1days") | |
40 | pattern_hour_min="[0-9][0-9][0-9][0-9]" | |
41 | pattern_hour_min_sec="${pattern_hour_min}[0-9][0-9]" | |
42 | ||
43 | base_pattern="@(${today}|${tommorow})T${pattern_hour_min_sec}[+-]${pattern_hour_min}" | |
e7716c6a | 44 | |
36e66320 | 45 | # Return the pattern |
fc58be13 | 46 | # YYYYMMDDTHHMMSS[+-]HHMM-YYYYMMDDTHHMMSS[+-]HHMM |
36e66320 | 47 | echo "${base_pattern}-${base_pattern}" |
e7716c6a JD |
48 | } |
49 | ||
50 | function validate_test_chunks () | |
51 | { | |
52 | local_path=$1 | |
53 | today=$2 | |
54 | app_path=$3 | |
55 | domain=$4 | |
56 | per_pid=$5 | |
57 | ||
c7f64337 | 58 | local path= |
36e66320 JR |
59 | local chunk_pattern=$(get_chunk_pattern ${today}) |
60 | ||
61 | # Enable extglob for the use of chunk_pattern | |
62 | shopt -s extglob | |
e7716c6a | 63 | |
d1912efe | 64 | # Validate that only 2 chunks are present |
c7f64337 | 65 | nb_chunk=$(ls -A $local_path | wc -l) |
d1912efe JG |
66 | test $nb_chunk -eq 2 |
67 | ok $? "${local_path} contains 2 chunks only" | |
c7f64337 JR |
68 | |
69 | # Check if the first and second chunk folders exist and they contain a ${app_path}/metadata file. | |
d1912efe | 70 | for chunk in $(seq 0 1); do |
c7f64337 JR |
71 | path=$(ls $local_path/${chunk_pattern}-${chunk}/${app_path}/metadata) |
72 | ok $? "Chunk ${chunk} exists based on path $path" | |
73 | done | |
74 | ||
e7716c6a JD |
75 | # Make sure we don't have anything else in the first 2 chunk directories |
76 | # besides the kernel folder. | |
d1912efe | 77 | for chunk in $(seq 0 1); do |
3a9c3e86 JR |
78 | nr_stale=$(ls -A $local_path/${chunk_pattern}-${chunk} | grep -v $domain | wc -l) |
79 | ok $nr_stale "No stale folders in chunk ${chunk} directory" | |
80 | done | |
e7716c6a | 81 | |
c7f64337 | 82 | # We expect a complete session of 30 events |
e7716c6a JD |
83 | validate_trace_count $EVENT_NAME $local_path 30 |
84 | ||
85 | # Chunk 1: 10 events | |
d1912efe | 86 | validate_trace_count $EVENT_NAME $local_path/${chunk_pattern}-0 10 |
e7716c6a JD |
87 | |
88 | # Chunk 2: 20 events | |
d1912efe JG |
89 | validate_trace_count $EVENT_NAME $local_path/${chunk_pattern}-1 20 |
90 | ||
36e66320 | 91 | shopt -u extglob |
e7716c6a JD |
92 | } |
93 | ||
94 | function rotate_timer_test () | |
95 | { | |
96 | local_path=$1 | |
97 | per_pid=$2 | |
98 | ||
99 | today=$(date +%Y%m%d) | |
100 | nr=0 | |
101 | nr_iter=0 | |
102 | expected_chunks=3 | |
103 | ||
263fa20d JG |
104 | # Wait for the "archives" folder to appear after the first rotation |
105 | until [ -d $local_path ]; do | |
106 | sleep 1 | |
107 | done | |
108 | ||
e7716c6a JD |
109 | # Wait for $expected_chunks to be generated, timeout after |
110 | # 3 * $expected_chunks * 0.5s. | |
111 | # On a laptop with an empty session, a local rotation takes about 200ms, | |
112 | # and a remote rotation takes about 600ms. | |
113 | # We currently set the timeout to 6 seconds for 3 rotations, if we get | |
114 | # errors, we can bump this value. | |
115 | ||
116 | until [ $nr -ge $expected_chunks ] || [ $nr_iter -ge $(($expected_chunks * 2 )) ]; do | |
117 | nr=$(ls $local_path | wc -l) | |
118 | nr_iter=$(($nr_iter+1)) | |
119 | sleep 1 | |
120 | done | |
121 | test $nr -ge $expected_chunks | |
122 | ok $? "Generated $nr chunks in $(($nr_iter))s" | |
123 | stop_lttng_tracing_ok $SESSION_NAME | |
124 | destroy_lttng_session_ok $SESSION_NAME | |
125 | ||
e7716c6a JD |
126 | # Make sure the 10 first chunks are valid empty traces |
127 | i=1 | |
36e66320 JR |
128 | local chunk_pattern=$(get_chunk_pattern ${today}) |
129 | ||
130 | # Enable extglob for the use of chunk_pattern | |
131 | shopt -s extglob | |
e7716c6a JD |
132 | |
133 | # In a per-pid setup, only the first chunk is a valid trace, the other | |
134 | # chunks should be empty folders | |
135 | if test $per_pid = 1; then | |
136 | validate_trace_empty $local_path/${chunk_pattern}-1 | |
137 | nr=$(ls $local_path/${chunk_pattern}-2/ust | wc -l) | |
138 | test $nr = 0 | |
139 | ok $? "Chunk 2 is empty" | |
140 | nr=$(ls $local_path/${chunk_pattern}-3/ust | wc -l) | |
141 | test $nr = 0 | |
142 | ok $? "Chunk 3 is empty" | |
143 | else | |
144 | while [ $i -le $expected_chunks ]; do | |
145 | validate_trace_empty $local_path/${chunk_pattern}-$i | |
146 | i=$(($i+1)) | |
9dc506ae JR |
147 | done |
148 | fi | |
36e66320 | 149 | shopt -u extglob |
e7716c6a | 150 | } |