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