syscalls/getpriority01: Cleanup && Convert to new API
PATCH 1/4 syscalls/getpriority01: Cleanup && Convert to new API
--- .../kernel/syscalls/getpriority/getpriority01.c | 171 +++++---------------- 1 file changed, 41 insertions(+), 130 deletions(-)
testcases/kernel/syscalls/getpriority/getpriority01.c +41 -130
@@ -1,147 +1,58 @@/* -* -* 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) International Business Machines Corp., 2001 +* 07/2001 Ported by Wayne Boyer +* 11/2016 Modified by Guangwen Feng <[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/>. */ /* -* Test Name: getpriority01 -* -* Test Description: -* Verify that getpriority() succeeds get the scheduling priority of -* the current process, process group or user. -* -* Expected Result: -* getpriority() should return the highest priority of the test process. -* -* Algorithm: -* Setup: -* Setup signal handling. -* Pause for SIGUSR1 if option specified. -* -* Test: -* Loop if the proper options are given. -* Execute system call -* Check return code, if system call failed (return=-1) -* Log the errno and Issue a FAIL message. -* Otherwise, -* Verify the Functionality of system call -* if successful, -* Issue Functionality-Pass message. -* Otherwise, -* Issue Functionality-Fail message. -* Cleanup: -* Print errno log and/or timing stats if options given -* -* Usage: <for command-line> -* getpriority01 [-c n] [-i n] [-I x] [-P x] [-t] -* where, -c n : Run n copies concurrently. -* -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. -* +* Verify that getpriority(2) succeeds get the scheduling priority of +* the current process, process group or user. */ -#include <stdio.h> -#include <unistd.h> -#include <sys/types.h> #include <errno.h> -#include <fcntl.h> -#include <string.h> -#include <signal.h> -#include <sys/param.h> -#include <sys/time.h> #include <sys/resource.h> +#include <sys/time.h> +#include "tst_test.h" -#include "test.h" - -char *TCID ="getpriority01" ; -int TST_TOTAL =1 ; - -void setup ();/* setup function for the test */ -void cleanup ();/* cleanup function for the test */ - -int prio_which[] = {PRIO_PROCESS ,PRIO_PGRP ,PRIO_USER }; +static struct tcase { +int which; +} tcases[] = { + {PRIO_PROCESS }, + {PRIO_PGRP }, + {PRIO_USER } +}; -int main (int ac,char **av) +static void verify_getpriority (unsigned int n) { -int lc; -int ind; -int which;/* scheduling priority category */ - -TST_TOTAL =sizeof (prio_which) /sizeof (int ); +struct tcase *tc = &tcases[n]; -tst_parse_opts (ac, av,NULL ,NULL ); +TEST (getpriority (tc->which,0 )); -setup (); - -for (lc =0 ;TEST_LOOPING (lc); lc++) { - - tst_count =0 ; - -for (ind =0 ; ind <TST_TOTAL ; ind++) { - which = prio_which[ind]; - -/* -* Invoke getpriority with the specified -* 'which' argument for the calling process. -*/ -TEST (getpriority (which,0 )); - -if (TEST_RETURN <0 &&TEST_ERRNO !=0 ) { -tst_resm (TFAIL ,"getpriority(%d, 0) " -"Failed, errno=%d : %s" , - which,TEST_ERRNO , -strerror (TEST_ERRNO )); - }else { -tst_resm (TPASS ,"getpriority(%d, 0) returned " -"%ld priority value" , - which,TEST_RETURN ); - } - } +if (TEST_RETURN <0 &&TEST_ERRNO !=0 ) { +tst_res (TFAIL |TTERRNO ,"getpriority(%d, 0) returned %ld" , + tc->which,TEST_RETURN ); +return ; } -cleanup (); - -tst_exit (); -} - -/* -* setup() - performs all ONE TIME setup for this test. -*/ -void setup (void ) -{ - -tst_sig (NOFORK ,DEF_HANDLER , cleanup); - -TEST_PAUSE ; +tst_res (TPASS ,"getpriority(%d, 0) returned %ld" , + tc->which,TEST_RETURN ); } -/* -* cleanup() - performs all ONE TIME cleanup for this test at -* completion or premature exit. -*/ -void cleanup (void ) -{ - -} +static struct tst_test test = { + .tid ="getpriority01" , + .tcnt =ARRAY_SIZE (tcases), + .test = verify_getpriority, +};
Signature · 1 line
1.8.4.2
PATCH 2/4 syscalls/getpriority02: Cleanup && Convert to new API
--- .../kernel/syscalls/getpriority/getpriority02.c | 210 ++++++--------------- 1 file changed, 53 insertions(+), 157 deletions(-)
testcases/kernel/syscalls/getpriority/getpriority02.c +53 -157
@@ -1,181 +1,77 @@/* +* Copyright (c) International Business Machines Corp., 2001 +* 07/2001 Ported by Wayne Boyer +* 11/2016 Modified by Guangwen Feng <[email protected]> * -* 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 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. * -* 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 +* You should have received a copy of the GNU General Public License +* along with this program; if not, see <http://www.gnu.org/licenses/>. */ /* -* Test Name: getpriority02 -* -* Test Description: -* Verify that, -* 1) getpriority() sets errno to ESRCH if no process was located -* was located for 'which' and 'who' arguments. -* 2) getpriority() sets errno to EINVAL if 'which' argument was -* not one of PRIO_PROCESS, PRIO_PGRP, or PRIO_USER. -* -* Expected Result: -* getpriority() should fail with return value -1 and set expected errno. -* -* Algorithm: -* Setup: -* Setup signal handling. -* Pause for SIGUSR1 if option specified. -* -* Test: -* Loop if the proper options are given. -* Execute system call -* Check return code, if system call failed (return=-1) -* if errno set == expected errno -* Issue sys call fails with expected return value and errno. -* Otherwise, -* Issue sys call fails with unexpected errno. -* Otherwise, -* Issue sys call returns unexpected value. -* -* Cleanup: -* Print errno log and/or timing stats if options given -* -* Usage: <for command-line> -* getpriority02 [-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. +* Verify that, +* 1) getpriority(2) fails with -1 and sets errno to EINVAL if 'which' +* argument was not one of PRIO_PROCESS, PRIO_PGRP, or PRIO_USER. +* 2) getpriority(2) fails with -1 and sets errno to ESRCH if no +* process was located for 'which' and 'who' arguments. */ -#include <stdio.h> -#include <unistd.h> -#include <sys/types.h> #include <errno.h> -#include <fcntl.h> -#include <string.h> -#include <signal.h> -#include <sys/param.h> -#include <sys/time.h> #include <sys/resource.h> +#include <sys/time.h> +#include "tst_test.h" -#include "test.h" - -#define INVAL_PID -1 -#define INVAL_FLAG -1 - -char *TCID ="getpriority02" ; -int TST_TOTAL =4 ; +#define INVAL_FLAG -1 +#define INVAL_ID -1 -struct test_case_t {/* test case struct. to hold ref. test cond's */ -int pro_which; -uid_t pro_uid; -char *desc; +static struct tcase { +int which; +int who;int exp_errno; -} Test_cases[] = { - { -INVAL_FLAG ,0 ,"Invalid 'which' value specified" ,EINVAL }, { -PRIO_PROCESS ,INVAL_PID ,"Invalid 'who' value specified" ,ESRCH }, { -PRIO_PGRP ,INVAL_PID ,"Invalid 'who' value specified" ,ESRCH }, { -PRIO_USER ,INVAL_PID ,"Invalid 'who' value specified" ,ESRCH }, { -0 ,0 ,NULL ,0 } +} tcases[] = { +/* test 1 */ + {INVAL_FLAG ,0 ,EINVAL }, + +/* test 2 */ + {PRIO_PROCESS ,INVAL_ID ,ESRCH }, + {PRIO_PGRP ,INVAL_ID ,ESRCH }, + {PRIO_USER ,INVAL_ID ,ESRCH } }; -void setup ();/* Main setup function of test */ -void cleanup ();/* cleanup function for the test */ - -int main (int ac,char **av) +static void verify_getpriority (unsigned int n) { -int lc; -int ind;/* counter variable for test case looping */ -char *test_desc;/* test specific error message */ -int which;/* process priority category */ -uid_t who;/* process uid of the test process */ - -tst_parse_opts (ac, av,NULL ,NULL ); - -setup (); - -for (lc =0 ;TEST_LOOPING (lc); lc++) { - - tst_count =0 ; +struct tcase *tc = &tcases[n]; -for (ind =0 ; ind <TST_TOTAL ; ind++) { - which = Test_cases[ind].pro_which; - who = Test_cases[ind].pro_uid; - test_desc = Test_cases[ind].desc; - -if (who ==0 ) { -/* Get the actual uid of the process */ - who =getuid (); - } - -/* -* Invoke getpriority with the specified -* 'which' and 'who' arguments and verify -* that it fails with expected errno. -*/ -TEST (getpriority (which, who)); - -/* check return code from getpriority(2) */ -if (TEST_RETURN <0 ) { -if (TEST_ERRNO == Test_cases[ind].exp_errno) { -tst_resm (TPASS ,"getpriority(2) fails, " -"%s, errno:%d" , - test_desc,TEST_ERRNO ); - }else { -tst_resm (TFAIL ,"getpriority() fails, " -"%s, errno:%d, expected errno:" -"%d" , test_desc,TEST_ERRNO , - Test_cases[ind].exp_errno); - } - }else { -tst_resm (TFAIL ,"getpriority() returned %ld, " -"expected -1, errno:%d" ,TEST_RETURN , - Test_cases[ind].exp_errno); - } - } +TEST (getpriority (tc->which, tc->who)); +if (TEST_RETURN !=-1 ) { +tst_res (TFAIL ,"getpriority(%d, %d) succeeds unexpectedly" , + tc->which, tc->who); +return ; } -cleanup (); - -tst_exit (); -} - -/* -* setup() - performs all ONE TIME setup for this test. -*/ -void setup (void ) -{ - -tst_sig (NOFORK ,DEF_HANDLER , cleanup); +if (tc->exp_errno !=TEST_ERRNO ) { +tst_res (TFAIL |TTERRNO , +"getpriority(%d, %d) should fail with %s" , + tc->which, tc->who,tst_strerrno (tc->exp_errno)); +return ; + } -TEST_PAUSE ; +tst_res (TPASS |TTERRNO ,"getpriority(%d, %d) fails as expected" , + tc->which, tc->who); } -/* -* cleanup() - performs all ONE TIME cleanup for this test at -* completion or premature exit. -*/ -void cleanup (void ) -{ - -} +static struct tst_test test = { + .tid ="getpriority02" , + .tcnt =ARRAY_SIZE (tcases), + .test = verify_getpriority, +};
Signature · 1 line
1.8.4.2
PATCH 2/4 syscalls/getpriority02: Cleanup && Convert to new API
Hi!
testcases/kernel/syscalls/getpriority/getpriority02.c line 58
Quoted 3 lines
testcases/kernel/syscalls/getpriority/getpriority02.c +3
-0+if (TEST_RETURN !=-1 ) { +tst_res (TFAIL ,"getpriority(%d, %d) succeeds unexpectedly" , + tc->which, tc->who);
I've changed this tst_res() to include the TEST_RETURN in the message as well and pushed, thanks.
Signature · 2 lines
Cyril Hrubis [email protected]
PATCH 3/4 syscalls/setpriority01: Cleanup && Convert to new API
In reply to Guangwen Feng* add tests for PRIO_PGRP and PRIO_USER flag.
--- .../kernel/syscalls/setpriority/setpriority01.c | 120 +++++++++------------ 1 file changed, 50 insertions(+), 70 deletions(-)
testcases/kernel/syscalls/setpriority/setpriority01.c +50 -70
@@ -1,95 +1,75 @@/* * Copyright (c) International Business Machines Corp., 2001 -* 03/2001 - Written by Wayne Boyer +* 03/2001 Written by Wayne Boyer +* 11/2016 Modified by Guangwen Feng <[email protected]> * -* This program is free software; you can redistribute it and/or modify +* 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. +* 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 +* along with this program; if not, see <http://www.gnu.org/licenses/>. */ /* -* DESCRIPTION -* setpriority01 - set the priority for the test process lower. +* Verify that setpriority(2) succeeds set the scheduling priority of +* the current process, process group or user. */ -#include "test.h" -#include <errno.h> -#include <sys/time.h> #include <sys/resource.h> +#include <sys/time.h> +#include "tst_test.h" -static void cleanup (void ); -static void setpriority_verify (const int ); -static void setup (void ); - -char *TCID ="setpriority01" ; -int TST_TOTAL =40 ; - -int main (int ac,char **av) -{ -int lc; -int new_val; - -tst_parse_opts (ac, av,NULL ,NULL ); - -setup (); - -for (lc =0 ;TEST_LOOPING (lc); lc++) { - tst_count =0 ; -for (new_val =-20 ; new_val <20 ; new_val++) -setpriority_verify (new_val); - } - -cleanup (); -tst_exit (); - -} - -static void setup (void ) -{ -tst_require_root (); - -tst_sig (NOFORK ,DEF_HANDLER , cleanup); - -TEST_PAUSE ; -} +static struct tcase { +int which; +} tcases[] = { + {PRIO_PROCESS }, + {PRIO_PGRP }, + {PRIO_USER } +}; -static void setpriority_verify (const int new_prio) +static void verify_setpriority (unsigned int n) { -int priority; -TEST (setpriority (PRIO_PROCESS ,0 , new_prio)); - -if (TEST_RETURN !=0 ) { -tst_resm (TFAIL |TTERRNO ,"setpriority(%d) failed" , new_prio); -return ; - } - - priority =getpriority (PRIO_PROCESS ,0 ); -if (errno ==-1 ) { -tst_brkm (TBROK , cleanup, -"getpriority call failed - errno = %d - %s" , errno, -strerror (errno)); +struct tcase *tc = &tcases[n]; +int new_prio, cur_prio; +int failflag =0 ; + +for (new_prio =-20 ; new_prio <20 ; new_prio++) { +TEST (setpriority (tc->which,0 , new_prio)); + +if (TEST_RETURN !=0 ) { +tst_res (TFAIL |TTERRNO , +"setpriority(%d, 0, %d) failed" , + tc->which, new_prio); + failflag =1 ; +continue ; + } + + cur_prio =SAFE_GETPRIORITY (tc->which,0 ); + +if (cur_prio != new_prio) { +tst_res (TFAIL ,"current priority(%d) and " +"new priority(%d) do not match" , + cur_prio, new_prio); + failflag =1 ; + } } -if (priority == new_prio) { -tst_resm (TPASS ,"setpriority(%d) succeeded" , new_prio); - }else { -tst_resm (TFAIL , -"current priority-%d and new priority-%d do not match" , - priority, new_prio); - } +if (!failflag) +tst_res (TPASS ,"setpriority(%d, 0, -20..19) succeeded" , + tc->which); } -static void cleanup (void ) -{ -} +static struct tst_test test = { + .tid ="setpriority01" , + .tcnt =ARRAY_SIZE (tcases), + .needs_root =1 , + .test = verify_setpriority, +};
Signature · 1 line
1.8.4.2
PATCH 3/4 syscalls/setpriority01: Cleanup && Convert to new API
Hi!
Pushed with cosmetic change, thanks.
I've added a curly bracse around this multilne if body:
Quoted 3 lines
testcases/kernel/syscalls/setpriority/setpriority01.c +3
-0+if (!failflag) +tst_res (TPASS ,"setpriority(%d, 0, -20..19) succeeded" , + tc->which);
Signature · 2 lines
Cyril Hrubis [email protected]
PATCH 4/4 syscalls/setpriority02: Reconstruct && Convert to new API
In reply to Guangwen Feng* merge setpriority03, 04 and 05 into setpriority02
* add test for EACCES with PRIO_PGRP flag
* add tests for ESRCH with PRIO_PGRP and PRIO_USER flag
--- runtest/ltplite | 3 - runtest/stress.part3 | 3 - runtest/syscalls | 3 - .../kernel/syscalls/setpriority/setpriority02.c | 222 ++++++++++----------- .../kernel/syscalls/setpriority/setpriority03.c | 133 ------------ .../kernel/syscalls/setpriority/setpriority04.c | 134 ------------- .../kernel/syscalls/setpriority/setpriority05.c | 143 ------------- 7 files changed, 106 insertions(+), 535 deletions(-) delete mode 100644 testcases/kernel/syscalls/setpriority/setpriority03.c delete mode 100644 testcases/kernel/syscalls/setpriority/setpriority04.c delete mode 100644 testcases/kernel/syscalls/setpriority/setpriority05.c
runtest/ltplite +0 -3
@@ -787,9 +787,6 @@ setpgrp02 setpgrp02 setpriority01 setpriority01 setpriority02 setpriority02 -setpriority03 setpriority03 -setpriority04 setpriority04 -setpriority05 setpriority05 setregid01 setregid01 setregid02 setregid02
runtest/stress.part3 +0 -3
@@ -678,9 +678,6 @@ setpgrp02 setpgrp02 setpriority01 setpriority01 setpriority02 setpriority02 -setpriority03 setpriority03 -setpriority04 setpriority04 -setpriority05 setpriority05 setregid01 setregid01 setregid02 setregid02
runtest/syscalls +0 -3
@@ -1068,9 +1068,6 @@ setpgrp02 setpgrp02 setpriority01 setpriority01 setpriority02 setpriority02 -setpriority03 setpriority03 -setpriority04 setpriority04 -setpriority05 setpriority05 setregid01 setregid01 setregid01_16 setregid01_16
testcases/kernel/syscalls/setpriority/setpriority02.c +106 -116
249 lines not on this page · raw message
testcases/kernel/syscalls/setpriority/setpriority03.c deleted +0 -133
133 lines not on this page · raw message
testcases/kernel/syscalls/setpriority/setpriority04.c deleted +0 -134
134 lines not on this page · raw message
testcases/kernel/syscalls/setpriority/setpriority05.c deleted +0 -143
143 lines not on this page · raw message
Signature · 1 line
1.8.4.2
PATCH 4/4 syscalls/setpriority02: Reconstruct && Convert to new API
Hi!
Pushed with minor changes, thanks.
testcases/kernel/syscalls/setpriority/setpriority02.c line 83
Quoted 4 lines
testcases/kernel/syscalls/setpriority/setpriority02.c +4
-0+if (TEST_RETURN !=-1 ) { +tst_res (TFAIL , +"setpriority(%d, %d, %d) %ssucceeds unexpectedly" , + tc->which, tc->who, tc->prio, desc);
I've changed this tst_res() to include TEST_RETURN in the message and also fixed .gitignore file.
Signature · 2 lines
Cyril Hrubis [email protected]
PATCH 1/4 syscalls/getpriority01: Cleanup && Convert to new API
In reply to Guangwen FengHi!
testcases/kernel/syscalls/getpriority/getpriority01.c line 111
Quoted 1 line
testcases/kernel/syscalls/getpriority/getpriority01.c +0
-1-if (TEST_RETURN <0 &&TEST_ERRNO !=0 ) {
Since the default value for priorities is 0, I've changed this check to:
if (TEST_RETURN != 0 || TEST_ERRNO != 0) {
...
}And pushed, thanks.
Signature · 2 lines
Cyril Hrubis [email protected]