Tests: add an lttng-relayd working directory test
authorJonathan Rajotte <jonathan.rajotte-julien@efficios.com>
Fri, 18 May 2018 20:24:04 +0000 (16:24 -0400)
committerJérémie Galarneau <jeremie.galarneau@efficios.com>
Tue, 22 Oct 2019 19:01:29 +0000 (15:01 -0400)
Signed-off-by: Jonathan Rajotte <jonathan.rajotte-julien@efficios.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@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_working_directory [new file with mode: 0755]
tests/utils/utils.sh

index 616608659c580407ba12ae6c2310dc72222fdb5f..7212ed1957449b6bebd3a2dcfa6c021958c59b44 100644 (file)
@@ -1140,6 +1140,7 @@ AC_CONFIG_FILES([
        tests/regression/tools/rotation/Makefile
        tests/regression/tools/base-path/Makefile
        tests/regression/tools/metadata/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 73eb9f7dae597ef1fe743ee1d5f094d66ef4a47e..29201ed30421fa9b606c144f0900b777609ca05d 100644 (file)
@@ -32,7 +32,8 @@ TESTS = tools/filtering/test_invalid_filter \
        tools/rotation/test_kernel \
        tools/rotation/test_save_load_mi \
        tools/rotation/test_schedule_api \
-       tools/metadata/test_kernel
+       tools/metadata/test_kernel \
+       tools/working-directory/test_relayd_working_directory
 
 if HAVE_LIBLTTNG_UST_CTL
 SUBDIRS += ust
index c5046759923474de80ebbbf0c87bf6190e2aff0f..6fd5f35057cadefc4880d17720d63aa6eb29af08 100644 (file)
@@ -1,3 +1,3 @@
 SUBDIRS = streaming filtering health tracefile-limits snapshots live exclusion save-load mi \
                wildcard crash regen-metadata regen-statedump notification rotation \
-               base-path metadata
+               base-path metadata 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..3f6631f
--- /dev/null
@@ -0,0 +1,16 @@
+noinst_SCRIPTS = test_relayd_working_directory
+EXTRA_DIST = test_relayd_working_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_working_directory b/tests/regression/tools/working-directory/test_relayd_working_directory
new file mode 100755 (executable)
index 0000000..13e816d
--- /dev/null
@@ -0,0 +1,241 @@
+#!/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=27
+
+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 relayd_bin_path="$DIR/../src/bin/lttng-relayd/$RELAYD_BIN"
+       local working_dir
+       local pid
+       local cwd
+
+       working_dir=$(mktemp -d)
+
+       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 &
+       pid=$!
+
+       while true; do
+               cwd=$(readlink "/proc/${pid}/cwd")
+               if test "$working_dir" = "$cwd"; 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
+       local cwd
+       local pid
+
+       working_dir=$(mktemp -d)
+
+       diag "Test lttng-relayd daemon mode change working directory"
+
+       start_lttng_relayd_opt 1 "-d" "--working-directory $working_dir"
+
+       pid=$(pgrep "$RELAYD_MATCH")
+       ok $? "Found lttng-relayd"
+
+       cwd=$(readlink "/proc/${pid}/cwd")
+
+       is "$cwd" "$working_dir" "Working directory changed"
+
+       stop_lttng_relayd
+       rm -rf "$working_dir"
+}
+
+function test_relayd_daemon_no_working_dir()
+{
+       local expected_working_dir="/"
+       local cwd
+       local pid
+
+       diag "Test lttng-relayd daemon mode change working directory"
+
+       start_lttng_relayd_opt 1 "-d" ""
+
+       pid=$(pgrep "$RELAYD_MATCH")
+       ok $? "Found lttng-relayd"
+
+       cwd=$(readlink "/proc/${pid}/cwd")
+
+       is "$cwd" "$expected_working_dir" "Working directory is $expected_working_dir"
+
+       stop_lttng_relayd
+       rm -rf "$working_dir"
+}
+
+function test_relayd_background()
+{
+       local working_dir
+       local cwd
+       local pid
+
+       working_dir=$(mktemp -d)
+
+       diag "Test lttng-relayd background mode change working directory"
+
+       start_lttng_relayd_opt 1 "-b" "--working-directory $working_dir"
+
+       pid=$(pgrep "$RELAYD_MATCH")
+       ok $? "Found lttng-relayd"
+
+       cwd=$(readlink "/proc/${pid}/cwd")
+
+       is "$cwd" "$working_dir" "Working directory changed"
+
+       stop_lttng_relayd
+       rm -rf "$working_dir"
+}
+
+function test_relayd_background_no_working_dir()
+{
+       local expected_working_dir="/"
+       local cwd
+       local pid
+
+       diag "Test lttng-relayd background working directory"
+
+       start_lttng_relayd_opt 1 "-b" ""
+
+       pid=$(pgrep "$RELAYD_MATCH")
+       ok $? "Found lttng-relayd"
+
+       cwd=$(readlink "/proc/${pid}/cwd")
+
+       is "$cwd" "$expected_working_dir" "Working directory is $expected_working_dir"
+
+       stop_lttng_relayd
+       rm -rf "$working_dir"
+}
+
+function test_relayd_debug_permission()
+{
+       local output_pattern='Working directory \".*\" is not writable'
+       local working_dir
+       local cwd
+       local pid
+
+       working_dir=$(mktemp -d)
+
+       diag "Test lttng-relayd change working directory on non writable directory"
+
+       # Removing write access to working dir
+       okx chmod -w "$working_dir"
+
+       # Redirect the error output to a temporary file
+       ERROR_OUTPUT_DEST=$(mktemp)
+       start_lttng_relayd_opt 1 "-b" "-v --working-dir $working_dir"
+
+       pid=$(pgrep "$RELAYD_MATCH")
+       ok $? "Found lttng-relayd"
+
+       cwd=$(readlink "/proc/${pid}/cwd")
+       is "$cwd" "$working_dir" "Working directory changed"
+
+       grep -q "$output_pattern" "$ERROR_OUTPUT_DEST"
+       ok $? "Warning about missing write permission is present"
+
+       stop_lttng_relayd
+       rm "$ERROR_OUTPUT_DEST"
+       rm -rf "$working_dir" "$ERROR_OUTPUT_DEST"
+       ERROR_OUTPUT_DEST=/dev/null
+}
+
+function test_relayd_failure()
+{
+       local output_pattern='Failed to change working directory to'
+       local relayd_bin_path="$DIR/../src/bin/lttng-relayd/$RELAYD_BIN"
+
+       local working_dir
+       local working_dir_imaginary
+       local output_dest
+       local pid
+
+       working_dir="$(mktemp -d)"
+       working_dir_imaginary="${working_dir}/imaginary_directory"
+       output_dest=$(mktemp)
+
+       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"
+
+       pid=$(pgrep "$RELAYD_MATCH")
+       if [ -z "$pid" ]; then
+               pass "No lttng-relayd present"
+       else
+               fail "No lttng-relayd present"
+               stop_lttng_relayd_notap
+       fi
+
+       grep -q "$output_pattern" "$output_dest"
+       ok $? "Found error message: invalid directory"
+
+       rm "$output_dest"
+       rm -rf "$working_dir"
+}
+
+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
+       if ! ${fct_test}; then
+               break;
+       fi
+done
index 0b126a706d3a4da30cc1576875626b2224af09e1..a8b9b3bdf5e76718f0aca85991868809a3ed9eda 100644 (file)
@@ -397,22 +397,23 @@ 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
+       if [ -z $(pgrep $RELAYD_MATCH) ]; then
                # shellcheck disable=SC2086
-               "$DIR/../src/bin/lttng-relayd/$RELAYD_BIN" -b $opt 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
-               #"$DIR/../src/bin/lttng-relayd/$RELAYD_BIN" $opt -vvv >>/tmp/relayd.log 2>&1 &
+               $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)"
+                       if [ $withtap -eq "1" ]; then
+                               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)"
+                       if [ $withtap -eq "1" ]; then
+                               pass "Start lttng-relayd (process mode: $process_mode opt: $opt)"
                        fi
                fi
        else
@@ -422,12 +423,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.045665 seconds and 4 git commands to generate.