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