My Project: dynamics.mod/NewtonDynamics/source/pthreads.2/tests/test.h Source File

My Project

test.h
Go to the documentation of this file.
1 /*
2 * test.h
3 *
4 * Useful definitions and declarations for tests.
5 *
6 *
7 * --------------------------------------------------------------------------
8 *
9 * Pthreads-win32 - POSIX Threads Library for Win32
10 * Copyright(C) 1998 John E. Bossom
11 * Copyright(C) 1999,2005 Pthreads-win32 contributors
12 *
13 * Contact Email: rpj@callisto.canberra.edu.au
14 *
15 * The current list of contributors is contained
16 * in the file CONTRIBUTORS included with the source
17 * code distribution. The list can also be seen at the
18 * following World Wide Web location:
19 * http://sources.redhat.com/pthreads-win32/contributors.html
20 *
21 * This library is free software; you can redistribute it and/or
22 * modify it under the terms of the GNU Lesser General Public
23 * License as published by the Free Software Foundation; either
24 * version 2 of the License, or (at your option) any later version.
25 *
26 * This library is distributed in the hope that it will be useful,
27 * but WITHOUT ANY WARRANTY; without even the implied warranty of
28 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
29 * Lesser General Public License for more details.
30 *
31 * You should have received a copy of the GNU Lesser General Public
32 * License along with this library in the file COPYING.LIB;
33 * if not, write to the Free Software Foundation, Inc.,
34 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
35 *
36 */
37
38 #ifndef _PTHREAD_TEST_H_
39 #define _PTHREAD_TEST_H_
40
41 #include "pthread.h"
42 #include "sched.h"
43 #include "semaphore.h"
44
45 #include <windows.h>
46 #include <stdio.h>
47
48 #define PTW32_THREAD_NULL_ID {NULL,0}
49
50 /*
51 * Some non-thread POSIX API substitutes
52 */
53 #define rand_r( _seed ) \
54 ( _seed == _seed? rand() : rand() )
55
56 #if defined(__MINGW32__)
57 #include <stdint.h>
58 #elif defined(__BORLANDC__)
59 #define int64_t ULONGLONG
60 #else
61 #define int64_t _int64
62 #endif
63
64 #if defined(_MSC_VER) && _MSC_VER >= 1400
65 # define PTW32_FTIME(x) _ftime64_s(x)
66 # define PTW32_STRUCT_TIMEB struct __timeb64
67 #elif ( defined(_MSC_VER) && _MSC_VER >= 1300 ) || \
68 ( defined(__MINGW32__) && __MSVCRT_VERSION__ >= 0x0601 )
69 # define PTW32_FTIME(x) _ftime64(x)
70 # define PTW32_STRUCT_TIMEB struct __timeb64
71 #else
72 # define PTW32_FTIME(x) _ftime(x)
73 # define PTW32_STRUCT_TIMEB struct _timeb
74 #endif
75
76
77 const char * error_string[] = {
78 "ZERO_or_EOK",
79 "EPERM",
80 "ENOFILE_or_ENOENT",
81 "ESRCH",
82 "EINTR",
83 "EIO",
84 "ENXIO",
85 "E2BIG",
86 "ENOEXEC",
87 "EBADF",
88 "ECHILD",
89 "EAGAIN",
90 "ENOMEM",
91 "EACCES",
92 "EFAULT",
93 "UNKNOWN_15",
94 "EBUSY",
95 "EEXIST",
96 "EXDEV",
97 "ENODEV",
98 "ENOTDIR",
99 "EISDIR",
100 "EINVAL",
101 "ENFILE",
102 "EMFILE",
103 "ENOTTY",
104 "UNKNOWN_26",
105 "EFBIG",
106 "ENOSPC",
107 "ESPIPE",
108 "EROFS",
109 "EMLINK",
110 "EPIPE",
111 "EDOM",
112 "ERANGE",
113 "UNKNOWN_35",
114 "EDEADLOCK_or_EDEADLK",
115 "UNKNOWN_37",
116 "ENAMETOOLONG",
117 "ENOLCK",
118 "ENOSYS",
119 "ENOTEMPTY",
120 "EILSEQ",
121 "EOWNERDEAD",
122 "ENOTRECOVERABLE"
123 };
124
125 /*
126 * The Mingw32 assert macro calls the CRTDLL _assert function
127 * which pops up a dialog. We want to run in batch mode so
128 * we define our own assert macro.
129 */
130 #ifdef assert
131 # undef assert
132 #endif
133
134 #ifndef ASSERT_TRACE
135 # define ASSERT_TRACE 0
136 #else
137 # undef ASSERT_TRACE
138 # define ASSERT_TRACE 1
139 #endif
140
141 # define assert(e) \
142 ((e) ? ((ASSERT_TRACE) ? fprintf(stderr, \
143 "Assertion succeeded: (%s), file %s, line %d\n", \
144 #e, __FILE__, (int) __LINE__), \
145 fflush(stderr) : \
146 0) : \
147 (fprintf(stderr, "Assertion failed: (%s), file %s, line %d\n", \
148 #e, __FILE__, (int) __LINE__), exit(1), 0))
149
150 int assertE;
151 # define assert_e(e, o, r) \
152 (((assertE = e) o (r)) ? ((ASSERT_TRACE) ? fprintf(stderr, \
153 "Assertion succeeded: (%s), file %s, line %d\n", \
154 #e, __FILE__, (int) __LINE__), \
155 fflush(stderr) : \
156 0) : \
157 (fprintf(stderr, "Assertion failed: (%s %s %s), file %s, line %d, error %s\n", \
158 #e,#o,#r, __FILE__, (int) __LINE__, error_string[assertE]), exit(1), 0))
159
160 #endif
161
162 # define BEGIN_MUTEX_STALLED_ROBUST(mxAttr) \
163 for(;;) \
164 { \
165 static int _i=0; \
166 static int _robust; \
167 pthread_mutexattr_getrobust(&(mxAttr), &_robust);
168
169 # define END_MUTEX_STALLED_ROBUST(mxAttr) \
170 printf("Pass %s\n", _robust==PTHREAD_MUTEX_ROBUST?"Robust":"Non-robust"); \
171 if (++_i > 1) \
172 break; \
173 else \
174 { \
175 pthread_mutexattr_t *pma, *pmaEnd; \
176 for(pma = &(mxAttr), pmaEnd = pma + sizeof(mxAttr)/sizeof(pthread_mutexattr_t); \
177 pma < pmaEnd; \
178 pthread_mutexattr_setrobust(pma++, PTHREAD_MUTEX_ROBUST)); \
179 } \
180 }
181
182 # define IS_ROBUST (_robust==PTHREAD_MUTEX_ROBUST)
error_string
const char * error_string[]
Definition: test.h:77
pthread.h
sched.h
semaphore.h
assertE
int assertE
Definition: test.h:150