Commit 225d3b67 authored by Linus Torvalds's avatar Linus Torvalds

Merge tag 'linux-kselftest-4.14-rc3-fixes' of...

Merge tag 'linux-kselftest-4.14-rc3-fixes' of git://git.kernel.org/pub/scm/linux/kernel/git/shuah/linux-kselftest

Pull kselftest fixes from Shuah Khan:
 "This update consists of:

   - fixes to several existing tests

   - a test for regression introduced by b9470c27 ("inet: kill
     smallest_size and smallest_port")

   - seccomp support for glibc 2.26 siginfo_t.h

   - fixes to kselftest framework and tests to run make O=dir use-case

   - fixes to silence unnecessary test output to de-clutter test results"

* tag 'linux-kselftest-4.14-rc3-fixes' of git://git.kernel.org/pub/scm/linux/kernel/git/shuah/linux-kselftest: (28 commits)
  selftests: timers: set-timer-lat: Fix hang when testing unsupported alarms
  selftests: timers: set-timer-lat: fix hang when std out/err are redirected
  selftests/memfd: correct run_tests.sh permission
  selftests/seccomp: Support glibc 2.26 siginfo_t.h
  selftests: futex: Makefile: fix for loops in targets to run silently
  selftests: Makefile: fix for loops in targets to run silently
  selftests: mqueue: Use full path to run tests from Makefile
  selftests: futex: copy sub-dir test scripts for make O=dir run
  selftests: lib.mk: copy test scripts and test files for make O=dir run
  selftests: sync: kselftest and kselftest-clean fail for make O=dir case
  selftests: sync: use TEST_CUSTOM_PROGS instead of TEST_PROGS
  selftests: lib.mk: add TEST_CUSTOM_PROGS to allow custom test run/install
  selftests: watchdog: fix to use TEST_GEN_PROGS and remove clean
  selftests: lib.mk: fix test executable status check to use full path
  selftests: Makefile: clear LDFLAGS for make O=dir use-case
  selftests: lib.mk: kselftest and kselftest-clean fail for make O=dir case
  Makefile: kselftest and kselftest-clean fail for make O=dir case
  selftests/net: msg_zerocopy enable build with older kernel headers
  selftests: actually run the various net selftests
  selftest: add a reuseaddr test
  ...
parents 7031b641 eefd95e1
...@@ -1172,11 +1172,11 @@ headers_check: headers_install ...@@ -1172,11 +1172,11 @@ headers_check: headers_install
PHONY += kselftest PHONY += kselftest
kselftest: kselftest:
$(Q)$(MAKE) -C tools/testing/selftests run_tests $(Q)$(MAKE) -C $(srctree)/tools/testing/selftests run_tests
PHONY += kselftest-clean PHONY += kselftest-clean
kselftest-clean: kselftest-clean:
$(Q)$(MAKE) -C tools/testing/selftests clean $(Q)$(MAKE) -C $(srctree)/tools/testing/selftests clean
PHONY += kselftest-merge PHONY += kselftest-merge
kselftest-merge: kselftest-merge:
......
...@@ -52,6 +52,10 @@ override LDFLAGS = ...@@ -52,6 +52,10 @@ override LDFLAGS =
override MAKEFLAGS = override MAKEFLAGS =
endif endif
ifneq ($(KBUILD_SRC),)
override LDFLAGS =
endif
BUILD := $(O) BUILD := $(O)
ifndef BUILD ifndef BUILD
BUILD := $(KBUILD_OUTPUT) BUILD := $(KBUILD_OUTPUT)
...@@ -62,32 +66,32 @@ endif ...@@ -62,32 +66,32 @@ endif
export BUILD export BUILD
all: all:
for TARGET in $(TARGETS); do \ @for TARGET in $(TARGETS); do \
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;\
done; done;
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;\
done; done;
hotplug: hotplug:
for TARGET in $(TARGETS_HOTPLUG); do \ @for TARGET in $(TARGETS_HOTPLUG); do \
BUILD_TARGET=$$BUILD/$$TARGET; \ BUILD_TARGET=$$BUILD/$$TARGET; \
make OUTPUT=$$BUILD_TARGET -C $$TARGET;\ make OUTPUT=$$BUILD_TARGET -C $$TARGET;\
done; done;
run_hotplug: hotplug run_hotplug: hotplug
for TARGET in $(TARGETS_HOTPLUG); do \ @for TARGET in $(TARGETS_HOTPLUG); do \
BUILD_TARGET=$$BUILD/$$TARGET; \ BUILD_TARGET=$$BUILD/$$TARGET; \
make OUTPUT=$$BUILD_TARGET -C $$TARGET run_full_test;\ make OUTPUT=$$BUILD_TARGET -C $$TARGET run_full_test;\
done; done;
clean_hotplug: clean_hotplug:
for TARGET in $(TARGETS_HOTPLUG); do \ @for TARGET in $(TARGETS_HOTPLUG); do \
BUILD_TARGET=$$BUILD/$$TARGET; \ BUILD_TARGET=$$BUILD/$$TARGET; \
make OUTPUT=$$BUILD_TARGET -C $$TARGET clean;\ make OUTPUT=$$BUILD_TARGET -C $$TARGET clean;\
done; done;
...@@ -103,7 +107,7 @@ install: ...@@ -103,7 +107,7 @@ install:
ifdef INSTALL_PATH ifdef INSTALL_PATH
@# Ask all targets to install their files @# Ask all targets to install their files
mkdir -p $(INSTALL_PATH) mkdir -p $(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; \
done; done;
...@@ -128,7 +132,7 @@ else ...@@ -128,7 +132,7 @@ else
endif endif
clean: clean:
for TARGET in $(TARGETS); do \ @for TARGET in $(TARGETS); do \
BUILD_TARGET=$$BUILD/$$TARGET; \ BUILD_TARGET=$$BUILD/$$TARGET; \
make OUTPUT=$$BUILD_TARGET -C $$TARGET clean;\ make OUTPUT=$$BUILD_TARGET -C $$TARGET clean;\
done; done;
......
...@@ -12,6 +12,7 @@ static inline unsigned int bpf_num_possible_cpus(void) ...@@ -12,6 +12,7 @@ static inline unsigned int bpf_num_possible_cpus(void)
unsigned int start, end, possible_cpus = 0; unsigned int start, end, possible_cpus = 0;
char buff[128]; char buff[128];
FILE *fp; FILE *fp;
int n;
fp = fopen(fcpu, "r"); fp = fopen(fcpu, "r");
if (!fp) { if (!fp) {
...@@ -20,17 +21,17 @@ static inline unsigned int bpf_num_possible_cpus(void) ...@@ -20,17 +21,17 @@ static inline unsigned int bpf_num_possible_cpus(void)
} }
while (fgets(buff, sizeof(buff), fp)) { while (fgets(buff, sizeof(buff), fp)) {
if (sscanf(buff, "%u-%u", &start, &end) == 2) { n = sscanf(buff, "%u-%u", &start, &end);
possible_cpus = start == 0 ? end + 1 : 0; if (n == 0) {
break; printf("Failed to retrieve # possible CPUs!\n");
exit(1);
} else if (n == 1) {
end = start;
} }
possible_cpus = start == 0 ? end + 1 : 0;
break;
} }
fclose(fp); fclose(fp);
if (!possible_cpus) {
printf("Failed to retrieve # possible CPUs!\n");
exit(1);
}
return possible_cpus; return possible_cpus;
} }
......
...@@ -2,14 +2,14 @@ ...@@ -2,14 +2,14 @@
uname_M := $(shell uname -m 2>/dev/null || echo not) 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/) ARCH ?= $(shell echo $(uname_M) | sed -e s/i.86/x86/ -e s/x86_64/x86/)
TEST_GEN_PROGS := step_after_suspend_test
ifeq ($(ARCH),x86) ifeq ($(ARCH),x86)
TEST_GEN_PROGS := breakpoint_test TEST_GEN_PROGS += breakpoint_test
endif endif
ifneq (,$(filter $(ARCH),aarch64 arm64)) ifneq (,$(filter $(ARCH),aarch64 arm64))
TEST_GEN_PROGS := breakpoint_test_arm64 TEST_GEN_PROGS += breakpoint_test_arm64
endif endif
TEST_GEN_PROGS += step_after_suspend_test
include ../lib.mk include ../lib.mk
#!/bin/sh #!/bin/sh
# description: Register/unregister many kprobe events # description: Register/unregister many kprobe events
[ -f kprobe_events ] || exit_unsupported # this is configurable
# ftrace fentry skip size depends on the machine architecture. # ftrace fentry skip size depends on the machine architecture.
# Currently HAVE_KPROBES_ON_FTRACE defined on x86 and powerpc64le # Currently HAVE_KPROBES_ON_FTRACE defined on x86 and powerpc64le
case `uname -m` in case `uname -m` in
......
...@@ -7,14 +7,17 @@ TEST_PROGS := run.sh ...@@ -7,14 +7,17 @@ TEST_PROGS := run.sh
include ../lib.mk include ../lib.mk
all: all:
for DIR in $(SUBDIRS); do \ @for DIR in $(SUBDIRS); do \
BUILD_TARGET=$(OUTPUT)/$$DIR; \ BUILD_TARGET=$(OUTPUT)/$$DIR; \
mkdir $$BUILD_TARGET -p; \ mkdir $$BUILD_TARGET -p; \
make OUTPUT=$$BUILD_TARGET -C $$DIR $@;\ make OUTPUT=$$BUILD_TARGET -C $$DIR $@;\
if [ -e $$DIR/$(TEST_PROGS) ]; then
rsync -a $$DIR/$(TEST_PROGS) $$BUILD_TARGET/;
fi
done done
override define RUN_TESTS override define RUN_TESTS
$(OUTPUT)/run.sh @cd $(OUTPUT); ./run.sh
endef endef
override define INSTALL_RULE override define INSTALL_RULE
...@@ -33,7 +36,7 @@ override define EMIT_TESTS ...@@ -33,7 +36,7 @@ override define EMIT_TESTS
endef endef
override define CLEAN override define CLEAN
for DIR in $(SUBDIRS); do \ @for DIR in $(SUBDIRS); do \
BUILD_TARGET=$(OUTPUT)/$$DIR; \ BUILD_TARGET=$(OUTPUT)/$$DIR; \
mkdir $$BUILD_TARGET -p; \ mkdir $$BUILD_TARGET -p; \
make OUTPUT=$$BUILD_TARGET -C $$DIR $@;\ make OUTPUT=$$BUILD_TARGET -C $$DIR $@;\
......
CFLAGS := $(CFLAGS) -Wall -D_GNU_SOURCE CFLAGS := $(CFLAGS) -Wall -D_GNU_SOURCE
LDLIBS := $(LDLIBS) -lm LDLIBS := $(LDLIBS) -lm
ifeq (,$(filter $(ARCH),x86))
TEST_GEN_FILES := msr aperf TEST_GEN_FILES := msr aperf
endif
TEST_PROGS := run.sh TEST_PROGS := run.sh
......
...@@ -29,13 +29,12 @@ ...@@ -29,13 +29,12 @@
EVALUATE_ONLY=0 EVALUATE_ONLY=0
max_cpus=$(($(nproc)-1)) if ! uname -m | sed -e s/i.86/x86/ -e s/x86_64/x86/ | grep -q x86; then
echo "$0 # Skipped: Test can only run on x86 architectures."
exit 0
fi
# compile programs max_cpus=$(($(nproc)-1))
gcc aperf.c -Wall -D_GNU_SOURCE -o aperf -lm
[ $? -ne 0 ] && echo "Problem compiling aperf.c." && exit 1
gcc -o msr msr.c -lm
[ $? -ne 0 ] && echo "Problem compiling msr.c." && exit 1
function run_test () { function run_test () {
......
...@@ -6,7 +6,14 @@ ifeq (0,$(MAKELEVEL)) ...@@ -6,7 +6,14 @@ ifeq (0,$(MAKELEVEL))
OUTPUT := $(shell pwd) OUTPUT := $(shell pwd)
endif endif
# The following are built by lib.mk common compile rules.
# TEST_CUSTOM_PROGS should be used by tests that require
# custom build rule and prevent common build rule use.
# TEST_PROGS are for test shell scripts.
# TEST_CUSTOM_PROGS and TEST_PROGS will be run by common run_tests
# and install targets. Common clean doesn't touch them.
TEST_GEN_PROGS := $(patsubst %,$(OUTPUT)/%,$(TEST_GEN_PROGS)) TEST_GEN_PROGS := $(patsubst %,$(OUTPUT)/%,$(TEST_GEN_PROGS))
TEST_GEN_PROGS_EXTENDED := $(patsubst %,$(OUTPUT)/%,$(TEST_GEN_PROGS_EXTENDED))
TEST_GEN_FILES := $(patsubst %,$(OUTPUT)/%,$(TEST_GEN_FILES)) TEST_GEN_FILES := $(patsubst %,$(OUTPUT)/%,$(TEST_GEN_FILES))
all: $(TEST_GEN_PROGS) $(TEST_GEN_PROGS_EXTENDED) $(TEST_GEN_FILES) all: $(TEST_GEN_PROGS) $(TEST_GEN_PROGS_EXTENDED) $(TEST_GEN_FILES)
...@@ -20,17 +27,28 @@ define RUN_TESTS ...@@ -20,17 +27,28 @@ define RUN_TESTS
test_num=`echo $$test_num+1 | bc`; \ test_num=`echo $$test_num+1 | bc`; \
echo "selftests: $$BASENAME_TEST"; \ echo "selftests: $$BASENAME_TEST"; \
echo "========================================"; \ echo "========================================"; \
if [ ! -x $$BASENAME_TEST ]; then \ if [ ! -x $$TEST ]; then \
echo "selftests: Warning: file $$BASENAME_TEST is not executable, correct this.";\ echo "selftests: Warning: file $$BASENAME_TEST is not executable, correct this.";\
echo "not ok 1..$$test_num selftests: $$BASENAME_TEST [FAIL]"; \ echo "not ok 1..$$test_num selftests: $$BASENAME_TEST [FAIL]"; \
else \ else \
cd `dirname $$TEST` > /dev/null; (./$$BASENAME_TEST && echo "ok 1..$$test_num selftests: $$BASENAME_TEST [PASS]") || echo "not ok 1..$$test_num selftests: $$BASENAME_TEST [FAIL]"; cd - > /dev/null;\ cd `dirname $$TEST` > /dev/null; (./$$BASENAME_TEST > /tmp/$$BASENAME_TEST 2>&1 && echo "ok 1..$$test_num selftests: $$BASENAME_TEST [PASS]") || echo "not ok 1..$$test_num selftests: $$BASENAME_TEST [FAIL]"; cd - > /dev/null;\
fi; \ fi; \
done; done;
endef endef
run_tests: all run_tests: all
$(call RUN_TESTS, $(TEST_GEN_PROGS) $(TEST_PROGS)) ifneq ($(KBUILD_SRC),)
@if [ "X$(TEST_PROGS) $(TEST_PROGS_EXTENDED) $(TEST_FILES)" != "X" ]; then
@rsync -aq $(TEST_PROGS) $(TEST_PROGS_EXTENDED) $(TEST_FILES) $(OUTPUT)
fi
@if [ "X$(TEST_PROGS)" != "X" ]; then
$(call RUN_TESTS, $(TEST_GEN_PROGS) $(TEST_CUSTOM_PROGS) $(OUTPUT)/$(TEST_PROGS))
else
$(call RUN_TESTS, $(TEST_GEN_PROGS) $(TEST_CUSTOM_PROGS))
fi
else
$(call RUN_TESTS, $(TEST_GEN_PROGS) $(TEST_CUSTOM_PROGS) $(TEST_PROGS))
endif
define INSTALL_RULE define INSTALL_RULE
@if [ "X$(TEST_PROGS)$(TEST_PROGS_EXTENDED)$(TEST_FILES)" != "X" ]; then \ @if [ "X$(TEST_PROGS)$(TEST_PROGS_EXTENDED)$(TEST_FILES)" != "X" ]; then \
...@@ -38,10 +56,10 @@ define INSTALL_RULE ...@@ -38,10 +56,10 @@ define INSTALL_RULE
echo "rsync -a $(TEST_PROGS) $(TEST_PROGS_EXTENDED) $(TEST_FILES) $(INSTALL_PATH)/"; \ echo "rsync -a $(TEST_PROGS) $(TEST_PROGS_EXTENDED) $(TEST_FILES) $(INSTALL_PATH)/"; \
rsync -a $(TEST_PROGS) $(TEST_PROGS_EXTENDED) $(TEST_FILES) $(INSTALL_PATH)/; \ rsync -a $(TEST_PROGS) $(TEST_PROGS_EXTENDED) $(TEST_FILES) $(INSTALL_PATH)/; \
fi fi
@if [ "X$(TEST_GEN_PROGS)$(TEST_GEN_PROGS_EXTENDED)$(TEST_GEN_FILES)" != "X" ]; then \ @if [ "X$(TEST_GEN_PROGS)$(TEST_CUSTOM_PROGS)$(TEST_GEN_PROGS_EXTENDED)$(TEST_GEN_FILES)" != "X" ]; then \
mkdir -p ${INSTALL_PATH}; \ mkdir -p ${INSTALL_PATH}; \
echo "rsync -a $(TEST_GEN_PROGS) $(TEST_GEN_PROGS_EXTENDED) $(TEST_GEN_FILES) $(INSTALL_PATH)/"; \ echo "rsync -a $(TEST_GEN_PROGS) $(TEST_CUSTOM_PROGS) $(TEST_GEN_PROGS_EXTENDED) $(TEST_GEN_FILES) $(INSTALL_PATH)/"; \
rsync -a $(TEST_GEN_PROGS) $(TEST_GEN_PROGS_EXTENDED) $(TEST_GEN_FILES) $(INSTALL_PATH)/; \ rsync -a $(TEST_GEN_PROGS) $(TEST_CUSTOM_PROGS) $(TEST_GEN_PROGS_EXTENDED) $(TEST_GEN_FILES) $(INSTALL_PATH)/; \
fi fi
endef endef
...@@ -53,15 +71,20 @@ else ...@@ -53,15 +71,20 @@ else
endif endif
define EMIT_TESTS define EMIT_TESTS
@for TEST in $(TEST_GEN_PROGS) $(TEST_PROGS); do \ @for TEST in $(TEST_GEN_PROGS) $(TEST_CUSTOM_PROGS) $(TEST_PROGS); do \
BASENAME_TEST=`basename $$TEST`; \ BASENAME_TEST=`basename $$TEST`; \
echo "(./$$BASENAME_TEST && echo \"selftests: $$BASENAME_TEST [PASS]\") || echo \"selftests: $$BASENAME_TEST [FAIL]\""; \ echo "(./$$BASENAME_TEST > /tmp/$$BASENAME_TEST 2>&1 && echo \"selftests: $$BASENAME_TEST [PASS]\") || echo \"selftests: $$BASENAME_TEST [FAIL]\""; \
done; done;
endef endef
emit_tests: emit_tests:
$(EMIT_TESTS) $(EMIT_TESTS)
# define if isn't already. It is undefined in make O= case.
ifeq ($(RM),)
RM := rm -f
endif
define CLEAN define CLEAN
$(RM) -r $(TEST_GEN_PROGS) $(TEST_GEN_PROGS_EXTENDED) $(TEST_GEN_FILES) $(EXTRA_CLEAN) $(RM) -r $(TEST_GEN_PROGS) $(TEST_GEN_PROGS_EXTENDED) $(TEST_GEN_FILES) $(EXTRA_CLEAN)
endef endef
...@@ -69,6 +92,15 @@ endef ...@@ -69,6 +92,15 @@ endef
clean: clean:
$(CLEAN) $(CLEAN)
# When make O= with kselftest target from main level
# the following aren't defined.
#
ifneq ($(KBUILD_SRC),)
LINK.c = $(CC) $(CFLAGS) $(CPPFLAGS) $(LDFLAGS) $(TARGET_ARCH)
COMPILE.S = $(CC) $(ASFLAGS) $(CPPFLAGS) $(TARGET_ARCH) -c
LINK.S = $(CC) $(ASFLAGS) $(CPPFLAGS) $(LDFLAGS) $(TARGET_ARCH)
endif
$(OUTPUT)/%:%.c $(OUTPUT)/%:%.c
$(LINK.c) $^ $(LDLIBS) -o $@ $(LINK.c) $^ $(LDLIBS) -o $@
......
File mode changed from 100644 to 100755
...@@ -5,8 +5,8 @@ TEST_GEN_PROGS := mq_open_tests mq_perf_tests ...@@ -5,8 +5,8 @@ TEST_GEN_PROGS := mq_open_tests mq_perf_tests
include ../lib.mk include ../lib.mk
override define RUN_TESTS override define RUN_TESTS
@./mq_open_tests /test1 || echo "selftests: mq_open_tests [FAIL]" $(OUTPUT)/mq_open_tests /test1 || echo "selftests: mq_open_tests [FAIL]"
@./mq_perf_tests || echo "selftests: mq_perf_tests [FAIL]" $(OUTPUT)//mq_perf_tests || echo "selftests: mq_perf_tests [FAIL]"
endef endef
override define EMIT_TESTS override define EMIT_TESTS
......
...@@ -6,3 +6,4 @@ reuseport_bpf ...@@ -6,3 +6,4 @@ reuseport_bpf
reuseport_bpf_cpu reuseport_bpf_cpu
reuseport_bpf_numa reuseport_bpf_numa
reuseport_dualstack reuseport_dualstack
reuseaddr_conflict
...@@ -5,9 +5,9 @@ CFLAGS += -I../../../../usr/include/ ...@@ -5,9 +5,9 @@ CFLAGS += -I../../../../usr/include/
TEST_PROGS := run_netsocktests run_afpackettests test_bpf.sh netdevice.sh rtnetlink.sh TEST_PROGS := run_netsocktests run_afpackettests test_bpf.sh netdevice.sh rtnetlink.sh
TEST_GEN_FILES = socket TEST_GEN_FILES = socket
TEST_GEN_FILES += psock_fanout psock_tpacket TEST_GEN_FILES += psock_fanout psock_tpacket msg_zerocopy
TEST_GEN_FILES += reuseport_bpf reuseport_bpf_cpu reuseport_bpf_numa TEST_GEN_PROGS = reuseport_bpf reuseport_bpf_cpu reuseport_bpf_numa
TEST_GEN_FILES += reuseport_dualstack msg_zerocopy TEST_GEN_PROGS += reuseport_dualstack reuseaddr_conflict
include ../lib.mk include ../lib.mk
......
...@@ -55,7 +55,7 @@ ...@@ -55,7 +55,7 @@
#include <unistd.h> #include <unistd.h>
#ifndef SO_EE_ORIGIN_ZEROCOPY #ifndef SO_EE_ORIGIN_ZEROCOPY
#define SO_EE_ORIGIN_ZEROCOPY SO_EE_ORIGIN_UPAGE #define SO_EE_ORIGIN_ZEROCOPY 5
#endif #endif
#ifndef SO_ZEROCOPY #ifndef SO_ZEROCOPY
......
...@@ -178,7 +178,7 @@ if [ "$(id -u)" -ne 0 ];then ...@@ -178,7 +178,7 @@ if [ "$(id -u)" -ne 0 ];then
exit 0 exit 0
fi fi
ip -Version 2>/dev/null >/dev/null ip link show 2>/dev/null >/dev/null
if [ $? -ne 0 ];then if [ $? -ne 0 ];then
echo "SKIP: Could not run test without the ip tool" echo "SKIP: Could not run test without the ip tool"
exit 0 exit 0
......
/*
* Test for the regression introduced by
*
* b9470c27607b ("inet: kill smallest_size and smallest_port")
*
* If we open an ipv4 socket on a port with reuseaddr we shouldn't reset the tb
* when we open the ipv6 conterpart, which is what was happening previously.
*/
#include <errno.h>
#include <error.h>
#include <arpa/inet.h>
#include <netinet/in.h>
#include <stdbool.h>
#include <stdio.h>
#include <sys/socket.h>
#include <sys/types.h>
#include <unistd.h>
#define PORT 9999
int open_port(int ipv6, int any)
{
int fd = -1;
int reuseaddr = 1;
int v6only = 1;
int addrlen;
int ret = -1;
struct sockaddr *addr;
int family = ipv6 ? AF_INET6 : AF_INET;
struct sockaddr_in6 addr6 = {
.sin6_family = AF_INET6,
.sin6_port = htons(PORT),
.sin6_addr = in6addr_any
};
struct sockaddr_in addr4 = {
.sin_family = AF_INET,
.sin_port = htons(PORT),
.sin_addr.s_addr = any ? htonl(INADDR_ANY) : inet_addr("127.0.0.1"),
};
if (ipv6) {
addr = (struct sockaddr*)&addr6;
addrlen = sizeof(addr6);
} else {
addr = (struct sockaddr*)&addr4;
addrlen = sizeof(addr4);
}
if ((fd = socket(family, SOCK_STREAM, IPPROTO_TCP)) < 0) {
perror("socket");
goto out;
}
if (ipv6 && setsockopt(fd, IPPROTO_IPV6, IPV6_V6ONLY, (void*)&v6only,
sizeof(v6only)) < 0) {
perror("setsockopt IPV6_V6ONLY");
goto out;
}
if (setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &reuseaddr,
sizeof(reuseaddr)) < 0) {
perror("setsockopt SO_REUSEADDR");
goto out;
}
if (bind(fd, addr, addrlen) < 0) {
perror("bind");
goto out;
}
if (any)
return fd;
if (listen(fd, 1) < 0) {
perror("listen");
goto out;
}
return fd;
out:
close(fd);
return ret;
}
int main(void)
{
int listenfd;
int fd1, fd2;
fprintf(stderr, "Opening 127.0.0.1:%d\n", PORT);
listenfd = open_port(0, 0);
if (listenfd < 0)
error(1, errno, "Couldn't open listen socket");
fprintf(stderr, "Opening INADDR_ANY:%d\n", PORT);
fd1 = open_port(0, 1);
if (fd1 >= 0)
error(1, 0, "Was allowed to create an ipv4 reuseport on a already bound non-reuseport socket");
fprintf(stderr, "Opening in6addr_any:%d\n", PORT);
fd1 = open_port(1, 1);
if (fd1 < 0)
error(1, errno, "Couldn't open ipv6 reuseport");
fprintf(stderr, "Opening INADDR_ANY:%d\n", PORT);
fd2 = open_port(0, 1);
if (fd2 >= 0)
error(1, 0, "Was allowed to create an ipv4 reuseport on a already bound non-reuseport socket");
close(fd1);
fprintf(stderr, "Opening INADDR_ANY:%d after closing ipv6 socket\n", PORT);
fd1 = open_port(0, 1);
if (fd1 >= 0)
error(1, 0, "Was allowed to create an ipv4 reuseport on an already bound non-reuseport socket with no ipv6");
fprintf(stderr, "Success");
return 0;
}
...@@ -6,10 +6,18 @@ ...@@ -6,10 +6,18 @@
*/ */
#include <sys/types.h> #include <sys/types.h>
#include <asm/siginfo.h>
#define __have_siginfo_t 1 /*
#define __have_sigval_t 1 * glibc 2.26 and later have SIGSYS in siginfo_t. Before that,
#define __have_sigevent_t 1 * we need to use the kernel's siginfo.h file and trick glibc
* into accepting it.
*/
#if !__GLIBC_PREREQ(2, 26)
# include <asm/siginfo.h>
# define __have_siginfo_t 1
# define __have_sigval_t 1
# define __have_sigevent_t 1
#endif
#include <errno.h> #include <errno.h>
#include <linux/filter.h> #include <linux/filter.h>
...@@ -884,7 +892,7 @@ TEST_F_SIGNAL(TRAP, ign, SIGSYS) ...@@ -884,7 +892,7 @@ TEST_F_SIGNAL(TRAP, ign, SIGSYS)
syscall(__NR_getpid); syscall(__NR_getpid);
} }
static struct siginfo TRAP_info; static siginfo_t TRAP_info;
static volatile int TRAP_nr; static volatile int TRAP_nr;
static void TRAP_action(int nr, siginfo_t *info, void *void_context) static void TRAP_action(int nr, siginfo_t *info, void *void_context)
{ {
......
...@@ -39,7 +39,11 @@ void my_usr1(int sig, siginfo_t *si, void *u) ...@@ -39,7 +39,11 @@ void my_usr1(int sig, siginfo_t *si, void *u)
stack_t stk; stack_t stk;
struct stk_data *p; struct stk_data *p;
#if __s390x__
register unsigned long sp asm("%15");
#else
register unsigned long sp asm("sp"); register unsigned long sp asm("sp");
#endif
if (sp < (unsigned long)sstack || if (sp < (unsigned long)sstack ||
sp >= (unsigned long)sstack + SIGSTKSZ) { sp >= (unsigned long)sstack + SIGSTKSZ) {
......
...@@ -2,12 +2,16 @@ CFLAGS += -O2 -g -std=gnu89 -pthread -Wall -Wextra ...@@ -2,12 +2,16 @@ CFLAGS += -O2 -g -std=gnu89 -pthread -Wall -Wextra
CFLAGS += -I../../../../usr/include/ CFLAGS += -I../../../../usr/include/
LDFLAGS += -pthread LDFLAGS += -pthread
TEST_PROGS = sync_test .PHONY: all clean
all: $(TEST_PROGS)
include ../lib.mk include ../lib.mk
# lib.mk TEST_CUSTOM_PROGS var is for custom tests that need special
# build rules. lib.mk will run and install them.
TEST_CUSTOM_PROGS := $(OUTPUT)/sync_test
all: $(TEST_CUSTOM_PROGS)
OBJS = sync_test.o sync.o OBJS = sync_test.o sync.o
TESTS += sync_alloc.o TESTS += sync_alloc.o
...@@ -18,6 +22,16 @@ TESTS += sync_stress_parallelism.o ...@@ -18,6 +22,16 @@ TESTS += sync_stress_parallelism.o
TESTS += sync_stress_consumer.o TESTS += sync_stress_consumer.o
TESTS += sync_stress_merge.o TESTS += sync_stress_merge.o
sync_test: $(OBJS) $(TESTS) OBJS := $(patsubst %,$(OUTPUT)/%,$(OBJS))
TESTS := $(patsubst %,$(OUTPUT)/%,$(TESTS))
$(TEST_CUSTOM_PROGS): $(TESTS) $(OBJS)
$(CC) -o $(TEST_CUSTOM_PROGS) $(OBJS) $(TESTS) $(CFLAGS) $(LDFLAGS)
$(OBJS): $(OUTPUT)/%.o: %.c
$(CC) -c $^ -o $@
$(TESTS): $(OUTPUT)/%.o: %.c
$(CC) -c $^ -o $@
EXTRA_CLEAN := sync_test $(OBJS) $(TESTS) EXTRA_CLEAN := $(TEST_CUSTOM_PROGS) $(OBJS) $(TESTS)
...@@ -143,7 +143,8 @@ int setup_timer(int clock_id, int flags, int interval, timer_t *tm1) ...@@ -143,7 +143,8 @@ int setup_timer(int clock_id, int flags, int interval, timer_t *tm1)
printf("%-22s %s missing CAP_WAKE_ALARM? : [UNSUPPORTED]\n", printf("%-22s %s missing CAP_WAKE_ALARM? : [UNSUPPORTED]\n",
clockstring(clock_id), clockstring(clock_id),
flags ? "ABSTIME":"RELTIME"); flags ? "ABSTIME":"RELTIME");
return 0; /* Indicate timer isn't set, so caller doesn't wait */
return 1;
} }
printf("%s - timer_create() failed\n", clockstring(clock_id)); printf("%s - timer_create() failed\n", clockstring(clock_id));
return -1; return -1;
...@@ -213,8 +214,9 @@ int do_timer(int clock_id, int flags) ...@@ -213,8 +214,9 @@ int do_timer(int clock_id, int flags)
int err; int err;
err = setup_timer(clock_id, flags, interval, &tm1); err = setup_timer(clock_id, flags, interval, &tm1);
/* Unsupported case - return 0 to not fail the test */
if (err) if (err)
return err; return err == 1 ? 0 : err;
while (alarmcount < 5) while (alarmcount < 5)
sleep(1); sleep(1);
...@@ -228,18 +230,17 @@ int do_timer_oneshot(int clock_id, int flags) ...@@ -228,18 +230,17 @@ int do_timer_oneshot(int clock_id, int flags)
timer_t tm1; timer_t tm1;
const int interval = 0; const int interval = 0;
struct timeval timeout; struct timeval timeout;
fd_set fds;
int err; int err;
err = setup_timer(clock_id, flags, interval, &tm1); err = setup_timer(clock_id, flags, interval, &tm1);
/* Unsupported case - return 0 to not fail the test */
if (err) if (err)
return err; return err == 1 ? 0 : err;
memset(&timeout, 0, sizeof(timeout)); memset(&timeout, 0, sizeof(timeout));
timeout.tv_sec = 5; timeout.tv_sec = 5;
FD_ZERO(&fds);
do { do {
err = select(FD_SETSIZE, &fds, NULL, NULL, &timeout); err = select(0, NULL, NULL, NULL, &timeout);
} while (err == -1 && errno == EINTR); } while (err == -1 && errno == EINTR);
timer_delete(tm1); timer_delete(tm1);
......
TEST_PROGS := watchdog-test TEST_GEN_PROGS := watchdog-test
all: $(TEST_PROGS)
include ../lib.mk include ../lib.mk
clean:
rm -fr $(TEST_PROGS)
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