Subversion Repositories HelenOS

Rev

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

Rev 1330 Rev 1339
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
#include <task.h>
36
#include <task.h>
37
#include <psthread.h>
37
#include <psthread.h>
38
#include <futex.h>
38
#include <futex.h>
39
#include <as.h>
39
#include <as.h>
40
#include <ddi.h>
40
#include <ddi.h>
41
#include <string.h>
41
#include <string.h>
-
 
42
#include <kbd.h>
42
 
43
 
43
int a;
44
int a;
44
atomic_t ftx;
45
atomic_t ftx;
45
 
46
 
46
int __thread stage;
47
int __thread stage;
47
 
48
 
48
extern void utest(void *arg);
49
extern void utest(void *arg);
49
void utest(void *arg)
50
void utest(void *arg)
50
{
51
{
51
    printf("Uspace thread started.\n");
52
    printf("Uspace thread started.\n");
52
    if (futex_down(&ftx) < 0)
53
    if (futex_down(&ftx) < 0)
53
        printf("Futex failed.\n");
54
        printf("Futex failed.\n");
54
    if (futex_up(&ftx) < 0)
55
    if (futex_up(&ftx) < 0)
55
        printf("Futex failed.\n");
56
        printf("Futex failed.\n");
56
       
57
       
57
    printf("%s in good condition.\n", __FUNCTION__);
58
    printf("%s in good condition.\n", __FUNCTION__);
58
   
59
   
59
    for (;;)
60
    for (;;)
60
        ;
61
        ;
61
}
62
}
62
 
63
 
63
/* test different parameters types and modifiers */
64
/* test different parameters types and modifiers */
64
static void test_printf(void)
65
static void test_printf(void)
65
{
66
{
66
    printf("Simple text.\n");
67
    printf("Simple text.\n");
67
    printf("Now insert '%s' string.\n","this");
68
    printf("Now insert '%s' string.\n","this");
68
    printf("Signed formats on uns. numbers: '%d', '%+d', '% d', '%u' (,+, ,u)\n", 321, 321, 321, 321);
69
    printf("Signed formats on uns. numbers: '%d', '%+d', '% d', '%u' (,+, ,u)\n", 321, 321, 321, 321);
69
    printf("Signed formats on sig. numbers: '%d', '%+d', '% d', '%u' (,+, ,u)\n", -321, -321, -321, -321);
70
    printf("Signed formats on sig. numbers: '%d', '%+d', '% d', '%u' (,+, ,u)\n", -321, -321, -321, -321);
70
    printf("Signed with different sized: '%hhd', '%hd', '%d', '%ld', %lld;\n", -3, -32, -321, -32101l, -3210123ll);
71
    printf("Signed with different sized: '%hhd', '%hd', '%d', '%ld', %lld;\n", -3, -32, -321, -32101l, -3210123ll);
71
    printf("And now... '%hhd' byte! '%hd' word! '%d' int! \n", 11, 11111, 1111111111);
72
    printf("And now... '%hhd' byte! '%hd' word! '%d' int! \n", 11, 11111, 1111111111);
72
    printf("Different bases: %#hx, %#hu, %#ho and %#hb\n", 123, 123, 123, 123);
73
    printf("Different bases: %#hx, %#hu, %#ho and %#hb\n", 123, 123, 123, 123);
73
    printf("Different bases signed: %#hx, %#hu, %#ho and %#hb\n", -123, -123, -123, -123);
74
    printf("Different bases signed: %#hx, %#hu, %#ho and %#hb\n", -123, -123, -123, -123);
74
    printf("'%llX' llX! Another '%llx' llx! \n", 0x1234567887654321ll, 0x1234567887654321ll);
75
    printf("'%llX' llX! Another '%llx' llx! \n", 0x1234567887654321ll, 0x1234567887654321ll);
75
    printf("'%llX' with 64bit value and '%x' with 32 bit value. \n", 0x1234567887654321ll, 0x12345678 );
76
    printf("'%llX' with 64bit value and '%x' with 32 bit value. \n", 0x1234567887654321ll, 0x12345678 );
76
    printf("'%llx' 64bit, '%x' 32bit, '%hhx' 8bit, '%hx' 16bit, '%llX' 64bit and '%s' string.\n", 0x1234567887654321ll, 0x12345678, 0x12, 0x1234, 0x1234567887654321ull, "Lovely string" );
77
    printf("'%llx' 64bit, '%x' 32bit, '%hhx' 8bit, '%hx' 16bit, '%llX' 64bit and '%s' string.\n", 0x1234567887654321ll, 0x12345678, 0x12, 0x1234, 0x1234567887654321ull, "Lovely string" );
77
   
78
   
78
    printf("Thats all, folks!\n");
79
    printf("Thats all, folks!\n");
79
}
80
}
80
 
81
 
81
/* test width and precision modifiers */
82
/* test width and precision modifiers */
82
static void test_printf2(void)
83
static void test_printf2(void)
83
{
84
{
84
    printf(" text 10.8s %*.*s \n", 5, 3, "text");
85
    printf(" text 10.8s %*.*s \n", 5, 3, "text");
85
    printf(" very long text 10.8s %10.8s \n", "very long text");
86
    printf(" very long text 10.8s %10.8s \n", "very long text");
86
    printf(" text 8.10s %8.10s \n", "text");
87
    printf(" text 8.10s %8.10s \n", "text");
87
    printf(" very long text 8.10s %8.10s \n", "very long text");
88
    printf(" very long text 8.10s %8.10s \n", "very long text");
88
 
89
 
89
    printf(" char: c '%c', 3.2c '%3.2c', -3.2c '%-3.2c', 2.3c '%2.3c', -2.3c '%-2.3c' \n",'a', 'b', 'c', 'd', 'e' );
90
    printf(" char: c '%c', 3.2c '%3.2c', -3.2c '%-3.2c', 2.3c '%2.3c', -2.3c '%-2.3c' \n",'a', 'b', 'c', 'd', 'e' );
90
    printf(" int: d '%d', 3.2d '%3.2d', -3.2d '%-3.2d', 2.3d '%2.3d', -2.3d '%-2.3d' \n",1, 1, 1, 1, 1 );
91
    printf(" int: d '%d', 3.2d '%3.2d', -3.2d '%-3.2d', 2.3d '%2.3d', -2.3d '%-2.3d' \n",1, 1, 1, 1, 1 );
91
    printf(" -int: d '%d', 3.2d '%3.2d', -3.2d '%-3.2d', 2.3d '%2.3d', -2.3d '%-2.3d' \n",-1, -1, -1, -1, -1 );
92
    printf(" -int: d '%d', 3.2d '%3.2d', -3.2d '%-3.2d', 2.3d '%2.3d', -2.3d '%-2.3d' \n",-1, -1, -1, -1, -1 );
92
    printf(" 0xint: x '%x', 5.3x '%#5.3x', -5.3x '%#-5.3x', 3.5x '%#3.5x', -3.5x '%#-3.5x' \n",17, 17, 17, 17, 17 );
93
    printf(" 0xint: x '%x', 5.3x '%#5.3x', -5.3x '%#-5.3x', 3.5x '%#3.5x', -3.5x '%#-3.5x' \n",17, 17, 17, 17, 17 );
93
 
94
 
94
}
95
}
95
 
96
 
96
extern char _heap;
97
extern char _heap;
97
static void test_mremap(void)
98
static void test_mremap(void)
98
{
99
{
99
    printf("Writing to good memory\n");
100
    printf("Writing to good memory\n");
100
    as_area_resize(&_heap, 120000, 0);
101
    as_area_resize(&_heap, 120000, 0);
101
    printf("%P\n", ((char *)&_heap));
102
    printf("%P\n", ((char *)&_heap));
102
    printf("%P\n", ((char *)&_heap) + 80000);
103
    printf("%P\n", ((char *)&_heap) + 80000);
103
    *(((char *)&_heap) + 80000) = 10;
104
    *(((char *)&_heap) + 80000) = 10;
104
    printf("Making small\n");
105
    printf("Making small\n");
105
    as_area_resize(&_heap, 16000, 0);
106
    as_area_resize(&_heap, 16000, 0);
106
    printf("Failing..\n");
107
    printf("Failing..\n");
107
    *((&_heap) + 80000) = 10;
108
    *((&_heap) + 80000) = 10;
108
 
109
 
109
    printf("memory done\n");
110
    printf("memory done\n");
110
}
111
}
111
/*
112
/*
112
static void test_sbrk(void)
113
static void test_sbrk(void)
113
{
114
{
114
    printf("Writing to good memory\n");
115
    printf("Writing to good memory\n");
115
    printf("Got: %P\n", sbrk(120000));
116
    printf("Got: %P\n", sbrk(120000));
116
    printf("%P\n", ((char *)&_heap));
117
    printf("%P\n", ((char *)&_heap));
117
    printf("%P\n", ((char *)&_heap) + 80000);
118
    printf("%P\n", ((char *)&_heap) + 80000);
118
    *(((char *)&_heap) + 80000) = 10;
119
    *(((char *)&_heap) + 80000) = 10;
119
    printf("Making small, got: %P\n",sbrk(-120000));
120
    printf("Making small, got: %P\n",sbrk(-120000));
120
    printf("Testing access to heap\n");
121
    printf("Testing access to heap\n");
121
    _heap = 10;
122
    _heap = 10;
122
    printf("Failing..\n");
123
    printf("Failing..\n");
123
    *((&_heap) + 80000) = 10;
124
    *((&_heap) + 80000) = 10;
124
 
125
 
125
    printf("memory done\n");
126
    printf("memory done\n");
126
}
127
}
127
*/
128
*/
128
/*
129
/*
129
static void test_malloc(void)
130
static void test_malloc(void)
130
{
131
{
131
    char *data;
132
    char *data;
132
 
133
 
133
    data = malloc(10);
134
    data = malloc(10);
134
    printf("Heap: %P, data: %P\n", &_heap, data);
135
    printf("Heap: %P, data: %P\n", &_heap, data);
135
    data[0] = 'a';
136
    data[0] = 'a';
136
    free(data);
137
    free(data);
137
}
138
}
138
*/
139
*/
139
 
140
 
140
 
141
 
141
static void test_ping(void)
142
static void test_ping(void)
142
{
143
{
143
    ipcarg_t result;
144
    ipcarg_t result;
144
    int retval;
145
    int retval;
145
 
146
 
146
    printf("Pinging\n");
147
    printf("Pinging\n");
147
    retval = ipc_call_sync(PHONE_NS, NS_PING, 0xbeef,&result);
148
    retval = ipc_call_sync(PHONE_NS, NS_PING, 0xbeef,&result);
148
    printf("Retval: %d - received: %P\n", retval, result);
149
    printf("Retval: %d - received: %P\n", retval, result);
149
}
150
}
150
 
151
 
151
static void got_answer(void *private, int retval, ipc_call_t *data)
152
static void got_answer(void *private, int retval, ipc_call_t *data)
152
{
153
{
153
    printf("Retval: %d...%s...%zX, %zX\n", retval, private,
154
    printf("Retval: %d...%s...%zX, %zX\n", retval, private,
154
           IPC_GET_ARG1(*data), IPC_GET_ARG2(*data));
155
           IPC_GET_ARG1(*data), IPC_GET_ARG2(*data));
155
}
156
}
156
static void test_async_ipc(void)
157
static void test_async_ipc(void)
157
{
158
{
158
    ipc_call_t data;
159
    ipc_call_t data;
159
    int i;
160
    int i;
160
 
161
 
161
    printf("Sending ping\n");
162
    printf("Sending ping\n");
162
    ipc_call_async_2(PHONE_NS, NS_PING, 1, 0xbeefbee2,
163
    ipc_call_async_2(PHONE_NS, NS_PING, 1, 0xbeefbee2,
163
             "Pong1", got_answer);
164
             "Pong1", got_answer);
164
    ipc_call_async_2(PHONE_NS, NS_PING, 2, 0xbeefbee4,
165
    ipc_call_async_2(PHONE_NS, NS_PING, 2, 0xbeefbee4,
165
             "Pong2", got_answer);
166
             "Pong2", got_answer);
166
    ipc_call_async_2(PHONE_NS, NS_PING, 3, 0xbeefbee4,
167
    ipc_call_async_2(PHONE_NS, NS_PING, 3, 0xbeefbee4,
167
             "Pong3", got_answer);
168
             "Pong3", got_answer);
168
    ipc_call_async_2(PHONE_NS, NS_PING, 4, 0xbeefbee4,
169
    ipc_call_async_2(PHONE_NS, NS_PING, 4, 0xbeefbee4,
169
             "Pong4", got_answer);
170
             "Pong4", got_answer);
170
    ipc_call_async_2(PHONE_NS, NS_PING, 5, 0xbeefbee4,
171
    ipc_call_async_2(PHONE_NS, NS_PING, 5, 0xbeefbee4,
171
             "Pong5", got_answer);
172
             "Pong5", got_answer);
172
    ipc_call_async_2(PHONE_NS, NS_PING, 6, 0xbeefbee4,
173
    ipc_call_async_2(PHONE_NS, NS_PING, 6, 0xbeefbee4,
173
             "Pong6", got_answer);
174
             "Pong6", got_answer);
174
    printf("Waiting forever...\n");
175
    printf("Waiting forever...\n");
175
    for (i=0; i<100;i++)
176
    for (i=0; i<100;i++)
176
        printf(".");
177
        printf(".");
177
    printf("\n");
178
    printf("\n");
178
    ipc_wait_for_call(&data, NULL);
179
    ipc_wait_for_call(&data, NULL);
179
    printf("Received call???\n");
180
    printf("Received call???\n");
180
}
181
}
181
 
182
 
182
 
183
 
183
static void got_answer_2(void *private, int retval, ipc_call_t *data)
184
static void got_answer_2(void *private, int retval, ipc_call_t *data)
184
{
185
{
185
    printf("Pong\n");
186
    printf("Pong\n");
186
}
187
}
187
static void test_advanced_ipc(void)
188
static void test_advanced_ipc(void)
188
{
189
{
189
    int res;
190
    int res;
190
    ipcarg_t phonead;
191
    ipcarg_t phonead;
191
    ipc_callid_t callid;
192
    ipc_callid_t callid;
192
    ipc_call_t data;
193
    ipc_call_t data;
193
    int i;
194
    int i;
194
 
195
 
195
    printf("Asking 0 to connect to me...\n");
196
    printf("Asking 0 to connect to me...\n");
196
    res = ipc_connect_to_me(0, 1, 2, &phonead);
197
    res = ipc_connect_to_me(0, 1, 2, &phonead);
197
    printf("Result: %d - phonead: %llu\n", res, phonead);
198
    printf("Result: %d - phonead: %llu\n", res, phonead);
198
    for (i=0; i < 100; i++) {
199
    for (i=0; i < 100; i++) {
199
        printf("----------------\n");
200
        printf("----------------\n");
200
        ipc_call_async(PHONE_NS, NS_PING_SVC, 0, "prov",
201
        ipc_call_async(PHONE_NS, NS_PING_SVC, 0, "prov",
201
                   got_answer_2);
202
                   got_answer_2);
202
        callid = ipc_wait_for_call(&data, NULL);
203
        callid = ipc_wait_for_call(&data, NULL);
203
        printf("Received ping\n");
204
        printf("Received ping\n");
204
        ipc_answer(callid, 0, 0, 0);
205
        ipc_answer(callid, 0, 0, 0);
205
    }
206
    }
206
//  callid = ipc_wait_for_call(&data, NULL);
207
//  callid = ipc_wait_for_call(&data, NULL);
207
}
208
}
208
 
209
 
209
static void test_connection_ipc(void)
210
static void test_connection_ipc(void)
210
{
211
{
211
    int res;
212
    int res;
212
    ipcarg_t result;
213
    ipcarg_t result;
213
    int phoneid;
214
    int phoneid;
214
 
215
 
215
    printf("Starting connect...\n");
216
    printf("Starting connect...\n");
216
    res = ipc_connect_me_to(PHONE_NS, 10, 20);
217
    res = ipc_connect_me_to(PHONE_NS, 10, 20);
217
    printf("Connected: %d\n", res);
218
    printf("Connected: %d\n", res);
218
    printf("pinging.\n");
219
    printf("pinging.\n");
219
    res = ipc_call_sync(res, NS_PING, 0xbeef,&result);
220
    res = ipc_call_sync(res, NS_PING, 0xbeef,&result);
220
    printf("Retval: %d - received: %X\n", res, result);
221
    printf("Retval: %d - received: %X\n", res, result);
221
   
222
   
222
}
223
}
223
 
224
 
224
static void test_hangup(void)
225
static void test_hangup(void)
225
{
226
{
226
    int phoneid;
227
    int phoneid;
227
    ipc_call_t data;
228
    ipc_call_t data;
228
    ipc_callid_t callid;
229
    ipc_callid_t callid;
229
    int i;
230
    int i;
230
 
231
 
231
    printf("Starting connect...\n");
232
    printf("Starting connect...\n");
232
    phoneid = ipc_connect_me_to(PHONE_NS, 10, 20);
233
    phoneid = ipc_connect_me_to(PHONE_NS, 10, 20);
233
    printf("Phoneid: %d, pinging\n", phoneid);
234
    printf("Phoneid: %d, pinging\n", phoneid);
234
    ipc_call_async_2(PHONE_NS, NS_PING, 1, 0xbeefbee2,
235
    ipc_call_async_2(PHONE_NS, NS_PING, 1, 0xbeefbee2,
235
             "Pong1", got_answer);
236
             "Pong1", got_answer);
236
    printf("Hangin up\n");
237
    printf("Hangin up\n");
237
    ipc_hangup(phoneid);
238
    ipc_hangup(phoneid);
238
    printf("Connecting\n");
239
    printf("Connecting\n");
239
    phoneid = ipc_connect_me_to(PHONE_NS, 10, 20);
240
    phoneid = ipc_connect_me_to(PHONE_NS, 10, 20);
240
    printf("Newphid: %d\n", phoneid);
241
    printf("Newphid: %d\n", phoneid);
241
    for (i=0; i < 1000; i++) {
242
    for (i=0; i < 1000; i++) {
242
        if ((callid=ipc_wait_for_call(&data, IPC_WAIT_NONBLOCKING)))
243
        if ((callid=ipc_wait_for_call(&data, IPC_WAIT_NONBLOCKING)))
243
            printf("callid: %d\n");
244
            printf("callid: %d\n");
244
    }
245
    }
245
    printf("New new phoneid: %d\n", ipc_connect_me_to(PHONE_NS, 10, 20));
246
    printf("New new phoneid: %d\n", ipc_connect_me_to(PHONE_NS, 10, 20));
246
}
247
}
247
 
248
 
248
static void test_slam(void)
249
static void test_slam(void)
249
{
250
{
250
    int i;
251
    int i;
251
    ipc_call_t data;
252
    ipc_call_t data;
252
    ipc_callid_t callid;
253
    ipc_callid_t callid;
253
 
254
 
254
    printf("ping");
255
    printf("ping");
255
    ipc_call_async_2(PHONE_NS, NS_PING, 1, 0xbeefbee2,
256
    ipc_call_async_2(PHONE_NS, NS_PING, 1, 0xbeefbee2,
256
             "Pong1", got_answer);
257
             "Pong1", got_answer);
257
    printf("slam");
258
    printf("slam");
258
    ipc_call_async_2(PHONE_NS, NS_HANGUP, 1, 0xbeefbee2,
259
    ipc_call_async_2(PHONE_NS, NS_HANGUP, 1, 0xbeefbee2,
259
             "Hang", got_answer);
260
             "Hang", got_answer);
260
    printf("ping2\n");
261
    printf("ping2\n");
261
    ipc_call_async_2(PHONE_NS, NS_PING, 1, 0xbeefbee2,
262
    ipc_call_async_2(PHONE_NS, NS_PING, 1, 0xbeefbee2,
262
             "Ping2", got_answer);
263
             "Ping2", got_answer);
263
   
264
   
264
    for (i=0; i < 1000; i++) {
265
    for (i=0; i < 1000; i++) {
265
        if ((callid=ipc_wait_for_call(&data, IPC_WAIT_NONBLOCKING)))
266
        if ((callid=ipc_wait_for_call(&data, IPC_WAIT_NONBLOCKING)))
266
            printf("callid: %d\n");
267
            printf("callid: %d\n");
267
    }
268
    }
268
    ipc_call_async_2(PHONE_NS, NS_PING, 1, 0xbeefbee2,
269
    ipc_call_async_2(PHONE_NS, NS_PING, 1, 0xbeefbee2,
269
             "Pong1", got_answer);
270
             "Pong1", got_answer);
270
    printf("Closing file\n");
271
    printf("Closing file\n");
271
    ipc_hangup(PHONE_NS);
272
    ipc_hangup(PHONE_NS);
272
    ipc_call_async_2(PHONE_NS, NS_PING, 1, 0xbeefbee2,
273
    ipc_call_async_2(PHONE_NS, NS_PING, 1, 0xbeefbee2,
273
             "Pong1", got_answer);
274
             "Pong1", got_answer);
274
    ipc_wait_for_call(&data, 0);
275
    ipc_wait_for_call(&data, 0);
275
}
276
}
276
 
277
 
277
static int ptest(void *arg)
278
static int ptest(void *arg)
278
{
279
{
279
    stage = 1;
280
    stage = 1;
280
    printf("Pseudo thread stage%d.\n", stage);
281
    printf("Pseudo thread stage%d.\n", stage);
281
    stage++;
282
    stage++;
282
    psthread_schedule_next();
283
    psthread_schedule_next();
283
    printf("Pseudo thread stage%d.\n", stage);
284
    printf("Pseudo thread stage%d.\n", stage);
284
    stage++;
285
    stage++;
285
    psthread_schedule_next();
286
    psthread_schedule_next();
286
    printf("Pseudo thread stage%d.\n", stage);
287
    printf("Pseudo thread stage%d.\n", stage);
287
    psthread_schedule_next();
288
    psthread_schedule_next();
288
    stage++;
289
    stage++;
289
    printf("Pseudo thread stage%d.\n", stage);
290
    printf("Pseudo thread stage%d.\n", stage);
290
    psthread_schedule_next();
291
    psthread_schedule_next();
291
    printf("Pseudo thread exiting.\n");
292
    printf("Pseudo thread exiting.\n");
292
    return 0;  
293
    return 0;  
293
}
294
}
294
 
295
 
-
 
296
static void test_kbd()
-
 
297
{
-
 
298
    int res;
-
 
299
    ipcarg_t result;
-
 
300
    int phoneid;
-
 
301
 
-
 
302
    printf("Test: Starting connect...\n");
-
 
303
    while ((phoneid = ipc_connect_me_to(PHONE_NS, 30, 60)) < 0) {
-
 
304
    };
-
 
305
   
-
 
306
    printf("Test: Connected: %d\n", res);
-
 
307
    printf("Test: pinging.\n");
-
 
308
    while (1) {
-
 
309
        res = ipc_call_sync(phoneid, KBD_GETCHAR, 0xbeef,&result);
-
 
310
//      printf("Test: Retval: %d - received: %c\n", res, result);
-
 
311
        printf("%c", result);
-
 
312
    }
-
 
313
   
-
 
314
    printf("Test: Hangin up\n");
-
 
315
    ipc_hangup(phoneid);
-
 
316
}
-
 
317
 
295
static int test_as_send()
318
static int test_as_send()
296
{
319
{
297
    char *as;
320
    char *as;
298
    int retval;
321
    int retval;
299
    ipcarg_t result;
322
    ipcarg_t result;
300
 
323
 
301
    as = as_area_create((void *)(1024*1024), 16384, AS_AREA_READ | AS_AREA_WRITE);
324
    as = as_area_create((void *)(1024*1024), 16384, AS_AREA_READ | AS_AREA_WRITE);
302
    if (!as) {
325
    if (!as) {
303
        printf("Error creating as.\n");
326
        printf("Error creating as.\n");
304
        return 0;
327
        return 0;
305
    }
328
    }
306
 
329
 
307
    memcpy(as, "Hello world.\n", 14);
330
    memcpy(as, "Hello world.\n", 14);
308
 
331
 
309
    retval = ipc_call_sync_2(PHONE_NS, IPC_M_AS_SEND, 0, (sysarg_t) as,
332
    retval = ipc_call_sync_2(PHONE_NS, IPC_M_AS_SEND, 0, (sysarg_t) as,
310
        NULL, NULL);
333
        NULL, NULL);
311
    if (retval) {
334
    if (retval) {
312
        printf("AS_SEND failed.\n");
335
        printf("AS_SEND failed.\n");
313
        return 0;
336
        return 0;
314
    }
337
    }
315
    printf("Done\n");
338
    printf("Done\n");
316
}
339
}
317
 
340
 
318
int main(int argc, char *argv[])
341
int main(int argc, char *argv[])
319
{
342
{
320
    pstid_t ptid;
343
    pstid_t ptid;
321
    int tid;
344
    int tid;
322
   
345
   
323
    version_print();
346
    version_print();
324
 
347
 
325
//  test_printf();
348
//  test_printf();
326
//  test_printf2();
349
//  test_printf2();
327
//  test_ping();
350
//  test_ping();
328
//  test_async_ipc();
351
//  test_async_ipc();
329
//  test_advanced_ipc();
352
//  test_advanced_ipc();
330
//  test_connection_ipc();
353
//  test_connection_ipc();
331
//  test_hangup();
354
//  test_hangup();
332
//  test_slam();
355
//  test_slam();
333
    test_as_send();
356
//  test_as_send();
-
 
357
    test_kbd();
-
 
358
 
334
/* 
359
/* 
335
    printf("Userspace task, taskid=%llX\n", task_get_id());
360
    printf("Userspace task, taskid=%llX\n", task_get_id());
336
 
361
 
337
    futex_initialize(&ftx, 1);
362
    futex_initialize(&ftx, 1);
338
    if (futex_down(&ftx) < 0)
363
    if (futex_down(&ftx) < 0)
339
        printf("Futex failed.\n");
364
        printf("Futex failed.\n");
340
    if (futex_up(&ftx) < 0)
365
    if (futex_up(&ftx) < 0)
341
        printf("Futex failed.\n");
366
        printf("Futex failed.\n");
342
 
367
 
343
    if (futex_down(&ftx) < 0)
368
    if (futex_down(&ftx) < 0)
344
        printf("Futex failed.\n");
369
        printf("Futex failed.\n");
345
 
370
 
346
    if ((tid = thread_create(utest, NULL, "utest")) != -1) {
371
    if ((tid = thread_create(utest, NULL, "utest")) != -1) {
347
        printf("Created thread tid=%d\n", tid);
372
        printf("Created thread tid=%d\n", tid);
348
    }
373
    }
349
 
374
 
350
    if ((tid = thread_create(utest, NULL, "utest")) != -1) {
375
    if ((tid = thread_create(utest, NULL, "utest")) != -1) {
351
        printf("Created thread tid=%d\n", tid);
376
        printf("Created thread tid=%d\n", tid);
352
    }
377
    }
353
 
378
 
354
    int i;
379
    int i;
355
   
380
   
356
    for (i = 0; i < 50000000; i++)
381
    for (i = 0; i < 50000000; i++)
357
        ;
382
        ;
358
       
383
       
359
    if (futex_up(&ftx) < 0)
384
    if (futex_up(&ftx) < 0)
360
        printf("Futex failed.\n");
385
        printf("Futex failed.\n");
361
 
386
 
362
 
387
 
363
    printf("Creating pseudo thread.\n");
388
    printf("Creating pseudo thread.\n");
364
    stage = 1;
389
    stage = 1;
365
    ptid = psthread_create(ptest, NULL);
390
    ptid = psthread_create(ptest, NULL);
366
    printf("Main thread stage%d.\n", stage);
391
    printf("Main thread stage%d.\n", stage);
367
    stage++;
392
    stage++;
368
    psthread_schedule_next();;
393
    psthread_schedule_next();;
369
    printf("Main thread stage%d.\n", stage);
394
    printf("Main thread stage%d.\n", stage);
370
    stage++;
395
    stage++;
371
    psthread_schedule_next();;
396
    psthread_schedule_next();;
372
    printf("Main thread stage%d.\n", stage);
397
    printf("Main thread stage%d.\n", stage);
373
 
398
 
374
    psthread_join(ptid);
399
    psthread_join(ptid);
375
 
400
 
376
    printf("Main thread exiting.\n");
401
    printf("Main thread exiting.\n");
377
*/
402
*/
378
    return 0;
403
    return 0;
379
}
404
}
380
 
405