From 724f7c734b5484116aefb9f055d6303204c7be8b Mon Sep 17 00:00:00 2001 From: Sanchayan Maity Date: Sat, 7 Oct 2017 19:13:22 +0530 Subject: Add test for 'fallocate' --- test/test_fcntl.rs | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/test/test_fcntl.rs b/test/test_fcntl.rs index 43bfc091..d171b91d 100644 --- a/test/test_fcntl.rs +++ b/test/test_fcntl.rs @@ -54,11 +54,11 @@ mod linux_android { use libc::loff_t; - use nix::fcntl::{SpliceFFlags, splice, tee, vmsplice}; + use nix::fcntl::{SpliceFFlags, FallocateFlags, fallocate, splice, tee, vmsplice}; use nix::sys::uio::IoVec; use nix::unistd::{close, pipe, read, write}; - use tempfile::tempfile; + use tempfile::{tempfile, NamedTempFile}; #[test] fn test_splice() { @@ -131,4 +131,15 @@ mod linux_android { close(wr).unwrap(); } + #[test] + fn test_fallocate() { + let tmp = NamedTempFile::new().unwrap(); + + let fd = tmp.as_raw_fd(); + fallocate(fd, FallocateFlags::empty(), 0, 100).unwrap(); + + // Check if we read exactly 100 bytes + let mut buf = [0u8; 200]; + assert_eq!(100, read(fd, &mut buf).unwrap()); + } } -- cgit v1.2.3