Subversion Repositories HelenOS-historic

Rev

Rev 1618 | Rev 1657 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 1618 Rev 1653
-
 
1
/*
-
 
2
 * Copyright (C) 2006 Ondrej Palkovsky
-
 
3
 * All rights reserved.
-
 
4
 *
-
 
5
 * Redistribution and use in source and binary forms, with or without
-
 
6
 * modification, are permitted provided that the following conditions
-
 
7
 * are met:
-
 
8
 *
-
 
9
 * - Redistributions of source code must retain the above copyright
-
 
10
 *   notice, this list of conditions and the following disclaimer.
-
 
11
 * - Redistributions in binary form must reproduce the above copyright
-
 
12
 *   notice, this list of conditions and the following disclaimer in the
-
 
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
-
 
15
 *   derived from this software without specific prior written permission.
-
 
16
 *
-
 
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
-
 
19
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
-
 
20
 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
-
 
21
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
-
 
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
-
 
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
-
 
26
 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
 
27
 */
-
 
28
 
-
 
29
/** @addtogroup ippc IPPC
-
 
30
 * @brief   Interprocess communication tester.
-
 
31
 * @{
-
 
32
 */
-
 
33
/**
-
 
34
 * @file
-
 
35
 */
-
 
36
 
1
#include <stdio.h>
37
#include <stdio.h>
2
#include <async.h>
38
#include <async.h>
3
#include <ipc/ipc.h>
39
#include <ipc/ipc.h>
4
#include <ipc/services.h>
40
#include <ipc/services.h>
5
#include <errno.h>
41
#include <errno.h>
6
 
42
 
7
#define TEST_START       10000
43
#define TEST_START       10000
8
#define MAXLIST          4
44
#define MAXLIST          4
9
 
45
 
10
#define MSG_HANG_ME_UP   2000
46
#define MSG_HANG_ME_UP   2000
11
 
47
 
12
static int connections[50];
48
static int connections[50];
13
static ipc_callid_t callids[50];
49
static ipc_callid_t callids[50];
14
static int phones[20];
50
static int phones[20];
15
static int myservice = 0;
51
static int myservice = 0;
16
 
52
 
17
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)
18
{
54
{
19
    ipc_callid_t callid;
55
    ipc_callid_t callid;
20
    ipc_call_t call;
56
    ipc_call_t call;
21
    ipcarg_t phonehash = icall->in_phone_hash;
57
    ipcarg_t phonehash = icall->in_phone_hash;
22
    int retval;
58
    int retval;
23
    int i;
59
    int i;
24
 
60
 
25
    printf("Connected phone: %P, accepting\n", icall->in_phone_hash);
61
    printf("Connected phone: %P, accepting\n", icall->in_phone_hash);
26
    ipc_answer_fast(iid, 0, 0, 0);
62
    ipc_answer_fast(iid, 0, 0, 0);
27
    for (i=0;i < 1024;i++)
63
    for (i=0;i < 1024;i++)
28
        if (!connections[i]) {
64
        if (!connections[i]) {
29
            connections[i] = phonehash;
65
            connections[i] = phonehash;
30
            break;
66
            break;
31
        }
67
        }
32
   
68
   
33
    while (1) {
69
    while (1) {
34
        callid = async_get_call(&call);
70
        callid = async_get_call(&call);
35
        switch (IPC_GET_METHOD(call)) {
71
        switch (IPC_GET_METHOD(call)) {
36
        case IPC_M_PHONE_HUNGUP:
72
        case IPC_M_PHONE_HUNGUP:
37
            printf("Phone (%P) hung up.\n", phonehash);
73
            printf("Phone (%P) hung up.\n", phonehash);
38
            retval = 0;
74
            retval = 0;
39
            break;
75
            break;
40
        default:
76
        default:
41
            printf("Received message from %P: %X\n", phonehash,callid);
77
            printf("Received message from %P: %X\n", phonehash,callid);
42
            for (i=0; i < 1024; i++)
78
            for (i=0; i < 1024; i++)
43
                if (!callids[i]) {
79
                if (!callids[i]) {
44
                    callids[i] = callid;
80
                    callids[i] = callid;
45
                    break;
81
                    break;
46
                }
82
                }
47
            continue;
83
            continue;
48
        }
84
        }
49
        ipc_answer_fast(callid, retval, 0, 0);
85
        ipc_answer_fast(callid, retval, 0, 0);
50
    }
86
    }
51
}
87
}
52
 
88
 
53
static void printhelp(void)
89
static void printhelp(void)
54
{
90
{
55
    printf("? - help\n");
91
    printf("? - help\n");
56
    printf("c - connect to other service\n");
92
    printf("c - connect to other service\n");
57
    printf("h - hangup connection\n");
93
    printf("h - hangup connection\n");
58
    printf("a - send async message to other service\n");
94
    printf("a - send async message to other service\n");
59
    printf("s - send sync message to other service\n");
95
    printf("s - send sync message to other service\n");
60
    printf("d - answer message that we have received\n");
96
    printf("d - answer message that we have received\n");
61
    printf("j - jump to endless loop\n");
97
    printf("j - jump to endless loop\n");
62
    printf("p - page fault\n");
98
    printf("p - page fault\n");
63
    printf("u - unaligned read\n");
99
    printf("u - unaligned read\n");
64
}
100
}
65
 
101
 
66
static void callback(void *private, int retval, ipc_call_t *data)
102
static void callback(void *private, int retval, ipc_call_t *data)
67
{
103
{
68
    printf("Received response to msg %d - retval: %d.\n", private,
104
    printf("Received response to msg %d - retval: %d.\n", private,
69
           retval);
105
           retval);
70
}
106
}
71
 
107
 
72
static void do_answer_msg(void)
108
static void do_answer_msg(void)
73
{
109
{
74
    int i,cnt, errn;
110
    int i,cnt, errn;
75
    char c;
111
    char c;
76
    ipc_callid_t callid;
112
    ipc_callid_t callid;
77
 
113
 
78
    cnt = 0;
114
    cnt = 0;
79
    for (i=0;i < 50;i++) {
115
    for (i=0;i < 50;i++) {
80
        if (callids[i]) {
116
        if (callids[i]) {
81
            printf("%d: %P\n", cnt, callids[i]);
117
            printf("%d: %P\n", cnt, callids[i]);
82
            cnt++;
118
            cnt++;
83
        }
119
        }
84
        if (cnt >= 10)
120
        if (cnt >= 10)
85
            break;
121
            break;
86
    }
122
    }
87
    if (!cnt)
123
    if (!cnt)
88
        return;
124
        return;
89
    printf("Choose message:\n");
125
    printf("Choose message:\n");
90
    do {
126
    do {
91
        c = getchar();
127
        c = getchar();
92
    } while (c < '0' || (c-'0') >= cnt);
128
    } while (c < '0' || (c-'0') >= cnt);
93
    cnt = c - '0' + 1;
129
    cnt = c - '0' + 1;
94
   
130
   
95
    for (i=0;cnt;i++)
131
    for (i=0;cnt;i++)
96
        if (callids[i])
132
        if (callids[i])
97
            cnt--;
133
            cnt--;
98
    i -= 1;
134
    i -= 1;
99
 
135
 
100
    printf("Normal (n) or hangup (h) or error(e) message?\n");
136
    printf("Normal (n) or hangup (h) or error(e) message?\n");
101
    do {
137
    do {
102
        c = getchar();
138
        c = getchar();
103
    } while (c != 'n' && c != 'h' && c != 'e');
139
    } while (c != 'n' && c != 'h' && c != 'e');
104
    if (c == 'n')
140
    if (c == 'n')
105
        errn = 0;
141
        errn = 0;
106
    else if (c == 'h')
142
    else if (c == 'h')
107
        errn = EHANGUP;
143
        errn = EHANGUP;
108
    else if (c == 'e')
144
    else if (c == 'e')
109
        errn = ENOENT;
145
        errn = ENOENT;
110
    printf("Answering %P\n", callids[i]);
146
    printf("Answering %P\n", callids[i]);
111
    ipc_answer_fast(callids[i], errn, 0, 0);
147
    ipc_answer_fast(callids[i], errn, 0, 0);
112
    callids[i] = 0;
148
    callids[i] = 0;
113
}
149
}
114
 
150
 
115
static void do_send_msg(int async)
151
static void do_send_msg(int async)
116
{
152
{
117
    int phoneid;
153
    int phoneid;
118
    int res;
154
    int res;
119
    static int msgid = 1;
155
    static int msgid = 1;
120
    char c;
156
    char c;
121
 
157
 
122
    printf("Select phoneid to send msg: 2-9\n");
158
    printf("Select phoneid to send msg: 2-9\n");
123
    do {
159
    do {
124
        c = getchar();
160
        c = getchar();
125
    } while (c < '2' || c > '9');
161
    } while (c < '2' || c > '9');
126
    phoneid = c - '0';
162
    phoneid = c - '0';
127
 
163
 
128
    if (async) {
164
    if (async) {
129
        ipc_call_async(phoneid, 2000, 0, (void *)msgid, callback, 1);
165
        ipc_call_async(phoneid, 2000, 0, (void *)msgid, callback, 1);
130
        printf("Async sent - msg %d\n", msgid);
166
        printf("Async sent - msg %d\n", msgid);
131
        msgid++;
167
        msgid++;
132
    } else {
168
    } else {
133
        printf("Sending msg...");
169
        printf("Sending msg...");
134
        res = ipc_call_sync_2(phoneid, 2000, 0, 0, NULL, NULL);
170
        res = ipc_call_sync_2(phoneid, 2000, 0, 0, NULL, NULL);
135
        printf("done: %d\n", res);
171
        printf("done: %d\n", res);
136
    }
172
    }
137
}
173
}
138
 
174
 
139
static void do_hangup(void)
175
static void do_hangup(void)
140
{
176
{
141
    char c;
177
    char c;
142
    int res;
178
    int res;
143
    int phoneid;
179
    int phoneid;
144
 
180
 
145
    printf("Select phoneid to hangup: 2-9\n");
181
    printf("Select phoneid to hangup: 2-9\n");
146
    do {
182
    do {
147
        c = getchar();
183
        c = getchar();
148
    } while (c < '2' || c > '9');
184
    } while (c < '2' || c > '9');
149
    phoneid = c - '0';
185
    phoneid = c - '0';
150
   
186
   
151
    printf("Hanging up...");
187
    printf("Hanging up...");
152
    res = ipc_hangup(phoneid);
188
    res = ipc_hangup(phoneid);
153
    printf("done: %d\n", phoneid);
189
    printf("done: %d\n", phoneid);
154
}
190
}
155
 
191
 
156
static void do_connect(void)
192
static void do_connect(void)
157
{
193
{
158
    char c;
194
    char c;
159
    int svc;
195
    int svc;
160
    int phid;
196
    int phid;
161
 
197
 
162
    printf("Choose one service: 0:10000....9:10009\n");
198
    printf("Choose one service: 0:10000....9:10009\n");
163
    do {
199
    do {
164
        c = getchar();
200
        c = getchar();
165
    } while (c < '0' || c > '9');
201
    } while (c < '0' || c > '9');
166
    svc = TEST_START + c - '0';
202
    svc = TEST_START + c - '0';
167
    if (svc == myservice) {
203
    if (svc == myservice) {
168
        printf("Currently cannot connect to myself, update test\n");
204
        printf("Currently cannot connect to myself, update test\n");
169
        return;
205
        return;
170
    }
206
    }
171
    printf("Connecting to %d..", svc);
207
    printf("Connecting to %d..", svc);
172
    phid = ipc_connect_me_to(PHONE_NS, svc, 0);
208
    phid = ipc_connect_me_to(PHONE_NS, svc, 0);
173
    if (phid > 0) {
209
    if (phid > 0) {
174
        printf("phoneid: %d\n", phid);
210
        printf("phoneid: %d\n", phid);
175
        phones[phid] = 1;
211
        phones[phid] = 1;
176
    } else
212
    } else
177
        printf("error: %d\n", phid);
213
        printf("error: %d\n", phid);
178
}
214
}
179
 
215
 
180
 
216
 
181
 
217
 
182
int main(void)
218
int main(void)
183
{
219
{
184
    ipcarg_t phonead;
220
    ipcarg_t phonead;
185
    int i;
221
    int i;
186
    char c;
222
    char c;
187
    int res;
223
    int res;
188
    volatile long long var;
224
    volatile long long var;
189
    volatile int var1;
225
    volatile int var1;
190
   
226
   
191
    printf("********************************\n");
227
    printf("********************************\n");
192
    printf("***********IPC Tester***********\n");
228
    printf("***********IPC Tester***********\n");
193
    printf("********************************\n");
229
    printf("********************************\n");
194
 
230
 
195
   
231
   
196
    async_set_client_connection(client_connection);
232
    async_set_client_connection(client_connection);
197
 
233
 
198
    for (i=TEST_START;i < TEST_START+10;i++) {
234
    for (i=TEST_START;i < TEST_START+10;i++) {
199
        res = ipc_connect_to_me(PHONE_NS, i, 0, &phonead);
235
        res = ipc_connect_to_me(PHONE_NS, i, 0, &phonead);
200
        if (!res)
236
        if (!res)
201
            break;
237
            break;
202
        printf("Failed registering as %d..:%d\n", i, res);
238
        printf("Failed registering as %d..:%d\n", i, res);
203
    }
239
    }
204
    printf("Registered as service: %d\n", i);
240
    printf("Registered as service: %d\n", i);
205
    myservice = i;
241
    myservice = i;
206
 
242
 
207
    printhelp();
243
    printhelp();
208
    while (1) {
244
    while (1) {
209
        c = getchar();
245
        c = getchar();
210
        switch (c) {
246
        switch (c) {
211
        case '?':
247
        case '?':
212
            printhelp();
248
            printhelp();
213
            break;
249
            break;
214
        case 'h':
250
        case 'h':
215
            do_hangup();
251
            do_hangup();
216
            break;
252
            break;
217
        case 'c':
253
        case 'c':
218
            do_connect();
254
            do_connect();
219
            break;
255
            break;
220
        case 'a':
256
        case 'a':
221
            do_send_msg(1);
257
            do_send_msg(1);
222
            break;
258
            break;
223
        case 's':
259
        case 's':
224
            do_send_msg(0);
260
            do_send_msg(0);
225
            break;
261
            break;
226
        case 'd':
262
        case 'd':
227
            do_answer_msg();
263
            do_answer_msg();
228
            break;
264
            break;
229
        case 'j':
265
        case 'j':
230
            while (1)
266
            while (1)
231
                ;
267
                ;
232
        case 'p':
268
        case 'p':
233
            printf("Doing page fault\n");
269
            printf("Doing page fault\n");
234
            *((char *)0) = 1;
270
            *((char *)0) = 1;
235
            printf("done\n");
271
            printf("done\n");
236
        case 'u':
272
        case 'u':
237
            var1=*( (int *) ( ( (char *)(&var) ) + 1 ) );
273
            var1=*( (int *) ( ( (char *)(&var) ) + 1 ) );
238
            break;
274
            break;
239
        }
275
        }
240
    }
276
    }
241
}
277
}
-
 
278
 
-
 
279
/** @}
-
 
280
 */
-
 
281
 
242
 
282