source: mainline/kernel/test/fpu/mips2.c@ c2efbb4

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since c2efbb4 was 228666c, checked in by Martin Decky <martin@…>, 15 years ago

introduce atomic_count_t as the explicit type of the internal value in atomic_t (this is probably better than the chaotic mix of int/long)
atomic_count_t is defined as unsigned, for signed semantics you can cast it to atomic_signed_t

  • Property mode set to 100644
File size: 3.8 KB
RevLine 
[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]43static atomic_t threads_ok;
[34db7fa]44static atomic_t threads_fault;
[ffc277e]45static waitq_t can_start;
46
47static void testit1(void *data)
48{
49 int i;
[34db7fa]50 int arg __attribute__((aligned(16))) = (int) ((unative_t) data);
[ffc277e]51 int after_arg __attribute__((aligned(16)));
[34db7fa]52
[8d6d76a]53 thread_detach(THREAD);
[ffc277e]54
55 waitq_sleep(&can_start);
[8a72a9a]56
[34db7fa]57 for (i = 0; i < ATTEMPTS; i++) {
58 asm volatile (
[ffc277e]59 "mtc1 %0,$1"
[34db7fa]60 : "=r" (arg)
61 );
62
[ffc277e]63 delay(DELAY);
[34db7fa]64
65 asm volatile (
[ffc277e]66 "mfc1 %0, $1"
[34db7fa]67 : "=r" (after_arg)
68 );
[ffc277e]69
[34db7fa]70 if (arg != after_arg) {
[cb01e1e]71 TPRINTF("General reg tid%" PRIu64 ": arg(%d) != %d\n", THREAD->tid, arg, after_arg);
[34db7fa]72 atomic_inc(&threads_fault);
73 break;
74 }
[ffc277e]75 }
76 atomic_inc(&threads_ok);
77}
78
79static void testit2(void *data)
80{
81 int i;
[34db7fa]82 int arg __attribute__((aligned(16))) = (int) ((unative_t) data);
[ffc277e]83 int after_arg __attribute__((aligned(16)));
[34db7fa]84
[8d6d76a]85 thread_detach(THREAD);
[34db7fa]86
[ffc277e]87 waitq_sleep(&can_start);
[8a72a9a]88
[34db7fa]89 for (i = 0; i < ATTEMPTS; i++) {
90 asm volatile (
[24241cf]91 "mtc1 %0,$1"
[34db7fa]92 : "=r" (arg)
93 );
[8a72a9a]94
[ffc277e]95 scheduler();
[34db7fa]96 asm volatile (
[24241cf]97 "mfc1 %0,$1"
[34db7fa]98 : "=r" (after_arg)
99 );
[ffc277e]100
[34db7fa]101 if (arg != after_arg) {
[cb01e1e]102 TPRINTF("General reg tid%" PRIu64 ": arg(%d) != %d\n", THREAD->tid, arg, after_arg);
[34db7fa]103 atomic_inc(&threads_fault);
104 break;
105 }
[ffc277e]106 }
107 atomic_inc(&threads_ok);
108}
109
110
[cb01e1e]111char *test_mips2(void)
[ffc277e]112{
[228666c]113 unsigned int i;
114 atomic_count_t total = 0;
[34db7fa]115
[ffc277e]116 waitq_initialize(&can_start);
[34db7fa]117 atomic_set(&threads_ok, 0);
118 atomic_set(&threads_fault, 0);
[deada67]119
[cb01e1e]120 TPRINTF("Creating %u threads... ", 2 * THREADS);
[8a72a9a]121
[34db7fa]122 for (i = 0; i < THREADS; i++) {
123 thread_t *t;
124
[62b6d17]125 if (!(t = thread_create(testit1, (void *) ((unative_t) 2 * i), TASK, 0, "testit1", false))) {
[cb01e1e]126 TPRINTF("could not create thread %u\n", 2 * i);
[34db7fa]127 break;
128 }
[ffc277e]129 thread_ready(t);
[34db7fa]130 total++;
131
[62b6d17]132 if (!(t = thread_create(testit2, (void *) ((unative_t) 2 * i + 1), TASK, 0, "testit2", false))) {
[cb01e1e]133 TPRINTF("could not create thread %u\n", 2 * i + 1);
[34db7fa]134 break;
135 }
[ffc277e]136 thread_ready(t);
[34db7fa]137 total++;
[ffc277e]138 }
[deada67]139
[cb01e1e]140 TPRINTF("ok\n");
[228666c]141
[ffc277e]142 thread_sleep(1);
143 waitq_wakeup(&can_start, WAKEUP_ALL);
[34db7fa]144
[228666c]145 while (atomic_get(&threads_ok) != total) {
[cb01e1e]146 TPRINTF("Threads left: %d\n", total - atomic_get(&threads_ok));
[34db7fa]147 thread_sleep(1);
148 }
149
150 if (atomic_get(&threads_fault) == 0)
151 return NULL;
152
153 return "Test failed";
[f272cb8]154}
Note: See TracBrowser for help on using the repository browser.