Skip to content

Commit

Permalink
Merge tag 'linux-kselftest-4.20-rc1' of git://git.kernel.org/pub/scm/…
Browse files Browse the repository at this point in the history
…linux/kernel/git/shuah/linux-kselftest

Pull kselftest updates from Shuah Khan:
 "This Kselftest update for Linux 4.20-rc1 consists of:

   - Improvements to ftrace test suite from Masami Hiramatsu.

   - Color coded ftrace PASS / FAIL results from Steven Rostedt (VMware)
     to improve readability of reports.

   - watchdog Fixes and enhancement to add gettimeout and get|set
     pretimeout options from Jerry Hoemann.

   - Several fixes to warnings and spelling etc"

* tag 'linux-kselftest-4.20-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/shuah/linux-kselftest: (40 commits)
  selftests/ftrace: Strip escape sequences for log file
  selftests/ftrace: Use colored output when available
  selftests: fix warning: "_GNU_SOURCE" redefined
  selftests: kvm: Fix -Wformat warnings
  selftests/ftrace: Add color to the PASS / FAIL results
  kvm: selftests: fix spelling mistake "Insufficent" -> "Insufficient"
  selftests: gpio: Fix OUTPUT directory in Makefile
  selftests: gpio: restructure Makefile
  selftests: watchdog: Fix ioctl SET* error paths to take oneshot exit path
  selftests: watchdog: Add gettimeout and get|set pretimeout
  selftests: watchdog: Fix error message.
  selftests: watchdog: fix message when /dev/watchdog open fails
  selftests/ftrace: Add ftrace cpumask testcase
  selftests/ftrace: Add wakeup_rt tracer testcase
  selftests/ftrace: Add wakeup tracer testcase
  selftests/ftrace: Add stacktrace ftrace filter command testcase
  selftests/ftrace: Add trace_pipe testcase
  selftests/ftrace: Add function filter on module testcase
  selftests/ftrace: Add max stack tracer testcase
  selftests/ftrace: Add function profiling stat testcase
  ...
  • Loading branch information
Linus Torvalds committed Oct 28, 2018
2 parents dad4f14 + f73581f commit f8cab69
Show file tree
Hide file tree
Showing 67 changed files with 564 additions and 466 deletions.
6 changes: 6 additions & 0 deletions tools/testing/selftests/ftrace/config
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ CONFIG_FUNCTION_PROFILER=y
CONFIG_TRACER_SNAPSHOT=y
CONFIG_STACK_TRACER=y
CONFIG_HIST_TRIGGERS=y
CONFIG_SCHED_TRACER=y
CONFIG_PREEMPT_TRACER=y
CONFIG_IRQSOFF_TRACER=y
CONFIG_PREEMPTIRQ_DELAY_TEST=m
CONFIG_MODULES=y
CONFIG_MODULE_UNLOAD=y
CONFIG_SAMPLES=y
CONFIG_SAMPLE_TRACE_PRINTK=m
CONFIG_KALLSYMS_ALL=y
72 changes: 60 additions & 12 deletions tools/testing/selftests/ftrace/ftracetest
Original file line number Diff line number Diff line change
Expand Up @@ -60,15 +60,29 @@ parse_opts() { # opts
shift 1
;;
--verbose|-v|-vv|-vvv)
if [ $VERBOSE -eq -1 ]; then
usage "--console can not use with --verbose"
fi
VERBOSE=$((VERBOSE + 1))
[ $1 = '-vv' ] && VERBOSE=$((VERBOSE + 1))
[ $1 = '-vvv' ] && VERBOSE=$((VERBOSE + 2))
shift 1
;;
--console)
if [ $VERBOSE -ne 0 ]; then
usage "--console can not use with --verbose"
fi
VERBOSE=-1
shift 1
;;
--debug|-d)
DEBUG=1
shift 1
;;
--stop-fail)
STOP_FAILURE=1
shift 1
;;
--fail-unsupported)
UNSUPPORTED_RESULT=1
shift 1
Expand Down Expand Up @@ -117,6 +131,7 @@ KEEP_LOG=0
DEBUG=0
VERBOSE=0
UNSUPPORTED_RESULT=0
STOP_FAILURE=0
# Parse command-line options
parse_opts $*

Expand All @@ -137,11 +152,33 @@ else
date > $LOG_FILE
fi

# Define text colors
# Check available colors on the terminal, if any
ncolors=`tput colors 2>/dev/null`
color_reset=
color_red=
color_green=
color_blue=
# If stdout exists and number of colors is eight or more, use them
if [ -t 1 -a "$ncolors" -a "$ncolors" -ge 8 ]; then
color_reset="\e[0m"
color_red="\e[31m"
color_green="\e[32m"
color_blue="\e[34m"
fi

strip_esc() {
# busybox sed implementation doesn't accept "\x1B", so use [:cntrl:] instead.
sed -E "s/[[:cntrl:]]\[([0-9]{1,2}(;[0-9]{1,2})?)?[m|K]//g"
}

prlog() { # messages
[ -z "$LOG_FILE" ] && echo "$@" || echo "$@" | tee -a $LOG_FILE
echo -e "$@"
[ "$LOG_FILE" ] && echo -e "$@" | strip_esc >> $LOG_FILE
}
catlog() { #file
[ -z "$LOG_FILE" ] && cat $1 || cat $1 | tee -a $LOG_FILE
cat $1
[ "$LOG_FILE" ] && cat $1 | strip_esc >> $LOG_FILE
}
prlog "=== Ftrace unit tests ==="

Expand Down Expand Up @@ -180,37 +217,37 @@ test_on_instance() { # testfile
eval_result() { # sigval
case $1 in
$PASS)
prlog " [PASS]"
prlog " [${color_green}PASS${color_reset}]"
PASSED_CASES="$PASSED_CASES $CASENO"
return 0
;;
$FAIL)
prlog " [FAIL]"
prlog " [${color_red}FAIL${color_reset}]"
FAILED_CASES="$FAILED_CASES $CASENO"
return 1 # this is a bug.
;;
$UNRESOLVED)
prlog " [UNRESOLVED]"
prlog " [${color_blue}UNRESOLVED${color_reset}]"
UNRESOLVED_CASES="$UNRESOLVED_CASES $CASENO"
return 1 # this is a kind of bug.. something happened.
;;
$UNTESTED)
prlog " [UNTESTED]"
prlog " [${color_blue}UNTESTED${color_reset}]"
UNTESTED_CASES="$UNTESTED_CASES $CASENO"
return 0
;;
$UNSUPPORTED)
prlog " [UNSUPPORTED]"
prlog " [${color_blue}UNSUPPORTED${color_reset}]"
UNSUPPORTED_CASES="$UNSUPPORTED_CASES $CASENO"
return $UNSUPPORTED_RESULT # depends on use case
;;
$XFAIL)
prlog " [XFAIL]"
prlog " [${color_red}XFAIL${color_reset}]"
XFAILED_CASES="$XFAILED_CASES $CASENO"
return 0
;;
*)
prlog " [UNDEFINED]"
prlog " [${color_blue}UNDEFINED${color_reset}]"
UNDEFINED_CASES="$UNDEFINED_CASES $CASENO"
return 1 # this must be a test bug
;;
Expand Down Expand Up @@ -269,16 +306,18 @@ __run_test() { # testfile
# Run one test case
run_test() { # testfile
local testname=`basename $1`
testcase $1
if [ ! -z "$LOG_FILE" ] ; then
local testlog=`mktemp $LOG_DIR/${testname}-log.XXXXXX`
local testlog=`mktemp $LOG_DIR/${CASENO}-${testname}-log.XXXXXX`
else
local testlog=/proc/self/fd/1
fi
export TMPDIR=`mktemp -d /tmp/ftracetest-dir.XXXXXX`
testcase $1
echo "execute$INSTANCE: "$1 > $testlog
SIG_RESULT=0
if [ -z "$LOG_FILE" ]; then
if [ $VERBOSE -eq -1 ]; then
__run_test $1
elif [ -z "$LOG_FILE" ]; then
__run_test $1 2>&1
elif [ $VERBOSE -ge 3 ]; then
__run_test $1 | tee -a $testlog 2>&1
Expand All @@ -304,6 +343,10 @@ run_test() { # testfile
# Main loop
for t in $TEST_CASES; do
run_test $t
if [ $STOP_FAILURE -ne 0 -a $TOTAL_RESULT -ne 0 ]; then
echo "A failure detected. Stop test."
exit 1
fi
done

# Test on instance loop
Expand All @@ -315,7 +358,12 @@ for t in $TEST_CASES; do
run_test $t
rmdir $TRACING_DIR
TRACING_DIR=$SAVED_TRACING_DIR
if [ $STOP_FAILURE -ne 0 -a $TOTAL_RESULT -ne 0 ]; then
echo "A failure detected. Stop test."
exit 1
fi
done
(cd $TRACING_DIR; initialize_ftrace) # for cleanup

prlog ""
prlog "# of passed: " `echo $PASSED_CASES | wc -w`
Expand Down
22 changes: 22 additions & 0 deletions tools/testing/selftests/ftrace/test.d/00basic/ringbuffer_size.tc
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/bin/sh
# SPDX-License-Identifier: GPL-2.0
# description: Change the ringbuffer size
# flags: instance

rb_size_test() {
ORIG=`cat buffer_size_kb`

expr $ORIG / 2 > buffer_size_kb

expr $ORIG \* 2 > buffer_size_kb

echo $ORIG > buffer_size_kb
}

rb_size_test

: "If per-cpu buffer is supported, imbalance it"
if [ -d per_cpu/cpu0 ]; then
cd per_cpu/cpu0
rb_size_test
fi
16 changes: 16 additions & 0 deletions tools/testing/selftests/ftrace/test.d/00basic/trace_pipe.tc
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/bin/sh
# SPDX-License-Identifier: GPL-2.0
# description: trace_pipe and trace_marker
# flags: instance

[ ! -f trace_marker ] && exit_unsupported

echo "test input 1" > trace_marker

: "trace interface never consume the ring buffer"
grep -q "test input 1" trace
grep -q "test input 1" trace

: "trace interface never consume the ring buffer"
head -n 1 trace_pipe | grep -q "test input 1"
! grep -q "test input 1" trace
10 changes: 0 additions & 10 deletions tools/testing/selftests/ftrace/test.d/event/event-enable.tc
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,15 @@ do_reset() {
}

fail() { #msg
do_reset
echo $1
exit_fail
}

yield() {
ping localhost -c 1 || sleep .001 || usleep 1 || sleep 1
}

if [ ! -f set_event -o ! -d events/sched ]; then
echo "event tracing is not supported"
exit_unsupported
fi

reset_tracer
do_reset

echo 'sched:sched_switch' > set_event

yield
Expand Down Expand Up @@ -57,6 +49,4 @@ if [ $count -ne 0 ]; then
fail "sched_switch events should not be recorded"
fi

do_reset

exit 0
8 changes: 2 additions & 6 deletions tools/testing/selftests/ftrace/test.d/event/event-pid.tc
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,6 @@ fail() { #msg
exit_fail
}

yield() {
ping localhost -c 1 || sleep .001 || usleep 1 || sleep 1
}

if [ ! -f set_event -o ! -d events/sched ]; then
echo "event tracing is not supported"
exit_unsupported
Expand All @@ -30,8 +26,7 @@ if [ ! -f set_event_pid ]; then
exit_unsupported
fi

reset_tracer
do_reset
echo 0 > options/event-fork

echo 1 > events/sched/sched_switch/enable

Expand All @@ -47,6 +42,7 @@ do_reset
read mypid rest < /proc/self/stat

echo $mypid > set_event_pid
grep -q $mypid set_event_pid
echo 'sched:sched_switch' > set_event

yield
Expand Down
10 changes: 0 additions & 10 deletions tools/testing/selftests/ftrace/test.d/event/subsystem-enable.tc
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,15 @@ do_reset() {
}

fail() { #msg
do_reset
echo $1
exit_fail
}

yield() {
ping localhost -c 1 || sleep .001 || usleep 1 || sleep 1
}

if [ ! -f set_event -o ! -d events/sched ]; then
echo "event tracing is not supported"
exit_unsupported
fi

reset_tracer
do_reset

echo 'sched:*' > set_event

yield
Expand Down Expand Up @@ -57,6 +49,4 @@ if [ $count -ne 0 ]; then
fail "any of scheduler events should not be recorded"
fi

do_reset

exit 0
10 changes: 0 additions & 10 deletions tools/testing/selftests/ftrace/test.d/event/toplevel-enable.tc
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,15 @@ do_reset() {
}

fail() { #msg
do_reset
echo $1
exit_fail
}

yield() {
ping localhost -c 1 || sleep .001 || usleep 1 || sleep 1
}

if [ ! -f available_events -o ! -f set_event -o ! -d events ]; then
echo "event tracing is not supported"
exit_unsupported
fi

reset_tracer
do_reset

echo '*:*' > set_event

yield
Expand Down Expand Up @@ -60,6 +52,4 @@ if [ $count -ne 0 ]; then
fail "any of events should not be recorded"
fi

do_reset

exit 0
27 changes: 27 additions & 0 deletions tools/testing/selftests/ftrace/test.d/event/trace_printk.tc
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#!/bin/sh
# SPDX-License-Identifier: GPL-2.0
# description: Test trace_printk from module

rmmod trace-printk ||:
if ! modprobe trace-printk ; then
echo "No trace-printk sample module - please make CONFIG_SAMPLE_TRACE_PRINTK=m"
exit_unresolved;
fi

echo "Waiting for irq work"
sleep 1

grep -q ": This .* trace_bputs" trace
grep -q ": This .* trace_puts" trace
grep -q ": This .* trace_bprintk" trace
grep -q ": This .* trace_printk" trace

grep -q ": (irq) .* trace_bputs" trace
grep -q ": (irq) .* trace_puts" trace
grep -q ": (irq) .* trace_bprintk" trace
grep -q ": (irq) .* trace_printk" trace

grep -q "This is a %s that will use trace_bprintk" printk_formats
grep -q "(irq) This is a static string that will use trace_bputs" printk_formats

rmmod trace-printk ||:
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,9 @@ if [ ! -f set_ftrace_filter ]; then
fi

do_reset() {
reset_tracer
if [ -e /proc/sys/kernel/stack_tracer_enabled ]; then
echo 0 > /proc/sys/kernel/stack_tracer_enabled
fi
enable_tracing
clear_trace
echo > set_ftrace_filter
}

fail() { # msg
Expand Down
Loading

0 comments on commit f8cab69

Please sign in to comment.