Index: kernel/test/atomic/atomic1/test.c
===================================================================
--- kernel/test/atomic/atomic1/test.c	(revision 1167520724b9b526c27b67f2d4bc447ef626240c)
+++ kernel/test/atomic/atomic1/test.c	(revision 1167520724b9b526c27b67f2d4bc447ef626240c)
@@ -0,0 +1,56 @@
+/*
+ * Copyright (C) 2006 Jakub Jermar
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the distribution.
+ * - The name of the author may not be used to endorse or promote products
+ *   derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <test.h>
+#include <print.h>
+#include <atomic.h>
+#include <debug.h>
+
+void test(void)
+{
+	atomic_t a;
+
+	atomic_set(&a, 10);
+	printf("Testing atomic_set() and atomic_get().\n");
+	ASSERT(atomic_get(&a) == 10);
+	printf("Testing atomic_postinc()\n");
+	ASSERT(atomic_postinc(&a) == 10);
+	ASSERT(atomic_get(&a) == 11);
+	printf("Testing atomic_postdec()\n");
+	ASSERT(atomic_postdec(&a) == 11);
+	ASSERT(atomic_get(&a) == 10);
+	printf("Testing atomic_preinc()\n");
+	ASSERT(atomic_preinc(&a) == 11);
+	ASSERT(atomic_get(&a) == 11);
+	printf("Testing atomic_predec()\n");
+	ASSERT(atomic_postdec(&a) == 11);
+	ASSERT(atomic_get(&a) == 10);
+
+	printf("Test passed.\n");	
+	return;
+}
Index: kernel/test/btree/btree1/test.c
===================================================================
--- kernel/test/btree/btree1/test.c	(revision 1167520724b9b526c27b67f2d4bc447ef626240c)
+++ kernel/test/btree/btree1/test.c	(revision 1167520724b9b526c27b67f2d4bc447ef626240c)
@@ -0,0 +1,159 @@
+/*
+ * Copyright (C) 2006 Jakub Jermar
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the distribution.
+ * - The name of the author may not be used to endorse or promote products
+ *   derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <test.h>
+#include <print.h>
+#include <adt/btree.h>
+#include <debug.h>
+
+void *data = (void *) 0xdeadbeef;
+
+void test(void)
+{
+	btree_t t;
+	int i;
+
+	btree_create(&t);
+
+	printf("Inserting keys.\n");
+	btree_insert(&t, 19, data, NULL);
+	btree_insert(&t, 20, data, NULL);
+	btree_insert(&t, 21, data, NULL);
+	btree_insert(&t, 0, data, NULL);
+	btree_insert(&t, 25, data, NULL);
+	btree_insert(&t, 22, data, NULL);
+	btree_insert(&t, 26, data, NULL);
+	btree_insert(&t, 23, data, NULL);
+	btree_insert(&t, 24, data, NULL);
+	btree_insert(&t, 5, data, NULL);
+	btree_insert(&t, 1, data, NULL);
+	btree_insert(&t, 4, data, NULL);
+	btree_insert(&t, 28, data, NULL);
+	btree_insert(&t, 29, data, NULL);
+	btree_insert(&t, 7, data, NULL);
+	btree_insert(&t, 8, data, NULL);
+	btree_insert(&t, 9, data, NULL);
+	btree_insert(&t, 17, data, NULL);
+	btree_insert(&t, 18, data, NULL);
+	btree_insert(&t, 2, data, NULL);
+	btree_insert(&t, 3, data, NULL);
+	btree_insert(&t, 6, data, NULL);
+	btree_insert(&t, 10, data, NULL);
+	btree_insert(&t, 11, data, NULL);
+	btree_insert(&t, 12, data, NULL);
+	btree_insert(&t, 13, data, NULL);
+	btree_insert(&t, 14, data, NULL);
+	btree_insert(&t, 15, data, NULL);
+	btree_insert(&t, 16, data, NULL);
+	btree_insert(&t, 27, data, NULL);
+
+	for (i = 30; i < 50; i++)
+		btree_insert(&t, i, data, NULL);
+	for (i = 100; i >= 50; i--)
+		btree_insert(&t, i, data, NULL);
+
+	btree_print(&t);
+	
+	printf("Removing keys.\n");
+	btree_remove(&t, 50, NULL);
+	btree_remove(&t, 49, NULL);
+	btree_remove(&t, 51, NULL);
+	btree_remove(&t, 46, NULL);
+	btree_remove(&t, 45, NULL);
+	btree_remove(&t, 48, NULL);
+	btree_remove(&t, 53, NULL);
+	btree_remove(&t, 47, NULL);
+	btree_remove(&t, 52, NULL);
+	btree_remove(&t, 54, NULL);
+	btree_remove(&t, 65, NULL);
+	btree_remove(&t, 60, NULL);
+	btree_remove(&t, 99, NULL);
+	btree_remove(&t, 97, NULL);
+	btree_remove(&t, 57, NULL);
+	btree_remove(&t, 58, NULL);
+	btree_remove(&t, 61, NULL);
+	btree_remove(&t, 64, NULL);
+	btree_remove(&t, 56, NULL);
+	btree_remove(&t, 41, NULL);
+
+	for (i = 5; i < 20; i++)
+		btree_remove(&t, i, NULL);
+
+	btree_remove(&t, 2, NULL);
+	btree_remove(&t, 43, NULL);
+	btree_remove(&t, 22, NULL);
+	btree_remove(&t, 100, NULL);
+	btree_remove(&t, 98, NULL);
+	btree_remove(&t, 96, NULL);
+	btree_remove(&t, 66, NULL);
+	btree_remove(&t, 1, NULL);
+
+	for (i = 70; i < 90; i++)
+		btree_remove(&t, i, NULL);
+
+	btree_remove(&t, 20, NULL);
+	btree_remove(&t, 0, NULL);
+	btree_remove(&t, 40, NULL);
+	btree_remove(&t, 3, NULL);
+	btree_remove(&t, 4, NULL);
+	btree_remove(&t, 21, NULL);
+	btree_remove(&t, 44, NULL);
+	btree_remove(&t, 55, NULL);
+	btree_remove(&t, 62, NULL);
+	btree_remove(&t, 26, NULL);
+	btree_remove(&t, 27, NULL);
+	btree_remove(&t, 28, NULL);
+	btree_remove(&t, 29, NULL);
+	btree_remove(&t, 30, NULL);
+	btree_remove(&t, 31, NULL);
+	btree_remove(&t, 32, NULL);
+	btree_remove(&t, 33, NULL);
+	btree_remove(&t, 93, NULL);
+	btree_remove(&t, 95, NULL);
+	btree_remove(&t, 94, NULL);
+	btree_remove(&t, 69, NULL);
+	btree_remove(&t, 68, NULL);
+	btree_remove(&t, 92, NULL);
+	btree_remove(&t, 91, NULL);
+	btree_remove(&t, 67, NULL);
+	btree_remove(&t, 63, NULL);
+	btree_remove(&t, 90, NULL);
+	btree_remove(&t, 59, NULL);
+	btree_remove(&t, 23, NULL);
+	btree_remove(&t, 24, NULL);
+	btree_remove(&t, 25, NULL);
+	btree_remove(&t, 37, NULL);
+	btree_remove(&t, 38, NULL);
+	btree_remove(&t, 42, NULL);
+	btree_remove(&t, 39, NULL);
+	btree_remove(&t, 34, NULL);
+	btree_remove(&t, 35, NULL);
+	btree_remove(&t, 36, NULL);
+
+	btree_print(&t);
+}
Index: kernel/test/debug/mips1/test.c
===================================================================
--- kernel/test/debug/mips1/test.c	(revision 1167520724b9b526c27b67f2d4bc447ef626240c)
+++ kernel/test/debug/mips1/test.c	(revision 1167520724b9b526c27b67f2d4bc447ef626240c)
@@ -0,0 +1,50 @@
+/*
+ * Copyright (C) 2005 Ondrej Palkovsky
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the distribution.
+ * - The name of the author may not be used to endorse or promote products
+ *   derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <print.h>
+#include <debug.h>
+#include <panic.h>
+
+#include <test.h>
+#include <atomic.h>
+#include <proc/thread.h>
+#include <time/delay.h>
+
+#include <arch.h>
+
+
+void test(void)
+{
+	printf("MIPS debug test #1\n");
+
+	printf("You should enter kconsole debug mode now.\n");
+
+	asm __volatile__ ("break");
+
+	printf("Test passed.\n");
+}
Index: kernel/test/fault/fault1/test.c
===================================================================
--- kernel/test/fault/fault1/test.c	(revision 1167520724b9b526c27b67f2d4bc447ef626240c)
+++ kernel/test/fault/fault1/test.c	(revision 1167520724b9b526c27b67f2d4bc447ef626240c)
@@ -0,0 +1,46 @@
+/*
+ * Copyright (C) 2005 Jakub Vana
+ * Copyright (C) 2005 Jakub Jermar
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the distribution.
+ * - The name of the author may not be used to endorse or promote products
+ *   derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <print.h>
+#include <debug.h>
+#include <panic.h>
+
+#include <test.h>
+#include <atomic.h>
+#include <proc/thread.h>
+
+#include <arch.h>
+
+
+void test(void)
+{
+
+	((int *)(0))[1]=0;  
+
+}
Index: kernel/test/fpu/fpu1/test.c
===================================================================
--- kernel/test/fpu/fpu1/test.c	(revision 1167520724b9b526c27b67f2d4bc447ef626240c)
+++ kernel/test/fpu/fpu1/test.c	(revision 1167520724b9b526c27b67f2d4bc447ef626240c)
@@ -0,0 +1,178 @@
+/*
+ * Copyright (C) 2005 Jakub Vana
+ * Copyright (C) 2005 Jakub Jermar
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the distribution.
+ * - The name of the author may not be used to endorse or promote products
+ *   derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <print.h>
+#include <debug.h>
+#include <panic.h>
+
+#include <test.h>
+#include <atomic.h>
+#include <proc/thread.h>
+
+#include <arch.h>
+#include <arch/arch.h>
+
+#define THREADS		150*2
+#define ATTEMPTS	100
+
+#define E_10e8	271828182
+#define PI_10e8	314159265
+
+
+#ifdef __ia32_ARCH_H__
+static inline double sqrt(double x) { double v; __asm__ ("fsqrt\n" : "=t" (v) : "0" (x)); return v; }
+#endif
+
+#ifdef __amd64_ARCH_H__
+static inline double sqrt(double x) { double v; __asm__ ("fsqrt\n" : "=t" (v) : "0" (x)); return v; }
+#endif
+
+#ifdef __ia64_ARCH_H__
+static inline long double sqrt(long double a) 
+{   
+	long double x =	1;
+	long double lx = 0;
+
+	if(a<0.00000000000000001) return 0;
+		
+	while(x!=lx)
+	{
+		lx=x;
+		x=(x+(a/x))/2;
+	}
+	return x; 
+}
+#endif
+
+
+
+static atomic_t threads_ok;
+static waitq_t can_start;
+
+static void e(void *data)
+{
+	int i;
+	double e,d,le,f;
+
+	thread_detach(THREAD);
+
+	waitq_sleep(&can_start);
+
+	for (i = 0; i<ATTEMPTS; i++) {
+		le=-1;
+		e=0;
+		f=1;
+
+		for(d=1;e!=le;d*=f,f+=1) {
+			le=e;
+			e=e+1/d;
+		}
+
+		if((int)(100000000*e)!=E_10e8)
+			panic("tid%d: e*10e8=%zd should be %zd\n", THREAD->tid, (unative_t) (100000000*e),(unative_t) E_10e8);
+	}
+
+	printf("tid%d: e*10e8=%zd should be %zd\n", THREAD->tid, (unative_t) (100000000*e),(unative_t) E_10e8);
+	atomic_inc(&threads_ok);
+}
+
+static void pi(void *data)
+{
+
+#ifdef __ia64_ARCH_H__
+#undef PI_10e8	
+#define PI_10e8	3141592
+#endif
+
+
+	int i;
+	double lpi, pi;
+	double n, ab, ad;
+	
+	thread_detach(THREAD);
+
+	waitq_sleep(&can_start);
+
+
+	for (i = 0; i<ATTEMPTS; i++) {
+		lpi = -1;
+		pi = 0;
+
+		for (n=2, ab = sqrt(2); lpi != pi; n *= 2, ab = ad) {
+			double sc, cd;
+
+			sc = sqrt(1 - (ab*ab/4));
+			cd = 1 - sc;
+			ad = sqrt(ab*ab/4 + cd*cd);
+			lpi = pi;
+			pi = 2 * n * ad;
+		}
+
+#ifdef __ia64_ARCH_H__
+		if((int)(1000000*pi)!=PI_10e8)
+			panic("tid%d: pi*10e8=%zd should be %zd\n", THREAD->tid, (unative_t) (1000000*pi),(unative_t) (PI_10e8/100));
+#else
+		if((int)(100000000*pi)!=PI_10e8)
+			panic("tid%d: pi*10e8=%zd should be %zd\n", THREAD->tid, (unative_t) (100000000*pi),(unative_t) PI_10e8);
+#endif
+
+	}
+
+	printf("tid%d: pi*10e8=%zd should be %zd\n", THREAD->tid, (unative_t) (100000000*pi),(unative_t) PI_10e8);
+	atomic_inc(&threads_ok);
+}
+
+void test(void)
+{
+	thread_t *t;
+	int i;
+
+	waitq_initialize(&can_start);
+
+	printf("FPU test #1\n");
+	printf("Creating %d threads... ", THREADS);
+
+	for (i=0; i<THREADS/2; i++) {  
+		if (!(t = thread_create(e, NULL, TASK, 0, "e")))
+			panic("could not create thread\n");
+		thread_ready(t);
+		if (!(t = thread_create(pi, NULL, TASK, 0, "pi")))
+			panic("could not create thread\n");
+		thread_ready(t);
+	}
+	printf("ok\n");
+	
+	thread_sleep(1);
+	waitq_wakeup(&can_start, WAKEUP_ALL);
+
+	while (atomic_get(&threads_ok) != THREADS)
+		;
+		
+	printf("Test passed.\n");
+}
Index: kernel/test/fpu/mips1/test.c
===================================================================
--- kernel/test/fpu/mips1/test.c	(revision 1167520724b9b526c27b67f2d4bc447ef626240c)
+++ kernel/test/fpu/mips1/test.c	(revision 1167520724b9b526c27b67f2d4bc447ef626240c)
@@ -0,0 +1,136 @@
+/*
+ * Copyright (C) 2005 Ondrej Palkovsky
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the distribution.
+ * - The name of the author may not be used to endorse or promote products
+ *   derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <print.h>
+#include <debug.h>
+#include <panic.h>
+
+#include <test.h>
+#include <atomic.h>
+#include <proc/thread.h>
+#include <time/delay.h>
+
+#include <arch.h>
+
+#define THREADS		50
+#define DELAY   	10000L
+#define ATTEMPTS        5
+
+static atomic_t threads_ok;
+static waitq_t can_start;
+
+static void testit1(void *data)
+{
+	int i;
+	int arg __attribute__((aligned(16))) = (int)((unative_t) data);
+	int after_arg __attribute__((aligned(16)));
+
+	thread_detach(THREAD);
+	
+	waitq_sleep(&can_start);
+
+	for (i = 0; i<ATTEMPTS; i++) {
+		__asm__ volatile (
+			"mtc1 %0,$1"
+			:"=r"(arg)
+			);
+
+		delay(DELAY);
+		__asm__ volatile (
+			"mfc1 %0, $1"
+			:"=r"(after_arg)
+			);
+		
+		if(arg != after_arg)
+			panic("General reg tid%d: arg(%d) != %d\n", 
+			      THREAD->tid, arg, after_arg);
+	}
+
+	atomic_inc(&threads_ok);
+}
+
+static void testit2(void *data)
+{
+	int i;
+	int arg __attribute__((aligned(16))) = (int)((unative_t) data);
+	int after_arg __attribute__((aligned(16)));
+
+	thread_detach(THREAD);
+
+	waitq_sleep(&can_start);
+
+	for (i = 0; i<ATTEMPTS; i++) {
+		__asm__ volatile (
+			"mtc1 %0,$1"
+			:"=r"(arg)
+			);
+
+		scheduler();
+		__asm__ volatile (
+			"mfc1 %0,$1"
+			:"=r"(after_arg)
+			);
+		
+		if(arg != after_arg)
+			panic("General reg tid%d: arg(%d) != %d\n", 
+			      THREAD->tid, arg, after_arg);
+	}
+
+	atomic_inc(&threads_ok);
+}
+
+
+void test(void)
+{
+	thread_t *t;
+	int i;
+
+	waitq_initialize(&can_start);
+
+	printf("MIPS test #1\n");
+	printf("Creating %d threads... ", THREADS);
+
+	for (i=0; i<THREADS/2; i++) {  
+		if (!(t = thread_create(testit1, (void *)((unative_t)i*2), TASK, 0, "testit1")))
+			panic("could not create thread\n");
+		thread_ready(t);
+		if (!(t = thread_create(testit2, (void *)((unative_t)i*2+1), TASK, 0, "testit2")))
+			panic("could not create thread\n");
+		thread_ready(t);
+	}
+
+	printf("ok\n");
+	
+	thread_sleep(1);
+	waitq_wakeup(&can_start, WAKEUP_ALL);
+
+	while (atomic_get(&threads_ok) != THREADS)
+		;
+		
+	printf("Test passed.\n");
+}
Index: kernel/test/fpu/sse1/test.c
===================================================================
--- kernel/test/fpu/sse1/test.c	(revision 1167520724b9b526c27b67f2d4bc447ef626240c)
+++ kernel/test/fpu/sse1/test.c	(revision 1167520724b9b526c27b67f2d4bc447ef626240c)
@@ -0,0 +1,136 @@
+/*
+ * Copyright (C) 2005 Ondrej Palkovsky
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the distribution.
+ * - The name of the author may not be used to endorse or promote products
+ *   derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <print.h>
+#include <debug.h>
+#include <panic.h>
+
+#include <test.h>
+#include <atomic.h>
+#include <proc/thread.h>
+#include <time/delay.h>
+
+#include <arch.h>
+
+#define THREADS		50
+#define DELAY   	10000L
+#define ATTEMPTS        5
+
+static atomic_t threads_ok;
+static waitq_t can_start;
+
+static void testit1(void *data)
+{
+	int i;
+	int arg __attribute__((aligned(16))) = (int)((unative_t) data);
+	int after_arg __attribute__((aligned(16)));
+
+	thread_detach(THREAD);
+	
+	waitq_sleep(&can_start);
+
+	for (i = 0; i<ATTEMPTS; i++) {
+		__asm__ volatile (
+			"movlpd	%0, %%xmm2"
+			:"=m"(arg)
+			);
+
+		delay(DELAY);
+		__asm__ volatile (
+			"movlpd %%xmm2, %0"
+			:"=m"(after_arg)
+			);
+		
+		if(arg != after_arg)
+			panic("tid%d: arg(%d) != %d\n", 
+			      THREAD->tid, arg, after_arg);
+	}
+
+	atomic_inc(&threads_ok);
+}
+
+static void testit2(void *data)
+{
+	int i;
+	int arg __attribute__((aligned(16))) = (int)((unative_t) data);
+	int after_arg __attribute__((aligned(16)));
+
+	thread_detach(THREAD);
+	
+	waitq_sleep(&can_start);
+
+	for (i = 0; i<ATTEMPTS; i++) {
+		__asm__ volatile (
+			"movlpd	%0, %%xmm2"
+			:"=m"(arg)
+			);
+
+		scheduler();
+		__asm__ volatile (
+			"movlpd %%xmm2, %0"
+			:"=m"(after_arg)
+			);
+		
+		if(arg != after_arg)
+			panic("tid%d: arg(%d) != %d\n", 
+			      THREAD->tid, arg, after_arg);
+	}
+
+	atomic_inc(&threads_ok);
+}
+
+
+void test(void)
+{
+	thread_t *t;
+	int i;
+
+	waitq_initialize(&can_start);
+
+	printf("SSE test #1\n");
+	printf("Creating %d threads... ", THREADS);
+
+	for (i=0; i<THREADS/2; i++) {  
+		if (!(t = thread_create(testit1, (void *)((unative_t)i*2), TASK, 0, "testit1")))
+			panic("could not create thread\n");
+		thread_ready(t);
+		if (!(t = thread_create(testit2, (void *)((unative_t)i*2+1), TASK, 0, "testit2")))
+			panic("could not create thread\n");
+		thread_ready(t);
+	}
+
+	printf("ok\n");
+	
+	thread_sleep(1);
+	waitq_wakeup(&can_start, WAKEUP_ALL);
+
+	while (atomic_get(&threads_ok) != THREADS)
+		;
+		
+	printf("Test passed.\n");
+}
Index: kernel/test/mm/falloc1/test.c
===================================================================
--- kernel/test/mm/falloc1/test.c	(revision 1167520724b9b526c27b67f2d4bc447ef626240c)
+++ kernel/test/mm/falloc1/test.c	(revision 1167520724b9b526c27b67f2d4bc447ef626240c)
@@ -0,0 +1,92 @@
+/*
+ * Copyright (C) 2006 Sergey Bondari
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the distribution.
+ * - The name of the author may not be used to endorse or promote products
+ *   derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+#include <print.h>
+#include <test.h>
+#include <mm/page.h>
+#include <mm/frame.h>
+#include <mm/slab.h>
+#include <arch/mm/page.h>
+#include <arch/types.h>
+#include <debug.h>
+#include <align.h>
+
+#define MAX_FRAMES 1024
+#define MAX_ORDER 8
+#define TEST_RUNS 2
+
+void test(void) {
+	uintptr_t * frames = (uintptr_t *) malloc(MAX_FRAMES*sizeof(uintptr_t), 0);
+	int results[MAX_ORDER+1];
+	
+	int i, order, run;
+	int allocated;
+
+	ASSERT(TEST_RUNS > 1);
+	ASSERT(frames != NULL)
+
+	for (run = 0; run < TEST_RUNS; run++) {
+		for (order = 0; order <= MAX_ORDER; order++) {
+			printf("Allocating %d frames blocks ... ", 1 << order);
+			allocated = 0;
+			for (i = 0; i < MAX_FRAMES >> order; i++) {
+				frames[allocated] = (uintptr_t) frame_alloc(order, FRAME_ATOMIC | FRAME_KA);
+				
+				if (ALIGN_UP(frames[allocated], FRAME_SIZE << order) != frames[allocated]) {
+					panic("Test failed. Block at address %p (size %dK) is not aligned\n", frames[allocated], (FRAME_SIZE << order) >> 10);
+				}
+				
+				if (frames[allocated]) {
+					allocated++;
+				} else {
+					printf("done. ");
+					break;
+				}
+			}
+		
+			printf("%d blocks allocated.\n", allocated);
+		
+			if (run) {
+				if (results[order] != allocated) {
+					panic("Test failed. Frame leak possible.\n");
+				}
+			} else
+				results[order] = allocated;
+			
+			printf("Deallocating ... ");
+			for (i = 0; i < allocated; i++) {
+				frame_free(KA2PA(frames[i]));
+			}
+			printf("done.\n");
+		}
+	}
+
+	free(frames);
+	
+	printf("Test passed.\n");
+}
+
Index: kernel/test/mm/falloc2/test.c
===================================================================
--- kernel/test/mm/falloc2/test.c	(revision 1167520724b9b526c27b67f2d4bc447ef626240c)
+++ kernel/test/mm/falloc2/test.c	(revision 1167520724b9b526c27b67f2d4bc447ef626240c)
@@ -0,0 +1,123 @@
+/*
+ * Copyright (C) 2006 Sergey Bondari
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the distribution.
+ * - The name of the author may not be used to endorse or promote products
+ *   derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+#include <print.h>
+#include <test.h>
+#include <mm/page.h>
+#include <mm/frame.h>
+#include <mm/slab.h>
+#include <arch/mm/page.h>
+#include <arch/types.h>
+#include <atomic.h>
+#include <debug.h>
+#include <proc/thread.h>
+#include <memstr.h>
+#include <arch.h>
+
+#define MAX_FRAMES 256
+#define MAX_ORDER 8
+
+#define THREAD_RUNS 1
+#define THREADS 8
+
+static void falloc(void * arg);
+static void failed(void);
+
+static atomic_t thread_count;
+
+void falloc(void * arg)
+{
+	int order, run, allocated, i;
+	uint8_t val = THREAD->tid % THREADS;
+	index_t k;
+	
+	uintptr_t * frames =  (uintptr_t *) malloc(MAX_FRAMES * sizeof(uintptr_t), FRAME_ATOMIC);
+	ASSERT(frames != NULL);
+	
+	thread_detach(THREAD);
+
+	for (run = 0; run < THREAD_RUNS; run++) {
+		for (order = 0; order <= MAX_ORDER; order++) {
+			printf("Thread #%d (cpu%d): Allocating %d frames blocks ... \n", THREAD->tid, CPU->id, 1 << order);
+			allocated = 0;
+			for (i = 0; i < (MAX_FRAMES >> order); i++) {
+				frames[allocated] = (uintptr_t)frame_alloc(order, FRAME_ATOMIC | FRAME_KA);
+				if (frames[allocated]) {
+					memsetb(frames[allocated], FRAME_SIZE << order, val);
+					allocated++;
+				} else {
+					break;
+				}
+			}
+			printf("Thread #%d (cpu%d): %d blocks allocated.\n", THREAD->tid, CPU->id, allocated);
+
+			printf("Thread #%d (cpu%d): Deallocating ... \n", THREAD->tid, CPU->id);
+			for (i = 0; i < allocated; i++) {
+				for (k = 0; k <= ((FRAME_SIZE << order) - 1); k++) {
+					if (((uint8_t *) frames[i])[k] != val) {
+						printf("Thread #%d (cpu%d): Unexpected data (%d) in block %p offset %#zx\n", THREAD->tid, CPU->id, ((char *) frames[i])[k], frames[i], k);
+						failed();
+					}
+				}
+				frame_free(KA2PA(frames[i]));
+			}
+			printf("Thread #%d (cpu%d): Finished run.\n", THREAD->tid, CPU->id);
+		}
+	}
+	
+	free(frames);
+	printf("Thread #%d (cpu%d): Exiting\n", THREAD->tid, CPU->id);
+	atomic_dec(&thread_count);
+}
+
+
+void failed(void)
+{
+	panic("Test failed.\n");
+}
+
+
+void test(void)
+{
+	int i;
+
+	atomic_set(&thread_count, THREADS);
+		
+	for (i = 0; i < THREADS; i++) {
+		thread_t * thrd;
+		thrd = thread_create(falloc, NULL, TASK, 0, "falloc");
+		if (thrd)
+			thread_ready(thrd);
+		else
+			failed();
+	}
+	
+	while (thread_count.count)
+		;
+
+	printf("Test passed.\n");
+}
Index: kernel/test/mm/mapping1/test.c
===================================================================
--- kernel/test/mm/mapping1/test.c	(revision 1167520724b9b526c27b67f2d4bc447ef626240c)
+++ kernel/test/mm/mapping1/test.c	(revision 1167520724b9b526c27b67f2d4bc447ef626240c)
@@ -0,0 +1,85 @@
+/*
+ * Copyright (C) 2005 Jakub Jermar
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the distribution.
+ * - The name of the author may not be used to endorse or promote products
+ *   derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+#include <print.h>
+#include <test.h>
+#include <mm/page.h>
+#include <mm/frame.h>
+#include <mm/as.h>
+#include <arch/mm/page.h>
+#include <arch/types.h>
+#include <debug.h>
+
+#define PAGE0	0x10000000
+#define PAGE1	(PAGE0+PAGE_SIZE)
+
+#define VALUE0	0x01234567
+#define VALUE1	0x89abcdef
+
+void test(void)
+{
+	uintptr_t frame0, frame1;
+	uint32_t v0, v1;
+
+	printf("Memory management test mapping #1\n");
+
+	frame0 = frame_alloc(ONE_FRAME, FRAME_KA);
+	frame1 = frame_alloc(ONE_FRAME, FRAME_KA);
+
+	printf("Writing %#x to physical address %p.\n", VALUE0, KA2PA(frame0));
+	*((uint32_t *) frame0) = VALUE0;
+	printf("Writing %#x to physical address %p.\n", VALUE1, KA2PA(frame1));
+	*((uint32_t *) frame1) = VALUE1;
+	
+	printf("Mapping virtual address %p to physical address %p.\n", PAGE0, KA2PA(frame0));
+	page_mapping_insert(AS_KERNEL, PAGE0, KA2PA(frame0), PAGE_PRESENT | PAGE_WRITE);
+	printf("Mapping virtual address %p to physical address %p.\n", PAGE1, KA2PA(frame1));	
+	page_mapping_insert(AS_KERNEL, PAGE1, KA2PA(frame1), PAGE_PRESENT | PAGE_WRITE);
+	
+	printf("Value at virtual address %p is %#x.\n", PAGE0, v0 = *((uint32_t *) PAGE0));
+	printf("Value at virtual address %p is %#x.\n", PAGE1, v1 = *((uint32_t *) PAGE1));
+	
+	ASSERT(v0 == VALUE0);
+	ASSERT(v1 == VALUE1);
+
+	printf("Writing %#x to virtual address %p.\n", 0, PAGE0);
+	*((uint32_t *) PAGE0) = 0;
+	printf("Writing %#x to virtual address %p.\n", 0, PAGE1);
+	*((uint32_t *) PAGE1) = 0;	
+
+	v0 = *((uint32_t *) PAGE0);
+	v1 = *((uint32_t *) PAGE1);
+	
+	printf("Value at virtual address %p is %#x.\n", PAGE0, *((uint32_t *) PAGE0));	
+	printf("Value at virtual address %p is %#x.\n", PAGE1, *((uint32_t *) PAGE1));
+
+	ASSERT(v0 == 0);
+	ASSERT(v1 == 0);
+	
+	printf("Test passed.\n");
+	
+}
Index: kernel/test/mm/purge1/test.c
===================================================================
--- kernel/test/mm/purge1/test.c	(revision 1167520724b9b526c27b67f2d4bc447ef626240c)
+++ kernel/test/mm/purge1/test.c	(revision 1167520724b9b526c27b67f2d4bc447ef626240c)
@@ -0,0 +1,85 @@
+/*
+ * Copyright (C) 2005 Jakub Jermar
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the distribution.
+ * - The name of the author may not be used to endorse or promote products
+ *   derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+#include <print.h>
+#include <test.h>
+#include <mm/page.h>
+#include <mm/frame.h>
+#include <mm/as.h>
+#include <arch/mm/page.h>
+#include <arch/mm/tlb.h>
+#include <arch/types.h>
+#include <debug.h>
+
+
+extern void tlb_invalidate_all(void);
+extern void tlb_invalidate_pages(asid_t asid, uintptr_t va, count_t cnt);
+void test(void)
+{
+	tlb_entry_t entryi;
+	tlb_entry_t entryd;
+
+	int i;
+																																													
+  entryd.word[0] = 0;
+  entryd.word[1] = 0;
+												
+  entryd.p = true;                 /* present */
+  entryd.ma = MA_WRITEBACK;
+  entryd.a = true;                 /* already accessed */
+  entryd.d = true;                 /* already dirty */
+  entryd.pl = PL_KERNEL;
+  entryd.ar = AR_READ | AR_WRITE;
+  entryd.ppn = 0;
+  entryd.ps = PAGE_WIDTH;
+
+
+  entryi.word[0] = 0;
+  entryi.word[1] = 0;
+												
+  entryi.p = true;                 /* present */
+  entryi.ma = MA_WRITEBACK;
+  entryi.a = true;                 /* already accessed */
+  entryi.d = true;                 /* already dirty */
+  entryi.pl = PL_KERNEL;
+  entryi.ar = AR_READ | AR_EXECUTE;
+  entryi.ppn = 0;
+  entryi.ps = PAGE_WIDTH;
+
+	
+	for(i=0;i<100;i++)
+	{
+		itc_mapping_insert(0+i*(1<<PAGE_WIDTH),8,entryi);
+		dtc_mapping_insert(0+i*(1<<PAGE_WIDTH),9,entryd);
+	}	
+	
+
+	tlb_invalidate_pages(8,0x0c000,14);
+	
+	/*tlb_invalidate_all();*/
+	
+}
Index: kernel/test/mm/slab1/test.c
===================================================================
--- kernel/test/mm/slab1/test.c	(revision 1167520724b9b526c27b67f2d4bc447ef626240c)
+++ kernel/test/mm/slab1/test.c	(revision 1167520724b9b526c27b67f2d4bc447ef626240c)
@@ -0,0 +1,160 @@
+/*
+ * Copyright (C) 2006 Ondrej Palkovsky
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the distribution.
+ * - The name of the author may not be used to endorse or promote products
+ *   derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <test.h>
+#include <mm/slab.h>
+#include <print.h>
+#include <proc/thread.h>
+#include <arch.h>
+#include <panic.h>
+#include <memstr.h>
+
+#define VAL_COUNT   1024
+
+void * data[VAL_COUNT];
+
+static void testit(int size, int count) 
+{
+	slab_cache_t *cache;
+	int i;
+	
+	printf("Creating cache, object size: %d.\n", size);
+	cache = slab_cache_create("test_cache", size, 0, NULL, NULL, 
+				  SLAB_CACHE_NOMAGAZINE);	
+	printf("Allocating %d items...", count);
+	for (i=0; i < count; i++) {
+		data[i] = slab_alloc(cache, 0);
+		memsetb((uintptr_t)data[i], size, 0);
+	}
+	printf("done.\n");
+	printf("Freeing %d items...", count);
+	for (i=0; i < count; i++) {
+		slab_free(cache, data[i]);
+	}
+	printf("done.\n");
+
+	printf("Allocating %d items...", count);
+	for (i=0; i < count; i++) {
+		data[i] = slab_alloc(cache, 0);
+		memsetb((uintptr_t)data[i], size, 0);
+	}
+	printf("done.\n");
+
+	printf("Freeing %d items...", count/2);
+	for (i=count-1; i >= count/2; i--) {
+		slab_free(cache, data[i]);
+	}
+	printf("done.\n");	
+
+	printf("Allocating %d items...", count/2);
+	for (i=count/2; i < count; i++) {
+		data[i] = slab_alloc(cache, 0);
+		memsetb((uintptr_t)data[i], size, 0);
+	}
+	printf("done.\n");
+	printf("Freeing %d items...", count);
+	for (i=0; i < count; i++) {
+		slab_free(cache, data[i]);
+	}
+	printf("done.\n");	
+	slab_cache_destroy(cache);
+
+	printf("Test complete.\n");
+}
+
+static void testsimple(void)
+{
+	testit(100, VAL_COUNT);
+	testit(200, VAL_COUNT);
+	testit(1024, VAL_COUNT);
+	testit(2048, 512);
+	testit(4000, 128);
+	testit(8192, 128);
+	testit(16384, 128);
+	testit(16385, 128);
+}
+
+
+#define THREADS     6
+#define THR_MEM_COUNT   1024
+#define THR_MEM_SIZE    128
+
+void * thr_data[THREADS][THR_MEM_COUNT];
+slab_cache_t *thr_cache;
+semaphore_t thr_sem;
+
+static void slabtest(void *data)
+{
+	int offs = (int)(unative_t) data;
+	int i,j;
+	
+	thread_detach(THREAD);
+	
+	printf("Starting thread #%d...\n",THREAD->tid);
+	for (j=0; j<10; j++) {
+		for (i=0; i<THR_MEM_COUNT; i++)
+			thr_data[offs][i] = slab_alloc(thr_cache,0);
+		for (i=0; i<THR_MEM_COUNT/2; i++)
+			slab_free(thr_cache, thr_data[offs][i]);
+		for (i=0; i< THR_MEM_COUNT/2; i++)
+			thr_data[offs][i] = slab_alloc(thr_cache, 0);
+		for (i=0; i<THR_MEM_COUNT;i++)
+			slab_free(thr_cache, thr_data[offs][i]);
+	}
+	printf("Thread #%d finished\n", THREAD->tid);
+	semaphore_up(&thr_sem);
+}
+
+static void testthreads(void)
+{
+	thread_t *t;
+	int i;
+
+	thr_cache = slab_cache_create("thread_cache", THR_MEM_SIZE, 0, 
+				      NULL, NULL, 
+				      SLAB_CACHE_NOMAGAZINE);
+	semaphore_initialize(&thr_sem,0);
+	for (i=0; i<THREADS; i++) {  
+		if (!(t = thread_create(slabtest, (void *)(unative_t)i, TASK, 0, "slabtest")))
+			panic("could not create thread\n");
+		thread_ready(t);
+	}
+
+	for (i=0; i<THREADS; i++)
+		semaphore_down(&thr_sem);
+	
+	slab_cache_destroy(thr_cache);
+	printf("Test complete.\n");
+	
+}
+
+void test(void)
+{
+	testsimple();
+	testthreads();
+}
Index: kernel/test/mm/slab2/test.c
===================================================================
--- kernel/test/mm/slab2/test.c	(revision 1167520724b9b526c27b67f2d4bc447ef626240c)
+++ kernel/test/mm/slab2/test.c	(revision 1167520724b9b526c27b67f2d4bc447ef626240c)
@@ -0,0 +1,221 @@
+/*
+ * Copyright (C) 2006 Ondrej Palkovsky
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the distribution.
+ * - The name of the author may not be used to endorse or promote products
+ *   derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <test.h>
+#include <mm/slab.h>
+#include <print.h>
+#include <proc/thread.h>
+#include <arch.h>
+#include <panic.h>
+#include <mm/frame.h>
+#include <memstr.h>
+#include <synch/condvar.h>
+#include <synch/mutex.h>
+
+#define ITEM_SIZE 256
+
+/** Fill memory with 2 caches, when allocation fails,
+ *  free one of the caches. We should have everything in magazines,
+ *  now allocation should clean magazines and allow for full allocation.
+ */
+static void totalmemtest(void)
+{
+	slab_cache_t *cache1;
+	slab_cache_t *cache2;
+	int i;
+
+	void *data1, *data2;
+	void *olddata1=NULL, *olddata2=NULL;
+	
+	cache1 = slab_cache_create("cache1_tst", ITEM_SIZE, 0, NULL, NULL, 0);
+	cache2 = slab_cache_create("cache2_tst", ITEM_SIZE, 0, NULL, NULL, 0);
+
+	printf("Allocating...");
+	/* Use atomic alloc, so that we find end of memory */
+	do {
+		data1 = slab_alloc(cache1, FRAME_ATOMIC);
+		data2 = slab_alloc(cache2, FRAME_ATOMIC);
+		if (!data1 || !data2) {
+			if (data1)
+				slab_free(cache1,data1);
+			if (data2)
+				slab_free(cache2,data2);
+			break;
+		}
+		memsetb((uintptr_t)data1, ITEM_SIZE, 0);
+		memsetb((uintptr_t)data2, ITEM_SIZE, 0);
+		*((void **)data1) = olddata1;
+		*((void **)data2) = olddata2;
+		olddata1 = data1;
+		olddata2 = data2;
+	}while(1);
+	printf("done.\n");
+	/* We do not have memory - now deallocate cache2 */
+	printf("Deallocating cache2...");
+	while (olddata2) {
+		data2 = *((void **)olddata2);
+		slab_free(cache2, olddata2);
+		olddata2 = data2;
+	}
+	printf("done.\n");
+
+	printf("Allocating to cache1...\n");
+	for (i=0; i<30; i++) {
+		data1 = slab_alloc(cache1, FRAME_ATOMIC);
+		if (!data1) {
+			panic("Incorrect memory size - use another test.");
+		}
+		memsetb((uintptr_t)data1, ITEM_SIZE, 0);
+		*((void **)data1) = olddata1;
+		olddata1 = data1;
+	}
+	while (1) {
+		data1 = slab_alloc(cache1, FRAME_ATOMIC);
+		if (!data1) {
+			break;
+		}
+		memsetb((uintptr_t)data1, ITEM_SIZE, 0);
+		*((void **)data1) = olddata1;
+		olddata1 = data1;
+	}
+	printf("Deallocating cache1...");
+	while (olddata1) {
+		data1 = *((void **)olddata1);
+		slab_free(cache1, olddata1);
+		olddata1 = data1;
+	}
+	printf("done.\n");
+	slab_print_list();
+	slab_cache_destroy(cache1);
+	slab_cache_destroy(cache2);
+}
+
+slab_cache_t *thr_cache;
+semaphore_t thr_sem;
+condvar_t thread_starter;
+mutex_t starter_mutex;
+
+#define THREADS 8
+
+static void slabtest(void *priv)
+{
+	void *data=NULL, *new;
+
+	thread_detach(THREAD);
+
+	mutex_lock(&starter_mutex);
+	condvar_wait(&thread_starter,&starter_mutex);
+	mutex_unlock(&starter_mutex);
+		
+	printf("Starting thread #%d...\n",THREAD->tid);
+
+	/* Alloc all */
+	printf("Thread #%d allocating...\n", THREAD->tid);
+	while (1) {
+		/* Call with atomic to detect end of memory */
+		new = slab_alloc(thr_cache, FRAME_ATOMIC);
+		if (!new)
+			break;
+		*((void **)new) = data;
+		data = new;
+	}
+	printf("Thread #%d releasing...\n", THREAD->tid);
+	while (data) {
+		new = *((void **)data);
+		*((void **)data) = NULL;
+		slab_free(thr_cache, data);
+		data = new;
+	}
+	printf("Thread #%d allocating...\n", THREAD->tid);
+	while (1) {
+		/* Call with atomic to detect end of memory */
+		new = slab_alloc(thr_cache, FRAME_ATOMIC);
+		if (!new)
+			break;
+		*((void **)new) = data;
+		data = new;
+	}
+	printf("Thread #%d releasing...\n", THREAD->tid);
+	while (data) {
+		new = *((void **)data);
+		*((void **)data) = NULL;
+		slab_free(thr_cache, data);
+		data = new;
+	}
+
+
+	printf("Thread #%d finished\n", THREAD->tid);
+	slab_print_list();
+	semaphore_up(&thr_sem);
+}
+
+
+static void multitest(int size)
+{
+	/* Start 8 threads that just allocate as much as possible,
+	 * then release everything, then again allocate, then release
+	 */
+	thread_t *t;
+	int i;
+
+	printf("Running stress test with size %d\n", size);
+	condvar_initialize(&thread_starter);
+	mutex_initialize(&starter_mutex);
+
+	thr_cache = slab_cache_create("thread_cache", size, 0, 
+				      NULL, NULL, 
+				      0);
+	semaphore_initialize(&thr_sem,0);
+	for (i=0; i<THREADS; i++) {  
+		if (!(t = thread_create(slabtest, NULL, TASK, 0, "slabtest")))
+			panic("could not create thread\n");
+		thread_ready(t);
+	}
+	thread_sleep(1);
+	condvar_broadcast(&thread_starter);
+
+	for (i=0; i<THREADS; i++)
+		semaphore_down(&thr_sem);
+	
+	slab_cache_destroy(thr_cache);
+	printf("Stress test complete.\n");
+}
+
+void test(void)
+{
+	printf("Running reclaim single-thread test .. pass1\n");
+	totalmemtest();
+	printf("Running reclaim single-thread test .. pass2\n");
+	totalmemtest();
+	printf("Reclaim test OK.\n");
+
+	multitest(128);
+	multitest(2048);
+	multitest(8192);
+	printf("All done.\n");
+}
Index: kernel/test/print/print1/test.c
===================================================================
--- kernel/test/print/print1/test.c	(revision 1167520724b9b526c27b67f2d4bc447ef626240c)
+++ kernel/test/print/print1/test.c	(revision 1167520724b9b526c27b67f2d4bc447ef626240c)
@@ -0,0 +1,71 @@
+/*
+ * Copyright (C) 2005 Josef Cejka
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the distribution.
+ * - The name of the author may not be used to endorse or promote products
+ *   derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+#include <print.h>
+#include <test.h>
+
+#define BUFFER_SIZE 32
+
+void test(void)
+{
+	int retval;
+	unative_t nat = 0x12345678u;
+	
+	char buffer[BUFFER_SIZE];
+	
+	printf(" Printf test \n");
+	
+	printf(" text 10.8s %*.*s \n", 5, 3, "text");
+	printf(" very long text 10.8s %10.8s \n", "very long text");
+	printf(" text 8.10s %8.10s \n", "text");
+	printf(" very long text 8.10s %8.10s \n", "very long text");
+
+	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' );
+	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 );
+	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 );
+	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 );
+
+	printf("'%#llx' 64bit, '%#x' 32bit, '%#hhx' 8bit, '%#hx' 16bit, unative_t '%#zx'. '%#llx' 64bit and '%s' string.\n", 0x1234567887654321ll, 0x12345678, 0x12, 0x1234, nat, 0x1234567887654321ull, "Lovely string" );
+	
+	printf(" Print to NULL '%s'\n",NULL);
+
+	retval = snprintf(buffer, BUFFER_SIZE, "Short text without parameters.");
+	printf("Result is: '%s', retval = %d\n", buffer, retval);
+
+	retval = snprintf(buffer, BUFFER_SIZE, "Very very very long text without parameters.");
+	printf("Result is: '%s', retval = %d\n", buffer, retval);
+	
+	printf("Print short text to %d char long buffer via snprintf.\n", BUFFER_SIZE);
+	retval = snprintf(buffer, BUFFER_SIZE, "Short %s", "text");
+	printf("Result is: '%s', retval = %d\n", buffer, retval);
+	
+	printf("Print long text to %d char long buffer via snprintf.\n", BUFFER_SIZE);
+	retval = snprintf(buffer, BUFFER_SIZE, "Very long %s. This text`s length is more than %d. We are interested in the result.", "text" , BUFFER_SIZE);
+	printf("Result is: '%s', retval = %d\n", buffer, retval);
+	
+	return;
+}
Index: kernel/test/synch/rwlock1/test.c
===================================================================
--- kernel/test/synch/rwlock1/test.c	(revision 1167520724b9b526c27b67f2d4bc447ef626240c)
+++ kernel/test/synch/rwlock1/test.c	(revision 1167520724b9b526c27b67f2d4bc447ef626240c)
@@ -0,0 +1,78 @@
+/*
+ * Copyright (C) 2001-2004 Jakub Jermar
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the distribution.
+ * - The name of the author may not be used to endorse or promote products
+ *   derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <test.h>
+#include <arch.h>
+#include <atomic.h>
+#include <print.h>
+#include <proc/thread.h>
+
+#include <synch/waitq.h>
+#include <synch/rwlock.h>
+
+#define READERS		50
+#define WRITERS		50
+
+static rwlock_t rwlock;
+
+void test(void)
+{
+	printf("Read/write locks test #1\n");
+
+	rwlock_initialize(&rwlock);
+
+	rwlock_write_lock(&rwlock);
+	rwlock_write_unlock(&rwlock);	
+
+	rwlock_read_lock(&rwlock);
+	rwlock_read_lock(&rwlock);	
+	rwlock_read_lock(&rwlock);
+	rwlock_read_lock(&rwlock);
+	rwlock_read_lock(&rwlock);
+
+	rwlock_read_unlock(&rwlock);
+	rwlock_read_unlock(&rwlock);	
+	rwlock_read_unlock(&rwlock);
+	rwlock_read_unlock(&rwlock);
+	rwlock_read_unlock(&rwlock);
+	
+	
+	rwlock_write_lock(&rwlock);
+	rwlock_write_unlock(&rwlock);	
+
+	rwlock_read_lock(&rwlock);
+	rwlock_read_unlock(&rwlock);
+
+	rwlock_write_lock(&rwlock);
+	rwlock_write_unlock(&rwlock);	
+
+	rwlock_read_lock(&rwlock);
+	rwlock_read_unlock(&rwlock);
+
+	printf("Test passed.\n");
+}
Index: kernel/test/synch/rwlock2/test.c
===================================================================
--- kernel/test/synch/rwlock2/test.c	(revision 1167520724b9b526c27b67f2d4bc447ef626240c)
+++ kernel/test/synch/rwlock2/test.c	(revision 1167520724b9b526c27b67f2d4bc447ef626240c)
@@ -0,0 +1,94 @@
+/*
+ * Copyright (C) 2001-2004 Jakub Jermar
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the distribution.
+ * - The name of the author may not be used to endorse or promote products
+ *   derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <test.h>
+#include <arch.h>
+#include <atomic.h>
+#include <print.h>
+#include <proc/thread.h>
+
+#include <synch/rwlock.h>
+
+#define READERS		50
+#define WRITERS		50
+
+static rwlock_t rwlock;
+
+static void writer(void *arg);
+static void failed(void);
+
+void writer(void *arg)
+{
+
+	thread_detach(THREAD);
+
+	printf("Trying to lock rwlock for writing....\n");    
+
+	rwlock_write_lock(&rwlock);
+	rwlock_write_unlock(&rwlock);
+	
+	printf("Trying to lock rwlock for reading....\n");    	
+	rwlock_read_lock(&rwlock);
+	rwlock_read_unlock(&rwlock);	
+	printf("Test passed.\n");
+}
+
+void failed()
+{
+	printf("Test failed prematurely.\n");
+	thread_exit();
+}
+
+void test(void)
+{
+	thread_t *thrd;
+	
+	printf("Read/write locks test #2\n");
+    
+	rwlock_initialize(&rwlock);
+
+	rwlock_read_lock(&rwlock);
+	rwlock_read_lock(&rwlock);
+	rwlock_read_lock(&rwlock);
+	rwlock_read_lock(&rwlock);	
+	
+	thrd = thread_create(writer, NULL, TASK, 0, "writer");
+	if (thrd)
+		thread_ready(thrd);
+	else
+		failed();
+
+
+	thread_sleep(1);
+	
+	rwlock_read_unlock(&rwlock);
+	rwlock_read_unlock(&rwlock);
+	rwlock_read_unlock(&rwlock);
+	rwlock_read_unlock(&rwlock);	
+
+}
Index: kernel/test/synch/rwlock3/test.c
===================================================================
--- kernel/test/synch/rwlock3/test.c	(revision 1167520724b9b526c27b67f2d4bc447ef626240c)
+++ kernel/test/synch/rwlock3/test.c	(revision 1167520724b9b526c27b67f2d4bc447ef626240c)
@@ -0,0 +1,93 @@
+/*
+ * Copyright (C) 2001-2004 Jakub Jermar
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the distribution.
+ * - The name of the author may not be used to endorse or promote products
+ *   derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <test.h>
+#include <arch.h>
+#include <atomic.h>
+#include <print.h>
+#include <proc/thread.h>
+
+#include <synch/rwlock.h>
+
+#define READERS		50
+#define WRITERS		50
+
+static rwlock_t rwlock;
+
+static void reader(void *arg);
+static void failed(void);
+
+void reader(void *arg)
+{
+	thread_detach(THREAD);
+
+	printf("cpu%d, tid %d: trying to lock rwlock for reading....\n", CPU->id, THREAD->tid);    	
+	rwlock_read_lock(&rwlock);
+	rwlock_read_unlock(&rwlock);	
+	printf("cpu%d, tid %d: success\n", CPU->id, THREAD->tid);    		
+
+	printf("cpu%d, tid %d: trying to lock rwlock for writing....\n", CPU->id, THREAD->tid);    	
+
+	rwlock_write_lock(&rwlock);
+	rwlock_write_unlock(&rwlock);
+	printf("cpu%d, tid %d: success\n", CPU->id, THREAD->tid);    			
+	
+	printf("Test passed.\n");	
+
+}
+
+void failed(void)
+{
+	printf("Test failed prematurely.\n");
+	thread_exit();
+}
+
+void test(void)
+{
+	int i;
+	thread_t *thrd;
+	
+	printf("Read/write locks test #3\n");
+    
+	rwlock_initialize(&rwlock);
+
+	rwlock_write_lock(&rwlock);
+	
+	for (i=0; i<4; i++) {
+		thrd = thread_create(reader, NULL, TASK, 0, "reader");
+		if (thrd)
+			thread_ready(thrd);
+		else
+			failed();
+	}
+
+
+	thread_sleep(1);
+	
+	rwlock_write_unlock(&rwlock);
+}
Index: kernel/test/synch/rwlock4/test.c
===================================================================
--- kernel/test/synch/rwlock4/test.c	(revision 1167520724b9b526c27b67f2d4bc447ef626240c)
+++ kernel/test/synch/rwlock4/test.c	(revision 1167520724b9b526c27b67f2d4bc447ef626240c)
@@ -0,0 +1,163 @@
+/*
+ * Copyright (C) 2001-2004 Jakub Jermar
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the distribution.
+ * - The name of the author may not be used to endorse or promote products
+ *   derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <test.h>
+#include <arch.h>
+#include <atomic.h>
+#include <print.h>
+#include <proc/thread.h>
+#include <arch/types.h>
+#include <arch/context.h>
+#include <context.h>
+#include <panic.h>
+
+#include <synch/waitq.h>
+#include <synch/rwlock.h>
+#include <synch/synch.h>
+#include <synch/spinlock.h>
+
+#define READERS		50
+#define WRITERS		50
+
+static rwlock_t rwlock;
+
+SPINLOCK_INITIALIZE(lock);
+
+static waitq_t can_start;
+
+uint32_t seed = 0xdeadbeef;
+
+static uint32_t random(uint32_t max);
+
+static void writer(void *arg);
+static void reader(void *arg);
+static void failed(void);
+
+uint32_t random(uint32_t max)
+{
+	uint32_t rc;
+
+	spinlock_lock(&lock);	
+	rc = seed % max;
+	seed = (((seed<<2) ^ (seed>>2)) * 487) + rc;
+	spinlock_unlock(&lock);
+	return rc;
+}
+
+
+void writer(void *arg)
+{
+	int rc, to;
+	thread_detach(THREAD);
+	waitq_sleep(&can_start);
+
+	to = random(40000);
+	printf("cpu%d, tid %d w+ (%d)\n", CPU->id, THREAD->tid, to);
+	rc = rwlock_write_lock_timeout(&rwlock, to);
+	if (SYNCH_FAILED(rc)) {
+		printf("cpu%d, tid %d w!\n", CPU->id, THREAD->tid);
+		return;
+	};
+	printf("cpu%d, tid %d w=\n", CPU->id, THREAD->tid);
+
+	if (rwlock.readers_in) panic("Oops.");
+	thread_usleep(random(1000000));
+	if (rwlock.readers_in) panic("Oops.");	
+
+	rwlock_write_unlock(&rwlock);
+	printf("cpu%d, tid %d w-\n", CPU->id, THREAD->tid);	
+}
+
+void reader(void *arg)
+{
+	int rc, to;
+	thread_detach(THREAD);
+	waitq_sleep(&can_start);
+	
+	to = random(2000);
+	printf("cpu%d, tid %d r+ (%d)\n", CPU->id, THREAD->tid, to);
+	rc = rwlock_read_lock_timeout(&rwlock, to);
+	if (SYNCH_FAILED(rc)) {
+		printf("cpu%d, tid %d r!\n", CPU->id, THREAD->tid);
+		return;
+	}
+	printf("cpu%d, tid %d r=\n", CPU->id, THREAD->tid);
+	thread_usleep(30000);
+	rwlock_read_unlock(&rwlock);
+	printf("cpu%d, tid %d r-\n", CPU->id, THREAD->tid);		
+}
+
+void failed(void)
+{
+	printf("Test failed prematurely.\n");
+	thread_exit();
+}
+
+void test(void)
+{
+	context_t ctx;
+	uint32_t i, k;
+	
+	printf("Read/write locks test #4\n");
+    
+	waitq_initialize(&can_start);
+	rwlock_initialize(&rwlock);
+	
+
+	
+	for (; ;) {
+		thread_t *thrd;
+		
+		context_save(&ctx);
+		printf("sp=%#x, readers_in=%d\n", ctx.sp, rwlock.readers_in);
+		
+		k = random(7) + 1;
+		printf("Creating %d readers\n", k);
+		for (i=0; i<k; i++) {
+			thrd = thread_create(reader, NULL, TASK, 0, "reader");
+			if (thrd)
+				thread_ready(thrd);
+			else
+				failed();
+		}
+
+		k = random(5) + 1;
+		printf("Creating %d writers\n", k);
+		for (i=0; i<k; i++) {
+			thrd = thread_create(writer, NULL, TASK, 0, "writer");
+			if (thrd)
+				thread_ready(thrd);
+			else
+				failed();
+		}
+		
+		thread_usleep(20000);
+		waitq_wakeup(&can_start, WAKEUP_ALL);
+	}		
+
+}
Index: kernel/test/synch/rwlock5/test.c
===================================================================
--- kernel/test/synch/rwlock5/test.c	(revision 1167520724b9b526c27b67f2d4bc447ef626240c)
+++ kernel/test/synch/rwlock5/test.c	(revision 1167520724b9b526c27b67f2d4bc447ef626240c)
@@ -0,0 +1,128 @@
+/*
+ * Copyright (C) 2001-2004 Jakub Jermar
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the distribution.
+ * - The name of the author may not be used to endorse or promote products
+ *   derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <test.h>
+#include <arch.h>
+#include <atomic.h>
+#include <print.h>
+#include <proc/thread.h>
+
+#include <synch/waitq.h>
+#include <synch/rwlock.h>
+
+#define READERS		50
+#define WRITERS		50
+
+static rwlock_t rwlock;
+
+static waitq_t can_start;
+static atomic_t items_read;
+static atomic_t items_written;
+
+static void writer(void *arg);
+static void reader(void *arg);
+static void failed(void);
+
+void writer(void *arg)
+{
+	thread_detach(THREAD);
+
+	waitq_sleep(&can_start);
+
+	rwlock_write_lock(&rwlock);
+	atomic_inc(&items_written);
+	rwlock_write_unlock(&rwlock);
+}
+
+void reader(void *arg)
+{
+	thread_detach(THREAD);
+
+	waitq_sleep(&can_start);
+	
+	rwlock_read_lock(&rwlock);
+	atomic_inc(&items_read);
+	rwlock_read_unlock(&rwlock);
+}
+
+void failed(void)
+{
+	printf("Test failed prematurely.\n");
+	thread_exit();
+}
+
+void test(void)
+{
+	int i, j, k;
+	count_t readers, writers;
+	
+	printf("Read/write locks test #5\n");
+    
+	waitq_initialize(&can_start);
+	rwlock_initialize(&rwlock);
+	
+	for (i=1; i<=3; i++) {
+		thread_t *thrd;
+
+		atomic_set(&items_read, 0);
+		atomic_set(&items_written, 0);
+
+		readers = i*READERS;
+		writers = (4-i)*WRITERS;
+
+		printf("Creating %ld readers and %ld writers...", readers, writers);
+		
+		for (j=0; j<(READERS+WRITERS)/2; j++) {
+			for (k=0; k<i; k++) {
+				thrd = thread_create(reader, NULL, TASK, 0, "reader");
+				if (thrd)
+					thread_ready(thrd);
+				else
+					failed();
+			}
+			for (k=0; k<(4-i); k++) {
+				thrd = thread_create(writer, NULL, TASK, 0, "writer");
+				if (thrd)
+					thread_ready(thrd);
+				else
+					failed();
+			}
+		}
+
+		printf("ok\n");
+
+		thread_sleep(1);
+		waitq_wakeup(&can_start, WAKEUP_ALL);
+	
+		while (items_read.count != readers || items_written.count != writers) {
+			printf("%zd readers remaining, %zd writers remaining, readers_in=%zd\n", readers - items_read.count, writers - items_written.count, rwlock.readers_in);
+			thread_usleep(100000);
+		}
+	}
+	printf("Test passed.\n");
+}
Index: kernel/test/synch/semaphore1/test.c
===================================================================
--- kernel/test/synch/semaphore1/test.c	(revision 1167520724b9b526c27b67f2d4bc447ef626240c)
+++ kernel/test/synch/semaphore1/test.c	(revision 1167520724b9b526c27b67f2d4bc447ef626240c)
@@ -0,0 +1,132 @@
+/*
+ * Copyright (C) 2001-2004 Jakub Jermar
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the distribution.
+ * - The name of the author may not be used to endorse or promote products
+ *   derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <test.h>
+#include <arch.h>
+#include <atomic.h>
+#include <print.h>
+#include <proc/thread.h>
+
+#include <synch/waitq.h>
+#include <synch/semaphore.h>
+
+#define AT_ONCE			3
+#define PRODUCERS		50
+#define CONSUMERS		50
+
+static semaphore_t sem;
+
+static waitq_t can_start;
+static atomic_t items_produced;
+static atomic_t items_consumed;
+
+static void consumer(void *arg);
+static void producer(void *arg);
+static void failed(void);
+
+void producer(void *arg)
+{
+	thread_detach(THREAD);	
+
+	waitq_sleep(&can_start);
+	    
+	semaphore_down(&sem);
+	atomic_inc(&items_produced);
+	thread_usleep(250);
+	semaphore_up(&sem);
+}
+
+void consumer(void *arg)
+{
+	thread_detach(THREAD);	
+	
+	waitq_sleep(&can_start);
+	
+	semaphore_down(&sem);
+	atomic_inc(&items_consumed);
+	thread_usleep(500);
+	semaphore_up(&sem);
+}
+
+void failed(void)
+{
+	printf("Test failed prematurely.\n");
+	thread_exit();
+}
+
+void test(void)
+{
+	int i, j, k;
+	int consumers, producers;
+	
+	printf("Semaphore test #1\n");
+    
+	waitq_initialize(&can_start);
+	semaphore_initialize(&sem, AT_ONCE);
+
+
+	for (i=1; i<=3; i++) {
+		thread_t *thrd;
+
+		atomic_set(&items_produced, 0);
+		atomic_set(&items_consumed, 0);
+		
+		consumers = i * CONSUMERS;
+		producers = (4-i) * PRODUCERS;
+		
+		printf("Creating %d consumers and %d producers...", consumers, producers);
+	
+		for (j=0; j<(CONSUMERS+PRODUCERS)/2; j++) {
+			for (k=0; k<i; k++) {
+				thrd = thread_create(consumer, NULL, TASK, 0, "consumer");
+				if (thrd)
+					thread_ready(thrd);
+				else
+					failed();
+			}
+			for (k=0; k<(4-i); k++) {
+				thrd = thread_create(producer, NULL, TASK, 0, "producer");
+				if (thrd)
+					thread_ready(thrd);
+				else
+					failed();
+			}
+		}
+
+		printf("ok\n");
+
+		thread_sleep(1);
+		waitq_wakeup(&can_start, WAKEUP_ALL);
+	
+		while (items_consumed.count != consumers || items_produced.count != producers) {
+			printf("%d consumers remaining, %d producers remaining\n", consumers - items_consumed.count, producers - items_produced.count);
+			thread_sleep(1);
+		}
+	}
+	printf("Test passed.\n");
+}
Index: kernel/test/synch/semaphore2/test.c
===================================================================
--- kernel/test/synch/semaphore2/test.c	(revision 1167520724b9b526c27b67f2d4bc447ef626240c)
+++ kernel/test/synch/semaphore2/test.c	(revision 1167520724b9b526c27b67f2d4bc447ef626240c)
@@ -0,0 +1,124 @@
+/*
+ * Copyright (C) 2001-2004 Jakub Jermar
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the distribution.
+ * - The name of the author may not be used to endorse or promote products
+ *   derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <test.h>
+#include <arch.h>
+#include <atomic.h>
+#include <print.h>
+#include <proc/thread.h>
+#include <arch/types.h>
+#include <arch/context.h>
+
+#include <synch/waitq.h>
+#include <synch/semaphore.h>
+#include <synch/synch.h>
+#include <synch/spinlock.h>
+
+static semaphore_t sem;
+
+SPINLOCK_INITIALIZE(lock);
+
+static waitq_t can_start;
+
+uint32_t seed = 0xdeadbeef;
+
+static uint32_t random(uint32_t max);
+
+static void consumer(void *arg);
+static void failed(void);
+
+uint32_t random(uint32_t max)
+{
+	uint32_t rc;
+
+	spinlock_lock(&lock);	
+	rc = seed % max;
+	seed = (((seed<<2) ^ (seed>>2)) * 487) + rc;
+	spinlock_unlock(&lock);
+	return rc;
+}
+
+
+void consumer(void *arg)
+{
+	int rc, to;
+	
+	thread_detach(THREAD);
+	
+	waitq_sleep(&can_start);
+	
+	to = random(20000);
+	printf("cpu%d, tid %d down+ (%d)\n", CPU->id, THREAD->tid, to);
+	rc = semaphore_down_timeout(&sem, to);
+	if (SYNCH_FAILED(rc)) {
+		printf("cpu%d, tid %d down!\n", CPU->id, THREAD->tid);
+		return;
+	}
+	
+	printf("cpu%d, tid %d down=\n", CPU->id, THREAD->tid);	
+	thread_usleep(random(30000));
+	
+	semaphore_up(&sem);
+	printf("cpu%d, tid %d up\n", CPU->id, THREAD->tid);
+}
+
+void failed(void)
+{
+	printf("Test failed prematurely.\n");
+	thread_exit();
+}
+
+void test(void)
+{
+	uint32_t i, k;
+	
+	printf("Semaphore test #2\n");
+    
+	waitq_initialize(&can_start);
+	semaphore_initialize(&sem, 5);
+	
+
+	
+	for (; ;) {
+		thread_t *thrd;
+		
+		k = random(7) + 1;
+		printf("Creating %d consumers\n", k);
+		for (i=0; i<k; i++) {
+			thrd = thread_create(consumer, NULL, TASK, 0, "consumer");
+			if (thrd)
+				thread_ready(thrd);
+			else
+				failed();
+		}
+		
+		thread_usleep(20000);
+		waitq_wakeup(&can_start, WAKEUP_ALL);
+	}		
+
+}
Index: kernel/test/sysinfo/test.c
===================================================================
--- kernel/test/sysinfo/test.c	(revision 1167520724b9b526c27b67f2d4bc447ef626240c)
+++ kernel/test/sysinfo/test.c	(revision 1167520724b9b526c27b67f2d4bc447ef626240c)
@@ -0,0 +1,55 @@
+/*
+ * Copyright (C) 2005 Jakub Vana
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the distribution.
+ * - The name of the author may not be used to endorse or promote products
+ *   derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <print.h>
+#include <debug.h>
+#include <panic.h>
+
+#include <test.h>
+#include <sysinfo/sysinfo.h>
+/*
+static unative_t counter(sysinfo_item_t *root)
+{
+	static unative_t i=0;
+	return i++;
+}*/
+
+void test(void)
+{
+/*	sysinfo_set_item_val("Ahoj.lidi.uaaaa",NULL,9);
+	sysinfo_set_item_val("Ahoj.lidi.ubbbb",NULL,15);
+	sysinfo_set_item_val("Ahoj.lidi",NULL,64);
+	sysinfo_set_item_function("Ahoj",NULL,counter);
+	sysinfo_dump(NULL,0);
+	sysinfo_set_item_val("Ahoj.lidi.ubbbb",NULL,75);
+	sysinfo_dump(NULL,0);
+	sysinfo_dump(NULL,0);
+	sysinfo_dump(NULL,0);*/
+	sysinfo_dump(NULL,0);
+	
+}
Index: kernel/test/thread/thread1/test.c
===================================================================
--- kernel/test/thread/thread1/test.c	(revision 1167520724b9b526c27b67f2d4bc447ef626240c)
+++ kernel/test/thread/thread1/test.c	(revision 1167520724b9b526c27b67f2d4bc447ef626240c)
@@ -0,0 +1,67 @@
+/*
+ * Copyright (C) 2005 Jakub Vana
+ * Copyright (C) 2005 Jakub Jermar
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the distribution.
+ * - The name of the author may not be used to endorse or promote products
+ *   derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <print.h>
+#include <debug.h>
+#include <panic.h>
+
+#include <test.h>
+#include <atomic.h>
+#include <proc/thread.h>
+
+#include <arch.h>
+
+#define THREADS 5
+
+static void threadtest(void *data)
+{
+
+	thread_detach(THREAD);	
+
+	while(1)
+	{
+		while (1)
+			;
+		printf("%d\n",(int)(THREAD->tid));
+		scheduler();
+	}
+}
+
+void test(void)
+{
+	thread_t *t;
+	int i;
+
+	for (i=0; i<THREADS; i++) {  
+		if (!(t = thread_create(threadtest, NULL, TASK, 0, "threadtest")))
+			panic("could not create thread\n");
+		thread_ready(t);
+	}
+	printf("ok\n");
+}
