Skip to content

Commit c31dbb1

Browse files
lmbborkmann
authored andcommitted
selftests: bpf: Use a temporary file in test_sockmap
Use a proper temporary file for sendpage tests. This means that running the tests doesn't clutter the working directory, and allows running the test on read-only filesystems. Fixes: 16962b2 ("bpf: sockmap, add selftests") Signed-off-by: Lorenz Bauer <[email protected]> Signed-off-by: Daniel Borkmann <[email protected]> Reviewed-by: Jakub Sitnicki <[email protected]> Acked-by: Martin KaFai Lau <[email protected]> Acked-by: John Fastabend <[email protected]> Link: https://lore.kernel.org/bpf/[email protected]
1 parent 4125828 commit c31dbb1

File tree

1 file changed

+5
-10
lines changed

1 file changed

+5
-10
lines changed

tools/testing/selftests/bpf/test_sockmap.c

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,7 @@ static int msg_loop_sendpage(int fd, int iov_length, int cnt,
331331
FILE *file;
332332
int i, fp;
333333

334-
file = fopen(".sendpage_tst.tmp", "w+");
334+
file = tmpfile();
335335
if (!file) {
336336
perror("create file for sendpage");
337337
return 1;
@@ -340,33 +340,28 @@ static int msg_loop_sendpage(int fd, int iov_length, int cnt,
340340
fwrite(&k, sizeof(char), 1, file);
341341
fflush(file);
342342
fseek(file, 0, SEEK_SET);
343-
fclose(file);
344343

345-
fp = open(".sendpage_tst.tmp", O_RDONLY);
346-
if (fp < 0) {
347-
perror("reopen file for sendpage");
348-
return 1;
349-
}
344+
fp = fileno(file);
350345

351346
clock_gettime(CLOCK_MONOTONIC, &s->start);
352347
for (i = 0; i < cnt; i++) {
353348
int sent = sendfile(fd, fp, NULL, iov_length);
354349

355350
if (!drop && sent < 0) {
356351
perror("send loop error");
357-
close(fp);
352+
fclose(file);
358353
return sent;
359354
} else if (drop && sent >= 0) {
360355
printf("sendpage loop error expected: %i\n", sent);
361-
close(fp);
356+
fclose(file);
362357
return -EIO;
363358
}
364359

365360
if (sent > 0)
366361
s->bytes_sent += sent;
367362
}
368363
clock_gettime(CLOCK_MONOTONIC, &s->end);
369-
close(fp);
364+
fclose(file);
370365
return 0;
371366
}
372367

0 commit comments

Comments
 (0)