From ad1ec29070e1ffba7461687cd268e64be06aa78b Mon Sep 17 00:00:00 2001 From: Alexis211 Date: Tue, 30 Mar 2010 19:22:23 +0200 Subject: More work on IPC and userland tools. --- src/modules/test/main.c | 41 +++++++++++++++++++++++++++++++---------- 1 file changed, 31 insertions(+), 10 deletions(-) (limited to 'src/modules/test') diff --git a/src/modules/test/main.c b/src/modules/test/main.c index df8b2ef..49dc50e 100644 --- a/src/modules/test/main.c +++ b/src/modules/test/main.c @@ -1,36 +1,57 @@ #include +#include +#include #define FACTOR 4 int obj = -1; +struct method_ret nulhandle(struct method_data *d) { + if (d->blocking) printk("[test:2?] Handling a request.\n"); + else printk("[test:2?] Handling a message.\n"); + return mr_void(); +} + void thread2(void* d) { printk("[test:2] Creating new object...\n"); - obj = object_create(); - struct user_request rq; + Server *s = srv_create(); + srv_addHandler(s, 0x00000010, nulhandle); + obj = s->id; while (1) { printk("[test:2] Waiting for a request...\n"); - request_get(obj, &rq, 1); - if (rq.isBlocking) { - printk("[test:2] Got request. Answering...\n"); - request_answer(obj, 42, 0); - } else { - printk("[test:2] Got message. Ignoring it.\n"); - } + srv_handle(s, HA_WAIT); } } int main() { + int i; + printk("[test:1] Hi world !\n"); printk("[test:1] Creating new thread...\n"); thread_new(thread2, 0); while (obj == -1); printk("[test:1] Object was created. Sending request...\n"); struct user_sendrequest sr; - sr.func = 0x80000001; + sr.func = 0x00000010; request(obj, &sr); printk("[test:1] Got answer. Sending message...\n"); send_msg(obj, &sr); + + printk("[test:1] testing malloc and free..."); + int* v = malloc(10 * sizeof(int)); + if (v == 0) printk("zero"); + int* vv = malloc(10 * sizeof(int)); + for (i = 0; i < 10; i++) { v[i] = i * 1243; } + for (i = 0; i < 10; i++) { vv[i] = i * 2; } + for (i = 0; i < 10; i++) { + if (v[i] != i * 1243) printk("FAIL"); + } + for (i = 0; i < 10; i++) { + if (vv[i] != i * 2) printk("fail"); + } + free(v); free(vv); + printk("nothing bad happened :)\n"); + printk("[test:1] HAHA !!! Death in 10 seconds!\n"); thread_sleep(10000); return 0; -- cgit v1.2.3