Home | History | Annotate | Download | only in nice
      1 /*
      2  * Copyright (c) International Business Machines  Corp., 2001
      3  *  07/2001 Ported by Wayne Boyer
      4  * Copyright (c) 2016 Cyril Hrubis <chrubis (at) suse.cz>
      5  *
      6  * This program is free software;  you can redistribute it and/or modify
      7  * it under the terms of the GNU General Public License as published by
      8  * the Free Software Foundation; either version 2 of the License, or
      9  * (at your option) any later version.
     10  *
     11  * This program is distributed in the hope that it will be useful,
     12  * but WITHOUT ANY WARRANTY;  without even the implied warranty of
     13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
     14  * the GNU General Public License for more details.
     15  *
     16  * You should have received a copy of the GNU General Public License
     17  * along with this program;  if not, write to the Free Software Foundation,
     18  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
     19  */
     20 /*
     21  *  Verify that any user can successfully increase the nice value of
     22  *  the process by passing an increment value (< max. applicable limits) to
     23  *  nice() system call.
     24  */
     25 #include <unistd.h>
     26 #include <stdlib.h>
     27 #include <errno.h>
     28 #include <sys/resource.h>
     29 #include "tst_test.h"
     30 
     31 #define	NICEINC	2
     32 
     33 static void nice_test(void)
     34 {
     35 	int new_nice;
     36 	int orig_nice;
     37 
     38 	orig_nice = SAFE_GETPRIORITY(PRIO_PROCESS, 0);
     39 
     40 	TEST(nice(NICEINC));
     41 
     42 	if (TST_RET == -1) {
     43 		tst_res(TFAIL | TTERRNO, "nice(%d) returned -1", NICEINC);
     44 		return;
     45 	}
     46 
     47 	if (TST_ERR) {
     48 		tst_res(TFAIL | TTERRNO, "nice(%d) failed", NICEINC);
     49 		return;
     50 	}
     51 
     52 	new_nice = SAFE_GETPRIORITY(PRIO_PROCESS, 0);
     53 
     54 	if (new_nice != (orig_nice + NICEINC)) {
     55 		tst_res(TFAIL, "Process priority %i, expected %i",
     56 		        new_nice, orig_nice + NICEINC);
     57 		return;
     58 	}
     59 
     60 	tst_res(TPASS, "nice(%d) passed", NICEINC);
     61 
     62 	exit(0);
     63 }
     64 
     65 static void verify_nice(void)
     66 {
     67 	if (!SAFE_FORK())
     68 		nice_test();
     69 
     70 	tst_reap_children();
     71 }
     72 
     73 static struct tst_test test = {
     74 	.forks_child = 1,
     75 	.test_all = verify_nice,
     76 };
     77