Tests: clean-up: remove trailing dot in snapshot test statements
[lttng-tools.git] / tests / regression / tools / snapshots / test_kernel_streaming
CommitLineData
26402e0c
DG
1#!/bin/bash
2#
9d16b343 3# Copyright (C) 2013 David Goulet <dgoulet@efficios.com>
26402e0c 4#
9d16b343
MJ
5# SPDX-License-Identifier: LGPL-2.1-only
6
26402e0c
DG
7TEST_DESC="Streaming - Snapshot Kernel tracing"
8
9CURDIR=$(dirname $0)/
10TESTDIR=$CURDIR/../../..
11EVENT_NAME="sched_switch"
26402e0c
DG
12SESSION_NAME=""
13CHANNEL_NAME="chan1"
14
15TRACE_PATH=$(mktemp -d)
16
b61ccd96 17NUM_TESTS=61
26402e0c
DG
18
19source $TESTDIR/utils/utils.sh
20
26402e0c
DG
21function snapshot_add_output ()
22{
23 local sess_name=$1
24 local trace_path=$2
25 local name=$3
26 local extra_opt=""
27
28 if [ ! -z $name ]; then
29 extra_opt="-n $name"
30 fi
31
32 $TESTDIR/../src/bin/lttng/$LTTNG_BIN snapshot add-output -s $sess_name $extra_opt $trace_path >/dev/null 2>&1
33 ok $? "Added snapshot output $trace_path"
34}
35
36# Test a snapshot using a default name for the output destination.
37function test_kernel_default_name_with_del()
38{
39 diag "Test kernel snapshot streaming with default name with delete output"
40 create_lttng_session_no_output $SESSION_NAME
41 enable_lttng_mmap_overwrite_kernel_channel $SESSION_NAME $CHANNEL_NAME
42 lttng_enable_kernel_event $SESSION_NAME $EVENT_NAME $CHANNEL_NAME
e563bbdb 43 start_lttng_tracing_ok $SESSION_NAME
26402e0c
DG
44 snapshot_add_output $SESSION_NAME "net://localhost"
45 lttng_snapshot_record $SESSION_NAME
46
47 # Validate test
b178f53e 48 validate_trace $EVENT_NAME $TRACE_PATH/$HOSTNAME/$SESSION_NAME*/snapshot-1*
26402e0c
DG
49 if [ $? -ne 0 ]; then
50 return $?
51 fi
52
31580dc7 53 lttng_snapshot_del_output_ok $SESSION_NAME 1
26402e0c 54 snapshot_add_output $SESSION_NAME "net://localhost"
26402e0c
DG
55 lttng_snapshot_record $SESSION_NAME
56
57 # Validate test with the next ID since a del output was done prior.
b178f53e 58 validate_trace $EVENT_NAME $TRACE_PATH/$HOSTNAME/$SESSION_NAME*/snapshot-2*
26402e0c
DG
59 if [ $? -ne 0 ]; then
60 return $?
61 fi
62
96340a01 63 stop_lttng_tracing_ok $SESSION_NAME
67b4c664 64 destroy_lttng_session_ok $SESSION_NAME
26402e0c
DG
65
66 return 0
67}
68
69# Test a snapshot using a default name for the output destination.
70function test_kernel_default_name()
71{
72 diag "Test kernel snapshot streaming with default name"
73 create_lttng_session_no_output $SESSION_NAME
74 enable_lttng_mmap_overwrite_kernel_channel $SESSION_NAME $CHANNEL_NAME
75 lttng_enable_kernel_event $SESSION_NAME $EVENT_NAME $CHANNEL_NAME
e563bbdb 76 start_lttng_tracing_ok $SESSION_NAME
26402e0c
DG
77 snapshot_add_output $SESSION_NAME "net://localhost"
78 lttng_snapshot_record $SESSION_NAME
96340a01 79 stop_lttng_tracing_ok $SESSION_NAME
67b4c664 80 destroy_lttng_session_ok $SESSION_NAME
26402e0c 81 # Validate test
b178f53e 82 validate_trace $EVENT_NAME $TRACE_PATH/$HOSTNAME/$SESSION_NAME*/snapshot-1*
26402e0c
DG
83 out=$?
84
85 return $out
86}
87
88# Test a snapshot using a custom name for the output destination.
89function test_kernel_custom_name()
90{
91 local out
92 local name="asnapshotname"
93
94 diag "Test kernel snapshot streaming with custom name"
95 create_lttng_session_no_output $SESSION_NAME
96 enable_lttng_mmap_overwrite_kernel_channel $SESSION_NAME $CHANNEL_NAME
97 lttng_enable_kernel_event $SESSION_NAME $EVENT_NAME $CHANNEL_NAME
e563bbdb 98 start_lttng_tracing_ok $SESSION_NAME
26402e0c
DG
99 snapshot_add_output $SESSION_NAME "net://localhost" $name
100 lttng_snapshot_record $SESSION_NAME
96340a01 101 stop_lttng_tracing_ok $SESSION_NAME
67b4c664 102 destroy_lttng_session_ok $SESSION_NAME
26402e0c 103
b178f53e 104 if ls $TRACE_PATH/$HOSTNAME/$SESSION_NAME*/$name* &> /dev/null; then
26402e0c
DG
105 ok 0 "Custom name snapshot exists"
106 # Validate test
b178f53e 107 validate_trace $EVENT_NAME $TRACE_PATH/$HOSTNAME/$SESSION_NAME*/$name-*
26402e0c
DG
108 out=$?
109 else
110 fail "No custom name snapshot found"
111 out=1
112 fi
113
114 return $out
115}
116
b61ccd96
JR
117function test_kernel_n_snapshot()
118{
119 diag "Test kernel snapshot streaming multiple consecutive snapshot"
120 create_lttng_session_no_output $SESSION_NAME
121 enable_lttng_mmap_overwrite_kernel_channel $SESSION_NAME $CHANNEL_NAME
122 lttng_enable_kernel_event $SESSION_NAME $EVENT_NAME $CHANNEL_NAME
123 snapshot_add_output $SESSION_NAME "net://localhost"
124
125 for i in {1..5};
126 do
127 start_lttng_tracing_ok $SESSION_NAME
128 lttng_snapshot_record $SESSION_NAME
129 stop_lttng_tracing_ok $SESSION_NAME
b178f53e 130 validate_trace $EVENT_NAME $TRACE_PATH/$HOSTNAME/$SESSION_NAME*/snapshot-1*
b61ccd96
JR
131 if [ $? -ne 0 ]; then
132 return 1
133 fi
134 set -u
135 rm -rf $TRACE_PATH/$HOSTNAME
136 set +u
137 done
138
139 destroy_lttng_session_ok $SESSION_NAME
140 return 0
141}
142
26402e0c
DG
143plan_tests $NUM_TESTS
144
145print_test_banner "$TEST_DESC"
146
147if [ "$(id -u)" == "0" ]; then
148 isroot=1
149else
150 isroot=0
151fi
152
ce83431d 153skip $isroot "Root access is needed. Skipping all kernel streaming tests" $NUM_TESTS ||
26402e0c 154{
9c8a3964
JR
155 validate_lttng_modules_present
156
26402e0c
DG
157 start_lttng_relayd "-o $TRACE_PATH"
158 start_lttng_sessiond
159
b61ccd96
JR
160 tests=( test_kernel_default_name
161 test_kernel_custom_name
162 test_kernel_default_name_with_del
163 test_kernel_n_snapshot
164 )
26402e0c
DG
165
166 for fct_test in ${tests[@]};
167 do
168 SESSION_NAME=$(randstring 16 0)
169 ${fct_test}
170 if [ $? -eq 0 ]; then
171 # Only delete if successful
25d6f007 172 rm -rf $TRACE_PATH
26402e0c
DG
173 else
174 break
175 fi
176 done
177
178 stop_lttng_sessiond
179 stop_lttng_relayd
180}
This page took 0.044266 seconds and 4 git commands to generate.