Test: lttng clear command for snapshot session
[lttng-tools.git] / tests / regression / tools / clear / test_kernel
CommitLineData
806530f2
JR
1#!/bin/bash
2#
3# Copyright (C) - 2019 Jonathan Rajotte-Julien <jonathan.rajotte-julien@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
18TEST_DESC="Clear - Kernel tracing"
19
20CURDIR=$(dirname $0)/
21TESTDIR=$CURDIR/../../..
22EVENT_NAME="lttng_test_filter_event"
23
24TRACE_PATH=$(mktemp -d)
25
26NUM_TESTS=55
27
28source $TESTDIR/utils/utils.sh
29
30function clean_path ()
31{
32 local trace_path=$1
33 set -u
34 rm -rf $trace_path/*
35 set +u
36}
37
38function test_kernel_streaming ()
39{
40 diag "Test kernel streaming clear"
41 create_lttng_session_uri $SESSION_NAME net://localhost
42 lttng_enable_kernel_event $SESSION_NAME $EVENT_NAME
43 start_lttng_tracing_ok $SESSION_NAME
44 # TODO: place holder, support for streaming MUST be implemented
45 # This validate that for now we fail correctly
46 lttng_clear_session_fail $SESSION_NAME
47
48 destroy_lttng_session_ok $SESSION_NAME
49}
50
51function test_kernel_streaming_live ()
52{
53 diag "Test kernel streaming live clear"
54 create_lttng_session_uri $SESSION_NAME net://localhost "--live"
55 lttng_enable_kernel_event $SESSION_NAME $EVENT_NAME
56 start_lttng_tracing_ok $SESSION_NAME
57 # TODO: place holder, support for streaming MUST be implemented
58 # This validate that for now we fail correctly
59 lttng_clear_session_fail $SESSION_NAME
60
61 destroy_lttng_session_ok $SESSION_NAME
62}
63
64function test_kernel_local ()
65{
66 diag "Test kernel local"
67 create_lttng_session_ok $SESSION_NAME $TRACE_PATH
68 lttng_enable_kernel_event $SESSION_NAME $EVENT_NAME
69 start_lttng_tracing_ok $SESSION_NAME
70 # TODO: place holder, support for local MUST be implemented
71 lttng_clear_session_fail $SESSION_NAME
72 # TODO: validate that the previous chunk IS no more present
73
74 destroy_lttng_session_ok $SESSION_NAME
75}
76
77function do_kernel_snapshot ()
78{
79 local session_name=$1
80 local trace_path=$2
81
82 lttng_enable_kernel_event $session_name $EVENT_NAME
83 start_lttng_tracing_ok $session_name
84
85 # Generate 10 events that will sit in the buffers.
86 echo -n "10" > /proc/lttng-test-filter-event
87
88 # Take a first snapshot and validate that the events are present.
89 lttng_snapshot_record $session_name
90 stop_lttng_tracing_ok $session_name
91 validate_trace_count $EVENT_NAME $trace_path 10
92
93 # Clean the output path
94 clean_path $trace_path
95 start_lttng_tracing_ok $session_name
96
97 lttng_clear_session_ok $session_name
98
99 # Make sure the subsequent snapshot is empty and valid.
100 lttng_snapshot_record $session_name
101 stop_lttng_tracing_ok $session_name
102 validate_trace_empty $trace_path
103
104 # Clean the output path
105 clean_path $trace_path
106 start_lttng_tracing_ok $session_name
107
108 # Make sure that everything still works, generate events and take a
109 # snapshot.
110 echo -n "10" > /proc/lttng-test-filter-event
111 lttng_snapshot_record $session_name
112 stop_lttng_tracing_ok $session_name
113 validate_trace_count $EVENT_NAME $trace_path 10
114}
115
116function test_kernel_streaming_snapshot ()
117{
118 diag "Test kernel streaming snapshot clear"
119
120 create_lttng_session_uri $SESSION_NAME net://localhost "--snapshot"
121 do_kernel_snapshot $SESSION_NAME $TRACE_PATH
122 destroy_lttng_session_ok $SESSION_NAME
123}
124
125function test_kernel_local_snapshot ()
126{
127 diag "Test kernel local snapshot clear"
128
129 create_lttng_session_ok $SESSION_NAME $TRACE_PATH "--snapshot"
130 do_kernel_snapshot $SESSION_NAME $TRACE_PATH
131 destroy_lttng_session_ok $SESSION_NAME
132}
133
134plan_tests $NUM_TESTS
135
136print_test_banner "$TEST_DESC"
137
138if [ "$(id -u)" == "0" ]; then
139 isroot=1
140else
141 isroot=0
142fi
143
144tests=( test_kernel_streaming
145 test_kernel_streaming_live
146 test_kernel_local
147 test_kernel_streaming_snapshot
148 test_kernel_local_snapshot
149)
150
151skip $isroot "Root access is needed. Skipping all kernel streaming tests." $NUM_TESTS ||
152{
153 validate_lttng_modules_present
154
155 start_lttng_relayd "-o $TRACE_PATH"
156 start_lttng_sessiond
157 modprobe lttng-test
158
159 for fct_test in ${tests[@]};
160 do
161 SESSION_NAME=$(randstring 16 0)
162 ${fct_test}
163 clean_path $TRACE_PATH
164 done
165
166 rmmod lttng-test
167 stop_lttng_sessiond
168 stop_lttng_relayd
169}
170
171clean_path $TRACE_PATH
This page took 0.030696 seconds and 5 git commands to generate.