Rev 1128 | Rev 1152 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 1128 | Rev 1129 | ||
---|---|---|---|
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 <psthread.h> |
36 | #include <psthread.h> |
37 | #include <futex.h> |
37 | #include <futex.h> |
38 | 38 | ||
39 | int a; |
39 | int a; |
40 | atomic_t ftx; |
40 | atomic_t ftx; |
41 | 41 | ||
- | 42 | int __thread tls_prom; |
|
- | 43 | ||
42 | extern void utest(void *arg); |
44 | extern void utest(void *arg); |
43 | void utest(void *arg) |
45 | void utest(void *arg) |
44 | { |
46 | { |
45 | printf("Uspace thread started.\n"); |
47 | printf("Uspace thread started.\n"); |
46 | if (futex_down(&ftx) < 0) |
48 | if (futex_down(&ftx) < 0) |
47 | printf("Futex failed.\n"); |
49 | printf("Futex failed.\n"); |
48 | if (futex_up(&ftx) < 0) |
50 | if (futex_up(&ftx) < 0) |
49 | printf("Futex failed.\n"); |
51 | printf("Futex failed.\n"); |
50 | 52 | ||
51 | printf("%s in good condition.\n", __FUNCTION__); |
53 | printf("%s in good condition.\n", __FUNCTION__); |
52 | 54 | ||
53 | for (;;) |
55 | for (;;) |
54 | ; |
56 | ; |
55 | } |
57 | } |
56 | 58 | ||
57 | static void test_printf(void) |
59 | static void test_printf(void) |
58 | { |
60 | { |
59 | printf("Simple text.\n"); |
61 | printf("Simple text.\n"); |
60 | printf("Now insert '%s' string.\n","this"); |
62 | printf("Now insert '%s' string.\n","this"); |
61 | printf("Signed formats on uns. numbers: '%d', '%+d', '% d', '%u' (,+, ,u)\n", 321, 321, 321, 321); |
63 | printf("Signed formats on uns. numbers: '%d', '%+d', '% d', '%u' (,+, ,u)\n", 321, 321, 321, 321); |
62 | printf("Signed formats on sig. 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); |
63 | printf("Signed with different sized: '%hhd', '%hd', '%d', '%ld', %lld;\n", -3, -32, -321, -32101l, -3210123ll); |
65 | printf("Signed with different sized: '%hhd', '%hd', '%d', '%ld', %lld;\n", -3, -32, -321, -32101l, -3210123ll); |
64 | printf("And now... '%hhd' byte! '%hd' word! '%d' int! \n", 11, 11111, 1111111111); |
66 | printf("And now... '%hhd' byte! '%hd' word! '%d' int! \n", 11, 11111, 1111111111); |
65 | printf("Different bases: %#hx, %#hu, %#ho and %#hb\n", 123, 123, 123, 123); |
67 | printf("Different bases: %#hx, %#hu, %#ho and %#hb\n", 123, 123, 123, 123); |
66 | printf("Different bases signed: %#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); |
67 | printf("'%llX' llX! Another '%llx' llx! \n", 0x1234567887654321ll, 0x1234567887654321ll); |
69 | printf("'%llX' llX! Another '%llx' llx! \n", 0x1234567887654321ll, 0x1234567887654321ll); |
68 | printf("'%llX' with 64bit value and '%x' with 32 bit value. \n", 0x1234567887654321ll, 0x12345678 ); |
70 | printf("'%llX' with 64bit value and '%x' with 32 bit value. \n", 0x1234567887654321ll, 0x12345678 ); |
69 | printf("'%llx' 64bit, '%x' 32bit, '%hhx' 8bit, '%hx' 16bit, '%llX' 64bit and '%s' string.\n", 0x1234567887654321ll, 0x12345678, 0x12, 0x1234, 0x1234567887654321ull, "Lovely string" ); |
71 | printf("'%llx' 64bit, '%x' 32bit, '%hhx' 8bit, '%hx' 16bit, '%llX' 64bit and '%s' string.\n", 0x1234567887654321ll, 0x12345678, 0x12, 0x1234, 0x1234567887654321ull, "Lovely string" ); |
70 | 72 | ||
71 | printf("Thats all, folks!\n"); |
73 | printf("Thats all, folks!\n"); |
72 | } |
74 | } |
73 | 75 | ||
74 | 76 | ||
75 | extern char _heap; |
77 | extern char _heap; |
76 | static void test_mremap(void) |
78 | static void test_mremap(void) |
77 | { |
79 | { |
78 | printf("Writing to good memory\n"); |
80 | printf("Writing to good memory\n"); |
79 | mremap(&_heap, 120000, 0); |
81 | mremap(&_heap, 120000, 0); |
80 | printf("%P\n", ((char *)&_heap)); |
82 | printf("%P\n", ((char *)&_heap)); |
81 | printf("%P\n", ((char *)&_heap) + 80000); |
83 | printf("%P\n", ((char *)&_heap) + 80000); |
82 | *(((char *)&_heap) + 80000) = 10; |
84 | *(((char *)&_heap) + 80000) = 10; |
83 | printf("Making small\n"); |
85 | printf("Making small\n"); |
84 | mremap(&_heap, 16000, 0); |
86 | mremap(&_heap, 16000, 0); |
85 | printf("Failing..\n"); |
87 | printf("Failing..\n"); |
86 | *((&_heap) + 80000) = 10; |
88 | *((&_heap) + 80000) = 10; |
87 | 89 | ||
88 | printf("memory done\n"); |
90 | printf("memory done\n"); |
89 | } |
91 | } |
90 | /* |
92 | /* |
91 | static void test_sbrk(void) |
93 | static void test_sbrk(void) |
92 | { |
94 | { |
93 | printf("Writing to good memory\n"); |
95 | printf("Writing to good memory\n"); |
94 | printf("Got: %P\n", sbrk(120000)); |
96 | printf("Got: %P\n", sbrk(120000)); |
95 | printf("%P\n", ((char *)&_heap)); |
97 | printf("%P\n", ((char *)&_heap)); |
96 | printf("%P\n", ((char *)&_heap) + 80000); |
98 | printf("%P\n", ((char *)&_heap) + 80000); |
97 | *(((char *)&_heap) + 80000) = 10; |
99 | *(((char *)&_heap) + 80000) = 10; |
98 | printf("Making small, got: %P\n",sbrk(-120000)); |
100 | printf("Making small, got: %P\n",sbrk(-120000)); |
99 | printf("Testing access to heap\n"); |
101 | printf("Testing access to heap\n"); |
100 | _heap = 10; |
102 | _heap = 10; |
101 | printf("Failing..\n"); |
103 | printf("Failing..\n"); |
102 | *((&_heap) + 80000) = 10; |
104 | *((&_heap) + 80000) = 10; |
103 | 105 | ||
104 | printf("memory done\n"); |
106 | printf("memory done\n"); |
105 | } |
107 | } |
106 | */ |
108 | */ |
107 | /* |
109 | /* |
108 | static void test_malloc(void) |
110 | static void test_malloc(void) |
109 | { |
111 | { |
110 | char *data; |
112 | char *data; |
111 | 113 | ||
112 | data = malloc(10); |
114 | data = malloc(10); |
113 | printf("Heap: %P, data: %P\n", &_heap, data); |
115 | printf("Heap: %P, data: %P\n", &_heap, data); |
114 | data[0] = 'a'; |
116 | data[0] = 'a'; |
115 | free(data); |
117 | free(data); |
116 | } |
118 | } |
117 | */ |
119 | */ |
118 | 120 | ||
119 | 121 | ||
120 | static void test_ping(void) |
122 | static void test_ping(void) |
121 | { |
123 | { |
122 | ipcarg_t result; |
124 | ipcarg_t result; |
123 | int retval; |
125 | int retval; |
124 | 126 | ||
125 | printf("Pinging\n"); |
127 | printf("Pinging\n"); |
126 | retval = ipc_call_sync(PHONE_NS, NS_PING, 0xbeef,&result); |
128 | retval = ipc_call_sync(PHONE_NS, NS_PING, 0xbeef,&result); |
127 | printf("Retval: %d - received: %P\n", retval, result); |
129 | printf("Retval: %d - received: %P\n", retval, result); |
128 | } |
130 | } |
129 | 131 | ||
130 | static void got_answer(void *private, int retval, ipc_call_t *data) |
132 | static void got_answer(void *private, int retval, ipc_call_t *data) |
131 | { |
133 | { |
132 | printf("Retval: %d...%s...%zX, %zX\n", retval, private, |
134 | printf("Retval: %d...%s...%zX, %zX\n", retval, private, |
133 | IPC_GET_ARG1(*data), IPC_GET_ARG2(*data)); |
135 | IPC_GET_ARG1(*data), IPC_GET_ARG2(*data)); |
134 | } |
136 | } |
135 | static void test_async_ipc(void) |
137 | static void test_async_ipc(void) |
136 | { |
138 | { |
137 | ipc_call_t data; |
139 | ipc_call_t data; |
138 | int i; |
140 | int i; |
139 | 141 | ||
140 | printf("Sending ping\n"); |
142 | printf("Sending ping\n"); |
141 | ipc_call_async_2(PHONE_NS, NS_PING, 1, 0xbeefbee2, |
143 | ipc_call_async_2(PHONE_NS, NS_PING, 1, 0xbeefbee2, |
142 | "Pong1", got_answer); |
144 | "Pong1", got_answer); |
143 | ipc_call_async_2(PHONE_NS, NS_PING, 2, 0xbeefbee4, |
145 | ipc_call_async_2(PHONE_NS, NS_PING, 2, 0xbeefbee4, |
144 | "Pong2", got_answer); |
146 | "Pong2", got_answer); |
145 | ipc_call_async_2(PHONE_NS, NS_PING, 3, 0xbeefbee4, |
147 | ipc_call_async_2(PHONE_NS, NS_PING, 3, 0xbeefbee4, |
146 | "Pong3", got_answer); |
148 | "Pong3", got_answer); |
147 | ipc_call_async_2(PHONE_NS, NS_PING, 4, 0xbeefbee4, |
149 | ipc_call_async_2(PHONE_NS, NS_PING, 4, 0xbeefbee4, |
148 | "Pong4", got_answer); |
150 | "Pong4", got_answer); |
149 | ipc_call_async_2(PHONE_NS, NS_PING, 5, 0xbeefbee4, |
151 | ipc_call_async_2(PHONE_NS, NS_PING, 5, 0xbeefbee4, |
150 | "Pong5", got_answer); |
152 | "Pong5", got_answer); |
151 | ipc_call_async_2(PHONE_NS, NS_PING, 6, 0xbeefbee4, |
153 | ipc_call_async_2(PHONE_NS, NS_PING, 6, 0xbeefbee4, |
152 | "Pong6", got_answer); |
154 | "Pong6", got_answer); |
153 | printf("Waiting forever...\n"); |
155 | printf("Waiting forever...\n"); |
154 | for (i=0; i<100;i++) |
156 | for (i=0; i<100;i++) |
155 | printf("."); |
157 | printf("."); |
156 | printf("\n"); |
158 | printf("\n"); |
157 | ipc_wait_for_call(&data, NULL); |
159 | ipc_wait_for_call(&data, NULL); |
158 | printf("Received call???\n"); |
160 | printf("Received call???\n"); |
159 | } |
161 | } |
160 | 162 | ||
161 | 163 | ||
162 | static void got_answer_2(void *private, int retval, ipc_call_t *data) |
164 | static void got_answer_2(void *private, int retval, ipc_call_t *data) |
163 | { |
165 | { |
164 | printf("Pong\n"); |
166 | printf("Pong\n"); |
165 | } |
167 | } |
166 | static void test_advanced_ipc(void) |
168 | static void test_advanced_ipc(void) |
167 | { |
169 | { |
168 | int res; |
170 | int res; |
169 | ipcarg_t phonead; |
171 | ipcarg_t phonead; |
170 | ipc_callid_t callid; |
172 | ipc_callid_t callid; |
171 | ipc_call_t data; |
173 | ipc_call_t data; |
172 | int i; |
174 | int i; |
173 | 175 | ||
174 | printf("Asking 0 to connect to me...\n"); |
176 | printf("Asking 0 to connect to me...\n"); |
175 | res = ipc_connect_to_me(0, 1, 2, &phonead); |
177 | res = ipc_connect_to_me(0, 1, 2, &phonead); |
176 | printf("Result: %d - phonead: %llu\n", res, phonead); |
178 | printf("Result: %d - phonead: %llu\n", res, phonead); |
177 | for (i=0; i < 100; i++) { |
179 | for (i=0; i < 100; i++) { |
178 | printf("----------------\n"); |
180 | printf("----------------\n"); |
179 | ipc_call_async(PHONE_NS, NS_PING_SVC, 0, "prov", |
181 | ipc_call_async(PHONE_NS, NS_PING_SVC, 0, "prov", |
180 | got_answer_2); |
182 | got_answer_2); |
181 | callid = ipc_wait_for_call(&data, NULL); |
183 | callid = ipc_wait_for_call(&data, NULL); |
182 | printf("Received ping\n"); |
184 | printf("Received ping\n"); |
183 | ipc_answer(callid, 0, 0, 0); |
185 | ipc_answer(callid, 0, 0, 0); |
184 | } |
186 | } |
185 | // callid = ipc_wait_for_call(&data, NULL); |
187 | // callid = ipc_wait_for_call(&data, NULL); |
186 | } |
188 | } |
187 | 189 | ||
188 | static void test_connection_ipc(void) |
190 | static void test_connection_ipc(void) |
189 | { |
191 | { |
190 | int res; |
192 | int res; |
191 | ipcarg_t result; |
193 | ipcarg_t result; |
192 | int phoneid; |
194 | int phoneid; |
193 | 195 | ||
194 | printf("Starting connect...\n"); |
196 | printf("Starting connect...\n"); |
195 | res = ipc_connect_me_to(PHONE_NS, 10, 20); |
197 | res = ipc_connect_me_to(PHONE_NS, 10, 20); |
196 | printf("Connected: %d\n", res); |
198 | printf("Connected: %d\n", res); |
197 | printf("pinging.\n"); |
199 | printf("pinging.\n"); |
198 | res = ipc_call_sync(res, NS_PING, 0xbeef,&result); |
200 | res = ipc_call_sync(res, NS_PING, 0xbeef,&result); |
199 | printf("Retval: %d - received: %X\n", res, result); |
201 | printf("Retval: %d - received: %X\n", res, result); |
200 | 202 | ||
201 | } |
203 | } |
202 | 204 | ||
203 | static void test_hangup(void) |
205 | static void test_hangup(void) |
204 | { |
206 | { |
205 | int phoneid; |
207 | int phoneid; |
206 | ipc_call_t data; |
208 | ipc_call_t data; |
207 | ipc_callid_t callid; |
209 | ipc_callid_t callid; |
208 | int i; |
210 | int i; |
209 | 211 | ||
210 | printf("Starting connect...\n"); |
212 | printf("Starting connect...\n"); |
211 | phoneid = ipc_connect_me_to(PHONE_NS, 10, 20); |
213 | phoneid = ipc_connect_me_to(PHONE_NS, 10, 20); |
212 | printf("Phoneid: %d, pinging\n", phoneid); |
214 | printf("Phoneid: %d, pinging\n", phoneid); |
213 | ipc_call_async_2(PHONE_NS, NS_PING, 1, 0xbeefbee2, |
215 | ipc_call_async_2(PHONE_NS, NS_PING, 1, 0xbeefbee2, |
214 | "Pong1", got_answer); |
216 | "Pong1", got_answer); |
215 | printf("Hangin up\n"); |
217 | printf("Hangin up\n"); |
216 | ipc_hangup(phoneid); |
218 | ipc_hangup(phoneid); |
217 | printf("Connecting\n"); |
219 | printf("Connecting\n"); |
218 | phoneid = ipc_connect_me_to(PHONE_NS, 10, 20); |
220 | phoneid = ipc_connect_me_to(PHONE_NS, 10, 20); |
219 | printf("Newphid: %d\n", phoneid); |
221 | printf("Newphid: %d\n", phoneid); |
220 | for (i=0; i < 1000; i++) { |
222 | for (i=0; i < 1000; i++) { |
221 | if ((callid=ipc_wait_for_call(&data, IPC_WAIT_NONBLOCKING))) |
223 | if ((callid=ipc_wait_for_call(&data, IPC_WAIT_NONBLOCKING))) |
222 | printf("callid: %d\n"); |
224 | printf("callid: %d\n"); |
223 | } |
225 | } |
224 | printf("New new phoneid: %d\n", ipc_connect_me_to(PHONE_NS, 10, 20)); |
226 | printf("New new phoneid: %d\n", ipc_connect_me_to(PHONE_NS, 10, 20)); |
225 | } |
227 | } |
226 | 228 | ||
227 | static void test_slam(void) |
229 | static void test_slam(void) |
228 | { |
230 | { |
229 | int i; |
231 | int i; |
230 | ipc_call_t data; |
232 | ipc_call_t data; |
231 | ipc_callid_t callid; |
233 | ipc_callid_t callid; |
232 | 234 | ||
233 | printf("ping"); |
235 | printf("ping"); |
234 | ipc_call_async_2(PHONE_NS, NS_PING, 1, 0xbeefbee2, |
236 | ipc_call_async_2(PHONE_NS, NS_PING, 1, 0xbeefbee2, |
235 | "Pong1", got_answer); |
237 | "Pong1", got_answer); |
236 | printf("slam"); |
238 | printf("slam"); |
237 | ipc_call_async_2(PHONE_NS, NS_HANGUP, 1, 0xbeefbee2, |
239 | ipc_call_async_2(PHONE_NS, NS_HANGUP, 1, 0xbeefbee2, |
238 | "Hang", got_answer); |
240 | "Hang", got_answer); |
239 | printf("ping2\n"); |
241 | printf("ping2\n"); |
240 | ipc_call_async_2(PHONE_NS, NS_PING, 1, 0xbeefbee2, |
242 | ipc_call_async_2(PHONE_NS, NS_PING, 1, 0xbeefbee2, |
241 | "Ping2", got_answer); |
243 | "Ping2", got_answer); |
242 | 244 | ||
243 | for (i=0; i < 1000; i++) { |
245 | for (i=0; i < 1000; i++) { |
244 | if ((callid=ipc_wait_for_call(&data, IPC_WAIT_NONBLOCKING))) |
246 | if ((callid=ipc_wait_for_call(&data, IPC_WAIT_NONBLOCKING))) |
245 | printf("callid: %d\n"); |
247 | printf("callid: %d\n"); |
246 | } |
248 | } |
247 | ipc_call_async_2(PHONE_NS, NS_PING, 1, 0xbeefbee2, |
249 | ipc_call_async_2(PHONE_NS, NS_PING, 1, 0xbeefbee2, |
248 | "Pong1", got_answer); |
250 | "Pong1", got_answer); |
249 | printf("Closing file\n"); |
251 | printf("Closing file\n"); |
250 | ipc_hangup(PHONE_NS); |
252 | ipc_hangup(PHONE_NS); |
251 | ipc_call_async_2(PHONE_NS, NS_PING, 1, 0xbeefbee2, |
253 | ipc_call_async_2(PHONE_NS, NS_PING, 1, 0xbeefbee2, |
252 | "Pong1", got_answer); |
254 | "Pong1", got_answer); |
253 | ipc_wait_for_call(&data, 0); |
255 | ipc_wait_for_call(&data, 0); |
254 | } |
256 | } |
255 | 257 | ||
256 | static int ptest(void *arg) |
258 | static int ptest(void *arg) |
257 | { |
259 | { |
- | 260 | tls_prom = -1; |
|
258 | printf("Pseudo thread stage1.\n"); |
261 | printf("Pseudo thread stage%d.\n", -tls_prom); |
- | 262 | tls_prom = -2; |
|
259 | psthread_schedule_next(); |
263 | psthread_schedule_next(); |
260 | printf("Pseudo thread stage2.\n"); |
264 | printf("Pseudo thread stage%d.\n", -tls_prom); |
- | 265 | tls_prom = -3; |
|
261 | psthread_schedule_next(); |
266 | psthread_schedule_next(); |
262 | printf("Pseudo thread stage3.\n"); |
267 | printf("Pseudo thread stage%d\n", -tls_prom); |
263 | psthread_schedule_next(); |
268 | psthread_schedule_next(); |
264 | printf("Pseudo thread stage4.\n"); |
269 | printf("Pseudo thread stage4.\n"); |
265 | psthread_schedule_next(); |
270 | psthread_schedule_next(); |
266 | printf("Pseudo thread exiting.\n"); |
271 | printf("Pseudo thread exiting.\n"); |
267 | return 0; |
272 | return 0; |
268 | } |
273 | } |
269 | 274 | ||
270 | int main(int argc, char *argv[]) |
275 | int main(int argc, char *argv[]) |
271 | { |
276 | { |
272 | pstid_t ptid; |
277 | pstid_t ptid; |
273 | int tid; |
278 | int tid; |
274 | 279 | ||
275 | version_print(); |
280 | version_print(); |
276 | 281 | ||
277 | // test_printf(); |
282 | // test_printf(); |
278 | // test_ping(); |
283 | // test_ping(); |
279 | // test_async_ipc(); |
284 | // test_async_ipc(); |
280 | // test_advanced_ipc(); |
285 | // test_advanced_ipc(); |
281 | // test_connection_ipc(); |
286 | // test_connection_ipc(); |
282 | // test_hangup(); |
287 | // test_hangup(); |
283 | // test_slam(); |
288 | // test_slam(); |
284 | 289 | ||
285 | futex_initialize(&ftx, 1); |
290 | futex_initialize(&ftx, 1); |
286 | if (futex_down(&ftx) < 0) |
291 | if (futex_down(&ftx) < 0) |
287 | printf("Futex failed.\n"); |
292 | printf("Futex failed.\n"); |
288 | if (futex_up(&ftx) < 0) |
293 | if (futex_up(&ftx) < 0) |
289 | printf("Futex failed.\n"); |
294 | printf("Futex failed.\n"); |
290 | 295 | ||
291 | if (futex_down(&ftx) < 0) |
296 | if (futex_down(&ftx) < 0) |
292 | printf("Futex failed.\n"); |
297 | printf("Futex failed.\n"); |
293 | 298 | /* |
|
294 | if ((tid = thread_create(utest, NULL, "utest")) != -1) { |
299 | if ((tid = thread_create(utest, NULL, "utest")) != -1) { |
295 | printf("Created thread tid=%d\n", tid); |
300 | printf("Created thread tid=%d\n", tid); |
296 | } |
301 | } |
297 | 302 | ||
298 | if ((tid = thread_create(utest, NULL, "utest")) != -1) { |
303 | if ((tid = thread_create(utest, NULL, "utest")) != -1) { |
299 | printf("Created thread tid=%d\n", tid); |
304 | printf("Created thread tid=%d\n", tid); |
300 | } |
305 | } |
301 | 306 | */ |
|
302 | int i; |
307 | int i; |
303 | 308 | ||
304 | for (i = 0; i < 50000000; i++) |
309 | for (i = 0; i < 50000000; i++) |
305 | ; |
310 | ; |
306 | 311 | ||
307 | if (futex_up(&ftx) < 0) |
312 | if (futex_up(&ftx) < 0) |
308 | printf("Futex failed.\n"); |
313 | printf("Futex failed.\n"); |
309 | 314 | ||
- | 315 | ||
- | 316 | printf("Creating pathread\n"); |
|
- | 317 | tls_prom = 1; |
|
310 | ptid = psthread_create(ptest, NULL); |
318 | ptid = psthread_create(ptest, NULL); |
311 | printf("Main thread stage1.\n"); |
319 | printf("Main thread stage%d\n",tls_prom); |
- | 320 | tls_prom = 2; |
|
312 | psthread_schedule_next();; |
321 | psthread_schedule_next();; |
313 | printf("Main thread stage2.\n"); |
322 | printf("Main thread stage%d\n", tls_prom); |
- | 323 | tls_prom = 3; |
|
314 | psthread_schedule_next();; |
324 | psthread_schedule_next();; |
315 | printf("Main thread stage3.\n"); |
325 | printf("Main thread stage%d\n", tls_prom); |
316 | 326 | ||
317 | psthread_join(ptid); |
327 | psthread_join(ptid); |
318 | 328 | ||
319 | printf("Main thread exiting.\n"); |
329 | printf("Main thread exiting.\n"); |
320 | return 0; |
330 | return 0; |
321 | } |
331 | } |
322 | 332 |