Subversion Repositories HelenOS-historic

Rev

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

Rev 1028 Rev 1049
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
 
35
 
36
/*
36
 
37
static void test_printf(void)
37
static void test_printf(void)
38
{
38
{
39
    printf("Simple text.\n");
39
    printf("Simple text.\n");
40
    printf("Now insert '%s' string.\n","this");
40
    printf("Now insert '%s' string.\n","this");
41
    printf("We are brave enought to print numbers like %%d = '%d'\n", 0x123456);
41
    printf("We are brave enought to print numbers like %%d = '%d'\n", 0x123456);
42
    printf("And now... '%b' byte! '%w' word! '%W' Word! \n", 0x12, 0x1234, 0x1234);
42
    printf("And now... '%b' byte! '%w' word! '%W' Word! \n", 0x12, 0x1234, 0x1234);
43
    printf(" '%Q' Q! Another '%q' q! \n", 0x1234567887654321ll, 0x1234567887654321ll);
43
    printf("'%Q' Q! Another '%q' q! \n", 0x1234567887654321ll, 0x1234567887654321ll);
44
    printf(" '%P' with 64bit value and '%p' with 32 bit value. \n", 0x1234567887654321ll, 0x12345678 );
44
    printf("'%Q' with 64bit value and '%p' with 32 bit value. \n", 0x1234567887654321ll, 0x12345678 );
-
 
45
    printf("'%Q' 64bit, '%p' 32bit, '%b' 8bit, '%w' 16bit, '%Q' 64bit and '%s' string.\n", 0x1234567887654321ll, 0x12345678, 0x12, 0x1234, 0x1234567887654321ull, "Lovely string" );
-
 
46
   
45
    printf("Thats all, folks!\n");
47
    printf("Thats all, folks!\n");
46
}
48
}
47
*/
49
 
48
 
50
 
49
extern char _heap;
51
extern char _heap;
50
static void test_mremap(void)
52
static void test_mremap(void)
51
{
53
{
52
    printf("Writing to good memory\n");
54
    printf("Writing to good memory\n");
53
    mremap(&_heap, 120000, 0);
55
    mremap(&_heap, 120000, 0);
54
    printf("%P\n", ((char *)&_heap));
56
    printf("%P\n", ((char *)&_heap));
55
    printf("%P\n", ((char *)&_heap) + 80000);
57
    printf("%P\n", ((char *)&_heap) + 80000);
56
    *(((char *)&_heap) + 80000) = 10;
58
    *(((char *)&_heap) + 80000) = 10;
57
    printf("Making small\n");
59
    printf("Making small\n");
58
    mremap(&_heap, 16000, 0);
60
    mremap(&_heap, 16000, 0);
59
    printf("Failing..\n");
61
    printf("Failing..\n");
60
    *((&_heap) + 80000) = 10;
62
    *((&_heap) + 80000) = 10;
61
 
63
 
62
    printf("memory done\n");
64
    printf("memory done\n");
63
}
65
}
64
/*
66
/*
65
static void test_sbrk(void)
67
static void test_sbrk(void)
66
{
68
{
67
    printf("Writing to good memory\n");
69
    printf("Writing to good memory\n");
68
    printf("Got: %P\n", sbrk(120000));
70
    printf("Got: %P\n", sbrk(120000));
69
    printf("%P\n", ((char *)&_heap));
71
    printf("%P\n", ((char *)&_heap));
70
    printf("%P\n", ((char *)&_heap) + 80000);
72
    printf("%P\n", ((char *)&_heap) + 80000);
71
    *(((char *)&_heap) + 80000) = 10;
73
    *(((char *)&_heap) + 80000) = 10;
72
    printf("Making small, got: %P\n",sbrk(-120000));
74
    printf("Making small, got: %P\n",sbrk(-120000));
73
    printf("Testing access to heap\n");
75
    printf("Testing access to heap\n");
74
    _heap = 10;
76
    _heap = 10;
75
    printf("Failing..\n");
77
    printf("Failing..\n");
76
    *((&_heap) + 80000) = 10;
78
    *((&_heap) + 80000) = 10;
77
 
79
 
78
    printf("memory done\n");
80
    printf("memory done\n");
79
}
81
}
80
*/
82
*/
81
/*
83
/*
82
static void test_malloc(void)
84
static void test_malloc(void)
83
{
85
{
84
    char *data;
86
    char *data;
85
 
87
 
86
    data = malloc(10);
88
    data = malloc(10);
87
    printf("Heap: %P, data: %P\n", &_heap, data);
89
    printf("Heap: %P, data: %P\n", &_heap, data);
88
    data[0] = 'a';
90
    data[0] = 'a';
89
    free(data);
91
    free(data);
90
}
92
}
91
*/
93
*/
92
 
94
 
93
 
95
 
94
static void test_ping(void)
96
static void test_ping(void)
95
{
97
{
96
    ipcarg_t result;
98
    ipcarg_t result;
97
    int retval;
99
    int retval;
98
 
100
 
99
    retval = ipc_call_sync(PHONE_NS, NS_PING, 0xbeef,&result);
101
    retval = ipc_call_sync(PHONE_NS, NS_PING, 0xbeef,&result);
100
    printf("Retval: %d - received: %P\n", retval, result);
102
    printf("Retval: %d - received: %P\n", retval, result);
101
}
103
}
102
 
104
 
103
static void got_answer(void *private, int retval, ipc_data_t *data)
105
static void got_answer(void *private, int retval, ipc_data_t *data)
104
{
106
{
105
    printf("Retval: %d...%s...%X, %X\n", retval, private,
107
    printf("Retval: %d...%s...%X, %X\n", retval, private,
106
           IPC_GET_ARG1(*data), IPC_GET_ARG2(*data));
108
           IPC_GET_ARG1(*data), IPC_GET_ARG2(*data));
107
}
109
}
108
static void test_async_ipc(void)
110
static void test_async_ipc(void)
109
{
111
{
110
    ipc_call_t data;
112
    ipc_call_t data;
111
    int i;
113
    int i;
112
 
114
 
113
    printf("Sending ping\n");
115
    printf("Sending ping\n");
114
    ipc_call_async_2(PHONE_NS, NS_PING, 1, 0xbeefbee2,
116
    ipc_call_async_2(PHONE_NS, NS_PING, 1, 0xbeefbee2,
115
             "Pong1", got_answer);
117
             "Pong1", got_answer);
116
    ipc_call_async_2(PHONE_NS, NS_PING, 2, 0xbeefbee4,
118
    ipc_call_async_2(PHONE_NS, NS_PING, 2, 0xbeefbee4,
117
             "Pong2", got_answer);
119
             "Pong2", got_answer);
118
    ipc_call_async_2(PHONE_NS, NS_PING, 3, 0xbeefbee4,
120
    ipc_call_async_2(PHONE_NS, NS_PING, 3, 0xbeefbee4,
119
             "Pong3", got_answer);
121
             "Pong3", got_answer);
120
    ipc_call_async_2(PHONE_NS, NS_PING, 4, 0xbeefbee4,
122
    ipc_call_async_2(PHONE_NS, NS_PING, 4, 0xbeefbee4,
121
             "Pong4", got_answer);
123
             "Pong4", got_answer);
122
    ipc_call_async_2(PHONE_NS, NS_PING, 5, 0xbeefbee4,
124
    ipc_call_async_2(PHONE_NS, NS_PING, 5, 0xbeefbee4,
123
             "Pong5", got_answer);
125
             "Pong5", got_answer);
124
    ipc_call_async_2(PHONE_NS, NS_PING, 6, 0xbeefbee4,
126
    ipc_call_async_2(PHONE_NS, NS_PING, 6, 0xbeefbee4,
125
             "Pong6", got_answer);
127
             "Pong6", got_answer);
126
    printf("Waiting forever...\n");
128
    printf("Waiting forever...\n");
127
    for (i=0; i<100;i++)
129
    for (i=0; i<100;i++)
128
        printf(".");
130
        printf(".");
129
    printf("\n");
131
    printf("\n");
130
    ipc_wait_for_call(&data, NULL);
132
    ipc_wait_for_call(&data, NULL);
131
    printf("Received call???\n");
133
    printf("Received call???\n");
132
}
134
}
133
 
135
 
134
 
136
 
135
static void got_answer_2(void *private, int retval, ipc_data_t *data)
137
static void got_answer_2(void *private, int retval, ipc_data_t *data)
136
{
138
{
137
    printf("Pong\n");
139
    printf("Pong\n");
138
}
140
}
139
static void test_advanced_ipc(void)
141
static void test_advanced_ipc(void)
140
{
142
{
141
    int res;
143
    int res;
142
    unsigned long long taskid;
144
    unsigned long long taskid;
143
    ipc_callid_t callid;
145
    ipc_callid_t callid;
144
    ipc_call_t data;
146
    ipc_call_t data;
145
 
147
 
146
    printf("Asking 0 to connect to me...\n");
148
    printf("Asking 0 to connect to me...\n");
147
    res = ipc_connect_to_me(0, 1, 2, &taskid);
149
    res = ipc_connect_to_me(0, 1, 2, &taskid);
148
    printf("Result: %d - taskid: %Q\n", res, taskid);
150
    printf("Result: %d - taskid: %Q\n", res, taskid);
149
//  while (1) {
151
//  while (1) {
150
        printf("----------------\n");
152
        printf("----------------\n");
151
        ipc_call_async(PHONE_NS, NS_PING_SVC, 0, "prov",
153
        ipc_call_async(PHONE_NS, NS_PING_SVC, 0, "prov",
152
                   got_answer_2);
154
                   got_answer_2);
153
        callid = ipc_wait_for_call(&data, NULL);
155
        callid = ipc_wait_for_call(&data, NULL);
154
        printf("Received ping\n");
156
        printf("Received ping\n");
155
        ipc_answer(callid, 0, 0, 0);
157
        ipc_answer(callid, 0, 0, 0);
156
//  }
158
//  }
157
        callid = ipc_wait_for_call(&data, NULL);
159
        callid = ipc_wait_for_call(&data, NULL);
158
}
160
}
159
 
161
 
160
int main(int argc, char *argv[])
162
int main(int argc, char *argv[])
161
{
163
{
162
    version_print();
164
    version_print();
163
 
165
 
-
 
166
/*  test_printf(); */
164
//  test_ping();
167
//  test_ping();
165
//  test_async_ipc();
168
//  test_async_ipc();
166
    test_advanced_ipc();
169
    test_advanced_ipc();
167
    return 0;
170
    return 0;
168
}
171
}
169
 
172