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