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