1 /* 2 * Copyright (c) International Business Machines Corp., 2001 3 * 07/2001 Ported by Wayne Boyer 4 * 11/2016 Modified by Guangwen Feng <fenggw-fnst (at) cn.fujitsu.com> 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 the 14 * 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, see <http://www.gnu.org/licenses/>. 18 */ 19 20 /* 21 * Verify that getpriority(2) succeeds get the scheduling priority of 22 * the current process, process group or user, and the priority values 23 * are in the ranges of [0, 0], [0, 0] and [-20, 0] by default for the 24 * flags PRIO_PROCESS, PRIO_PGRP and PRIO_USER respectively. 25 */ 26 27 #include <errno.h> 28 #include <sys/resource.h> 29 #include <sys/time.h> 30 #include "tst_test.h" 31 32 static struct tcase { 33 int which; 34 int min; 35 int max; 36 } tcases[] = { 37 {PRIO_PROCESS, 0, 0}, 38 {PRIO_PGRP, 0, 0}, 39 {PRIO_USER, -20, 0} 40 }; 41 42 static void verify_getpriority(unsigned int n) 43 { 44 struct tcase *tc = &tcases[n]; 45 46 TEST(getpriority(tc->which, 0)); 47 48 if (TEST_ERRNO != 0) { 49 tst_res(TFAIL | TTERRNO, "getpriority(%d, 0) failed", 50 tc->which); 51 return; 52 } 53 54 if (TEST_RETURN < tc->min || TEST_RETURN > tc->max) { 55 tst_res(TFAIL, "getpriority(%d, 0) returned %ld, " 56 "expected in the range of [%d, %d]", 57 tc->which, TEST_RETURN, tc->min, tc->max); 58 return; 59 } 60 61 tst_res(TPASS, "getpriority(%d, 0) returned %ld", 62 tc->which, TEST_RETURN); 63 } 64 65 static struct tst_test test = { 66 .tid = "getpriority01", 67 .tcnt = ARRAY_SIZE(tcases), 68 .test = verify_getpriority, 69 }; 70