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