Rev 1418 | Rev 1435 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 1418 | Rev 1427 | ||
---|---|---|---|
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/ipc.h> |
30 | #include <ipc/ipc.h> |
31 | #include <ipc/services.h> |
31 | #include <ipc/services.h> |
32 | #include <ipc/ns.h> |
32 | #include <ipc/ns.h> |
33 | #include <stdio.h> |
33 | #include <stdio.h> |
34 | #include <unistd.h> |
34 | #include <unistd.h> |
35 | #include <stdlib.h> |
35 | #include <stdlib.h> |
36 | #include <thread.h> |
36 | #include <thread.h> |
37 | #include <task.h> |
37 | #include <task.h> |
38 | #include <psthread.h> |
38 | #include <psthread.h> |
39 | #include <futex.h> |
39 | #include <futex.h> |
40 | #include <as.h> |
40 | #include <as.h> |
41 | #include <ddi.h> |
41 | #include <ddi.h> |
42 | #include <string.h> |
42 | #include <string.h> |
43 | #include <errno.h> |
43 | #include <errno.h> |
44 | #include <kbd.h> |
44 | #include <kbd.h> |
45 | #include <ipc/fb.h> |
45 | #include <ipc/fb.h> |
- | 46 | #include <async.h> |
|
46 | 47 | ||
47 | int a; |
48 | int a; |
48 | atomic_t ftx; |
49 | atomic_t ftx; |
49 | 50 | ||
50 | int __thread stage; |
51 | int __thread stage; |
51 | 52 | ||
52 | extern void utest(void *arg); |
53 | extern void utest(void *arg); |
53 | void utest(void *arg) |
54 | void utest(void *arg) |
54 | { |
55 | { |
55 | printf("Uspace thread started.\n"); |
56 | printf("Uspace thread started.\n"); |
56 | if (futex_down(&ftx) < 0) |
57 | if (futex_down(&ftx) < 0) |
57 | printf("Futex failed.\n"); |
58 | printf("Futex failed.\n"); |
58 | if (futex_up(&ftx) < 0) |
59 | if (futex_up(&ftx) < 0) |
59 | printf("Futex failed.\n"); |
60 | printf("Futex failed.\n"); |
60 | 61 | ||
61 | printf("%s in good condition.\n", __FUNCTION__); |
62 | printf("%s in good condition.\n", __FUNCTION__); |
62 | 63 | ||
63 | for (;;) |
64 | for (;;) |
64 | ; |
65 | ; |
65 | } |
66 | } |
66 | 67 | ||
67 | /* test different parameters types and modifiers */ |
68 | /* test different parameters types and modifiers */ |
68 | static void test_printf(void) |
69 | static void test_printf(void) |
69 | { |
70 | { |
70 | printf("Simple text.\n"); |
71 | printf("Simple text.\n"); |
71 | printf("Now insert '%s' string.\n","this"); |
72 | printf("Now insert '%s' string.\n","this"); |
72 | printf("Signed formats on uns. numbers: '%d', '%+d', '% d', '%u' (,+, ,u)\n", 321, 321, 321, 321); |
73 | printf("Signed formats on uns. numbers: '%d', '%+d', '% d', '%u' (,+, ,u)\n", 321, 321, 321, 321); |
73 | printf("Signed formats on sig. numbers: '%d', '%+d', '% d', '%u' (,+, ,u)\n", -321, -321, -321, -321); |
74 | printf("Signed formats on sig. numbers: '%d', '%+d', '% d', '%u' (,+, ,u)\n", -321, -321, -321, -321); |
74 | printf("Signed with different sized: '%hhd', '%hd', '%d', '%ld', %lld;\n", -3, -32, -321, -32101l, -3210123ll); |
75 | printf("Signed with different sized: '%hhd', '%hd', '%d', '%ld', %lld;\n", -3, -32, -321, -32101l, -3210123ll); |
75 | printf("And now... '%hhd' byte! '%hd' word! '%d' int! \n", 11, 11111, 1111111111); |
76 | printf("And now... '%hhd' byte! '%hd' word! '%d' int! \n", 11, 11111, 1111111111); |
76 | printf("Different bases: %#hx, %#hu, %#ho and %#hb\n", 123, 123, 123, 123); |
77 | printf("Different bases: %#hx, %#hu, %#ho and %#hb\n", 123, 123, 123, 123); |
77 | printf("Different bases signed: %#hx, %#hu, %#ho and %#hb\n", -123, -123, -123, -123); |
78 | printf("Different bases signed: %#hx, %#hu, %#ho and %#hb\n", -123, -123, -123, -123); |
78 | printf("'%llX' llX! Another '%llx' llx! \n", 0x1234567887654321ll, 0x1234567887654321ll); |
79 | printf("'%llX' llX! Another '%llx' llx! \n", 0x1234567887654321ll, 0x1234567887654321ll); |
79 | printf("'%llX' with 64bit value and '%x' with 32 bit value. \n", 0x1234567887654321ll, 0x12345678 ); |
80 | printf("'%llX' with 64bit value and '%x' with 32 bit value. \n", 0x1234567887654321ll, 0x12345678 ); |
80 | printf("'%llx' 64bit, '%x' 32bit, '%hhx' 8bit, '%hx' 16bit, '%llX' 64bit and '%s' string.\n", 0x1234567887654321ll, 0x12345678, 0x12, 0x1234, 0x1234567887654321ull, "Lovely string" ); |
81 | printf("'%llx' 64bit, '%x' 32bit, '%hhx' 8bit, '%hx' 16bit, '%llX' 64bit and '%s' string.\n", 0x1234567887654321ll, 0x12345678, 0x12, 0x1234, 0x1234567887654321ull, "Lovely string" ); |
81 | 82 | ||
82 | printf("Thats all, folks!\n"); |
83 | printf("Thats all, folks!\n"); |
83 | } |
84 | } |
84 | 85 | ||
85 | /* test width and precision modifiers */ |
86 | /* test width and precision modifiers */ |
86 | static void test_printf2(void) |
87 | static void test_printf2(void) |
87 | { |
88 | { |
88 | printf(" text 10.8s %*.*s \n", 5, 3, "text"); |
89 | printf(" text 10.8s %*.*s \n", 5, 3, "text"); |
89 | printf(" very long text 10.8s %10.8s \n", "very long text"); |
90 | printf(" very long text 10.8s %10.8s \n", "very long text"); |
90 | printf(" text 8.10s %8.10s \n", "text"); |
91 | printf(" text 8.10s %8.10s \n", "text"); |
91 | printf(" very long text 8.10s %8.10s \n", "very long text"); |
92 | printf(" very long text 8.10s %8.10s \n", "very long text"); |
92 | 93 | ||
93 | 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' ); |
94 | 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' ); |
94 | 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 ); |
95 | 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 ); |
95 | 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 ); |
96 | 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 ); |
96 | 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 ); |
97 | 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 ); |
97 | 98 | ||
98 | } |
99 | } |
99 | 100 | ||
100 | extern char _heap; |
101 | extern char _heap; |
101 | static void test_mremap(void) |
102 | static void test_mremap(void) |
102 | { |
103 | { |
103 | printf("Writing to good memory\n"); |
104 | printf("Writing to good memory\n"); |
104 | as_area_resize(&_heap, 120000, 0); |
105 | as_area_resize(&_heap, 120000, 0); |
105 | printf("%P\n", ((char *)&_heap)); |
106 | printf("%P\n", ((char *)&_heap)); |
106 | printf("%P\n", ((char *)&_heap) + 80000); |
107 | printf("%P\n", ((char *)&_heap) + 80000); |
107 | *(((char *)&_heap) + 80000) = 10; |
108 | *(((char *)&_heap) + 80000) = 10; |
108 | printf("Making small\n"); |
109 | printf("Making small\n"); |
109 | as_area_resize(&_heap, 16000, 0); |
110 | as_area_resize(&_heap, 16000, 0); |
110 | printf("Failing..\n"); |
111 | printf("Failing..\n"); |
111 | *((&_heap) + 80000) = 10; |
112 | *((&_heap) + 80000) = 10; |
112 | 113 | ||
113 | printf("memory done\n"); |
114 | printf("memory done\n"); |
114 | } |
115 | } |
115 | /* |
116 | /* |
116 | static void test_sbrk(void) |
117 | static void test_sbrk(void) |
117 | { |
118 | { |
118 | printf("Writing to good memory\n"); |
119 | printf("Writing to good memory\n"); |
119 | printf("Got: %P\n", sbrk(120000)); |
120 | printf("Got: %P\n", sbrk(120000)); |
120 | printf("%P\n", ((char *)&_heap)); |
121 | printf("%P\n", ((char *)&_heap)); |
121 | printf("%P\n", ((char *)&_heap) + 80000); |
122 | printf("%P\n", ((char *)&_heap) + 80000); |
122 | *(((char *)&_heap) + 80000) = 10; |
123 | *(((char *)&_heap) + 80000) = 10; |
123 | printf("Making small, got: %P\n",sbrk(-120000)); |
124 | printf("Making small, got: %P\n",sbrk(-120000)); |
124 | printf("Testing access to heap\n"); |
125 | printf("Testing access to heap\n"); |
125 | _heap = 10; |
126 | _heap = 10; |
126 | printf("Failing..\n"); |
127 | printf("Failing..\n"); |
127 | *((&_heap) + 80000) = 10; |
128 | *((&_heap) + 80000) = 10; |
128 | 129 | ||
129 | printf("memory done\n"); |
130 | printf("memory done\n"); |
130 | } |
131 | } |
131 | */ |
132 | */ |
132 | /* |
133 | /* |
133 | static void test_malloc(void) |
134 | static void test_malloc(void) |
134 | { |
135 | { |
135 | char *data; |
136 | char *data; |
136 | 137 | ||
137 | data = malloc(10); |
138 | data = malloc(10); |
138 | printf("Heap: %P, data: %P\n", &_heap, data); |
139 | printf("Heap: %P, data: %P\n", &_heap, data); |
139 | data[0] = 'a'; |
140 | data[0] = 'a'; |
140 | free(data); |
141 | free(data); |
141 | } |
142 | } |
142 | */ |
143 | */ |
143 | 144 | ||
144 | 145 | ||
145 | static void test_ping(void) |
146 | static void test_ping(void) |
146 | { |
147 | { |
147 | ipcarg_t result; |
148 | ipcarg_t result; |
148 | int retval; |
149 | int retval; |
149 | 150 | ||
150 | printf("Pinging\n"); |
151 | printf("Pinging\n"); |
151 | retval = ipc_call_sync(PHONE_NS, NS_PING, 0xbeef,&result); |
152 | retval = ipc_call_sync(PHONE_NS, NS_PING, 0xbeef,&result); |
152 | printf("Retval: %d - received: %P\n", retval, result); |
153 | printf("Retval: %d - received: %P\n", retval, result); |
153 | } |
154 | } |
154 | 155 | ||
155 | static void got_answer(void *private, int retval, ipc_call_t *data) |
156 | static void got_answer(void *private, int retval, ipc_call_t *data) |
156 | { |
157 | { |
157 | printf("Retval: %d...%s...%zX, %zX\n", retval, private, |
158 | printf("Retval: %d...%s...%zX, %zX\n", retval, private, |
158 | IPC_GET_ARG1(*data), IPC_GET_ARG2(*data)); |
159 | IPC_GET_ARG1(*data), IPC_GET_ARG2(*data)); |
159 | } |
160 | } |
160 | static void test_async_ipc(void) |
161 | static void test_async_ipc(void) |
161 | { |
162 | { |
162 | ipc_call_t data; |
163 | ipc_call_t data; |
163 | int i; |
164 | int i; |
164 | 165 | ||
165 | printf("Sending ping\n"); |
166 | printf("Sending ping\n"); |
166 | ipc_call_async_2(PHONE_NS, NS_PING, 1, 0xbeefbee2, |
167 | ipc_call_async_2(PHONE_NS, NS_PING, 1, 0xbeefbee2, |
167 | "Pong1", got_answer); |
168 | "Pong1", got_answer); |
168 | ipc_call_async_2(PHONE_NS, NS_PING, 2, 0xbeefbee4, |
169 | ipc_call_async_2(PHONE_NS, NS_PING, 2, 0xbeefbee4, |
169 | "Pong2", got_answer); |
170 | "Pong2", got_answer); |
170 | ipc_call_async_2(PHONE_NS, NS_PING, 3, 0xbeefbee4, |
171 | ipc_call_async_2(PHONE_NS, NS_PING, 3, 0xbeefbee4, |
171 | "Pong3", got_answer); |
172 | "Pong3", got_answer); |
172 | ipc_call_async_2(PHONE_NS, NS_PING, 4, 0xbeefbee4, |
173 | ipc_call_async_2(PHONE_NS, NS_PING, 4, 0xbeefbee4, |
173 | "Pong4", got_answer); |
174 | "Pong4", got_answer); |
174 | ipc_call_async_2(PHONE_NS, NS_PING, 5, 0xbeefbee4, |
175 | ipc_call_async_2(PHONE_NS, NS_PING, 5, 0xbeefbee4, |
175 | "Pong5", got_answer); |
176 | "Pong5", got_answer); |
176 | ipc_call_async_2(PHONE_NS, NS_PING, 6, 0xbeefbee4, |
177 | ipc_call_async_2(PHONE_NS, NS_PING, 6, 0xbeefbee4, |
177 | "Pong6", got_answer); |
178 | "Pong6", got_answer); |
178 | printf("Waiting forever...\n"); |
179 | printf("Waiting forever...\n"); |
179 | for (i=0; i<100;i++) |
180 | for (i=0; i<100;i++) |
180 | printf("."); |
181 | printf("."); |
181 | printf("\n"); |
182 | printf("\n"); |
182 | ipc_wait_for_call(&data); |
183 | ipc_wait_for_call(&data); |
183 | printf("Received call???\n"); |
184 | printf("Received call???\n"); |
184 | } |
185 | } |
185 | 186 | ||
186 | 187 | ||
187 | static void got_answer_2(void *private, int retval, ipc_call_t *data) |
188 | static void got_answer_2(void *private, int retval, ipc_call_t *data) |
188 | { |
189 | { |
189 | printf("Pong\n"); |
190 | printf("Pong\n"); |
190 | } |
191 | } |
191 | static void test_advanced_ipc(void) |
192 | static void test_advanced_ipc(void) |
192 | { |
193 | { |
193 | int res; |
194 | int res; |
194 | ipcarg_t phonead; |
195 | ipcarg_t phonead; |
195 | ipc_callid_t callid; |
196 | ipc_callid_t callid; |
196 | ipc_call_t data; |
197 | ipc_call_t data; |
197 | int i; |
198 | int i; |
198 | 199 | ||
199 | printf("Asking 0 to connect to me...\n"); |
200 | printf("Asking 0 to connect to me...\n"); |
200 | res = ipc_connect_to_me(0, 1, 2, &phonead); |
201 | res = ipc_connect_to_me(0, 1, 2, &phonead); |
201 | printf("Result: %d - phonead: %llu\n", res, phonead); |
202 | printf("Result: %d - phonead: %llu\n", res, phonead); |
202 | for (i=0; i < 100; i++) { |
203 | for (i=0; i < 100; i++) { |
203 | printf("----------------\n"); |
204 | printf("----------------\n"); |
204 | ipc_call_async(PHONE_NS, NS_PING_SVC, 0, "prov", |
205 | ipc_call_async(PHONE_NS, NS_PING_SVC, 0, "prov", |
205 | got_answer_2); |
206 | got_answer_2); |
206 | callid = ipc_wait_for_call(&data); |
207 | callid = ipc_wait_for_call(&data); |
207 | printf("Received ping\n"); |
208 | printf("Received ping\n"); |
208 | ipc_answer_fast(callid, 0, 0, 0); |
209 | ipc_answer_fast(callid, 0, 0, 0); |
209 | } |
210 | } |
210 | // callid = ipc_wait_for_call(&data, NULL); |
211 | // callid = ipc_wait_for_call(&data, NULL); |
211 | } |
212 | } |
212 | 213 | ||
213 | static void test_connection_ipc(void) |
214 | static void test_connection_ipc(void) |
214 | { |
215 | { |
215 | int res; |
216 | int res; |
216 | ipcarg_t result; |
217 | ipcarg_t result; |
217 | int phoneid; |
218 | int phoneid; |
218 | 219 | ||
219 | printf("Starting connect...\n"); |
220 | printf("Starting connect...\n"); |
220 | res = ipc_connect_me_to(PHONE_NS, 10, 20); |
221 | res = ipc_connect_me_to(PHONE_NS, 10, 20); |
221 | printf("Connected: %d\n", res); |
222 | printf("Connected: %d\n", res); |
222 | printf("pinging.\n"); |
223 | printf("pinging.\n"); |
223 | res = ipc_call_sync(res, NS_PING, 0xbeef,&result); |
224 | res = ipc_call_sync(res, NS_PING, 0xbeef,&result); |
224 | printf("Retval: %d - received: %X\n", res, result); |
225 | printf("Retval: %d - received: %X\n", res, result); |
225 | 226 | ||
226 | } |
227 | } |
227 | 228 | ||
228 | static void test_hangup(void) |
229 | static void test_hangup(void) |
229 | { |
230 | { |
230 | int phoneid; |
231 | int phoneid; |
231 | ipc_call_t data; |
232 | ipc_call_t data; |
232 | ipc_callid_t callid; |
233 | ipc_callid_t callid; |
233 | int i; |
234 | int i; |
234 | 235 | ||
235 | printf("Starting connect...\n"); |
236 | printf("Starting connect...\n"); |
236 | phoneid = ipc_connect_me_to(PHONE_NS, 10, 20); |
237 | phoneid = ipc_connect_me_to(PHONE_NS, 10, 20); |
237 | printf("Phoneid: %d, pinging\n", phoneid); |
238 | printf("Phoneid: %d, pinging\n", phoneid); |
238 | ipc_call_async_2(PHONE_NS, NS_PING, 1, 0xbeefbee2, |
239 | ipc_call_async_2(PHONE_NS, NS_PING, 1, 0xbeefbee2, |
239 | "Pong1", got_answer); |
240 | "Pong1", got_answer); |
240 | printf("Hangin up\n"); |
241 | printf("Hangin up\n"); |
241 | ipc_hangup(phoneid); |
242 | ipc_hangup(phoneid); |
242 | printf("Connecting\n"); |
243 | printf("Connecting\n"); |
243 | phoneid = ipc_connect_me_to(PHONE_NS, 10, 20); |
244 | phoneid = ipc_connect_me_to(PHONE_NS, 10, 20); |
244 | printf("Newphid: %d\n", phoneid); |
245 | printf("Newphid: %d\n", phoneid); |
245 | for (i=0; i < 1000; i++) { |
246 | for (i=0; i < 1000; i++) { |
246 | if ((callid=ipc_trywait_for_call(&data))) |
247 | if ((callid=ipc_trywait_for_call(&data))) |
247 | printf("callid: %d\n"); |
248 | printf("callid: %d\n"); |
248 | } |
249 | } |
249 | printf("New new phoneid: %d\n", ipc_connect_me_to(PHONE_NS, 10, 20)); |
250 | printf("New new phoneid: %d\n", ipc_connect_me_to(PHONE_NS, 10, 20)); |
250 | } |
251 | } |
251 | 252 | ||
252 | static void test_slam(void) |
253 | static void test_slam(void) |
253 | { |
254 | { |
254 | int i; |
255 | int i; |
255 | ipc_call_t data; |
256 | ipc_call_t data; |
256 | ipc_callid_t callid; |
257 | ipc_callid_t callid; |
257 | 258 | ||
258 | printf("ping"); |
259 | printf("ping"); |
259 | ipc_call_async_2(PHONE_NS, NS_PING, 1, 0xbeefbee2, |
260 | ipc_call_async_2(PHONE_NS, NS_PING, 1, 0xbeefbee2, |
260 | "Pong1", got_answer); |
261 | "Pong1", got_answer); |
261 | printf("slam"); |
262 | printf("slam"); |
262 | ipc_call_async_2(PHONE_NS, NS_HANGUP, 1, 0xbeefbee2, |
263 | ipc_call_async_2(PHONE_NS, NS_HANGUP, 1, 0xbeefbee2, |
263 | "Hang", got_answer); |
264 | "Hang", got_answer); |
264 | printf("ping2\n"); |
265 | printf("ping2\n"); |
265 | ipc_call_async_2(PHONE_NS, NS_PING, 1, 0xbeefbee2, |
266 | ipc_call_async_2(PHONE_NS, NS_PING, 1, 0xbeefbee2, |
266 | "Ping2", got_answer); |
267 | "Ping2", got_answer); |
267 | 268 | ||
268 | for (i=0; i < 1000; i++) { |
269 | for (i=0; i < 1000; i++) { |
269 | if ((callid=ipc_trywait_for_call(&data))) |
270 | if ((callid=ipc_trywait_for_call(&data))) |
270 | printf("callid: %d\n"); |
271 | printf("callid: %d\n"); |
271 | } |
272 | } |
272 | ipc_call_async_2(PHONE_NS, NS_PING, 1, 0xbeefbee2, |
273 | ipc_call_async_2(PHONE_NS, NS_PING, 1, 0xbeefbee2, |
273 | "Pong1", got_answer); |
274 | "Pong1", got_answer); |
274 | printf("Closing file\n"); |
275 | printf("Closing file\n"); |
275 | ipc_hangup(PHONE_NS); |
276 | ipc_hangup(PHONE_NS); |
276 | ipc_call_async_2(PHONE_NS, NS_PING, 1, 0xbeefbee2, |
277 | ipc_call_async_2(PHONE_NS, NS_PING, 1, 0xbeefbee2, |
277 | "Pong1", got_answer); |
278 | "Pong1", got_answer); |
278 | ipc_wait_for_call(&data); |
279 | ipc_wait_for_call(&data); |
279 | } |
280 | } |
280 | 281 | ||
281 | static int ptest(void *arg) |
282 | static int ptest(void *arg) |
282 | { |
283 | { |
283 | stage = 1; |
284 | stage = 1; |
284 | printf("Pseudo thread stage%d.\n", stage); |
285 | printf("Pseudo thread stage%d.\n", stage); |
285 | stage++; |
286 | stage++; |
286 | psthread_schedule_next(); |
287 | psthread_schedule_next(); |
287 | printf("Pseudo thread stage%d.\n", stage); |
288 | printf("Pseudo thread stage%d.\n", stage); |
288 | stage++; |
289 | stage++; |
289 | psthread_schedule_next(); |
290 | psthread_schedule_next(); |
290 | printf("Pseudo thread stage%d.\n", stage); |
291 | printf("Pseudo thread stage%d.\n", stage); |
291 | psthread_schedule_next(); |
292 | psthread_schedule_next(); |
292 | stage++; |
293 | stage++; |
293 | printf("Pseudo thread stage%d.\n", stage); |
294 | printf("Pseudo thread stage%d.\n", stage); |
294 | psthread_schedule_next(); |
295 | psthread_schedule_next(); |
295 | printf("Pseudo thread exiting.\n"); |
296 | printf("Pseudo thread exiting.\n"); |
296 | return 0; |
297 | return 0; |
297 | } |
298 | } |
298 | 299 | ||
299 | static void test_kbd() |
300 | static void test_kbd() |
300 | { |
301 | { |
301 | int res; |
302 | int res; |
302 | ipcarg_t result; |
303 | ipcarg_t result; |
303 | int phoneid; |
304 | int phoneid; |
304 | 305 | ||
305 | printf("Test: Starting connect...\n"); |
306 | printf("Test: Starting connect...\n"); |
306 | while ((phoneid = ipc_connect_me_to(PHONE_NS, SERVICE_KEYBOARD, 0)) < 0) { |
307 | while ((phoneid = ipc_connect_me_to(PHONE_NS, SERVICE_KEYBOARD, 0)) < 0) { |
307 | }; |
308 | }; |
308 | 309 | ||
309 | printf("Test: Connected: %d\n", res); |
310 | printf("Test: Connected: %d\n", res); |
310 | printf("Test: pinging.\n"); |
311 | printf("Test: pinging.\n"); |
311 | while (1) { |
312 | while (1) { |
312 | res = ipc_call_sync(phoneid, KBD_GETCHAR, 0xbeef,&result); |
313 | res = ipc_call_sync(phoneid, KBD_GETCHAR, 0xbeef,&result); |
313 | // printf("Test: Retval: %d - received: %c\n", res, result); |
314 | // printf("Test: Retval: %d - received: %c\n", res, result); |
314 | printf("%c", result); |
315 | printf("%c", result); |
315 | } |
316 | } |
316 | 317 | ||
317 | printf("Test: Hangin up\n"); |
318 | printf("Test: Hangin up\n"); |
318 | ipc_hangup(phoneid); |
319 | ipc_hangup(phoneid); |
319 | } |
320 | } |
320 | 321 | ||
- | 322 | static void test_async_kbd() |
|
- | 323 | { |
|
- | 324 | int res; |
|
- | 325 | ipcarg_t result; |
|
- | 326 | ipc_call_t kbddata; |
|
- | 327 | int phoneid; |
|
- | 328 | aid_t aid; |
|
- | 329 | ||
- | 330 | printf("Test: Starting connect...\n"); |
|
- | 331 | while ((phoneid = ipc_connect_me_to(PHONE_NS, SERVICE_KEYBOARD, 0)) < 0) { |
|
- | 332 | }; |
|
- | 333 | ||
- | 334 | printf("Test: Connected: %d\n", res); |
|
- | 335 | printf("Test: pinging.\n"); |
|
- | 336 | while (1) { |
|
- | 337 | aid = async_send_2(phoneid, KBD_GETCHAR, 0, 0, &kbddata); |
|
- | 338 | async_wait_for(aid, NULL); |
|
- | 339 | printf("%c", IPC_GET_ARG1(kbddata)); |
|
- | 340 | } |
|
- | 341 | ||
- | 342 | printf("Test: Hangin up\n"); |
|
- | 343 | ipc_hangup(phoneid); |
|
- | 344 | } |
|
- | 345 | ||
321 | static void test_pci() |
346 | static void test_pci() |
322 | { |
347 | { |
323 | int phone; |
348 | int phone; |
324 | while ((phone = ipc_connect_me_to(PHONE_NS, SERVICE_PCI, 0)) < 0) |
349 | while ((phone = ipc_connect_me_to(PHONE_NS, SERVICE_PCI, 0)) < 0) |
325 | ; |
350 | ; |
326 | printf("Connected to PCI service through phone %d.\n", phone); |
351 | printf("Connected to PCI service through phone %d.\n", phone); |
327 | } |
352 | } |
328 | 353 | ||
329 | static int test_as_area_send() |
354 | static int test_as_area_send() |
330 | { |
355 | { |
331 | char *as_area; |
356 | char *as_area; |
332 | int retval; |
357 | int retval; |
333 | ipcarg_t result; |
358 | ipcarg_t result; |
334 | 359 | ||
335 | as_area = as_area_create((void *)(1024*1024), 16384, AS_AREA_READ | AS_AREA_WRITE); |
360 | as_area = as_area_create((void *)(1024*1024), 16384, AS_AREA_READ | AS_AREA_WRITE); |
336 | if (!as_area) { |
361 | if (!as_area) { |
337 | printf("Error creating as_area.\n"); |
362 | printf("Error creating as_area.\n"); |
338 | return 0; |
363 | return 0; |
339 | } |
364 | } |
340 | 365 | ||
341 | memcpy(as_area, "Hello world.\n", 14); |
366 | memcpy(as_area, "Hello world.\n", 14); |
342 | 367 | ||
343 | retval = ipc_call_sync_3(PHONE_NS, IPC_M_AS_AREA_SEND, (sysarg_t) as_area, 0, AS_AREA_READ, |
368 | retval = ipc_call_sync_3(PHONE_NS, IPC_M_AS_AREA_SEND, (sysarg_t) as_area, 0, AS_AREA_READ, |
344 | NULL, NULL, NULL); |
369 | NULL, NULL, NULL); |
345 | if (retval) { |
370 | if (retval) { |
346 | printf("AS_AREA_SEND failed.\n"); |
371 | printf("AS_AREA_SEND failed.\n"); |
347 | return 0; |
372 | return 0; |
348 | } |
373 | } |
349 | printf("Done\n"); |
374 | printf("Done\n"); |
350 | } |
375 | } |
351 | 376 | ||
352 | static void test_fb() |
377 | static void test_fb() |
353 | { |
378 | { |
354 | int res; |
379 | int res; |
355 | ipcarg_t result; |
380 | ipcarg_t result; |
356 | int phoneid; |
381 | int phoneid; |
357 | 382 | ||
358 | // printf("Test: Starting connect...\n"); |
383 | // printf("Test: Starting connect...\n"); |
359 | 384 | ||
360 | phoneid = ipc_connect_me_to(PHONE_NS, SERVICE_VIDEO, 0); |
385 | phoneid = ipc_connect_me_to(PHONE_NS, SERVICE_VIDEO, 0); |
361 | 386 | ||
362 | while ((phoneid = ipc_connect_me_to(PHONE_NS, SERVICE_VIDEO, 0)) < 0) { |
387 | while ((phoneid = ipc_connect_me_to(PHONE_NS, SERVICE_VIDEO, 0)) < 0) { |
363 | volatile int a; |
388 | volatile int a; |
364 | for(a=0;a<1048576;a++); |
389 | for(a=0;a<1048576;a++); |
365 | }; |
390 | }; |
366 | 391 | ||
367 | // printf("Test: Connected: %d\n", res); |
392 | // printf("Test: Connected: %d\n", res); |
368 | // printf("Test: pinging.\n"); |
393 | // printf("Test: pinging.\n"); |
369 | while (1) { |
394 | while (1) { |
370 | res = ipc_call_sync(phoneid, FB_GET_VFB, 0xbeef,&result); |
395 | res = ipc_call_sync(phoneid, FB_GET_VFB, 0xbeef,&result); |
371 | // printf("Test: Retval: %d - received: %c\n", res, result); |
396 | // printf("Test: Retval: %d - received: %c\n", res, result); |
372 | // printf("%c", result); |
397 | // printf("%c", result); |
373 | } |
398 | } |
374 | 399 | ||
375 | // printf("Test: Hangin up\n"); |
400 | // printf("Test: Hangin up\n"); |
376 | ipc_hangup(phoneid); |
401 | ipc_hangup(phoneid); |
377 | } |
402 | } |
378 | 403 | ||
379 | 404 | ||
380 | int main(int argc, char *argv[]) |
405 | int main(int argc, char *argv[]) |
381 | { |
406 | { |
382 | pstid_t ptid; |
407 | pstid_t ptid; |
383 | int tid; |
408 | int tid; |
384 | 409 | ||
385 | // version_print(); |
410 | // version_print(); |
386 | 411 | ||
387 | // test_printf(); |
412 | // test_printf(); |
388 | // test_printf2(); |
413 | // test_printf2(); |
389 | // test_ping(); |
414 | // test_ping(); |
390 | // test_async_ipc(); |
415 | // test_async_ipc(); |
391 | // test_advanced_ipc(); |
416 | // test_advanced_ipc(); |
392 | // test_connection_ipc(); |
417 | // test_connection_ipc(); |
393 | // test_hangup(); |
418 | // test_hangup(); |
394 | // test_slam(); |
419 | // test_slam(); |
395 | test_as_area_send(); |
420 | // test_as_area_send(); |
396 | // test_pci(); |
421 | // test_pci(); |
397 | test_kbd(); |
422 | // test_kbd(); |
- | 423 | test_async_kbd(); |
|
398 | // test_fb(); |
424 | // test_fb(); |
399 | 425 | ||
400 | printf("Hello\nThis is Init\n\nBye."); |
426 | printf("Hello\nThis is Init\n\nBye."); |
401 | 427 | ||
402 | 428 | ||
403 | /* |
429 | /* |
404 | printf("Userspace task, taskid=%llX\n", task_get_id()); |
430 | printf("Userspace task, taskid=%llX\n", task_get_id()); |
405 | 431 | ||
406 | futex_initialize(&ftx, 1); |
432 | futex_initialize(&ftx, 1); |
407 | if (futex_down(&ftx) < 0) |
433 | if (futex_down(&ftx) < 0) |
408 | printf("Futex failed.\n"); |
434 | printf("Futex failed.\n"); |
409 | if (futex_up(&ftx) < 0) |
435 | if (futex_up(&ftx) < 0) |
410 | printf("Futex failed.\n"); |
436 | printf("Futex failed.\n"); |
411 | 437 | ||
412 | if (futex_down(&ftx) < 0) |
438 | if (futex_down(&ftx) < 0) |
413 | printf("Futex failed.\n"); |
439 | printf("Futex failed.\n"); |
414 | 440 | ||
415 | if ((tid = thread_create(utest, NULL, "utest")) != -1) { |
441 | if ((tid = thread_create(utest, NULL, "utest")) != -1) { |
416 | printf("Created thread tid=%d\n", tid); |
442 | printf("Created thread tid=%d\n", tid); |
417 | } |
443 | } |
418 | 444 | ||
419 | if ((tid = thread_create(utest, NULL, "utest")) != -1) { |
445 | if ((tid = thread_create(utest, NULL, "utest")) != -1) { |
420 | printf("Created thread tid=%d\n", tid); |
446 | printf("Created thread tid=%d\n", tid); |
421 | } |
447 | } |
422 | 448 | ||
423 | int i; |
449 | int i; |
424 | 450 | ||
425 | for (i = 0; i < 50000000; i++) |
451 | for (i = 0; i < 50000000; i++) |
426 | ; |
452 | ; |
427 | |
453 | |
428 | if (futex_up(&ftx) < 0) |
454 | if (futex_up(&ftx) < 0) |
429 | printf("Futex failed.\n"); |
455 | printf("Futex failed.\n"); |
430 | 456 | ||
431 | 457 | ||
432 | printf("Creating pseudo thread.\n"); |
458 | printf("Creating pseudo thread.\n"); |
433 | stage = 1; |
459 | stage = 1; |
434 | ptid = psthread_create(ptest, NULL); |
460 | ptid = psthread_create(ptest, NULL); |
435 | printf("Main thread stage%d.\n", stage); |
461 | printf("Main thread stage%d.\n", stage); |
436 | stage++; |
462 | stage++; |
437 | psthread_schedule_next();; |
463 | psthread_schedule_next();; |
438 | printf("Main thread stage%d.\n", stage); |
464 | printf("Main thread stage%d.\n", stage); |
439 | stage++; |
465 | stage++; |
440 | psthread_schedule_next();; |
466 | psthread_schedule_next();; |
441 | printf("Main thread stage%d.\n", stage); |
467 | printf("Main thread stage%d.\n", stage); |
442 | 468 | ||
443 | psthread_join(ptid); |
469 | psthread_join(ptid); |
444 | 470 | ||
445 | printf("Main thread exiting.\n"); |
471 | printf("Main thread exiting.\n"); |
446 | */ |
472 | */ |
447 | 473 | ||
448 | return 0; |
474 | return 0; |
449 | } |
475 | } |
450 | 476 |