syscalls/readv03: Convert to new API
PATCH 1/1 syscalls/readv03: Convert to new API
Signed-off-by Dai Shili <[email protected]>
--- testcases/kernel/syscalls/readv/readv03.c | 150 ++++++------------------------ 1 file changed, 27 insertions(+), 123 deletions(-)
testcases/kernel/syscalls/readv/readv03.c +27 -123
@@ -1,148 +1,52 @@ +// SPDX-License-Identifier: GPL-2.0-or-later /* -* -* Copyright (C) Bull S.A. 2001 -* Copyright (c) International Business Machines Corp., 2001 -* -* 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, write to the Free Software -* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +* Copyright (C) Bull S.A. 2001 +* Copyright (c) International Business Machines Corp., 2001 +* 05/2002 Ported by Jacky Malcles */ -/* -* NAME -* readv03.c -* -* DESCRIPTION -* Testcase to check the error condition of the readv(2) system call -* when fd refers to a directory. -* -* CALLS -* readv() -* -* ALGORITHM -* loop if that option was specified -* call readv() when fd refers to a directory. -* check the errno value -* issue a PASS message if we get EISDIR - errno 21 -* otherwise, the tests fails -* issue a FAIL message -* call cleanup -* -* USAGE$ -* readv03 -* -* HISTORY -* 05/2002 Ported by Jacky Malcles -* -* RESTRICTIONS -* None +/*\ +* [Description] +* Testcase to check EISDIR error when fd refers to a directory. */ -#include <sys/types.h> +#include <sys/uio.h> #include <fcntl.h> -#include <errno.h> -#include <string.h> -#include <sys/stat.h> +#include "tst_test.h" -#include "test.h" -#include "safe_macros.h" - -#define K_1 1024 +#define K_1 1024#define MODES S_IRWXUchar buf1[K_1 ];struct iovec rd_iovec[1 ] = { - {buf1,K_1 } + {buf1,K_1 } };const char *TEST_DIR ="alpha" ; -int r_val; -int fd; - -char *TCID ="readv03" ; -int TST_TOTAL =1 ; +static int fd; -void setup (); -void cleanup (); - -int main (int ac,char **av) +static void verify_readv (void ) { -int lc; - -tst_parse_opts (ac, av,NULL ,NULL ); - -setup (); - -/* The following loop checks looping state if -i option given */ -for (lc =0 ;TEST_LOOPING (lc); lc++) { - -/* reset tst_count in case we are looping */ - tst_count =0 ; - -if (readv (fd, rd_iovec,1 ) <0 ) { -if (errno !=EISDIR ) { -tst_resm (TFAIL ,"expected errno = EISDIR, " -"got %d" , errno); - }else { -tst_resm (TPASS ,"got EISDIR" ); - } - }else { -tst_resm (TFAIL ,"Error: readv returned a positive " -"value" ); - } - - } -cleanup (); -tst_exit (); - +TST_EXP_FAIL2 (readv (fd, rd_iovec,1 ),EISDIR , +"readv() got EISDIR" ); } -/* -* setup() - performs all ONE TIME setup for this test. -*/ void setup (void ) { - -tst_sig (NOFORK ,DEF_HANDLER , cleanup); - -TEST_PAUSE ; - -/* make a temporary directory and cd to it */ -tst_tmpdir (); - -/* -* create a new directory and open it -*/ - -if ((r_val =mkdir (TEST_DIR ,MODES )) ==-1 ) { -tst_brkm (TBROK , cleanup,"%s - mkdir() in main() " -"failed" ,TCID ); - } - -if ((fd =open (TEST_DIR ,O_RDONLY )) ==-1 ) { -tst_brkm (TBROK , cleanup,"open of directory failed" ); - } - +SAFE_MKDIR (TEST_DIR ,MODES ); + fd =SAFE_OPEN (TEST_DIR ,O_RDONLY ); } -/* -* cleanup() - performs all ONE TIME cleanup for this test at -* completion or premature exit. -*/ -void cleanup (void ) +static void cleanup (void ) { -SAFE_CLOSE (cleanup, fd); -tst_rmdir (); - +if (fd >0 ) +SAFE_CLOSE (fd); } + +static struct tst_test test = { + .needs_tmpdir =1 , + .setup = setup, + .cleanup = cleanup, + .test_all = verify_readv, +};
Signature · 1 line
1.8.3.1
PATCH 1/1 syscalls/readv03: Convert to new API
Hi!
Nice cleanup, pushed with minor change, thanks.
* I've changed the buf and rd_iovec to static.
Also it would probably be for the best if we implemented the EINVAL, EFAULT, and EBADFD tests in the readv03.c and got rid of readv02.c as well.
Signature · 2 lines
Cyril Hrubis [email protected]