2.12.90-14
[glibc.git] / nptl / tst-tpp.h
blobc5844b26ddb95e4db01916e200fb35434b50ea8b
1 /* Copyright (C) 2006 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, write to the Free
17 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
18 02111-1307 USA. */
20 #include <errno.h>
21 #include <pthread.h>
22 #include <sched.h>
23 #include <stdio.h>
24 #include <stdlib.h>
25 #include <string.h>
26 #include <unistd.h>
27 #include <sys/syscall.h>
29 /* This test is Linux specific. */
30 #define CHECK_TPP_PRIORITY(normal, boosted) \
31 do \
32 { \
33 pid_t tid = syscall (__NR_gettid); \
35 struct sched_param cep_sp; \
36 int cep_policy; \
37 if (pthread_getschedparam (pthread_self (), &cep_policy, \
38 &cep_sp) != 0) \
39 { \
40 puts ("getschedparam failed"); \
41 ret = 1; \
42 } \
43 else if (cep_sp.sched_priority != (normal)) \
44 { \
45 printf ("unexpected priority %d != %d\n", \
46 cep_sp.sched_priority, (normal)); \
47 } \
48 if (syscall (__NR_sched_getparam, tid, &cep_sp) == 0 \
49 && cep_sp.sched_priority != (boosted)) \
50 { \
51 printf ("unexpected boosted priority %d != %d\n", \
52 cep_sp.sched_priority, (boosted)); \
53 ret = 1; \
54 } \
55 } \
56 while (0)
58 int fifo_min, fifo_max;
60 void
61 init_tpp_test (void)
63 fifo_min = sched_get_priority_min (SCHED_FIFO);
64 if (fifo_min < 0)
66 printf ("couldn't get min priority for SCHED_FIFO: %m\n");
67 exit (1);
70 fifo_max = sched_get_priority_max (SCHED_FIFO);
71 if (fifo_max < 0)
73 printf ("couldn't get max priority for SCHED_FIFO: %m\n");
74 exit (1);
77 if (fifo_min > 4 || fifo_max < 10)
79 printf ("%d..%d SCHED_FIFO priority interval not suitable for this test\n",
80 fifo_min, fifo_max);
81 exit (0);
84 struct sched_param sp;
85 memset (&sp, 0, sizeof (sp));
86 sp.sched_priority = 4;
87 int e = pthread_setschedparam (pthread_self (), SCHED_FIFO, &sp);
88 if (e != 0)
90 errno = e;
91 printf ("cannot set scheduling params: %m\n");
92 exit (0);