Test: save/load: pid_tracker basic test
[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=41
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 lttng_track_ok "-p 666 -u -s $SESSION_NAME"
72
73 lttng_save $SESSION_NAME "-o $TRACE_PATH"
74
75 is_session_saved $TRACE_PATH $SESSION_NAME
76
77 destroy_lttng_session_ok $SESSION_NAME
78 }
79
80 function test_basic_save_all()
81 {
82 diag "Test basic save all"
83
84 create_lttng_session_ok $SESSION_NAME-1 $TRACE_PATH
85 create_lttng_session_ok $SESSION_NAME-2 $TRACE_PATH
86 create_lttng_session_ok $SESSION_NAME-3 $TRACE_PATH
87
88 enable_ust_lttng_channel_ok $SESSION_NAME-1 $CHANNEL_NAME
89 enable_ust_lttng_channel_ok $SESSION_NAME-2 $CHANNEL_NAME
90 enable_ust_lttng_channel_ok $SESSION_NAME-3 $CHANNEL_NAME
91
92 enable_ust_lttng_event_ok $SESSION_NAME-1 $EVENT_NAME $CHANNEL_NAME
93 enable_ust_lttng_event_ok $SESSION_NAME-2 $EVENT_NAME $CHANNEL_NAME
94 enable_ust_lttng_event_ok $SESSION_NAME-3 $EVENT_NAME $CHANNEL_NAME
95
96 lttng_track_ok "-p 666 -u -s $SESSION_NAME-1"
97 lttng_track_ok "-p 666 -u -s $SESSION_NAME-2"
98 lttng_track_ok "-p 666 -u -s $SESSION_NAME-3"
99
100 lttng_save "" "-a -o $TRACE_PATH"
101
102 is_session_saved $TRACE_PATH $SESSION_NAME-1
103 is_session_saved $TRACE_PATH $SESSION_NAME-2
104 is_session_saved $TRACE_PATH $SESSION_NAME-3
105
106 destroy_lttng_session_ok $SESSION_NAME-1
107 destroy_lttng_session_ok $SESSION_NAME-2
108 destroy_lttng_session_ok $SESSION_NAME-3
109 }
110
111 function test_overwrite()
112 {
113 diag "Test overwrite session file"
114
115 create_lttng_session_ok $SESSION_NAME $TRACE_PATH
116 enable_ust_lttng_channel_ok $SESSION_NAME $CHANNEL_NAME
117 enable_ust_lttng_event_ok $SESSION_NAME $EVENT_NAME $CHANNEL_NAME
118
119 lttng_save $SESSION_NAME "-o $TRACE_PATH"
120
121 is_session_saved $TRACE_PATH $SESSION_NAME
122
123 destroy_lttng_session_ok $SESSION_NAME
124
125 # Create a new session with same name so we can force the overwrite
126 create_lttng_session_ok $SESSION_NAME $TRACE_PATH
127 enable_ust_lttng_channel_ok $SESSION_NAME $CHANNEL_NAME
128 enable_ust_lttng_event_ok $SESSION_NAME $EVENT_NAME $CHANNEL_NAME
129
130 # This one MUST fail
131 save_lttng_fail $SESSION_NAME "-o $TRACE_PATH"
132
133 # This one MUST succeed
134 lttng_save $SESSION_NAME "-f -o $TRACE_PATH"
135
136 is_session_saved $TRACE_PATH $SESSION_NAME
137
138 destroy_lttng_session_ok $SESSION_NAME
139 }
140
141 start_lttng_sessiond
142
143 TESTS=(
144 test_basic_save
145 test_basic_save_all
146 test_overwrite
147 )
148
149 for fct_test in ${TESTS[@]};
150 do
151 TRACE_PATH=$(mktemp -d)
152
153 ${fct_test}
154 if [ $? -ne 0 ]; then
155 break;
156 fi
157 # Only delete if successful
158 rm -rf $TRACE_PATH
159 done
160
161 stop_lttng_sessiond
This page took 0.03738 seconds and 5 git commands to generate.