Subversion Repositories HelenOS-historic

Rev

Rev 1489 | Rev 1531 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
447 decky 1
/*
2
 * Copyright (C) 2005 Martin Decky
3
 * All rights reserved.
4
 *
5
 * Redistribution and use in source and binary forms, with or without
6
 * modification, are permitted provided that the following conditions
7
 * are met:
8
 *
9
 * - Redistributions of source code must retain the above copyright
10
 *   notice, this list of conditions and the following disclaimer.
11
 * - Redistributions in binary form must reproduce the above copyright
12
 *   notice, this list of conditions and the following disclaimer in the
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
15
 *   derived from this software without specific prior written permission.
16
 *
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
19
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20
 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
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
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
26
 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27
 */
28
 
713 decky 29
#include "version.h"
1353 jermar 30
#include <ipc/ipc.h>
31
#include <ipc/services.h>
32
#include <ipc/ns.h>
988 palkovsky 33
#include <stdio.h>
34
#include <unistd.h>
35
#include <stdlib.h>
1065 jermar 36
#include <thread.h>
1175 jermar 37
#include <task.h>
1113 palkovsky 38
#include <psthread.h>
1111 jermar 39
#include <futex.h>
1250 jermar 40
#include <as.h>
1279 palkovsky 41
#include <ddi.h>
1330 palkovsky 42
#include <string.h>
1343 jermar 43
#include <errno.h>
1339 cejka 44
#include <kbd.h>
1363 vana 45
#include <ipc/fb.h>
1427 palkovsky 46
#include <async.h>
1449 palkovsky 47
#include <sys/time.h>
999 palkovsky 48
 
1089 palkovsky 49
int a;
1111 jermar 50
atomic_t ftx;
1089 palkovsky 51
 
1152 jermar 52
int __thread stage;
1129 palkovsky 53
 
1065 jermar 54
extern void utest(void *arg);
55
void utest(void *arg)
56
{
1081 jermar 57
    printf("Uspace thread started.\n");
1111 jermar 58
    if (futex_down(&ftx) < 0)
59
        printf("Futex failed.\n");
60
    if (futex_up(&ftx) < 0)
61
        printf("Futex failed.\n");
62
 
63
    printf("%s in good condition.\n", __FUNCTION__);
64
 
1065 jermar 65
    for (;;)
66
        ;
67
}
1049 cejka 68
 
1197 cejka 69
/* test different parameters types and modifiers */
995 cejka 70
static void test_printf(void)
71
{
72
    printf("Simple text.\n");
73
    printf("Now insert '%s' string.\n","this");
1073 cejka 74
    printf("Signed formats on uns. numbers: '%d', '%+d', '% d', '%u' (,+, ,u)\n", 321, 321, 321, 321);
75
    printf("Signed formats on sig. numbers: '%d', '%+d', '% d', '%u' (,+, ,u)\n", -321, -321, -321, -321);
76
    printf("Signed with different sized: '%hhd', '%hd', '%d', '%ld', %lld;\n", -3, -32, -321, -32101l, -3210123ll);
77
    printf("And now... '%hhd' byte! '%hd' word! '%d' int! \n", 11, 11111, 1111111111);
78
    printf("Different bases: %#hx, %#hu, %#ho and %#hb\n", 123, 123, 123, 123);
79
    printf("Different bases signed: %#hx, %#hu, %#ho and %#hb\n", -123, -123, -123, -123);
80
    printf("'%llX' llX! Another '%llx' llx! \n", 0x1234567887654321ll, 0x1234567887654321ll);
81
    printf("'%llX' with 64bit value and '%x' with 32 bit value. \n", 0x1234567887654321ll, 0x12345678 );
82
    printf("'%llx' 64bit, '%x' 32bit, '%hhx' 8bit, '%hx' 16bit, '%llX' 64bit and '%s' string.\n", 0x1234567887654321ll, 0x12345678, 0x12, 0x1234, 0x1234567887654321ull, "Lovely string" );
1049 cejka 83
 
995 cejka 84
    printf("Thats all, folks!\n");
85
}
999 palkovsky 86
 
1197 cejka 87
/* test width and precision modifiers */
88
static void test_printf2(void)
89
{
90
    printf(" text 10.8s %*.*s \n", 5, 3, "text");
91
    printf(" very long text 10.8s %10.8s \n", "very long text");
92
    printf(" text 8.10s %8.10s \n", "text");
93
    printf(" very long text 8.10s %8.10s \n", "very long text");
1049 cejka 94
 
1197 cejka 95
    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' );
96
    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 );
97
    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 );
98
    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 );
99
 
100
}
101
 
1028 palkovsky 102
extern char _heap;
994 jermar 103
static void test_mremap(void)
988 palkovsky 104
{
105
    printf("Writing to good memory\n");
1228 jermar 106
    as_area_resize(&_heap, 120000, 0);
988 palkovsky 107
    printf("%P\n", ((char *)&_heap));
108
    printf("%P\n", ((char *)&_heap) + 80000);
109
    *(((char *)&_heap) + 80000) = 10;
110
    printf("Making small\n");
1228 jermar 111
    as_area_resize(&_heap, 16000, 0);
988 palkovsky 112
    printf("Failing..\n");
113
    *((&_heap) + 80000) = 10;
114
 
115
    printf("memory done\n");
116
}
117
/*
118
static void test_sbrk(void)
119
{
120
    printf("Writing to good memory\n");
121
    printf("Got: %P\n", sbrk(120000));
122
    printf("%P\n", ((char *)&_heap));
123
    printf("%P\n", ((char *)&_heap) + 80000);
124
    *(((char *)&_heap) + 80000) = 10;
125
    printf("Making small, got: %P\n",sbrk(-120000));
126
    printf("Testing access to heap\n");
127
    _heap = 10;
128
    printf("Failing..\n");
129
    *((&_heap) + 80000) = 10;
130
 
131
    printf("memory done\n");
132
}
133
*/
134
/*
135
static void test_malloc(void)
136
{
137
    char *data;
138
 
139
    data = malloc(10);
140
    printf("Heap: %P, data: %P\n", &_heap, data);
141
    data[0] = 'a';
142
    free(data);
143
}
144
*/
145
 
1028 palkovsky 146
 
147
static void test_ping(void)
148
{
149
    ipcarg_t result;
150
    int retval;
151
 
1091 palkovsky 152
    printf("Pinging\n");
1028 palkovsky 153
    retval = ipc_call_sync(PHONE_NS, NS_PING, 0xbeef,&result);
154
    printf("Retval: %d - received: %P\n", retval, result);
155
}
156
 
1091 palkovsky 157
static void got_answer(void *private, int retval, ipc_call_t *data)
999 palkovsky 158
{
1073 cejka 159
    printf("Retval: %d...%s...%zX, %zX\n", retval, private,
999 palkovsky 160
           IPC_GET_ARG1(*data), IPC_GET_ARG2(*data));
161
}
162
 
163
 
1091 palkovsky 164
static void got_answer_2(void *private, int retval, ipc_call_t *data)
1028 palkovsky 165
{
166
    printf("Pong\n");
167
}
168
 
1061 palkovsky 169
static void test_connection_ipc(void)
170
{
171
    int res;
172
    ipcarg_t result;
1091 palkovsky 173
    int phoneid;
1061 palkovsky 174
 
175
    printf("Starting connect...\n");
176
    res = ipc_connect_me_to(PHONE_NS, 10, 20);
177
    printf("Connected: %d\n", res);
178
    printf("pinging.\n");
179
    res = ipc_call_sync(res, NS_PING, 0xbeef,&result);
1089 palkovsky 180
    printf("Retval: %d - received: %X\n", res, result);
1061 palkovsky 181
 
182
}
183
 
1113 palkovsky 184
static int ptest(void *arg)
185
{
1152 jermar 186
    stage = 1;
187
    printf("Pseudo thread stage%d.\n", stage);
188
    stage++;
1128 jermar 189
    psthread_schedule_next();
1152 jermar 190
    printf("Pseudo thread stage%d.\n", stage);
191
    stage++;
1128 jermar 192
    psthread_schedule_next();
1152 jermar 193
    printf("Pseudo thread stage%d.\n", stage);
1128 jermar 194
    psthread_schedule_next();
1152 jermar 195
    stage++;
196
    printf("Pseudo thread stage%d.\n", stage);
1128 jermar 197
    psthread_schedule_next();
198
    printf("Pseudo thread exiting.\n");
1113 palkovsky 199
    return 0;  
200
}
1111 jermar 201
 
1339 cejka 202
static void test_kbd()
203
{
204
    int res;
205
    ipcarg_t result;
206
    int phoneid;
207
 
208
    printf("Test: Starting connect...\n");
1445 cejka 209
    while ((phoneid = ipc_connect_me_to(PHONE_NS, SERVICE_CONSOLE, 0)) < 0) {
1339 cejka 210
    };
211
 
212
    printf("Test: Connected: %d\n", res);
213
    printf("Test: pinging.\n");
1445 cejka 214
/*  while (1) {
215
 
1339 cejka 216
        res = ipc_call_sync(phoneid, KBD_GETCHAR, 0xbeef,&result);
217
//      printf("Test: Retval: %d - received: %c\n", res, result);
218
        printf("%c", result);
219
    }
1445 cejka 220
*/ 
1339 cejka 221
    printf("Test: Hangin up\n");
222
    ipc_hangup(phoneid);
223
}
224
 
1427 palkovsky 225
static void test_async_kbd()
226
{
227
    int res;
228
    ipcarg_t result;
229
    ipc_call_t kbddata;
230
    int phoneid;
231
    aid_t aid;
232
 
233
    printf("Test: Starting connect...\n");
234
    while ((phoneid = ipc_connect_me_to(PHONE_NS, SERVICE_KEYBOARD, 0)) < 0) {
235
    };
236
 
237
    printf("Test: Connected: %d\n", res);
238
    printf("Test: pinging.\n");
1441 palkovsky 239
 
1445 cejka 240
 
1427 palkovsky 241
    while (1) {
242
    }
243
 
244
    printf("Test: Hangin up\n");
245
    ipc_hangup(phoneid);
246
}
247
 
1343 jermar 248
static void test_pci()
249
{
250
    int phone;
251
    while ((phone = ipc_connect_me_to(PHONE_NS, SERVICE_PCI, 0)) < 0)
252
        ;
253
    printf("Connected to PCI service through phone %d.\n", phone);
254
}
255
 
1360 jermar 256
static int test_as_area_send()
1330 palkovsky 257
{
1360 jermar 258
    char *as_area;
1330 palkovsky 259
    int retval;
260
    ipcarg_t result;
261
 
1360 jermar 262
    as_area = as_area_create((void *)(1024*1024), 16384, AS_AREA_READ | AS_AREA_WRITE);
263
    if (!as_area) {
264
        printf("Error creating as_area.\n");
1330 palkovsky 265
        return 0;
266
    }
267
 
1360 jermar 268
    memcpy(as_area, "Hello world.\n", 14);
1330 palkovsky 269
 
1418 jermar 270
    retval = ipc_call_sync_3(PHONE_NS, IPC_M_AS_AREA_SEND, (sysarg_t) as_area, 0, AS_AREA_READ,
271
        NULL, NULL, NULL);
1330 palkovsky 272
    if (retval) {
1360 jermar 273
        printf("AS_AREA_SEND failed.\n");
1330 palkovsky 274
        return 0;
275
    }
276
    printf("Done\n");
277
}
278
 
1363 vana 279
static void test_fb()
280
{
281
    int res;
282
    ipcarg_t result;
283
    int phoneid;
1486 palkovsky 284
    int vp;
1363 vana 285
 
286
//  printf("Test: Starting connect...\n");
287
 
288
    while ((phoneid = ipc_connect_me_to(PHONE_NS, SERVICE_VIDEO, 0)) < 0) {
289
        volatile int a;
290
        for(a=0;a<1048576;a++);
291
    };
292
 
1486 palkovsky 293
    usleep(100000);
294
    vp = ipc_call_sync_3(phoneid, FB_VIEWPORT_CREATE, (200 << 16) | 300, (200 << 16) | 150,0,NULL,NULL,NULL);
295
    if (! ipc_call_sync(phoneid, FB_VIEWPORT_SWITCH, vp, NULL)) {
296
        ipc_call_sync_2(phoneid, FB_SET_STYLE, 0, 0xffffff, NULL, NULL);
297
        ipc_call_sync(phoneid, FB_CLEAR, 0, NULL);
298
        ipc_call_sync_3(phoneid, FB_PUTCHAR, 'X', 0,0, NULL, NULL, NULL);
1363 vana 299
    }
1486 palkovsky 300
 
1363 vana 301
    ipc_hangup(phoneid);
302
}
303
 
1435 palkovsky 304
static void test_time(void)
305
{
306
    int rc;
307
    struct timeval tv;
308
    struct timezone tz;
1363 vana 309
 
1435 palkovsky 310
    while (1) {
311
        rc = gettimeofday(&tv, &tz);
312
        printf("Rc: %d, Secs: %d, Usecs: %d\n", rc, tv.tv_sec,
313
               tv.tv_usec);
314
    }
315
}
316
 
1465 cejka 317
static void test_console(void)
318
{
319
    int c;
320
 
321
    while ((c = getchar()) != EOF)
322
        putchar(c);
323
}
324
 
325
 
447 decky 326
int main(int argc, char *argv[])
327
{
1113 palkovsky 328
    pstid_t ptid;
1065 jermar 329
    int tid;
1197 cejka 330
 
1363 vana 331
//  version_print();
954 palkovsky 332
 
1465 cejka 333
    printf("Hello\nThis is Init\n");
334
 
1125 jermar 335
//  test_printf();
1197 cejka 336
//  test_printf2();
1028 palkovsky 337
//  test_ping();
338
//  test_async_ipc();
1061 palkovsky 339
//  test_advanced_ipc();
1089 palkovsky 340
//  test_connection_ipc();
341
//  test_hangup();
1091 palkovsky 342
//  test_slam();
1427 palkovsky 343
//  test_as_area_send();
1347 palkovsky 344
//  test_pci();
1427 palkovsky 345
//  test_kbd();
1441 palkovsky 346
//  test_time();
1453 palkovsky 347
//  test_async_kbd();
1363 vana 348
//  test_fb();
1489 palkovsky 349
    test_console();
1339 cejka 350
 
1465 cejka 351
    printf("\nBye.\n");
1363 vana 352
 
1330 palkovsky 353
/* 
1228 jermar 354
    printf("Userspace task, taskid=%llX\n", task_get_id());
1175 jermar 355
 
1111 jermar 356
    futex_initialize(&ftx, 1);
357
    if (futex_down(&ftx) < 0)
358
        printf("Futex failed.\n");
359
    if (futex_up(&ftx) < 0)
360
        printf("Futex failed.\n");
1089 palkovsky 361
 
1111 jermar 362
    if (futex_down(&ftx) < 0)
363
        printf("Futex failed.\n");
1152 jermar 364
 
1125 jermar 365
    if ((tid = thread_create(utest, NULL, "utest")) != -1) {
1091 palkovsky 366
        printf("Created thread tid=%d\n", tid);
367
    }
1111 jermar 368
 
1125 jermar 369
    if ((tid = thread_create(utest, NULL, "utest")) != -1) {
370
        printf("Created thread tid=%d\n", tid);
371
    }
1152 jermar 372
 
1111 jermar 373
    int i;
1343 jermar 374
 
1125 jermar 375
    for (i = 0; i < 50000000; i++)
1111 jermar 376
        ;
377
 
378
    if (futex_up(&ftx) < 0)
379
        printf("Futex failed.\n");
380
 
1129 palkovsky 381
 
1152 jermar 382
    printf("Creating pseudo thread.\n");
383
    stage = 1;
1113 palkovsky 384
    ptid = psthread_create(ptest, NULL);
1152 jermar 385
    printf("Main thread stage%d.\n", stage);
386
    stage++;
1128 jermar 387
    psthread_schedule_next();;
1152 jermar 388
    printf("Main thread stage%d.\n", stage);
389
    stage++;
1128 jermar 390
    psthread_schedule_next();;
1152 jermar 391
    printf("Main thread stage%d.\n", stage);
1113 palkovsky 392
 
1128 jermar 393
    psthread_join(ptid);
1113 palkovsky 394
 
1111 jermar 395
    printf("Main thread exiting.\n");
1330 palkovsky 396
*/
1343 jermar 397
 
447 decky 398
    return 0;
399
}