Rev 1152 | Rev 1197 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 1152 | Rev 1175 | ||
---|---|---|---|
1 | /* |
1 | /* |
2 | * Copyright (C) 2005 Martin Decky |
2 | * Copyright (C) 2005 Martin Decky |
3 | * All rights reserved. |
3 | * All rights reserved. |
4 | * |
4 | * |
5 | * Redistribution and use in source and binary forms, with or without |
5 | * Redistribution and use in source and binary forms, with or without |
6 | * modification, are permitted provided that the following conditions |
6 | * modification, are permitted provided that the following conditions |
7 | * are met: |
7 | * are met: |
8 | * |
8 | * |
9 | * - Redistributions of source code must retain the above copyright |
9 | * - Redistributions of source code must retain the above copyright |
10 | * notice, this list of conditions and the following disclaimer. |
10 | * notice, this list of conditions and the following disclaimer. |
11 | * - Redistributions in binary form must reproduce the above copyright |
11 | * - Redistributions in binary form must reproduce the above copyright |
12 | * notice, this list of conditions and the following disclaimer in the |
12 | * notice, this list of conditions and the following disclaimer in the |
13 | * documentation and/or other materials provided with the distribution. |
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 |
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. |
15 | * derived from this software without specific prior written permission. |
16 | * |
16 | * |
17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
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 |
18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
22 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
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 |
23 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
24 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
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 |
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. |
26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
27 | */ |
27 | */ |
28 | 28 | ||
29 | #include "version.h" |
29 | #include "version.h" |
30 | #include <ipc.h> |
30 | #include <ipc.h> |
31 | #include <stdio.h> |
31 | #include <stdio.h> |
32 | #include <unistd.h> |
32 | #include <unistd.h> |
33 | #include <stdlib.h> |
33 | #include <stdlib.h> |
34 | #include <ns.h> |
34 | #include <ns.h> |
35 | #include <thread.h> |
35 | #include <thread.h> |
- | 36 | #include <task.h> |
|
36 | #include <psthread.h> |
37 | #include <psthread.h> |
37 | #include <futex.h> |
38 | #include <futex.h> |
38 | 39 | ||
39 | int a; |
40 | int a; |
40 | atomic_t ftx; |
41 | atomic_t ftx; |
41 | 42 | ||
42 | int __thread stage; |
43 | int __thread stage; |
43 | 44 | ||
44 | extern void utest(void *arg); |
45 | extern void utest(void *arg); |
45 | void utest(void *arg) |
46 | void utest(void *arg) |
46 | { |
47 | { |
47 | printf("Uspace thread started.\n"); |
48 | printf("Uspace thread started.\n"); |
48 | if (futex_down(&ftx) < 0) |
49 | if (futex_down(&ftx) < 0) |
49 | printf("Futex failed.\n"); |
50 | printf("Futex failed.\n"); |
50 | if (futex_up(&ftx) < 0) |
51 | if (futex_up(&ftx) < 0) |
51 | printf("Futex failed.\n"); |
52 | printf("Futex failed.\n"); |
52 | 53 | ||
53 | printf("%s in good condition.\n", __FUNCTION__); |
54 | printf("%s in good condition.\n", __FUNCTION__); |
54 | 55 | ||
55 | for (;;) |
56 | for (;;) |
56 | ; |
57 | ; |
57 | } |
58 | } |
58 | 59 | ||
59 | static void test_printf(void) |
60 | static void test_printf(void) |
60 | { |
61 | { |
61 | printf("Simple text.\n"); |
62 | printf("Simple text.\n"); |
62 | printf("Now insert '%s' string.\n","this"); |
63 | printf("Now insert '%s' string.\n","this"); |
63 | printf("Signed formats on uns. numbers: '%d', '%+d', '% d', '%u' (,+, ,u)\n", 321, 321, 321, 321); |
64 | printf("Signed formats on uns. numbers: '%d', '%+d', '% d', '%u' (,+, ,u)\n", 321, 321, 321, 321); |
64 | printf("Signed formats on sig. numbers: '%d', '%+d', '% d', '%u' (,+, ,u)\n", -321, -321, -321, -321); |
65 | printf("Signed formats on sig. numbers: '%d', '%+d', '% d', '%u' (,+, ,u)\n", -321, -321, -321, -321); |
65 | printf("Signed with different sized: '%hhd', '%hd', '%d', '%ld', %lld;\n", -3, -32, -321, -32101l, -3210123ll); |
66 | printf("Signed with different sized: '%hhd', '%hd', '%d', '%ld', %lld;\n", -3, -32, -321, -32101l, -3210123ll); |
66 | printf("And now... '%hhd' byte! '%hd' word! '%d' int! \n", 11, 11111, 1111111111); |
67 | printf("And now... '%hhd' byte! '%hd' word! '%d' int! \n", 11, 11111, 1111111111); |
67 | printf("Different bases: %#hx, %#hu, %#ho and %#hb\n", 123, 123, 123, 123); |
68 | printf("Different bases: %#hx, %#hu, %#ho and %#hb\n", 123, 123, 123, 123); |
68 | printf("Different bases signed: %#hx, %#hu, %#ho and %#hb\n", -123, -123, -123, -123); |
69 | printf("Different bases signed: %#hx, %#hu, %#ho and %#hb\n", -123, -123, -123, -123); |
69 | printf("'%llX' llX! Another '%llx' llx! \n", 0x1234567887654321ll, 0x1234567887654321ll); |
70 | printf("'%llX' llX! Another '%llx' llx! \n", 0x1234567887654321ll, 0x1234567887654321ll); |
70 | printf("'%llX' with 64bit value and '%x' with 32 bit value. \n", 0x1234567887654321ll, 0x12345678 ); |
71 | printf("'%llX' with 64bit value and '%x' with 32 bit value. \n", 0x1234567887654321ll, 0x12345678 ); |
71 | printf("'%llx' 64bit, '%x' 32bit, '%hhx' 8bit, '%hx' 16bit, '%llX' 64bit and '%s' string.\n", 0x1234567887654321ll, 0x12345678, 0x12, 0x1234, 0x1234567887654321ull, "Lovely string" ); |
72 | printf("'%llx' 64bit, '%x' 32bit, '%hhx' 8bit, '%hx' 16bit, '%llX' 64bit and '%s' string.\n", 0x1234567887654321ll, 0x12345678, 0x12, 0x1234, 0x1234567887654321ull, "Lovely string" ); |
72 | 73 | ||
73 | printf("Thats all, folks!\n"); |
74 | printf("Thats all, folks!\n"); |
74 | } |
75 | } |
75 | 76 | ||
76 | 77 | ||
77 | extern char _heap; |
78 | extern char _heap; |
78 | static void test_mremap(void) |
79 | static void test_mremap(void) |
79 | { |
80 | { |
80 | printf("Writing to good memory\n"); |
81 | printf("Writing to good memory\n"); |
81 | mremap(&_heap, 120000, 0); |
82 | mremap(&_heap, 120000, 0); |
82 | printf("%P\n", ((char *)&_heap)); |
83 | printf("%P\n", ((char *)&_heap)); |
83 | printf("%P\n", ((char *)&_heap) + 80000); |
84 | printf("%P\n", ((char *)&_heap) + 80000); |
84 | *(((char *)&_heap) + 80000) = 10; |
85 | *(((char *)&_heap) + 80000) = 10; |
85 | printf("Making small\n"); |
86 | printf("Making small\n"); |
86 | mremap(&_heap, 16000, 0); |
87 | mremap(&_heap, 16000, 0); |
87 | printf("Failing..\n"); |
88 | printf("Failing..\n"); |
88 | *((&_heap) + 80000) = 10; |
89 | *((&_heap) + 80000) = 10; |
89 | 90 | ||
90 | printf("memory done\n"); |
91 | printf("memory done\n"); |
91 | } |
92 | } |
92 | /* |
93 | /* |
93 | static void test_sbrk(void) |
94 | static void test_sbrk(void) |
94 | { |
95 | { |
95 | printf("Writing to good memory\n"); |
96 | printf("Writing to good memory\n"); |
96 | printf("Got: %P\n", sbrk(120000)); |
97 | printf("Got: %P\n", sbrk(120000)); |
97 | printf("%P\n", ((char *)&_heap)); |
98 | printf("%P\n", ((char *)&_heap)); |
98 | printf("%P\n", ((char *)&_heap) + 80000); |
99 | printf("%P\n", ((char *)&_heap) + 80000); |
99 | *(((char *)&_heap) + 80000) = 10; |
100 | *(((char *)&_heap) + 80000) = 10; |
100 | printf("Making small, got: %P\n",sbrk(-120000)); |
101 | printf("Making small, got: %P\n",sbrk(-120000)); |
101 | printf("Testing access to heap\n"); |
102 | printf("Testing access to heap\n"); |
102 | _heap = 10; |
103 | _heap = 10; |
103 | printf("Failing..\n"); |
104 | printf("Failing..\n"); |
104 | *((&_heap) + 80000) = 10; |
105 | *((&_heap) + 80000) = 10; |
105 | 106 | ||
106 | printf("memory done\n"); |
107 | printf("memory done\n"); |
107 | } |
108 | } |
108 | */ |
109 | */ |
109 | /* |
110 | /* |
110 | static void test_malloc(void) |
111 | static void test_malloc(void) |
111 | { |
112 | { |
112 | char *data; |
113 | char *data; |
113 | 114 | ||
114 | data = malloc(10); |
115 | data = malloc(10); |
115 | printf("Heap: %P, data: %P\n", &_heap, data); |
116 | printf("Heap: %P, data: %P\n", &_heap, data); |
116 | data[0] = 'a'; |
117 | data[0] = 'a'; |
117 | free(data); |
118 | free(data); |
118 | } |
119 | } |
119 | */ |
120 | */ |
120 | 121 | ||
121 | 122 | ||
122 | static void test_ping(void) |
123 | static void test_ping(void) |
123 | { |
124 | { |
124 | ipcarg_t result; |
125 | ipcarg_t result; |
125 | int retval; |
126 | int retval; |
126 | 127 | ||
127 | printf("Pinging\n"); |
128 | printf("Pinging\n"); |
128 | retval = ipc_call_sync(PHONE_NS, NS_PING, 0xbeef,&result); |
129 | retval = ipc_call_sync(PHONE_NS, NS_PING, 0xbeef,&result); |
129 | printf("Retval: %d - received: %P\n", retval, result); |
130 | printf("Retval: %d - received: %P\n", retval, result); |
130 | } |
131 | } |
131 | 132 | ||
132 | static void got_answer(void *private, int retval, ipc_call_t *data) |
133 | static void got_answer(void *private, int retval, ipc_call_t *data) |
133 | { |
134 | { |
134 | printf("Retval: %d...%s...%zX, %zX\n", retval, private, |
135 | printf("Retval: %d...%s...%zX, %zX\n", retval, private, |
135 | IPC_GET_ARG1(*data), IPC_GET_ARG2(*data)); |
136 | IPC_GET_ARG1(*data), IPC_GET_ARG2(*data)); |
136 | } |
137 | } |
137 | static void test_async_ipc(void) |
138 | static void test_async_ipc(void) |
138 | { |
139 | { |
139 | ipc_call_t data; |
140 | ipc_call_t data; |
140 | int i; |
141 | int i; |
141 | 142 | ||
142 | printf("Sending ping\n"); |
143 | printf("Sending ping\n"); |
143 | ipc_call_async_2(PHONE_NS, NS_PING, 1, 0xbeefbee2, |
144 | ipc_call_async_2(PHONE_NS, NS_PING, 1, 0xbeefbee2, |
144 | "Pong1", got_answer); |
145 | "Pong1", got_answer); |
145 | ipc_call_async_2(PHONE_NS, NS_PING, 2, 0xbeefbee4, |
146 | ipc_call_async_2(PHONE_NS, NS_PING, 2, 0xbeefbee4, |
146 | "Pong2", got_answer); |
147 | "Pong2", got_answer); |
147 | ipc_call_async_2(PHONE_NS, NS_PING, 3, 0xbeefbee4, |
148 | ipc_call_async_2(PHONE_NS, NS_PING, 3, 0xbeefbee4, |
148 | "Pong3", got_answer); |
149 | "Pong3", got_answer); |
149 | ipc_call_async_2(PHONE_NS, NS_PING, 4, 0xbeefbee4, |
150 | ipc_call_async_2(PHONE_NS, NS_PING, 4, 0xbeefbee4, |
150 | "Pong4", got_answer); |
151 | "Pong4", got_answer); |
151 | ipc_call_async_2(PHONE_NS, NS_PING, 5, 0xbeefbee4, |
152 | ipc_call_async_2(PHONE_NS, NS_PING, 5, 0xbeefbee4, |
152 | "Pong5", got_answer); |
153 | "Pong5", got_answer); |
153 | ipc_call_async_2(PHONE_NS, NS_PING, 6, 0xbeefbee4, |
154 | ipc_call_async_2(PHONE_NS, NS_PING, 6, 0xbeefbee4, |
154 | "Pong6", got_answer); |
155 | "Pong6", got_answer); |
155 | printf("Waiting forever...\n"); |
156 | printf("Waiting forever...\n"); |
156 | for (i=0; i<100;i++) |
157 | for (i=0; i<100;i++) |
157 | printf("."); |
158 | printf("."); |
158 | printf("\n"); |
159 | printf("\n"); |
159 | ipc_wait_for_call(&data, NULL); |
160 | ipc_wait_for_call(&data, NULL); |
160 | printf("Received call???\n"); |
161 | printf("Received call???\n"); |
161 | } |
162 | } |
162 | 163 | ||
163 | 164 | ||
164 | static void got_answer_2(void *private, int retval, ipc_call_t *data) |
165 | static void got_answer_2(void *private, int retval, ipc_call_t *data) |
165 | { |
166 | { |
166 | printf("Pong\n"); |
167 | printf("Pong\n"); |
167 | } |
168 | } |
168 | static void test_advanced_ipc(void) |
169 | static void test_advanced_ipc(void) |
169 | { |
170 | { |
170 | int res; |
171 | int res; |
171 | ipcarg_t phonead; |
172 | ipcarg_t phonead; |
172 | ipc_callid_t callid; |
173 | ipc_callid_t callid; |
173 | ipc_call_t data; |
174 | ipc_call_t data; |
174 | int i; |
175 | int i; |
175 | 176 | ||
176 | printf("Asking 0 to connect to me...\n"); |
177 | printf("Asking 0 to connect to me...\n"); |
177 | res = ipc_connect_to_me(0, 1, 2, &phonead); |
178 | res = ipc_connect_to_me(0, 1, 2, &phonead); |
178 | printf("Result: %d - phonead: %llu\n", res, phonead); |
179 | printf("Result: %d - phonead: %llu\n", res, phonead); |
179 | for (i=0; i < 100; i++) { |
180 | for (i=0; i < 100; i++) { |
180 | printf("----------------\n"); |
181 | printf("----------------\n"); |
181 | ipc_call_async(PHONE_NS, NS_PING_SVC, 0, "prov", |
182 | ipc_call_async(PHONE_NS, NS_PING_SVC, 0, "prov", |
182 | got_answer_2); |
183 | got_answer_2); |
183 | callid = ipc_wait_for_call(&data, NULL); |
184 | callid = ipc_wait_for_call(&data, NULL); |
184 | printf("Received ping\n"); |
185 | printf("Received ping\n"); |
185 | ipc_answer(callid, 0, 0, 0); |
186 | ipc_answer(callid, 0, 0, 0); |
186 | } |
187 | } |
187 | // callid = ipc_wait_for_call(&data, NULL); |
188 | // callid = ipc_wait_for_call(&data, NULL); |
188 | } |
189 | } |
189 | 190 | ||
190 | static void test_connection_ipc(void) |
191 | static void test_connection_ipc(void) |
191 | { |
192 | { |
192 | int res; |
193 | int res; |
193 | ipcarg_t result; |
194 | ipcarg_t result; |
194 | int phoneid; |
195 | int phoneid; |
195 | 196 | ||
196 | printf("Starting connect...\n"); |
197 | printf("Starting connect...\n"); |
197 | res = ipc_connect_me_to(PHONE_NS, 10, 20); |
198 | res = ipc_connect_me_to(PHONE_NS, 10, 20); |
198 | printf("Connected: %d\n", res); |
199 | printf("Connected: %d\n", res); |
199 | printf("pinging.\n"); |
200 | printf("pinging.\n"); |
200 | res = ipc_call_sync(res, NS_PING, 0xbeef,&result); |
201 | res = ipc_call_sync(res, NS_PING, 0xbeef,&result); |
201 | printf("Retval: %d - received: %X\n", res, result); |
202 | printf("Retval: %d - received: %X\n", res, result); |
202 | 203 | ||
203 | } |
204 | } |
204 | 205 | ||
205 | static void test_hangup(void) |
206 | static void test_hangup(void) |
206 | { |
207 | { |
207 | int phoneid; |
208 | int phoneid; |
208 | ipc_call_t data; |
209 | ipc_call_t data; |
209 | ipc_callid_t callid; |
210 | ipc_callid_t callid; |
210 | int i; |
211 | int i; |
211 | 212 | ||
212 | printf("Starting connect...\n"); |
213 | printf("Starting connect...\n"); |
213 | phoneid = ipc_connect_me_to(PHONE_NS, 10, 20); |
214 | phoneid = ipc_connect_me_to(PHONE_NS, 10, 20); |
214 | printf("Phoneid: %d, pinging\n", phoneid); |
215 | printf("Phoneid: %d, pinging\n", phoneid); |
215 | ipc_call_async_2(PHONE_NS, NS_PING, 1, 0xbeefbee2, |
216 | ipc_call_async_2(PHONE_NS, NS_PING, 1, 0xbeefbee2, |
216 | "Pong1", got_answer); |
217 | "Pong1", got_answer); |
217 | printf("Hangin up\n"); |
218 | printf("Hangin up\n"); |
218 | ipc_hangup(phoneid); |
219 | ipc_hangup(phoneid); |
219 | printf("Connecting\n"); |
220 | printf("Connecting\n"); |
220 | phoneid = ipc_connect_me_to(PHONE_NS, 10, 20); |
221 | phoneid = ipc_connect_me_to(PHONE_NS, 10, 20); |
221 | printf("Newphid: %d\n", phoneid); |
222 | printf("Newphid: %d\n", phoneid); |
222 | for (i=0; i < 1000; i++) { |
223 | for (i=0; i < 1000; i++) { |
223 | if ((callid=ipc_wait_for_call(&data, IPC_WAIT_NONBLOCKING))) |
224 | if ((callid=ipc_wait_for_call(&data, IPC_WAIT_NONBLOCKING))) |
224 | printf("callid: %d\n"); |
225 | printf("callid: %d\n"); |
225 | } |
226 | } |
226 | printf("New new phoneid: %d\n", ipc_connect_me_to(PHONE_NS, 10, 20)); |
227 | printf("New new phoneid: %d\n", ipc_connect_me_to(PHONE_NS, 10, 20)); |
227 | } |
228 | } |
228 | 229 | ||
229 | static void test_slam(void) |
230 | static void test_slam(void) |
230 | { |
231 | { |
231 | int i; |
232 | int i; |
232 | ipc_call_t data; |
233 | ipc_call_t data; |
233 | ipc_callid_t callid; |
234 | ipc_callid_t callid; |
234 | 235 | ||
235 | printf("ping"); |
236 | printf("ping"); |
236 | ipc_call_async_2(PHONE_NS, NS_PING, 1, 0xbeefbee2, |
237 | ipc_call_async_2(PHONE_NS, NS_PING, 1, 0xbeefbee2, |
237 | "Pong1", got_answer); |
238 | "Pong1", got_answer); |
238 | printf("slam"); |
239 | printf("slam"); |
239 | ipc_call_async_2(PHONE_NS, NS_HANGUP, 1, 0xbeefbee2, |
240 | ipc_call_async_2(PHONE_NS, NS_HANGUP, 1, 0xbeefbee2, |
240 | "Hang", got_answer); |
241 | "Hang", got_answer); |
241 | printf("ping2\n"); |
242 | printf("ping2\n"); |
242 | ipc_call_async_2(PHONE_NS, NS_PING, 1, 0xbeefbee2, |
243 | ipc_call_async_2(PHONE_NS, NS_PING, 1, 0xbeefbee2, |
243 | "Ping2", got_answer); |
244 | "Ping2", got_answer); |
244 | 245 | ||
245 | for (i=0; i < 1000; i++) { |
246 | for (i=0; i < 1000; i++) { |
246 | if ((callid=ipc_wait_for_call(&data, IPC_WAIT_NONBLOCKING))) |
247 | if ((callid=ipc_wait_for_call(&data, IPC_WAIT_NONBLOCKING))) |
247 | printf("callid: %d\n"); |
248 | printf("callid: %d\n"); |
248 | } |
249 | } |
249 | ipc_call_async_2(PHONE_NS, NS_PING, 1, 0xbeefbee2, |
250 | ipc_call_async_2(PHONE_NS, NS_PING, 1, 0xbeefbee2, |
250 | "Pong1", got_answer); |
251 | "Pong1", got_answer); |
251 | printf("Closing file\n"); |
252 | printf("Closing file\n"); |
252 | ipc_hangup(PHONE_NS); |
253 | ipc_hangup(PHONE_NS); |
253 | ipc_call_async_2(PHONE_NS, NS_PING, 1, 0xbeefbee2, |
254 | ipc_call_async_2(PHONE_NS, NS_PING, 1, 0xbeefbee2, |
254 | "Pong1", got_answer); |
255 | "Pong1", got_answer); |
255 | ipc_wait_for_call(&data, 0); |
256 | ipc_wait_for_call(&data, 0); |
256 | } |
257 | } |
257 | 258 | ||
258 | static int ptest(void *arg) |
259 | static int ptest(void *arg) |
259 | { |
260 | { |
260 | stage = 1; |
261 | stage = 1; |
261 | printf("Pseudo thread stage%d.\n", stage); |
262 | printf("Pseudo thread stage%d.\n", stage); |
262 | stage++; |
263 | stage++; |
263 | psthread_schedule_next(); |
264 | psthread_schedule_next(); |
264 | printf("Pseudo thread stage%d.\n", stage); |
265 | printf("Pseudo thread stage%d.\n", stage); |
265 | stage++; |
266 | stage++; |
266 | psthread_schedule_next(); |
267 | psthread_schedule_next(); |
267 | printf("Pseudo thread stage%d.\n", stage); |
268 | printf("Pseudo thread stage%d.\n", stage); |
268 | psthread_schedule_next(); |
269 | psthread_schedule_next(); |
269 | stage++; |
270 | stage++; |
270 | printf("Pseudo thread stage%d.\n", stage); |
271 | printf("Pseudo thread stage%d.\n", stage); |
271 | psthread_schedule_next(); |
272 | psthread_schedule_next(); |
272 | printf("Pseudo thread exiting.\n"); |
273 | printf("Pseudo thread exiting.\n"); |
273 | return 0; |
274 | return 0; |
274 | } |
275 | } |
275 | 276 | ||
276 | int main(int argc, char *argv[]) |
277 | int main(int argc, char *argv[]) |
277 | { |
278 | { |
278 | pstid_t ptid; |
279 | pstid_t ptid; |
279 | int tid; |
280 | int tid; |
280 | 281 | ||
281 | version_print(); |
282 | version_print(); |
282 | 283 | ||
283 | // test_printf(); |
284 | // test_printf(); |
284 | // test_ping(); |
285 | // test_ping(); |
285 | // test_async_ipc(); |
286 | // test_async_ipc(); |
286 | // test_advanced_ipc(); |
287 | // test_advanced_ipc(); |
287 | // test_connection_ipc(); |
288 | // test_connection_ipc(); |
288 | // test_hangup(); |
289 | // test_hangup(); |
289 | // test_slam(); |
290 | // test_slam(); |
290 | 291 | ||
- | 292 | printf("Userspace task, taskid=%llX\n", get_task_id()); |
|
- | 293 | ||
291 | futex_initialize(&ftx, 1); |
294 | futex_initialize(&ftx, 1); |
292 | if (futex_down(&ftx) < 0) |
295 | if (futex_down(&ftx) < 0) |
293 | printf("Futex failed.\n"); |
296 | printf("Futex failed.\n"); |
294 | if (futex_up(&ftx) < 0) |
297 | if (futex_up(&ftx) < 0) |
295 | printf("Futex failed.\n"); |
298 | printf("Futex failed.\n"); |
296 | 299 | ||
297 | if (futex_down(&ftx) < 0) |
300 | if (futex_down(&ftx) < 0) |
298 | printf("Futex failed.\n"); |
301 | printf("Futex failed.\n"); |
299 | 302 | ||
300 | if ((tid = thread_create(utest, NULL, "utest")) != -1) { |
303 | if ((tid = thread_create(utest, NULL, "utest")) != -1) { |
301 | printf("Created thread tid=%d\n", tid); |
304 | printf("Created thread tid=%d\n", tid); |
302 | } |
305 | } |
303 | 306 | ||
304 | if ((tid = thread_create(utest, NULL, "utest")) != -1) { |
307 | if ((tid = thread_create(utest, NULL, "utest")) != -1) { |
305 | printf("Created thread tid=%d\n", tid); |
308 | printf("Created thread tid=%d\n", tid); |
306 | } |
309 | } |
307 | 310 | ||
308 | int i; |
311 | int i; |
309 | 312 | ||
310 | for (i = 0; i < 50000000; i++) |
313 | for (i = 0; i < 50000000; i++) |
311 | ; |
314 | ; |
312 | 315 | ||
313 | if (futex_up(&ftx) < 0) |
316 | if (futex_up(&ftx) < 0) |
314 | printf("Futex failed.\n"); |
317 | printf("Futex failed.\n"); |
315 | 318 | ||
316 | 319 | ||
317 | printf("Creating pseudo thread.\n"); |
320 | printf("Creating pseudo thread.\n"); |
318 | stage = 1; |
321 | stage = 1; |
319 | ptid = psthread_create(ptest, NULL); |
322 | ptid = psthread_create(ptest, NULL); |
320 | printf("Main thread stage%d.\n", stage); |
323 | printf("Main thread stage%d.\n", stage); |
321 | stage++; |
324 | stage++; |
322 | psthread_schedule_next();; |
325 | psthread_schedule_next();; |
323 | printf("Main thread stage%d.\n", stage); |
326 | printf("Main thread stage%d.\n", stage); |
324 | stage++; |
327 | stage++; |
325 | psthread_schedule_next();; |
328 | psthread_schedule_next();; |
326 | printf("Main thread stage%d.\n", stage); |
329 | printf("Main thread stage%d.\n", stage); |
327 | 330 | ||
328 | psthread_join(ptid); |
331 | psthread_join(ptid); |
329 | 332 | ||
330 | printf("Main thread exiting.\n"); |
333 | printf("Main thread exiting.\n"); |
331 | return 0; |
334 | return 0; |
332 | } |
335 | } |
333 | 336 |