aboutsummaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
authorMasami Hiramatsu <mhiramat@kernel.org>2017-07-06 21:02:33 -0400
committerShuah Khan <shuahkh@osg.samsung.com>2017-07-26 17:41:36 -0400
commit97bece60ef87d813cbe6f8f9b8e532a6a95d422a (patch)
tree89deb105cd435c13134631415c483152e779f90f /tools
parentdab24fb1f2d6dfb6b134535e4510cb1f681d9d23 (diff)
selftests: ftrace: Output only to console with "--logdir -"
Output logs only to console if "-" is given to --logdir option. In this case, ftracetest doesn't record any log on the disk, and all logs immediately shown (including all command logs.) Since there is no "tee" in the middle of command and console, it outputs the log really soon. This option is useful only when the console is logged. Signed-off-by: Masami Hiramatsu <mhiramat@kernel.org> Acked-by: Steven Rostedt (VMware) <srostedt@goodmis.org> Signed-off-by: Shuah Khan <shuahkh@osg.samsung.com>
Diffstat (limited to 'tools')
-rwxr-xr-xtools/testing/selftests/ftrace/ftracetest29
1 files changed, 21 insertions, 8 deletions
diff --git a/tools/testing/selftests/ftrace/ftracetest b/tools/testing/selftests/ftrace/ftracetest
index 892ca4ec17f4..cce1a0c26daf 100755
--- a/tools/testing/selftests/ftrace/ftracetest
+++ b/tools/testing/selftests/ftrace/ftracetest
@@ -19,6 +19,7 @@ echo " -vvv Alias of -v -v -v (Show all commands immediately)"
19echo " --fail-unsupported Treat UNSUPPORTED as a failure" 19echo " --fail-unsupported Treat UNSUPPORTED as a failure"
20echo " -d|--debug Debug mode (trace all shell commands)" 20echo " -d|--debug Debug mode (trace all shell commands)"
21echo " -l|--logdir <dir> Save logs on the <dir>" 21echo " -l|--logdir <dir> Save logs on the <dir>"
22echo " If <dir> is -, all logs output in console only"
22exit $1 23exit $1
23} 24}
24 25
@@ -127,14 +128,20 @@ if [ -z "$TRACING_DIR" -o ! -d "$TRACING_DIR" ]; then
127fi 128fi
128 129
129# Preparing logs 130# Preparing logs
130LOG_FILE=$LOG_DIR/ftracetest.log 131if [ "x$LOG_DIR" = "x-" ]; then
131mkdir -p $LOG_DIR || errexit "Failed to make a log directory: $LOG_DIR" 132 LOG_FILE=
132date > $LOG_FILE 133 date
134else
135 LOG_FILE=$LOG_DIR/ftracetest.log
136 mkdir -p $LOG_DIR || errexit "Failed to make a log directory: $LOG_DIR"
137 date > $LOG_FILE
138fi
139
133prlog() { # messages 140prlog() { # messages
134 echo "$@" | tee -a $LOG_FILE 141 [ -z "$LOG_FILE" ] && echo "$@" || echo "$@" | tee -a $LOG_FILE
135} 142}
136catlog() { #file 143catlog() { #file
137 cat $1 | tee -a $LOG_FILE 144 [ -z "$LOG_FILE" ] && cat $1 || cat $1 | tee -a $LOG_FILE
138} 145}
139prlog "=== Ftrace unit tests ===" 146prlog "=== Ftrace unit tests ==="
140 147
@@ -255,12 +262,18 @@ __run_test() { # testfile
255# Run one test case 262# Run one test case
256run_test() { # testfile 263run_test() { # testfile
257 local testname=`basename $1` 264 local testname=`basename $1`
258 local testlog=`mktemp $LOG_DIR/${testname}-log.XXXXXX` 265 if [ ! -z "$LOG_FILE" ] ; then
266 local testlog=`mktemp $LOG_DIR/${testname}-log.XXXXXX`
267 else
268 local testlog=/proc/self/fd/1
269 fi
259 export TMPDIR=`mktemp -d /tmp/ftracetest-dir.XXXXXX` 270 export TMPDIR=`mktemp -d /tmp/ftracetest-dir.XXXXXX`
260 testcase $1 271 testcase $1
261 echo "execute$INSTANCE: "$1 > $testlog 272 echo "execute$INSTANCE: "$1 > $testlog
262 SIG_RESULT=0 273 SIG_RESULT=0
263 if [ $VERBOSE -ge 3 ]; then 274 if [ -z "$LOG_FILE" ]; then
275 __run_test $1 2>&1
276 elif [ $VERBOSE -ge 3 ]; then
264 __run_test $1 | tee -a $testlog 2>&1 277 __run_test $1 | tee -a $testlog 2>&1
265 elif [ $VERBOSE -eq 2 ]; then 278 elif [ $VERBOSE -eq 2 ]; then
266 __run_test $1 2>> $testlog | tee -a $testlog 279 __run_test $1 2>> $testlog | tee -a $testlog
@@ -270,7 +283,7 @@ run_test() { # testfile
270 eval_result $SIG_RESULT 283 eval_result $SIG_RESULT
271 if [ $? -eq 0 ]; then 284 if [ $? -eq 0 ]; then
272 # Remove test log if the test was done as it was expected. 285 # Remove test log if the test was done as it was expected.
273 [ $KEEP_LOG -eq 0 ] && rm $testlog 286 [ $KEEP_LOG -eq 0 -a ! -z "$LOG_FILE" ] && rm $testlog
274 else 287 else
275 [ $VERBOSE -eq 1 -o $VERBOSE -eq 2 ] && catlog $testlog 288 [ $VERBOSE -eq 1 -o $VERBOSE -eq 2 ] && catlog $testlog
276 TOTAL_RESULT=1 289 TOTAL_RESULT=1