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 | |
c7f64337 JR |
64 | # Validate that only 3 chunks are present |
65 | nb_chunk=$(ls -A $local_path | wc -l) | |
66 | test $nb_chunk -eq 3 | |
67 | ok $? "${local_path} contains 3 chunks only" | |
68 | ||
69 | # Check if the first and second chunk folders exist and they contain a ${app_path}/metadata file. | |
70 | for chunk in $(seq 1 2); do | |
71 | path=$(ls $local_path/${chunk_pattern}-${chunk}/${app_path}/metadata) | |
72 | ok $? "Chunk ${chunk} exists based on path $path" | |
73 | done | |
74 | ||
75 | # In per-pid the last chunk (3) must be empty. | |
76 | if [ "${per_pid}" -eq "1" ]; then | |
77 | test -z "$(ls -A $local_path/${chunk_pattern}-3/${domain})" | |
78 | ok $? "Chunk 3 is empty per-pid mode" | |
79 | else | |
80 | path=$(ls $local_path/${chunk_pattern}-3/${app_path}/metadata) | |
81 | ok $? "Chunk 3 exists based on path $path" | |
82 | fi | |
e7716c6a JD |
83 | |
84 | # Make sure we don't have anything else in the first 2 chunk directories | |
85 | # besides the kernel folder. | |
3a9c3e86 JR |
86 | for chunk in $(seq 1 2); do |
87 | nr_stale=$(ls -A $local_path/${chunk_pattern}-${chunk} | grep -v $domain | wc -l) | |
88 | ok $nr_stale "No stale folders in chunk ${chunk} directory" | |
89 | done | |
e7716c6a | 90 | |
c7f64337 | 91 | # We expect a complete session of 30 events |
e7716c6a JD |
92 | validate_trace_count $EVENT_NAME $local_path 30 |
93 | ||
94 | # Chunk 1: 10 events | |
95 | validate_trace_count $EVENT_NAME $local_path/${chunk_pattern}-1 10 | |
e7716c6a JD |
96 | |
97 | # Chunk 2: 20 events | |
98 | validate_trace_count $EVENT_NAME $local_path/${chunk_pattern}-2 20 | |
e7716c6a JD |
99 | |
100 | # Chunk 3: 0 event | |
c7f64337 JR |
101 | # Trace for chunk number 3 can only be read in per-uid mode since in |
102 | # per-pid mode it is empty (no metadata or stream files). | |
103 | if test $per_pid = 0; then | |
e7716c6a | 104 | validate_trace_empty $local_path/${chunk_pattern}-3 |
e7716c6a | 105 | fi |
36e66320 | 106 | shopt -u extglob |
e7716c6a JD |
107 | } |
108 | ||
109 | function rotate_timer_test () | |
110 | { | |
111 | local_path=$1 | |
112 | per_pid=$2 | |
113 | ||
114 | today=$(date +%Y%m%d) | |
115 | nr=0 | |
116 | nr_iter=0 | |
117 | expected_chunks=3 | |
118 | ||
119 | # Wait for $expected_chunks to be generated, timeout after | |
120 | # 3 * $expected_chunks * 0.5s. | |
121 | # On a laptop with an empty session, a local rotation takes about 200ms, | |
122 | # and a remote rotation takes about 600ms. | |
123 | # We currently set the timeout to 6 seconds for 3 rotations, if we get | |
124 | # errors, we can bump this value. | |
125 | ||
126 | until [ $nr -ge $expected_chunks ] || [ $nr_iter -ge $(($expected_chunks * 2 )) ]; do | |
127 | nr=$(ls $local_path | wc -l) | |
128 | nr_iter=$(($nr_iter+1)) | |
129 | sleep 1 | |
130 | done | |
131 | test $nr -ge $expected_chunks | |
132 | ok $? "Generated $nr chunks in $(($nr_iter))s" | |
133 | stop_lttng_tracing_ok $SESSION_NAME | |
134 | destroy_lttng_session_ok $SESSION_NAME | |
135 | ||
e7716c6a JD |
136 | # Make sure the 10 first chunks are valid empty traces |
137 | i=1 | |
36e66320 JR |
138 | local chunk_pattern=$(get_chunk_pattern ${today}) |
139 | ||
140 | # Enable extglob for the use of chunk_pattern | |
141 | shopt -s extglob | |
e7716c6a JD |
142 | |
143 | # In a per-pid setup, only the first chunk is a valid trace, the other | |
144 | # chunks should be empty folders | |
145 | if test $per_pid = 1; then | |
146 | validate_trace_empty $local_path/${chunk_pattern}-1 | |
147 | nr=$(ls $local_path/${chunk_pattern}-2/ust | wc -l) | |
148 | test $nr = 0 | |
149 | ok $? "Chunk 2 is empty" | |
150 | nr=$(ls $local_path/${chunk_pattern}-3/ust | wc -l) | |
151 | test $nr = 0 | |
152 | ok $? "Chunk 3 is empty" | |
153 | else | |
154 | while [ $i -le $expected_chunks ]; do | |
155 | validate_trace_empty $local_path/${chunk_pattern}-$i | |
156 | i=$(($i+1)) | |
9dc506ae JR |
157 | done |
158 | fi | |
36e66320 | 159 | shopt -u extglob |
e7716c6a | 160 | } |