Subversion Repositories HelenOS

Rev

Rev 3874 | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

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