File tree Expand file tree Collapse file tree 5 files changed +64
-40
lines changed
tools/testing/selftests/memfd Expand file tree Collapse file tree 5 files changed +64
-40
lines changed Original file line number Diff line number Diff line change @@ -12,3 +12,8 @@ fuse_mnt.o: CFLAGS += $(shell pkg-config fuse --cflags)
12
12
include ../lib.mk
13
13
14
14
$(OUTPUT ) /fuse_mnt : LDLIBS += $(shell pkg-config fuse --libs)
15
+
16
+ $(OUTPUT ) /memfd_test : memfd_test.c common.o
17
+ $(OUTPUT ) /fuse_test : fuse_test.c common.o
18
+
19
+ EXTRA_CLEAN = common.o
Original file line number Diff line number Diff line change
1
+ // SPDX-License-Identifier: GPL-2.0
2
+ #define _GNU_SOURCE
3
+ #define __EXPORTED_HEADERS__
4
+
5
+ #include <stdio.h>
6
+ #include <stdlib.h>
7
+ #include <linux/fcntl.h>
8
+ #include <linux/memfd.h>
9
+ #include <unistd.h>
10
+ #include <sys/syscall.h>
11
+
12
+ #include "common.h"
13
+
14
+ int hugetlbfs_test = 0 ;
15
+
16
+ /*
17
+ * Copied from mlock2-tests.c
18
+ */
19
+ unsigned long default_huge_page_size (void )
20
+ {
21
+ unsigned long hps = 0 ;
22
+ char * line = NULL ;
23
+ size_t linelen = 0 ;
24
+ FILE * f = fopen ("/proc/meminfo" , "r" );
25
+
26
+ if (!f )
27
+ return 0 ;
28
+ while (getline (& line , & linelen , f ) > 0 ) {
29
+ if (sscanf (line , "Hugepagesize: %lu kB" , & hps ) == 1 ) {
30
+ hps <<= 10 ;
31
+ break ;
32
+ }
33
+ }
34
+
35
+ free (line );
36
+ fclose (f );
37
+ return hps ;
38
+ }
39
+
40
+ int sys_memfd_create (const char * name , unsigned int flags )
41
+ {
42
+ if (hugetlbfs_test )
43
+ flags |= MFD_HUGETLB ;
44
+
45
+ return syscall (__NR_memfd_create , name , flags );
46
+ }
Original file line number Diff line number Diff line change
1
+ #ifndef COMMON_H_
2
+ #define COMMON_H_
3
+
4
+ extern int hugetlbfs_test ;
5
+
6
+ unsigned long default_huge_page_size (void );
7
+ int sys_memfd_create (const char * name , unsigned int flags );
8
+
9
+ #endif
Original file line number Diff line number Diff line change 33
33
#include <sys/wait.h>
34
34
#include <unistd.h>
35
35
36
+ #include "common.h"
37
+
36
38
#define MFD_DEF_SIZE 8192
37
39
#define STACK_SIZE 65536
38
40
39
- static int sys_memfd_create (const char * name ,
40
- unsigned int flags )
41
- {
42
- return syscall (__NR_memfd_create , name , flags );
43
- }
44
-
45
41
static int mfd_assert_new (const char * name , loff_t sz , unsigned int flags )
46
42
{
47
43
int r , fd ;
Original file line number Diff line number Diff line change 19
19
#include <sys/wait.h>
20
20
#include <unistd.h>
21
21
22
+ #include "common.h"
23
+
22
24
#define MEMFD_STR "memfd:"
23
25
#define MEMFD_HUGE_STR "memfd-hugetlb:"
24
26
#define SHARED_FT_STR "(shared file-table)"
29
31
/*
30
32
* Default is not to test hugetlbfs
31
33
*/
32
- static int hugetlbfs_test ;
33
34
static size_t mfd_def_size = MFD_DEF_SIZE ;
34
35
static const char * memfd_str = MEMFD_STR ;
35
36
36
- /*
37
- * Copied from mlock2-tests.c
38
- */
39
- static unsigned long default_huge_page_size (void )
40
- {
41
- unsigned long hps = 0 ;
42
- char * line = NULL ;
43
- size_t linelen = 0 ;
44
- FILE * f = fopen ("/proc/meminfo" , "r" );
45
-
46
- if (!f )
47
- return 0 ;
48
- while (getline (& line , & linelen , f ) > 0 ) {
49
- if (sscanf (line , "Hugepagesize: %lu kB" , & hps ) == 1 ) {
50
- hps <<= 10 ;
51
- break ;
52
- }
53
- }
54
-
55
- free (line );
56
- fclose (f );
57
- return hps ;
58
- }
59
-
60
- static int sys_memfd_create (const char * name ,
61
- unsigned int flags )
62
- {
63
- if (hugetlbfs_test )
64
- flags |= MFD_HUGETLB ;
65
-
66
- return syscall (__NR_memfd_create , name , flags );
67
- }
68
-
69
37
static int mfd_assert_new (const char * name , loff_t sz , unsigned int flags )
70
38
{
71
39
int r , fd ;
You can’t perform that action at this time.
0 commit comments