00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00037 #include <stdio.h>
00038 #include <async.h>
00039 #include <ipc/ipc.h>
00040 #include <ipc/services.h>
00041 #include <errno.h>
00042
00043 #define TEST_START 10000
00044 #define MAXLIST 4
00045
00046 #define MSG_HANG_ME_UP 2000
00047
00048 static int connections[50];
00049 static ipc_callid_t callids[50];
00050 static int phones[20];
00051 static int myservice = 0;
00052
00053 static void client_connection(ipc_callid_t iid, ipc_call_t *icall)
00054 {
00055 ipc_callid_t callid;
00056 ipc_call_t call;
00057 ipcarg_t phonehash = icall->in_phone_hash;
00058 int retval;
00059 int i;
00060
00061 printf("Connected phone: %P, accepting\n", icall->in_phone_hash);
00062 ipc_answer_fast(iid, 0, 0, 0);
00063 for (i=0;i < 1024;i++)
00064 if (!connections[i]) {
00065 connections[i] = phonehash;
00066 break;
00067 }
00068
00069 while (1) {
00070 callid = async_get_call(&call);
00071 switch (IPC_GET_METHOD(call)) {
00072 case IPC_M_PHONE_HUNGUP:
00073 printf("Phone (%P) hung up.\n", phonehash);
00074 retval = 0;
00075 break;
00076 default:
00077 printf("Received message from %P: %X\n", phonehash,callid);
00078 for (i=0; i < 1024; i++)
00079 if (!callids[i]) {
00080 callids[i] = callid;
00081 break;
00082 }
00083 continue;
00084 }
00085 ipc_answer_fast(callid, retval, 0, 0);
00086 }
00087 }
00088
00089 static void printhelp(void)
00090 {
00091 printf("? - help\n");
00092 printf("c - connect to other service\n");
00093 printf("h - hangup connection\n");
00094 printf("a - send async message to other service\n");
00095 printf("s - send sync message to other service\n");
00096 printf("d - answer message that we have received\n");
00097 printf("j - jump to endless loop\n");
00098 printf("p - page fault\n");
00099 printf("u - unaligned read\n");
00100 }
00101
00102 static void callback(void *private, int retval, ipc_call_t *data)
00103 {
00104 printf("Received response to msg %d - retval: %d.\n", private,
00105 retval);
00106 }
00107
00108 static void do_answer_msg(void)
00109 {
00110 int i,cnt, errn = 0;
00111 char c;
00112
00113 cnt = 0;
00114 for (i=0;i < 50;i++) {
00115 if (callids[i]) {
00116 printf("%d: %P\n", cnt, callids[i]);
00117 cnt++;
00118 }
00119 if (cnt >= 10)
00120 break;
00121 }
00122 if (!cnt)
00123 return;
00124 printf("Choose message:\n");
00125 do {
00126 c = getchar();
00127 } while (c < '0' || (c-'0') >= cnt);
00128 cnt = c - '0' + 1;
00129
00130 for (i=0;cnt;i++)
00131 if (callids[i])
00132 cnt--;
00133 i -= 1;
00134
00135 printf("Normal (n) or hangup (h) or error(e) message?\n");
00136 do {
00137 c = getchar();
00138 } while (c != 'n' && c != 'h' && c != 'e');
00139 if (c == 'n')
00140 errn = 0;
00141 else if (c == 'h')
00142 errn = EHANGUP;
00143 else if (c == 'e')
00144 errn = ENOENT;
00145 printf("Answering %P\n", callids[i]);
00146 ipc_answer_fast(callids[i], errn, 0, 0);
00147 callids[i] = 0;
00148 }
00149
00150 static void do_send_msg(int async)
00151 {
00152 int phoneid;
00153 int res;
00154 static int msgid = 1;
00155 char c;
00156
00157 printf("Select phoneid to send msg: 2-9\n");
00158 do {
00159 c = getchar();
00160 } while (c < '2' || c > '9');
00161 phoneid = c - '0';
00162
00163 if (async) {
00164 ipc_call_async(phoneid, 2000, 0, (void *)msgid, callback, 1);
00165 printf("Async sent - msg %d\n", msgid);
00166 msgid++;
00167 } else {
00168 printf("Sending msg...");
00169 res = ipc_call_sync_2(phoneid, 2000, 0, 0, NULL, NULL);
00170 printf("done: %d\n", res);
00171 }
00172 }
00173
00174 static void do_hangup(void)
00175 {
00176 char c;
00177 int res;
00178 int phoneid;
00179
00180 printf("Select phoneid to hangup: 2-9\n");
00181 do {
00182 c = getchar();
00183 } while (c < '2' || c > '9');
00184 phoneid = c - '0';
00185
00186 printf("Hanging up...");
00187 res = ipc_hangup(phoneid);
00188 printf("done: %d\n", phoneid);
00189 }
00190
00191 static void do_connect(void)
00192 {
00193 char c;
00194 int svc;
00195 int phid;
00196
00197 printf("Choose one service: 0:10000....9:10009\n");
00198 do {
00199 c = getchar();
00200 } while (c < '0' || c > '9');
00201 svc = TEST_START + c - '0';
00202 if (svc == myservice) {
00203 printf("Currently cannot connect to myself, update test\n");
00204 return;
00205 }
00206 printf("Connecting to %d..", svc);
00207 phid = ipc_connect_me_to(PHONE_NS, svc, 0);
00208 if (phid > 0) {
00209 printf("phoneid: %d\n", phid);
00210 phones[phid] = 1;
00211 } else
00212 printf("error: %d\n", phid);
00213 }
00214
00215
00216
00217 int main(void)
00218 {
00219 ipcarg_t phonead;
00220 int i;
00221 char c;
00222 int res;
00223 volatile long long var;
00224 volatile int var1;
00225
00226 printf("********************************\n");
00227 printf("***********IPC Tester***********\n");
00228 printf("********************************\n");
00229
00230
00231 async_set_client_connection(client_connection);
00232
00233 for (i=TEST_START;i < TEST_START+10;i++) {
00234 res = ipc_connect_to_me(PHONE_NS, i, 0, &phonead);
00235 if (!res)
00236 break;
00237 printf("Failed registering as %d..:%d\n", i, res);
00238 }
00239 printf("Registered as service: %d\n", i);
00240 myservice = i;
00241
00242 printhelp();
00243 while (1) {
00244 c = getchar();
00245 switch (c) {
00246 case '?':
00247 printhelp();
00248 break;
00249 case 'h':
00250 do_hangup();
00251 break;
00252 case 'c':
00253 do_connect();
00254 break;
00255 case 'a':
00256 do_send_msg(1);
00257 break;
00258 case 's':
00259 do_send_msg(0);
00260 break;
00261 case 'd':
00262 do_answer_msg();
00263 break;
00264 case 'j':
00265 while (1)
00266 ;
00267 case 'p':
00268 printf("Doing page fault\n");
00269 *((char *)0) = 1;
00270 printf("done\n");
00271 case 'u':
00272 var1=*( (int *) ( ( (char *)(&var) ) + 1 ) );
00273 break;
00274 }
00275 }
00276 }
00277