Skip to content

Commit 0f50767

Browse files
committed
Merge tag 'linux-kselftest-next-6.4-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/shuah/linux-kselftest
Pull Kselftest updates from Shuah Khan: - several patches to enhance and fix resctrl test - nolibc support for kselftest with an addition to vprintf() to tools/nolibc/stdio and related test changes - Refactor 'peeksiginfo' ptrace test part - add 'malloc' failures checks in cgroup test_memcontrol - a new prctl test - enhancements sched test with additional ore schedule prctl calls * tag 'linux-kselftest-next-6.4-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/shuah/linux-kselftest: (25 commits) selftests/resctrl: Fix incorrect error return on test complete selftests/resctrl: Remove duplicate codes that clear each test result file selftests/resctrl: Commonize the signal handler register/unregister for all tests selftests/resctrl: Cleanup properly when an error occurs in CAT test selftests/resctrl: Flush stdout file buffer before executing fork() selftests/resctrl: Return MBA check result and make it to output message selftests/resctrl: Fix set up schemata with 100% allocation on first run in MBM test selftests/resctrl: Use correct exit code when tests fail kselftest/arm64: Convert za-fork to use kselftest.h kselftest: Support nolibc tools/nolibc/stdio: Implement vprintf() selftests/resctrl: Correct get_llc_perf() param in function comment selftests/resctrl: Use remount_resctrlfs() consistently with boolean selftests/resctrl: Change name from CBM_MASK_PATH to INFO_PATH selftests/resctrl: Change initialize_llc_perf() return type to void selftests/resctrl: Replace obsolete memalign() with posix_memalign() selftests/resctrl: Check for return value after write_schemata() selftests/resctrl: Allow ->setup() to return errors selftests/resctrl: Move ->setup() call outside of test specific branches selftests/resctrl: Return NULL if malloc_and_init_memory() did not alloc mem ...
2 parents 5dfb75e + 50ad2fb commit 0f50767

24 files changed

+306
-204
lines changed

tools/include/nolibc/stdio.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,12 @@ int vfprintf(FILE *stream, const char *fmt, va_list args)
273273
return written;
274274
}
275275

276+
static __attribute__((unused))
277+
int vprintf(const char *fmt, va_list args)
278+
{
279+
return vfprintf(stdout, fmt, args);
280+
}
281+
276282
static __attribute__((unused, format(printf, 2, 3)))
277283
int fprintf(FILE *stream, const char *fmt, ...)
278284
{

tools/testing/selftests/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ TARGETS += nsfs
5858
TARGETS += pidfd
5959
TARGETS += pid_namespace
6060
TARGETS += powerpc
61+
TARGETS += prctl
6162
TARGETS += proc
6263
TARGETS += pstore
6364
TARGETS += ptrace

tools/testing/selftests/amd-pstate/gitsource.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ parse_gitsource()
117117
printf "Gitsource-$1-#$2 power consumption(J): $en_sum\n" | tee -a $OUTFILE_GIT.result
118118

119119
# Permance is the number of run gitsource per second, denoted 1/t, where 1 is the number of run gitsource in t
120-
# senconds. It is well known that P=E/t, where P is power measured in watts(W), E is energy measured in joules(J),
120+
# seconds. It is well known that P=E/t, where P is power measured in watts(W), E is energy measured in joules(J),
121121
# and t is time measured in seconds(s). This means that performance per watt becomes
122122
# 1/t 1/t 1
123123
# ----- = ----- = ---
@@ -175,7 +175,7 @@ gather_gitsource()
175175
printf "Gitsource-$1 avg power consumption(J): $avg_en\n" | tee -a $OUTFILE_GIT.result
176176

177177
# Permance is the number of run gitsource per second, denoted 1/t, where 1 is the number of run gitsource in t
178-
# senconds. It is well known that P=E/t, where P is power measured in watts(W), E is energy measured in joules(J),
178+
# seconds. It is well known that P=E/t, where P is power measured in watts(W), E is energy measured in joules(J),
179179
# and t is time measured in seconds(s). This means that performance per watt becomes
180180
# 1/t 1/t 1
181181
# ----- = ----- = ---

tools/testing/selftests/amd-pstate/run.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -244,15 +244,15 @@ prerequisite()
244244
if [ "$scaling_driver" != "$CURRENT_TEST" ]; then
245245
echo "$0 # Skipped: Test can only run on $CURRENT_TEST driver or run comparative test."
246246
echo "$0 # Please set X86_AMD_PSTATE enabled or run comparative test."
247-
echo "$0 # Current cpufreq scaling drvier is $scaling_driver."
247+
echo "$0 # Current cpufreq scaling driver is $scaling_driver."
248248
exit $ksft_skip
249249
fi
250250
else
251251
case "$FUNC" in
252252
"tbench" | "gitsource")
253253
if [ "$scaling_driver" != "$COMPARATIVE_TEST" ]; then
254254
echo "$0 # Skipped: Comparison test can only run on $COMPARISON_TEST driver."
255-
echo "$0 # Current cpufreq scaling drvier is $scaling_driver."
255+
echo "$0 # Current cpufreq scaling driver is $scaling_driver."
256256
exit $ksft_skip
257257
fi
258258
;;

tools/testing/selftests/arm64/fp/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ $(OUTPUT)/vec-syscfg: vec-syscfg.c $(OUTPUT)/rdvl.o
3838
$(OUTPUT)/vlset: vlset.c
3939
$(OUTPUT)/za-fork: za-fork.c $(OUTPUT)/za-fork-asm.o
4040
$(CC) -fno-asynchronous-unwind-tables -fno-ident -s -Os -nostdlib \
41-
-include ../../../../include/nolibc/nolibc.h \
41+
-include ../../../../include/nolibc/nolibc.h -I../..\
4242
-static -ffreestanding -Wall $^ -o $@
4343
$(OUTPUT)/za-ptrace: za-ptrace.c
4444
$(OUTPUT)/za-test: za-test.S $(OUTPUT)/asm-utils.o

tools/testing/selftests/arm64/fp/za-fork.c

Lines changed: 16 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -9,42 +9,9 @@
99
#include <linux/sched.h>
1010
#include <linux/wait.h>
1111

12-
#define EXPECTED_TESTS 1
13-
14-
static void putstr(const char *str)
15-
{
16-
write(1, str, strlen(str));
17-
}
18-
19-
static void putnum(unsigned int num)
20-
{
21-
char c;
22-
23-
if (num / 10)
24-
putnum(num / 10);
25-
26-
c = '0' + (num % 10);
27-
write(1, &c, 1);
28-
}
12+
#include "kselftest.h"
2913

30-
static int tests_run;
31-
static int tests_passed;
32-
static int tests_failed;
33-
static int tests_skipped;
34-
35-
static void print_summary(void)
36-
{
37-
if (tests_passed + tests_failed + tests_skipped != EXPECTED_TESTS)
38-
putstr("# UNEXPECTED TEST COUNT: ");
39-
40-
putstr("# Totals: pass:");
41-
putnum(tests_passed);
42-
putstr(" fail:");
43-
putnum(tests_failed);
44-
putstr(" xfail:0 xpass:0 skip:");
45-
putnum(tests_skipped);
46-
putstr(" error:0\n");
47-
}
14+
#define EXPECTED_TESTS 1
4815

4916
int fork_test(void);
5017
int verify_fork(void);
@@ -63,71 +30,53 @@ int fork_test_c(void)
6330
if (newpid == 0) {
6431
/* In child */
6532
if (!verify_fork()) {
66-
putstr("# ZA state invalid in child\n");
33+
ksft_print_msg("ZA state invalid in child\n");
6734
exit(0);
6835
} else {
6936
exit(1);
7037
}
7138
}
7239
if (newpid < 0) {
73-
putstr("# fork() failed: -");
74-
putnum(-newpid);
75-
putstr("\n");
40+
ksft_print_msg("fork() failed: %d\n", newpid);
41+
7642
return 0;
7743
}
7844

7945
parent_result = verify_fork();
8046
if (!parent_result)
81-
putstr("# ZA state invalid in parent\n");
47+
ksft_print_msg("ZA state invalid in parent\n");
8248

8349
for (;;) {
8450
waiting = waitpid(newpid, &child_status, 0);
8551

8652
if (waiting < 0) {
8753
if (errno == EINTR)
8854
continue;
89-
putstr("# waitpid() failed: ");
90-
putnum(errno);
91-
putstr("\n");
55+
ksft_print_msg("waitpid() failed: %d\n", errno);
9256
return 0;
9357
}
9458
if (waiting != newpid) {
95-
putstr("# waitpid() returned wrong PID\n");
59+
ksft_print_msg("waitpid() returned wrong PID\n");
9660
return 0;
9761
}
9862

9963
if (!WIFEXITED(child_status)) {
100-
putstr("# child did not exit\n");
64+
ksft_print_msg("child did not exit\n");
10165
return 0;
10266
}
10367

10468
return WEXITSTATUS(child_status) && parent_result;
10569
}
10670
}
10771

108-
#define run_test(name) \
109-
if (name()) { \
110-
tests_passed++; \
111-
} else { \
112-
tests_failed++; \
113-
putstr("not "); \
114-
} \
115-
putstr("ok "); \
116-
putnum(++tests_run); \
117-
putstr(" " #name "\n");
118-
11972
int main(int argc, char **argv)
12073
{
12174
int ret, i;
12275

123-
putstr("TAP version 13\n");
124-
putstr("1..");
125-
putnum(EXPECTED_TESTS);
126-
putstr("\n");
76+
ksft_print_header();
77+
ksft_set_plan(EXPECTED_TESTS);
12778

128-
putstr("# PID: ");
129-
putnum(getpid());
130-
putstr("\n");
79+
ksft_print_msg("PID: %d\n", getpid());
13180

13281
/*
13382
* This test is run with nolibc which doesn't support hwcap and
@@ -136,21 +85,16 @@ int main(int argc, char **argv)
13685
*/
13786
ret = open("/proc/sys/abi/sme_default_vector_length", O_RDONLY, 0);
13887
if (ret >= 0) {
139-
run_test(fork_test);
88+
ksft_test_result(fork_test(), "fork_test");
14089

14190
} else {
142-
putstr("# SME support not present\n");
143-
91+
ksft_print_msg("SME not supported\n");
14492
for (i = 0; i < EXPECTED_TESTS; i++) {
145-
putstr("ok ");
146-
putnum(i);
147-
putstr(" skipped\n");
93+
ksft_test_result_skip("fork_test\n");
14894
}
149-
150-
tests_skipped += EXPECTED_TESTS;
15195
}
15296

153-
print_summary();
97+
ksft_finished();
15498

15599
return 0;
156100
}

tools/testing/selftests/cgroup/test_memcontrol.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,11 @@ static int alloc_anon_50M_check(const char *cgroup, void *arg)
9898
int ret = -1;
9999

100100
buf = malloc(size);
101+
if (buf == NULL) {
102+
fprintf(stderr, "malloc() failed\n");
103+
return -1;
104+
}
105+
101106
for (ptr = buf; ptr < buf + size; ptr += PAGE_SIZE)
102107
*ptr = 0;
103108

@@ -211,6 +216,11 @@ static int alloc_anon_noexit(const char *cgroup, void *arg)
211216
char *buf, *ptr;
212217

213218
buf = malloc(size);
219+
if (buf == NULL) {
220+
fprintf(stderr, "malloc() failed\n");
221+
return -1;
222+
}
223+
214224
for (ptr = buf; ptr < buf + size; ptr += PAGE_SIZE)
215225
*ptr = 0;
216226

@@ -778,6 +788,11 @@ static int alloc_anon_50M_check_swap(const char *cgroup, void *arg)
778788
int ret = -1;
779789

780790
buf = malloc(size);
791+
if (buf == NULL) {
792+
fprintf(stderr, "malloc() failed\n");
793+
return -1;
794+
}
795+
781796
for (ptr = buf; ptr < buf + size; ptr += PAGE_SIZE)
782797
*ptr = 0;
783798

tools/testing/selftests/kselftest.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,13 @@
4343
#ifndef __KSELFTEST_H
4444
#define __KSELFTEST_H
4545

46+
#ifndef NOLIBC
4647
#include <errno.h>
4748
#include <stdlib.h>
4849
#include <unistd.h>
4950
#include <stdarg.h>
5051
#include <stdio.h>
52+
#endif
5153

5254
#ifndef ARRAY_SIZE
5355
#define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))

tools/testing/selftests/prctl/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@
22
disable-tsc-ctxt-sw-stress-test
33
disable-tsc-on-off-stress-test
44
disable-tsc-test
5+
set-anon-vma-name-test

tools/testing/selftests/prctl/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ ARCH ?= $(shell echo $(uname_M) | sed -e s/i.86/x86/ -e s/x86_64/x86/)
55

66
ifeq ($(ARCH),x86)
77
TEST_PROGS := disable-tsc-ctxt-sw-stress-test disable-tsc-on-off-stress-test \
8-
disable-tsc-test
8+
disable-tsc-test set-anon-vma-name-test
99
all: $(TEST_PROGS)
1010

1111
include ../lib.mk

tools/testing/selftests/prctl/config

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
CONFIG_ANON_VMA_NAME=y
Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
// SPDX-License-Identifier: GPL-2.0
2+
/*
3+
* This test covers the anonymous VMA naming functionality through prctl calls
4+
*/
5+
6+
#include <errno.h>
7+
#include <sys/prctl.h>
8+
#include <stdio.h>
9+
#include <stdlib.h>
10+
#include <sys/mman.h>
11+
#include <string.h>
12+
13+
#include "../kselftest_harness.h"
14+
15+
#define AREA_SIZE 1024
16+
17+
#define GOOD_NAME "goodname"
18+
#define BAD_NAME "badname\1"
19+
20+
#ifndef PR_SET_VMA
21+
#define PR_SET_VMA 0x53564d41
22+
#define PR_SET_VMA_ANON_NAME 0
23+
#endif
24+
25+
26+
int rename_vma(unsigned long addr, unsigned long size, char *name)
27+
{
28+
int res;
29+
30+
res = prctl(PR_SET_VMA, PR_SET_VMA_ANON_NAME, addr, size, name);
31+
if (res < 0)
32+
return -errno;
33+
return res;
34+
}
35+
36+
int was_renaming_successful(char *target_name, unsigned long ptr)
37+
{
38+
FILE *maps_file;
39+
40+
char line_buf[512], name[128], mode[8];
41+
unsigned long start_addr, end_addr, offset;
42+
unsigned int major_id, minor_id, node_id;
43+
44+
char target_buf[128];
45+
int res = 0, sscanf_res;
46+
47+
// The entry name in maps will be in format [anon:<target_name>]
48+
sprintf(target_buf, "[anon:%s]", target_name);
49+
maps_file = fopen("/proc/self/maps", "r");
50+
if (!maps_file) {
51+
printf("## /proc/self/maps file opening error\n");
52+
return 0;
53+
}
54+
55+
// Parse the maps file to find the entry we renamed
56+
while (fgets(line_buf, sizeof(line_buf), maps_file)) {
57+
sscanf_res = sscanf(line_buf, "%lx-%lx %7s %lx %u:%u %u %s", &start_addr,
58+
&end_addr, mode, &offset, &major_id,
59+
&minor_id, &node_id, name);
60+
if (sscanf_res == EOF) {
61+
res = 0;
62+
printf("## EOF while parsing the maps file\n");
63+
break;
64+
}
65+
if (!strcmp(name, target_buf) && start_addr == ptr) {
66+
res = 1;
67+
break;
68+
}
69+
}
70+
fclose(maps_file);
71+
return res;
72+
}
73+
74+
FIXTURE(vma) {
75+
void *ptr_anon, *ptr_not_anon;
76+
};
77+
78+
FIXTURE_SETUP(vma) {
79+
self->ptr_anon = mmap(NULL, AREA_SIZE, PROT_READ | PROT_WRITE,
80+
MAP_PRIVATE | MAP_ANONYMOUS, 0, 0);
81+
ASSERT_NE(self->ptr_anon, NULL);
82+
self->ptr_not_anon = mmap(NULL, AREA_SIZE, PROT_READ | PROT_WRITE,
83+
MAP_PRIVATE, 0, 0);
84+
ASSERT_NE(self->ptr_not_anon, NULL);
85+
}
86+
87+
FIXTURE_TEARDOWN(vma) {
88+
munmap(self->ptr_anon, AREA_SIZE);
89+
munmap(self->ptr_not_anon, AREA_SIZE);
90+
}
91+
92+
TEST_F(vma, renaming) {
93+
TH_LOG("Try to rename the VMA with correct parameters");
94+
EXPECT_GE(rename_vma((unsigned long)self->ptr_anon, AREA_SIZE, GOOD_NAME), 0);
95+
EXPECT_TRUE(was_renaming_successful(GOOD_NAME, (unsigned long)self->ptr_anon));
96+
97+
TH_LOG("Try to pass invalid name (with non-printable character \\1) to rename the VMA");
98+
EXPECT_EQ(rename_vma((unsigned long)self->ptr_anon, AREA_SIZE, BAD_NAME), -EINVAL);
99+
100+
TH_LOG("Try to rename non-anonynous VMA");
101+
EXPECT_EQ(rename_vma((unsigned long) self->ptr_not_anon, AREA_SIZE, GOOD_NAME), -EINVAL);
102+
}
103+
104+
TEST_HARNESS_MAIN

0 commit comments

Comments
 (0)