source: mainline/kernel/test/fpu/mips2.c@ 96b02eb9

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

more unification of basic types

  • use sysarg_t and native_t (unsigned and signed variant) in both kernel and uspace
  • remove ipcarg_t in favour of sysarg_t

(no change in functionality)

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