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