Subversion Repositories HelenOS-historic

Rev

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

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