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