Rev 1061 | Rev 1073 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 1061 | Rev 1065 | ||
---|---|---|---|
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 | 36 | ||
- | 37 | extern void utest(void *arg); |
|
- | 38 | void utest(void *arg) |
|
- | 39 | { |
|
- | 40 | // printf("Uspace thread created.\n"); |
|
- | 41 | for (;;) |
|
- | 42 | ; |
|
- | 43 | } |
|
36 | 44 | ||
37 | static void test_printf(void) |
45 | static void test_printf(void) |
38 | { |
46 | { |
39 | printf("Simple text.\n"); |
47 | printf("Simple text.\n"); |
40 | printf("Now insert '%s' string.\n","this"); |
48 | printf("Now insert '%s' string.\n","this"); |
41 | printf("We are brave enought to print numbers like %%d = '%d'\n", 0x123456); |
49 | 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); |
50 | printf("And now... '%b' byte! '%w' word! '%W' Word! \n", 0x12, 0x1234, 0x1234); |
43 | printf("'%Q' Q! Another '%q' q! \n", 0x1234567887654321ll, 0x1234567887654321ll); |
51 | printf("'%Q' Q! Another '%q' q! \n", 0x1234567887654321ll, 0x1234567887654321ll); |
44 | printf("'%Q' with 64bit value and '%p' with 32 bit value. \n", 0x1234567887654321ll, 0x12345678 ); |
52 | 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" ); |
53 | printf("'%Q' 64bit, '%p' 32bit, '%b' 8bit, '%w' 16bit, '%Q' 64bit and '%s' string.\n", 0x1234567887654321ll, 0x12345678, 0x12, 0x1234, 0x1234567887654321ull, "Lovely string" ); |
46 | 54 | ||
47 | printf("Thats all, folks!\n"); |
55 | printf("Thats all, folks!\n"); |
48 | } |
56 | } |
49 | 57 | ||
50 | 58 | ||
51 | extern char _heap; |
59 | extern char _heap; |
52 | static void test_mremap(void) |
60 | static void test_mremap(void) |
53 | { |
61 | { |
54 | printf("Writing to good memory\n"); |
62 | printf("Writing to good memory\n"); |
55 | mremap(&_heap, 120000, 0); |
63 | mremap(&_heap, 120000, 0); |
56 | printf("%P\n", ((char *)&_heap)); |
64 | printf("%P\n", ((char *)&_heap)); |
57 | printf("%P\n", ((char *)&_heap) + 80000); |
65 | printf("%P\n", ((char *)&_heap) + 80000); |
58 | *(((char *)&_heap) + 80000) = 10; |
66 | *(((char *)&_heap) + 80000) = 10; |
59 | printf("Making small\n"); |
67 | printf("Making small\n"); |
60 | mremap(&_heap, 16000, 0); |
68 | mremap(&_heap, 16000, 0); |
61 | printf("Failing..\n"); |
69 | printf("Failing..\n"); |
62 | *((&_heap) + 80000) = 10; |
70 | *((&_heap) + 80000) = 10; |
63 | 71 | ||
64 | printf("memory done\n"); |
72 | printf("memory done\n"); |
65 | } |
73 | } |
66 | /* |
74 | /* |
67 | static void test_sbrk(void) |
75 | static void test_sbrk(void) |
68 | { |
76 | { |
69 | printf("Writing to good memory\n"); |
77 | printf("Writing to good memory\n"); |
70 | printf("Got: %P\n", sbrk(120000)); |
78 | printf("Got: %P\n", sbrk(120000)); |
71 | printf("%P\n", ((char *)&_heap)); |
79 | printf("%P\n", ((char *)&_heap)); |
72 | printf("%P\n", ((char *)&_heap) + 80000); |
80 | printf("%P\n", ((char *)&_heap) + 80000); |
73 | *(((char *)&_heap) + 80000) = 10; |
81 | *(((char *)&_heap) + 80000) = 10; |
74 | printf("Making small, got: %P\n",sbrk(-120000)); |
82 | printf("Making small, got: %P\n",sbrk(-120000)); |
75 | printf("Testing access to heap\n"); |
83 | printf("Testing access to heap\n"); |
76 | _heap = 10; |
84 | _heap = 10; |
77 | printf("Failing..\n"); |
85 | printf("Failing..\n"); |
78 | *((&_heap) + 80000) = 10; |
86 | *((&_heap) + 80000) = 10; |
79 | 87 | ||
80 | printf("memory done\n"); |
88 | printf("memory done\n"); |
81 | } |
89 | } |
82 | */ |
90 | */ |
83 | /* |
91 | /* |
84 | static void test_malloc(void) |
92 | static void test_malloc(void) |
85 | { |
93 | { |
86 | char *data; |
94 | char *data; |
87 | 95 | ||
88 | data = malloc(10); |
96 | data = malloc(10); |
89 | printf("Heap: %P, data: %P\n", &_heap, data); |
97 | printf("Heap: %P, data: %P\n", &_heap, data); |
90 | data[0] = 'a'; |
98 | data[0] = 'a'; |
91 | free(data); |
99 | free(data); |
92 | } |
100 | } |
93 | */ |
101 | */ |
94 | 102 | ||
95 | 103 | ||
96 | static void test_ping(void) |
104 | static void test_ping(void) |
97 | { |
105 | { |
98 | ipcarg_t result; |
106 | ipcarg_t result; |
99 | int retval; |
107 | int retval; |
100 | 108 | ||
101 | retval = ipc_call_sync(PHONE_NS, NS_PING, 0xbeef,&result); |
109 | retval = ipc_call_sync(PHONE_NS, NS_PING, 0xbeef,&result); |
102 | printf("Retval: %d - received: %P\n", retval, result); |
110 | printf("Retval: %d - received: %P\n", retval, result); |
103 | } |
111 | } |
104 | 112 | ||
105 | static void got_answer(void *private, int retval, ipc_data_t *data) |
113 | static void got_answer(void *private, int retval, ipc_data_t *data) |
106 | { |
114 | { |
107 | printf("Retval: %d...%s...%X, %X\n", retval, private, |
115 | printf("Retval: %d...%s...%X, %X\n", retval, private, |
108 | IPC_GET_ARG1(*data), IPC_GET_ARG2(*data)); |
116 | IPC_GET_ARG1(*data), IPC_GET_ARG2(*data)); |
109 | } |
117 | } |
110 | static void test_async_ipc(void) |
118 | static void test_async_ipc(void) |
111 | { |
119 | { |
112 | ipc_call_t data; |
120 | ipc_call_t data; |
113 | int i; |
121 | int i; |
114 | 122 | ||
115 | printf("Sending ping\n"); |
123 | printf("Sending ping\n"); |
116 | ipc_call_async_2(PHONE_NS, NS_PING, 1, 0xbeefbee2, |
124 | ipc_call_async_2(PHONE_NS, NS_PING, 1, 0xbeefbee2, |
117 | "Pong1", got_answer); |
125 | "Pong1", got_answer); |
118 | ipc_call_async_2(PHONE_NS, NS_PING, 2, 0xbeefbee4, |
126 | ipc_call_async_2(PHONE_NS, NS_PING, 2, 0xbeefbee4, |
119 | "Pong2", got_answer); |
127 | "Pong2", got_answer); |
120 | ipc_call_async_2(PHONE_NS, NS_PING, 3, 0xbeefbee4, |
128 | ipc_call_async_2(PHONE_NS, NS_PING, 3, 0xbeefbee4, |
121 | "Pong3", got_answer); |
129 | "Pong3", got_answer); |
122 | ipc_call_async_2(PHONE_NS, NS_PING, 4, 0xbeefbee4, |
130 | ipc_call_async_2(PHONE_NS, NS_PING, 4, 0xbeefbee4, |
123 | "Pong4", got_answer); |
131 | "Pong4", got_answer); |
124 | ipc_call_async_2(PHONE_NS, NS_PING, 5, 0xbeefbee4, |
132 | ipc_call_async_2(PHONE_NS, NS_PING, 5, 0xbeefbee4, |
125 | "Pong5", got_answer); |
133 | "Pong5", got_answer); |
126 | ipc_call_async_2(PHONE_NS, NS_PING, 6, 0xbeefbee4, |
134 | ipc_call_async_2(PHONE_NS, NS_PING, 6, 0xbeefbee4, |
127 | "Pong6", got_answer); |
135 | "Pong6", got_answer); |
128 | printf("Waiting forever...\n"); |
136 | printf("Waiting forever...\n"); |
129 | for (i=0; i<100;i++) |
137 | for (i=0; i<100;i++) |
130 | printf("."); |
138 | printf("."); |
131 | printf("\n"); |
139 | printf("\n"); |
132 | ipc_wait_for_call(&data, NULL); |
140 | ipc_wait_for_call(&data, NULL); |
133 | printf("Received call???\n"); |
141 | printf("Received call???\n"); |
134 | } |
142 | } |
135 | 143 | ||
136 | 144 | ||
137 | static void got_answer_2(void *private, int retval, ipc_data_t *data) |
145 | static void got_answer_2(void *private, int retval, ipc_data_t *data) |
138 | { |
146 | { |
139 | printf("Pong\n"); |
147 | printf("Pong\n"); |
140 | } |
148 | } |
141 | static void test_advanced_ipc(void) |
149 | static void test_advanced_ipc(void) |
142 | { |
150 | { |
143 | int res; |
151 | int res; |
144 | unsigned long long taskid; |
152 | unsigned long long taskid; |
145 | ipc_callid_t callid; |
153 | ipc_callid_t callid; |
146 | ipc_call_t data; |
154 | ipc_call_t data; |
147 | int i; |
155 | int i; |
148 | 156 | ||
149 | printf("Asking 0 to connect to me...\n"); |
157 | printf("Asking 0 to connect to me...\n"); |
150 | res = ipc_connect_to_me(0, 1, 2, &taskid); |
158 | res = ipc_connect_to_me(0, 1, 2, &taskid); |
151 | printf("Result: %d - taskid: %Q\n", res, taskid); |
159 | printf("Result: %d - taskid: %Q\n", res, taskid); |
152 | for (i=0; i < 100; i++) { |
160 | for (i=0; i < 100; i++) { |
153 | printf("----------------\n"); |
161 | printf("----------------\n"); |
154 | ipc_call_async(PHONE_NS, NS_PING_SVC, 0, "prov", |
162 | ipc_call_async(PHONE_NS, NS_PING_SVC, 0, "prov", |
155 | got_answer_2); |
163 | got_answer_2); |
156 | callid = ipc_wait_for_call(&data, NULL); |
164 | callid = ipc_wait_for_call(&data, NULL); |
157 | printf("Received ping\n"); |
165 | printf("Received ping\n"); |
158 | ipc_answer(callid, 0, 0, 0); |
166 | ipc_answer(callid, 0, 0, 0); |
159 | } |
167 | } |
160 | callid = ipc_wait_for_call(&data, NULL); |
168 | callid = ipc_wait_for_call(&data, NULL); |
161 | } |
169 | } |
162 | 170 | ||
163 | static void test_connection_ipc(void) |
171 | static void test_connection_ipc(void) |
164 | { |
172 | { |
165 | int res; |
173 | int res; |
166 | ipcarg_t result; |
174 | ipcarg_t result; |
167 | 175 | ||
168 | printf("Starting connect...\n"); |
176 | printf("Starting connect...\n"); |
169 | res = ipc_connect_me_to(PHONE_NS, 10, 20); |
177 | res = ipc_connect_me_to(PHONE_NS, 10, 20); |
170 | printf("Connected: %d\n", res); |
178 | printf("Connected: %d\n", res); |
171 | printf("pinging.\n"); |
179 | printf("pinging.\n"); |
172 | res = ipc_call_sync(res, NS_PING, 0xbeef,&result); |
180 | res = ipc_call_sync(res, NS_PING, 0xbeef,&result); |
173 | printf("Retval: %d - received: %P\n", res, result); |
181 | printf("Retval: %d - received: %P\n", res, result); |
174 | 182 | ||
175 | } |
183 | } |
176 | 184 | ||
177 | int main(int argc, char *argv[]) |
185 | int main(int argc, char *argv[]) |
178 | { |
186 | { |
- | 187 | int tid; |
|
- | 188 | char *stack; |
|
179 | version_print(); |
189 | version_print(); |
180 | 190 | ||
181 | /* test_printf(); */ |
191 | /* test_printf(); */ |
182 | // test_ping(); |
192 | // test_ping(); |
183 | // test_async_ipc(); |
193 | // test_async_ipc(); |
184 | // test_advanced_ipc(); |
194 | // test_advanced_ipc(); |
185 | test_connection_ipc(); |
195 | test_connection_ipc(); |
- | 196 | ||
- | 197 | stack = (char *) malloc(getpagesize()); |
|
- | 198 | if (!stack) { |
|
- | 199 | printf("Malloc failed.\n"); |
|
- | 200 | } else { |
|
- | 201 | if ((tid = thread_create(utest, NULL, stack, "utest") != -1)) { |
|
- | 202 | printf("Created thread tid=%d\n", tid); |
|
- | 203 | } |
|
- | 204 | } |
|
- | 205 | ||
186 | return 0; |
206 | return 0; |
187 | } |
207 | } |
188 | 208 |