Subversion Repositories HelenOS-historic

Rev

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

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