Home | History | Annotate | Download | only in setpriority
      1 /*
      2  * Copyright (c) International Business Machines  Corp., 2001
      3  *	03/2001 - Written by Wayne Boyer
      4  *
      5  * This program is free software;  you can redistribute it and/or modify
      6  * it under the terms of the GNU General Public License as published by
      7  * the Free Software Foundation; either version 2 of the License, or
      8  * (at your option) any later version.
      9  *
     10  * This program is distributed in the hope that it will be useful,
     11  * but WITHOUT ANY WARRANTY;  without even the implied warranty of
     12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
     13  * the GNU General Public License for more details.
     14  *
     15  * You should have received a copy of the GNU General Public License
     16  * along with this program;  if not, write to the Free Software
     17  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
     18  */
     19 
     20 /*
     21  * DESCRIPTION
     22  *	setpriority01 - set the priority for the test process lower.
     23  */
     24 
     25 #include "test.h"
     26 
     27 #include <errno.h>
     28 #include <sys/time.h>
     29 #include <sys/resource.h>
     30 
     31 static void cleanup(void);
     32 static void setpriority_verify(const int);
     33 static void setup(void);
     34 
     35 char *TCID = "setpriority01";
     36 int TST_TOTAL = 40;
     37 
     38 int main(int ac, char **av)
     39 {
     40 	int lc;
     41 	int new_val;
     42 
     43 	tst_parse_opts(ac, av, NULL, NULL);
     44 
     45 	setup();
     46 
     47 	for (lc = 0; TEST_LOOPING(lc); lc++) {
     48 		tst_count = 0;
     49 		for (new_val = -20; new_val < 20; new_val++)
     50 			setpriority_verify(new_val);
     51 	}
     52 
     53 	cleanup();
     54 	tst_exit();
     55 
     56 }
     57 
     58 static void setup(void)
     59 {
     60 	tst_require_root();
     61 
     62 	tst_sig(NOFORK, DEF_HANDLER, cleanup);
     63 
     64 	TEST_PAUSE;
     65 }
     66 
     67 static void setpriority_verify(const int new_prio)
     68 {
     69 	int priority;
     70 	TEST(setpriority(PRIO_PROCESS, 0, new_prio));
     71 
     72 	if (TEST_RETURN != 0) {
     73 		tst_resm(TFAIL | TTERRNO, "setpriority(%d) failed", new_prio);
     74 		return;
     75 	}
     76 
     77 	priority = getpriority(PRIO_PROCESS, 0);
     78 	if (errno == -1) {
     79 		tst_brkm(TBROK, cleanup,
     80 			 "getpriority call failed - errno = %d - %s", errno,
     81 			 strerror(errno));
     82 	}
     83 
     84 	if (priority == new_prio) {
     85 		tst_resm(TPASS, "setpriority(%d) succeeded", new_prio);
     86 	} else {
     87 		tst_resm(TFAIL,
     88 			 "current priority-%d and new priority-%d do not match",
     89 			 priority, new_prio);
     90 	}
     91 }
     92 
     93 static void cleanup(void)
     94 {
     95 }
     96