File tree Expand file tree Collapse file tree 2 files changed +32
-0
lines changed Expand file tree Collapse file tree 2 files changed +32
-0
lines changed Original file line number Diff line number Diff line change @@ -82,3 +82,13 @@ mod test_statfs;
82
82
target_os = "haiku"
83
83
) ) ) ]
84
84
mod test_resource;
85
+
86
+ // This test module should be enabled for both linux_android and freebsd, but
87
+ // the `memfd_create(2)` symbol is not available under Linux QEMU,
88
+ //
89
+ // https://github.com/nix-rust/nix/actions/runs/9427112650/job/25970870477
90
+ //
91
+ // and I haven't found a way to stop the linker from linking that symbol, so
92
+ // only enable this for FreeBSD for now.
93
+ #[ cfg( target_os = "freebsd" ) ]
94
+ mod test_memfd;
Original file line number Diff line number Diff line change
1
+ #[ test]
2
+ fn test_memfd_create ( ) {
3
+ use nix:: sys:: memfd:: memfd_create;
4
+ use nix:: sys:: memfd:: MemFdCreateFlag ;
5
+ use nix:: unistd:: lseek;
6
+ use nix:: unistd:: read;
7
+ use nix:: unistd:: { write, Whence } ;
8
+ use std:: os:: fd:: { AsFd , AsRawFd } ;
9
+
10
+ let fd =
11
+ memfd_create ( "test_memfd_create_name" , MemFdCreateFlag :: MFD_CLOEXEC )
12
+ . unwrap ( ) ;
13
+ let contents = b"hello" ;
14
+ assert_eq ! ( write( fd. as_fd( ) , contents) . unwrap( ) , 5 ) ;
15
+
16
+ lseek ( fd. as_raw_fd ( ) , 0 , Whence :: SeekSet ) . unwrap ( ) ;
17
+
18
+ let mut buf = vec ! [ 0_u8 ; contents. len( ) ] ;
19
+ assert_eq ! ( read( fd. as_raw_fd( ) , & mut buf) . unwrap( ) , 5 ) ;
20
+
21
+ assert_eq ! ( contents, buf. as_slice( ) ) ;
22
+ }
You can’t perform that action at this time.
0 commit comments