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