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

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

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

Pull Kselftest updates from Shuah Khan:
 "Several build and cleanup fixes:

   - removing obsolete config options

   - removing dependency on internal kernel macros

   - adding config options

   - several build fixes related to headers and install paths"

* tag 'linux-kselftest-next-5.18-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/shuah/linux-kselftest: (22 commits)
  selftests: Fix build when $(O) points to a relative path
  selftests: netfilter: fix a build error on openSUSE
  selftests: kvm: add generated file to the .gitignore
  selftests/exec: add generated files to .gitignore
  selftests: add kselftest_install to .gitignore
  selftests/rtc: continuously read RTC in a loop for 30s
  selftests/lkdtm: Add UBSAN config
  selftests/lkdtm: Remove dead config option
  selftests/exec: Rename file binfmt_script to binfmt_script.py
  selftests: Use -isystem instead of -I to include headers
  selftests: vm: remove dependecy from internal kernel macros
  selftests: vm: Add the uapi headers include variable
  selftests: mptcp: Add the uapi headers include variable
  selftests: net: Add the uapi headers include variable
  selftests: landlock: Add the uapi headers include variable
  selftests: kvm: Add the uapi headers include variable
  selftests: futex: Add the uapi headers include variable
  selftests: Correct the headers install path
  selftests: Add and export a kernel uapi headers path
  selftests: set the BUILD variable to absolute path
  ...
parents 2fce7ea0 f6d344cd
...@@ -3,6 +3,7 @@ gpiogpio-event-mon ...@@ -3,6 +3,7 @@ gpiogpio-event-mon
gpiogpio-hammer gpiogpio-hammer
gpioinclude/ gpioinclude/
gpiolsgpio gpiolsgpio
kselftest_install/
tpm2/SpaceTest.log tpm2/SpaceTest.log
# Python bytecode and cache # Python bytecode and cache
......
...@@ -114,23 +114,35 @@ ifdef building_out_of_srctree ...@@ -114,23 +114,35 @@ ifdef building_out_of_srctree
override LDFLAGS = override LDFLAGS =
endif endif
ifneq ($(O),) top_srcdir ?= ../../..
BUILD := $(O)/kselftest
ifeq ("$(origin O)", "command line")
KBUILD_OUTPUT := $(O)
endif
ifneq ($(KBUILD_OUTPUT),)
# Make's built-in functions such as $(abspath ...), $(realpath ...) cannot
# expand a shell special character '~'. We use a somewhat tedious way here.
abs_objtree := $(shell cd $(top_srcdir) && mkdir -p $(KBUILD_OUTPUT) && cd $(KBUILD_OUTPUT) && pwd)
$(if $(abs_objtree),, \
$(error failed to create output directory "$(KBUILD_OUTPUT)"))
# $(realpath ...) resolves symlinks
abs_objtree := $(realpath $(abs_objtree))
BUILD := $(abs_objtree)/kselftest
KHDR_INCLUDES := -isystem ${abs_objtree}/usr/include
else else
ifneq ($(KBUILD_OUTPUT),) BUILD := $(CURDIR)
BUILD := $(KBUILD_OUTPUT)/kselftest abs_srctree := $(shell cd $(top_srcdir) && pwd)
else KHDR_INCLUDES := -isystem ${abs_srctree}/usr/include
BUILD := $(shell pwd) DEFAULT_INSTALL_HDR_PATH := 1
DEFAULT_INSTALL_HDR_PATH := 1
endif
endif endif
# Prepare for headers install # Prepare for headers install
top_srcdir ?= ../../..
include $(top_srcdir)/scripts/subarch.include include $(top_srcdir)/scripts/subarch.include
ARCH ?= $(SUBARCH) ARCH ?= $(SUBARCH)
export KSFT_KHDR_INSTALL_DONE := 1 export KSFT_KHDR_INSTALL_DONE := 1
export BUILD export BUILD
export KHDR_INCLUDES
# set default goal to all, so make without a target runs all, even when # set default goal to all, so make without a target runs all, even when
# all isn't the first target in the file. # all isn't the first target in the file.
...@@ -155,7 +167,7 @@ khdr: ...@@ -155,7 +167,7 @@ khdr:
ifeq (1,$(DEFAULT_INSTALL_HDR_PATH)) ifeq (1,$(DEFAULT_INSTALL_HDR_PATH))
$(MAKE) --no-builtin-rules ARCH=$(ARCH) -C $(top_srcdir) headers_install $(MAKE) --no-builtin-rules ARCH=$(ARCH) -C $(top_srcdir) headers_install
else else
$(MAKE) --no-builtin-rules INSTALL_HDR_PATH=$$BUILD/usr \ $(MAKE) --no-builtin-rules INSTALL_HDR_PATH=$(abs_objtree)/usr \
ARCH=$(ARCH) -C $(top_srcdir) headers_install ARCH=$(ARCH) -C $(top_srcdir) headers_install
endif endif
...@@ -165,6 +177,7 @@ all: khdr ...@@ -165,6 +177,7 @@ all: khdr
BUILD_TARGET=$$BUILD/$$TARGET; \ BUILD_TARGET=$$BUILD/$$TARGET; \
mkdir $$BUILD_TARGET -p; \ mkdir $$BUILD_TARGET -p; \
$(MAKE) OUTPUT=$$BUILD_TARGET -C $$TARGET \ $(MAKE) OUTPUT=$$BUILD_TARGET -C $$TARGET \
O=$(abs_objtree) \
$(if $(FORCE_TARGETS),|| exit); \ $(if $(FORCE_TARGETS),|| exit); \
ret=$$((ret * $$?)); \ ret=$$((ret * $$?)); \
done; exit $$ret; done; exit $$ret;
...@@ -172,7 +185,8 @@ all: khdr ...@@ -172,7 +185,8 @@ all: khdr
run_tests: all run_tests: all
@for TARGET in $(TARGETS); do \ @for TARGET in $(TARGETS); do \
BUILD_TARGET=$$BUILD/$$TARGET; \ BUILD_TARGET=$$BUILD/$$TARGET; \
$(MAKE) OUTPUT=$$BUILD_TARGET -C $$TARGET run_tests;\ $(MAKE) OUTPUT=$$BUILD_TARGET -C $$TARGET run_tests \
O=$(abs_objtree); \
done; done;
hotplug: hotplug:
...@@ -223,6 +237,7 @@ ifdef INSTALL_PATH ...@@ -223,6 +237,7 @@ ifdef INSTALL_PATH
for TARGET in $(TARGETS); do \ for TARGET in $(TARGETS); do \
BUILD_TARGET=$$BUILD/$$TARGET; \ BUILD_TARGET=$$BUILD/$$TARGET; \
$(MAKE) OUTPUT=$$BUILD_TARGET -C $$TARGET INSTALL_PATH=$(INSTALL_PATH)/$$TARGET install \ $(MAKE) OUTPUT=$$BUILD_TARGET -C $$TARGET INSTALL_PATH=$(INSTALL_PATH)/$$TARGET install \
O=$(abs_objtree) \
$(if $(FORCE_TARGETS),|| exit); \ $(if $(FORCE_TARGETS),|| exit); \
ret=$$((ret * $$?)); \ ret=$$((ret * $$?)); \
done; exit $$ret; done; exit $$ret;
......
...@@ -7,6 +7,8 @@ execveat.moved ...@@ -7,6 +7,8 @@ execveat.moved
execveat.path.ephemeral execveat.path.ephemeral
execveat.ephemeral execveat.ephemeral
execveat.denatured execveat.denatured
non-regular
null-argv
/load_address_* /load_address_*
/recursion-depth /recursion-depth
xxxxxxxx* xxxxxxxx*
......
...@@ -3,7 +3,7 @@ CFLAGS = -Wall ...@@ -3,7 +3,7 @@ CFLAGS = -Wall
CFLAGS += -Wno-nonnull CFLAGS += -Wno-nonnull
CFLAGS += -D_GNU_SOURCE CFLAGS += -D_GNU_SOURCE
TEST_PROGS := binfmt_script TEST_PROGS := binfmt_script.py
TEST_GEN_PROGS := execveat load_address_4096 load_address_2097152 load_address_16777216 non-regular TEST_GEN_PROGS := execveat load_address_4096 load_address_2097152 load_address_16777216 non-regular
TEST_GEN_FILES := execveat.symlink execveat.denatured script subdir TEST_GEN_FILES := execveat.symlink execveat.denatured script subdir
# Makefile is a run-time dependency, since it's accessed by the execveat test # Makefile is a run-time dependency, since it's accessed by the execveat test
......
# SPDX-License-Identifier: GPL-2.0 # SPDX-License-Identifier: GPL-2.0
INCLUDES := -I../include -I../../ -I../../../../../usr/include/ \ INCLUDES := -I../include -I../../ -I../../../../../usr/include/
-I$(KBUILD_OUTPUT)/kselftest/usr/include CFLAGS := $(CFLAGS) -g -O2 -Wall -D_GNU_SOURCE -pthread $(INCLUDES) $(KHDR_INCLUDES)
CFLAGS := $(CFLAGS) -g -O2 -Wall -D_GNU_SOURCE -pthread $(INCLUDES)
LDLIBS := -lpthread -lrt LDLIBS := -lpthread -lrt
HEADERS := \ HEADERS := \
...@@ -24,6 +23,7 @@ TEST_PROGS := run.sh ...@@ -24,6 +23,7 @@ TEST_PROGS := run.sh
top_srcdir = ../../../../.. top_srcdir = ../../../../..
KSFT_KHDR_INSTALL := 1 KSFT_KHDR_INSTALL := 1
DEFAULT_INSTALL_HDR_PATH := 1
include ../../lib.mk include ../../lib.mk
$(TEST_GEN_FILES): $(HEADERS) $(TEST_GEN_FILES): $(HEADERS)
...@@ -18,6 +18,8 @@ if [ -z "$BASE_DIR" ]; then ...@@ -18,6 +18,8 @@ if [ -z "$BASE_DIR" ]; then
exit 1 exit 1
fi fi
TR_CMD=$(command -v tr)
# If Perl is unavailable, we must fall back to line-at-a-time prefixing # If Perl is unavailable, we must fall back to line-at-a-time prefixing
# with sed instead of unbuffered output. # with sed instead of unbuffered output.
tap_prefix() tap_prefix()
...@@ -49,6 +51,31 @@ run_one() ...@@ -49,6 +51,31 @@ run_one()
# Reset any "settings"-file variables. # Reset any "settings"-file variables.
export kselftest_timeout="$kselftest_default_timeout" export kselftest_timeout="$kselftest_default_timeout"
# Safe default if tr not available
kselftest_cmd_args_ref="KSELFTEST_ARGS"
# Optional arguments for this command, possibly defined as an
# environment variable built using the test executable in all
# uppercase and sanitized substituting non acceptable shell
# variable name characters with "_" as in:
#
# KSELFTEST_<UPPERCASE_SANITIZED_TESTNAME>_ARGS="<options>"
#
# e.g.
#
# rtctest --> KSELFTEST_RTCTEST_ARGS="/dev/rtc1"
#
# cpu-on-off-test.sh --> KSELFTEST_CPU_ON_OFF_TEST_SH_ARGS="-a -p 10"
#
if [ -n "$TR_CMD" ]; then
BASENAME_SANITIZED=$(echo "$BASENAME_TEST" | \
$TR_CMD -d "[:blank:][:cntrl:]" | \
$TR_CMD -c "[:alnum:]_" "_" | \
$TR_CMD [:lower:] [:upper:])
kselftest_cmd_args_ref="KSELFTEST_${BASENAME_SANITIZED}_ARGS"
fi
# Load per-test-directory kselftest "settings" file. # Load per-test-directory kselftest "settings" file.
settings="$BASE_DIR/$DIR/settings" settings="$BASE_DIR/$DIR/settings"
if [ -r "$settings" ] ; then if [ -r "$settings" ] ; then
...@@ -69,7 +96,8 @@ run_one() ...@@ -69,7 +96,8 @@ run_one()
echo "# Warning: file $TEST is missing!" echo "# Warning: file $TEST is missing!"
echo "not ok $test_num $TEST_HDR_MSG" echo "not ok $test_num $TEST_HDR_MSG"
else else
cmd="./$BASENAME_TEST" eval kselftest_cmd_args="\$${kselftest_cmd_args_ref:-}"
cmd="./$BASENAME_TEST $kselftest_cmd_args"
if [ ! -x "$TEST" ]; then if [ ! -x "$TEST" ]; then
echo "# Warning: file $TEST is not executable" echo "# Warning: file $TEST is not executable"
......
...@@ -20,6 +20,7 @@ ...@@ -20,6 +20,7 @@
/x86_64/hyperv_clock /x86_64/hyperv_clock
/x86_64/hyperv_cpuid /x86_64/hyperv_cpuid
/x86_64/hyperv_features /x86_64/hyperv_features
/x86_64/hyperv_svm_test
/x86_64/mmio_warning_test /x86_64/mmio_warning_test
/x86_64/mmu_role_test /x86_64/mmu_role_test
/x86_64/platform_info_test /x86_64/platform_info_test
......
...@@ -149,7 +149,7 @@ endif ...@@ -149,7 +149,7 @@ endif
CFLAGS += -Wall -Wstrict-prototypes -Wuninitialized -O2 -g -std=gnu99 \ CFLAGS += -Wall -Wstrict-prototypes -Wuninitialized -O2 -g -std=gnu99 \
-fno-stack-protector -fno-PIE -I$(LINUX_TOOL_INCLUDE) \ -fno-stack-protector -fno-PIE -I$(LINUX_TOOL_INCLUDE) \
-I$(LINUX_TOOL_ARCH_INCLUDE) -I$(LINUX_HDR_PATH) -Iinclude \ -I$(LINUX_TOOL_ARCH_INCLUDE) -I$(LINUX_HDR_PATH) -Iinclude \
-I$(<D) -Iinclude/$(UNAME_M) -I.. $(EXTRA_CFLAGS) -I$(<D) -Iinclude/$(UNAME_M) -I.. $(EXTRA_CFLAGS) $(KHDR_INCLUDES)
no-pie-option := $(call try-run, echo 'int main() { return 0; }' | \ no-pie-option := $(call try-run, echo 'int main() { return 0; }' | \
$(CC) -Werror -no-pie -x c - -o "$$TMP", -no-pie) $(CC) -Werror -no-pie -x c - -o "$$TMP", -no-pie)
......
# SPDX-License-Identifier: GPL-2.0 # SPDX-License-Identifier: GPL-2.0
CFLAGS += -Wall -O2 CFLAGS += -Wall -O2 $(KHDR_INCLUDES)
src_test := $(wildcard *_test.c) src_test := $(wildcard *_test.c)
......
...@@ -3,9 +3,9 @@ CONFIG_DEBUG_LIST=y ...@@ -3,9 +3,9 @@ CONFIG_DEBUG_LIST=y
CONFIG_SLAB_FREELIST_HARDENED=y CONFIG_SLAB_FREELIST_HARDENED=y
CONFIG_FORTIFY_SOURCE=y CONFIG_FORTIFY_SOURCE=y
CONFIG_HARDENED_USERCOPY=y CONFIG_HARDENED_USERCOPY=y
# CONFIG_HARDENED_USERCOPY_FALLBACK is not set
CONFIG_RANDOMIZE_KSTACK_OFFSET_DEFAULT=y CONFIG_RANDOMIZE_KSTACK_OFFSET_DEFAULT=y
CONFIG_INIT_ON_ALLOC_DEFAULT_ON=y CONFIG_INIT_ON_ALLOC_DEFAULT_ON=y
CONFIG_UBSAN=y
CONFIG_UBSAN_BOUNDS=y CONFIG_UBSAN_BOUNDS=y
CONFIG_UBSAN_TRAP=y CONFIG_UBSAN_TRAP=y
CONFIG_STACKPROTECTOR_STRONG=y CONFIG_STACKPROTECTOR_STRONG=y
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
# Makefile for net selftests # Makefile for net selftests
CFLAGS = -Wall -Wl,--no-as-needed -O2 -g CFLAGS = -Wall -Wl,--no-as-needed -O2 -g
CFLAGS += -I../../../../usr/include/ CFLAGS += -I../../../../usr/include/ $(KHDR_INCLUDES)
TEST_PROGS := run_netsocktests run_afpackettests test_bpf.sh netdevice.sh \ TEST_PROGS := run_netsocktests run_afpackettests test_bpf.sh netdevice.sh \
rtnetlink.sh xfrm_policy.sh test_blackhole_dev.sh rtnetlink.sh xfrm_policy.sh test_blackhole_dev.sh
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
top_srcdir = ../../../../.. top_srcdir = ../../../../..
KSFT_KHDR_INSTALL := 1 KSFT_KHDR_INSTALL := 1
CFLAGS = -Wall -Wl,--no-as-needed -O2 -g -I$(top_srcdir)/usr/include CFLAGS = -Wall -Wl,--no-as-needed -O2 -g -I$(top_srcdir)/usr/include $(KHDR_INCLUDES)
TEST_PROGS := mptcp_connect.sh pm_netlink.sh mptcp_join.sh diag.sh \ TEST_PROGS := mptcp_connect.sh pm_netlink.sh mptcp_join.sh diag.sh \
simult_flows.sh mptcp_sockopt.sh simult_flows.sh mptcp_sockopt.sh
......
...@@ -8,6 +8,7 @@ TEST_PROGS := nft_trans_stress.sh nft_fib.sh nft_nat.sh bridge_brouter.sh \ ...@@ -8,6 +8,7 @@ TEST_PROGS := nft_trans_stress.sh nft_fib.sh nft_nat.sh bridge_brouter.sh \
ipip-conntrack-mtu.sh conntrack_tcp_unreplied.sh \ ipip-conntrack-mtu.sh conntrack_tcp_unreplied.sh \
conntrack_vrf.sh nft_synproxy.sh conntrack_vrf.sh nft_synproxy.sh
CFLAGS += $(shell pkg-config --cflags libmnl 2>/dev/null || echo "-I/usr/include/libmnl")
LDLIBS = -lmnl LDLIBS = -lmnl
TEST_GEN_FILES = nf-queue connect_close TEST_GEN_FILES = nf-queue connect_close
......
...@@ -20,6 +20,8 @@ ...@@ -20,6 +20,8 @@
#define NUM_UIE 3 #define NUM_UIE 3
#define ALARM_DELTA 3 #define ALARM_DELTA 3
#define READ_LOOP_DURATION_SEC 30
#define READ_LOOP_SLEEP_MS 11
static char *rtc_file = "/dev/rtc0"; static char *rtc_file = "/dev/rtc0";
...@@ -49,6 +51,70 @@ TEST_F(rtc, date_read) { ...@@ -49,6 +51,70 @@ TEST_F(rtc, date_read) {
rtc_tm.tm_hour, rtc_tm.tm_min, rtc_tm.tm_sec); rtc_tm.tm_hour, rtc_tm.tm_min, rtc_tm.tm_sec);
} }
static time_t rtc_time_to_timestamp(struct rtc_time *rtc_time)
{
struct tm tm_time = {
.tm_sec = rtc_time->tm_sec,
.tm_min = rtc_time->tm_min,
.tm_hour = rtc_time->tm_hour,
.tm_mday = rtc_time->tm_mday,
.tm_mon = rtc_time->tm_mon,
.tm_year = rtc_time->tm_year,
};
return mktime(&tm_time);
}
static void nanosleep_with_retries(long ns)
{
struct timespec req = {
.tv_sec = 0,
.tv_nsec = ns,
};
struct timespec rem;
while (nanosleep(&req, &rem) != 0) {
req.tv_sec = rem.tv_sec;
req.tv_nsec = rem.tv_nsec;
}
}
TEST_F_TIMEOUT(rtc, date_read_loop, READ_LOOP_DURATION_SEC + 2) {
int rc;
long iter_count = 0;
struct rtc_time rtc_tm;
time_t start_rtc_read, prev_rtc_read;
TH_LOG("Continuously reading RTC time for %ds (with %dms breaks after every read).",
READ_LOOP_DURATION_SEC, READ_LOOP_SLEEP_MS);
rc = ioctl(self->fd, RTC_RD_TIME, &rtc_tm);
ASSERT_NE(-1, rc);
start_rtc_read = rtc_time_to_timestamp(&rtc_tm);
prev_rtc_read = start_rtc_read;
do {
time_t rtc_read;
rc = ioctl(self->fd, RTC_RD_TIME, &rtc_tm);
ASSERT_NE(-1, rc);
rtc_read = rtc_time_to_timestamp(&rtc_tm);
/* Time should not go backwards */
ASSERT_LE(prev_rtc_read, rtc_read);
/* Time should not increase more then 1s at a time */
ASSERT_GE(prev_rtc_read + 1, rtc_read);
/* Sleep 11ms to avoid killing / overheating the RTC */
nanosleep_with_retries(READ_LOOP_SLEEP_MS * 1000000);
prev_rtc_read = rtc_read;
iter_count++;
} while (prev_rtc_read <= start_rtc_read + READ_LOOP_DURATION_SEC);
TH_LOG("Performed %ld RTC time reads.", iter_count);
}
TEST_F_TIMEOUT(rtc, uie_read, NUM_UIE + 2) { TEST_F_TIMEOUT(rtc, uie_read, NUM_UIE + 2) {
int i, rc, irq = 0; int i, rc, irq = 0;
unsigned long data; unsigned long data;
......
...@@ -25,7 +25,7 @@ MACHINE ?= $(shell echo $(uname_M) | sed -e 's/aarch64.*/arm64/' -e 's/ppc64.*/p ...@@ -25,7 +25,7 @@ MACHINE ?= $(shell echo $(uname_M) | sed -e 's/aarch64.*/arm64/' -e 's/ppc64.*/p
# LDLIBS. # LDLIBS.
MAKEFLAGS += --no-builtin-rules MAKEFLAGS += --no-builtin-rules
CFLAGS = -Wall -I ../../../../usr/include $(EXTRA_CFLAGS) CFLAGS = -Wall -I ../../../../usr/include $(EXTRA_CFLAGS) $(KHDR_INCLUDES)
LDLIBS = -lrt -lpthread LDLIBS = -lrt -lpthread
TEST_GEN_FILES = compaction_test TEST_GEN_FILES = compaction_test
TEST_GEN_FILES += gup_test TEST_GEN_FILES += gup_test
......
...@@ -120,6 +120,9 @@ struct uffd_stats { ...@@ -120,6 +120,9 @@ struct uffd_stats {
~(unsigned long)(sizeof(unsigned long long) \ ~(unsigned long)(sizeof(unsigned long long) \
- 1))) - 1)))
#define swap(a, b) \
do { typeof(a) __tmp = (a); (a) = (b); (b) = __tmp; } while (0)
const char *examples = const char *examples =
"# Run anonymous memory test on 100MiB region with 99999 bounces:\n" "# Run anonymous memory test on 100MiB region with 99999 bounces:\n"
"./userfaultfd anon 100 99999\n\n" "./userfaultfd anon 100 99999\n\n"
......
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