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 | |
46 | ||
47 | # Check if the 3 chunk folders exist and they contain a ${app_path}/metadata file. | |
48 | ls $local_path/${chunk_pattern}-1/${app_path}/metadata >/dev/null | |
49 | ok $? "Chunk 1 exists" | |
50 | ls $local_path/${chunk_pattern}-2/${app_path}/metadata >/dev/null | |
51 | ok $? "Chunk 2 exists" | |
52 | ls $local_path/${chunk_pattern}-3/${domain} >/dev/null | |
53 | ok $? "Chunk 3 exists" | |
54 | ||
55 | # Make sure we don't have anything else in the first 2 chunk directories | |
56 | # besides the kernel folder. | |
57 | nr_stale=$(\ls $local_path/${chunk_pattern}-1 | grep -v $domain | wc -l) | |
58 | ok $nr_stale "No stale folders in chunk 1 directory" | |
59 | nr_stale=$(\ls $local_path/${chunk_pattern}-2 | grep -v $domain | wc -l) | |
60 | ok $nr_stale "No stale folders in chunk 2 directory" | |
61 | ||
62 | # We expect a session of 30 events | |
63 | validate_trace_count $EVENT_NAME $local_path 30 | |
64 | ||
65 | # Chunk 1: 10 events | |
66 | validate_trace_count $EVENT_NAME $local_path/${chunk_pattern}-1 10 | |
67 | if [ $? -eq 0 ]; then | |
68 | # Only delete if successful | |
69 | rm -rf $local_path/${chunk_pattern}-1 | |
70 | fi | |
71 | ||
72 | # Chunk 2: 20 events | |
73 | validate_trace_count $EVENT_NAME $local_path/${chunk_pattern}-2 20 | |
74 | if [ $? -eq 0 ]; then | |
75 | # Only delete if successful | |
76 | rm -rf $local_path/${chunk_pattern}-2 | |
77 | fi | |
78 | ||
79 | # Chunk 3: 0 event | |
80 | # Do not check in per-pid, because the folder is really empty, no metadata | |
81 | # or stream files. | |
82 | if test $per_pid = 1; then | |
83 | rm -rf $local_path/${chunk_pattern}-3 | |
84 | else | |
85 | validate_trace_empty $local_path/${chunk_pattern}-3 | |
86 | if [ $? -eq 0 ]; then | |
87 | # Only delete if successful | |
88 | rm -rf $local_path/${chunk_pattern}-3 | |
89 | fi | |
90 | fi | |
91 | ||
92 | # The session folder after all chunks have been removed is empty | |
93 | test -z "$(\ls -A $local_path)" | |
94 | empty=$? | |
95 | ok $empty "Trace folder is now empty" | |
e7716c6a JD |
96 | } |
97 | ||
98 | function rotate_timer_test () | |
99 | { | |
100 | local_path=$1 | |
101 | per_pid=$2 | |
102 | ||
103 | today=$(date +%Y%m%d) | |
104 | nr=0 | |
105 | nr_iter=0 | |
106 | expected_chunks=3 | |
107 | ||
108 | # Wait for $expected_chunks to be generated, timeout after | |
109 | # 3 * $expected_chunks * 0.5s. | |
110 | # On a laptop with an empty session, a local rotation takes about 200ms, | |
111 | # and a remote rotation takes about 600ms. | |
112 | # We currently set the timeout to 6 seconds for 3 rotations, if we get | |
113 | # errors, we can bump this value. | |
114 | ||
115 | until [ $nr -ge $expected_chunks ] || [ $nr_iter -ge $(($expected_chunks * 2 )) ]; do | |
116 | nr=$(ls $local_path | wc -l) | |
117 | nr_iter=$(($nr_iter+1)) | |
118 | sleep 1 | |
119 | done | |
120 | test $nr -ge $expected_chunks | |
121 | ok $? "Generated $nr chunks in $(($nr_iter))s" | |
122 | stop_lttng_tracing_ok $SESSION_NAME | |
123 | destroy_lttng_session_ok $SESSION_NAME | |
124 | ||
125 | now=$(date +%Y%m%d) | |
126 | test $today = $now | |
127 | ok $? "Date did not change during the test" | |
128 | ||
129 | # Make sure the 10 first chunks are valid empty traces | |
130 | i=1 | |
131 | set_chunk_pattern | |
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 | |
e7716c6a | 149 | } |