Commit 23a68d14 authored by Linus Torvalds's avatar Linus Torvalds

Merge tag 'linux-kselftest-next-6.2-rc1' of...

Merge tag 'linux-kselftest-next-6.2-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/shuah/linux-kselftest

Pull Kselftest updates from Shuah Khan:
 "Several fixes and enhancements to existing tests and a few new tests:

   - add new amd-pstate tests and fix and enhance existing ones

   - add new watchdog tests and enhance existing ones to improve
     coverage

   - fixes to ftrace, splice_read, rtc, and efivars tests

   - fixes to handle egrep obsolescence in the latest grep release

   - miscellaneous spelling and SPDX fixes"

* tag 'linux-kselftest-next-6.2-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/shuah/linux-kselftest: (24 commits)
  selftests/ftrace: Use long for synthetic event probe test
  selftests/tpm2: Split async tests call to separate shell script runner
  selftests: splice_read: Fix sysfs read cases
  selftests: ftrace: Use "grep -E" instead of "egrep"
  selftests: gpio: Use "grep -E" instead of "egrep"
  selftests: kselftest_deps: Use "grep -E" instead of "egrep"
  selftests/efivarfs: Add checking of the test return value
  cpufreq: amd-pstate: fix spdxcheck warnings for amd-pstate-ut.c
  selftests: rtc: skip when RTC is not present
  selftests/ftrace: event_triggers: wait longer for test_event_enable
  selftests/vDSO: Add riscv getcpu & gettimeofday test
  Documentation: amd-pstate: Add tbench and gitsource test introduction
  selftests: amd-pstate: Trigger gitsource benchmark and test cpus
  selftests: amd-pstate: Trigger tbench benchmark and test cpus
  selftests: amd-pstate: Split basic.sh into run.sh and basic.sh.
  selftests: amd-pstate: Rename amd-pstate-ut.sh to basic.sh.
  selftests/ftrace: Convert tracer tests to use 'requires' to specify program dependency
  selftests/ftrace: Add check for ping command for trigger tests
  selftests/watchdog: Fix spelling mistake "Temeprature" -> "Temperature"
  selftests/watchdog: add test for WDIOC_GETTEMP
  ...
parents 268325bd d5ba85d6
This diff is collapsed.
// SPDX-License-Identifier: GPL-1.0-or-later
// SPDX-License-Identifier: GPL-2.0-or-later
/*
* AMD Processor P-state Frequency Driver Unit Test
*
......
......@@ -4,6 +4,15 @@
# No binaries, but make sure arg-less "make" doesn't trigger "run_tests"
all:
TEST_PROGS := amd-pstate-ut.sh
uname_M := $(shell uname -m 2>/dev/null || echo not)
ARCH ?= $(shell echo $(uname_M) | sed -e s/i.86/x86/ -e s/x86_64/x86/)
ifeq (x86,$(ARCH))
TEST_GEN_FILES += ../../../power/x86/amd_pstate_tracer/amd_pstate_trace.py
TEST_GEN_FILES += ../../../power/x86/intel_pstate_tracer/intel_pstate_tracer.py
endif
TEST_PROGS := run.sh
TEST_FILES := basic.sh tbench.sh gitsource.sh
include ../lib.mk
......@@ -11,46 +11,28 @@
# (3) We can introduce more functional or performance tests to align
# the result together, it will benefit power and performance scale optimization.
# Kselftest framework requirement - SKIP code is 4.
ksft_skip=4
# amd-pstate-ut only run on x86/x86_64 AMD systems.
ARCH=$(uname -m 2>/dev/null | sed -e 's/i.86/x86/' -e 's/x86_64/x86/')
VENDOR=$(cat /proc/cpuinfo | grep -m 1 'vendor_id' | awk '{print $NF}')
if ! echo "$ARCH" | grep -q x86; then
echo "$0 # Skipped: Test can only run on x86 architectures."
exit $ksft_skip
fi
if ! echo "$VENDOR" | grep -iq amd; then
echo "$0 # Skipped: Test can only run on AMD CPU."
echo "$0 # Current cpu vendor is $VENDOR."
exit $ksft_skip
fi
scaling_driver=$(cat /sys/devices/system/cpu/cpufreq/policy0/scaling_driver)
if [ "$scaling_driver" != "amd-pstate" ]; then
echo "$0 # Skipped: Test can only run on amd-pstate driver."
echo "$0 # Please set X86_AMD_PSTATE enabled."
echo "$0 # Current cpufreq scaling drvier is $scaling_driver."
exit $ksft_skip
fi
msg="Skip all tests:"
if [ ! -w /dev ]; then
echo $msg please run this as root >&2
exit $ksft_skip
fi
if ! /sbin/modprobe -q -n amd-pstate-ut; then
echo "amd-pstate-ut: module amd-pstate-ut is not found [SKIP]"
exit $ksft_skip
fi
if /sbin/modprobe -q amd-pstate-ut; then
/sbin/modprobe -q -r amd-pstate-ut
echo "amd-pstate-ut: ok"
# protect against multiple inclusion
if [ $FILE_BASIC ]; then
return 0
else
echo "amd-pstate-ut: [FAIL]"
exit 1
FILE_BASIC=DONE
fi
amd_pstate_basic()
{
printf "\n---------------------------------------------\n"
printf "*** Running AMD P-state ut ***"
printf "\n---------------------------------------------\n"
if ! /sbin/modprobe -q -n amd-pstate-ut; then
echo "amd-pstate-ut: module amd-pstate-ut is not found [SKIP]"
exit $ksft_skip
fi
if /sbin/modprobe -q amd-pstate-ut; then
/sbin/modprobe -q -r amd-pstate-ut
echo "amd-pstate-basic: ok"
else
echo "amd-pstate-basic: [FAIL]"
exit 1
fi
}
This diff is collapsed.
#!/bin/bash
# SPDX-License-Identifier: GPL-2.0
# protect against multiple inclusion
if [ $FILE_MAIN ]; then
return 0
else
FILE_MAIN=DONE
fi
source basic.sh
source tbench.sh
source gitsource.sh
# amd-pstate-ut only run on x86/x86_64 AMD systems.
ARCH=$(uname -m 2>/dev/null | sed -e 's/i.86/x86/' -e 's/x86_64/x86/')
VENDOR=$(cat /proc/cpuinfo | grep -m 1 'vendor_id' | awk '{print $NF}')
msg="Skip all tests:"
FUNC=all
OUTFILE=selftest
OUTFILE_TBENCH="$OUTFILE.tbench"
OUTFILE_GIT="$OUTFILE.gitsource"
SYSFS=
CPUROOT=
CPUFREQROOT=
MAKE_CPUS=
TIME_LIMIT=100
PROCESS_NUM=128
LOOP_TIMES=3
TRACER_INTERVAL=10
CURRENT_TEST=amd-pstate
COMPARATIVE_TEST=
# Kselftest framework requirement - SKIP code is 4.
ksft_skip=4
all_scaling_names=("acpi-cpufreq" "amd-pstate")
# Get current cpufreq scaling driver name
scaling_name()
{
if [ "$COMPARATIVE_TEST" = "" ]; then
echo "$CURRENT_TEST"
else
echo "$COMPARATIVE_TEST"
fi
}
# Counts CPUs with cpufreq directories
count_cpus()
{
count=0;
for cpu in `ls $CPUROOT | grep "cpu[0-9].*"`; do
if [ -d $CPUROOT/$cpu/cpufreq ]; then
let count=count+1;
fi
done
echo $count;
}
# $1: policy
find_current_governor()
{
cat $CPUFREQROOT/$1/scaling_governor
}
backup_governor()
{
policies=$(ls $CPUFREQROOT| grep "policy[0-9].*")
for policy in $policies; do
cur_gov=$(find_current_governor $policy)
echo "$policy $cur_gov" >> $OUTFILE.backup_governor.log
done
printf "Governor $cur_gov backup done.\n"
}
restore_governor()
{
i=0;
policies=$(awk '{print $1}' $OUTFILE.backup_governor.log)
for policy in $policies; do
let i++;
governor=$(sed -n ''$i'p' $OUTFILE.backup_governor.log | awk '{print $2}')
# switch governor
echo $governor > $CPUFREQROOT/$policy/scaling_governor
done
printf "Governor restored to $governor.\n"
}
# $1: governor
switch_governor()
{
policies=$(ls $CPUFREQROOT| grep "policy[0-9].*")
for policy in $policies; do
filepath=$CPUFREQROOT/$policy/scaling_available_governors
# Exit if cpu isn't managed by cpufreq core
if [ ! -f $filepath ]; then
return;
fi
echo $1 > $CPUFREQROOT/$policy/scaling_governor
done
printf "Switched governor to $1.\n"
}
# All amd-pstate tests
amd_pstate_all()
{
printf "\n=============================================\n"
printf "***** Running AMD P-state Sanity Tests *****\n"
printf "=============================================\n\n"
count=$(count_cpus)
if [ $count = 0 ]; then
printf "No cpu is managed by cpufreq core, exiting\n"
exit;
else
printf "AMD P-state manages: $count CPUs\n"
fi
# unit test for amd-pstate kernel driver
amd_pstate_basic
# tbench
amd_pstate_tbench
# gitsource
amd_pstate_gitsource
}
help()
{
printf "Usage: $0 [OPTION...]
[-h <help>]
[-o <output-file-for-dump>]
[-c <all: All testing,
basic: Basic testing,
tbench: Tbench testing,
gitsource: Gitsource testing.>]
[-t <tbench time limit>]
[-p <tbench process number>]
[-l <loop times for tbench>]
[-i <amd tracer interval>]
[-m <comparative test: acpi-cpufreq>]
\n"
exit 2
}
parse_arguments()
{
while getopts ho:c:t:p:l:i:m: arg
do
case $arg in
h) # --help
help
;;
c) # --func_type (Function to perform: basic, tbench, gitsource (default: all))
FUNC=$OPTARG
;;
o) # --output-file (Output file to store dumps)
OUTFILE=$OPTARG
;;
t) # --tbench-time-limit
TIME_LIMIT=$OPTARG
;;
p) # --tbench-process-number
PROCESS_NUM=$OPTARG
;;
l) # --tbench/gitsource-loop-times
LOOP_TIMES=$OPTARG
;;
i) # --amd-tracer-interval
TRACER_INTERVAL=$OPTARG
;;
m) # --comparative-test
COMPARATIVE_TEST=$OPTARG
;;
*)
help
;;
esac
done
}
command_perf()
{
if ! command -v perf > /dev/null; then
echo $msg please install perf. >&2
exit $ksft_skip
fi
}
command_tbench()
{
if ! command -v tbench > /dev/null; then
if apt policy dbench > /dev/null 2>&1; then
echo $msg apt install dbench >&2
exit $ksft_skip
elif yum list available | grep dbench > /dev/null 2>&1; then
echo $msg yum install dbench >&2
exit $ksft_skip
fi
fi
if ! command -v tbench > /dev/null; then
echo $msg please install tbench. >&2
exit $ksft_skip
fi
}
prerequisite()
{
if ! echo "$ARCH" | grep -q x86; then
echo "$0 # Skipped: Test can only run on x86 architectures."
exit $ksft_skip
fi
if ! echo "$VENDOR" | grep -iq amd; then
echo "$0 # Skipped: Test can only run on AMD CPU."
echo "$0 # Current cpu vendor is $VENDOR."
exit $ksft_skip
fi
scaling_driver=$(cat /sys/devices/system/cpu/cpufreq/policy0/scaling_driver)
if [ "$COMPARATIVE_TEST" = "" ]; then
if [ "$scaling_driver" != "$CURRENT_TEST" ]; then
echo "$0 # Skipped: Test can only run on $CURRENT_TEST driver or run comparative test."
echo "$0 # Please set X86_AMD_PSTATE enabled or run comparative test."
echo "$0 # Current cpufreq scaling drvier is $scaling_driver."
exit $ksft_skip
fi
else
case "$FUNC" in
"tbench" | "gitsource")
if [ "$scaling_driver" != "$COMPARATIVE_TEST" ]; then
echo "$0 # Skipped: Comparison test can only run on $COMPARISON_TEST driver."
echo "$0 # Current cpufreq scaling drvier is $scaling_driver."
exit $ksft_skip
fi
;;
*)
echo "$0 # Skipped: Comparison test are only for tbench or gitsource."
echo "$0 # Current comparative test is for $FUNC."
exit $ksft_skip
;;
esac
fi
if [ ! -w /dev ]; then
echo $msg please run this as root >&2
exit $ksft_skip
fi
case "$FUNC" in
"all")
command_perf
command_tbench
;;
"tbench")
command_perf
command_tbench
;;
"gitsource")
command_perf
;;
esac
SYSFS=`mount -t sysfs | head -1 | awk '{ print $3 }'`
if [ ! -d "$SYSFS" ]; then
echo $msg sysfs is not mounted >&2
exit 2
fi
CPUROOT=$SYSFS/devices/system/cpu
CPUFREQROOT="$CPUROOT/cpufreq"
if ! ls $CPUROOT/cpu* > /dev/null 2>&1; then
echo $msg cpus not available in sysfs >&2
exit 2
fi
if ! ls $CPUROOT/cpufreq > /dev/null 2>&1; then
echo $msg cpufreq directory not available in sysfs >&2
exit 2
fi
}
do_test()
{
# Check if CPUs are managed by cpufreq or not
count=$(count_cpus)
MAKE_CPUS=$((count*2))
if [ $count = 0 ]; then
echo "No cpu is managed by cpufreq core, exiting"
exit 2;
fi
case "$FUNC" in
"all")
amd_pstate_all
;;
"basic")
amd_pstate_basic
;;
"tbench")
amd_pstate_tbench
;;
"gitsource")
amd_pstate_gitsource
;;
*)
echo "Invalid [-f] function type"
help
;;
esac
}
# clear dumps
pre_clear_dumps()
{
case "$FUNC" in
"all")
rm -rf $OUTFILE.log
rm -rf $OUTFILE.backup_governor.log
rm -rf *.png
;;
"tbench")
rm -rf $OUTFILE.log
rm -rf $OUTFILE.backup_governor.log
rm -rf tbench_*.png
;;
"gitsource")
rm -rf $OUTFILE.log
rm -rf $OUTFILE.backup_governor.log
rm -rf gitsource_*.png
;;
*)
;;
esac
}
post_clear_dumps()
{
rm -rf $OUTFILE.log
rm -rf $OUTFILE.backup_governor.log
}
# Parse arguments
parse_arguments $@
# Make sure all requirements are met
prerequisite
# Run requested functions
pre_clear_dumps
do_test | tee -a $OUTFILE.log
post_clear_dumps
This diff is collapsed.
......@@ -87,6 +87,11 @@ test_create_read()
{
local file=$efivarfs_mount/$FUNCNAME-$test_guid
./create-read $file
if [ $? -ne 0 ]; then
echo "create and read $file failed"
file_cleanup $file
exit 1
fi
file_cleanup $file
}
......
......@@ -38,11 +38,18 @@ cnt_trace() {
test_event_enabled() {
val=$1
check_times=10 # wait for 10 * SLEEP_TIME at most
e=`cat $EVENT_ENABLE`
if [ "$e" != $val ]; then
fail "Expected $val but found $e"
fi
while [ $check_times -ne 0 ]; do
e=`cat $EVENT_ENABLE`
if [ "$e" == $val ]; then
return 0
fi
sleep $SLEEP_TIME
check_times=$((check_times - 1))
done
fail "Expected $val but found $e"
}
run_enable_disable() {
......
......@@ -142,9 +142,15 @@ finish_ftrace() {
check_requires() { # Check required files and tracers
for i in "$@" ; do
p=${i%:program}
r=${i%:README}
t=${i%:tracer}
if [ $t != $i ]; then
if [ $p != $i ]; then
if ! which $p ; then
echo "Required program $p is not found."
exit_unresolved
fi
elif [ $t != $i ]; then
if ! grep -wq $t available_tracers ; then
echo "Required tracer $t is not configured."
exit_unsupported
......
......@@ -46,10 +46,10 @@ cat trace
grep -q "tracer: preemptoff" trace || fail
# Check the end of the section
egrep -q "5.....us : <stack trace>" trace || fail
grep -E -q "5.....us : <stack trace>" trace || fail
# Check for 500ms of latency
egrep -q "latency: 5..... us" trace || fail
grep -E -q "latency: 5..... us" trace || fail
reset_tracer
......@@ -69,10 +69,10 @@ cat trace
grep -q "tracer: irqsoff" trace || fail
# Check the end of the section
egrep -q "5.....us : <stack trace>" trace || fail
grep -E -q "5.....us : <stack trace>" trace || fail
# Check for 500ms of latency
egrep -q "latency: 5..... us" trace || fail
grep -E -q "latency: 5..... us" trace || fail
reset_tracer
exit 0
#!/bin/sh
# SPDX-License-Identifier: GPL-2.0
# description: Test wakeup tracer
# requires: wakeup:tracer
if ! which chrt ; then
echo "chrt is not found. This test requires nice command."
exit_unresolved
fi
# requires: wakeup:tracer chrt:program
echo wakeup > current_tracer
echo 1 > tracing_on
......
#!/bin/sh
# SPDX-License-Identifier: GPL-2.0
# description: Test wakeup RT tracer
# requires: wakeup_rt:tracer
if ! which chrt ; then
echo "chrt is not found. This test requires chrt command."
exit_unresolved
fi
# requires: wakeup_rt:tracer chrt:program
echo wakeup_rt > current_tracer
echo 1 > tracing_on
......
#!/bin/sh
# SPDX-License-Identifier: GPL-2.0
# description: event trigger - test field variable support
# requires: set_event synthetic_events events/sched/sched_process_fork/hist
# requires: set_event synthetic_events events/sched/sched_process_fork/hist ping:program
fail() { #msg
echo $1
......
#!/bin/sh
# SPDX-License-Identifier: GPL-2.0
# description: event trigger - test inter-event combined histogram trigger
# requires: set_event synthetic_events events/sched/sched_process_fork/hist
# requires: set_event synthetic_events events/sched/sched_process_fork/hist ping:program
fail() { #msg
echo $1
......
#!/bin/sh
# SPDX-License-Identifier: GPL-2.0
# description: event trigger - test inter-event histogram trigger onchange action
# requires: set_event "onchange(var)":README
# requires: set_event "onchange(var)":README ping:program
fail() { #msg
echo $1
......
#!/bin/sh
# SPDX-License-Identifier: GPL-2.0
# description: event trigger - test inter-event histogram trigger onmatch action
# requires: set_event synthetic_events events/sched/sched_process_fork/hist
# requires: set_event synthetic_events events/sched/sched_process_fork/hist ping:program
fail() { #msg
echo $1
......
#!/bin/sh
# SPDX-License-Identifier: GPL-2.0
# description: event trigger - test inter-event histogram trigger onmatch-onmax action
# requires: set_event synthetic_events events/sched/sched_process_fork/hist
# requires: set_event synthetic_events events/sched/sched_process_fork/hist ping:program
fail() { #msg
echo $1
......
#!/bin/sh
# SPDX-License-Identifier: GPL-2.0
# description: event trigger - test inter-event histogram trigger onmax action
# requires: set_event synthetic_events events/sched/sched_process_fork/hist
# requires: set_event synthetic_events events/sched/sched_process_fork/hist ping:program
fail() { #msg
echo $1
......
#!/bin/sh
# SPDX-License-Identifier: GPL-2.0
# description: event trigger - test inter-event histogram trigger snapshot action
# requires: set_event snapshot events/sched/sched_process_fork/hist "onchange(var)":README "snapshot()":README
# requires: set_event snapshot events/sched/sched_process_fork/hist "onchange(var)":README "snapshot()":README ping:program
fail() { #msg
echo $1
......
......@@ -14,7 +14,7 @@ FIELD="filename"
SYNTH="synth_open"
EPROBE="eprobe_open"
echo "$SYNTH u64 filename; s64 ret;" > synthetic_events
echo "$SYNTH unsigned long filename; long ret;" > synthetic_events
echo "hist:keys=common_pid:__arg__1=$FIELD" > events/$SYSTEM/$START/trigger
echo "hist:keys=common_pid:filename=\$__arg__1,ret=ret:onmatch($SYSTEM.$START).trace($SYNTH,\$filename,\$ret)" > events/$SYSTEM/$END/trigger
......
#!/bin/sh
# SPDX-License-Identifier: GPL-2.0
# description: event trigger - test inter-event histogram trigger trace action with dynamic string param
# requires: set_event synthetic_events events/sched/sched_process_exec/hist "char name[]' >> synthetic_events":README
# requires: set_event synthetic_events events/sched/sched_process_exec/hist "char name[]' >> synthetic_events":README ping:program
fail() { #msg
echo $1
......
#!/bin/sh
# SPDX-License-Identifier: GPL-2.0
# description: event trigger - test inter-event histogram trigger trace action
# requires: set_event synthetic_events events/sched/sched_process_fork/hist "trace(<synthetic_event>":README
# requires: set_event synthetic_events events/sched/sched_process_fork/hist "trace(<synthetic_event>":README ping:program
fail() { #msg
echo $1
......
......@@ -27,7 +27,7 @@ remove_chip() {
continue
fi
LINES=`ls $CONFIGFS_DIR/$CHIP/$BANK/ | egrep ^line`
LINES=`ls $CONFIGFS_DIR/$CHIP/$BANK/ | grep -E ^line`
if [ "$?" = 0 ]; then
for LINE in $LINES; do
if [ -e $CONFIGFS_DIR/$CHIP/$BANK/$LINE/hog ]; then
......
......@@ -90,7 +90,7 @@ pass_libs=()
pass_cnt=0
# Get all TARGETS from selftests Makefile
targets=$(egrep "^TARGETS +|^TARGETS =" Makefile | cut -d "=" -f2)
targets=$(grep -E "^TARGETS +|^TARGETS =" Makefile | cut -d "=" -f2)
# Single test case
if [ $# -eq 2 ]
......
......@@ -123,6 +123,11 @@ endef
clean:
$(CLEAN)
# Enables to extend CFLAGS and LDFLAGS from command line, e.g.
# make USERCFLAGS=-Werror USERLDFLAGS=-static
CFLAGS += $(USERCFLAGS)
LDFLAGS += $(USERLDFLAGS)
# When make O= with kselftest target from main level
# the following aren't defined.
#
......
......@@ -31,7 +31,6 @@ FIXTURE(rtc) {
FIXTURE_SETUP(rtc) {
self->fd = open(rtc_file, O_RDONLY);
ASSERT_NE(-1, self->fd);
}
FIXTURE_TEARDOWN(rtc) {
......@@ -42,6 +41,10 @@ TEST_F(rtc, date_read) {
int rc;
struct rtc_time rtc_tm;
if (self->fd == -1 && errno == ENOENT)
SKIP(return, "Skipping test since %s does not exist", rtc_file);
ASSERT_NE(-1, self->fd);
/* Read the RTC time/date */
rc = ioctl(self->fd, RTC_RD_TIME, &rtc_tm);
ASSERT_NE(-1, rc);
......@@ -85,6 +88,10 @@ TEST_F_TIMEOUT(rtc, date_read_loop, READ_LOOP_DURATION_SEC + 2) {
struct rtc_time rtc_tm;
time_t start_rtc_read, prev_rtc_read;
if (self->fd == -1 && errno == ENOENT)
SKIP(return, "Skipping test since %s does not exist", rtc_file);
ASSERT_NE(-1, self->fd);
TH_LOG("Continuously reading RTC time for %ds (with %dms breaks after every read).",
READ_LOOP_DURATION_SEC, READ_LOOP_SLEEP_MS);
......@@ -119,6 +126,10 @@ TEST_F_TIMEOUT(rtc, uie_read, NUM_UIE + 2) {
int i, rc, irq = 0;
unsigned long data;
if (self->fd == -1 && errno == ENOENT)
SKIP(return, "Skipping test since %s does not exist", rtc_file);
ASSERT_NE(-1, self->fd);
/* Turn on update interrupts */
rc = ioctl(self->fd, RTC_UIE_ON, 0);
if (rc == -1) {
......@@ -144,6 +155,10 @@ TEST_F(rtc, uie_select) {
int i, rc, irq = 0;
unsigned long data;
if (self->fd == -1 && errno == ENOENT)
SKIP(return, "Skipping test since %s does not exist", rtc_file);
ASSERT_NE(-1, self->fd);
/* Turn on update interrupts */
rc = ioctl(self->fd, RTC_UIE_ON, 0);
if (rc == -1) {
......@@ -183,6 +198,10 @@ TEST_F(rtc, alarm_alm_set) {
time_t secs, new;
int rc;
if (self->fd == -1 && errno == ENOENT)
SKIP(return, "Skipping test since %s does not exist", rtc_file);
ASSERT_NE(-1, self->fd);
rc = ioctl(self->fd, RTC_RD_TIME, &tm);
ASSERT_NE(-1, rc);
......@@ -237,6 +256,10 @@ TEST_F(rtc, alarm_wkalm_set) {
time_t secs, new;
int rc;
if (self->fd == -1 && errno == ENOENT)
SKIP(return, "Skipping test since %s does not exist", rtc_file);
ASSERT_NE(-1, self->fd);
rc = ioctl(self->fd, RTC_RD_TIME, &alarm.time);
ASSERT_NE(-1, rc);
......@@ -285,6 +308,10 @@ TEST_F_TIMEOUT(rtc, alarm_alm_set_minute, 65) {
time_t secs, new;
int rc;
if (self->fd == -1 && errno == ENOENT)
SKIP(return, "Skipping test since %s does not exist", rtc_file);
ASSERT_NE(-1, self->fd);
rc = ioctl(self->fd, RTC_RD_TIME, &tm);
ASSERT_NE(-1, rc);
......@@ -339,6 +366,10 @@ TEST_F_TIMEOUT(rtc, alarm_wkalm_set_minute, 65) {
time_t secs, new;
int rc;
if (self->fd == -1 && errno == ENOENT)
SKIP(return, "Skipping test since %s does not exist", rtc_file);
ASSERT_NE(-1, self->fd);
rc = ioctl(self->fd, RTC_RD_TIME, &alarm.time);
ASSERT_NE(-1, rc);
......
......@@ -127,7 +127,7 @@ expect_success "proc_handler: special read splice" test_splice /proc/sys/kernel/
if ! [ -d /sys/module/test_module/sections ] ; then
expect_success "test_module kernel module load" modprobe test_module
fi
expect_failure "kernfs attr splice" test_splice /sys/module/test_module/coresize
expect_failure "kernfs binattr splice" test_splice /sys/module/test_module/sections/.init.text
expect_success "kernfs attr splice" test_splice /sys/module/test_module/coresize
expect_success "kernfs binattr splice" test_splice /sys/module/test_module/sections/.init.text
exit $ret
# SPDX-License-Identifier: (GPL-2.0 OR BSD-3-Clause)
include ../lib.mk
TEST_PROGS := test_smoke.sh test_space.sh
TEST_PROGS := test_smoke.sh test_space.sh test_async.sh
TEST_PROGS_EXTENDED := tpm2.py tpm2_tests.py
#!/bin/sh
# SPDX-License-Identifier: (GPL-2.0 OR BSD-3-Clause)
# Kselftest framework requirement - SKIP code is 4.
ksft_skip=4
[ -e /dev/tpm0 ] || exit $ksft_skip
[ -e /dev/tpmrm0 ] || exit $ksft_skip
python3 -m unittest -v tpm2_tests.AsyncTest
......@@ -7,4 +7,3 @@ ksft_skip=4
[ -e /dev/tpm0 ] || exit $ksft_skip
python3 -m unittest -v tpm2_tests.SmokeTest
python3 -m unittest -v tpm2_tests.AsyncTest
......@@ -14,7 +14,11 @@
#include "../kselftest.h"
#include "parse_vdso.h"
#if defined(__riscv)
const char *version = "LINUX_4.15";
#else
const char *version = "LINUX_2.6";
#endif
const char *name = "__vdso_getcpu";
struct getcpu_cache;
......
......@@ -27,6 +27,9 @@
#if defined(__aarch64__)
const char *version = "LINUX_2.6.39";
const char *name = "__kernel_gettimeofday";
#elif defined(__riscv)
const char *version = "LINUX_4.15";
const char *name = "__vdso_gettimeofday";
#else
const char *version = "LINUX_2.6";
const char *name = "__vdso_gettimeofday";
......
// SPDX-License-Identifier: GPL-2.0
/*
* Watchdog Driver Test Program
* Watchdog Driver Test Program
* - Tests all ioctls
* - Tests Magic Close - CONFIG_WATCHDOG_NOWAYOUT
* - Could be tested against softdog driver on systems that
* don't have watchdog hardware.
* - TODO:
* - Enhance test to add coverage for WDIOC_GETTEMP.
*
* Reference: Documentation/watchdog/watchdog-api.rst
*/
#include <errno.h>
......@@ -19,13 +27,14 @@
int fd;
const char v = 'V';
static const char sopts[] = "bdehp:t:Tn:NLf:i";
static const char sopts[] = "bdehp:st:Tn:NLf:i";
static const struct option lopts[] = {
{"bootstatus", no_argument, NULL, 'b'},
{"disable", no_argument, NULL, 'd'},
{"enable", no_argument, NULL, 'e'},
{"help", no_argument, NULL, 'h'},
{"pingrate", required_argument, NULL, 'p'},
{"status", no_argument, NULL, 's'},
{"timeout", required_argument, NULL, 't'},
{"gettimeout", no_argument, NULL, 'T'},
{"pretimeout", required_argument, NULL, 'n'},
......@@ -74,6 +83,7 @@ static void usage(char *progname)
printf(" -f, --file\t\tOpen watchdog device file\n");
printf("\t\t\tDefault is /dev/watchdog\n");
printf(" -i, --info\t\tShow watchdog_info\n");
printf(" -s, --status\t\tGet status & supported features\n");
printf(" -b, --bootstatus\tGet last boot status (Watchdog/POR)\n");
printf(" -d, --disable\t\tTurn off the watchdog timer\n");
printf(" -e, --enable\t\tTurn on the watchdog timer\n");
......@@ -91,6 +101,73 @@ static void usage(char *progname)
printf("Example: %s -t 12 -T -n 7 -N\n", progname);
}
struct wdiof_status {
int flag;
const char *status_str;
};
#define WDIOF_NUM_STATUS 8
static const struct wdiof_status wdiof_status[WDIOF_NUM_STATUS] = {
{WDIOF_SETTIMEOUT, "Set timeout (in seconds)"},
{WDIOF_MAGICCLOSE, "Supports magic close char"},
{WDIOF_PRETIMEOUT, "Pretimeout (in seconds), get/set"},
{WDIOF_ALARMONLY, "Watchdog triggers a management or other external alarm not a reboot"},
{WDIOF_KEEPALIVEPING, "Keep alive ping reply"},
{WDIOS_DISABLECARD, "Turn off the watchdog timer"},
{WDIOS_ENABLECARD, "Turn on the watchdog timer"},
{WDIOS_TEMPPANIC, "Kernel panic on temperature trip"},
};
static void print_status(int flags)
{
int wdiof = 0;
if (flags == WDIOS_UNKNOWN) {
printf("Unknown status error from WDIOC_GETSTATUS\n");
return;
}
for (wdiof = 0; wdiof < WDIOF_NUM_STATUS; wdiof++) {
if (flags & wdiof_status[wdiof].flag)
printf("Support/Status: %s\n",
wdiof_status[wdiof].status_str);
}
}
#define WDIOF_NUM_BOOTSTATUS 7
static const struct wdiof_status wdiof_bootstatus[WDIOF_NUM_BOOTSTATUS] = {
{WDIOF_OVERHEAT, "Reset due to CPU overheat"},
{WDIOF_FANFAULT, "Fan failed"},
{WDIOF_EXTERN1, "External relay 1"},
{WDIOF_EXTERN2, "External relay 2"},
{WDIOF_POWERUNDER, "Power bad/power fault"},
{WDIOF_CARDRESET, "Card previously reset the CPU"},
{WDIOF_POWEROVER, "Power over voltage"},
};
static void print_boot_status(int flags)
{
int wdiof = 0;
if (flags == WDIOF_UNKNOWN) {
printf("Unknown flag error from WDIOC_GETBOOTSTATUS\n");
return;
}
if (flags == 0) {
printf("Last boot is caused by: Power-On-Reset\n");
return;
}
for (wdiof = 0; wdiof < WDIOF_NUM_BOOTSTATUS; wdiof++) {
if (flags & wdiof_bootstatus[wdiof].flag)
printf("Last boot is caused by: %s\n",
wdiof_bootstatus[wdiof].status_str);
}
}
int main(int argc, char *argv[])
{
int flags;
......@@ -100,6 +177,7 @@ int main(int argc, char *argv[])
int oneshot = 0;
char *file = "/dev/watchdog";
struct watchdog_info info;
int temperature;
setbuf(stdout, NULL);
......@@ -140,8 +218,7 @@ int main(int argc, char *argv[])
oneshot = 1;
ret = ioctl(fd, WDIOC_GETBOOTSTATUS, &flags);
if (!ret)
printf("Last boot is caused by: %s.\n", (flags != 0) ?
"Watchdog" : "Power-On-Reset");
print_boot_status(flags);
else
printf("WDIOC_GETBOOTSTATUS error '%s'\n", strerror(errno));
break;
......@@ -170,6 +247,21 @@ int main(int argc, char *argv[])
if (!ping_rate)
ping_rate = DEFAULT_PING_RATE;
printf("Watchdog ping rate set to %u seconds.\n", ping_rate);
break;
case 's':
flags = 0;
oneshot = 1;
ret = ioctl(fd, WDIOC_GETSTATUS, &flags);
if (!ret)
print_status(flags);
else
printf("WDIOC_GETSTATUS error '%s'\n", strerror(errno));
ret = ioctl(fd, WDIOC_GETTEMP, &temperature);
if (ret)
printf("WDIOC_GETTEMP: '%s'\n", strerror(errno));
else
printf("Temperature %d\n", temperature);
break;
case 't':
flags = strtoul(optarg, NULL, 0);
......@@ -228,7 +320,7 @@ int main(int argc, char *argv[])
printf(" identity:\t\t%s\n", info.identity);
printf(" firmware_version:\t%u\n",
info.firmware_version);
printf(" options:\t\t%08x\n", info.options);
print_status(info.options);
break;
default:
......@@ -249,6 +341,10 @@ int main(int argc, char *argv[])
sleep(ping_rate);
}
end:
/*
* Send specific magic character 'V' just in case Magic Close is
* enabled to ensure watchdog gets disabled on close.
*/
ret = write(fd, &v, 1);
if (ret < 0)
printf("Stopping watchdog ticks failed (%d)...\n", errno);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment