port: add support for BSD mktemp
[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
8d5a3312 15TRACE_PATH=$(mktemp -d -t tmp.test_snapshots_kernel_streaming_trace_path.XXXXXX)
26402e0c 16
bd666153 17NUM_TESTS=66
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
bd666153 130 validate_trace_path_kernel_snapshot_network "$TRACE_PATH" "$SESSION_NAME" "snapshot-1" $(( i - 1 )) ""
b178f53e 131 validate_trace $EVENT_NAME $TRACE_PATH/$HOSTNAME/$SESSION_NAME*/snapshot-1*
b61ccd96
JR
132 if [ $? -ne 0 ]; then
133 return 1
134 fi
135 set -u
136 rm -rf $TRACE_PATH/$HOSTNAME
137 set +u
138 done
139
140 destroy_lttng_session_ok $SESSION_NAME
141 return 0
142}
143
26402e0c
DG
144plan_tests $NUM_TESTS
145
146print_test_banner "$TEST_DESC"
147
148if [ "$(id -u)" == "0" ]; then
149 isroot=1
150else
151 isroot=0
152fi
153
ce83431d 154skip $isroot "Root access is needed. Skipping all kernel streaming tests" $NUM_TESTS ||
26402e0c 155{
9c8a3964
JR
156 validate_lttng_modules_present
157
26402e0c
DG
158 start_lttng_relayd "-o $TRACE_PATH"
159 start_lttng_sessiond
160
b61ccd96
JR
161 tests=( test_kernel_default_name
162 test_kernel_custom_name
163 test_kernel_default_name_with_del
164 test_kernel_n_snapshot
165 )
26402e0c
DG
166
167 for fct_test in ${tests[@]};
168 do
169 SESSION_NAME=$(randstring 16 0)
170 ${fct_test}
171 if [ $? -eq 0 ]; then
172 # Only delete if successful
25d6f007 173 rm -rf $TRACE_PATH
26402e0c
DG
174 else
175 break
176 fi
177 done
178
179 stop_lttng_sessiond
180 stop_lttng_relayd
181}
This page took 0.059155 seconds and 4 git commands to generate.