summaryrefslogtreecommitdiff
path: root/lib/libc_r/TEST/test_preemption_float.c
diff options
context:
space:
mode:
Diffstat (limited to 'lib/libc_r/TEST/test_preemption_float.c')
-rw-r--r--lib/libc_r/TEST/test_preemption_float.c84
1 files changed, 51 insertions, 33 deletions
diff --git a/lib/libc_r/TEST/test_preemption_float.c b/lib/libc_r/TEST/test_preemption_float.c
index 621297001a5..48246f577ed 100644
--- a/lib/libc_r/TEST/test_preemption_float.c
+++ b/lib/libc_r/TEST/test_preemption_float.c
@@ -7,6 +7,7 @@
#include <pthread.h>
#include <math.h>
#include <stdio.h>
+#include "test.h"
int limit = 2;
int float_passed = 0;
@@ -58,39 +59,56 @@ void *trig_loop (void *x) {
pthread_exit(&float_passed);
}
+int
+floatloop(pthread_attr_t *attrp)
+{
+ pthread_t thread[2];
+ int *x, *y;
+
+ CHECKr(pthread_create (&thread[0], attrp, trig_loop, 0));
+ CHECKr(pthread_create (&thread[1], attrp, log_loop, 0));
+ CHECKr(pthread_join(thread[0], (void **) &x));
+ CHECKr(pthread_join(thread[1], (void **) &y));
+
+ /* Return 0 for success */
+ return ((*y == float_failed)?2:0) |
+ ((*x == float_failed)?1:0);
+}
+
#define N 10
-int main () {
- pthread_t thread[2];
- pthread_attr_t attr;
- int *x, *y;
-
- pthread_attr_init(&attr);
- /* pthread_attr_setfloatstate(&attr, PTHREAD_NOFLOAT); */
-
- while(limit < 100000) {
- pthread_create (&thread[0], &attr, trig_loop, 0);
- pthread_create (&thread[1], &attr, log_loop, 0);
- pthread_join(thread[0], (void **) &x);
- pthread_join(thread[1], (void **) &y);
- if ((*x == float_failed) || (*y == float_failed)) {
- limit *= 4;
- break;
+int
+main()
+{
+ pthread_attr_t attr;
+ int i;
+
+ /* Try with float point state not preserved */
+
+ CHECKr(pthread_attr_init(&attr));
+ CHECKr(pthread_attr_setfloatstate(&attr, PTHREAD_NOFLOAT));
+
+ for(limit = 2; limit < 100000; limit *=4)
+ if (floatloop(&attr) != 0)
+ break;
+
+ if (limit >= 100000) {
+ printf("results are INDETERMINATE\n");
+ SUCCEED; /* XXX */
}
- limit *= 4;
- }
- if ((*x == float_passed) && (*y == float_passed)) {
- printf("test_preemption_float INDETERMINATE\n");
- return(0);
- }
- pthread_create (&thread[0], NULL, trig_loop, 0);
- pthread_create (&thread[1], NULL, log_loop, 0);
- pthread_join(thread[0], (void **) &x);
- pthread_join(thread[1], (void **) &y);
-
- if ((*x == float_failed) || (*y == float_failed)) {
- printf("test_preemption_float FAILED\n");
- return(1);
- }
- printf("test_preemption_float PASSED\n");
- return(0);
+
+ limit *= 4; /* just to make sure */
+
+ printf("using limit = %d\n", limit);
+
+ for (i = 0; i < 32; i++) {
+ /* Try the failure mode one more time. */
+ if (floatloop(&attr) == 0) {
+ printf("%d ", i);
+ fflush(stdout);
+ }
+ /* Now see if saving float state will get rid of failure. */
+ ASSERT(floatloop(NULL) == 0);
+ }
+
+ SUCCEED;
}