Backport: Test: lttng-relayd working directory
authorJonathan Rajotte <jonathan.rajotte-julien@efficios.com>
Fri, 18 May 2018 20:24:04 +0000 (16:24 -0400)
committerJonathan Rajotte <jonathan.rajotte-julien@efficios.com>
Fri, 21 Sep 2018 04:00:52 +0000 (00:00 -0400)
Signed-off-by: Jonathan Rajotte <jonathan.rajotte-julien@efficios.com>
configure.ac
src/common/daemonize.c
tests/regression/Makefile.am
tests/regression/tools/Makefile.am
tests/regression/tools/working-directory/Makefile.am [new file with mode: 0644]
tests/regression/tools/working-directory/test_relayd_workding_directory [new file with mode: 0755]
tests/utils/utils.sh

index f035e24e4730a165cfcc48f096f0392baa159d2d..4697f9bd67e48429675d8e015358b20c33e2a955 100644 (file)
@@ -1024,6 +1024,7 @@ AC_CONFIG_FILES([
        tests/regression/tools/crash/Makefile
        tests/regression/tools/regen-metadata/Makefile
        tests/regression/tools/regen-statedump/Makefile
+       tests/regression/tools/working-directory/Makefile
        tests/regression/ust/Makefile
        tests/regression/ust/nprocesses/Makefile
        tests/regression/ust/high-throughput/Makefile
index b12194ee9480c9aab2933258c987a9adff126100..d5f5ffda5f14e2a4a85b3bdb4291206ff9affeea 100644 (file)
@@ -118,7 +118,7 @@ int lttng_daemonize(pid_t *child_ppid, int *completion_flag,
 
                /*
                 * From this point on, the parent can exit and the child
-                * is now an operationnal session daemon ready to serve
+                * is now an operational session daemon ready to serve
                 * clients and applications.
                 */
                exit(EXIT_SUCCESS);
index 01cff148cc2c595e60bf585781f18f17ca8d24fd..8dab7f591e81030e9bf48de263c4c615680d4cdf 100644 (file)
@@ -23,7 +23,8 @@ TESTS = tools/filtering/test_invalid_filter \
        tools/wildcard/test_event_wildcard \
        tools/crash/test_crash \
        tools/regen-metadata/test_ust \
-       tools/regen-statedump/test_ust
+       tools/regen-statedump/test_ust \
+       tools/working-directory/test_relayd_workding_directory
 
 if HAVE_LIBLTTNG_UST_CTL
 SUBDIRS += ust
index 76374c75461ccfabe3268718605c4061c73c8656..8d7f4ff5a962b20e177a056d0c4896d8270c9568 100644 (file)
@@ -1,2 +1,2 @@
 SUBDIRS = streaming filtering health tracefile-limits snapshots live exclusion save-load mi \
-               wildcard crash regen-metadata regen-statedump
+               wildcard crash regen-metadata regen-statedump working-directory
diff --git a/tests/regression/tools/working-directory/Makefile.am b/tests/regression/tools/working-directory/Makefile.am
new file mode 100644 (file)
index 0000000..069e700
--- /dev/null
@@ -0,0 +1,16 @@
+noinst_SCRIPTS = test_relayd_workding_directory
+EXTRA_DIST = test_relayd_workding_directory
+
+all-local:
+       @if [ x"$(srcdir)" != x"$(builddir)" ]; then \
+               for script in $(EXTRA_DIST); do \
+                       cp -f $(srcdir)/$$script $(builddir); \
+               done; \
+       fi
+
+clean-local:
+       @if [ x"$(srcdir)" != x"$(builddir)" ]; then \
+               for script in $(EXTRA_DIST); do \
+                       rm -f $(builddir)/$$script; \
+               done; \
+       fi
diff --git a/tests/regression/tools/working-directory/test_relayd_workding_directory b/tests/regression/tools/working-directory/test_relayd_workding_directory
new file mode 100755 (executable)
index 0000000..2422ea8
--- /dev/null
@@ -0,0 +1,200 @@
+#!/bin/bash
+#
+# Copyright (C) - 2018 Jonathan Rajotte <jonathan.rajotte-julien@efficios.com>
+#
+# This library is free software; you can redistribute it and/or modify it under
+# the terms of the GNU Lesser General Public License as published by the Free
+# Software Foundation; version 2.1 of the License.
+#
+# This library is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+# FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
+# details.
+#
+# You should have received a copy of the GNU Lesser General Public License
+# along with this library; if not, write to the Free Software Foundation, Inc.,
+# 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301 USA
+
+TEST_DESC="Change working directory of process"
+
+CURDIR=$(dirname $0)/
+TESTDIR=$CURDIR/../../../
+
+DIR=$(readlink -f $TESTDIR)
+
+NUM_TESTS=22
+
+source $TESTDIR/utils/utils.sh
+
+
+#MUST set TESTDIR before calling those functions
+plan_tests $NUM_TESTS
+
+print_test_banner "$TEST_DESC"
+function test_relayd()
+{
+       local working_dir=$(mktemp -d)
+       local test_dir=$(readlink -f $TESTDIR)
+       local relayd_bin_path="$DIR/../src/bin/lttng-relayd/$RELAYD_BIN"
+
+       diag "Test lttng-relayd normal mode change working directory"
+
+       # There is no rendez-vous mechanism that can guarantee the good timing
+       # to check if the workdir directory was changed.
+       # In the case of lttng-sessiond this would be achieved using the
+       # --sig-parent option but lttng-relayd does not have this feature yet.
+       # Fall back on using polling of the value and unblock when the value is
+       # the one we expect. In case of a failure the test will hang.
+       $relayd_bin_path --working-directory $working_dir > /dev/null 2>&1 &
+       RELAYD_PIDS=$!
+
+       while true; do
+               local cwd=$(readlink /proc/${RELAYD_PIDS}/cwd)
+               test "${working_dir}" = "${cwd}"
+               if [ $? -eq 0 ]; then
+                       # Working dir for process is valid
+                       break
+               fi
+               sleep 0.1
+       done
+
+       # If we are here the test passed
+       pass "Working directory changed"
+
+       stop_lttng_relayd
+       rm -rf ${working_dir}
+}
+
+function test_relayd_daemon()
+{
+       local working_dir=$(mktemp -d)
+
+       diag "Test lttng-relayd daemon mode change working directory"
+
+       start_lttng_relayd_opt 1 "-d" "--working-directory $working_dir"
+
+       local cwd=$(readlink /proc/${RELAYD_PIDS}/cwd)
+
+       is "x${cwd}" "x${working_dir}" "Working directory changed"
+
+       stop_lttng_relayd
+       rm -rf ${working_dir}
+}
+
+function test_relayd_daemon_no_working_dir()
+{
+       local expected_working_dir="/"
+
+       diag "Test lttng-relayd daemon mode change working directory"
+
+       start_lttng_relayd_opt 1 "-d" ""
+
+       local cwd=$(readlink /proc/${RELAYD_PIDS}/cwd)
+
+       is "x${cwd}" "x${expected_working_dir}" "Working directory is ${expected_working_dir}"
+
+       stop_lttng_relayd
+       rm -rf ${working_dir}
+}
+
+function test_relayd_background()
+{
+       local working_dir=$(mktemp -d)
+
+       diag "Test lttng-relayd background mode change working directory"
+
+       start_lttng_relayd_opt 1 "-b" "--working-directory $working_dir"
+
+       local cwd=$(readlink /proc/${RELAYD_PIDS}/cwd)
+
+       is "x${cwd}" "x${working_dir}" "Working directory changed"
+
+       stop_lttng_relayd
+       rm -rf ${working_dir}
+}
+
+function test_relayd_background_no_working_dir()
+{
+       local expected_working_dir="/"
+       diag "Test lttng-relayd background working directory"
+
+       start_lttng_relayd_opt 1 "-b" ""
+
+       local cwd=$(readlink /proc/${RELAYD_PIDS}/cwd)
+
+       is "x${cwd}" "x${expected_working_dir}" "Working directory is ${expected_working_dir}"
+
+       stop_lttng_relayd
+       rm -rf ${working_dir}
+}
+
+function test_relayd_debug_permission()
+{
+       local working_dir=$(mktemp -d)
+       local output_pattern='Working directory is not writable'
+       ERROR_OUTPUT_DEST=$(mktemp -u)
+
+       diag "Test lttng-relayd change working directory on non writable directory"
+
+       # Removing write access to working dir
+       okx chmod -w ${working_dir}
+
+       start_lttng_relayd_opt 1 "-b" "-v --working-dir $working_dir"
+
+       local cwd=$(readlink /proc/${RELAYD_PIDS}/cwd)
+       is "x${cwd}" "x${working_dir}" "Workind directory changed"
+
+       local output_content="$(cat ${ERROR_OUTPUT_DEST})"
+       like "x${output_content}" "$output_pattern" "Warning about missing write permission is present"
+
+       stop_lttng_relayd
+       rm -rf ${working_dir} ${ERROR_OUTPUT_DEST}
+       ERROR_OUTPUT_DEST=/dev/null
+}
+
+function test_relayd_failure()
+{
+       local working_dir="$(mktemp -d)"
+       local working_dir_imaginary="${working_dir}/imaginary_directory"
+       local output_dest=$(mktemp -u)
+       local output_pattern='Error: Changing working directory'
+       local test_dir=$(readlink -f $TESTDIR)
+       local relayd_bin_path="$DIR/../src/bin/lttng-relayd/$RELAYD_BIN"
+
+       diag "Test lttng-relayd normal mode change non-existing directory"
+
+       $relayd_bin_path -b --working-directory $working_dir_imaginary > $output_dest 2>&1
+       test $? -eq "1"
+       ok $? "Expect failure to start lttng-relayd for non-existent working directory"
+
+       RELAYD_PIDS=$(pgrep $RELAYD_MATCH)
+       if [ -z "${RELAYD_PIDS}" ]; then
+               pass "No lttng-relayd present"
+       else
+               fail "No lttng-relayd present"
+               stop_lttng_relayd_notap
+       fi
+
+       local output_content="$(cat ${output_dest})"
+       like "x${output_content}" "$output_pattern" "Error about invalid directory"
+
+       rm -rf ${working_dir} ${output_dest}
+}
+
+TESTS=(
+       test_relayd
+       test_relayd_daemon
+       test_relayd_daemon_no_working_dir
+       test_relayd_background
+       test_relayd_background_no_working_dir
+       test_relayd_debug_permission
+       test_relayd_failure
+)
+
+for fct_test in ${TESTS[@]};
+do
+       ${fct_test}
+       if [ $? -ne 0 ]; then
+               break;
+       fi
+done
index 89aca464002d9b950571852b244b4b392cffb8a6..c9b405805659f23d0e9f1dead6e2e45fd5831254 100644 (file)
@@ -304,21 +304,22 @@ function lttng_disable_kernel_channel_fail()
 function start_lttng_relayd_opt()
 {
        local withtap=$1
-       local opt=$2
+       local process_mode=$2
+       local opt=$3
 
        DIR=$(readlink -f $TESTDIR)
 
        if [ -z $(pgrep $RELAYD_MATCH) ]; then
-               $DIR/../src/bin/lttng-relayd/$RELAYD_BIN -b $opt 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
+               $DIR/../src/bin/lttng-relayd/$RELAYD_BIN $process_mode $opt 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
                #$DIR/../src/bin/lttng-relayd/$RELAYD_BIN $opt -vvv >>/tmp/relayd.log 2>&1 &
                if [ $? -eq 1 ]; then
                        if [ $withtap -eq "1" ]; then
-                               fail "Start lttng-relayd (opt: $opt)"
+                               fail "Start lttng-relayd (process mode: $process_mode opt: $opt)"
                        fi
                        return 1
                else
                        if [ $withtap -eq "1" ]; then
-                               pass "Start lttng-relayd (opt: $opt)"
+                               pass "Start lttng-relayd (process mode: $process_mode opt: $opt)"
                        fi
                fi
        else
@@ -330,12 +331,12 @@ function start_lttng_relayd_opt()
 
 function start_lttng_relayd()
 {
-       start_lttng_relayd_opt 1 "$@"
+       start_lttng_relayd_opt 1 "-b" "$@"
 }
 
 function start_lttng_relayd_notap()
 {
-       start_lttng_relayd_opt 0 "$@"
+       start_lttng_relayd_opt 0 "-b" "$@"
 }
 
 function stop_lttng_relayd_opt()
This page took 0.03266 seconds and 5 git commands to generate.