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