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