9c19e29b69dc2460d4c534b4203b48d322a719e0
[lttng-tools.git] / tests / regression / tools / rotation / rotate_utils.sh
1 # Clean everything under directory but keep directory
2 function clean_path ()
3 {
4 local path=$1
5 # Use -u from bash top prevent empty expansion of variable yielding a
6 # list of current directory from find.
7 set -u
8 find $path -mindepth 1 -maxdepth 1 -exec rm -rf '{}' \;
9 set +u
10 }
11
12 function set_chunk_pattern ()
13 {
14 # Need to call this function after $today has been set.
15
16 # YYYYMMDDTHHMMSS[+-]HHMM-YYYYMMDDTHHMMSS[+-]HHMM
17 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]"
18 }
19
20 function validate_test_chunks ()
21 {
22 local_path=$1
23 today=$2
24 app_path=$3
25 domain=$4
26 per_pid=$5
27
28 set_chunk_pattern
29
30 # Check if the 3 chunk folders exist and they contain a ${app_path}/metadata file.
31 ls $local_path/${chunk_pattern}-1/${app_path}/metadata >/dev/null
32 ok $? "Chunk 1 exists"
33 ls $local_path/${chunk_pattern}-2/${app_path}/metadata >/dev/null
34 ok $? "Chunk 2 exists"
35 ls $local_path/${chunk_pattern}-3/${domain} >/dev/null
36 ok $? "Chunk 3 exists"
37
38 # Make sure we don't have anything else in the first 2 chunk directories
39 # besides the kernel folder.
40 nr_stale=$(\ls $local_path/${chunk_pattern}-1 | grep -v $domain | wc -l)
41 ok $nr_stale "No stale folders in chunk 1 directory"
42 nr_stale=$(\ls $local_path/${chunk_pattern}-2 | grep -v $domain | wc -l)
43 ok $nr_stale "No stale folders in chunk 2 directory"
44
45 # We expect a session of 30 events
46 validate_trace_count $EVENT_NAME $local_path 30
47
48 # Chunk 1: 10 events
49 validate_trace_count $EVENT_NAME $local_path/${chunk_pattern}-1 10
50 if [ $? -eq 0 ]; then
51 # Only delete if successful
52 rm -rf $local_path/${chunk_pattern}-1
53 fi
54
55 # Chunk 2: 20 events
56 validate_trace_count $EVENT_NAME $local_path/${chunk_pattern}-2 20
57 if [ $? -eq 0 ]; then
58 # Only delete if successful
59 rm -rf $local_path/${chunk_pattern}-2
60 fi
61
62 # Chunk 3: 0 event
63 # Do not check in per-pid, because the folder is really empty, no metadata
64 # or stream files.
65 if test $per_pid = 1; then
66 rm -rf $local_path/${chunk_pattern}-3
67 else
68 validate_trace_empty $local_path/${chunk_pattern}-3
69 if [ $? -eq 0 ]; then
70 # Only delete if successful
71 rm -rf $local_path/${chunk_pattern}-3
72 fi
73 fi
74
75 # The session folder after all chunks have been removed is empty
76 test -z "$(\ls -A $local_path)"
77 empty=$?
78 ok $empty "Trace folder is now empty"
79 }
80
81 function rotate_timer_test ()
82 {
83 local_path=$1
84 per_pid=$2
85
86 today=$(date +%Y%m%d)
87 nr=0
88 nr_iter=0
89 expected_chunks=3
90
91 # Wait for $expected_chunks to be generated, timeout after
92 # 3 * $expected_chunks * 0.5s.
93 # On a laptop with an empty session, a local rotation takes about 200ms,
94 # and a remote rotation takes about 600ms.
95 # We currently set the timeout to 6 seconds for 3 rotations, if we get
96 # errors, we can bump this value.
97
98 until [ $nr -ge $expected_chunks ] || [ $nr_iter -ge $(($expected_chunks * 2 )) ]; do
99 nr=$(ls $local_path | wc -l)
100 nr_iter=$(($nr_iter+1))
101 sleep 1
102 done
103 test $nr -ge $expected_chunks
104 ok $? "Generated $nr chunks in $(($nr_iter))s"
105 stop_lttng_tracing_ok $SESSION_NAME
106 destroy_lttng_session_ok $SESSION_NAME
107
108 now=$(date +%Y%m%d)
109 test $today = $now
110 ok $? "Date did not change during the test"
111
112 # Make sure the 10 first chunks are valid empty traces
113 i=1
114 set_chunk_pattern
115
116 # In a per-pid setup, only the first chunk is a valid trace, the other
117 # chunks should be empty folders
118 if test $per_pid = 1; then
119 validate_trace_empty $local_path/${chunk_pattern}-1
120 nr=$(ls $local_path/${chunk_pattern}-2/ust | wc -l)
121 test $nr = 0
122 ok $? "Chunk 2 is empty"
123 nr=$(ls $local_path/${chunk_pattern}-3/ust | wc -l)
124 test $nr = 0
125 ok $? "Chunk 3 is empty"
126 else
127 while [ $i -le $expected_chunks ]; do
128 validate_trace_empty $local_path/${chunk_pattern}-$i
129 i=$(($i+1))
130 done
131 fi
132 }
This page took 0.032297 seconds and 3 git commands to generate.