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