Add build-many-glibcs.py arm-linux-gnueabihf-v7{-disable-multiarch}
[glibc.git] / nptl / tst-robust10.c
blobc56b420b013552d0e9ab2ab6910059021c03a913
1 /* Test that pthread_mutex_timedlock properly times out.
2 Copyright (C) 2016-2017 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/>. */
19 #include <pthread.h>
20 #include <stdio.h>
21 #include <stdlib.h>
22 #include <string.h>
23 #include <errno.h>
25 pthread_mutex_t mutex;
27 static void *
28 thr (void *arg)
30 struct timespec abstime;
31 clock_gettime (CLOCK_REALTIME, &abstime);
32 abstime.tv_sec += 1;
33 int ret = pthread_mutex_timedlock (&mutex, &abstime);
34 if (ret == 0)
36 puts ("mutex_timedlock didn't fail");
37 exit (1);
39 if (ret != ETIMEDOUT)
41 printf ("mutex_timedlock failed: %s\n", strerror (ret));
42 exit (1);
45 return 0;
48 static int
49 do_test (void)
51 pthread_t pt;
52 pthread_mutexattr_t ma;
54 if (pthread_mutexattr_init (&ma) != 0)
56 puts ("mutexattr_init failed");
57 return 0;
59 if (pthread_mutexattr_setrobust_np (&ma, PTHREAD_MUTEX_ROBUST_NP) != 0)
61 puts ("mutexattr_setrobust failed");
62 return 1;
64 if (pthread_mutex_init (&mutex, &ma))
66 puts ("mutex_init failed");
67 return 1;
70 if (pthread_mutexattr_destroy (&ma))
72 puts ("mutexattr_destroy failed");
73 return 1;
76 if (pthread_mutex_lock (&mutex))
78 puts ("mutex_lock failed");
79 return 1;
82 if (pthread_create (&pt, NULL, thr, NULL))
84 puts ("pthread_create failed");
85 return 1;
88 if (pthread_join (pt, NULL))
90 puts ("pthread_join failed");
91 return 1;
94 if (pthread_mutex_unlock (&mutex))
96 puts ("mutex_unlock failed");
97 return 1;
100 if (pthread_mutex_destroy (&mutex))
102 puts ("mutex_destroy failed");
103 return 1;
106 return 0;
109 #define TEST_FUNCTION do_test ()
110 #include "../test-skeleton.c"