Skip to content

Commit c0747ad

Browse files
committed
Merge tag 'linux-kselftest-4.19-rc5' of git://git.kernel.org/pub/scm/linux/kernel/git/shuah/linux-kselftest
Pulled kselftest fixes from Shuah: "This Kselftest fixes update for 4.9-rc5 consists of: -- fixes to build failures -- fixes to add missing config files to increase test coverage -- fixes to cgroup test and a new cgroup test for memory.oom.group"
2 parents 7876320 + a987785 commit c0747ad

File tree

19 files changed

+280
-32
lines changed

19 files changed

+280
-32
lines changed

Makefile

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -299,19 +299,7 @@ KERNELRELEASE = $(shell cat include/config/kernel.release 2> /dev/null)
299299
KERNELVERSION = $(VERSION)$(if $(PATCHLEVEL),.$(PATCHLEVEL)$(if $(SUBLEVEL),.$(SUBLEVEL)))$(EXTRAVERSION)
300300
export VERSION PATCHLEVEL SUBLEVEL KERNELRELEASE KERNELVERSION
301301

302-
# SUBARCH tells the usermode build what the underlying arch is. That is set
303-
# first, and if a usermode build is happening, the "ARCH=um" on the command
304-
# line overrides the setting of ARCH below. If a native build is happening,
305-
# then ARCH is assigned, getting whatever value it gets normally, and
306-
# SUBARCH is subsequently ignored.
307-
308-
SUBARCH := $(shell uname -m | sed -e s/i.86/x86/ -e s/x86_64/x86/ \
309-
-e s/sun4u/sparc64/ \
310-
-e s/arm.*/arm/ -e s/sa110/arm/ \
311-
-e s/s390x/s390/ -e s/parisc64/parisc/ \
312-
-e s/ppc.*/powerpc/ -e s/mips.*/mips/ \
313-
-e s/sh[234].*/sh/ -e s/aarch64.*/arm64/ \
314-
-e s/riscv.*/riscv/)
302+
include scripts/subarch.include
315303

316304
# Cross compiling and selecting different set of gcc/bin-utils
317305
# ---------------------------------------------------------------------------

scripts/subarch.include

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# SUBARCH tells the usermode build what the underlying arch is. That is set
2+
# first, and if a usermode build is happening, the "ARCH=um" on the command
3+
# line overrides the setting of ARCH below. If a native build is happening,
4+
# then ARCH is assigned, getting whatever value it gets normally, and
5+
# SUBARCH is subsequently ignored.
6+
7+
SUBARCH := $(shell uname -m | sed -e s/i.86/x86/ -e s/x86_64/x86/ \
8+
-e s/sun4u/sparc64/ \
9+
-e s/arm.*/arm/ -e s/sa110/arm/ \
10+
-e s/s390x/s390/ -e s/parisc64/parisc/ \
11+
-e s/ppc.*/powerpc/ -e s/mips.*/mips/ \
12+
-e s/sh[234].*/sh/ -e s/aarch64.*/arm64/ \
13+
-e s/riscv.*/riscv/)

tools/testing/selftests/android/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ TEST_PROGS := run.sh
66

77
include ../lib.mk
88

9-
all:
9+
all: khdr
1010
@for DIR in $(SUBDIRS); do \
1111
BUILD_TARGET=$(OUTPUT)/$$DIR; \
1212
mkdir $$BUILD_TARGET -p; \

tools/testing/selftests/android/ion/Makefile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ $(TEST_GEN_FILES): ipcsocket.c ionutils.c
1010

1111
TEST_PROGS := ion_test.sh
1212

13+
KSFT_KHDR_INSTALL := 1
14+
top_srcdir = ../../../../..
1315
include ../../lib.mk
1416

1517
$(OUTPUT)/ionapp_export: ionapp_export.c ipcsocket.c ionutils.c
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
test_memcontrol
2+
test_core

tools/testing/selftests/cgroup/cgroup_util.c

Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,17 +89,28 @@ int cg_read(const char *cgroup, const char *control, char *buf, size_t len)
8989
int cg_read_strcmp(const char *cgroup, const char *control,
9090
const char *expected)
9191
{
92-
size_t size = strlen(expected) + 1;
92+
size_t size;
9393
char *buf;
94+
int ret;
95+
96+
/* Handle the case of comparing against empty string */
97+
if (!expected)
98+
size = 32;
99+
else
100+
size = strlen(expected) + 1;
94101

95102
buf = malloc(size);
96103
if (!buf)
97104
return -1;
98105

99-
if (cg_read(cgroup, control, buf, size))
106+
if (cg_read(cgroup, control, buf, size)) {
107+
free(buf);
100108
return -1;
109+
}
101110

102-
return strcmp(expected, buf);
111+
ret = strcmp(expected, buf);
112+
free(buf);
113+
return ret;
103114
}
104115

105116
int cg_read_strstr(const char *cgroup, const char *control, const char *needle)
@@ -337,3 +348,24 @@ int is_swap_enabled(void)
337348

338349
return cnt > 1;
339350
}
351+
352+
int set_oom_adj_score(int pid, int score)
353+
{
354+
char path[PATH_MAX];
355+
int fd, len;
356+
357+
sprintf(path, "/proc/%d/oom_score_adj", pid);
358+
359+
fd = open(path, O_WRONLY | O_APPEND);
360+
if (fd < 0)
361+
return fd;
362+
363+
len = dprintf(fd, "%d", score);
364+
if (len < 0) {
365+
close(fd);
366+
return len;
367+
}
368+
369+
close(fd);
370+
return 0;
371+
}

tools/testing/selftests/cgroup/cgroup_util.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,3 +40,4 @@ extern int get_temp_fd(void);
4040
extern int alloc_pagecache(int fd, size_t size);
4141
extern int alloc_anon(const char *cgroup, void *arg);
4242
extern int is_swap_enabled(void);
43+
extern int set_oom_adj_score(int pid, int score);

tools/testing/selftests/cgroup/test_memcontrol.c

Lines changed: 205 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#define _GNU_SOURCE
33

44
#include <linux/limits.h>
5+
#include <linux/oom.h>
56
#include <fcntl.h>
67
#include <stdio.h>
78
#include <stdlib.h>
@@ -202,6 +203,36 @@ static int alloc_pagecache_50M_noexit(const char *cgroup, void *arg)
202203
return 0;
203204
}
204205

206+
static int alloc_anon_noexit(const char *cgroup, void *arg)
207+
{
208+
int ppid = getppid();
209+
210+
if (alloc_anon(cgroup, arg))
211+
return -1;
212+
213+
while (getppid() == ppid)
214+
sleep(1);
215+
216+
return 0;
217+
}
218+
219+
/*
220+
* Wait until processes are killed asynchronously by the OOM killer
221+
* If we exceed a timeout, fail.
222+
*/
223+
static int cg_test_proc_killed(const char *cgroup)
224+
{
225+
int limit;
226+
227+
for (limit = 10; limit > 0; limit--) {
228+
if (cg_read_strcmp(cgroup, "cgroup.procs", "") == 0)
229+
return 0;
230+
231+
usleep(100000);
232+
}
233+
return -1;
234+
}
235+
205236
/*
206237
* First, this test creates the following hierarchy:
207238
* A memory.min = 50M, memory.max = 200M
@@ -964,6 +995,177 @@ static int test_memcg_sock(const char *root)
964995
return ret;
965996
}
966997

998+
/*
999+
* This test disables swapping and tries to allocate anonymous memory
1000+
* up to OOM with memory.group.oom set. Then it checks that all
1001+
* processes in the leaf (but not the parent) were killed.
1002+
*/
1003+
static int test_memcg_oom_group_leaf_events(const char *root)
1004+
{
1005+
int ret = KSFT_FAIL;
1006+
char *parent, *child;
1007+
1008+
parent = cg_name(root, "memcg_test_0");
1009+
child = cg_name(root, "memcg_test_0/memcg_test_1");
1010+
1011+
if (!parent || !child)
1012+
goto cleanup;
1013+
1014+
if (cg_create(parent))
1015+
goto cleanup;
1016+
1017+
if (cg_create(child))
1018+
goto cleanup;
1019+
1020+
if (cg_write(parent, "cgroup.subtree_control", "+memory"))
1021+
goto cleanup;
1022+
1023+
if (cg_write(child, "memory.max", "50M"))
1024+
goto cleanup;
1025+
1026+
if (cg_write(child, "memory.swap.max", "0"))
1027+
goto cleanup;
1028+
1029+
if (cg_write(child, "memory.oom.group", "1"))
1030+
goto cleanup;
1031+
1032+
cg_run_nowait(parent, alloc_anon_noexit, (void *) MB(60));
1033+
cg_run_nowait(child, alloc_anon_noexit, (void *) MB(1));
1034+
cg_run_nowait(child, alloc_anon_noexit, (void *) MB(1));
1035+
if (!cg_run(child, alloc_anon, (void *)MB(100)))
1036+
goto cleanup;
1037+
1038+
if (cg_test_proc_killed(child))
1039+
goto cleanup;
1040+
1041+
if (cg_read_key_long(child, "memory.events", "oom_kill ") <= 0)
1042+
goto cleanup;
1043+
1044+
if (cg_read_key_long(parent, "memory.events", "oom_kill ") != 0)
1045+
goto cleanup;
1046+
1047+
ret = KSFT_PASS;
1048+
1049+
cleanup:
1050+
if (child)
1051+
cg_destroy(child);
1052+
if (parent)
1053+
cg_destroy(parent);
1054+
free(child);
1055+
free(parent);
1056+
1057+
return ret;
1058+
}
1059+
1060+
/*
1061+
* This test disables swapping and tries to allocate anonymous memory
1062+
* up to OOM with memory.group.oom set. Then it checks that all
1063+
* processes in the parent and leaf were killed.
1064+
*/
1065+
static int test_memcg_oom_group_parent_events(const char *root)
1066+
{
1067+
int ret = KSFT_FAIL;
1068+
char *parent, *child;
1069+
1070+
parent = cg_name(root, "memcg_test_0");
1071+
child = cg_name(root, "memcg_test_0/memcg_test_1");
1072+
1073+
if (!parent || !child)
1074+
goto cleanup;
1075+
1076+
if (cg_create(parent))
1077+
goto cleanup;
1078+
1079+
if (cg_create(child))
1080+
goto cleanup;
1081+
1082+
if (cg_write(parent, "memory.max", "80M"))
1083+
goto cleanup;
1084+
1085+
if (cg_write(parent, "memory.swap.max", "0"))
1086+
goto cleanup;
1087+
1088+
if (cg_write(parent, "memory.oom.group", "1"))
1089+
goto cleanup;
1090+
1091+
cg_run_nowait(parent, alloc_anon_noexit, (void *) MB(60));
1092+
cg_run_nowait(child, alloc_anon_noexit, (void *) MB(1));
1093+
cg_run_nowait(child, alloc_anon_noexit, (void *) MB(1));
1094+
1095+
if (!cg_run(child, alloc_anon, (void *)MB(100)))
1096+
goto cleanup;
1097+
1098+
if (cg_test_proc_killed(child))
1099+
goto cleanup;
1100+
if (cg_test_proc_killed(parent))
1101+
goto cleanup;
1102+
1103+
ret = KSFT_PASS;
1104+
1105+
cleanup:
1106+
if (child)
1107+
cg_destroy(child);
1108+
if (parent)
1109+
cg_destroy(parent);
1110+
free(child);
1111+
free(parent);
1112+
1113+
return ret;
1114+
}
1115+
1116+
/*
1117+
* This test disables swapping and tries to allocate anonymous memory
1118+
* up to OOM with memory.group.oom set. Then it checks that all
1119+
* processes were killed except those set with OOM_SCORE_ADJ_MIN
1120+
*/
1121+
static int test_memcg_oom_group_score_events(const char *root)
1122+
{
1123+
int ret = KSFT_FAIL;
1124+
char *memcg;
1125+
int safe_pid;
1126+
1127+
memcg = cg_name(root, "memcg_test_0");
1128+
1129+
if (!memcg)
1130+
goto cleanup;
1131+
1132+
if (cg_create(memcg))
1133+
goto cleanup;
1134+
1135+
if (cg_write(memcg, "memory.max", "50M"))
1136+
goto cleanup;
1137+
1138+
if (cg_write(memcg, "memory.swap.max", "0"))
1139+
goto cleanup;
1140+
1141+
if (cg_write(memcg, "memory.oom.group", "1"))
1142+
goto cleanup;
1143+
1144+
safe_pid = cg_run_nowait(memcg, alloc_anon_noexit, (void *) MB(1));
1145+
if (set_oom_adj_score(safe_pid, OOM_SCORE_ADJ_MIN))
1146+
goto cleanup;
1147+
1148+
cg_run_nowait(memcg, alloc_anon_noexit, (void *) MB(1));
1149+
if (!cg_run(memcg, alloc_anon, (void *)MB(100)))
1150+
goto cleanup;
1151+
1152+
if (cg_read_key_long(memcg, "memory.events", "oom_kill ") != 3)
1153+
goto cleanup;
1154+
1155+
if (kill(safe_pid, SIGKILL))
1156+
goto cleanup;
1157+
1158+
ret = KSFT_PASS;
1159+
1160+
cleanup:
1161+
if (memcg)
1162+
cg_destroy(memcg);
1163+
free(memcg);
1164+
1165+
return ret;
1166+
}
1167+
1168+
9671169
#define T(x) { x, #x }
9681170
struct memcg_test {
9691171
int (*fn)(const char *root);
@@ -978,6 +1180,9 @@ struct memcg_test {
9781180
T(test_memcg_oom_events),
9791181
T(test_memcg_swap_max),
9801182
T(test_memcg_sock),
1183+
T(test_memcg_oom_group_leaf_events),
1184+
T(test_memcg_oom_group_parent_events),
1185+
T(test_memcg_oom_group_score_events),
9811186
};
9821187
#undef T
9831188

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
CONFIG_EFIVAR_FS=y

tools/testing/selftests/futex/functional/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ TEST_GEN_FILES := \
1818

1919
TEST_PROGS := run.sh
2020

21+
top_srcdir = ../../../../..
2122
include ../../lib.mk
2223

2324
$(TEST_GEN_FILES): $(HEADERS)

tools/testing/selftests/gpio/Makefile

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,8 @@ endef
2121
CFLAGS += -O2 -g -std=gnu99 -Wall -I../../../../usr/include/
2222
LDLIBS += -lmount -I/usr/include/libmount
2323

24-
$(BINARIES): ../../../gpio/gpio-utils.o ../../../../usr/include/linux/gpio.h
24+
$(BINARIES):| khdr
25+
$(BINARIES): ../../../gpio/gpio-utils.o
2526

2627
../../../gpio/gpio-utils.o:
2728
make ARCH=$(ARCH) CROSS_COMPILE=$(CROSS_COMPILE) -C ../../../gpio
28-
29-
../../../../usr/include/linux/gpio.h:
30-
make -C ../../../.. headers_install INSTALL_HDR_PATH=$(shell pwd)/../../../../usr/
31-

tools/testing/selftests/kselftest.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
#define KSFT_FAIL 1
2020
#define KSFT_XFAIL 2
2121
#define KSFT_XPASS 3
22-
/* Treat skip as pass */
2322
#define KSFT_SKIP 4
2423

2524
/* counters */

tools/testing/selftests/kvm/Makefile

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,6 @@ $(LIBKVM_OBJ): $(OUTPUT)/%.o: %.c
3737
$(OUTPUT)/libkvm.a: $(LIBKVM_OBJ)
3838
$(AR) crs $@ $^
3939

40-
$(LINUX_HDR_PATH):
41-
make -C $(top_srcdir) headers_install
42-
43-
all: $(STATIC_LIBS) $(LINUX_HDR_PATH)
40+
all: $(STATIC_LIBS)
4441
$(TEST_GEN_PROGS): $(STATIC_LIBS)
45-
$(TEST_GEN_PROGS) $(LIBKVM_OBJ): | $(LINUX_HDR_PATH)
42+
$(STATIC_LIBS):| khdr

0 commit comments

Comments
 (0)