Fix: sessiond: fs.protected_regular sysctl breaks app registration
[lttng-tools.git] / tests / regression / tools / save-load / test_save
CommitLineData
e02b109b
DG
1#!/bin/bash
2#
3# Copyright (C) - 2014 David Goulet <dgoulet@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="Save session(s)"
19
20CURDIR=$(dirname $0)/
21TESTDIR=$CURDIR/../../../
e02b109b
DG
22
23SESSION_NAME="save-42"
24CHANNEL_NAME="chan-save"
25EVENT_NAME="tp:tptest"
26
27DIR=$(readlink -f $TESTDIR)
28
722f854b 29NUM_TESTS=41
e02b109b
DG
30
31source $TESTDIR/utils/utils.sh
32
33# MUST set TESTDIR before calling those functions
34plan_tests $NUM_TESTS
35
36print_test_banner "$TEST_DESC"
37
38# Expected to fail
39function save_lttng_fail()
40{
41 local sess_name=$1
42 local opts=$2
43
44 $TESTDIR/../src/bin/lttng/$LTTNG_BIN save $sess_name $opts >/dev/null 2>&1
45 if [ $? -ne 0 ]; then
46 ok 0 "Session failed to be saved. Expected!"
47 else
48 ok 1 "Session has been saved. NOT expected!"
49 fi
50}
51
52function is_session_saved()
53{
54 local path=$1
55 local name=$2
56
57 [ -f "$path/$name.lttng" ];
58 ok $? "Session $name.lttng file found!"
59}
60
61function test_basic_save()
62{
63 diag "Test basic save"
64
bf6ae429 65 create_lttng_session_ok $SESSION_NAME $TRACE_PATH
827caf52 66 enable_ust_lttng_channel_ok $SESSION_NAME $CHANNEL_NAME
c4926bb5 67 enable_ust_lttng_event_ok $SESSION_NAME $EVENT_NAME $CHANNEL_NAME
722f854b 68 lttng_track_ok "-p 666 -u -s $SESSION_NAME"
e02b109b
DG
69
70 lttng_save $SESSION_NAME "-o $TRACE_PATH"
71
72 is_session_saved $TRACE_PATH $SESSION_NAME
73
67b4c664 74 destroy_lttng_session_ok $SESSION_NAME
e02b109b
DG
75}
76
77function test_basic_save_all()
78{
79 diag "Test basic save all"
80
bf6ae429
JR
81 create_lttng_session_ok $SESSION_NAME-1 $TRACE_PATH
82 create_lttng_session_ok $SESSION_NAME-2 $TRACE_PATH
83 create_lttng_session_ok $SESSION_NAME-3 $TRACE_PATH
e02b109b 84
827caf52
JR
85 enable_ust_lttng_channel_ok $SESSION_NAME-1 $CHANNEL_NAME
86 enable_ust_lttng_channel_ok $SESSION_NAME-2 $CHANNEL_NAME
87 enable_ust_lttng_channel_ok $SESSION_NAME-3 $CHANNEL_NAME
e02b109b 88
c4926bb5
JR
89 enable_ust_lttng_event_ok $SESSION_NAME-1 $EVENT_NAME $CHANNEL_NAME
90 enable_ust_lttng_event_ok $SESSION_NAME-2 $EVENT_NAME $CHANNEL_NAME
91 enable_ust_lttng_event_ok $SESSION_NAME-3 $EVENT_NAME $CHANNEL_NAME
e02b109b 92
722f854b
JR
93 lttng_track_ok "-p 666 -u -s $SESSION_NAME-1"
94 lttng_track_ok "-p 666 -u -s $SESSION_NAME-2"
95 lttng_track_ok "-p 666 -u -s $SESSION_NAME-3"
96
e02b109b
DG
97 lttng_save "" "-a -o $TRACE_PATH"
98
99 is_session_saved $TRACE_PATH $SESSION_NAME-1
100 is_session_saved $TRACE_PATH $SESSION_NAME-2
101 is_session_saved $TRACE_PATH $SESSION_NAME-3
102
67b4c664
JR
103 destroy_lttng_session_ok $SESSION_NAME-1
104 destroy_lttng_session_ok $SESSION_NAME-2
105 destroy_lttng_session_ok $SESSION_NAME-3
e02b109b
DG
106}
107
108function test_overwrite()
109{
110 diag "Test overwrite session file"
111
bf6ae429 112 create_lttng_session_ok $SESSION_NAME $TRACE_PATH
827caf52 113 enable_ust_lttng_channel_ok $SESSION_NAME $CHANNEL_NAME
c4926bb5 114 enable_ust_lttng_event_ok $SESSION_NAME $EVENT_NAME $CHANNEL_NAME
e02b109b
DG
115
116 lttng_save $SESSION_NAME "-o $TRACE_PATH"
117
118 is_session_saved $TRACE_PATH $SESSION_NAME
119
67b4c664 120 destroy_lttng_session_ok $SESSION_NAME
e02b109b
DG
121
122 # Create a new session with same name so we can force the overwrite
bf6ae429 123 create_lttng_session_ok $SESSION_NAME $TRACE_PATH
827caf52 124 enable_ust_lttng_channel_ok $SESSION_NAME $CHANNEL_NAME
c4926bb5 125 enable_ust_lttng_event_ok $SESSION_NAME $EVENT_NAME $CHANNEL_NAME
e02b109b
DG
126
127 # This one MUST fail
128 save_lttng_fail $SESSION_NAME "-o $TRACE_PATH"
129
130 # This one MUST succeed
131 lttng_save $SESSION_NAME "-f -o $TRACE_PATH"
132
133 is_session_saved $TRACE_PATH $SESSION_NAME
134
67b4c664 135 destroy_lttng_session_ok $SESSION_NAME
e02b109b
DG
136}
137
138start_lttng_sessiond
139
140TESTS=(
141 test_basic_save
142 test_basic_save_all
143 test_overwrite
144)
145
146for fct_test in ${TESTS[@]};
147do
148 TRACE_PATH=$(mktemp -d)
149
150 ${fct_test}
151 if [ $? -ne 0 ]; then
152 break;
153 fi
154 # Only delete if successful
edb62ef5 155 rm -rf $TRACE_PATH
e02b109b
DG
156done
157
158stop_lttng_sessiond
This page took 0.040586 seconds and 4 git commands to generate.