Subversion Repositories HelenOS

Rev

Rev 2186 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 2186 Rev 2188
Line 1... Line 1...
1
/*
1
/*
2
 * Copyright (c) 2006 Ondrej Palkovsky
2
 * Copyright (c) 2006 Ondrej Palkovsky
-
 
3
 * Copyright (c) 2007 Martin Decky
3
 * All rights reserved.
4
 * All rights reserved.
4
 *
5
 *
5
 * Redistribution and use in source and binary forms, with or without
6
 * Redistribution and use in source and binary forms, with or without
6
 * modification, are permitted provided that the following conditions
7
 * modification, are permitted provided that the following conditions
7
 * are met:
8
 * are met:
Line 24... Line 25...
24
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25
 * 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
 * (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
 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27
 */
28
 */
28
 
29
 
29
/** @addtogroup ippc IPC Tester
30
/** @addtogroup tester User space Tester
30
 * @brief   IPC tester and task faulter.
31
 * @brief   User space testing infrastructure.
31
 * @{
32
 * @{
32
 */
33
 */
33
/**
34
/**
34
 * @file
35
 * @file
35
 */
36
 */
36
 
37
 
-
 
38
#include <unistd.h>
37
#include <stdio.h>
39
#include <stdio.h>
38
#include <async.h>
-
 
39
#include <ipc/ipc.h>
-
 
40
#include <ipc/services.h>
-
 
41
#include <errno.h>
40
#include "tester.h"
42
 
41
 
-
 
42
int myservice = 0;
-
 
43
int phones[MAX_PHONES];
-
 
44
int connections[MAX_CONNECTIONS];
-
 
45
ipc_callid_t callids[MAX_CONNECTIONS];
-
 
46
 
-
 
47
test_t tests[] = {
-
 
48
#include "thread/thread1.def"
43
#define TEST_START       10000
49
#include "print/print1.def"
44
#define MAXLIST          4
50
#include "ipc/register.def"
-
 
51
#include "ipc/connect.def"
-
 
52
    {NULL, NULL, NULL}
-
 
53
};
45
 
54
 
46
#define MSG_HANG_ME_UP   2000
-
 
47
 
-
 
48
static int connections[50];
55
static bool run_test(test_t *test)
49
static ipc_callid_t callids[50];
-
 
50
static int phones[20];
-
 
51
static int myservice = 0;
-
 
52
 
-
 
53
static void client_connection(ipc_callid_t iid, ipc_call_t *icall)
-
 
54
{
56
{
55
    ipc_callid_t callid;
-
 
56
    ipc_call_t call;
-
 
57
    ipcarg_t phonehash = icall->in_phone_hash;
-
 
58
    int retval;
-
 
59
    int i;
-
 
60
 
-
 
61
    printf("Connected phone: %P, accepting\n", icall->in_phone_hash);
57
    printf("%s\t\t%s\n", test->name, test->desc);
62
    ipc_answer_fast(iid, 0, 0, 0);
-
 
63
    for (i=0;i < 1024;i++)
-
 
64
        if (!connections[i]) {
-
 
65
            connections[i] = phonehash;
-
 
66
            break;
-
 
67
        }
-
 
68
   
58
   
69
    while (1) {
59
    /* Execute the test */
70
        callid = async_get_call(&call);
60
    char * ret = test->entry(false);
71
        switch (IPC_GET_METHOD(call)) {
-
 
72
        case IPC_M_PHONE_HUNGUP:
-
 
73
            printf("Phone (%P) hung up.\n", phonehash);
-
 
74
            retval = 0;
-
 
75
            break;
61
   
76
        default:
-
 
77
            printf("Received message from %P: %X\n", phonehash,callid);
-
 
78
            for (i = 0; i < 1024; i++)
-
 
79
                if (!callids[i]) {
62
    if (ret == NULL) {
80
                    callids[i] = callid;
63
        printf("Test passed\n\n");
81
                    break;
-
 
82
                }
-
 
83
            continue;
64
        return true;
84
        }
-
 
85
        ipc_answer_fast(callid, retval, 0, 0);
-
 
86
    }
65
    }
87
}
-
 
88
 
66
 
89
static void printhelp(void)
-
 
90
{
-
 
91
    printf("? - help\n");
67
    printf("%s\n\n", ret);
92
    printf("c - connect to other service\n");
-
 
93
    printf("h - hangup connection\n");
-
 
94
    printf("a - send async 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");
-
 
97
    printf("j - jump to endless loop\n");
-
 
98
    printf("p - page fault\n");
68
    return false;
99
    printf("u - unaligned read\n");
-
 
100
}
69
}
101
 
70
 
102
static void callback(void *private, int retval, ipc_call_t *data)
71
static void run_safe_tests(void)
103
{
72
{
104
    printf("Received response to msg %d - retval: %d.\n", private,
-
 
105
           retval);
-
 
106
}
73
}
107
 
74
 
108
static void do_answer_msg(void)
75
static void list_tests(void)
109
{
76
{
110
    int i,cnt, errn = 0;
-
 
111
    char c;
-
 
112
 
-
 
113
    cnt = 0;
77
    test_t *test;
114
    for (i = 0;i < 50; i++) {
-
 
115
        if (callids[i]) {
-
 
116
            printf("%d: %P\n", cnt, callids[i]);
-
 
117
            cnt++;
-
 
118
        }
-
 
119
        if (cnt >= 10)
-
 
120
            break;
-
 
121
    }
-
 
122
    if (!cnt)
-
 
123
        return;
-
 
124
    printf("Choose message:\n");
-
 
125
    do {
-
 
126
        c = getchar();
-
 
127
    } while (c < '0' || (c-'0') >= cnt);
-
 
128
    cnt = c - '0' + 1;
78
    char c = 'a';
129
   
79
   
130
    for (i = 0; cnt; i++)
80
    for (test = tests; test->name != NULL; test++, c++)
131
        if (callids[i])
-
 
132
            cnt--;
-
 
133
    i -= 1;
-
 
134
 
-
 
135
    printf("Normal (n) or hangup (h) or error(e) message?\n");
81
        printf("%c\t%s\t\t%s%s\n", c, test->name, test->desc, (test->safe ? "" : " (unsafe)"));
136
    do {
-
 
137
        c = getchar();
-
 
138
    } while (c != 'n' && c != 'h' && c != 'e');
-
 
139
    if (c == 'n')
-
 
140
        errn = 0;
-
 
141
    else if (c == 'h')
-
 
142
        errn = EHANGUP;
-
 
143
    else if (c == 'e')
-
 
144
        errn = ENOENT;
-
 
145
    printf("Answering %P\n", callids[i]);
-
 
146
    ipc_answer_fast(callids[i], errn, 0, 0);
-
 
147
    callids[i] = 0;
-
 
148
}
-
 
149
 
-
 
150
static void do_send_msg(int async)
-
 
151
{
-
 
152
    int phoneid;
-
 
153
    int res;
-
 
154
    static int msgid = 1;
-
 
155
    char c;
-
 
156
 
-
 
157
    printf("Select phoneid to send msg: 2-9\n");
-
 
158
    do {
-
 
159
        c = getchar();
-
 
160
    } while (c < '2' || c > '9');
-
 
161
    phoneid = c - '0';
-
 
162
 
-
 
163
    if (async) {
-
 
164
        ipc_call_async(phoneid, 2000, 0, (void *)msgid, callback, 1);
-
 
165
        printf("Async sent - msg %d\n", msgid);
-
 
166
        msgid++;
-
 
167
    } else {
-
 
168
        printf("Sending msg...");
-
 
169
        res = ipc_call_sync_2(phoneid, 2000, 0, 0, NULL, NULL);
-
 
170
        printf("done: %d\n", res);
-
 
171
    }
-
 
172
}
-
 
173
 
-
 
174
static void do_hangup(void)
-
 
175
{
-
 
176
    char c;
-
 
177
    int res;
-
 
178
    int phoneid;
-
 
179
 
-
 
180
    printf("Select phoneid to hangup: 2-9\n");
-
 
181
    do {
-
 
182
        c = getchar();
-
 
183
    } while (c < '2' || c > '9');
-
 
184
    phoneid = c - '0';
-
 
185
   
82
   
186
    printf("Hanging up...");
-
 
187
    res = ipc_hangup(phoneid);
-
 
188
    printf("done: %d\n", phoneid);
-
 
189
}
-
 
190
 
-
 
191
static void do_connect(void)
-
 
192
{
-
 
193
    char c;
-
 
194
    int svc;
-
 
195
    int phid;
-
 
196
 
-
 
197
    printf("Choose one service: 0:10000....9:10009\n");
-
 
198
    do {
-
 
199
        c = getchar();
-
 
200
    } while (c < '0' || c > '9');
-
 
201
    svc = TEST_START + c - '0';
-
 
202
    if (svc == myservice) {
-
 
203
        printf("Currently cannot connect to myself, update test\n");
-
 
204
        return;
-
 
205
    }
-
 
206
    printf("Connecting to %d..", svc);
83
    printf("*\t\t\tRun all safe tests\n");
207
    phid = ipc_connect_me_to(PHONE_NS, svc, 0);
-
 
208
    if (phid > 0) {
-
 
209
        printf("phoneid: %d\n", phid);
-
 
210
        phones[phid] = 1;
-
 
211
    } else
-
 
212
        printf("error: %d\n", phid);
-
 
213
}
84
}
214
 
85
 
215
int main(void)
86
int main(void)
216
{
87
{
217
    ipcarg_t phonead;
-
 
218
    int i;
-
 
219
    char c;
-
 
220
    int res;
-
 
221
    volatile long long var;
-
 
222
    volatile int var1;
-
 
223
   
-
 
224
    printf("********************************\n");
-
 
225
    printf("***********IPC Tester***********\n");
-
 
226
    printf("********************************\n");
-
 
227
   
-
 
228
    async_set_client_connection(client_connection);
-
 
229
 
-
 
230
    for (i = TEST_START; i < TEST_START + 10; i++) {
-
 
231
        res = ipc_connect_to_me(PHONE_NS, i, 0, &phonead);
-
 
232
        if (!res)
-
 
233
            break;
-
 
234
        printf("Failed registering as %d..:%d\n", i, res);
-
 
235
    }
-
 
236
    printf("Registered as service: %d\n", i);
-
 
237
    myservice = i;
-
 
238
 
-
 
239
    printhelp();
-
 
240
    while (1) {
88
    while (1) {
241
        c = getchar();
89
        char c;
242
        switch (c) {
90
        test_t *test;
243
        case '?':
91
       
244
            printhelp();
92
        list_tests();
245
            break;
-
 
246
        case 'h':
-
 
247
            do_hangup();
93
        printf("> ");
248
            break;
94
       
249
        case 'c':
95
        c = getchar();
250
            do_connect();
96
        printf("%c\n", c);
251
            break;
97
       
252
        case 'a':
98
        if ((c >= 'a') && (c <= 'z')) {
253
            do_send_msg(1);
99
            for (test = tests; test->name != NULL; test++, c--)
254
            break;
-
 
255
        case 's':
100
                if (c == 'a')
256
            do_send_msg(0);
-
 
257
            break;
101
                    break;
258
        case 'd':
-
 
259
            do_answer_msg();
-
 
260
            break;
102
           
261
        case 'j':
103
            if (c > 'a')
262
            printf("Entering infinite loop\n");
104
                printf("Unknown test\n\n");
263
            while (1)
-
 
264
                ;
105
            else
265
            break;
106
                run_test(test);
266
        case 'p':
-
 
267
            printf("Doing page fault\n");
-
 
268
            *((char *)0) = 1;
107
        } else if (c == '*')
269
            printf("done\n");
108
            run_safe_tests();
270
            break;
109
        else
271
        case 'u':
-
 
272
            var1=*( (int *) ( ( (char *)(&var) ) + 1 ) );
110
            printf("Invalid test\n\n");
273
            break;
-
 
274
        }
-
 
275
    }
111
    }
276
}
112
}
277
 
113
 
278
/** @}
114
/** @}
279
 */
115
 */
280
 
-