Subversion Repositories HelenOS

Rev

Rev 3918 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 3918 Rev 4055
1
/*
1
/*
2
 * Copyright (c) 2005 Jakub Vana
2
 * Copyright (c) 2005 Jakub Vana
3
 * Copyright (c) 2005 Jakub Jermar
3
 * Copyright (c) 2005 Jakub Jermar
4
 * All rights reserved.
4
 * All rights reserved.
5
 *
5
 *
6
 * Redistribution and use in source and binary forms, with or without
6
 * Redistribution and use in source and binary forms, with or without
7
 * modification, are permitted provided that the following conditions
7
 * modification, are permitted provided that the following conditions
8
 * are met:
8
 * are met:
9
 *
9
 *
10
 * - Redistributions of source code must retain the above copyright
10
 * - Redistributions of source code must retain the above copyright
11
 *   notice, this list of conditions and the following disclaimer.
11
 *   notice, this list of conditions and the following disclaimer.
12
 * - Redistributions in binary form must reproduce the above copyright
12
 * - Redistributions in binary form must reproduce the above copyright
13
 *   notice, this list of conditions and the following disclaimer in the
13
 *   notice, this list of conditions and the following disclaimer in the
14
 *   documentation and/or other materials provided with the distribution.
14
 *   documentation and/or other materials provided with the distribution.
15
 * - The name of the author may not be used to endorse or promote products
15
 * - The name of the author may not be used to endorse or promote products
16
 *   derived from this software without specific prior written permission.
16
 *   derived from this software without specific prior written permission.
17
 *
17
 *
18
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
19
 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19
 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
20
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21
 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21
 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
22
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
23
 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23
 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
27
 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27
 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28
 */
28
 */
29
 
29
 
30
#include <print.h>
30
#include <print.h>
31
#include <debug.h>
31
#include <debug.h>
32
 
32
 
33
#include <test.h>
33
#include <test.h>
34
#include <atomic.h>
34
#include <atomic.h>
35
#include <proc/thread.h>
35
#include <proc/thread.h>
36
 
36
 
37
#include <arch.h>
37
#include <arch.h>
38
#include <arch/arch.h>
38
#include <arch/arch.h>
39
 
39
 
40
 
40
 
41
#define THREADS   150
41
#define THREADS   150
42
#define ATTEMPTS  100
42
#define ATTEMPTS  100
43
 
43
 
44
#define E_10e8   271828182
44
#define E_10e8   271828182
45
#define PI_10e8  3141592
45
#define PI_10e8  3141592
46
 
46
 
47
static inline long double sqrt(long double a)
47
static inline long double sqrt(long double a)
48
{
48
{
49
    long double x = 1;
49
    long double x = 1;
50
    long double lx = 0;
50
    long double lx = 0;
51
   
51
   
52
    if (a < 0.00000000000000001)
52
    if (a < 0.00000000000000001)
53
        return 0;
53
        return 0;
54
       
54
       
55
    while (x != lx) {
55
    while (x != lx) {
56
        lx = x;
56
        lx = x;
57
        x = (x + (a / x)) / 2;
57
        x = (x + (a / x)) / 2;
58
    }
58
    }
59
   
59
   
60
    return x;
60
    return x;
61
}
61
}
62
 
62
 
63
static atomic_t threads_ok;
63
static atomic_t threads_ok;
64
static atomic_t threads_fault;
64
static atomic_t threads_fault;
65
static waitq_t can_start;
65
static waitq_t can_start;
66
static bool sh_quiet;
66
static bool sh_quiet;
67
 
67
 
68
static void e(void *data)
68
static void e(void *data)
69
{
69
{
70
    int i;
70
    int i;
71
    double e, d, le, f;
71
    double e, d, le, f;
72
   
72
   
73
    thread_detach(THREAD);
73
    thread_detach(THREAD);
74
   
74
   
75
    waitq_sleep(&can_start);
75
    waitq_sleep(&can_start);
76
   
76
   
77
    for (i = 0; i<ATTEMPTS; i++) {
77
    for (i = 0; i<ATTEMPTS; i++) {
78
        le = -1;
78
        le = -1;
79
        e = 0;
79
        e = 0;
80
        f = 1;
80
        f = 1;
81
       
81
       
82
        for (d = 1; e != le; d *= f, f += 1) {
82
        for (d = 1; e != le; d *= f, f += 1) {
83
            le = e;
83
            le = e;
84
            e = e + 1 / d;
84
            e = e + 1 / d;
85
        }
85
        }
86
       
86
       
87
        if ((int) (100000000 * e) != E_10e8) {
87
        if ((int) (100000000 * e) != E_10e8) {
88
            if (!sh_quiet)
88
            if (!sh_quiet)
89
                printf("tid%" PRIu64 ": e*10e8=%zd should be %" PRIun "\n", THREAD->tid, (unative_t) (100000000 * e), (unative_t) E_10e8);
89
                printf("tid%" PRIu64 ": e*10e8=%zd should be %" PRIun "\n", THREAD->tid, (unative_t) (100000000 * e), (unative_t) E_10e8);
90
            atomic_inc(&threads_fault);
90
            atomic_inc(&threads_fault);
91
            break;
91
            break;
92
        }
92
        }
93
    }
93
    }
94
    atomic_inc(&threads_ok);
94
    atomic_inc(&threads_ok);
95
}
95
}
96
 
96
 
97
static void pi(void *data)
97
static void pi(void *data)
98
{
98
{
99
    int i;
99
    int i;
100
    double lpi, pi;
100
    double lpi, pi;
101
    double n, ab, ad;
101
    double n, ab, ad;
102
   
102
   
103
    thread_detach(THREAD);
103
    thread_detach(THREAD);
104
   
104
   
105
    waitq_sleep(&can_start);
105
    waitq_sleep(&can_start);
106
   
106
   
107
    for (i = 0; i < ATTEMPTS; i++) {
107
    for (i = 0; i < ATTEMPTS; i++) {
108
        lpi = -1;
108
        lpi = -1;
109
        pi = 0;
109
        pi = 0;
110
       
110
       
111
        for (n = 2, ab = sqrt(2); lpi != pi; n *= 2, ab = ad) {
111
        for (n = 2, ab = sqrt(2); lpi != pi; n *= 2, ab = ad) {
112
            double sc, cd;
112
            double sc, cd;
113
           
113
           
114
            sc = sqrt(1 - (ab * ab / 4));
114
            sc = sqrt(1 - (ab * ab / 4));
115
            cd = 1 - sc;
115
            cd = 1 - sc;
116
            ad = sqrt(ab * ab / 4 + cd * cd);
116
            ad = sqrt(ab * ab / 4 + cd * cd);
117
            lpi = pi;
117
            lpi = pi;
118
            pi = 2 * n * ad;
118
            pi = 2 * n * ad;
119
        }
119
        }
120
       
120
       
121
        if ((int) (1000000 * pi) != PI_10e8) {
121
        if ((int) (1000000 * pi) != PI_10e8) {
122
            if (!sh_quiet)
122
            if (!sh_quiet)
123
                printf("tid%" PRIu64 ": pi*10e8=%zd should be %" PRIun "\n", THREAD->tid, (unative_t) (1000000 * pi), (unative_t) (PI_10e8 / 100));
123
                printf("tid%" PRIu64 ": pi*10e8=%zd should be %" PRIun "\n", THREAD->tid, (unative_t) (1000000 * pi), (unative_t) (PI_10e8 / 100));
124
            atomic_inc(&threads_fault);
124
            atomic_inc(&threads_fault);
125
            break;
125
            break;
126
        }
126
        }
127
    }
127
    }
128
    atomic_inc(&threads_ok);
128
    atomic_inc(&threads_ok);
129
}
129
}
130
 
130
 
131
char * test_fpu1(bool quiet)
131
char * test_fpu1(bool quiet)
132
{
132
{
133
    unsigned int i, total = 0;
133
    unsigned int i, total = 0;
134
    sh_quiet = quiet;
134
    sh_quiet = quiet;
135
   
135
   
136
    waitq_initialize(&can_start);
136
    waitq_initialize(&can_start);
137
    atomic_set(&threads_ok, 0);
137
    atomic_set(&threads_ok, 0);
138
    atomic_set(&threads_fault, 0);
138
    atomic_set(&threads_fault, 0);
139
   
139
   
140
    if (!quiet)
140
    if (!quiet)
141
        printf("Creating %u threads... ", 2 * THREADS);
141
        printf("Creating %u threads... ", 2 * THREADS);
142
   
142
   
143
    for (i = 0; i < THREADS; i++) {  
143
    for (i = 0; i < THREADS; i++) {  
144
        thread_t *t;
144
        thread_t *t;
145
       
145
       
146
        if (!(t = thread_create(e, NULL, TASK, 0, "e", false))) {
146
        if (!(t = thread_create(e, NULL, TASK, 0, "e", false))) {
147
            if (!quiet)
147
            if (!quiet)
148
                printf("could not create thread %u\n", 2 * i);
148
                printf("could not create thread %u\n", 2 * i);
149
            break;
149
            break;
150
        }
150
        }
151
        thread_ready(t);
151
        thread_ready(t);
152
        total++;
152
        total++;
153
       
153
       
154
        if (!(t = thread_create(pi, NULL, TASK, 0, "pi", false))) {
154
        if (!(t = thread_create(pi, NULL, TASK, 0, "pi", false))) {
155
            if (!quiet)
155
            if (!quiet)
156
                printf("could not create thread %u\n", 2 * i + 1);
156
                printf("could not create thread %u\n", 2 * i + 1);
157
            break;
157
            break;
158
        }
158
        }
159
        thread_ready(t);
159
        thread_ready(t);
160
        total++;
160
        total++;
161
    }
161
    }
162
   
162
   
163
    if (!quiet)
163
    if (!quiet)
164
        printf("ok\n");
164
        printf("ok\n");
165
   
165
   
166
    thread_sleep(1);
166
    thread_sleep(1);
167
    waitq_wakeup(&can_start, WAKEUP_ALL);
167
    waitq_wakeup(&can_start, WAKEUP_ALL);
168
   
168
   
169
    while (atomic_get(&threads_ok) != (long) total) {
169
    while (atomic_get(&threads_ok) != (long) total) {
170
        if (!quiet)
170
        if (!quiet)
171
            printf("Threads left: %d\n", total - atomic_get(&threads_ok));
171
            printf("Threads left: %d\n", total - atomic_get(&threads_ok));
172
        thread_sleep(1);
172
        thread_sleep(1);
173
    }
173
    }
174
   
174
   
175
    if (atomic_get(&threads_fault) == 0)
175
    if (atomic_get(&threads_fault) == 0)
176
        return NULL;
176
        return NULL;
177
   
177
   
178
    return "Test failed";
178
    return "Test failed";
179
}
179
}
180
 
180