summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorrpj <rpj>2005-03-16 01:33:20 +0000
committerrpj <rpj>2005-03-16 01:33:20 +0000
commit37f6fe772e5779120d2ee372c5d51ff60b6801dc (patch)
treeb611e6b1c26e36a32e761962ab6693b02744c784 /tests
parent3d32060783bcaf10f38ff6eef6fcf5711bfeada4 (diff)
Diffstat (limited to 'tests')
-rw-r--r--tests/ChangeLog7
-rw-r--r--tests/mutex5.c18
-rw-r--r--tests/test.h9
3 files changed, 22 insertions, 12 deletions
diff --git a/tests/ChangeLog b/tests/ChangeLog
index 321adc3..edf7ded 100644
--- a/tests/ChangeLog
+++ b/tests/ChangeLog
@@ -1,10 +1,11 @@
-2005-03-12 Ross Johnson <rpj@callisto.canberra.edu.au>
+2005-03-16 Ross Johnson <rpj@callisto.canberra.edu.au>
+ * mutex5.c: Prevent optimiser from removing asserts.
* once3.c: New test.
-2005-03-08 Ross Johnson <rpj@callisto.canberra.edu.au>
+2005-03-08 Ross Johnson <rpj@callisto.canberra.edu.au>
- * once2.c: New test.
+ * once2.c: New test.
2004-11-19 Ross Johnson <rpj@callisto.canberra.edu.au>
diff --git a/tests/mutex5.c b/tests/mutex5.c
index a597892..a71f9d8 100644
--- a/tests/mutex5.c
+++ b/tests/mutex5.c
@@ -41,19 +41,23 @@
static pthread_mutexattr_t mxAttr;
+/* Prevent optimiser from removing dead or obvious asserts. */
+int _optimiseFoil;
+#define FOIL(x) (_optimiseFoil = x)
+
int
main()
{
int mxType = -1;
- assert(PTHREAD_MUTEX_DEFAULT == PTHREAD_MUTEX_NORMAL);
- assert(PTHREAD_MUTEX_DEFAULT != PTHREAD_MUTEX_ERRORCHECK);
- assert(PTHREAD_MUTEX_DEFAULT != PTHREAD_MUTEX_RECURSIVE);
- assert(PTHREAD_MUTEX_RECURSIVE != PTHREAD_MUTEX_ERRORCHECK);
+ assert(FOIL(PTHREAD_MUTEX_DEFAULT) == PTHREAD_MUTEX_NORMAL);
+ assert(FOIL(PTHREAD_MUTEX_DEFAULT) != PTHREAD_MUTEX_ERRORCHECK);
+ assert(FOIL(PTHREAD_MUTEX_DEFAULT) != PTHREAD_MUTEX_RECURSIVE);
+ assert(FOIL(PTHREAD_MUTEX_RECURSIVE) != PTHREAD_MUTEX_ERRORCHECK);
- assert(PTHREAD_MUTEX_NORMAL == PTHREAD_MUTEX_FAST_NP);
- assert(PTHREAD_MUTEX_RECURSIVE == PTHREAD_MUTEX_RECURSIVE_NP);
- assert(PTHREAD_MUTEX_ERRORCHECK == PTHREAD_MUTEX_ERRORCHECK_NP);
+ assert(FOIL(PTHREAD_MUTEX_NORMAL) == PTHREAD_MUTEX_FAST_NP);
+ assert(FOIL(PTHREAD_MUTEX_RECURSIVE) == PTHREAD_MUTEX_RECURSIVE_NP);
+ assert(FOIL(PTHREAD_MUTEX_ERRORCHECK) == PTHREAD_MUTEX_ERRORCHECK_NP);
assert(pthread_mutexattr_init(&mxAttr) == 0);
assert(pthread_mutexattr_gettype(&mxAttr, &mxType) == 0);
diff --git a/tests/test.h b/tests/test.h
index a664bb6..11498cd 100644
--- a/tests/test.h
+++ b/tests/test.h
@@ -109,8 +109,13 @@ char * error_string[] = {
# define ASSERT_TRACE 1
#endif
+/*
+ * Trick to force the compiler to not optimise out dead or obvious expressions.
+ */
+int ptw32_assert_force = 1;
+
# define assert(e) \
- ((e) ? ((ASSERT_TRACE) ? fprintf(stderr, \
+ (ptw32_assert_force && (e) ? ((ASSERT_TRACE) ? fprintf(stderr, \
"Assertion succeeded: (%s), file %s, line %d\n", \
#e, __FILE__, (int) __LINE__), \
fflush(stderr) : \
@@ -120,7 +125,7 @@ char * error_string[] = {
int assertE;
# define assert_e(e, o, r) \
- (((assertE = e) o (r)) ? ((ASSERT_TRACE) ? fprintf(stderr, \
+ (ptw32_assert_force && ((assertE = e) o (r)) ? ((ASSERT_TRACE) ? fprintf(stderr, \
"Assertion succeeded: (%s), file %s, line %d\n", \
#e, __FILE__, (int) __LINE__), \
fflush(stderr) : \