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>
Thu, 31 May 2018 19:54:04 +0000 (15:54 -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 cb36d6b68423b6edd1eefe9351b58e168b9d7284..d96656d2cf228834fbcdfbdecfe52cd4e9f45cd0 100644 (file)
@@ -1080,6 +1080,7 @@ AC_CONFIG_FILES([
        tests/regression/tools/regen-statedump/Makefile
        tests/regression/tools/notification/Makefile
        tests/regression/tools/rotation/Makefile
+       tests/regression/tools/working-directory/Makefile
        tests/regression/ust/Makefile
        tests/regression/ust/nprocesses/Makefile
        tests/regression/ust/high-throughput/Makefile
index 88ec9f13472a88aba1f49ae07a97ced16806b5dd..40cef3840000a9a44848d779f531a9ea400ae983 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 50e89e4c52ad7f5a9426003c356082ffe62e70cc..cb82a9461cee82626542ee0f45b89a95e66cc1b6 100644 (file)
@@ -29,7 +29,8 @@ TESTS = tools/filtering/test_invalid_filter \
        tools/notification/test_notification_multi_app \
        tools/rotation/test_ust \
        tools/rotation/test_kernel \
-       tools/rotation/test_save_load_mi
+       tools/rotation/test_save_load_mi \
+       tools/working-directory/test_relayd_workding_directory
 
 if HAVE_LIBLTTNG_UST_CTL
 SUBDIRS += ust
index dea9938869f92bdb8d5ccff4bd6df55d65b26766..42e4a5d8193c189fba85d236531da9b660273ed7 100644 (file)
@@ -1,2 +1,3 @@
 SUBDIRS = streaming filtering health tracefile-limits snapshots live exclusion save-load mi \
-               wildcard crash regen-metadata regen-statedump notification rotation
+               wildcard crash regen-metadata regen-statedump notification rotation \
+               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 2d53a7237350e6df4b5492ab2930c0d2f6f391a9..7989bf612997960cf0c30dafbfcf9bd64a40db49 100644 (file)
@@ -342,21 +342,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
@@ -368,12 +369,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.034986 seconds and 5 git commands to generate.