mirror of
https://sourceware.org/git/glibc.git
synced 2024-11-23 17:53:37 +08:00
30891f35fa
We stopped adding "Contributed by" or similar lines in sources in 2012 in favour of git logs and keeping the Contributors section of the glibc manual up to date. Removing these lines makes the license header a bit more consistent across files and also removes the possibility of error in attribution when license blocks or files are copied across since the contributed-by lines don't actually reflect reality in those cases. Move all "Contributed by" and similar lines (Written by, Test by, etc.) into a new file CONTRIBUTED-BY to retain record of these contributions. These contributors are also mentioned in manual/contrib.texi, so we just maintain this additional record as a courtesy to the earlier developers. The following scripts were used to filter a list of files to edit in place and to clean up the CONTRIBUTED-BY file respectively. These were not added to the glibc sources because they're not expected to be of any use in future given that this is a one time task: https://gist.github.com/siddhesh/b5ecac94eabfd72ed2916d6d8157e7dc https://gist.github.com/siddhesh/15ea1f5e435ace9774f485030695ee02 Reviewed-by: Carlos O'Donell <carlos@redhat.com>
333 lines
6.9 KiB
C
333 lines
6.9 KiB
C
/* Copyright (C) 2006-2021 Free Software Foundation, Inc.
|
|
This file is part of the GNU C Library.
|
|
|
|
The GNU C Library is free software; you can redistribute it and/or
|
|
modify it under the terms of the GNU Lesser General Public
|
|
License as published by the Free Software Foundation; either
|
|
version 2.1 of the License, or (at your option) any later version.
|
|
|
|
The GNU C Library is distributed in the hope that it will be useful,
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
Lesser General Public License for more details.
|
|
|
|
You should have received a copy of the GNU Lesser General Public
|
|
License along with the GNU C Library; if not, see
|
|
<https://www.gnu.org/licenses/>. */
|
|
|
|
#include <errno.h>
|
|
#include <limits.h>
|
|
#include <pthread.h>
|
|
#include <sched.h>
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
#include <unistd.h>
|
|
|
|
#include "tst-tpp.h"
|
|
|
|
static int
|
|
do_test (void)
|
|
{
|
|
int ret = 0;
|
|
|
|
init_tpp_test ();
|
|
|
|
pthread_mutexattr_t ma;
|
|
if (pthread_mutexattr_init (&ma))
|
|
{
|
|
puts ("mutexattr_init failed");
|
|
return 1;
|
|
}
|
|
if (pthread_mutexattr_setprotocol (&ma, PTHREAD_PRIO_PROTECT))
|
|
{
|
|
puts ("mutexattr_setprotocol failed");
|
|
return 1;
|
|
}
|
|
|
|
int prioceiling;
|
|
if (pthread_mutexattr_getprioceiling (&ma, &prioceiling))
|
|
{
|
|
puts ("mutexattr_getprioceiling failed");
|
|
return 1;
|
|
}
|
|
|
|
if (prioceiling < fifo_min || prioceiling > fifo_max)
|
|
{
|
|
printf ("prioceiling %d not in %d..%d range\n",
|
|
prioceiling, fifo_min, fifo_max);
|
|
return 1;
|
|
}
|
|
|
|
if (fifo_max < INT_MAX
|
|
&& pthread_mutexattr_setprioceiling (&ma, fifo_max + 1) != EINVAL)
|
|
{
|
|
printf ("mutexattr_setprioceiling %d did not fail with EINVAL\n",
|
|
fifo_max + 1);
|
|
return 1;
|
|
}
|
|
|
|
if (fifo_min > 0
|
|
&& pthread_mutexattr_setprioceiling (&ma, fifo_min - 1) != EINVAL)
|
|
{
|
|
printf ("mutexattr_setprioceiling %d did not fail with EINVAL\n",
|
|
fifo_min - 1);
|
|
return 1;
|
|
}
|
|
|
|
if (pthread_mutexattr_setprioceiling (&ma, fifo_min))
|
|
{
|
|
puts ("mutexattr_setprioceiling failed");
|
|
return 1;
|
|
}
|
|
|
|
if (pthread_mutexattr_setprioceiling (&ma, fifo_max))
|
|
{
|
|
puts ("mutexattr_setprioceiling failed");
|
|
return 1;
|
|
}
|
|
|
|
if (pthread_mutexattr_setprioceiling (&ma, 6))
|
|
{
|
|
puts ("mutexattr_setprioceiling failed");
|
|
return 1;
|
|
}
|
|
|
|
if (pthread_mutexattr_getprioceiling (&ma, &prioceiling))
|
|
{
|
|
puts ("mutexattr_getprioceiling failed");
|
|
return 1;
|
|
}
|
|
|
|
if (prioceiling != 6)
|
|
{
|
|
printf ("mutexattr_getprioceiling returned %d != 6\n",
|
|
prioceiling);
|
|
return 1;
|
|
}
|
|
|
|
pthread_mutex_t m1, m2, m3;
|
|
int e = pthread_mutex_init (&m1, &ma);
|
|
if (e == ENOTSUP)
|
|
{
|
|
puts ("cannot support selected type of mutexes");
|
|
return 0;
|
|
}
|
|
else if (e != 0)
|
|
{
|
|
puts ("mutex_init failed");
|
|
return 1;
|
|
}
|
|
|
|
if (pthread_mutexattr_setprioceiling (&ma, 8))
|
|
{
|
|
puts ("mutexattr_setprioceiling failed");
|
|
return 1;
|
|
}
|
|
|
|
if (pthread_mutex_init (&m2, &ma))
|
|
{
|
|
puts ("mutex_init failed");
|
|
return 1;
|
|
}
|
|
|
|
if (pthread_mutexattr_setprioceiling (&ma, 5))
|
|
{
|
|
puts ("mutexattr_setprioceiling failed");
|
|
return 1;
|
|
}
|
|
|
|
if (pthread_mutex_init (&m3, &ma))
|
|
{
|
|
puts ("mutex_init failed");
|
|
return 1;
|
|
}
|
|
|
|
CHECK_TPP_PRIORITY (4, 4);
|
|
|
|
if (pthread_mutex_lock (&m1) != 0)
|
|
{
|
|
puts ("mutex_lock failed");
|
|
return 1;
|
|
}
|
|
|
|
CHECK_TPP_PRIORITY (4, 6);
|
|
|
|
if (pthread_mutex_trylock (&m2) != 0)
|
|
{
|
|
puts ("mutex_lock failed");
|
|
return 1;
|
|
}
|
|
|
|
CHECK_TPP_PRIORITY (4, 8);
|
|
|
|
if (pthread_mutex_lock (&m3) != 0)
|
|
{
|
|
puts ("mutex_lock failed");
|
|
return 1;
|
|
}
|
|
|
|
CHECK_TPP_PRIORITY (4, 8);
|
|
|
|
if (pthread_mutex_unlock (&m2) != 0)
|
|
{
|
|
puts ("mutex_unlock failed");
|
|
return 1;
|
|
}
|
|
|
|
CHECK_TPP_PRIORITY (4, 6);
|
|
|
|
if (pthread_mutex_unlock (&m1) != 0)
|
|
{
|
|
puts ("mutex_unlock failed");
|
|
return 1;
|
|
}
|
|
|
|
CHECK_TPP_PRIORITY (4, 5);
|
|
|
|
if (pthread_mutex_lock (&m2) != 0)
|
|
{
|
|
puts ("mutex_lock failed");
|
|
return 1;
|
|
}
|
|
|
|
CHECK_TPP_PRIORITY (4, 8);
|
|
|
|
if (pthread_mutex_unlock (&m2) != 0)
|
|
{
|
|
puts ("mutex_unlock failed");
|
|
return 1;
|
|
}
|
|
|
|
CHECK_TPP_PRIORITY (4, 5);
|
|
|
|
if (pthread_mutex_getprioceiling (&m1, &prioceiling))
|
|
{
|
|
puts ("mutex_getprioceiling m1 failed");
|
|
return 1;
|
|
}
|
|
else if (prioceiling != 6)
|
|
{
|
|
printf ("unexpected m1 prioceiling %d != 6\n", prioceiling);
|
|
return 1;
|
|
}
|
|
|
|
if (pthread_mutex_getprioceiling (&m2, &prioceiling))
|
|
{
|
|
puts ("mutex_getprioceiling m2 failed");
|
|
return 1;
|
|
}
|
|
else if (prioceiling != 8)
|
|
{
|
|
printf ("unexpected m2 prioceiling %d != 8\n", prioceiling);
|
|
return 1;
|
|
}
|
|
|
|
if (pthread_mutex_getprioceiling (&m3, &prioceiling))
|
|
{
|
|
puts ("mutex_getprioceiling m3 failed");
|
|
return 1;
|
|
}
|
|
else if (prioceiling != 5)
|
|
{
|
|
printf ("unexpected m3 prioceiling %d != 5\n", prioceiling);
|
|
return 1;
|
|
}
|
|
|
|
if (pthread_mutex_setprioceiling (&m1, 7, &prioceiling))
|
|
{
|
|
printf ("mutex_setprioceiling failed");
|
|
return 1;
|
|
}
|
|
else if (prioceiling != 6)
|
|
{
|
|
printf ("unexpected m1 old prioceiling %d != 6\n", prioceiling);
|
|
return 1;
|
|
}
|
|
|
|
if (pthread_mutex_getprioceiling (&m1, &prioceiling))
|
|
{
|
|
puts ("mutex_getprioceiling m1 failed");
|
|
return 1;
|
|
}
|
|
else if (prioceiling != 7)
|
|
{
|
|
printf ("unexpected m1 prioceiling %d != 7\n", prioceiling);
|
|
return 1;
|
|
}
|
|
|
|
CHECK_TPP_PRIORITY (4, 5);
|
|
|
|
if (pthread_mutex_unlock (&m3) != 0)
|
|
{
|
|
puts ("mutex_unlock failed");
|
|
return 1;
|
|
}
|
|
|
|
CHECK_TPP_PRIORITY (4, 4);
|
|
|
|
if (pthread_mutex_trylock (&m1) != 0)
|
|
{
|
|
puts ("mutex_lock failed");
|
|
return 1;
|
|
}
|
|
|
|
CHECK_TPP_PRIORITY (4, 7);
|
|
|
|
struct sched_param sp;
|
|
memset (&sp, 0, sizeof (sp));
|
|
sp.sched_priority = 8;
|
|
if (pthread_setschedparam (pthread_self (), SCHED_FIFO, &sp))
|
|
{
|
|
puts ("cannot set scheduling params");
|
|
return 1;
|
|
}
|
|
|
|
CHECK_TPP_PRIORITY (8, 8);
|
|
|
|
if (pthread_mutex_unlock (&m1) != 0)
|
|
{
|
|
puts ("mutex_unlock failed");
|
|
return 1;
|
|
}
|
|
|
|
CHECK_TPP_PRIORITY (8, 8);
|
|
|
|
if (pthread_mutex_lock (&m3) != EINVAL)
|
|
{
|
|
puts ("pthread_mutex_lock didn't fail with EINVAL");
|
|
return 1;
|
|
}
|
|
|
|
CHECK_TPP_PRIORITY (8, 8);
|
|
|
|
if (pthread_mutex_destroy (&m1) != 0)
|
|
{
|
|
puts ("mutex_destroy failed");
|
|
return 1;
|
|
}
|
|
|
|
if (pthread_mutex_destroy (&m2) != 0)
|
|
{
|
|
puts ("mutex_destroy failed");
|
|
return 1;
|
|
}
|
|
|
|
if (pthread_mutex_destroy (&m3) != 0)
|
|
{
|
|
puts ("mutex_destroy failed");
|
|
return 1;
|
|
}
|
|
|
|
if (pthread_mutexattr_destroy (&ma) != 0)
|
|
{
|
|
puts ("mutexattr_destroy failed");
|
|
return 1;
|
|
}
|
|
|
|
return ret;
|
|
}
|
|
|
|
#define TEST_FUNCTION do_test ()
|
|
#include "../test-skeleton.c"
|