Refactor: test: wrapper for lttng_snapshot_add_output
[lttng-tools.git] / tests / regression / tools / snapshots / test_kernel
1 #!/bin/bash
2 #
3 # Copyright (C) - 2013 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="Snapshots - Kernel tracing"
18
19 CURDIR=$(dirname $0)/
20 TESTDIR=$CURDIR/../../..
21 EVENT_NAME="sched_switch"
22 PID_RELAYD=0
23 SESSION_NAME=""
24 CHANNEL_NAME="snapchan"
25
26 TRACE_PATH=$(mktemp -d)
27
28 NUM_TESTS=2040
29
30 source $TESTDIR/utils/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 test_kernel_local_snapshot ()
39 {
40 diag "Test local kernel snapshots"
41 create_lttng_session_no_output $SESSION_NAME
42 enable_lttng_mmap_overwrite_kernel_channel $SESSION_NAME $CHANNEL_NAME
43 lttng_enable_kernel_event $SESSION_NAME $EVENT_NAME $CHANNEL_NAME
44 start_lttng_tracing_ok $SESSION_NAME
45 lttng_snapshot_add_output_ok $SESSION_NAME $TRACE_PATH
46 lttng_snapshot_record $SESSION_NAME
47 stop_lttng_tracing_ok $SESSION_NAME
48 destroy_lttng_session_ok $SESSION_NAME
49
50 # Validate test
51 validate_trace $EVENT_NAME $TRACE_PATH/
52 if [ $? -eq 0 ]; then
53 # Only delete if successful
54 rm -rf $TRACE_PATH
55 else
56 break
57 fi
58 }
59
60 function test_kernel_local_snapshot_after_stop ()
61 {
62 diag "Test local kernel snapshots after stop"
63 create_lttng_session_no_output $SESSION_NAME
64 enable_lttng_mmap_overwrite_kernel_channel $SESSION_NAME $CHANNEL_NAME
65 lttng_enable_kernel_event $SESSION_NAME $EVENT_NAME $CHANNEL_NAME
66 start_lttng_tracing_ok $SESSION_NAME
67 stop_lttng_tracing_ok $SESSION_NAME
68 lttng_snapshot_add_output_ok $SESSION_NAME $TRACE_PATH
69 lttng_snapshot_record $SESSION_NAME
70 destroy_lttng_session_ok $SESSION_NAME
71
72 # Validate test
73 validate_trace $EVENT_NAME $TRACE_PATH/
74 if [ $? -eq 0 ]; then
75 # Only delete if successful
76 rm -rf $TRACE_PATH
77 else
78 break
79 fi
80 }
81
82 function test_kernel_local_snapshot_append_to_metadata ()
83 {
84 local EVENT1=sched_switch
85 local EVENT2=sched_process_exit
86
87 diag "Test local kernel snapshots with one event $EVENT1"
88 create_lttng_session_no_output $SESSION_NAME
89 enable_lttng_mmap_overwrite_kernel_channel $SESSION_NAME $CHANNEL_NAME
90 lttng_enable_kernel_event $SESSION_NAME $EVENT1 $CHANNEL_NAME
91 start_lttng_tracing_ok $SESSION_NAME
92 lttng_snapshot_add_output_ok $SESSION_NAME $TRACE_PATH
93
94 # first snapshot with only 1 event
95 lttng_snapshot_record $SESSION_NAME
96 validate_trace $EVENT_NAME $TRACE_PATH/
97 if [ $? -eq 0 ]; then
98 # Only delete if successful
99 rm -rf $TRACE_PATH
100 else
101 break
102 fi
103
104 diag "Adding event $EVENT2"
105 # second snapshot with 2 events
106 lttng_enable_kernel_event $SESSION_NAME $EVENT2 $CHANNEL_NAME
107 rm -rf $TRACE_PATH/snapshot/* 2>/dev/null
108 lttng_snapshot_record $SESSION_NAME
109 validate_trace "${EVENT1},${EVENT2}" $TRACE_PATH/
110 if [ $? -eq 0 ]; then
111 # Only delete if successful
112 rm -rf $TRACE_PATH
113 else
114 break
115 fi
116
117 stop_lttng_tracing_ok $SESSION_NAME
118 destroy_lttng_session_ok $SESSION_NAME
119 }
120
121 function test_kernel_1000_local_snapshots ()
122 {
123 NB_SNAP=1000
124
125 diag "Test local kernel snapshots"
126 create_lttng_session_no_output $SESSION_NAME
127 enable_lttng_mmap_overwrite_kernel_channel $SESSION_NAME $CHANNEL_NAME
128 lttng_enable_kernel_event $SESSION_NAME $EVENT_NAME $CHANNEL_NAME
129 start_lttng_tracing_ok $SESSION_NAME
130 lttng_snapshot_add_output_ok $SESSION_NAME $TRACE_PATH
131 for i in $(seq 1 $NB_SNAP); do
132 diag "Snapshot $i/$NB_SNAP"
133 rm -rf $TRACE_PATH/snapshot/* 2>/dev/null
134 lttng_snapshot_record $SESSION_NAME
135 # Validate test
136 validate_trace $EVENT_NAME $TRACE_PATH/
137 if [ $? -eq 0 ]; then
138 # Only delete if successful
139 rm -rf $TRACE_PATH
140 else
141 break
142 fi
143 done
144 stop_lttng_tracing_ok $SESSION_NAME
145 destroy_lttng_session_ok $SESSION_NAME
146 }
147
148 plan_tests $NUM_TESTS
149
150 print_test_banner "$TEST_DESC"
151
152 if [ "$(id -u)" == "0" ]; then
153 isroot=1
154 else
155 isroot=0
156 fi
157
158 skip $isroot "Root access is needed. Skipping all kernel snapshot tests." $NUM_TESTS ||
159 {
160 start_lttng_sessiond
161
162 #tests=( test_kernel_1000_local_snapshots )
163 tests=( test_kernel_local_snapshot test_kernel_local_snapshot_after_stop test_kernel_local_snapshot_append_to_metadata test_kernel_1000_local_snapshots )
164
165 for fct_test in ${tests[@]};
166 do
167 SESSION_NAME=$(randstring 16 0)
168 ${fct_test}
169
170 done
171
172 stop_lttng_sessiond
173 }
This page took 0.034827 seconds and 5 git commands to generate.