674d00134a157cb08c05556bd71ce94c8795a223
[lttng-tools.git] / tests / regression / tools / save-load / test_save
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
18 TEST_DESC="Save session(s)"
19
20 CURDIR=$(dirname $0)/
21 TESTDIR=$CURDIR/../../../
22 SESSIOND_BIN="lttng-sessiond"
23 RELAYD_BIN="lttng-relayd"
24 LTTNG_BIN="lttng"
25
26 SESSION_NAME="save-42"
27 CHANNEL_NAME="chan-save"
28 EVENT_NAME="tp:tptest"
29
30 DIR=$(readlink -f $TESTDIR)
31
32 NUM_TESTS=37
33
34 source $TESTDIR/utils/utils.sh
35
36 # MUST set TESTDIR before calling those functions
37 plan_tests $NUM_TESTS
38
39 print_test_banner "$TEST_DESC"
40
41 # Expected to fail
42 function 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
55 function 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
64 function test_basic_save()
65 {
66 diag "Test basic save"
67
68 create_lttng_session_ok $SESSION_NAME $TRACE_PATH
69 enable_ust_lttng_channel_ok $SESSION_NAME $CHANNEL_NAME
70 enable_ust_lttng_event_ok $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_ok $SESSION_NAME
77 }
78
79 function test_basic_save_all()
80 {
81 diag "Test basic save all"
82
83 create_lttng_session_ok $SESSION_NAME-1 $TRACE_PATH
84 create_lttng_session_ok $SESSION_NAME-2 $TRACE_PATH
85 create_lttng_session_ok $SESSION_NAME-3 $TRACE_PATH
86
87 enable_ust_lttng_channel_ok $SESSION_NAME-1 $CHANNEL_NAME
88 enable_ust_lttng_channel_ok $SESSION_NAME-2 $CHANNEL_NAME
89 enable_ust_lttng_channel_ok $SESSION_NAME-3 $CHANNEL_NAME
90
91 enable_ust_lttng_event_ok $SESSION_NAME-1 $EVENT_NAME $CHANNEL_NAME
92 enable_ust_lttng_event_ok $SESSION_NAME-2 $EVENT_NAME $CHANNEL_NAME
93 enable_ust_lttng_event_ok $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_ok $SESSION_NAME-1
102 destroy_lttng_session_ok $SESSION_NAME-2
103 destroy_lttng_session_ok $SESSION_NAME-3
104 }
105
106 function test_overwrite()
107 {
108 diag "Test overwrite session file"
109
110 create_lttng_session_ok $SESSION_NAME $TRACE_PATH
111 enable_ust_lttng_channel_ok $SESSION_NAME $CHANNEL_NAME
112 enable_ust_lttng_event_ok $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_ok $SESSION_NAME
119
120 # Create a new session with same name so we can force the overwrite
121 create_lttng_session_ok $SESSION_NAME $TRACE_PATH
122 enable_ust_lttng_channel_ok $SESSION_NAME $CHANNEL_NAME
123 enable_ust_lttng_event_ok $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_ok $SESSION_NAME
134 }
135
136 start_lttng_sessiond
137
138 TESTS=(
139 test_basic_save
140 test_basic_save_all
141 test_overwrite
142 )
143
144 for fct_test in ${TESTS[@]};
145 do
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
154 done
155
156 stop_lttng_sessiond
This page took 0.03572 seconds and 4 git commands to generate.