1 /* Test that pthread_create diagnoses invalid scheduling parameters.
2 Copyright (C) 2014-2015 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
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/>. */
28 thread_function (void *arg
)
37 #if !defined SCHED_FIFO || !defined SCHED_OTHER
38 puts ("SCHED_FIFO or SCHED_OTHER not available at compile time");
44 #define TRY(func, arglist) \
45 if ((err = func arglist) != 0) \
47 printf ("%s: %s\n", #func, strerror (err)); \
51 int fifo_max
= sched_get_priority_max (SCHED_FIFO
);
54 assert (errno
== ENOTSUP
|| errno
== ENOSYS
);
55 puts ("SCHED_FIFO not supported, cannot test");
59 int other_max
= sched_get_priority_max (SCHED_OTHER
);
62 assert (errno
== ENOTSUP
|| errno
== ENOSYS
);
63 puts ("SCHED_OTHER not supported, cannot test");
67 assert (fifo_max
> other_max
);
70 TRY (pthread_attr_init
, (&attr
));
71 TRY (pthread_attr_setinheritsched
, (&attr
, PTHREAD_EXPLICIT_SCHED
));
72 TRY (pthread_attr_setschedpolicy
, (&attr
, SCHED_FIFO
));
74 /* This value is chosen so as to be valid for SCHED_FIFO but invalid for
76 struct sched_param param
= { .sched_priority
= other_max
+ 1 };
77 TRY (pthread_attr_setschedparam
, (&attr
, ¶m
));
79 TRY (pthread_attr_setschedpolicy
, (&attr
, SCHED_OTHER
));
81 /* Now ATTR has a sched_param that is invalid for its policy. */
83 err
= pthread_create (&th
, &attr
, &thread_function
, NULL
);
86 printf ("pthread_create returned %d (%s), expected %d (EINVAL: %s)\n",
87 err
, strerror (err
), EINVAL
, strerror (EINVAL
));
96 #define TEST_FUNCTION do_test ()
97 #include "../test-skeleton.c"