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