Framework to test IFUNC implementations on target
[glibc.git] / nptl / tst-cond-except.c
blobb9871ba86492395a235b73338a39b5d66c31d0d3
1 /* Verify that exception table for pthread_cond_wait is correct.
2 Copyright (C) 2012 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 <string.h>
22 #include <unistd.h>
24 pthread_mutex_t mutex;
25 pthread_cond_t cond;
27 #define CHECK_RETURN_VAL_OR_FAIL(ret,str) \
28 ({ if ((ret) != 0) \
29 { \
30 printf ("%s failed: %s\n", (str), strerror (ret)); \
31 ret = 1; \
32 goto out; \
33 } \
37 void
38 clean (void *arg)
40 puts ("clean: Unlocking mutex...");
41 pthread_mutex_unlock ((pthread_mutex_t *) arg);
42 puts ("clean: Mutex unlocked...");
45 void *
46 thr (void *arg)
48 int ret = 0;
49 pthread_mutexattr_t mutexAttr;
50 ret = pthread_mutexattr_init (&mutexAttr);
51 CHECK_RETURN_VAL_OR_FAIL (ret, "pthread_mutexattr_init");
53 ret = pthread_mutexattr_setprotocol (&mutexAttr, PTHREAD_PRIO_INHERIT);
54 CHECK_RETURN_VAL_OR_FAIL (ret, "pthread_mutexattr_setprotocol");
56 ret = pthread_mutex_init (&mutex, &mutexAttr);
57 CHECK_RETURN_VAL_OR_FAIL (ret, "pthread_mutex_init");
59 ret = pthread_cond_init (&cond, 0);
60 CHECK_RETURN_VAL_OR_FAIL (ret, "pthread_cond_init");
62 puts ("th: Init done, entering wait...");
64 pthread_cleanup_push (clean, (void *) &mutex);
65 ret = pthread_mutex_lock (&mutex);
66 CHECK_RETURN_VAL_OR_FAIL (ret, "pthread_mutex_lock");
67 while (1)
69 ret = pthread_cond_wait (&cond, &mutex);
70 CHECK_RETURN_VAL_OR_FAIL (ret, "pthread_cond_wait");
72 pthread_cleanup_pop (1);
74 out:
75 return (void *)ret;
78 int
79 do_test ()
81 pthread_t thread;
82 int ret = 0;
83 void *thr_ret = 0;
84 ret = pthread_create (&thread, 0, thr, &thr_ret);
85 CHECK_RETURN_VAL_OR_FAIL (ret, "pthread_create");
87 puts ("main: Thread created, waiting a bit...");
88 sleep (2);
90 puts ("main: Cancelling thread...");
91 ret = pthread_cancel (thread);
92 CHECK_RETURN_VAL_OR_FAIL (ret, "pthread_cancel");
94 puts ("main: Joining th...");
95 ret = pthread_join (thread, NULL);
96 CHECK_RETURN_VAL_OR_FAIL (ret, "pthread_join");
98 if (thr_ret != NULL)
99 return 1;
101 puts ("main: Joined thread, done!");
103 out:
104 return ret;
107 #define TIMEOUT 5
108 #include "../test-skeleton.c"