syscall/read: add new testcase for read
PATCH 1/1 syscall/read: add new testcase for read
Check the return value of read
1. Count bytes are read from the current file
2. Current offset is modified by lseek()
3. Count bytes are read from the current file
Signed-off-by Lucas Boehm <[email protected]>
--- testcases/kernel/syscalls/read/read05.c | 76 +++++++++++++++++++++++++++++++++ 1 file changed, 76 insertions(+) create mode 100644 testcases/kernel/syscalls/read/read05.c
testcases/kernel/syscalls/read/read05.c new file +76 -0
@@ -0,0 +1,76 @@ +/* +* Copyright (c) 2017 Lucas Boehm <[email protected]> +* +* This program is free software: you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation, either version 2 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program. If not, see <http://www.gnu.org/licenses/>. +*/ + +/* Check the return value of read +* +* 1. Count bytes are read from the current file +* 2. Current offset is modified by lseek() +* 3. Return value equals read +*/ + +#include <errno.h> +#include "tst_test.h" +#include <stdio.h> + +#define SIZE 512 + +static int fd; +static char buf[SIZE ]; +int pos; + +static void verify_read (void ) +{ +SAFE_LSEEK (fd,0 ,SEEK_SET ); + +TEST (read (fd, buf,SIZE /2 )); + +if (TEST_RETURN ==-1 ) +tst_res (TFAIL |TTERRNO ,"read(2) failed" ); +else +tst_res (TPASS ,"read(2) returned %ld" ,TEST_RETURN ); + + +SAFE_LSEEK (fd,2 ,SEEK_CUR ); + +TEST (read (fd, buf,SIZE /2 )); + + +if (TEST_RETURN ==-1 ) +tst_res (TFAIL |TTERRNO ,"read(2) failed" ); +else +tst_res (TPASS ,"read(2) returned %ld" ,TEST_RETURN ); +} + +static void setup (void ) +{ +memset (buf,'*' ,SIZE ); + fd =SAFE_OPEN ("testfile" ,O_RDWR |O_CREAT ,0700 ); +SAFE_WRITE (1 , fd, buf,SIZE ); +} + +static void cleanup (void ) +{ +if (fd >0 ) +SAFE_CLOSE (fd); +} + +static struct tst_test test = { + .test_all = verify_read, + .setup = setup, + .cleanup = cleanup, + .needs_tmpdir =1 , +};
Signature · 1 line
2.11.0
PATCH 1/1 syscall/read: add new testcase for read
----- Original Message -----
Quoted 1 line
Check the return value of read
Hi,
Is this testing some known kernel bug?
How is it different from what read01 and lseek01 already do?
Regards,
Jan