syscalls/sync_file_range: add partial file sync test-case
PATCH 1/2 syscalls/sync_file_range: add partial file sync test-case
Add partial file sync test as part of sync_file_range02 test-case.
--- .../syscalls/sync_file_range/sync_file_range02.c | 49 +++++++++++++++++++++- 1 file changed, 47 insertions(+), 2 deletions(-)
testcases/kernel/syscalls/sync_file_range/sync_file_range02.c +47 -2
@@ -27,7 +27,7 @@#define FILE_SIZE (FILE_SIZE_MB * TST_MB)#define MODE 0644 -static void verify_sync_file_range (void ) +static void verify_sync_full_file (void ) {int fd;unsigned long written;
@@ -56,6 +56,50 @@ static void verify_sync_file_range(void)tst_res (TFAIL ,"Synced %li, expected %i" , written,FILE_SIZE ); } +static void verify_sync_partial_file (void ) +{ +int fd; +unsigned long written; + + fd =SAFE_OPEN (FNAME ,O_RDWR |O_CREAT ,MODE ); + +lseek (fd,FILE_SIZE /4 ,SEEK_SET ); + +tst_dev_bytes_written (tst_device->dev); + +tst_fill_fd (fd,0xff ,TST_MB ,FILE_SIZE_MB /2 ); + +TEST (sync_file_range (fd,FILE_SIZE /4 ,FILE_SIZE /2 , +SYNC_FILE_RANGE_WAIT_BEFORE | +SYNC_FILE_RANGE_WRITE | +SYNC_FILE_RANGE_WAIT_AFTER )); + +if (TST_RET ) +tst_brk (TFAIL |TTERRNO ,"sync_file_range() failed" ); + + written =tst_dev_bytes_written (tst_device->dev); + +SAFE_CLOSE (fd); + +if (written >=FILE_SIZE /2 ) +tst_res (TPASS ,"Test file range synced to device" ); +else +tst_res (TFAIL ,"Synced %li, expected %i" , written, +FILE_SIZE /2 ); +} + +static struct tcase { +void (*tfunc)(void ); +} tcases[] = { + {&verify_sync_full_file}, + {&verify_sync_partial_file} +}; + +static void run (unsigned int i) +{ + tcases[i].tfunc (); +} +static void setup (void ) {if (!check_sync_file_range ())
@@ -63,10 +107,11 @@ static void setup(void) }static struct tst_test test = { + .tcnt =ARRAY_SIZE (tcases), .needs_root =1 , .mount_device =1 , .all_filesystems =1 , .mntpoint =MNTPOINT , .setup = setup, - .test_all = verify_sync_file_range, + .test = run, };
Signature · 1 line
2.7.4
PATCH 2/2 doc: document new library functions
Document following library functions:
1. tst_fill_file()
2. tst_fill_fd()
3. tst_dev_bytes_written()
--- doc/test-writing-guidelines.txt | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+)
doc/test-writing-guidelines.txt +28 -0
@@ -1033,6 +1033,16 @@ results in 'umount(2)' failing with 'EBUSY'. IMPORTANT: All testcases should use 'tst_umount()' instead of 'umount(2)' to umount filesystems. +[source,c] +------------------------------------------------------------------------------- +#include "tst_test.h" + +unsigned long tst_dev_bytes_written(const char *dev); +------------------------------------------------------------------------------- + +This function reads test block device stat file (/sys/block/<device>/stat) and +returns the bytes written since the last invocation of this function. + 2.2.15 Formatting a device with a filesystem ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -1142,6 +1152,24 @@ Returns non-zero if directory is empty and zero otherwise. Directory is considered empty if it contains only '.' and '..'. +[source,c] +------------------------------------------------------------------------------- +#include "tst_test.h" + +int tst_fill_fd(int fd, char pattern, size_t bs, size_t bcount); +------------------------------------------------------------------------------- + +Fill a file with specified pattern using file descriptor. + +[source,c] +------------------------------------------------------------------------------- +#include "tst_test.h" + +int tst_fill_file(const char *path, char pattern, size_t bs, size_t bcount); +------------------------------------------------------------------------------- + +Creates/ovewrites a file with specified pattern using file path. + 2.2.18 Getting an unused PID number ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Signature · 1 line
2.7.4
PATCH 2/2 doc: document new library functions
Hi!
Pushed, thanks.
Signature · 2 lines
Cyril Hrubis [email protected]
PATCH 1/2 syscalls/sync_file_range: add partial file sync test-case
In reply to Sumit GargHi!
testcases/kernel/syscalls/sync_file_range/sync_file_range02.c static void verify_sync_file_range(void) · line 70
Quoted 12 lines
testcases/kernel/syscalls/sync_file_range/sync_file_range02.c +12
-0+static void verify_sync_partial_file (void ) +{ +int fd; +unsigned long written; + + fd =SAFE_OPEN (FNAME ,O_RDWR |O_CREAT ,MODE ); + +lseek (fd,FILE_SIZE /4 ,SEEK_SET ); + +tst_dev_bytes_written (tst_device->dev); + +tst_fill_fd (fd,0xff ,TST_MB ,FILE_SIZE_MB /2 );
Any reason why we don't do full FILE_SIZE_MB write here and then check that the result was somewhere between FILE_SIZE/2 +-10% ?
Other than that the patch looks good.
Signature · 2 lines
Cyril Hrubis [email protected]
PATCH 1/2 syscalls/sync_file_range: add partial file sync test-case
Quoted 18 lines · Cyril Hrubis
Hi!
testcases/kernel/syscalls/sync_file_range/sync_file_range02.c static void verify_sync_file_range(void) · line 70
Quoted 12 lines
testcases/kernel/syscalls/sync_file_range/sync_file_range02.c +12
-0+static void verify_sync_partial_file (void ) +{ +int fd; +unsigned long written; + + fd =SAFE_OPEN (FNAME ,O_RDWR |O_CREAT ,MODE ); + +lseek (fd,FILE_SIZE /4 ,SEEK_SET ); + +tst_dev_bytes_written (tst_device->dev); + +tst_fill_fd (fd,0xff ,TST_MB ,FILE_SIZE_MB /2 );Any reason why we don't do full
FILE_SIZE_MBwrite here and then check that the result was somewhere between FILE_SIZE/2 +-10% ?
Don't have any compelling reason to not do full file write. So will write whole file and test sync for particular portion of file (FILE_SIZE/4 to 3*FILE_SIZE/4).
-Sumit
Quoted 5 lines
Other than that the patch looks good.
--
Cyril Hrubis
[email protected]