6f85e293041dc83c53d1a78d524d4fcc7b7915e0
[lttng-tools.git] / tests / regression / tools / rotation / test_kernel
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 TEST_DESC="Rotation - Kernel tracing"
18
19 CURDIR=$(dirname $0)/
20 TESTDIR=$CURDIR/../../..
21 EVENT_NAME="lttng_test_filter_event"
22
23 TRACE_PATH=$(mktemp -d)
24
25 NUM_TESTS=68
26
27 source $TESTDIR/utils/utils.sh
28 source $CURDIR/rotate_utils.sh
29
30 function rotate_kernel_test ()
31 {
32 local_path=$1
33
34 lttng_enable_kernel_event $SESSION_NAME $EVENT_NAME
35 start_lttng_tracing_ok $SESSION_NAME
36
37 today=$(date +%Y%m%d)
38 # First chunk contains 10 events.
39 echo -n "10" > /proc/lttng-test-filter-event
40 rotate_session_ok $SESSION_NAME
41
42 # Second chunk contains 20 events.
43 echo -n "20" > /proc/lttng-test-filter-event
44 stop_lttng_tracing_ok $SESSION_NAME
45
46 # Third chunk contains no event (rotate after stop).
47 rotate_session_ok $SESSION_NAME
48
49 destroy_lttng_session_ok $SESSION_NAME
50
51 # The tests on the chunk folder rely on the date staying the same during
52 # the duration of the test, if this fail we will now why the other checks
53 # fail afterwards. There is a short window of time where an automated test
54 # could fail because of that.
55 now=$(date +%Y%m%d)
56 test $today = $now
57 ok $? "Date did not change during the test"
58
59 validate_test_chunks $local_path $today kernel kernel 0
60 }
61
62 function test_kernel_streaming ()
63 {
64 diag "Test kernel streaming with session rotation"
65 create_lttng_session_uri $SESSION_NAME net://localhost
66 rotate_kernel_test "${TRACE_PATH}/${HOSTNAME}/${SESSION_NAME}*"
67 clean_path $TRACE_PATH
68 }
69
70 function test_kernel_local ()
71 {
72 diag "Test kernel local with session rotation"
73 create_lttng_session_ok $SESSION_NAME $TRACE_PATH
74
75 rotate_kernel_test "${TRACE_PATH}"
76 }
77
78 function test_kernel_local_timer ()
79 {
80 diag "Test kernel local with session rotation timer"
81 create_lttng_session_ok $SESSION_NAME $TRACE_PATH
82 lttng_enable_kernel_event $SESSION_NAME $EVENT_NAME
83 lttng_enable_rotation_timer_ok $SESSION_NAME 500ms
84 start_lttng_tracing_ok $SESSION_NAME
85
86 rotate_timer_test "${TRACE_PATH}" 0
87 }
88
89 function test_kernel_streaming_timer ()
90 {
91 diag "Test kernel remote with session rotation timer"
92 create_lttng_session_uri $SESSION_NAME net://localhost
93 lttng_enable_kernel_event $SESSION_NAME $EVENT_NAME
94 lttng_enable_rotation_timer_ok $SESSION_NAME 500ms
95 start_lttng_tracing_ok $SESSION_NAME
96
97 rotate_timer_test "${TRACE_PATH}/${HOSTNAME}/${SESSION_NAME}*" 0
98 clean_path $TRACE_PATH
99 }
100
101 plan_tests $NUM_TESTS
102
103 print_test_banner "$TEST_DESC"
104
105 if [ "$(id -u)" == "0" ]; then
106 isroot=1
107 else
108 isroot=0
109 fi
110
111 skip $isroot "Root access is needed. Skipping all kernel streaming tests." $NUM_TESTS ||
112 {
113 validate_lttng_modules_present
114
115 start_lttng_relayd "-o $TRACE_PATH"
116 start_lttng_sessiond
117 modprobe lttng-test
118
119 tests=( test_kernel_streaming test_kernel_local test_kernel_local_timer test_kernel_streaming_timer)
120
121 for fct_test in ${tests[@]};
122 do
123 SESSION_NAME=$(randstring 16 0)
124 ${fct_test}
125 done
126
127 rmmod lttng-test
128 stop_lttng_sessiond
129 stop_lttng_relayd
130 }
131
132 rm -rf $TRACE_PATH
This page took 0.046916 seconds and 3 git commands to generate.