1f08c3bdfSopenharmony_ci// SPDX-License-Identifier: GPL-2.0-or-later 2f08c3bdfSopenharmony_ci/* 3f08c3bdfSopenharmony_ci * Copyright (c) International Business Machines Corp., 2001 4f08c3bdfSopenharmony_ci * Ported to LTP: Wayne Boyer 5f08c3bdfSopenharmony_ci * Copyright (c) 2016 Cyril Hrubis <chrubis@suse.cz> 6f08c3bdfSopenharmony_ci */ 7f08c3bdfSopenharmony_ci 8f08c3bdfSopenharmony_ci/*\ 9f08c3bdfSopenharmony_ci * [Description] 10f08c3bdfSopenharmony_ci * 11f08c3bdfSopenharmony_ci * Verify that any user can successfully increase the nice value of 12f08c3bdfSopenharmony_ci * the process by passing a higher increment value (> max. applicable limits) 13f08c3bdfSopenharmony_ci * to nice() system call. 14f08c3bdfSopenharmony_ci */ 15f08c3bdfSopenharmony_ci#include <unistd.h> 16f08c3bdfSopenharmony_ci#include <errno.h> 17f08c3bdfSopenharmony_ci#include <sys/resource.h> 18f08c3bdfSopenharmony_ci 19f08c3bdfSopenharmony_ci#include "tst_test.h" 20f08c3bdfSopenharmony_ci 21f08c3bdfSopenharmony_ci#define NICEINC 50 22f08c3bdfSopenharmony_ci#define MAX_PRIO 19 23f08c3bdfSopenharmony_ci#define DEFAULT_PRIO 0 24f08c3bdfSopenharmony_ci 25f08c3bdfSopenharmony_cistatic void verify_nice(void) 26f08c3bdfSopenharmony_ci{ 27f08c3bdfSopenharmony_ci int new_nice; 28f08c3bdfSopenharmony_ci 29f08c3bdfSopenharmony_ci TEST(nice(NICEINC)); 30f08c3bdfSopenharmony_ci 31f08c3bdfSopenharmony_ci if (TST_RET == -1) { 32f08c3bdfSopenharmony_ci tst_res(TFAIL | TTERRNO, "nice(%d) returned -1", NICEINC); 33f08c3bdfSopenharmony_ci return; 34f08c3bdfSopenharmony_ci } 35f08c3bdfSopenharmony_ci 36f08c3bdfSopenharmony_ci if (TST_ERR) { 37f08c3bdfSopenharmony_ci tst_res(TFAIL | TTERRNO, "nice(%d) failed", NICEINC); 38f08c3bdfSopenharmony_ci return; 39f08c3bdfSopenharmony_ci } 40f08c3bdfSopenharmony_ci 41f08c3bdfSopenharmony_ci new_nice = SAFE_GETPRIORITY(PRIO_PROCESS, 0); 42f08c3bdfSopenharmony_ci 43f08c3bdfSopenharmony_ci if (new_nice != MAX_PRIO) { 44f08c3bdfSopenharmony_ci tst_res(TFAIL, "Process priority %i, expected %i", 45f08c3bdfSopenharmony_ci new_nice, MAX_PRIO); 46f08c3bdfSopenharmony_ci return; 47f08c3bdfSopenharmony_ci } 48f08c3bdfSopenharmony_ci 49f08c3bdfSopenharmony_ci tst_res(TPASS, "nice(%d) passed", NICEINC); 50f08c3bdfSopenharmony_ci 51f08c3bdfSopenharmony_ci TEST(nice(DEFAULT_PRIO)); 52f08c3bdfSopenharmony_ci if (TST_ERR) 53f08c3bdfSopenharmony_ci tst_brk(TBROK | TTERRNO, "nice(%d) failed", DEFAULT_PRIO); 54f08c3bdfSopenharmony_ci} 55f08c3bdfSopenharmony_ci 56f08c3bdfSopenharmony_cistatic struct tst_test test = { 57f08c3bdfSopenharmony_ci .test_all = verify_nice, 58f08c3bdfSopenharmony_ci}; 59