Skip to content

Commit

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

Pull Kselftest fixes from Shuah Khan:
 "Fixes for existing tests and the framework.

  Cristian Marussi's patches add the ability to skip targets (tests) and
  exclude tests that didn't build from run-list. These patches improve
  the Kselftest results. Ability to skip targets helps avoid running
  tests that aren't supported in certain environments. As an example,
  bpf tests from mainline aren't supported on stable kernels and have
  dependency on bleeding edge llvm. Being able to skip bpf on systems
  that can't meet this llvm dependency will be helpful.

  Kselftest can be built and installed from the main Makefile. This
  change help simplify Kselftest use-cases which addresses request from
  users.

  Kees Cook added per test timeout support to limit individual test
  run-time"

* tag 'linux-kselftest-5.4-rc3' of git://git.kernel.org/pub/scm/linux/kernel/git/shuah/linux-kselftest:
  selftests: watchdog: Add command line option to show watchdog_info
  selftests: watchdog: Validate optional file argument
  selftests/kselftest/runner.sh: Add 45 second timeout per test
  kselftest: exclude failed TARGETS from runlist
  kselftest: add capability to skip chosen TARGETS
  selftests: Add kselftest-all and kselftest-install targets
  • Loading branch information
torvalds committed Oct 8, 2019
2 parents eda57a0 + ce3a677 commit f54e66a
Show file tree
Hide file tree
Showing 7 changed files with 97 additions and 11 deletions.
16 changes: 16 additions & 0 deletions Documentation/dev-tools/kselftest.rst
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,22 @@ To build, save output files in a separate directory with KBUILD_OUTPUT ::

$ export KBUILD_OUTPUT=/tmp/kselftest; make TARGETS="size timers" kselftest

Additionally you can use the "SKIP_TARGETS" variable on the make command
line to specify one or more targets to exclude from the TARGETS list.

To run all tests but a single subsystem::

$ make -C tools/testing/selftests SKIP_TARGETS=ptrace run_tests

You can specify multiple tests to skip::

$ make SKIP_TARGETS="size timers" kselftest

You can also specify a restricted list of tests to run together with a
dedicated skiplist::

$ make TARGETS="bpf breakpoints size timers" SKIP_TARGETS=bpf kselftest

See the top-level tools/testing/selftests/Makefile for the list of all
possible targets.

Expand Down
5 changes: 2 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -1217,9 +1217,8 @@ PHONY += kselftest
kselftest:
$(Q)$(MAKE) -C $(srctree)/tools/testing/selftests run_tests

PHONY += kselftest-clean
kselftest-clean:
$(Q)$(MAKE) -C $(srctree)/tools/testing/selftests clean
kselftest-%: FORCE
$(Q)$(MAKE) -C $(srctree)/tools/testing/selftests $*

PHONY += kselftest-merge
kselftest-merge:
Expand Down
19 changes: 17 additions & 2 deletions tools/testing/selftests/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,13 @@ TARGETS += zram
TARGETS_HOTPLUG = cpu-hotplug
TARGETS_HOTPLUG += memory-hotplug

# User can optionally provide a TARGETS skiplist.
SKIP_TARGETS ?=
ifneq ($(SKIP_TARGETS),)
TMP := $(filter-out $(SKIP_TARGETS), $(TARGETS))
override TARGETS := $(TMP)
endif

# Clear LDFLAGS and MAKEFLAGS if called from main
# Makefile to avoid test build failures when test
# Makefile doesn't have explicit build rules.
Expand Down Expand Up @@ -171,9 +178,12 @@ run_pstore_crash:
# 1. output_dir=kernel_src
# 2. a separate output directory is specified using O= KBUILD_OUTPUT
# 3. a separate output directory is specified using KBUILD_OUTPUT
# Avoid conflict with INSTALL_PATH set by the main Makefile
#
INSTALL_PATH ?= $(BUILD)/install
INSTALL_PATH := $(abspath $(INSTALL_PATH))
KSFT_INSTALL_PATH ?= $(BUILD)/kselftest_install
KSFT_INSTALL_PATH := $(abspath $(KSFT_INSTALL_PATH))
# Avoid changing the rest of the logic here and lib.mk.
INSTALL_PATH := $(KSFT_INSTALL_PATH)
ALL_SCRIPT := $(INSTALL_PATH)/run_kselftest.sh

install: all
Expand All @@ -198,11 +208,16 @@ ifdef INSTALL_PATH
echo " cat /dev/null > \$$logfile" >> $(ALL_SCRIPT)
echo "fi" >> $(ALL_SCRIPT)

@# While building run_kselftest.sh skip also non-existent TARGET dirs:
@# they could be the result of a build failure and should NOT be
@# included in the generated runlist.
for TARGET in $(TARGETS); do \
BUILD_TARGET=$$BUILD/$$TARGET; \
[ ! -d $$INSTALL_PATH/$$TARGET ] && echo "Skipping non-existent dir: $$TARGET" && continue; \
echo "[ -w /dev/kmsg ] && echo \"kselftest: Running tests in $$TARGET\" >> /dev/kmsg" >> $(ALL_SCRIPT); \
echo "cd $$TARGET" >> $(ALL_SCRIPT); \
echo -n "run_many" >> $(ALL_SCRIPT); \
echo -n "Emit Tests for $$TARGET\n"; \
$(MAKE) -s --no-print-directory OUTPUT=$$BUILD_TARGET -C $$TARGET emit_tests >> $(ALL_SCRIPT); \
echo "" >> $(ALL_SCRIPT); \
echo "cd \$$ROOT" >> $(ALL_SCRIPT); \
Expand Down
36 changes: 33 additions & 3 deletions tools/testing/selftests/kselftest/runner.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,14 @@
#
# Runs a set of tests in a given subdirectory.
export skip_rc=4
export timeout_rc=124
export logfile=/dev/stdout
export per_test_logging=

# Defaults for "settings" file fields:
# "timeout" how many seconds to let each test run before failing.
export kselftest_default_timeout=45

# There isn't a shell-agnostic way to find the path of a sourced file,
# so we must rely on BASE_DIR being set to find other tools.
if [ -z "$BASE_DIR" ]; then
Expand All @@ -24,6 +29,16 @@ tap_prefix()
fi
}

tap_timeout()
{
# Make sure tests will time out if utility is available.
if [ -x /usr/bin/timeout ] ; then
/usr/bin/timeout "$kselftest_timeout" "$1"
else
"$1"
fi
}

run_one()
{
DIR="$1"
Expand All @@ -32,6 +47,18 @@ run_one()

BASENAME_TEST=$(basename $TEST)

# Reset any "settings"-file variables.
export kselftest_timeout="$kselftest_default_timeout"
# Load per-test-directory kselftest "settings" file.
settings="$BASE_DIR/$DIR/settings"
if [ -r "$settings" ] ; then
while read line ; do
field=$(echo "$line" | cut -d= -f1)
value=$(echo "$line" | cut -d= -f2-)
eval "kselftest_$field"="$value"
done < "$settings"
fi

TEST_HDR_MSG="selftests: $DIR: $BASENAME_TEST"
echo "# $TEST_HDR_MSG"
if [ ! -x "$TEST" ]; then
Expand All @@ -44,14 +71,17 @@ run_one()
echo "not ok $test_num $TEST_HDR_MSG"
else
cd `dirname $TEST` > /dev/null
(((((./$BASENAME_TEST 2>&1; echo $? >&3) |
((((( tap_timeout ./$BASENAME_TEST 2>&1; echo $? >&3) |
tap_prefix >&4) 3>&1) |
(read xs; exit $xs)) 4>>"$logfile" &&
echo "ok $test_num $TEST_HDR_MSG") ||
(if [ $? -eq $skip_rc ]; then \
(rc=$?; \
if [ $rc -eq $skip_rc ]; then \
echo "not ok $test_num $TEST_HDR_MSG # SKIP"
elif [ $rc -eq $timeout_rc ]; then \
echo "not ok $test_num $TEST_HDR_MSG # TIMEOUT"
else
echo "not ok $test_num $TEST_HDR_MSG"
echo "not ok $test_num $TEST_HDR_MSG # exit=$rc"
fi)
cd - >/dev/null
fi
Expand Down
4 changes: 2 additions & 2 deletions tools/testing/selftests/kselftest_install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@ main()
echo "$0: Installing in specified location - $install_loc ..."
fi

install_dir=$install_loc/kselftest
install_dir=$install_loc/kselftest_install

# Create install directory
mkdir -p $install_dir
# Build tests
INSTALL_PATH=$install_dir make install
KSFT_INSTALL_PATH=$install_dir make install
}

main "$@"
1 change: 1 addition & 0 deletions tools/testing/selftests/rtc/settings
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
timeout=90
27 changes: 26 additions & 1 deletion tools/testing/selftests/watchdog/watchdog-test.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

int fd;
const char v = 'V';
static const char sopts[] = "bdehp:t:Tn:NLf:";
static const char sopts[] = "bdehp:t:Tn:NLf:i";
static const struct option lopts[] = {
{"bootstatus", no_argument, NULL, 'b'},
{"disable", no_argument, NULL, 'd'},
Expand All @@ -32,6 +32,7 @@ static const struct option lopts[] = {
{"getpretimeout", no_argument, NULL, 'N'},
{"gettimeleft", no_argument, NULL, 'L'},
{"file", required_argument, NULL, 'f'},
{"info", no_argument, NULL, 'i'},
{NULL, no_argument, NULL, 0x0}
};

Expand Down Expand Up @@ -72,6 +73,7 @@ static void usage(char *progname)
printf("Usage: %s [options]\n", 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(" -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");
Expand All @@ -97,6 +99,7 @@ int main(int argc, char *argv[])
int c;
int oneshot = 0;
char *file = "/dev/watchdog";
struct watchdog_info info;

setbuf(stdout, NULL);

Expand All @@ -118,6 +121,16 @@ int main(int argc, char *argv[])
exit(-1);
}

/*
* Validate that `file` is a watchdog device
*/
ret = ioctl(fd, WDIOC_GETSUPPORT, &info);
if (ret) {
printf("WDIOC_GETSUPPORT error '%s'\n", strerror(errno));
close(fd);
exit(ret);
}

optind = 0;

while ((c = getopt_long(argc, argv, sopts, lopts, NULL)) != -1) {
Expand Down Expand Up @@ -205,6 +218,18 @@ int main(int argc, char *argv[])
case 'f':
/* Handled above */
break;
case 'i':
/*
* watchdog_info was obtained as part of file open
* validation. So we just show it here.
*/
oneshot = 1;
printf("watchdog_info:\n");
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);
break;

default:
usage(argv[0]);
Expand Down

0 comments on commit f54e66a

Please sign in to comment.