Subversion Repositories HelenOS

Rev

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

Rev 2027 Rev 2029
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
#ifdef mips32
29
#ifdef mips32
30
 
30
 
31
#include <print.h>
31
#include <print.h>
32
#include <debug.h>
32
#include <debug.h>
33
#include <panic.h>
-
 
34
 
33
 
35
#include <test.h>
34
#include <test.h>
36
#include <atomic.h>
35
#include <atomic.h>
37
#include <proc/thread.h>
36
#include <proc/thread.h>
38
#include <time/delay.h>
37
#include <time/delay.h>
39
 
38
 
40
#include <arch.h>
39
#include <arch.h>
41
 
40
 
42
#define THREADS     50
41
#define THREADS     50
43
#define DELAY       10000L
42
#define DELAY       10000L
44
#define ATTEMPTS        5
43
#define ATTEMPTS        5
45
 
44
 
46
static atomic_t threads_ok;
45
static atomic_t threads_ok;
47
static atomic_t threads_fault;
46
static atomic_t threads_fault;
48
static waitq_t can_start;
47
static waitq_t can_start;
49
 
48
 
50
static void testit1(void *data)
49
static void testit1(void *data)
51
{
50
{
52
    int i;
51
    int i;
53
    int arg __attribute__((aligned(16))) = (int) ((unative_t) data);
52
    int arg __attribute__((aligned(16))) = (int) ((unative_t) data);
54
    int after_arg __attribute__((aligned(16)));
53
    int after_arg __attribute__((aligned(16)));
55
   
54
   
56
    thread_detach(THREAD);
55
    thread_detach(THREAD);
57
   
56
   
58
    waitq_sleep(&can_start);
57
    waitq_sleep(&can_start);
59
 
58
 
60
    for (i = 0; i < ATTEMPTS; i++) {
59
    for (i = 0; i < ATTEMPTS; i++) {
61
        asm volatile (
60
        asm volatile (
62
            "mtc1 %0,$1"
61
            "mtc1 %0,$1"
63
            : "=r" (arg)
62
            : "=r" (arg)
64
        );
63
        );
65
       
64
       
66
        delay(DELAY);
65
        delay(DELAY);
67
       
66
       
68
        asm volatile (
67
        asm volatile (
69
            "mfc1 %0, $1"
68
            "mfc1 %0, $1"
70
            : "=r" (after_arg)
69
            : "=r" (after_arg)
71
        );
70
        );
72
       
71
       
73
        if (arg != after_arg) {
72
        if (arg != after_arg) {
74
            printf("General reg tid%d: arg(%d) != %d\n", THREAD->tid, arg, after_arg);
73
            printf("General reg tid%d: arg(%d) != %d\n", THREAD->tid, arg, after_arg);
75
            atomic_inc(&threads_fault);
74
            atomic_inc(&threads_fault);
76
            break;
75
            break;
77
        }
76
        }
78
    }
77
    }
79
    atomic_inc(&threads_ok);
78
    atomic_inc(&threads_ok);
80
}
79
}
81
 
80
 
82
static void testit2(void *data)
81
static void testit2(void *data)
83
{
82
{
84
    int i;
83
    int i;
85
    int arg __attribute__((aligned(16))) = (int) ((unative_t) data);
84
    int arg __attribute__((aligned(16))) = (int) ((unative_t) data);
86
    int after_arg __attribute__((aligned(16)));
85
    int after_arg __attribute__((aligned(16)));
87
   
86
   
88
    thread_detach(THREAD);
87
    thread_detach(THREAD);
89
   
88
   
90
    waitq_sleep(&can_start);
89
    waitq_sleep(&can_start);
91
 
90
 
92
    for (i = 0; i < ATTEMPTS; i++) {
91
    for (i = 0; i < ATTEMPTS; i++) {
93
        asm volatile (
92
        asm volatile (
94
            "mtc1 %0,$1"
93
            "mtc1 %0,$1"
95
            : "=r" (arg)
94
            : "=r" (arg)
96
        );
95
        );
97
 
96
 
98
        scheduler();
97
        scheduler();
99
        asm volatile (
98
        asm volatile (
100
            "mfc1 %0,$1"
99
            "mfc1 %0,$1"
101
            : "=r" (after_arg)
100
            : "=r" (after_arg)
102
        );
101
        );
103
       
102
       
104
        if (arg != after_arg) {
103
        if (arg != after_arg) {
105
            panic("General reg tid%d: arg(%d) != %d\n", THREAD->tid, arg, after_arg);
104
            printf("General reg tid%d: arg(%d) != %d\n", THREAD->tid, arg, after_arg);
106
            atomic_inc(&threads_fault);
105
            atomic_inc(&threads_fault);
107
            break;
106
            break;
108
        }
107
        }
109
    }
108
    }
110
    atomic_inc(&threads_ok);
109
    atomic_inc(&threads_ok);
111
}
110
}
112
 
111
 
113
 
112
 
114
char * test_mips2(void)
113
char * test_mips2(void)
115
{
114
{
116
    unsigned int i, total = 0;
115
    unsigned int i, total = 0;
117
   
116
   
118
    waitq_initialize(&can_start);
117
    waitq_initialize(&can_start);
119
    atomic_set(&threads_ok, 0);
118
    atomic_set(&threads_ok, 0);
120
    atomic_set(&threads_fault, 0);
119
    atomic_set(&threads_fault, 0);
121
    printf("Creating %d threads... ", 2 * THREADS);
120
    printf("Creating %d threads... ", 2 * THREADS);
122
 
121
 
123
    for (i = 0; i < THREADS; i++) {
122
    for (i = 0; i < THREADS; i++) {
124
        thread_t *t;
123
        thread_t *t;
125
       
124
       
126
        if (!(t = thread_create(testit1, (void *) ((unative_t) 2 * i), TASK, 0, "testit1"))) {
125
        if (!(t = thread_create(testit1, (void *) ((unative_t) 2 * i), TASK, 0, "testit1"))) {
127
            printf("could not create thread %d\n", 2 * i);
126
            printf("could not create thread %d\n", 2 * i);
128
            break;
127
            break;
129
        }
128
        }
130
        thread_ready(t);
129
        thread_ready(t);
131
        total++;
130
        total++;
132
       
131
       
133
        if (!(t = thread_create(testit2, (void *) ((unative_t) 2 * i + 1), TASK, 0, "testit2"))) {
132
        if (!(t = thread_create(testit2, (void *) ((unative_t) 2 * i + 1), TASK, 0, "testit2"))) {
134
            printf("could not create thread %d\n", 2 * i + 1);
133
            printf("could not create thread %d\n", 2 * i + 1);
135
            break;
134
            break;
136
        }
135
        }
137
        thread_ready(t);
136
        thread_ready(t);
138
        total++;
137
        total++;
139
    }
138
    }
140
    printf("ok\n");
139
    printf("ok\n");
141
       
140
       
142
    thread_sleep(1);
141
    thread_sleep(1);
143
    waitq_wakeup(&can_start, WAKEUP_ALL);
142
    waitq_wakeup(&can_start, WAKEUP_ALL);
144
   
143
   
145
    while (atomic_get(&threads_ok) != total) {
144
    while (atomic_get(&threads_ok) != total) {
146
        printf("Threads left: %d\n", total - atomic_get(&threads_ok));
145
        printf("Threads left: %d\n", total - atomic_get(&threads_ok));
147
        thread_sleep(1);
146
        thread_sleep(1);
148
    }
147
    }
149
   
148
   
150
    if (atomic_get(&threads_fault) == 0)
149
    if (atomic_get(&threads_fault) == 0)
151
        return NULL;
150
        return NULL;
152
   
151
   
153
    return "Test failed";
152
    return "Test failed";
154
}
153
}
155
 
154
 
156
#endif
155
#endif
157
 
156