Tests: wording of trace_matches is misleading
[lttng-tools.git] / tests / utils / utils.sh
index 9b1c872698ca48a48dd675d3f57c82f091f7aec3..4dc37db646e4432cd16a15f312c026cff43b0b8f 100644 (file)
@@ -33,6 +33,12 @@ KERNEL_PATCHLEVEL_VERSION=27
 # systems. Specialized tests should test those corner-cases.
 export LTTNG_UST_REGISTER_TIMEOUT=-1
 
+# We set the default lttng-sessiond path to /bin/true to prevent the spawning
+# of a daemonized sessiond. This is necessary since 'lttng create' will spawn
+# its own sessiond if none is running. It also ensures that 'lttng create'
+# fails when no sessiond is running.
+export LTTNG_SESSIOND_PATH="/bin/true"
+
 source $TESTDIR/utils/tap/tap.sh
 
 function print_ok ()
@@ -82,7 +88,17 @@ function validate_kernel_version ()
 function randstring()
 {
        [ "$2" == "0" ] && CHAR="[:alnum:]" || CHAR="[:graph:]"
-       cat /dev/urandom | tr -cd "$CHAR" | head -c ${1:-16}
+       cat /dev/urandom 2>/dev/null | tr -cd "$CHAR" 2>/dev/null | head -c ${1:-16} 2>/dev/null
+       echo
+}
+
+# Return the number of _configured_ CPUs.
+function conf_proc_count()
+{
+       getconf _NPROCESSORS_CONF
+       if [ $? -ne 0 ]; then
+               diag "Failed to get the number of configured CPUs"
+       fi
        echo
 }
 
@@ -239,9 +255,10 @@ function lttng_disable_kernel_channel_fail()
        lttng_disable_kernel_channel 1 ${*}
 }
 
-function start_lttng_relayd
+function start_lttng_relayd_opt()
 {
-       local opt=$1
+       local withtap=$1
+       local opt=$2
 
        DIR=$(readlink -f $TESTDIR)
 
@@ -249,52 +266,77 @@ function start_lttng_relayd
                $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 &
                if [ $? -eq 1 ]; then
-                       fail "Start lttng-relayd (opt: $opt)"
+                       if [ $withtap -eq "1" ]; then
+                               fail "Start lttng-relayd (opt: $opt)"
+                       fi
                        return 1
                else
-                       pass "Start lttng-relayd (opt: $opt)"
+                       if [ $withtap -eq "1" ]; then
+                               pass "Start lttng-relayd (opt: $opt)"
+                       fi
                fi
        else
                pass "Start lttng-relayd (opt: $opt)"
        fi
 }
 
-function stop_lttng_relayd_nocheck
+function start_lttng_relayd()
+{
+       start_lttng_relayd_opt 1 "$@"
+}
+
+function start_lttng_relayd_notap()
 {
+       start_lttng_relayd_opt 0 "$@"
+}
+
+function stop_lttng_relayd_opt()
+{
+       local withtap=$1
+
        PID_RELAYD=`pidof lt-$RELAYD_BIN`
 
-       diag "Killing lttng-relayd (pid: $PID_RELAYD)"
+       if [ $withtap -eq "1" ]; then
+               diag "Killing lttng-relayd (pid: $PID_RELAYD)"
+       fi
        kill $PID_RELAYD 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
        retval=$?
 
-       if [ $retval -eq 1 ]; then
+       if [ $? -eq 1 ]; then
+               if [ $withtap -eq "1" ]; then
+                       fail "Kill relay daemon"
+               fi
+               return 1
+       else
                out=1
                while [ -n "$out" ]; do
                        out=$(pidof lt-$RELAYD_BIN)
                        sleep 0.5
                done
+               if [ $withtap -eq "1" ]; then
+                       pass "Kill relay daemon"
+               fi
        fi
        return $retval
 }
 
-function stop_lttng_relayd
+function stop_lttng_relayd()
 {
-       stop_lttng_relayd_nocheck
+       stop_lttng_relayd_opt 1 "$@"
+}
 
-       if [ $? -eq 1 ]; then
-               fail "Killed lttng-relayd (pid: $PID_RELAYD)"
-               return 1
-       else
-               pass "Killed lttng-relayd (pid: $PID_RELAYD)"
-               return 0
-       fi
+function stop_lttng_relayd_notap()
+{
+       stop_lttng_relayd_opt 0 "$@"
 }
 
-#First argument: load path for automatic loading
-function start_lttng_sessiond()
+#First arg: show tap output
+#Second argument: load path for automatic loading
+function start_lttng_sessiond_opt()
 {
+       local withtap=$1
+       local load_path=$2
 
-       local load_path="$1"
        if [ -n $TEST_NO_SESSIOND ] && [ "$TEST_NO_SESSIOND" == "1" ]; then
                # Env variable requested no session daemon
                return
@@ -312,19 +354,33 @@ function start_lttng_sessiond()
 
        if [ -z $(pidof lt-$SESSIOND_BIN) ]; then
                # Have a load path ?
-               if [ -n "$1" ]; then
+               if [ -n "$load_path" ]; then
                        $DIR/../src/bin/lttng-sessiond/$SESSIOND_BIN --load "$1" --background --consumerd32-path="$DIR/../src/bin/lttng-consumerd/lttng-consumerd" --consumerd64-path="$DIR/../src/bin/lttng-consumerd/lttng-consumerd"
                else
                        $DIR/../src/bin/lttng-sessiond/$SESSIOND_BIN --background --consumerd32-path="$DIR/../src/bin/lttng-consumerd/lttng-consumerd" --consumerd64-path="$DIR/../src/bin/lttng-consumerd/lttng-consumerd"
                fi
                #$DIR/../src/bin/lttng-sessiond/$SESSIOND_BIN --background --consumerd32-path="$DIR/../src/bin/lttng-consumerd/lttng-consumerd" --consumerd64-path="$DIR/../src/bin/lttng-consumerd/lttng-consumerd" --verbose-consumer >>/tmp/sessiond.log 2>&1
                status=$?
-               ok $status "Start session daemon"
+               if [ $withtap -eq "1" ]; then
+                       ok $status "Start session daemon"
+               fi
        fi
 }
 
-function stop_lttng_sessiond ()
+function start_lttng_sessiond()
+{
+       start_lttng_sessiond_opt 1 "$@"
+}
+
+function start_lttng_sessiond_notap()
 {
+       start_lttng_sessiond_opt 0 "$@"
+}
+
+function stop_lttng_sessiond_opt()
+{
+       local withtap=$1
+
        if [ -n $TEST_NO_SESSIOND ] && [ "$TEST_NO_SESSIOND" == "1" ]; then
                # Env variable requested no session daemon
                return
@@ -335,8 +391,9 @@ function stop_lttng_sessiond ()
        kill $PID_SESSIOND 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
 
        if [ $? -eq 1 ]; then
-               fail "Kill sessions daemon"
-               return 1
+               if [ $withtap -eq "1" ]; then
+                       fail "Kill sessions daemon"
+               fi
        else
                out=1
                while [ -n "$out" ]; do
@@ -348,10 +405,22 @@ function stop_lttng_sessiond ()
                        out=$(pidof $CONSUMERD_BIN)
                        sleep 0.5
                done
-               pass "Kill session daemon"
+               if [ $withtap -eq "1" ]; then
+                       pass "Kill session daemon"
+               fi
        fi
 }
 
+function stop_lttng_sessiond()
+{
+       stop_lttng_sessiond_opt 1 "$@"
+}
+
+function stop_lttng_sessiond_notap()
+{
+       stop_lttng_sessiond_opt 0 "$@"
+}
+
 function list_lttng_with_opts ()
 {
        local opts=$1
@@ -714,7 +783,7 @@ function trace_matches ()
 
        if [ "$count" -ne "$nr_iter" ]; then
                fail "Trace match"
-               diag "$count events found in trace"
+               diag "$count matching events found in trace"
        else
                pass "Trace match"
        fi
This page took 0.025339 seconds and 4 git commands to generate.