Update copyright dates with scripts/update-copyrights.
[glibc.git] / nptl / tst-tpp.h
blob5c6c2f650ad5a723b2559f7c2cf277fb047c56f9
1 /* Copyright (C) 2006-2015 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
3 Contributed by Jakub Jelinek <jakub@redhat.com>, 2006.
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, see
17 <http://www.gnu.org/licenses/>. */
19 #include <errno.h>
20 #include <pthread.h>
21 #include <sched.h>
22 #include <stdio.h>
23 #include <stdlib.h>
24 #include <string.h>
25 #include <unistd.h>
26 #include <sys/syscall.h>
28 /* This test is Linux specific. */
29 #define CHECK_TPP_PRIORITY(normal, boosted) \
30 do \
31 { \
32 pid_t tid = syscall (__NR_gettid); \
34 struct sched_param cep_sp; \
35 int cep_policy; \
36 if (pthread_getschedparam (pthread_self (), &cep_policy, \
37 &cep_sp) != 0) \
38 { \
39 puts ("getschedparam failed"); \
40 ret = 1; \
41 } \
42 else if (cep_sp.sched_priority != (normal)) \
43 { \
44 printf ("unexpected priority %d != %d\n", \
45 cep_sp.sched_priority, (normal)); \
46 } \
47 if (syscall (__NR_sched_getparam, tid, &cep_sp) == 0 \
48 && cep_sp.sched_priority != (boosted)) \
49 { \
50 printf ("unexpected boosted priority %d != %d\n", \
51 cep_sp.sched_priority, (boosted)); \
52 ret = 1; \
53 } \
54 } \
55 while (0)
57 int fifo_min, fifo_max;
59 void
60 init_tpp_test (void)
62 fifo_min = sched_get_priority_min (SCHED_FIFO);
63 if (fifo_min < 0)
65 printf ("couldn't get min priority for SCHED_FIFO: %m\n");
66 exit (1);
69 fifo_max = sched_get_priority_max (SCHED_FIFO);
70 if (fifo_max < 0)
72 printf ("couldn't get max priority for SCHED_FIFO: %m\n");
73 exit (1);
76 if (fifo_min > 4 || fifo_max < 10)
78 printf ("%d..%d SCHED_FIFO priority interval not suitable for this test\n",
79 fifo_min, fifo_max);
80 exit (0);
83 struct sched_param sp;
84 memset (&sp, 0, sizeof (sp));
85 sp.sched_priority = 4;
86 int e = pthread_setschedparam (pthread_self (), SCHED_FIFO, &sp);
87 if (e != 0)
89 errno = e;
90 printf ("cannot set scheduling params: %m\n");
91 exit (0);