Rev 1721 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 1721 | Rev 1966 | ||
---|---|---|---|
1 | /* |
1 | /* |
2 | * Copyright (C) 2006 Ondrej Palkovsky |
2 | * Copyright (C) 2006 Ondrej Palkovsky |
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 | /** @addtogroup ippc IPC Tester |
29 | /** @addtogroup ippc IPC Tester |
30 | * @brief IPC tester and task faulter. |
30 | * @brief IPC tester and task faulter. |
31 | * @{ |
31 | * @{ |
32 | */ |
32 | */ |
33 | /** |
33 | /** |
34 | * @file |
34 | * @file |
35 | */ |
35 | */ |
36 | 36 | ||
37 | #include <stdio.h> |
37 | #include <stdio.h> |
38 | #include <async.h> |
38 | #include <async.h> |
39 | #include <ipc/ipc.h> |
39 | #include <ipc/ipc.h> |
40 | #include <ipc/services.h> |
40 | #include <ipc/services.h> |
41 | #include <errno.h> |
41 | #include <errno.h> |
42 | 42 | ||
43 | #define TEST_START 10000 |
43 | #define TEST_START 10000 |
44 | #define MAXLIST 4 |
44 | #define MAXLIST 4 |
45 | 45 | ||
46 | #define MSG_HANG_ME_UP 2000 |
46 | #define MSG_HANG_ME_UP 2000 |
47 | 47 | ||
48 | static int connections[50]; |
48 | static int connections[50]; |
49 | static ipc_callid_t callids[50]; |
49 | static ipc_callid_t callids[50]; |
50 | static int phones[20]; |
50 | static int phones[20]; |
51 | static int myservice = 0; |
51 | static int myservice = 0; |
52 | 52 | ||
53 | static void client_connection(ipc_callid_t iid, ipc_call_t *icall) |
53 | static void client_connection(ipc_callid_t iid, ipc_call_t *icall) |
54 | { |
54 | { |
55 | ipc_callid_t callid; |
55 | ipc_callid_t callid; |
56 | ipc_call_t call; |
56 | ipc_call_t call; |
57 | ipcarg_t phonehash = icall->in_phone_hash; |
57 | ipcarg_t phonehash = icall->in_phone_hash; |
58 | int retval; |
58 | int retval; |
59 | int i; |
59 | int i; |
60 | 60 | ||
61 | printf("Connected phone: %P, accepting\n", icall->in_phone_hash); |
61 | printf("Connected phone: %P, accepting\n", icall->in_phone_hash); |
62 | ipc_answer_fast(iid, 0, 0, 0); |
62 | ipc_answer_fast(iid, 0, 0, 0); |
63 | for (i=0;i < 1024;i++) |
63 | for (i=0;i < 1024;i++) |
64 | if (!connections[i]) { |
64 | if (!connections[i]) { |
65 | connections[i] = phonehash; |
65 | connections[i] = phonehash; |
66 | break; |
66 | break; |
67 | } |
67 | } |
68 | 68 | ||
69 | while (1) { |
69 | while (1) { |
70 | callid = async_get_call(&call); |
70 | callid = async_get_call(&call); |
71 | switch (IPC_GET_METHOD(call)) { |
71 | switch (IPC_GET_METHOD(call)) { |
72 | case IPC_M_PHONE_HUNGUP: |
72 | case IPC_M_PHONE_HUNGUP: |
73 | printf("Phone (%P) hung up.\n", phonehash); |
73 | printf("Phone (%P) hung up.\n", phonehash); |
74 | retval = 0; |
74 | retval = 0; |
75 | break; |
75 | break; |
76 | default: |
76 | default: |
77 | printf("Received message from %P: %X\n", phonehash,callid); |
77 | printf("Received message from %P: %X\n", phonehash,callid); |
78 | for (i=0; i < 1024; i++) |
78 | for (i=0; i < 1024; i++) |
79 | if (!callids[i]) { |
79 | if (!callids[i]) { |
80 | callids[i] = callid; |
80 | callids[i] = callid; |
81 | break; |
81 | break; |
82 | } |
82 | } |
83 | continue; |
83 | continue; |
84 | } |
84 | } |
85 | ipc_answer_fast(callid, retval, 0, 0); |
85 | ipc_answer_fast(callid, retval, 0, 0); |
86 | } |
86 | } |
87 | } |
87 | } |
88 | 88 | ||
89 | static void printhelp(void) |
89 | static void printhelp(void) |
90 | { |
90 | { |
91 | printf("? - help\n"); |
91 | printf("? - help\n"); |
92 | printf("c - connect to other service\n"); |
92 | printf("c - connect to other service\n"); |
93 | printf("h - hangup connection\n"); |
93 | printf("h - hangup connection\n"); |
94 | printf("a - send async message to other service\n"); |
94 | printf("a - send async message to other service\n"); |
95 | printf("s - send sync message to other service\n"); |
95 | printf("s - send sync message to other service\n"); |
96 | printf("d - answer message that we have received\n"); |
96 | printf("d - answer message that we have received\n"); |
97 | printf("j - jump to endless loop\n"); |
97 | printf("j - jump to endless loop\n"); |
98 | printf("p - page fault\n"); |
98 | printf("p - page fault\n"); |
99 | printf("u - unaligned read\n"); |
99 | printf("u - unaligned read\n"); |
100 | } |
100 | } |
101 | 101 | ||
102 | static void callback(void *private, int retval, ipc_call_t *data) |
102 | static void callback(void *private, int retval, ipc_call_t *data) |
103 | { |
103 | { |
104 | printf("Received response to msg %d - retval: %d.\n", private, |
104 | printf("Received response to msg %d - retval: %d.\n", private, |
105 | retval); |
105 | retval); |
106 | } |
106 | } |
107 | 107 | ||
108 | static void do_answer_msg(void) |
108 | static void do_answer_msg(void) |
109 | { |
109 | { |
110 | int i,cnt, errn = 0; |
110 | int i,cnt, errn = 0; |
111 | char c; |
111 | char c; |
112 | 112 | ||
113 | cnt = 0; |
113 | cnt = 0; |
114 | for (i=0;i < 50;i++) { |
114 | for (i=0;i < 50;i++) { |
115 | if (callids[i]) { |
115 | if (callids[i]) { |
116 | printf("%d: %P\n", cnt, callids[i]); |
116 | printf("%d: %P\n", cnt, callids[i]); |
117 | cnt++; |
117 | cnt++; |
118 | } |
118 | } |
119 | if (cnt >= 10) |
119 | if (cnt >= 10) |
120 | break; |
120 | break; |
121 | } |
121 | } |
122 | if (!cnt) |
122 | if (!cnt) |
123 | return; |
123 | return; |
124 | printf("Choose message:\n"); |
124 | printf("Choose message:\n"); |
125 | do { |
125 | do { |
126 | c = getchar(); |
126 | c = getchar(); |
127 | } while (c < '0' || (c-'0') >= cnt); |
127 | } while (c < '0' || (c-'0') >= cnt); |
128 | cnt = c - '0' + 1; |
128 | cnt = c - '0' + 1; |
129 | 129 | ||
130 | for (i=0;cnt;i++) |
130 | for (i=0;cnt;i++) |
131 | if (callids[i]) |
131 | if (callids[i]) |
132 | cnt--; |
132 | cnt--; |
133 | i -= 1; |
133 | i -= 1; |
134 | 134 | ||
135 | printf("Normal (n) or hangup (h) or error(e) message?\n"); |
135 | printf("Normal (n) or hangup (h) or error(e) message?\n"); |
136 | do { |
136 | do { |
137 | c = getchar(); |
137 | c = getchar(); |
138 | } while (c != 'n' && c != 'h' && c != 'e'); |
138 | } while (c != 'n' && c != 'h' && c != 'e'); |
139 | if (c == 'n') |
139 | if (c == 'n') |
140 | errn = 0; |
140 | errn = 0; |
141 | else if (c == 'h') |
141 | else if (c == 'h') |
142 | errn = EHANGUP; |
142 | errn = EHANGUP; |
143 | else if (c == 'e') |
143 | else if (c == 'e') |
144 | errn = ENOENT; |
144 | errn = ENOENT; |
145 | printf("Answering %P\n", callids[i]); |
145 | printf("Answering %P\n", callids[i]); |
146 | ipc_answer_fast(callids[i], errn, 0, 0); |
146 | ipc_answer_fast(callids[i], errn, 0, 0); |
147 | callids[i] = 0; |
147 | callids[i] = 0; |
148 | } |
148 | } |
149 | 149 | ||
150 | static void do_send_msg(int async) |
150 | static void do_send_msg(int async) |
151 | { |
151 | { |
152 | int phoneid; |
152 | int phoneid; |
153 | int res; |
153 | int res; |
154 | static int msgid = 1; |
154 | static int msgid = 1; |
155 | char c; |
155 | char c; |
156 | 156 | ||
157 | printf("Select phoneid to send msg: 2-9\n"); |
157 | printf("Select phoneid to send msg: 2-9\n"); |
158 | do { |
158 | do { |
159 | c = getchar(); |
159 | c = getchar(); |
160 | } while (c < '2' || c > '9'); |
160 | } while (c < '2' || c > '9'); |
161 | phoneid = c - '0'; |
161 | phoneid = c - '0'; |
162 | 162 | ||
163 | if (async) { |
163 | if (async) { |
164 | ipc_call_async(phoneid, 2000, 0, (void *)msgid, callback, 1); |
164 | ipc_call_async(phoneid, 2000, 0, (void *)msgid, callback, 1); |
165 | printf("Async sent - msg %d\n", msgid); |
165 | printf("Async sent - msg %d\n", msgid); |
166 | msgid++; |
166 | msgid++; |
167 | } else { |
167 | } else { |
168 | printf("Sending msg..."); |
168 | printf("Sending msg..."); |
169 | res = ipc_call_sync_2(phoneid, 2000, 0, 0, NULL, NULL); |
169 | res = ipc_call_sync_2(phoneid, 2000, 0, 0, NULL, NULL); |
170 | printf("done: %d\n", res); |
170 | printf("done: %d\n", res); |
171 | } |
171 | } |
172 | } |
172 | } |
173 | 173 | ||
174 | static void do_hangup(void) |
174 | static void do_hangup(void) |
175 | { |
175 | { |
176 | char c; |
176 | char c; |
177 | int res; |
177 | int res; |
178 | int phoneid; |
178 | int phoneid; |
179 | 179 | ||
180 | printf("Select phoneid to hangup: 2-9\n"); |
180 | printf("Select phoneid to hangup: 2-9\n"); |
181 | do { |
181 | do { |
182 | c = getchar(); |
182 | c = getchar(); |
183 | } while (c < '2' || c > '9'); |
183 | } while (c < '2' || c > '9'); |
184 | phoneid = c - '0'; |
184 | phoneid = c - '0'; |
185 | 185 | ||
186 | printf("Hanging up..."); |
186 | printf("Hanging up..."); |
187 | res = ipc_hangup(phoneid); |
187 | res = ipc_hangup(phoneid); |
188 | printf("done: %d\n", phoneid); |
188 | printf("done: %d\n", phoneid); |
189 | } |
189 | } |
190 | 190 | ||
191 | static void do_connect(void) |
191 | static void do_connect(void) |
192 | { |
192 | { |
193 | char c; |
193 | char c; |
194 | int svc; |
194 | int svc; |
195 | int phid; |
195 | int phid; |
196 | 196 | ||
197 | printf("Choose one service: 0:10000....9:10009\n"); |
197 | printf("Choose one service: 0:10000....9:10009\n"); |
198 | do { |
198 | do { |
199 | c = getchar(); |
199 | c = getchar(); |
200 | } while (c < '0' || c > '9'); |
200 | } while (c < '0' || c > '9'); |
201 | svc = TEST_START + c - '0'; |
201 | svc = TEST_START + c - '0'; |
202 | if (svc == myservice) { |
202 | if (svc == myservice) { |
203 | printf("Currently cannot connect to myself, update test\n"); |
203 | printf("Currently cannot connect to myself, update test\n"); |
204 | return; |
204 | return; |
205 | } |
205 | } |
206 | printf("Connecting to %d..", svc); |
206 | printf("Connecting to %d..", svc); |
207 | phid = ipc_connect_me_to(PHONE_NS, svc, 0); |
207 | phid = ipc_connect_me_to(PHONE_NS, svc, 0); |
208 | if (phid > 0) { |
208 | if (phid > 0) { |
209 | printf("phoneid: %d\n", phid); |
209 | printf("phoneid: %d\n", phid); |
210 | phones[phid] = 1; |
210 | phones[phid] = 1; |
211 | } else |
211 | } else |
212 | printf("error: %d\n", phid); |
212 | printf("error: %d\n", phid); |
213 | } |
213 | } |
214 | 214 | ||
215 | 215 | ||
216 | 216 | ||
217 | int main(void) |
217 | int main(void) |
218 | { |
218 | { |
219 | ipcarg_t phonead; |
219 | ipcarg_t phonead; |
220 | int i; |
220 | int i; |
221 | char c; |
221 | char c; |
222 | int res; |
222 | int res; |
223 | volatile long long var; |
223 | volatile long long var; |
224 | volatile int var1; |
224 | volatile int var1; |
225 | 225 | ||
226 | printf("********************************\n"); |
226 | printf("********************************\n"); |
227 | printf("***********IPC Tester***********\n"); |
227 | printf("***********IPC Tester***********\n"); |
228 | printf("********************************\n"); |
228 | printf("********************************\n"); |
229 | 229 | ||
230 | 230 | ||
231 | async_set_client_connection(client_connection); |
231 | async_set_client_connection(client_connection); |
232 | 232 | ||
233 | for (i=TEST_START;i < TEST_START+10;i++) { |
233 | for (i=TEST_START;i < TEST_START+10;i++) { |
234 | res = ipc_connect_to_me(PHONE_NS, i, 0, &phonead); |
234 | res = ipc_connect_to_me(PHONE_NS, i, 0, &phonead); |
235 | if (!res) |
235 | if (!res) |
236 | break; |
236 | break; |
237 | printf("Failed registering as %d..:%d\n", i, res); |
237 | printf("Failed registering as %d..:%d\n", i, res); |
238 | } |
238 | } |
239 | printf("Registered as service: %d\n", i); |
239 | printf("Registered as service: %d\n", i); |
240 | myservice = i; |
240 | myservice = i; |
241 | 241 | ||
242 | printhelp(); |
242 | printhelp(); |
243 | while (1) { |
243 | while (1) { |
244 | c = getchar(); |
244 | c = getchar(); |
245 | switch (c) { |
245 | switch (c) { |
246 | case '?': |
246 | case '?': |
247 | printhelp(); |
247 | printhelp(); |
248 | break; |
248 | break; |
249 | case 'h': |
249 | case 'h': |
250 | do_hangup(); |
250 | do_hangup(); |
251 | break; |
251 | break; |
252 | case 'c': |
252 | case 'c': |
253 | do_connect(); |
253 | do_connect(); |
254 | break; |
254 | break; |
255 | case 'a': |
255 | case 'a': |
256 | do_send_msg(1); |
256 | do_send_msg(1); |
257 | break; |
257 | break; |
258 | case 's': |
258 | case 's': |
259 | do_send_msg(0); |
259 | do_send_msg(0); |
260 | break; |
260 | break; |
261 | case 'd': |
261 | case 'd': |
262 | do_answer_msg(); |
262 | do_answer_msg(); |
263 | break; |
263 | break; |
264 | case 'j': |
264 | case 'j': |
265 | while (1) |
265 | while (1) |
266 | ; |
266 | ; |
267 | case 'p': |
267 | case 'p': |
268 | printf("Doing page fault\n"); |
268 | printf("Doing page fault\n"); |
269 | *((char *)0) = 1; |
269 | *((char *)0) = 1; |
270 | printf("done\n"); |
270 | printf("done\n"); |
271 | case 'u': |
271 | case 'u': |
272 | var1=*( (int *) ( ( (char *)(&var) ) + 1 ) ); |
272 | var1=*( (int *) ( ( (char *)(&var) ) + 1 ) ); |
273 | break; |
273 | break; |
274 | } |
274 | } |
275 | } |
275 | } |
276 | } |
276 | } |
277 | 277 | ||
278 | /** @} |
278 | /** @} |
279 | */ |
279 | */ |
280 | 280 | ||
281 | 281 |