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