All of lore.kernel.org
 help / color / mirror / Atom feed
* [LTP] [PATCH 1/2] syscalls/sync_file_range: add partial file sync test-case
@ 2019-03-01  8:28 Sumit Garg
  2019-03-01  8:28 ` [LTP] [PATCH 2/2] doc: document new library functions Sumit Garg
  2019-03-04 14:40 ` [LTP] [PATCH 1/2] syscalls/sync_file_range: add partial file sync test-case Cyril Hrubis
  0 siblings, 2 replies; 5+ messages in thread
From: Sumit Garg @ 2019-03-01  8:28 UTC (permalink / raw)
  To: ltp

Add partial file sync test as part of sync_file_range02 test-case.

Signed-off-by: Sumit Garg <sumit.garg@linaro.org>
---
 .../syscalls/sync_file_range/sync_file_range02.c   | 49 +++++++++++++++++++++-
 1 file changed, 47 insertions(+), 2 deletions(-)

diff --git a/testcases/kernel/syscalls/sync_file_range/sync_file_range02.c b/testcases/kernel/syscalls/sync_file_range/sync_file_range02.c
index 82d77f7..23240c0 100644
--- a/testcases/kernel/syscalls/sync_file_range/sync_file_range02.c
+++ b/testcases/kernel/syscalls/sync_file_range/sync_file_range02.c
@@ -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,
 };
-- 
2.7.4


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [LTP] [PATCH 2/2] doc: document new library functions
  2019-03-01  8:28 [LTP] [PATCH 1/2] syscalls/sync_file_range: add partial file sync test-case Sumit Garg
@ 2019-03-01  8:28 ` Sumit Garg
  2019-03-01 15:54   ` Cyril Hrubis
  2019-03-04 14:40 ` [LTP] [PATCH 1/2] syscalls/sync_file_range: add partial file sync test-case Cyril Hrubis
  1 sibling, 1 reply; 5+ messages in thread
From: Sumit Garg @ 2019-03-01  8:28 UTC (permalink / raw)
  To: ltp

Document following library functions:
1. tst_fill_file()
2. tst_fill_fd()
3. tst_dev_bytes_written()

Signed-off-by: Sumit Garg <sumit.garg@linaro.org>
---
 doc/test-writing-guidelines.txt | 28 ++++++++++++++++++++++++++++
 1 file changed, 28 insertions(+)

diff --git a/doc/test-writing-guidelines.txt b/doc/test-writing-guidelines.txt
index f2f72c4..a5fe589 100644
--- a/doc/test-writing-guidelines.txt
+++ b/doc/test-writing-guidelines.txt
@@ -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
 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
 
-- 
2.7.4


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [LTP] [PATCH 2/2] doc: document new library functions
  2019-03-01  8:28 ` [LTP] [PATCH 2/2] doc: document new library functions Sumit Garg
@ 2019-03-01 15:54   ` Cyril Hrubis
  0 siblings, 0 replies; 5+ messages in thread
From: Cyril Hrubis @ 2019-03-01 15:54 UTC (permalink / raw)
  To: ltp

Hi!
Pushed, thanks.

-- 
Cyril Hrubis
chrubis@suse.cz

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [LTP] [PATCH 1/2] syscalls/sync_file_range: add partial file sync test-case
  2019-03-01  8:28 [LTP] [PATCH 1/2] syscalls/sync_file_range: add partial file sync test-case Sumit Garg
  2019-03-01  8:28 ` [LTP] [PATCH 2/2] doc: document new library functions Sumit Garg
@ 2019-03-04 14:40 ` Cyril Hrubis
  2019-03-05  6:35   ` Sumit Garg
  1 sibling, 1 reply; 5+ messages in thread
From: Cyril Hrubis @ 2019-03-04 14:40 UTC (permalink / raw)
  To: ltp

Hi!
> +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.

-- 
Cyril Hrubis
chrubis@suse.cz

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [LTP] [PATCH 1/2] syscalls/sync_file_range: add partial file sync test-case
  2019-03-04 14:40 ` [LTP] [PATCH 1/2] syscalls/sync_file_range: add partial file sync test-case Cyril Hrubis
@ 2019-03-05  6:35   ` Sumit Garg
  0 siblings, 0 replies; 5+ messages in thread
From: Sumit Garg @ 2019-03-05  6:35 UTC (permalink / raw)
  To: ltp

On Mon, 4 Mar 2019 at 20:10, Cyril Hrubis <chrubis@suse.cz> wrote:
>
> Hi!
> > +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% ?
>

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

> Other than that the patch looks good.
>
> --
> Cyril Hrubis
> chrubis@suse.cz

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2019-03-05  6:35 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-03-01  8:28 [LTP] [PATCH 1/2] syscalls/sync_file_range: add partial file sync test-case Sumit Garg
2019-03-01  8:28 ` [LTP] [PATCH 2/2] doc: document new library functions Sumit Garg
2019-03-01 15:54   ` Cyril Hrubis
2019-03-04 14:40 ` [LTP] [PATCH 1/2] syscalls/sync_file_range: add partial file sync test-case Cyril Hrubis
2019-03-05  6:35   ` Sumit Garg

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.