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
30 #MUST set TESTDIR before calling those functions
33 print_test_banner
"$TEST_DESC"
34 function test_relayd
()
36 local working_dir
=$
(mktemp
-d)
37 local test_dir
=$
(readlink
-f $TESTDIR)
38 local relayd_bin_path
="$DIR/../src/bin/lttng-relayd/$RELAYD_BIN"
40 diag
"Test lttng-relayd normal mode change working directory"
42 # There is no rendez-vous mechanism that can guarantee the good timing
43 # to check if the workdir directory was changed.
44 # In the case of lttng-sessiond this would be achieved using the
45 # --sig-parent option but lttng-relayd does not have this feature yet.
46 # Fall back on using polling of the value and unblock when the value is
47 # the one we expect. In case of a failure the test will hang.
48 $relayd_bin_path --working-directory $working_dir > /dev
/null
2>&1 &
52 local cwd
=$
(readlink
/proc
/${RELAYD_PIDS}/cwd
)
53 test "${working_dir}" = "${cwd}"
55 # Working dir for process is valid
61 # If we are here the test passed
62 pass
"Working directory changed"
68 function test_relayd_daemon
()
70 local working_dir
=$
(mktemp
-d)
72 diag
"Test lttng-relayd daemon mode change working directory"
74 start_lttng_relayd_opt
1 "-d" "--working-directory $working_dir"
76 local cwd
=$
(readlink
/proc
/${RELAYD_PIDS}/cwd
)
78 is
"x${cwd}" "x${working_dir}" "Working directory changed"
84 function test_relayd_daemon_no_working_dir
()
86 local expected_working_dir
="/"
88 diag
"Test lttng-relayd daemon mode change working directory"
90 start_lttng_relayd_opt
1 "-d" ""
92 local cwd
=$
(readlink
/proc
/${RELAYD_PIDS}/cwd
)
94 is
"x${cwd}" "x${expected_working_dir}" "Working directory is ${expected_working_dir}"
100 function test_relayd_background
()
102 local working_dir
=$
(mktemp
-d)
104 diag
"Test lttng-relayd background mode change working directory"
106 start_lttng_relayd_opt
1 "-b" "--working-directory $working_dir"
108 local cwd
=$
(readlink
/proc
/${RELAYD_PIDS}/cwd
)
110 is
"x${cwd}" "x${working_dir}" "Working directory changed"
113 rm -rf ${working_dir}
116 function test_relayd_background_no_working_dir
()
118 local expected_working_dir
="/"
119 diag
"Test lttng-relayd background working directory"
121 start_lttng_relayd_opt
1 "-b" ""
123 local cwd
=$
(readlink
/proc
/${RELAYD_PIDS}/cwd
)
125 is
"x${cwd}" "x${expected_working_dir}" "Working directory is ${expected_working_dir}"
128 rm -rf ${working_dir}
131 function test_relayd_debug_permission
()
133 local working_dir
=$
(mktemp
-d)
134 local output_pattern
='Working directory is not writable'
135 ERROR_OUTPUT_DEST
=$
(mktemp
-u)
137 diag
"Test lttng-relayd change working directory on non writable directory"
139 # Removing write access to working dir
140 okx
chmod -w ${working_dir}
142 start_lttng_relayd_opt
1 "-b" "-v --working-dir $working_dir"
144 local cwd
=$
(readlink
/proc
/${RELAYD_PIDS}/cwd
)
145 is
"x${cwd}" "x${working_dir}" "Workind directory changed"
147 local output_content
="$(cat ${ERROR_OUTPUT_DEST})"
148 like
"x${output_content}" "$output_pattern" "Warning about missing write permission is present"
151 rm -rf ${working_dir} ${ERROR_OUTPUT_DEST}
152 ERROR_OUTPUT_DEST
=/dev
/null
155 function test_relayd_failure
()
157 local working_dir
="$(mktemp -d)"
158 local working_dir_imaginary
="${working_dir}/imaginary_directory"
159 local output_dest
=$
(mktemp
-u)
160 local output_pattern
='Error: Changing working directory'
161 local test_dir
=$
(readlink
-f $TESTDIR)
162 local relayd_bin_path
="$DIR/../src/bin/lttng-relayd/$RELAYD_BIN"
164 diag
"Test lttng-relayd normal mode change non-existing directory"
166 $relayd_bin_path -b --working-directory $working_dir_imaginary > $output_dest 2>&1
168 ok $?
"Expect failure to start lttng-relayd for non-existent working directory"
170 RELAYD_PIDS
=$
(pgrep
$RELAYD_MATCH)
171 if [ -z "${RELAYD_PIDS}" ]; then
172 pass
"No lttng-relayd present"
174 fail
"No lttng-relayd present"
175 stop_lttng_relayd_notap
178 local output_content
="$(cat ${output_dest})"
179 like
"x${output_content}" "$output_pattern" "Error about invalid directory"
181 rm -rf ${working_dir} ${output_dest}
187 test_relayd_daemon_no_working_dir
188 test_relayd_background
189 test_relayd_background_no_working_dir
190 test_relayd_debug_permission
194 for fct_test
in ${TESTS[@]};
197 if [ $?
-ne 0 ]; then