Skip to content

Commit 8021509

Browse files
committed
Merge tag 'linux-kselftest-next-5.12-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/shuah/linux-kselftest
Pull Kselftest updates from Shuah Khan: - dmabuf-heaps test fixes and cleanups from John Stultz - seccomp test fix to accept any valid fd in user_notification_addfd - Minor fixes to breakpoints and vDSO tests - Minor code cleanups to ipc and x86 tests * tag 'linux-kselftest-next-5.12-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/shuah/linux-kselftest: selftests/seccomp: Accept any valid fd in user_notification_addfd selftests/timens: add futex binary to .gitignore selftests: breakpoints: Use correct error messages in breakpoint_test_arm64.c selftests/vDSO: fix ABI selftest on riscv selftests/x86/ldt_gdt: remove unneeded semicolon selftests/ipc: remove unneeded semicolon kselftests: dmabuf-heaps: Add extra checking that allocated buffers are zeroed kselftests: dmabuf-heaps: Cleanup test output kselftests: dmabuf-heaps: Softly fail if don't find a vgem device kselftests: dmabuf-heaps: Add clearer checks on DMABUF_BEGIN/END_SYNC kselftests: dmabuf-heaps: Fix Makefile's inclusion of the kernel's usr/include dir
2 parents 0e63a5c + e0c0840 commit 8021509

File tree

8 files changed

+132
-44
lines changed

8 files changed

+132
-44
lines changed

tools/testing/selftests/breakpoints/breakpoint_test_arm64.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ static bool run_test(int wr_size, int wp_size, int wr, int wp)
145145

146146
if (ptrace(PTRACE_CONT, pid, NULL, NULL) < 0) {
147147
ksft_print_msg(
148-
"ptrace(PTRACE_SINGLESTEP) failed: %s\n",
148+
"ptrace(PTRACE_CONT) failed: %s\n",
149149
strerror(errno));
150150
return false;
151151
}
@@ -159,7 +159,7 @@ static bool run_test(int wr_size, int wp_size, int wr, int wp)
159159
}
160160
alarm(0);
161161
if (WIFEXITED(status)) {
162-
ksft_print_msg("child did not single-step\n");
162+
ksft_print_msg("child exited prematurely\n");
163163
return false;
164164
}
165165
if (!WIFSTOPPED(status)) {

tools/testing/selftests/dmabuf-heaps/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# SPDX-License-Identifier: GPL-2.0
2-
CFLAGS += -static -O3 -Wl,-no-as-needed -Wall -I../../../../usr/include
2+
CFLAGS += -static -O3 -Wl,-no-as-needed -Wall
33

44
TEST_GEN_PROGS = dmabuf-heap
55

tools/testing/selftests/dmabuf-heaps/dmabuf-heap.c

Lines changed: 119 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -130,16 +130,13 @@ static int dmabuf_heap_alloc(int fd, size_t len, unsigned int flags,
130130
dmabuf_fd);
131131
}
132132

133-
static void dmabuf_sync(int fd, int start_stop)
133+
static int dmabuf_sync(int fd, int start_stop)
134134
{
135135
struct dma_buf_sync sync = {
136136
.flags = start_stop | DMA_BUF_SYNC_RW,
137137
};
138-
int ret;
139138

140-
ret = ioctl(fd, DMA_BUF_IOCTL_SYNC, &sync);
141-
if (ret)
142-
printf("sync failed %d\n", errno);
139+
return ioctl(fd, DMA_BUF_IOCTL_SYNC, &sync);
143140
}
144141

145142
#define ONE_MEG (1024 * 1024)
@@ -151,16 +148,14 @@ static int test_alloc_and_import(char *heap_name)
151148
void *p = NULL;
152149
int ret;
153150

154-
printf("Testing heap: %s\n", heap_name);
155-
156151
heap_fd = dmabuf_heap_open(heap_name);
157152
if (heap_fd < 0)
158153
return -1;
159154

160-
printf("Allocating 1 MEG\n");
155+
printf(" Testing allocation and importing: ");
161156
ret = dmabuf_heap_alloc(heap_fd, ONE_MEG, 0, &dmabuf_fd);
162157
if (ret) {
163-
printf("Allocation Failed!\n");
158+
printf("FAIL (Allocation Failed!)\n");
164159
ret = -1;
165160
goto out;
166161
}
@@ -172,11 +167,10 @@ static int test_alloc_and_import(char *heap_name)
172167
dmabuf_fd,
173168
0);
174169
if (p == MAP_FAILED) {
175-
printf("mmap() failed: %m\n");
170+
printf("FAIL (mmap() failed)\n");
176171
ret = -1;
177172
goto out;
178173
}
179-
printf("mmap passed\n");
180174

181175
dmabuf_sync(dmabuf_fd, DMA_BUF_SYNC_START);
182176
memset(p, 1, ONE_MEG / 2);
@@ -186,25 +180,31 @@ static int test_alloc_and_import(char *heap_name)
186180
importer_fd = open_vgem();
187181
if (importer_fd < 0) {
188182
ret = importer_fd;
189-
printf("Failed to open vgem\n");
190-
goto out;
183+
printf("(Could not open vgem - skipping): ");
184+
} else {
185+
ret = import_vgem_fd(importer_fd, dmabuf_fd, &handle);
186+
if (ret < 0) {
187+
printf("FAIL (Failed to import buffer)\n");
188+
goto out;
189+
}
191190
}
192191

193-
ret = import_vgem_fd(importer_fd, dmabuf_fd, &handle);
192+
ret = dmabuf_sync(dmabuf_fd, DMA_BUF_SYNC_START);
194193
if (ret < 0) {
195-
printf("Failed to import buffer\n");
194+
printf("FAIL (DMA_BUF_SYNC_START failed!)\n");
196195
goto out;
197196
}
198-
printf("import passed\n");
199197

200-
dmabuf_sync(dmabuf_fd, DMA_BUF_SYNC_START);
201198
memset(p, 0xff, ONE_MEG);
202-
dmabuf_sync(dmabuf_fd, DMA_BUF_SYNC_END);
203-
printf("syncs passed\n");
199+
ret = dmabuf_sync(dmabuf_fd, DMA_BUF_SYNC_END);
200+
if (ret < 0) {
201+
printf("FAIL (DMA_BUF_SYNC_END failed!)\n");
202+
goto out;
203+
}
204204

205205
close_handle(importer_fd, handle);
206206
ret = 0;
207-
207+
printf(" OK\n");
208208
out:
209209
if (p)
210210
munmap(p, ONE_MEG);
@@ -218,6 +218,84 @@ static int test_alloc_and_import(char *heap_name)
218218
return ret;
219219
}
220220

221+
static int test_alloc_zeroed(char *heap_name, size_t size)
222+
{
223+
int heap_fd = -1, dmabuf_fd[32];
224+
int i, j, ret;
225+
void *p = NULL;
226+
char *c;
227+
228+
printf(" Testing alloced %ldk buffers are zeroed: ", size / 1024);
229+
heap_fd = dmabuf_heap_open(heap_name);
230+
if (heap_fd < 0)
231+
return -1;
232+
233+
/* Allocate and fill a bunch of buffers */
234+
for (i = 0; i < 32; i++) {
235+
ret = dmabuf_heap_alloc(heap_fd, size, 0, &dmabuf_fd[i]);
236+
if (ret < 0) {
237+
printf("FAIL (Allocation (%i) failed)\n", i);
238+
goto out;
239+
}
240+
/* mmap and fill with simple pattern */
241+
p = mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_SHARED, dmabuf_fd[i], 0);
242+
if (p == MAP_FAILED) {
243+
printf("FAIL (mmap() failed!)\n");
244+
ret = -1;
245+
goto out;
246+
}
247+
dmabuf_sync(dmabuf_fd[i], DMA_BUF_SYNC_START);
248+
memset(p, 0xff, size);
249+
dmabuf_sync(dmabuf_fd[i], DMA_BUF_SYNC_END);
250+
munmap(p, size);
251+
}
252+
/* close them all */
253+
for (i = 0; i < 32; i++)
254+
close(dmabuf_fd[i]);
255+
256+
/* Allocate and validate all buffers are zeroed */
257+
for (i = 0; i < 32; i++) {
258+
ret = dmabuf_heap_alloc(heap_fd, size, 0, &dmabuf_fd[i]);
259+
if (ret < 0) {
260+
printf("FAIL (Allocation (%i) failed)\n", i);
261+
goto out;
262+
}
263+
264+
/* mmap and validate everything is zero */
265+
p = mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_SHARED, dmabuf_fd[i], 0);
266+
if (p == MAP_FAILED) {
267+
printf("FAIL (mmap() failed!)\n");
268+
ret = -1;
269+
goto out;
270+
}
271+
dmabuf_sync(dmabuf_fd[i], DMA_BUF_SYNC_START);
272+
c = (char *)p;
273+
for (j = 0; j < size; j++) {
274+
if (c[j] != 0) {
275+
printf("FAIL (Allocated buffer not zeroed @ %i)\n", j);
276+
break;
277+
}
278+
}
279+
dmabuf_sync(dmabuf_fd[i], DMA_BUF_SYNC_END);
280+
munmap(p, size);
281+
}
282+
/* close them all */
283+
for (i = 0; i < 32; i++)
284+
close(dmabuf_fd[i]);
285+
286+
close(heap_fd);
287+
printf("OK\n");
288+
return 0;
289+
290+
out:
291+
while (i > 0) {
292+
close(dmabuf_fd[i]);
293+
i--;
294+
}
295+
close(heap_fd);
296+
return ret;
297+
}
298+
221299
/* Test the ioctl version compatibility w/ a smaller structure then expected */
222300
static int dmabuf_heap_alloc_older(int fd, size_t len, unsigned int flags,
223301
int *dmabuf_fd)
@@ -292,23 +370,24 @@ static int test_alloc_compat(char *heap_name)
292370
if (heap_fd < 0)
293371
return -1;
294372

295-
printf("Testing (theoretical)older alloc compat\n");
373+
printf(" Testing (theoretical)older alloc compat: ");
296374
ret = dmabuf_heap_alloc_older(heap_fd, ONE_MEG, 0, &dmabuf_fd);
297375
if (ret) {
298-
printf("Older compat allocation failed!\n");
376+
printf("FAIL (Older compat allocation failed!)\n");
299377
ret = -1;
300378
goto out;
301379
}
302380
close(dmabuf_fd);
381+
printf("OK\n");
303382

304-
printf("Testing (theoretical)newer alloc compat\n");
383+
printf(" Testing (theoretical)newer alloc compat: ");
305384
ret = dmabuf_heap_alloc_newer(heap_fd, ONE_MEG, 0, &dmabuf_fd);
306385
if (ret) {
307-
printf("Newer compat allocation failed!\n");
386+
printf("FAIL (Newer compat allocation failed!)\n");
308387
ret = -1;
309388
goto out;
310389
}
311-
printf("Ioctl compatibility tests passed\n");
390+
printf("OK\n");
312391
out:
313392
if (dmabuf_fd >= 0)
314393
close(dmabuf_fd);
@@ -327,30 +406,30 @@ static int test_alloc_errors(char *heap_name)
327406
if (heap_fd < 0)
328407
return -1;
329408

330-
printf("Testing expected error cases\n");
409+
printf(" Testing expected error cases: ");
331410
ret = dmabuf_heap_alloc(0, ONE_MEG, 0x111111, &dmabuf_fd);
332411
if (!ret) {
333-
printf("Did not see expected error (invalid fd)!\n");
412+
printf("FAIL (Did not see expected error (invalid fd)!)\n");
334413
ret = -1;
335414
goto out;
336415
}
337416

338417
ret = dmabuf_heap_alloc(heap_fd, ONE_MEG, 0x111111, &dmabuf_fd);
339418
if (!ret) {
340-
printf("Did not see expected error (invalid heap flags)!\n");
419+
printf("FAIL (Did not see expected error (invalid heap flags)!)\n");
341420
ret = -1;
342421
goto out;
343422
}
344423

345424
ret = dmabuf_heap_alloc_fdflags(heap_fd, ONE_MEG,
346425
~(O_RDWR | O_CLOEXEC), 0, &dmabuf_fd);
347426
if (!ret) {
348-
printf("Did not see expected error (invalid fd flags)!\n");
427+
printf("FAIL (Did not see expected error (invalid fd flags)!)\n");
349428
ret = -1;
350429
goto out;
351430
}
352431

353-
printf("Expected error checking passed\n");
432+
printf("OK\n");
354433
ret = 0;
355434
out:
356435
if (dmabuf_fd >= 0)
@@ -379,10 +458,20 @@ int main(void)
379458
if (!strncmp(dir->d_name, "..", 3))
380459
continue;
381460

461+
printf("Testing heap: %s\n", dir->d_name);
462+
printf("=======================================\n");
382463
ret = test_alloc_and_import(dir->d_name);
383464
if (ret)
384465
break;
385466

467+
ret = test_alloc_zeroed(dir->d_name, 4 * 1024);
468+
if (ret)
469+
break;
470+
471+
ret = test_alloc_zeroed(dir->d_name, ONE_MEG);
472+
if (ret)
473+
break;
474+
386475
ret = test_alloc_compat(dir->d_name);
387476
if (ret)
388477
break;

tools/testing/selftests/ipc/msgque.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ int restore_queue(struct msgque_data *msgque)
6969
printf("msgsnd failed (%m)\n");
7070
ret = -errno;
7171
goto destroy;
72-
};
72+
}
7373
}
7474
return 0;
7575

@@ -180,15 +180,15 @@ int fill_msgque(struct msgque_data *msgque)
180180
IPC_NOWAIT) != 0) {
181181
printf("First message send failed (%m)\n");
182182
return -errno;
183-
};
183+
}
184184

185185
msgbuf.mtype = ANOTHER_MSG_TYPE;
186186
memcpy(msgbuf.mtext, ANOTHER_TEST_STRING, sizeof(ANOTHER_TEST_STRING));
187187
if (msgsnd(msgque->msq_id, &msgbuf.mtype, sizeof(ANOTHER_TEST_STRING),
188188
IPC_NOWAIT) != 0) {
189189
printf("Second message send failed (%m)\n");
190190
return -errno;
191-
};
191+
}
192192
return 0;
193193
}
194194

tools/testing/selftests/seccomp/seccomp_bpf.c

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4019,18 +4019,14 @@ TEST(user_notification_addfd)
40194019

40204020
/* Verify we can set an arbitrary remote fd */
40214021
fd = ioctl(listener, SECCOMP_IOCTL_NOTIF_ADDFD, &addfd);
4022-
/*
4023-
* The child has fds 0(stdin), 1(stdout), 2(stderr), 3(memfd),
4024-
* 4(listener), so the newly allocated fd should be 5.
4025-
*/
4026-
EXPECT_EQ(fd, 5);
4022+
EXPECT_GE(fd, 0);
40274023
EXPECT_EQ(filecmp(getpid(), pid, memfd, fd), 0);
40284024

40294025
/* Verify we can set an arbitrary remote fd with large size */
40304026
memset(&big, 0x0, sizeof(big));
40314027
big.addfd = addfd;
40324028
fd = ioctl(listener, SECCOMP_IOCTL_NOTIF_ADDFD_BIG, &big);
4033-
EXPECT_EQ(fd, 6);
4029+
EXPECT_GE(fd, 0);
40344030

40354031
/* Verify we can set a specific remote fd */
40364032
addfd.newfd = 42;

tools/testing/selftests/timens/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# SPDX-License-Identifier: GPL-2.0-only
22
clock_nanosleep
33
exec
4+
futex
45
gettime_perf
56
gettime_perf_cold
67
procfs

tools/testing/selftests/vDSO/vdso_config.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,12 @@
4747
#elif defined(__x86_64__)
4848
#define VDSO_VERSION 0
4949
#define VDSO_NAMES 1
50-
#elif defined(__riscv__)
50+
#elif defined(__riscv__) || defined(__riscv)
5151
#define VDSO_VERSION 5
5252
#define VDSO_NAMES 1
53+
#if __riscv_xlen == 32
5354
#define VDSO_32BIT 1
55+
#endif
5456
#else /* nds32 */
5557
#define VDSO_VERSION 4
5658
#define VDSO_NAMES 1

tools/testing/selftests/x86/ldt_gdt.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -607,7 +607,7 @@ static void do_multicpu_tests(void)
607607

608608
failures++;
609609
asm volatile ("mov %0, %%ss" : : "rm" (orig_ss));
610-
};
610+
}
611611

612612
ftx = 100; /* Kill the thread. */
613613
syscall(SYS_futex, &ftx, FUTEX_WAKE, 0, NULL, NULL, 0);

0 commit comments

Comments
 (0)