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