Rev 1081 | Rev 1091 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 1081 | Rev 1089 | ||
---|---|---|---|
Line 32... | Line 32... | ||
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 (;;) |
Line 167... | Line 169... | ||
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; |
Line 180... | Line 182... | ||
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 | } |