1 /* Test for SEM_VALUE_MAX overflow detection: BZ #18434.
2 Copyright (C) 2015-2016 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/>. */
21 #include <semaphore.h>
32 if (sem_init (&s
, 0, SEM_VALUE_MAX
))
34 printf ("sem_init: %m\n");
40 int value
= 0xdeadbeef;
41 if (sem_getvalue (&s
, &value
))
43 printf ("sem_getvalue: %m\n");
48 printf ("sem_getvalue after init: %d\n", value
);
49 if (value
!= SEM_VALUE_MAX
)
51 printf ("\tshould be %d\n", SEM_VALUE_MAX
);
57 if (sem_post(&s
) == 0)
59 puts ("sem_post at SEM_VALUE_MAX succeeded!");
64 printf ("sem_post at SEM_VALUE_MAX: %m (%d)\n", errno
);
65 if (errno
!= EOVERFLOW
)
67 printf ("\tshould be %s (EOVERFLOW = %d)\n",
68 strerror (EOVERFLOW
), EOVERFLOW
);
74 if (sem_getvalue (&s
, &value
))
76 printf ("sem_getvalue: %m\n");
81 printf ("sem_getvalue after post: %d\n", value
);
82 if (value
!= SEM_VALUE_MAX
)
84 printf ("\tshould be %d\n", SEM_VALUE_MAX
);
91 printf ("sem_destroy: %m\n");
98 #define TEST_FUNCTION do_test ()
99 #include "../test-skeleton.c"