Subversion Repositories HelenOS-historic

Rev

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

Rev 1089 Rev 1091
1
/*
1
/*
2
 * Copyright (C) 2005 Martin Decky
2
 * Copyright (C) 2005 Martin Decky
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
#include "version.h"
29
#include "version.h"
30
#include <ipc.h>
30
#include <ipc.h>
31
#include <stdio.h>
31
#include <stdio.h>
32
#include <unistd.h>
32
#include <unistd.h>
33
#include <stdlib.h>
33
#include <stdlib.h>
34
#include <ns.h>
34
#include <ns.h>
35
#include <thread.h>
35
#include <thread.h>
36
 
36
 
37
int a;
37
int a;
38
 
38
 
39
extern void utest(void *arg);
39
extern void utest(void *arg);
40
void utest(void *arg)
40
void utest(void *arg)
41
{
41
{
42
    printf("Uspace thread started.\n");
42
    printf("Uspace thread started.\n");
43
    for (;;)
43
    for (;;)
44
        ;
44
        ;
45
}
45
}
46
 
46
 
47
static void test_printf(void)
47
static void test_printf(void)
48
{
48
{
49
    printf("Simple text.\n");
49
    printf("Simple text.\n");
50
    printf("Now insert '%s' string.\n","this");
50
    printf("Now insert '%s' string.\n","this");
51
    printf("Signed formats on uns. numbers: '%d', '%+d', '% d', '%u' (,+, ,u)\n", 321, 321, 321, 321);
51
    printf("Signed formats on uns. numbers: '%d', '%+d', '% d', '%u' (,+, ,u)\n", 321, 321, 321, 321);
52
    printf("Signed formats on sig. numbers: '%d', '%+d', '% d', '%u' (,+, ,u)\n", -321, -321, -321, -321);
52
    printf("Signed formats on sig. numbers: '%d', '%+d', '% d', '%u' (,+, ,u)\n", -321, -321, -321, -321);
53
    printf("Signed with different sized: '%hhd', '%hd', '%d', '%ld', %lld;\n", -3, -32, -321, -32101l, -3210123ll);
53
    printf("Signed with different sized: '%hhd', '%hd', '%d', '%ld', %lld;\n", -3, -32, -321, -32101l, -3210123ll);
54
    printf("And now... '%hhd' byte! '%hd' word! '%d' int! \n", 11, 11111, 1111111111);
54
    printf("And now... '%hhd' byte! '%hd' word! '%d' int! \n", 11, 11111, 1111111111);
55
    printf("Different bases: %#hx, %#hu, %#ho and %#hb\n", 123, 123, 123, 123);
55
    printf("Different bases: %#hx, %#hu, %#ho and %#hb\n", 123, 123, 123, 123);
56
    printf("Different bases signed: %#hx, %#hu, %#ho and %#hb\n", -123, -123, -123, -123);
56
    printf("Different bases signed: %#hx, %#hu, %#ho and %#hb\n", -123, -123, -123, -123);
57
    printf("'%llX' llX! Another '%llx' llx! \n", 0x1234567887654321ll, 0x1234567887654321ll);
57
    printf("'%llX' llX! Another '%llx' llx! \n", 0x1234567887654321ll, 0x1234567887654321ll);
58
    printf("'%llX' with 64bit value and '%x' with 32 bit value. \n", 0x1234567887654321ll, 0x12345678 );
58
    printf("'%llX' with 64bit value and '%x' with 32 bit value. \n", 0x1234567887654321ll, 0x12345678 );
59
    printf("'%llx' 64bit, '%x' 32bit, '%hhx' 8bit, '%hx' 16bit, '%llX' 64bit and '%s' string.\n", 0x1234567887654321ll, 0x12345678, 0x12, 0x1234, 0x1234567887654321ull, "Lovely string" );
59
    printf("'%llx' 64bit, '%x' 32bit, '%hhx' 8bit, '%hx' 16bit, '%llX' 64bit and '%s' string.\n", 0x1234567887654321ll, 0x12345678, 0x12, 0x1234, 0x1234567887654321ull, "Lovely string" );
60
   
60
   
61
    printf("Thats all, folks!\n");
61
    printf("Thats all, folks!\n");
62
}
62
}
63
 
63
 
64
 
64
 
65
extern char _heap;
65
extern char _heap;
66
static void test_mremap(void)
66
static void test_mremap(void)
67
{
67
{
68
    printf("Writing to good memory\n");
68
    printf("Writing to good memory\n");
69
    mremap(&_heap, 120000, 0);
69
    mremap(&_heap, 120000, 0);
70
    printf("%P\n", ((char *)&_heap));
70
    printf("%P\n", ((char *)&_heap));
71
    printf("%P\n", ((char *)&_heap) + 80000);
71
    printf("%P\n", ((char *)&_heap) + 80000);
72
    *(((char *)&_heap) + 80000) = 10;
72
    *(((char *)&_heap) + 80000) = 10;
73
    printf("Making small\n");
73
    printf("Making small\n");
74
    mremap(&_heap, 16000, 0);
74
    mremap(&_heap, 16000, 0);
75
    printf("Failing..\n");
75
    printf("Failing..\n");
76
    *((&_heap) + 80000) = 10;
76
    *((&_heap) + 80000) = 10;
77
 
77
 
78
    printf("memory done\n");
78
    printf("memory done\n");
79
}
79
}
80
/*
80
/*
81
static void test_sbrk(void)
81
static void test_sbrk(void)
82
{
82
{
83
    printf("Writing to good memory\n");
83
    printf("Writing to good memory\n");
84
    printf("Got: %P\n", sbrk(120000));
84
    printf("Got: %P\n", sbrk(120000));
85
    printf("%P\n", ((char *)&_heap));
85
    printf("%P\n", ((char *)&_heap));
86
    printf("%P\n", ((char *)&_heap) + 80000);
86
    printf("%P\n", ((char *)&_heap) + 80000);
87
    *(((char *)&_heap) + 80000) = 10;
87
    *(((char *)&_heap) + 80000) = 10;
88
    printf("Making small, got: %P\n",sbrk(-120000));
88
    printf("Making small, got: %P\n",sbrk(-120000));
89
    printf("Testing access to heap\n");
89
    printf("Testing access to heap\n");
90
    _heap = 10;
90
    _heap = 10;
91
    printf("Failing..\n");
91
    printf("Failing..\n");
92
    *((&_heap) + 80000) = 10;
92
    *((&_heap) + 80000) = 10;
93
 
93
 
94
    printf("memory done\n");
94
    printf("memory done\n");
95
}
95
}
96
*/
96
*/
97
/*
97
/*
98
static void test_malloc(void)
98
static void test_malloc(void)
99
{
99
{
100
    char *data;
100
    char *data;
101
 
101
 
102
    data = malloc(10);
102
    data = malloc(10);
103
    printf("Heap: %P, data: %P\n", &_heap, data);
103
    printf("Heap: %P, data: %P\n", &_heap, data);
104
    data[0] = 'a';
104
    data[0] = 'a';
105
    free(data);
105
    free(data);
106
}
106
}
107
*/
107
*/
108
 
108
 
109
 
109
 
110
static void test_ping(void)
110
static void test_ping(void)
111
{
111
{
112
    ipcarg_t result;
112
    ipcarg_t result;
113
    int retval;
113
    int retval;
114
 
114
 
-
 
115
    printf("Pinging\n");
115
    retval = ipc_call_sync(PHONE_NS, NS_PING, 0xbeef,&result);
116
    retval = ipc_call_sync(PHONE_NS, NS_PING, 0xbeef,&result);
116
    printf("Retval: %d - received: %P\n", retval, result);
117
    printf("Retval: %d - received: %P\n", retval, result);
117
}
118
}
118
 
119
 
119
static void got_answer(void *private, int retval, ipc_data_t *data)
120
static void got_answer(void *private, int retval, ipc_call_t *data)
120
{
121
{
121
    printf("Retval: %d...%s...%zX, %zX\n", retval, private,
122
    printf("Retval: %d...%s...%zX, %zX\n", retval, private,
122
           IPC_GET_ARG1(*data), IPC_GET_ARG2(*data));
123
           IPC_GET_ARG1(*data), IPC_GET_ARG2(*data));
123
}
124
}
124
static void test_async_ipc(void)
125
static void test_async_ipc(void)
125
{
126
{
126
    ipc_call_t data;
127
    ipc_call_t data;
127
    int i;
128
    int i;
128
 
129
 
129
    printf("Sending ping\n");
130
    printf("Sending ping\n");
130
    ipc_call_async_2(PHONE_NS, NS_PING, 1, 0xbeefbee2,
131
    ipc_call_async_2(PHONE_NS, NS_PING, 1, 0xbeefbee2,
131
             "Pong1", got_answer);
132
             "Pong1", got_answer);
132
    ipc_call_async_2(PHONE_NS, NS_PING, 2, 0xbeefbee4,
133
    ipc_call_async_2(PHONE_NS, NS_PING, 2, 0xbeefbee4,
133
             "Pong2", got_answer);
134
             "Pong2", got_answer);
134
    ipc_call_async_2(PHONE_NS, NS_PING, 3, 0xbeefbee4,
135
    ipc_call_async_2(PHONE_NS, NS_PING, 3, 0xbeefbee4,
135
             "Pong3", got_answer);
136
             "Pong3", got_answer);
136
    ipc_call_async_2(PHONE_NS, NS_PING, 4, 0xbeefbee4,
137
    ipc_call_async_2(PHONE_NS, NS_PING, 4, 0xbeefbee4,
137
             "Pong4", got_answer);
138
             "Pong4", got_answer);
138
    ipc_call_async_2(PHONE_NS, NS_PING, 5, 0xbeefbee4,
139
    ipc_call_async_2(PHONE_NS, NS_PING, 5, 0xbeefbee4,
139
             "Pong5", got_answer);
140
             "Pong5", got_answer);
140
    ipc_call_async_2(PHONE_NS, NS_PING, 6, 0xbeefbee4,
141
    ipc_call_async_2(PHONE_NS, NS_PING, 6, 0xbeefbee4,
141
             "Pong6", got_answer);
142
             "Pong6", got_answer);
142
    printf("Waiting forever...\n");
143
    printf("Waiting forever...\n");
143
    for (i=0; i<100;i++)
144
    for (i=0; i<100;i++)
144
        printf(".");
145
        printf(".");
145
    printf("\n");
146
    printf("\n");
146
    ipc_wait_for_call(&data, NULL);
147
    ipc_wait_for_call(&data, NULL);
147
    printf("Received call???\n");
148
    printf("Received call???\n");
148
}
149
}
149
 
150
 
150
 
151
 
151
static void got_answer_2(void *private, int retval, ipc_data_t *data)
152
static void got_answer_2(void *private, int retval, ipc_call_t *data)
152
{
153
{
153
    printf("Pong\n");
154
    printf("Pong\n");
154
}
155
}
155
static void test_advanced_ipc(void)
156
static void test_advanced_ipc(void)
156
{
157
{
157
    int res;
158
    int res;
158
    unsigned long long taskid;
159
    ipcarg_t phonead;
159
    ipc_callid_t callid;
160
    ipc_callid_t callid;
160
    ipc_call_t data;
161
    ipc_call_t data;
161
    int i;
162
    int i;
162
 
163
 
163
    printf("Asking 0 to connect to me...\n");
164
    printf("Asking 0 to connect to me...\n");
164
    res = ipc_connect_to_me(0, 1, 2, &taskid);
165
    res = ipc_connect_to_me(0, 1, 2, &phonead);
165
    printf("Result: %d - taskid: %llu\n", res, taskid);
166
    printf("Result: %d - phonead: %llu\n", res, phonead);
166
    for (i=0; i < 100; i++) {
167
    for (i=0; i < 100; i++) {
167
        printf("----------------\n");
168
        printf("----------------\n");
168
        ipc_call_async(PHONE_NS, NS_PING_SVC, 0, "prov",
169
        ipc_call_async(PHONE_NS, NS_PING_SVC, 0, "prov",
169
                   got_answer_2);
170
                   got_answer_2);
170
        callid = ipc_wait_for_call(&data, NULL);
171
        callid = ipc_wait_for_call(&data, NULL);
171
        printf("Received ping\n");
172
        printf("Received ping\n");
172
        ipc_answer(callid, 0, 0, 0);
173
        ipc_answer(callid, 0, 0, 0);
173
    }
174
    }
174
//  callid = ipc_wait_for_call(&data, NULL);
175
//  callid = ipc_wait_for_call(&data, NULL);
175
}
176
}
176
 
177
 
177
static void test_connection_ipc(void)
178
static void test_connection_ipc(void)
178
{
179
{
179
    int res;
180
    int res;
180
    ipcarg_t result;
181
    ipcarg_t result;
-
 
182
    int phoneid;
181
 
183
 
182
    printf("Starting connect...\n");
184
    printf("Starting connect...\n");
183
    res = ipc_connect_me_to(PHONE_NS, 10, 20);
185
    res = ipc_connect_me_to(PHONE_NS, 10, 20);
184
    printf("Connected: %d\n", res);
186
    printf("Connected: %d\n", res);
185
    printf("pinging.\n");
187
    printf("pinging.\n");
186
    res = ipc_call_sync(res, NS_PING, 0xbeef,&result);
188
    res = ipc_call_sync(res, NS_PING, 0xbeef,&result);
187
    printf("Retval: %d - received: %X\n", res, result);
189
    printf("Retval: %d - received: %X\n", res, result);
188
   
190
   
189
}
191
}
190
 
192
 
191
static void test_hangup(void)
193
static void test_hangup(void)
192
{
194
{
193
    int phoneid;
195
    int phoneid;
194
    ipc_call_t data;
196
    ipc_call_t data;
195
    ipc_callid_t callid;
197
    ipc_callid_t callid;
196
    int i;
198
    int i;
197
 
199
 
198
    printf("Starting connect...\n");
200
    printf("Starting connect...\n");
199
    phoneid = ipc_connect_me_to(PHONE_NS, 10, 20);
201
    phoneid = ipc_connect_me_to(PHONE_NS, 10, 20);
200
    printf("Phoneid: %d, pinging\n", phoneid);
202
    printf("Phoneid: %d, pinging\n", phoneid);
201
    ipc_call_async_2(PHONE_NS, NS_PING, 1, 0xbeefbee2,
203
    ipc_call_async_2(PHONE_NS, NS_PING, 1, 0xbeefbee2,
202
             "Pong1", got_answer);
204
             "Pong1", got_answer);
203
    printf("Hangin up\n");
205
    printf("Hangin up\n");
204
    ipc_hangup(phoneid);
206
    ipc_hangup(phoneid);
205
    printf("Connecting\n");
207
    printf("Connecting\n");
206
    phoneid = ipc_connect_me_to(PHONE_NS, 10, 20);
208
    phoneid = ipc_connect_me_to(PHONE_NS, 10, 20);
207
    printf("Newphid: %d\n", phoneid);
209
    printf("Newphid: %d\n", phoneid);
208
    for (i=0; i < 1000; i++) {
210
    for (i=0; i < 1000; i++) {
209
        if ((callid=ipc_wait_for_call(&data, IPC_WAIT_NONBLOCKING)))
211
        if ((callid=ipc_wait_for_call(&data, IPC_WAIT_NONBLOCKING)))
210
            printf("callid: %d\n");
212
            printf("callid: %d\n");
211
    }
213
    }
212
    printf("New new phoneid: %d\n", ipc_connect_me_to(PHONE_NS, 10, 20));
214
    printf("New new phoneid: %d\n", ipc_connect_me_to(PHONE_NS, 10, 20));
213
}
215
}
214
 
216
 
215
static void test_slam(void)
217
static void test_slam(void)
216
{
218
{
217
    int i;
219
    int i;
218
    ipc_call_t data;
220
    ipc_call_t data;
219
    ipc_callid_t callid;
221
    ipc_callid_t callid;
220
 
222
 
221
    printf("ping");
223
    printf("ping");
222
    ipc_call_async_2(PHONE_NS, NS_PING, 1, 0xbeefbee2,
224
    ipc_call_async_2(PHONE_NS, NS_PING, 1, 0xbeefbee2,
223
             "Pong1", got_answer);
225
             "Pong1", got_answer);
224
    printf("slam");
226
    printf("slam");
225
    ipc_call_async_2(PHONE_NS, NS_HANGUP, 1, 0xbeefbee2,
227
    ipc_call_async_2(PHONE_NS, NS_HANGUP, 1, 0xbeefbee2,
226
             "Hang", got_answer);
228
             "Hang", got_answer);
227
    printf("ping2\n");
229
    printf("ping2\n");
228
    ipc_call_async_2(PHONE_NS, NS_PING, 1, 0xbeefbee2,
230
    ipc_call_async_2(PHONE_NS, NS_PING, 1, 0xbeefbee2,
229
             "Ping2", got_answer);
231
             "Ping2", got_answer);
230
   
232
   
231
    for (i=0; i < 1000; i++) {
233
    for (i=0; i < 1000; i++) {
232
        if ((callid=ipc_wait_for_call(&data, IPC_WAIT_NONBLOCKING)))
234
        if ((callid=ipc_wait_for_call(&data, IPC_WAIT_NONBLOCKING)))
233
            printf("callid: %d\n");
235
            printf("callid: %d\n");
234
    }
236
    }
235
    ipc_call_async_2(PHONE_NS, NS_PING, 1, 0xbeefbee2,
237
    ipc_call_async_2(PHONE_NS, NS_PING, 1, 0xbeefbee2,
236
             "Pong1", got_answer);
238
             "Pong1", got_answer);
237
    printf("Closing file\n");
239
    printf("Closing file\n");
238
    ipc_hangup(PHONE_NS);
240
    ipc_hangup(PHONE_NS);
239
    ipc_call_async_2(PHONE_NS, NS_PING, 1, 0xbeefbee2,
241
    ipc_call_async_2(PHONE_NS, NS_PING, 1, 0xbeefbee2,
240
             "Pong1", got_answer);
242
             "Pong1", got_answer);
241
    ipc_wait_for_call(&data, 0);
243
    ipc_wait_for_call(&data, 0);
242
}
244
}
243
 
245
 
244
int main(int argc, char *argv[])
246
int main(int argc, char *argv[])
245
{
247
{
246
    int tid;
248
    int tid;
247
    version_print();
249
    version_print();
248
 
250
 
249
/*  test_printf(); */
251
/*  test_printf(); */
250
//  test_ping();
252
//  test_ping();
251
//  test_async_ipc();
253
//  test_async_ipc();
252
//  test_advanced_ipc();
254
//  test_advanced_ipc();
253
//  test_connection_ipc();
255
//  test_connection_ipc();
254
//  test_hangup();
256
//  test_hangup();
255
    test_slam();
257
//  test_slam();
256
 
258
 
257
//  if ((tid = thread_create(utest, NULL, "utest") != -1)) {
259
    if ((tid = thread_create(utest, NULL, "utest") != -1)) {
258
//      printf("Created thread tid=%d\n", tid);
260
        printf("Created thread tid=%d\n", tid);
259
//  }
261
    }
260
    return 0;
262
    return 0;
261
}
263
}
262
 
264