2 * Copyright (C) 2005 Ondrej Palkovsky
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
9 * - Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * - Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
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
15 * derived from this software without specific prior written permission.
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
19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
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
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
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 #include <proc/thread.h>
37 #include <time/delay.h>
45 static atomic_t threads_ok
;
46 static atomic_t threads_fault
;
47 static waitq_t can_start
;
50 static void testit1(void *data
)
53 int arg
__attribute__((aligned(16))) = (int) ((unative_t
) data
);
54 int after_arg
__attribute__((aligned(16)));
56 thread_detach(THREAD
);
58 waitq_sleep(&can_start
);
60 for (i
= 0; i
< ATTEMPTS
; i
++) {
73 if (arg
!= after_arg
) {
75 printf("General reg tid%d: arg(%d) != %d\n", THREAD
->tid
, arg
, after_arg
);
76 atomic_inc(&threads_fault
);
80 atomic_inc(&threads_ok
);
83 static void testit2(void *data
)
86 int arg
__attribute__((aligned(16))) = (int) ((unative_t
) data
);
87 int after_arg
__attribute__((aligned(16)));
89 thread_detach(THREAD
);
91 waitq_sleep(&can_start
);
93 for (i
= 0; i
< ATTEMPTS
; i
++) {
105 if (arg
!= after_arg
) {
107 printf("General reg tid%d: arg(%d) != %d\n", THREAD
->tid
, arg
, after_arg
);
108 atomic_inc(&threads_fault
);
112 atomic_inc(&threads_ok
);
116 char * test_mips2(bool quiet
)
118 unsigned int i
, total
= 0;
121 waitq_initialize(&can_start
);
122 atomic_set(&threads_ok
, 0);
123 atomic_set(&threads_fault
, 0);
126 printf("Creating %d threads... ", 2 * THREADS
);
128 for (i
= 0; i
< THREADS
; i
++) {
131 if (!(t
= thread_create(testit1
, (void *) ((unative_t
) 2 * i
), TASK
, 0, "testit1", false))) {
133 printf("could not create thread %d\n", 2 * i
);
139 if (!(t
= thread_create(testit2
, (void *) ((unative_t
) 2 * i
+ 1), TASK
, 0, "testit2", false))) {
141 printf("could not create thread %d\n", 2 * i
+ 1);
152 waitq_wakeup(&can_start
, WAKEUP_ALL
);
154 while (atomic_get(&threads_ok
) != total
) {
156 printf("Threads left: %d\n", total
- atomic_get(&threads_ok
));
160 if (atomic_get(&threads_fault
) == 0)
163 return "Test failed";