* Delete some useless commtents.
* Move the test body from main() to setpriority_verify().
* Expand tests([-20,19]).
* Add tst_require_root for lowering priorities testes.
* Some cleanup.
Signed-off-by: Zeng Linggang <zenglg...@cn.fujitsu.com>
---
.../kernel/syscalls/setpriority/setpriority01.c | 166 +++++++--------------
1 file changed, 52 insertions(+), 114 deletions(-)
diff --git a/testcases/kernel/syscalls/setpriority/setpriority01.c
b/testcases/kernel/syscalls/setpriority/setpriority01.c
index c0cbe15..d94d9d8 100644
--- a/testcases/kernel/syscalls/setpriority/setpriority01.c
+++ b/testcases/kernel/syscalls/setpriority/setpriority01.c
@@ -1,58 +1,25 @@
/*
+ * Copyright (c) International Business Machines Corp., 2001
+ * 03/2001 - Written by Wayne Boyer
*
- * 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, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
/*
- * NAME
- * setpriority01.c
- *
* DESCRIPTION
* setpriority01 - set the priority for the test process lower.
- *
- * CALLS
- * setpriority()
- *
- * ALGORITHM
- * loop if that option was specified
- * issue the system call
- * read back the priority with getpriority()
- * check the errno value
- * if errno == 0 and the new priority == the set priority
- * then issue a PASS message
- * otherwise, the tests fails
- * issue a FAIL message
- * break any remaining tests
- * call cleanup
- *
- * USAGE: <for command-line>
- * setpriority01 [-c n] [-f] [-i n] [-I x] [-p x] [-t]
- * where, -c n : Run n copies concurrently.
- * -f : Turn off functionality Testing.
- * -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
- * 03/2001 - Written by Wayne Boyer
- *
- * RESTRICTIONS
- * none
*/
#include "test.h"
@@ -62,73 +29,29 @@
#include <sys/time.h>
#include <sys/resource.h>
-void cleanup(void);
-void setup(void);
+static void cleanup(void);
+static void setpriority01(const int);
+static void setup(void);
char *TCID = "setpriority01";
-int TST_TOTAL = 1;
+int TST_TOTAL = 40;
int main(int ac, char **av)
{
int lc;
char *msg;
- int priority;
- int new_val = 2; /* lower our priority from 0 to new_val */
+ int new_val;
- if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL) {
+ msg = parse_opts(ac, av, NULL, NULL);
+ if (msg != NULL)
tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg);
- }
- setup(); /* global setup */
-
- /* The following loop checks looping state if -i option given */
+ setup();
for (lc = 0; TEST_LOOPING(lc); lc++) {
- /* reset tst_count in case we are looping */
tst_count = 0;
-
- /*
- * Lower the priority of this process from a default of 0
- * to a new value of 2. Then read the value using getpriority()
- * to verify the change.
- */
-
- /*
- * We need to be careful here. We could possibly set our
- * priority lower using PRIO_USER and then have no way
- * to set it back. So, let's use PRIO_PROCESS and make
- * sure we affect this test only.
- */
-
- /* call the system call with the TEST() macro */
- TEST(setpriority(PRIO_PROCESS, 0, new_val));
-
- if (TEST_RETURN != 0) {
- tst_resm(TFAIL, "call failed - errno = %d - "
- "%s", TEST_ERRNO, strerror(TEST_ERRNO));
- continue;
- }
-
- if (STD_FUNCTIONAL_TEST) {
- /* get the priority that we just set */
- priority = getpriority(PRIO_PROCESS, 0);
-
- if (errno == -1) {
- tst_brkm(TBROK, cleanup, "getpriority call "
- "failed - errno = %d - %s", errno,
- strerror(errno));
- }
-
- if (priority == new_val) {
- tst_resm(TPASS, "functionality is correct");
- } else {
- tst_resm(TFAIL, "current priority (%d) and new "
- "priority (%d) do not match",
- priority, new_val);
- }
- } else {
- tst_resm(TPASS, "call succeeded");
- }
+ for (new_val = -20; new_val < 20; new_val++)
+ setpriority01(new_val);
}
cleanup();
@@ -136,27 +59,42 @@ int main(int ac, char **av)
}
-/*
- * setup() - performs all the ONE TIME setup for this test.
- */
-void setup(void)
+static void setup(void)
{
+ tst_require_root(NULL);
tst_sig(NOFORK, DEF_HANDLER, cleanup);
TEST_PAUSE;
}
-/*
- * cleanup() - performs all the ONE TIME cleanup for this test at completion
- * or premature exit.
- */
-void cleanup(void)
+static void setpriority01(const int new_prio)
{
- /*
- * print timing stats if that option was specified.
- * print errno log if that option was specified.
- */
- TEST_CLEANUP;
+ 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));
+ }
+
+ 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);
+ }
+}
+
+static void cleanup(void)
+{
+ TEST_CLEANUP;
}
--
1.8.4.2
------------------------------------------------------------------------------
Is your legacy SCM system holding you back? Join Perforce May 7 to find out:
• 3 signs your SCM is hindering your productivity
• Requirements for releasing software faster
• Expert tips and advice for migrating your SCM now
http://p.sf.net/sfu/perforce
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list