diff options
author | Masami Hiramatsu <mhiramat@kernel.org> | 2017-07-06 21:02:33 -0400 |
---|---|---|
committer | Shuah Khan <shuahkh@osg.samsung.com> | 2017-07-26 17:41:36 -0400 |
commit | 97bece60ef87d813cbe6f8f9b8e532a6a95d422a (patch) | |
tree | 89deb105cd435c13134631415c483152e779f90f /tools | |
parent | dab24fb1f2d6dfb6b134535e4510cb1f681d9d23 (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-x | tools/testing/selftests/ftrace/ftracetest | 29 |
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)" | |||
19 | echo " --fail-unsupported Treat UNSUPPORTED as a failure" | 19 | echo " --fail-unsupported Treat UNSUPPORTED as a failure" |
20 | echo " -d|--debug Debug mode (trace all shell commands)" | 20 | echo " -d|--debug Debug mode (trace all shell commands)" |
21 | echo " -l|--logdir <dir> Save logs on the <dir>" | 21 | echo " -l|--logdir <dir> Save logs on the <dir>" |
22 | echo " If <dir> is -, all logs output in console only" | ||
22 | exit $1 | 23 | exit $1 |
23 | } | 24 | } |
24 | 25 | ||
@@ -127,14 +128,20 @@ if [ -z "$TRACING_DIR" -o ! -d "$TRACING_DIR" ]; then | |||
127 | fi | 128 | fi |
128 | 129 | ||
129 | # Preparing logs | 130 | # Preparing logs |
130 | LOG_FILE=$LOG_DIR/ftracetest.log | 131 | if [ "x$LOG_DIR" = "x-" ]; then |
131 | mkdir -p $LOG_DIR || errexit "Failed to make a log directory: $LOG_DIR" | 132 | LOG_FILE= |
132 | date > $LOG_FILE | 133 | date |
134 | else | ||
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 | ||
138 | fi | ||
139 | |||
133 | prlog() { # messages | 140 | prlog() { # messages |
134 | echo "$@" | tee -a $LOG_FILE | 141 | [ -z "$LOG_FILE" ] && echo "$@" || echo "$@" | tee -a $LOG_FILE |
135 | } | 142 | } |
136 | catlog() { #file | 143 | catlog() { #file |
137 | cat $1 | tee -a $LOG_FILE | 144 | [ -z "$LOG_FILE" ] && cat $1 || cat $1 | tee -a $LOG_FILE |
138 | } | 145 | } |
139 | prlog "=== Ftrace unit tests ===" | 146 | prlog "=== Ftrace unit tests ===" |
140 | 147 | ||
@@ -255,12 +262,18 @@ __run_test() { # testfile | |||
255 | # Run one test case | 262 | # Run one test case |
256 | run_test() { # testfile | 263 | run_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 |