|
Packit |
6c4009 |
/* Copyright (C) 2003-2018 Free Software Foundation, Inc.
|
|
Packit |
6c4009 |
This file is part of the GNU C Library.
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
The GNU C Library is free software; you can redistribute it and/or
|
|
Packit |
6c4009 |
modify it under the terms of the GNU Lesser General Public
|
|
Packit |
6c4009 |
License as published by the Free Software Foundation; either
|
|
Packit |
6c4009 |
version 2.1 of the License, or (at your option) any later version.
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
The GNU C Library is distributed in the hope that it will be useful,
|
|
Packit |
6c4009 |
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
Packit |
6c4009 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
Packit |
6c4009 |
Lesser General Public License for more details.
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
You should have received a copy of the GNU Lesser General Public
|
|
Packit |
6c4009 |
License along with the GNU C Library; if not, see
|
|
Packit |
6c4009 |
<http://www.gnu.org/licenses/>. */
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
#include <errno.h>
|
|
Packit |
6c4009 |
#include <stdio.h>
|
|
Packit |
6c4009 |
#include <unistd.h>
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
/* Test that nice() does not incorrectly return 0. */
|
|
Packit |
6c4009 |
static int
|
|
Packit |
6c4009 |
do_test (void)
|
|
Packit |
6c4009 |
{
|
|
Packit |
6c4009 |
int ret;
|
|
Packit |
6c4009 |
const int incr = 10;
|
|
Packit |
6c4009 |
int old;
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
/* Discover current nice value. */
|
|
Packit |
6c4009 |
errno = 0;
|
|
Packit |
6c4009 |
old = nice (0);
|
|
Packit |
6c4009 |
if (old == -1 && errno != 0)
|
|
Packit |
6c4009 |
{
|
|
Packit |
6c4009 |
printf ("break: nice(%d) return: %d, %m\n", 0, old);
|
|
Packit |
6c4009 |
return 1;
|
|
Packit |
6c4009 |
}
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
/* Nice ourselves up. */
|
|
Packit |
6c4009 |
errno = 0;
|
|
Packit |
6c4009 |
ret = nice (incr);
|
|
Packit |
6c4009 |
if (ret == -1 && errno != 0)
|
|
Packit |
6c4009 |
{
|
|
Packit |
6c4009 |
printf ("break: nice(%d) return: %d, %m\n", incr, ret);
|
|
Packit |
6c4009 |
return 1;
|
|
Packit |
6c4009 |
}
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
/* Check for return value being zero when it shouldn't. Cannot simply
|
|
Packit |
6c4009 |
check for expected value since nice values are capped at 2^n-1.
|
|
Packit |
6c4009 |
But we assume that we didn't start at the cap and so should have
|
|
Packit |
6c4009 |
increased some. */
|
|
Packit |
6c4009 |
if (ret <= old)
|
|
Packit |
6c4009 |
{
|
|
Packit |
6c4009 |
printf ("FAIL: retval (%d) of nice(%d) != %d\n", ret, incr, old + incr);
|
|
Packit |
6c4009 |
return 1;
|
|
Packit |
6c4009 |
}
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
/* BZ #18086. Make sure we don't reset errno. */
|
|
Packit |
6c4009 |
errno = EBADF;
|
|
Packit |
6c4009 |
nice (0);
|
|
Packit |
6c4009 |
if (errno != EBADF)
|
|
Packit |
6c4009 |
{
|
|
Packit |
6c4009 |
printf ("FAIL: errno = %i, but wanted EBADF (%i)\n", errno, EBADF);
|
|
Packit |
6c4009 |
return 1;
|
|
Packit |
6c4009 |
}
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
printf ("PASS: nice(%d) from %d return: %d\n", incr, old, ret);
|
|
Packit |
6c4009 |
return 0;
|
|
Packit |
6c4009 |
}
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
#define TEST_FUNCTION do_test ()
|
|
Packit |
6c4009 |
#include "../test-skeleton.c"
|