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