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 | ||
e7716c6a JD |
29 | function set_chunk_pattern () |
30 | { | |
31 | # Need to call this function after $today has been set. | |
32 | ||
fc58be13 JD |
33 | # YYYYMMDDTHHMMSS[+-]HHMM-YYYYMMDDTHHMMSS[+-]HHMM |
34 | export chunk_pattern="${today}T[0-9][0-9][0-9][0-9][0-9][0-9][+-][0-9][0-9][0-9][0-9]-${today}T[0-9][0-9][0-9][0-9][0-9][0-9][+-][0-9][0-9][0-9][0-9]" | |
e7716c6a JD |
35 | } |
36 | ||
37 | function validate_test_chunks () | |
38 | { | |
39 | local_path=$1 | |
40 | today=$2 | |
41 | app_path=$3 | |
42 | domain=$4 | |
43 | per_pid=$5 | |
44 | ||
45 | set_chunk_pattern | |
c7f64337 | 46 | local path= |
e7716c6a | 47 | |
c7f64337 JR |
48 | # Validate that only 3 chunks are present |
49 | nb_chunk=$(ls -A $local_path | wc -l) | |
50 | test $nb_chunk -eq 3 | |
51 | ok $? "${local_path} contains 3 chunks only" | |
52 | ||
53 | # Check if the first and second chunk folders exist and they contain a ${app_path}/metadata file. | |
54 | for chunk in $(seq 1 2); do | |
55 | path=$(ls $local_path/${chunk_pattern}-${chunk}/${app_path}/metadata) | |
56 | ok $? "Chunk ${chunk} exists based on path $path" | |
57 | done | |
58 | ||
59 | # In per-pid the last chunk (3) must be empty. | |
60 | if [ "${per_pid}" -eq "1" ]; then | |
61 | test -z "$(ls -A $local_path/${chunk_pattern}-3/${domain})" | |
62 | ok $? "Chunk 3 is empty per-pid mode" | |
63 | else | |
64 | path=$(ls $local_path/${chunk_pattern}-3/${app_path}/metadata) | |
65 | ok $? "Chunk 3 exists based on path $path" | |
66 | fi | |
e7716c6a JD |
67 | |
68 | # Make sure we don't have anything else in the first 2 chunk directories | |
69 | # besides the kernel folder. | |
3a9c3e86 JR |
70 | for chunk in $(seq 1 2); do |
71 | nr_stale=$(ls -A $local_path/${chunk_pattern}-${chunk} | grep -v $domain | wc -l) | |
72 | ok $nr_stale "No stale folders in chunk ${chunk} directory" | |
73 | done | |
e7716c6a | 74 | |
c7f64337 | 75 | # We expect a complete session of 30 events |
e7716c6a JD |
76 | validate_trace_count $EVENT_NAME $local_path 30 |
77 | ||
78 | # Chunk 1: 10 events | |
79 | validate_trace_count $EVENT_NAME $local_path/${chunk_pattern}-1 10 | |
e7716c6a JD |
80 | |
81 | # Chunk 2: 20 events | |
82 | validate_trace_count $EVENT_NAME $local_path/${chunk_pattern}-2 20 | |
e7716c6a JD |
83 | |
84 | # Chunk 3: 0 event | |
c7f64337 JR |
85 | # Trace for chunk number 3 can only be read in per-uid mode since in |
86 | # per-pid mode it is empty (no metadata or stream files). | |
87 | if test $per_pid = 0; then | |
e7716c6a | 88 | validate_trace_empty $local_path/${chunk_pattern}-3 |
e7716c6a | 89 | fi |
e7716c6a JD |
90 | } |
91 | ||
92 | function rotate_timer_test () | |
93 | { | |
94 | local_path=$1 | |
95 | per_pid=$2 | |
96 | ||
97 | today=$(date +%Y%m%d) | |
98 | nr=0 | |
99 | nr_iter=0 | |
100 | expected_chunks=3 | |
101 | ||
102 | # Wait for $expected_chunks to be generated, timeout after | |
103 | # 3 * $expected_chunks * 0.5s. | |
104 | # On a laptop with an empty session, a local rotation takes about 200ms, | |
105 | # and a remote rotation takes about 600ms. | |
106 | # We currently set the timeout to 6 seconds for 3 rotations, if we get | |
107 | # errors, we can bump this value. | |
108 | ||
109 | until [ $nr -ge $expected_chunks ] || [ $nr_iter -ge $(($expected_chunks * 2 )) ]; do | |
110 | nr=$(ls $local_path | wc -l) | |
111 | nr_iter=$(($nr_iter+1)) | |
112 | sleep 1 | |
113 | done | |
114 | test $nr -ge $expected_chunks | |
115 | ok $? "Generated $nr chunks in $(($nr_iter))s" | |
116 | stop_lttng_tracing_ok $SESSION_NAME | |
117 | destroy_lttng_session_ok $SESSION_NAME | |
118 | ||
119 | now=$(date +%Y%m%d) | |
120 | test $today = $now | |
121 | ok $? "Date did not change during the test" | |
122 | ||
123 | # Make sure the 10 first chunks are valid empty traces | |
124 | i=1 | |
125 | set_chunk_pattern | |
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 | |
130 | validate_trace_empty $local_path/${chunk_pattern}-1 | |
131 | nr=$(ls $local_path/${chunk_pattern}-2/ust | wc -l) | |
132 | test $nr = 0 | |
133 | ok $? "Chunk 2 is empty" | |
134 | nr=$(ls $local_path/${chunk_pattern}-3/ust | wc -l) | |
135 | test $nr = 0 | |
136 | ok $? "Chunk 3 is empty" | |
137 | else | |
138 | while [ $i -le $expected_chunks ]; do | |
139 | validate_trace_empty $local_path/${chunk_pattern}-$i | |
140 | i=$(($i+1)) | |
9dc506ae JR |
141 | done |
142 | fi | |
e7716c6a | 143 | } |