New library conversion for few system call tests
cover New library conversion for few system call tests
Following series is a set of system call tests that are converted to new library. Also deleted bdflush test at the same time. I have been going through the system call tests alphabetically and convert them to new library as applicable, so there will be more to come.
I have tested this on cuttlefish[1] and made sure they don't regress.
Sandeep Patil (5):
syscalls/adjtimex01: Convert to new library
syscalls/adjtimex02: Convert to new library
syscalls/asyncio02: convert to new library.
syscalls/bdflush01: delete bdflush test
syscalls/bind01: convert to new library.
.../kernel/syscalls/adjtimex/adjtimex01.c | 122 ++----- .../kernel/syscalls/adjtimex/adjtimex02.c | 307 +++++------------ testcases/kernel/syscalls/asyncio/asyncio02.c | 323 ++++-------------- testcases/kernel/syscalls/bdflush/.gitignore | 1 - testcases/kernel/syscalls/bdflush/Makefile | 23 -- testcases/kernel/syscalls/bdflush/bdflush01.c | 126 ------- testcases/kernel/syscalls/bind/bind01.c | 201 +++-------- 7 files changed, 219 insertions(+), 884 deletions(-) delete mode 100644 testcases/kernel/syscalls/bdflush/.gitignore delete mode 100644 testcases/kernel/syscalls/bdflush/Makefile delete mode 100644 testcases/kernel/syscalls/bdflush/bdflush01.c
Signature · 1 line
2.21.0.1020.gf2820cf01a-goog
PATCH 1/5 syscalls/adjtimex01: Convert to new library
remove UCLINUX checks along the way.
--- .../kernel/syscalls/adjtimex/adjtimex01.c | 122 +++++------------- 1 file changed, 32 insertions(+), 90 deletions(-)
testcases/kernel/syscalls/adjtimex/adjtimex01.c +32 -90
@@ -1,112 +1,54 @@ +// SPDX-License-Identifier: GPL-2.0 +/* * Copyright (c) Wipro Technologies Ltd, 2002. All Rights Reserved. -* -* This program is free software; you can redistribute it and/or modify it -* under the terms of version 2 of the GNU General Public License as -* published by the Free Software Foundation. -* -* This program is distributed in the hope that it would be useful, but -* WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. -* -* You should have received a copy of the GNU General Public License along -* with this program; if not, write the Free Software Foundation, Inc., -* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +* AUTHOR: Saji Kumar.V.R <[email protected]> */ -/* -AUTHOR: Saji Kumar.V.R <[email protected]> -EXECUTED BY: root / superuser - -TEST ITEMS: -1. Check to see if adjtimex succeed with mode combination : -ADJ_OFFSET | ADJ_FREQUENCY | ADJ_MAXERROR | ADJ_ESTERROR | -ADJ_STATUS | ADJ_TIMECONST | ADJ_TICK -2. Check to see if adjtimex succeed with mode ADJ_OFFSET_SINGLESHOT -*/ - -#if definedUCLINUX && !__THROW -/* workaround for libc bug causing failure in sys/timex.h */ -#define __THROW -#endif -#include <errno.h> #include <sys/timex.h> -#include "test.h" +#include "tst_test.h" #define SET_MODE (ADJ_OFFSET | ADJ_FREQUENCY | ADJ_MAXERROR | ADJ_ESTERROR | \ ADJ_STATUS | ADJ_TIMECONST | ADJ_TICK) -static void setup (void ); -static void cleanup (void ); - -char *TCID ="adjtimex01" ; -int TST_TOTAL =2 ; -static struct timex tim_save; +static struct timex buff; -int main (int ac,char **av) +void verify_adjtimex (void ) { -int lc; - -tst_parse_opts (ac, av,NULL ,NULL ); - -setup (); - -for (lc =0 ;TEST_LOOPING (lc); lc++) { - - tst_count =0 ; - -/* Call adjtimex(2) */ - tim_save.modes =SET_MODE ; - -TEST (adjtimex (&tim_save)); - -if ((TEST_RETURN >=0 ) && (TEST_RETURN <=5 )) { -tst_resm (TPASS ,"adjtimex() with mode %u returned %ld" , -SET_MODE ,TEST_RETURN ); - }else { -tst_resm (TFAIL |TTERRNO , -"Test Failed, adjtimex() with mode %u " -"returned %ld" ,SET_MODE ,TEST_RETURN ); - } - -/* Call adjtimex(2) */ - tim_save.modes =ADJ_OFFSET_SINGLESHOT ; - -TEST (adjtimex (&tim_save)); - -if ((TEST_RETURN >=0 ) && (TEST_RETURN <=5 )) { -tst_resm (TPASS ,"adjtimex() with mode %u returned %ld" , -ADJ_OFFSET_SINGLESHOT ,TEST_RETURN ); - }else { -tst_resm (TFAIL |TTERRNO , -"Test Failed, adjtimex() with mode %u returned " -"%ld" ,ADJ_OFFSET_SINGLESHOT ,TEST_RETURN ); - } - } - -cleanup (); - -tst_exit (); + buff = tim_save; + buff.modes =SET_MODE ; +TEST (adjtimex (&buff)); +if ((TST_RET >=TIME_OK ) && (TST_RET <=TIME_ERROR )) +tst_res (TPASS ,"adjtimex() with mode 0x%x " ,SET_MODE ); +else +tst_res (TFAIL |TTERRNO ,"adjtimex() with mode 0x%x " , +SET_MODE ); + + buff.modes =ADJ_OFFSET_SINGLESHOT ; +TEST (adjtimex (&buff)); +if ((TST_RET >=TIME_OK ) && (TST_RET <=TIME_ERROR )) +tst_res (TPASS ,"adjtimex() with mode 0x%x " , +ADJ_OFFSET_SINGLESHOT ); +else +tst_res (TFAIL |TTERRNO , +"adjtimex() with mode 0x%x " , +ADJ_OFFSET_SINGLESHOT ); }static void setup (void ) { -tst_require_root (); - tim_save.modes =0 ; -tst_sig (NOFORK ,DEF_HANDLER , cleanup); - -TEST_PAUSE ; - -/* Save current parameters in tim_save */ +/* Save current parameters */ if ((adjtimex (&tim_save)) ==-1 ) -tst_brkm (TBROK |TERRNO , cleanup, -"failed to save current parameters" ); +tst_brk (TBROK |TERRNO , +"adjtimex(): failed to save current params" ); } -static void cleanup (void ) -{ -} +static struct tst_test test = { + .needs_root =1 , + .setup = setup, + .test_all = verify_adjtimex, +};
Signature · 1 line
2.21.0.1020.gf2820cf01a-goog
PATCH 1/5 syscalls/adjtimex01: Convert to new library
Hi!
Pushed with minor changes, thanks.
I've added curly braces around the multiline if bodies, which is prefered in LKML coding style.
Signature · 2 lines
Cyril Hrubis [email protected]
PATCH 2/5 syscalls/adjtimex02: Convert to new library
In reply to Sandeep Patilremove UCLINUX checks along the way and simplify the test.
--- .../kernel/syscalls/adjtimex/adjtimex02.c | 307 +++++------------- 1 file changed, 77 insertions(+), 230 deletions(-)
testcases/kernel/syscalls/adjtimex/adjtimex02.c +77 -230
@@ -1,274 +1,121 @@ +// SPDX-License-Identifier: GPL-2.0 +/* * Copyright (c) Wipro Technologies Ltd, 2002. All Rights Reserved. -* -* This program is free software; you can redistribute it and/or modify it -* under the terms of version 2 of the GNU General Public License as -* published by the Free Software Foundation. -* -* This program is distributed in the hope that it would be useful, but -* WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. -* -* You should have received a copy of the GNU General Public License along -* with this program; if not, write the Free Software Foundation, Inc., -* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -* +* AUTHOR : Saji Kumar.V.R <[email protected]> */ -/********************************************************** -* -* TEST IDENTIFIER : adjtimex02 -* -* EXECUTED BY : root / superuser -* -* TEST TITLE : Tests for error conditions -* -* TEST CASE TOTAL : 6 -* -* AUTHOR : Saji Kumar.V.R <[email protected]> -* -* SIGNALS -* Uses SIGUSR1 to pause before test if option set. -* (See the parse_opts(3) man page). -* -* DESCRIPTION -* Verify that -* 1) adjtimex(2) fails with errno set to EFAULT if buf does -* not point to writable memory -* 2) adjtimex(2) fails with errno set to EINVAL if an attempt -* is made to set buf.tick to a value < 900000/HZ -* 3) adjtimex(2) fails with errno set to EINVAL if an attempt -* is made to set buf.tick to a value > 1100000/HZ -* 4) adjtimex(2) fails with errno set to EINVAL if an attempt -* is made to set buf.offset to a value > 512000L -* (This test case will be executed only if the kernel version -* is 2.6.25 or below) -* 5) adjtimex(2) fails with errno set to EINVAL if an attempt -* is made to set buf.offset to a value < 512000L -* (This test case will be executed only if the kernel version -* is 2.6.25 or below) -* 6) adjtimex(2) fails with errno set to EPERM if buf.mode is -* non-zero and the user is not super-user. -* -* Setup: -* Setup signal handling. -* Pause for SIGUSR1 if option specified. -* Save current parameters in tim_save -* -* Test: -* Loop if the proper options are given. -* Call test case specific setup if needed -* call adjtimex with saved timex structure -* Check return value is between 0 & 5 -* Test passed -* Otherwise -* Test failed -* Call test case specific cleanup if needed -* -* Cleanup: -* Print errno log and/or timing stats if options given -* -* USAGE: <for command-line> -* adjtimex02 [-c n] [-e] [-i n] [-I x] [-P x] [-t] [-h] [-f] [-p] -* where, -c n : Run n copies concurrently. -* -e : Turn on errno logging. -* -h : Show help screen -* -f : Turn off functional testing -* -i n : Execute test n times. -* -I x : Execute test for x seconds. -* -p : Pause for SIGUSR1 before starting -* -P x : Pause for x seconds between iterations. -* -t : Turn on syscall timing. -* -****************************************************************/ - -#if definedUCLINUX && !__THROW -/* workaround for libc bug causing failure in sys/timex.h */ -#define __THROW -#endif #include <errno.h> #include <sys/timex.h> #include <unistd.h> #include <pwd.h> -#include "test.h" -#include "safe_macros.h" +#include "tst_test.h" #define SET_MODE ( ADJ_OFFSET | ADJ_FREQUENCY | ADJ_MAXERROR | ADJ_ESTERROR | \ ADJ_STATUS | ADJ_TIMECONST | ADJ_TICK ) -static void setup (void ); -static int setup2 (void ); -static int setup3 (void ); -static int setup4 (void ); -static int setup5 (void ); -static int setup6 (void ); -static void cleanup (void ); -static void cleanup6 (void ); - -char *TCID ="adjtimex02" ; -static int hz;/* HZ from sysconf */ static struct timex tim_save;static struct timex buff; -static char nobody_uid[] ="nobody" ;struct passwd *ltpuser; -struct test_cases_t { +struct test_case {struct timex *buffp; -int (*setup) (); -void (*cleanup) ();int exp_errno; -} test_cases[] = { -#ifndef UCLINUX -/* Skip since uClinux does not implement memory protection */ - { - (struct timex *)-1 ,NULL ,NULL ,EFAULT }, -#endif - { - &buff, setup2,NULL ,EINVAL }, { - &buff, setup3,NULL ,EINVAL }, { - &buff, setup4,NULL ,EINVAL }, { - &buff, setup5,NULL ,EINVAL }, { - &buff, setup6, cleanup6,EPERM } +} tcases[] = { + { (struct timex *)-1 ,EFAULT }, + { &buff,EINVAL }, + { &buff,EINVAL }, + { &buff,EPERM }, + { &buff,EINVAL }, + { &buff,EINVAL }, }; -int TST_TOTAL =sizeof (test_cases) /sizeof (test_cases[0 ]); - -int main (int ac,char **av) +void verify_adjtimex (unsigned int nr) { - -int lc, i; - -tst_parse_opts (ac, av,NULL ,NULL ); - -setup (); - -for (lc =0 ;TEST_LOOPING (lc); lc++) { - - tst_count =0 ; - -for (i =0 ; i <TST_TOTAL ; ++i) { -/* -* since Linux 2.6.26, if buf.offset value is outside -* the acceptable range, it is simply normalized instead -* of letting the syscall fail. so just skip this test -* case. -*/ -if ((i ==3 || i ==4 ) &&tst_kvercmp (2 ,6 ,25 ) >0 ) { -tst_resm (TCONF ,"this kernel normalizes buf." -"offset value if it is outside" -" the acceptable range." ); -continue ; - } - - buff = tim_save; - buff.modes =SET_MODE ; -if ((test_cases[i].setup) && (test_cases[i].setup ())) { -tst_resm (TWARN ,"setup() failed, skipping" -" this test case" ); -continue ; - } - -/* Call adjtimex(2) */ -TEST (adjtimex (test_cases[i].buffp)); - -if ((TEST_RETURN ==-1 ) && (TEST_ERRNO == - test_cases[i].exp_errno)) { -tst_resm (TPASS |TTERRNO , -"Test Passed, adjtimex() returned -1" ); - }else { -tst_resm (TFAIL |TTERRNO , -"Test Failed, adjtimex() returned %ld" , -TEST_RETURN ); - } -if (test_cases[i].cleanup) { - test_cases[i].cleanup (); - } - } +struct test_case *tcase = &tcases[nr]; +/* +* since Linux 2.6.26, if buf.offset value is outside +* the acceptable range, it is simply normalized instead +* of letting the syscall fail. so just skip this test +* case. +*/ +if (nr >3 && (tst_kvercmp (2 ,6 ,25 ) >0 )) { +tst_res (TCONF ,"this kernel normalizes buf." +"offset value if it is outside" +" the acceptable range." ); +return ; } -/* cleanup and exit */ -cleanup (); + buff = tim_save; + buff.modes =SET_MODE ; +switch (nr) { +case 0 : +break ; +case 1 : + buff.tick =900000 / hz -1 ; +break ; +case 2 : + buff.tick =1100000 / hz +1 ; +break ; +case 3 : +/* Switch to nobody user for correct error code collection */ + ltpuser =SAFE_GETPWNAM ("nobody" ); +SAFE_SETEUID (ltpuser->pw_uid); +break ; +case 4 : + buff.offset =512000L +1 ; +break ; +case 5 : + buff.offset = (-1 ) * (512000L ) -1 ; +break ; +default : +tst_brk (TFAIL ,"Invalid test case %u " , nr); + } -tst_exit (); +TEST (adjtimex (tcase->buffp)); +if ((TST_RET ==-1 ) && (TST_ERR == tcase->exp_errno)) { +tst_res (TPASS |TTERRNO , +"adjtimex() error %u " , tcase->exp_errno); + }else { +tst_res (TFAIL |TTERRNO , +"Test Failed, adjtimex() returned %ld" , +TST_RET ); + } +/* clean up after ourselves */ +if (nr ==3 ) +SAFE_SETEUID (0 ); } -/* setup() - performs all ONE TIME setup for this test */ void setup (void ) { -tst_require_root (); - tim_save.modes =0 ; -tst_sig (NOFORK ,DEF_HANDLER , cleanup); -/* set the HZ from sysconf */ - hz =SAFE_SYSCONF (NULL , _SC_CLK_TCK); + hz =SAFE_SYSCONF (_SC_CLK_TCK); -TEST_PAUSE ; - -/* Save current parameters in tim_save */ -if ((adjtimex (&tim_save)) ==-1 ) { -tst_brkm (TBROK ,NULL ,"Failed to save current parameters" ); - } +/* Save current parameters */ +if ((adjtimex (&tim_save)) ==-1 ) +tst_brk (TBROK |TERRNO , +"adjtimex(): failed to save current params" ); } -/* -*cleanup() - performs all ONE TIME cleanup for this test at -* completion or premature exit. -*/ void cleanup (void ) { - tim_save.modes =SET_MODE ; -/* Restore saved parameters */ -if ((adjtimex (&tim_save)) ==-1 ) { -tst_resm (TWARN ,"Failed to restore saved parameters" ); - } -} - -int setup2 (void ) -{ - buff.tick =900000 / hz -1 ; -return 0 ; -} - -int setup3 (void ) -{ - buff.tick =1100000 / hz +1 ; -return 0 ; -} - -int setup4 (void ) -{ - buff.offset =512000L +1 ; -return 0 ; -} - -int setup5 (void ) -{ - buff.offset = (-1 ) * (512000L ) -1 ; -return 0 ; -} -int setup6 (void ) -{ -/* Switch to nobody user for correct error code collection */ -if ((ltpuser =getpwnam (nobody_uid)) ==NULL ) { -tst_brkm (TBROK ,NULL ,"\"nobody\" user not present" ); - } -if (seteuid (ltpuser->pw_uid) ==-1 ) { -tst_resm (TWARN |TERRNO ,"seteuid(%d) failed" , ltpuser->pw_uid); -return 1 ; - } -return 0 ; +/* Restore saved parameters */ +if ((adjtimex (&tim_save)) ==-1 ) +tst_res (TWARN ,"Failed to restore saved parameters" ); } -void cleanup6 (void ) -{ -/* Set effective user id back to root */ -SAFE_SETEUID (cleanup,0 ); -} +static struct tst_test test = { + .needs_root =1 , + .tcnt =ARRAY_SIZE (tcases), + .setup = setup, + .cleanup = cleanup, + .test = verify_adjtimex, +};
Signature · 1 line
2.21.0.1020.gf2820cf01a-goog
PATCH 2/5 syscalls/adjtimex02: Convert to new library
Hi!
Quoted 15 lines
testcases/kernel/syscalls/adjtimex/adjtimex02.c +15
-0+ buff = tim_save; + buff.modes =SET_MODE ; +switch (nr) { +case 0 : +break ; +case 1 : + buff.tick =900000 / hz -1 ; +break ; +case 2 : + buff.tick =1100000 / hz +1 ; +break ; +case 3 : +/* Switch to nobody user for correct error code collection */ + ltpuser =SAFE_GETPWNAM ("nobody" ); +SAFE_SETEUID (ltpuser->pw_uid);
testcases/kernel/syscalls/adjtimex/adjtimex02.c line 76
Quoted 10 lines
testcases/kernel/syscalls/adjtimex/adjtimex02.c +10
-0+break ; +case 4 : + buff.offset =512000L +1 ; +break ; +case 5 : + buff.offset = (-1 ) * (512000L ) -1 ; +break ; +default : +tst_brk (TFAIL ,"Invalid test case %u " , nr); + }
What I do not like about this is that half of the data is now in the structure with errnos while the other half is encoded in this switch and we depend on the order of the structure.
In this case I think that the cleaner option would be getting rid of the structure and set the expected errno in the switch. That way all the data would be in a single place at least.
Quoted 15 lines
testcases/kernel/syscalls/adjtimex/adjtimex02.c +12
-1-tst_exit (); +TEST (adjtimex (tcase->buffp)); +if ((TST_RET ==-1 ) && (TST_ERR == tcase->exp_errno)) { +tst_res (TPASS |TTERRNO , +"adjtimex() error %u " , tcase->exp_errno); + }else { +tst_res (TFAIL |TTERRNO , +"Test Failed, adjtimex() returned %ld" , +TST_RET ); + } +/* clean up after ourselves */ +if (nr ==3 ) +SAFE_SETEUID (0 ); }
Signature · 2 lines
Cyril Hrubis [email protected]
PATCH 3/5 syscalls/asyncio02: convert to new library.
In reply to Sandeep PatilDrop several duplicate test cases along the way
--- testcases/kernel/syscalls/asyncio/asyncio02.c | 323 ++++-------------- 1 file changed, 61 insertions(+), 262 deletions(-)
testcases/kernel/syscalls/asyncio/asyncio02.c +61 -262
@@ -1,94 +1,10 @@ +// SPDX-License-Identifier: GPL-2.0 +/* * Copyright (c) 2000 Silicon Graphics, Inc. All Rights Reserved. -* -* This program is free software; you can redistribute it and/or modify it -* under the terms of version 2 of the GNU General Public License as -* published by the Free Software Foundation. -* -* This program is distributed in the hope that it would be useful, but -* WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. -* -* Further, this software is distributed without any warranty that it is -* free of the rightful claim of any third person regarding infringement -* or the like. Any license provided herein, whether implied or -* otherwise, applies only to this software file. Patent licenses, if -* any, provided herein do not apply to combinations of this program with -* other software, or any other product whatsoever. -* -* You should have received a copy of the GNU General Public License along -* with this program; if not, write the Free Software Foundation, Inc., -* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -* -* Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy, -* Mountain View, CA 94043, or: -* -* http://www.sgi.com -* -* For further information regarding this notice, see: -* -* http://oss.sgi.com/projects/GenInfo/NoticeExplan/ -* -*/ -/* $Id: asyncio02.c,v 1.6 2009/08/28 11:17:39 vapier Exp $ */ -/************************************************************ -* OS Test - Silicon Graphics, Inc. -* Mendota Heights, Minnesota -* -* TEST IDENTIFIER: aiotcs02: write/close flushes data to the file -* -* PARENT DOCUMENT: aiotds01: kernel i/o -* * AUTHOR: Barrie Kletscher -* * CO-PILOT: Dave Baumgartner -* -* TEST ITEMS: -* for each open flags set used: -* 1. Multiple writes to a file work as specified for -* more than BUFSIZ bytes. -* 2. Multiple writes to a file work as specified for -* BUFSIZ bytes. -* 3. Multiple writes to a file work as specified for -* lower than BUFSIZ bytes. -* -* INPUT SPECIFICATIONS: -* Standard parse_opts supported options. -*$ -* OUTPUT SPECIFICATIONS -* Standard tst_res output format -* -* ENVIRONMENTAL NEEDS: -* This program uses the environment variable TMPDIR for the location -* of the temporary directory. -* -* -* SPECIAL PROCEDURAL REQUIREMENTS: -* The program must be linked with tst_*.o and parse_opts.o. -* -* INTERCASE DEPENDENCIES: -* NONE. -* -* DETAILED DESCRIPTION: -* Attempt to get some memory to work with. -* Call testrun writing (BUFSIZ + 1) bytes -* Call testrun writing BUFSIZ bytes -* Repeated call to testrun() with decreasing write sizes -* less than BUFSIZ -* End -* -* Start testrun() -* Attempt to open a temporary file. -* Write the memory to the file. -* Attempt to close the file which also flushes the buffers. -* Now check to see if the number of bytes written is the -* same as the number of bytes in the file. -* Cleanup -* -* BUGS: -* NONE. -* -************************************************************/ +*/ #include <fcntl.h> #include <sys/types.h>
@@ -96,199 +12,82 @@#include <sys/signal.h> #include <errno.h> #include <stdlib.h> -#include "test.h" -#include "safe_macros.h" - -#define FLAG O_RDWR | O_CREAT | O_TRUNC/* Flags used when opening temp tile */ -#define MODE 0777/* Mode to open file with */ -#define WRITES 10/* Number of times buffer is written */ -#define DECR 1000/* Number of bytes decremented between */ -/* Calls to testrun() */ -#define OK -1/* Return value from testrun() */ - -#define FNAME1 "aio02.1" -#define FNAME2 "aio02.2" -#define FNAME3 "aio02.3" - -#define ERR_MSG1 "Bytes in file not equal to bytes written." -#define ERR_MSG2 "Bytes in file (%d) not equal to bytes written (%d)." - -char *dp;/* pointer to area of memory */ - -void setup (); -void cleanup (); -int testrun (int flag,int bytes,int ti); - -char *TCID ="asyncio02" ; -int TST_TOTAL =6 ; - -char *filename;/* name of the temporary file */ - -char *Progname; -int Open_flags; - -int Flags[] = { -O_RDWR |O_CREAT |O_TRUNC , -O_RDWR |O_CREAT |O_TRUNC +#include "tst_test.h" + +/* Temporary file names */ +#define FNAME1 "asyncio02.1" +#define FNAME2 "asyncio02.2" + +/* Number of times each buffer is written */ +#define NUM_WRITES (10) +#define BUFSIZE (4096) + +char *buffer; + +static struct test_case { +const char *filename; +size_t bytes_to_write; +size_t decrement; +} tcases[] = { +/* Write and verify BUFSIZE byte chunks */ + {FNAME1 ,BUFSIZE ,BUFSIZE }, +/* Write and verify decreasing chunk sizes */ + {FNAME2 ,BUFSIZE ,1000 } }; -int Num_flags; - -/*********************************************************************** -* MAIN -***********************************************************************/ -int main (int ac,char **av) +void verify (const char *fname,size_t bytes,size_t decrement) { - -int i; -int ret_val; -int eok;/* everything is ok flag */ -int lc; -int flag_cnt; - - Num_flags =sizeof (Flags) /sizeof (int ); -TST_TOTAL =3 * Num_flags; - -tst_parse_opts (ac, av,NULL ,NULL ); - -setup (); - -for (lc =0 ;TEST_LOOPING (lc); lc++) { - - tst_count =0 ; - -for (flag_cnt =0 ; flag_cnt < Num_flags; flag_cnt++) { - -/* -* call testrun writing (BUFSIZ + 1) byte chunks -*/ - - filename =FNAME1 ; -if (testrun (Flags[flag_cnt],BUFSIZ +1 ,1 ) !=OK ) { -tst_resm (TFAIL ,ERR_MSG1 ); - }else { -tst_resm (TPASS , -"More than BUFSIZE bytes multiple synchronous writes to a file check out ok" ); - } - -/* -* call testrun writing BUFSIZ byte chunks -*/ - - filename =FNAME2 ; -if (testrun (Flags[flag_cnt],BUFSIZ ,2 ) !=OK ) { -tst_resm (TFAIL ,ERR_MSG1 ); - }else { -tst_resm (TPASS , -"BUFSIZE bytes multiple synchronous writes to a file checks out ok" ); - } - -/* -* while the byte chunks are greater than 0 -* call testrun() with decreasing chunk sizes -*/ - - filename =FNAME3 ; - eok =1 ; -for (i =BUFSIZ -1 ; i >=0 ; i -=DECR ) { -if ((ret_val = -testrun (Flags[flag_cnt], i,3 )) !=OK ) { -tst_resm (TFAIL ,ERR_MSG2 , ret_val, - i *WRITES ); - } - } - -if (eok) { -tst_resm (TPASS , -"Less than BUFSIZE bytes multiple synchronous writes to a file checks out ok" ); - } +struct stat s; +int fd, i; +size_t bytes_written =0 ; + + fd =SAFE_OPEN (fname,O_CREAT |O_TRUNC |O_RDWR ,0777 ); +while (bytes >0 ) { +for (i =0 ; i <NUM_WRITES ; i++) { +SAFE_WRITE (1 , fd, buffer, bytes); + bytes_written += bytes; } + bytes -= bytes > decrement ? decrement : bytes; } -cleanup (); -tst_exit (); -}/* end main() */ - -int testrun (int flag,int bytes,int ti) -{ - -int fildes, i, ret; -struct stat buffer;/* buffer of memory required for stat command */ +SAFE_CLOSE (fd); +SAFE_STAT (fname, &s); +SAFE_UNLINK (fname);/* -* Attempt to open a temporary file. +* Now check to see if the number of bytes written was +* the same as the number of bytes in the file. */ - -if ((fildes =open (filename, flag,MODE )) ==-1 ) { -tst_brkm (TBROK |TERRNO , cleanup,"open(%s) failed" , filename); +if (s.st_size != (off_t ) bytes_written) { +tst_res (TFAIL ,"file size (%zu) not as expected (%zu) bytes" , + s.st_size, bytes_written); +return ; } -/* -* Write the memory to the file. -*/ - -for (i =0 ; i <WRITES ; i++) { -TEST (write (fildes, dp, (unsigned )bytes)); - -if (TEST_RETURN ==-1 ) { -tst_brkm (TBROK |TTERRNO , cleanup,"write() failed" ); - } - }/* end for () */ - -/* -* Attempt to close the file which also flushes the buffers. -*/ - -SAFE_CLOSE (cleanup, fildes); - - ret =OK ; - -/* -* Now check to see if the number of bytes written is the -* same as the number of bytes in the file. -*/ - -SAFE_STAT (cleanup, filename, &buffer); - -if (buffer.st_size != (off_t) (bytes *WRITES )) { - ret = (int )buffer.st_size; - } - -SAFE_UNLINK (cleanup, filename); +tst_res (TPASS ,"File size reported as expected" ); +} -return ret; +void verify_asynchronous_io (unsigned int nr) +{ +struct test_case *tcase = &tcases[nr]; -}/* end testrun() */ +verify (tcase->filename, tcase->bytes_to_write, tcase->decrement); +} -/*************************************************************** -* setup() - performs all ONE TIME setup for this test. -***************************************************************/ void setup (void ) { - -tst_sig (FORK ,DEF_HANDLER , cleanup); - -TEST_PAUSE ; - -/* create a temporary directory and go to it */ -tst_tmpdir (); - -/* -* Attempt to get some memory to work with. -*/ - -if ((dp =malloc ((unsigned )BUFSIZ +1 )) ==NULL ) { -tst_brkm (TBROK |TERRNO , cleanup,"malloc() failed" ); - } - + buffer =SAFE_MALLOC (BUFSIZE ); } -/*************************************************************** -* cleanup() - performs all ONE TIME cleanup for this test at -* completion or premature exit. -***************************************************************/ void cleanup (void ) { - -tst_rmdir (); +free (buffer); } + +static struct tst_test test = { + .tcnt =ARRAY_SIZE (tcases), + .needs_tmpdir =1 , + .test = verify_asynchronous_io, + .setup = setup, + .cleanup = cleanup, +};
Signature · 1 line
2.21.0.1020.gf2820cf01a-goog
PATCH 3/5 syscalls/asyncio02: convert to new library.
Hi!
The cleanup looks good, but we should also decide what to do with the test as it is in a wrong place. There is no asyncio syscall in Linux and the test actually looks very similar to the stat01.c test, so maybe it would be best to rename the test to stat02.c after the cleanup. What do you think?
Signature · 2 lines
Cyril Hrubis [email protected]
PATCH 3/5 syscalls/asyncio02: convert to new library.
Hi,
Quoted 5 lines
The cleanup looks good, but we should also decide what to do with the test as it is in a wrong place. There is no asyncio syscall in Linux and the test actually looks very similar to the
stat01.ctest, so maybe it would be best to rename the test tostat02.cafter the cleanup. What do you think?
I'd also move it into stat/stat02.c.
Quoted 1 line
Cyril Hrubis
Kind regards,
Petr
PATCH 3/5 syscalls/asyncio02: convert to new library.
Quoted 8 lines · Petr Vorel
Hi,
Quoted 5 lines
The cleanup looks good, but we should also decide what to do with the test as it is in a wrong place. There is no asyncio syscall in Linux and the test actually looks very similar to the
stat01.ctest, so maybe it would be best to rename the test tostat02.cafter the cleanup. What do you think?I'd also move it into
stat/stat02.c.
I did this now as part of v2. However, the test is still super trivial and isn't at all unique. All it is now is "verify stat size" and I think stat01 covers it too.
Anyway, its there in the new series if you still see value in having a stat02.
- ssp
PATCH 4/5 syscalls/bdflush01: delete bdflush test
In reply to Sandeep PatilThe manual says the system call is deprecated since Linux 2.6 and does nothing. So, remove the test.
--- testcases/kernel/syscalls/bdflush/.gitignore | 1 - testcases/kernel/syscalls/bdflush/Makefile | 23 ---- testcases/kernel/syscalls/bdflush/bdflush01.c | 126 ------------------ 3 files changed, 150 deletions(-) delete mode 100644 testcases/kernel/syscalls/bdflush/.gitignore delete mode 100644 testcases/kernel/syscalls/bdflush/Makefile delete mode 100644 testcases/kernel/syscalls/bdflush/bdflush01.c
testcases/kernel/syscalls/bdflush/.gitignore deleted +0 -1
@@ -1 +0,0 @@ -/bdflush01
testcases/kernel/syscalls/bdflush/Makefile deleted +0 -23
@@ -1,23 +0,0 @@ -# -# Copyright (c) International Business Machines Corp., 2009 -# -# 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 St, Fifth Floor, Boston, MA 02110-1301 USA -# - -top_srcdir ?= ../../../.. - -include $(top_srcdir)/include/mk/testcases.mk - -include $(top_srcdir)/include/mk/generic_leaf_target.mk
testcases/kernel/syscalls/bdflush/bdflush01.c deleted +0 -126
126 lines not on this page · raw message
Signature · 1 line
2.21.0.1020.gf2820cf01a-goog
PATCH 4/5 syscalls/bdflush01: delete bdflush test
Quoted 4 lines · Sandeep Patil
The manual says the system call is deprecated since Linux 2.6 and does nothing. So, remove the test.
Signed-off-by Sandeep Patil <[email protected]>
Quoted 8 lines
--- testcases/kernel/syscalls/bdflush/.gitignore | 1 - testcases/kernel/syscalls/bdflush/Makefile | 23 ---- testcases/kernel/syscalls/bdflush/bdflush01.c | 126 ------------------ 3 files changed, 150 deletions(-) delete mode 100644 testcases/kernel/syscalls/bdflush/.gitignore delete mode 100644 testcases/kernel/syscalls/bdflush/Makefile delete mode 100644 testcases/kernel/syscalls/bdflush/bdflush01.c
It seems I've missed removing 'bdflush01' from runtest. I will send a v2 with that, if you can look at other patches in the mean time.
- ssp
PATCH v2 1/1 syscalls/bdflush01: delete bdflush test
In reply to Sandeep PatilThe manual says the system call is deprecated since Linux 2.6 and does nothing. So, remove the test.
---
v2
=====
- Delete bdflush01 from runtest
runtest/syscalls | 2 - testcases/kernel/syscalls/bdflush/.gitignore | 1 - testcases/kernel/syscalls/bdflush/Makefile | 23 ---- testcases/kernel/syscalls/bdflush/bdflush01.c | 126 ------------------ 4 files changed, 152 deletions(-) delete mode 100644 testcases/kernel/syscalls/bdflush/.gitignore delete mode 100644 testcases/kernel/syscalls/bdflush/Makefile delete mode 100644 testcases/kernel/syscalls/bdflush/bdflush01.c
runtest/syscalls +0 -2
@@ -31,8 +31,6 @@ bind01 bind01 bind02 bind02 bind03 bind03 -bdflush01 bdflush01 - brk01 brk01 capget01 capget01
testcases/kernel/syscalls/bdflush/.gitignore deleted +0 -1
@@ -1 +0,0 @@ -/bdflush01
testcases/kernel/syscalls/bdflush/Makefile deleted +0 -23
@@ -1,23 +0,0 @@ -# -# Copyright (c) International Business Machines Corp., 2009 -# -# 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 St, Fifth Floor, Boston, MA 02110-1301 USA -# - -top_srcdir ?= ../../../.. - -include $(top_srcdir)/include/mk/testcases.mk - -include $(top_srcdir)/include/mk/generic_leaf_target.mk
testcases/kernel/syscalls/bdflush/bdflush01.c deleted +0 -126
126 lines not on this page · raw message
Signature · 1 line
2.21.0.1020.gf2820cf01a-goog
Cyril Hrubis
AppliedPATCH v2 1/1 syscalls/bdflush01: delete bdflush test
Hi!
Quoted 2 lines
The manual says the system call is deprecated since Linux 2.6 and does nothing. So, remove the test.
Applied, thanks.
And actually looking into the kernel sources the syscall stub is still there on a subset of architectures, i.e. these that Linux was ported to before 2.6 with a comment that it will be removed see fs/buffer.c. Maybe it's a time to remove that stub as well...
Signature · 2 lines
Cyril Hrubis [email protected]
PATCH 5/5 syscalls/bind01: convert to new library.
In reply to Sandeep PatilDrop UCLINUX specific tests along the way.
--- testcases/kernel/syscalls/bind/bind01.c | 201 ++++++------------------ 1 file changed, 49 insertions(+), 152 deletions(-)
testcases/kernel/syscalls/bind/bind01.c +49 -152
@@ -1,43 +1,7 @@ -/* -* -* 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 -*/ +// SPDX-License-Identifier: GPL-2.0 /* -* Test Name: bind01 -* -* Test Description: -* Verify that bind() returns the proper errno for various failure cases -* -* Usage: <for command-line> -* bind01 [-c n] [-e] [-i n] [-I x] [-P x] [-t] -* where, -c n : Run n copies concurrently. -* -e : Turn on errno logging. -* -i n : Execute test n times. -* -I x : Execute test for x seconds. -* -P x : Pause for x seconds between iterations. -* -t : Turn on syscall timing. -* -* HISTORY -* 07/2001 Ported by Wayne Boyer -* -* RESTRICTIONS: -* None. -* +* Copyright (c) International Business Machines Corp., 2001 */ #include <stdio.h>
@@ -51,108 +15,54 @@#include <netinet/in.h> -#include "test.h" -#include "safe_macros.h" +#include "tst_test.h" -char *TCID ="bind01" ; -int testno; +int inet_socket; +int dev_null; -int s;/* socket descriptor */ struct sockaddr_in sin1, sin2, sin3; -struct sockaddr_un sun1; - -void setup (void ),setup0 (void ),setup1 (void ),setup2 (void ), -cleanup (void ),cleanup0 (void ),cleanup1 (void ); +struct sockaddr_un sun; -struct test_case_t {/* test case structure */ -int domain;/* PF_INET, PF_UNIX, ... */ -int type;/* SOCK_STREAM, SOCK_DGRAM ... */ -int proto;/* protocol number (usually 0 = default) */ +static struct test_case { +int *socket_fd;/* file descriptor for test case */ struct sockaddr *sockaddr;/* socket address buffer */ -int salen;/* bind's 3rd argument */ -int retval;/* syscall return value */ +socklen_t salen;/* bind's 3rd argument */ +int retval;/* expected return value */ int experrno;/* expected errno */ -void (*setup) (void ); -void (*cleanup) (void );char *desc; -} tdat[] = { -#ifndef UCLINUX -/* Skip since uClinux does not implement memory protection */ - { -PF_INET ,SOCK_STREAM ,0 , (struct sockaddr *)-1 , -sizeof (struct sockaddr_in ),-1 ,EFAULT , setup0, - cleanup0,"invalid sockaddr" }, -#endif - { -PF_INET ,SOCK_STREAM ,0 , (struct sockaddr *)&sin1, -3 ,-1 ,EINVAL , setup0, cleanup0,"invalid salen" }, { -0 ,0 ,0 , (struct sockaddr *)&sin1, -sizeof (sin1),-1 ,ENOTSOCK , setup1, cleanup1, -"invalid socket" } - , { -PF_INET ,SOCK_STREAM ,0 , (struct sockaddr *)&sin2, -sizeof (sin2),0 ,0 , setup0, cleanup0,"INADDR_ANYPORT" } - , { -PF_UNIX ,SOCK_STREAM ,0 , (struct sockaddr *)&sun1, -sizeof (sun1),-1 ,EADDRINUSE , setup0, cleanup0, -"UNIX-domain of current directory" } - , { -PF_INET ,SOCK_STREAM ,0 , (struct sockaddr *)&sin3, -sizeof (sin3),-1 ,EADDRNOTAVAIL , setup0, cleanup0, -"non-local address" } -,}; - -int TST_TOTAL =sizeof (tdat) /sizeof (tdat[0 ]); - -int main (int argc,char *argv[]) +} tcases[] = { + { &inet_socket, (struct sockaddr *)&sin1,3 ,-1 , +EINVAL ,"invalid salen" }, + { &dev_null, (struct sockaddr *)&sin1,sizeof (sin1),-1 , +ENOTSOCK ,"invalid socket" }, + { &inet_socket, (struct sockaddr *)&sin2,sizeof (sin2),0 , +0 ,"INADDR_ANYPORT" }, + { &inet_socket, (struct sockaddr *)&sun,sizeof (sun),-1 , +EAFNOSUPPORT ,"UNIX-domain of current directory" }, + { &inet_socket, (struct sockaddr *)&sin3,sizeof (sin3),-1 , +EADDRNOTAVAIL ,"non-local address" }, +}; + +void verify_bind (unsigned int nr) { -int lc; - -tst_parse_opts (argc, argv,NULL ,NULL ); - -setup (); - -for (lc =0 ;TEST_LOOPING (lc); ++lc) { - tst_count =0 ; - -for (testno =0 ; testno <TST_TOTAL ; ++testno) { - tdat[testno].setup (); - -TEST (bind - (s, tdat[testno].sockaddr, tdat[testno].salen)); -if (TEST_RETURN >0 ) { -TEST_RETURN =0 ; - }else { - } -if (TEST_RETURN != tdat[testno].retval || - (TEST_RETURN <0 && -TEST_ERRNO != tdat[testno].experrno)) { -tst_resm (TFAIL ,"%s ; returned" -" %ld (expected %d), errno %d (expected" -" %d)" , tdat[testno].desc, -TEST_RETURN , tdat[testno].retval, -TEST_ERRNO , tdat[testno].experrno); - }else { -tst_resm (TPASS ,"%s successful" , - tdat[testno].desc); - } - tdat[testno].cleanup (); - } +struct test_case *tcase = &tcases[nr]; + +TEST (bind (*tcase->socket_fd, tcase->sockaddr, tcase->salen)); +if (TST_RET != tcase->retval &&TST_ERR != tcase->experrno) { +tst_res (TFAIL ,"%s ; returned" +" %ld (expected %d), errno %d (expected" +" %d)" , tcase->desc,TST_RET , tcase->retval, +TST_ERR , tcase->experrno); + }else { +tst_res (TPASS ,"%s successful" , tcase->desc); } -cleanup (); - -tst_exit (); } -void setup (void ) +void test_setup (void ) { - -TEST_PAUSE ;/* if -p option specified */ -/* initialize sockaddr's */ sin1.sin_family =AF_INET ; -/* this port must be unused! */ - sin1.sin_port =tst_get_unused_port (NULL ,AF_INET ,SOCK_STREAM ); + sin1.sin_port =0 ; sin1.sin_addr.s_addr =INADDR_ANY ; sin2.sin_family =AF_INET ;
@@ -164,35 +74,22 @@ void setup(void)/* assumes 10.255.254.253 is not a local interface address! */ sin3.sin_addr.s_addr =htonl (0x0AFFFEFD ); - sun1.sun_family =AF_UNIX ; -strncpy (sun1.sun_path,"." ,sizeof (sun1.sun_path)); - -} - -void cleanup (void ) -{ -} + sun.sun_family =AF_UNIX ; +strncpy (sun.sun_path,"." ,sizeof (sun.sun_path)); -void setup0 (void ) -{ - s =SAFE_SOCKET (cleanup, tdat[testno].domain, tdat[testno].type, - tdat[testno].proto); + inet_socket =SAFE_SOCKET (PF_INET ,SOCK_STREAM ,0 ); + dev_null =SAFE_OPEN ("/dev/null" ,O_WRONLY ); } -void cleanup0 (void ) +void test_cleanup (void ) { - (void )close (s); +SAFE_CLOSE (inet_socket); +SAFE_CLOSE (dev_null); } -void setup1 (void ) -{ -/* setup for the "not a socket" case */ -if ((s =open ("/dev/null" ,O_WRONLY )) ==-1 ) -tst_brkm (TBROK |TERRNO , cleanup,"open(/dev/null) failed" ); - -} - -void cleanup1 (void ) -{ - s =-1 ; -} +static struct tst_test test = { + .tcnt =ARRAY_SIZE (tcases), + .setup = test_setup, + .cleanup = test_cleanup, + .test = verify_bind, +};
Signature · 1 line
2.21.0.1020.gf2820cf01a-goog
PATCH 5/5 syscalls/bind01: convert to new library.
Hi!
Unfortunatelly this does not apply cleanly after:
commit fa6a4e708495d9177eca395717ebab4ee9afd8d6
Author: Petr Vorel <[email protected]> Date: Tue Apr 23 21:38:23 2019 +0200
net: Introduce TST_GET_UNUSED_PORT() macro into C API
Can you please rebase your commit?
Signature · 2 lines
Cyril Hrubis [email protected]
PATCH 5/5 syscalls/bind01: convert to new library.
Quoted 11 lines · Cyril Hrubis
Hi!
Unfortunatelly this does not apply cleanly after:commit
fa6a4e708495d9177eca395717ebab4ee9afd8d6Author: Petr Vorel <[email protected]> Date: Tue Apr 23 21:38:23 2019 +0200net: Introduce
TST_GET_UNUSED_PORT()macro into C APICan you please rebase your commit?
Will do and resend the series addressing your comments on other patches.
Thanks for reviewing,
- ssp
Quoted 4 lines
Signature · 3 lines
-- Cyril Hrubis [email protected]
PATCH 5/5 syscalls/bind01: convert to new library.
In reply to Cyril HrubisQuoted 11 lines · Cyril Hrubis
Hi!
Unfortunatelly this does not apply cleanly after:commit
fa6a4e708495d9177eca395717ebab4ee9afd8d6Author: Petr Vorel <[email protected]> Date: Tue Apr 23 21:38:23 2019 +0200net: Introduce
TST_GET_UNUSED_PORT()macro into C APICan you please rebase your commit?
Done, v2 sent