diff mbox series

proc: smoke test lseek()

Message ID YG4OIhChOrVTPgdN@localhost.localdomain (mailing list archive)
State New, archived
Headers show
Series proc: smoke test lseek() | expand

Commit Message

Alexey Dobriyan April 7, 2021, 7:55 p.m. UTC
Now that ->proc_lseek has been made mandatory it would be nice to test
that nothing has been forgotten.

Signed-off-by: Alexey Dobriyan <adobriyan@gmail.com>
---

		May want to fold into
	proc-mandate-proc_lseek-in-struct-proc_ops.patch

 tools/testing/selftests/proc/read.c |    4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

Comments

Matthew Wilcox April 7, 2021, 7:58 p.m. UTC | #1
On Wed, Apr 07, 2021 at 10:55:14PM +0300, Alexey Dobriyan wrote:
> Now that ->proc_lseek has been made mandatory it would be nice to test
> that nothing has been forgotten.

> @@ -45,6 +45,8 @@ static void f_reg(DIR *d, const char *filename)
>  	fd = openat(dirfd(d), filename, O_RDONLY|O_NONBLOCK);
>  	if (fd == -1)
>  		return;
> +	/* struct proc_ops::proc_lseek is mandatory if file is seekable. */
> +	(void)lseek(fd, 0, SEEK_SET);
>  	rv = read(fd, buf, sizeof(buf));
>  	assert((0 <= rv && rv <= sizeof(buf)) || rv == -1);
>  	close(fd);

why throw away the return value?  if it returns an error seeking to
offset 0, something is terribly wrong.
Alexey Dobriyan April 7, 2021, 8:06 p.m. UTC | #2
On Wed, Apr 07, 2021 at 08:58:09PM +0100, Matthew Wilcox wrote:
> On Wed, Apr 07, 2021 at 10:55:14PM +0300, Alexey Dobriyan wrote:
> > Now that ->proc_lseek has been made mandatory it would be nice to test
> > that nothing has been forgotten.
> 
> > @@ -45,6 +45,8 @@ static void f_reg(DIR *d, const char *filename)
> >  	fd = openat(dirfd(d), filename, O_RDONLY|O_NONBLOCK);
> >  	if (fd == -1)
> >  		return;
> > +	/* struct proc_ops::proc_lseek is mandatory if file is seekable. */
> > +	(void)lseek(fd, 0, SEEK_SET);
> >  	rv = read(fd, buf, sizeof(buf));
> >  	assert((0 <= rv && rv <= sizeof(buf)) || rv == -1);
> >  	close(fd);
> 
> why throw away the return value?  if it returns an error seeking to
> offset 0, something is terribly wrong.

Some files may use nonseekable_open().
This smoke test doesn't verify that seeking is done correctly anyway.
diff mbox series

Patch

--- a/tools/testing/selftests/proc/read.c
+++ b/tools/testing/selftests/proc/read.c
@@ -14,7 +14,7 @@ 
  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  */
 // Test
-// 1) read of every file in /proc
+// 1) read and lseek on every file in /proc
 // 2) readlink of every symlink in /proc
 // 3) recursively (1) + (2) for every directory in /proc
 // 4) write to /proc/*/clear_refs and /proc/*/task/*/clear_refs
@@ -45,6 +45,8 @@  static void f_reg(DIR *d, const char *filename)
 	fd = openat(dirfd(d), filename, O_RDONLY|O_NONBLOCK);
 	if (fd == -1)
 		return;
+	/* struct proc_ops::proc_lseek is mandatory if file is seekable. */
+	(void)lseek(fd, 0, SEEK_SET);
 	rv = read(fd, buf, sizeof(buf));
 	assert((0 <= rv && rv <= sizeof(buf)) || rv == -1);
 	close(fd);