aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDaniel Díaz <daniel.diaz@linaro.org>2018-10-16 13:02:20 -0400
committerShuah Khan (Samsung OSG) <shuah@kernel.org>2018-10-24 16:49:37 -0400
commit8096fbcf55c0da535bdca9adab982ec0c5affb67 (patch)
tree2163b004622369bec41ef9df44c042b640134497
parent0387662d1b6c5ad2950d8e94d5e380af3f15c05c (diff)
selftests/ftrace: Use colored output when available
If test is being directly executed (with stdout opened on the terminal) and the terminal capabilities indicate enough colors, then use the existing scheme of green, red, and blue to show when tests pass, fail or end in a different way. When running the tests redirecting the stdout, for instance, to a file, then colors are not shown, thus producing a more readable output. Signed-off-by: Daniel Díaz <daniel.diaz@linaro.org> Acked-by: Steven Rostedt (VMware) <rostedt@goodmis.org> Signed-off-by: Shuah Khan (Samsung OSG) <shuah@kernel.org>
-rwxr-xr-xtools/testing/selftests/ftrace/ftracetest29
1 files changed, 22 insertions, 7 deletions
diff --git a/tools/testing/selftests/ftrace/ftracetest b/tools/testing/selftests/ftrace/ftracetest
index 4946b2edfcff..d987bbec675f 100755
--- a/tools/testing/selftests/ftrace/ftracetest
+++ b/tools/testing/selftests/ftrace/ftracetest
@@ -152,6 +152,21 @@ else
152 date > $LOG_FILE 152 date > $LOG_FILE
153fi 153fi
154 154
155# Define text colors
156# Check available colors on the terminal, if any
157ncolors=`tput colors 2>/dev/null`
158color_reset=
159color_red=
160color_green=
161color_blue=
162# If stdout exists and number of colors is eight or more, use them
163if [ -t 1 -a "$ncolors" -a "$ncolors" -ge 8 ]; then
164 color_reset="\e[0m"
165 color_red="\e[31m"
166 color_green="\e[32m"
167 color_blue="\e[34m"
168fi
169
155prlog() { # messages 170prlog() { # messages
156 [ -z "$LOG_FILE" ] && echo -e "$@" || echo -e "$@" | tee -a $LOG_FILE 171 [ -z "$LOG_FILE" ] && echo -e "$@" || echo -e "$@" | tee -a $LOG_FILE
157} 172}
@@ -195,37 +210,37 @@ test_on_instance() { # testfile
195eval_result() { # sigval 210eval_result() { # sigval
196 case $1 in 211 case $1 in
197 $PASS) 212 $PASS)
198 prlog " [\e[32mPASS\e[30m]" 213 prlog " [${color_green}PASS${color_reset}]"
199 PASSED_CASES="$PASSED_CASES $CASENO" 214 PASSED_CASES="$PASSED_CASES $CASENO"
200 return 0 215 return 0
201 ;; 216 ;;
202 $FAIL) 217 $FAIL)
203 prlog " [\e[31mFAIL\e[30m]" 218 prlog " [${color_red}FAIL${color_reset}]"
204 FAILED_CASES="$FAILED_CASES $CASENO" 219 FAILED_CASES="$FAILED_CASES $CASENO"
205 return 1 # this is a bug. 220 return 1 # this is a bug.
206 ;; 221 ;;
207 $UNRESOLVED) 222 $UNRESOLVED)
208 prlog " [\e[34mUNRESOLVED\e[30m]" 223 prlog " [${color_blue}UNRESOLVED${color_reset}]"
209 UNRESOLVED_CASES="$UNRESOLVED_CASES $CASENO" 224 UNRESOLVED_CASES="$UNRESOLVED_CASES $CASENO"
210 return 1 # this is a kind of bug.. something happened. 225 return 1 # this is a kind of bug.. something happened.
211 ;; 226 ;;
212 $UNTESTED) 227 $UNTESTED)
213 prlog " [\e[34mUNTESTED\e[30m]" 228 prlog " [${color_blue}UNTESTED${color_reset}]"
214 UNTESTED_CASES="$UNTESTED_CASES $CASENO" 229 UNTESTED_CASES="$UNTESTED_CASES $CASENO"
215 return 0 230 return 0
216 ;; 231 ;;
217 $UNSUPPORTED) 232 $UNSUPPORTED)
218 prlog " [\e[34mUNSUPPORTED\e[30m]" 233 prlog " [${color_blue}UNSUPPORTED${color_reset}]"
219 UNSUPPORTED_CASES="$UNSUPPORTED_CASES $CASENO" 234 UNSUPPORTED_CASES="$UNSUPPORTED_CASES $CASENO"
220 return $UNSUPPORTED_RESULT # depends on use case 235 return $UNSUPPORTED_RESULT # depends on use case
221 ;; 236 ;;
222 $XFAIL) 237 $XFAIL)
223 prlog " [\e[31mXFAIL\e[30m]" 238 prlog " [${color_red}XFAIL${color_reset}]"
224 XFAILED_CASES="$XFAILED_CASES $CASENO" 239 XFAILED_CASES="$XFAILED_CASES $CASENO"
225 return 0 240 return 0
226 ;; 241 ;;
227 *) 242 *)
228 prlog " [\e[34mUNDEFINED\e[30m]" 243 prlog " [${color_blue}UNDEFINED${color_reset}]"
229 UNDEFINED_CASES="$UNDEFINED_CASES $CASENO" 244 UNDEFINED_CASES="$UNDEFINED_CASES $CASENO"
230 return 1 # this must be a test bug 245 return 1 # this must be a test bug
231 ;; 246 ;;