3 # Copyright (C) - 2018 Jonathan Rajotte <jonathan.rajotte-julien@efficios.com>
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.
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
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
18 TEST_DESC
="Change working directory of process"
21 TESTDIR
=$CURDIR/..
/..
/..
/
23 DIR
=$
(readlink
-f $TESTDIR)
27 source $TESTDIR/utils
/utils.sh
29 #MUST set TESTDIR before calling those functions
32 print_test_banner
"$TEST_DESC"
33 function test_relayd
()
35 local working_dir
=$
(mktemp
-d)
36 local test_dir
=$
(readlink
-f $TESTDIR)
37 local relayd_bin_path
="$DIR/../src/bin/lttng-relayd/$RELAYD_BIN"
39 diag
"Test lttng-relayd normal mode change working directory"
41 # There is no rendez-vous mechanism that can guarantee the good timing
42 # to check if the workdir directory was changed.
43 # In the case of lttng-sessiond this would be achieved using the
44 # --sig-parent option but lttng-relayd does not have this feature yet.
45 # Fall back on using polling of the value and unblock when the value is
46 # the one we expect. In case of a failure the test will hang.
47 $relayd_bin_path --working-directory $working_dir > /dev
/null
2>&1 &
51 local cwd
=$
(readlink
/proc
/${RELAYD_PIDS}/cwd
)
52 test "${working_dir}" = "${cwd}"
54 # Working dir for process is valid
60 # If we are here the test passed
61 pass
"Working directory changed"
67 function test_relayd_daemon
()
69 local working_dir
=$
(mktemp
-d)
71 diag
"Test lttng-relayd daemon mode change working directory"
73 start_lttng_relayd_opt
1 "-d" "--working-directory $working_dir"
75 local cwd
=$
(readlink
/proc
/${RELAYD_PIDS}/cwd
)
77 is
"x${cwd}" "x${working_dir}" "Working directory changed"
83 function test_relayd_daemon_no_working_dir
()
85 local expected_working_dir
="/"
87 diag
"Test lttng-relayd daemon mode change working directory"
89 start_lttng_relayd_opt
1 "-d" ""
91 local cwd
=$
(readlink
/proc
/${RELAYD_PIDS}/cwd
)
93 is
"x${cwd}" "x${expected_working_dir}" "Working directory is ${expected_working_dir}"
99 function test_relayd_background
()
101 local working_dir
=$
(mktemp
-d)
103 diag
"Test lttng-relayd background mode change working directory"
105 start_lttng_relayd_opt
1 "-b" "--working-directory $working_dir"
107 local cwd
=$
(readlink
/proc
/${RELAYD_PIDS}/cwd
)
109 is
"x${cwd}" "x${working_dir}" "Working directory changed"
112 rm -rf ${working_dir}
115 function test_relayd_background_no_working_dir
()
117 local expected_working_dir
="/"
118 diag
"Test lttng-relayd background working directory"
120 start_lttng_relayd_opt
1 "-b" ""
122 local cwd
=$
(readlink
/proc
/${RELAYD_PIDS}/cwd
)
124 is
"x${cwd}" "x${expected_working_dir}" "Working directory is ${expected_working_dir}"
127 rm -rf ${working_dir}
130 function test_relayd_debug_permission
()
132 local working_dir
=$
(mktemp
-d)
133 local output_pattern
='Working directory is not writable'
134 ERROR_OUTPUT_DEST
=$
(mktemp
-u)
136 diag
"Test lttng-relayd change working directory on non writable directory"
138 # Removing write access to working dir
139 okx
chmod -w ${working_dir}
141 start_lttng_relayd_opt
1 "-b" "-v --working-dir $working_dir"
143 local cwd
=$
(readlink
/proc
/${RELAYD_PIDS}/cwd
)
144 is
"x${cwd}" "x${working_dir}" "Workind directory changed"
146 local output_content
="$(cat ${ERROR_OUTPUT_DEST})"
147 like
"x${output_content}" "$output_pattern" "Warning about missing write permission is present"
150 rm -rf ${working_dir} ${ERROR_OUTPUT_DEST}
151 ERROR_OUTPUT_DEST
=/dev
/null
154 function test_relayd_failure
()
156 local working_dir
="$(mktemp -d)"
157 local working_dir_imaginary
="${working_dir}/imaginary_directory"
158 local output_dest
=$
(mktemp
-u)
159 local output_pattern
='Error: Changing working directory'
160 local test_dir
=$
(readlink
-f $TESTDIR)
161 local relayd_bin_path
="$DIR/../src/bin/lttng-relayd/$RELAYD_BIN"
163 diag
"Test lttng-relayd normal mode change non-existing directory"
165 $relayd_bin_path -b --working-directory $working_dir_imaginary > $output_dest 2>&1
167 ok $?
"Expect failure to start lttng-relayd for non-existent working directory"
169 RELAYD_PIDS
=$
(pgrep
$RELAYD_MATCH)
170 if [ -z "${RELAYD_PIDS}" ]; then
171 pass
"No lttng-relayd present"
173 fail
"No lttng-relayd present"
174 stop_lttng_relayd_notap
177 local output_content
="$(cat ${output_dest})"
178 like
"x${output_content}" "$output_pattern" "Error about invalid directory"
180 rm -rf ${working_dir} ${output_dest}
183 function test_relayd_env
()
185 local working_dir
=$
(mktemp
-d)
187 diag
"Test lttng-relayd change working directory from env. variable"
189 export LTTNG_RELAYD_WORKING_DIRECTORY
=${working_dir}
190 start_lttng_relayd_opt
1 "-b" ""
192 local cwd
=$
(readlink
/proc
/${RELAYD_PIDS}/cwd
)
194 is
"x${cwd}" "x${working_dir}" "Working directory changed"
197 rm -rf ${working_dir}
198 unset LTTNG_RELAYD_WORKING_DIRECTORY
201 function test_relayd_cmdline_overwrite_env
()
203 local working_dir_env
=$
(mktemp
-d)
204 local working_dir_cmdline
=$
(mktemp
-d)
206 diag
"Test lttng-relayd change working directory command line overwrite env variable"
208 export LTTNG_RELAYD_WORKING_DIRECTORY
=${working_dir_env}
209 start_lttng_relayd_opt
1 "-b" "--working-dir ${working_dir_cmdline}"
211 local cwd
=$
(readlink
/proc
/${RELAYD_PIDS}/cwd
)
213 is
"x${cwd}" "x${working_dir_cmdline}" "Working directory is the one from command line"
216 rm -rf ${working_dir_env} ${working_dir_cmdline}
217 unset LTTNG_RELAYD_WORKING_DIRECTORY
222 test_relayd_daemon_no_working_dir
223 test_relayd_background
224 test_relayd_background_no_working_dir
225 test_relayd_debug_permission
228 test_relayd_cmdline_overwrite_env
231 for fct_test
in ${TESTS[@]};
234 if [ $?
-ne 0 ]; then