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