Index: kernel/Makefile
===================================================================
--- kernel/Makefile	(revision 134877d64bac047ca117c283bd304140ea31a7b0)
+++ kernel/Makefile	(revision 319e60e55b0b59b46de5960c99fbbfe193c9017a)
@@ -216,5 +216,8 @@
 ifneq ($(CONFIG_TEST),)
 	DEFS += -DCONFIG_TEST
-	GENERIC_SOURCES += test/$(CONFIG_TEST)/test.c
+	CFLAGS += -Itest/
+	GENERIC_SOURCES += \
+		test/test.c \
+		test/atomic/atomic1.c
 endif
 
Index: rnel/generic/include/test.h
===================================================================
--- kernel/generic/include/test.h	(revision 134877d64bac047ca117c283bd304140ea31a7b0)
+++ 	(revision )
@@ -1,43 +1,0 @@
-/*
- * 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.
- */
-
-/** @addtogroup generic	
- * @{
- */
-/** @file
- */
-
-#ifndef KERN_TEST_H_
-#define KERN_TEST_H_
-
-extern void test(void);
-
-#endif
-
-/** @}
- */
Index: kernel/generic/src/console/cmd.c
===================================================================
--- kernel/generic/src/console/cmd.c	(revision 134877d64bac047ca117c283bd304140ea31a7b0)
+++ kernel/generic/src/console/cmd.c	(revision 319e60e55b0b59b46de5960c99fbbfe193c9017a)
@@ -66,4 +66,8 @@
 #include <ipc/irq.h>
 
+#ifdef CONFIG_TEST
+#include <test.h>
+#endif
+
 /* Data and methods for 'help' command. */
 static int cmd_help(cmd_arg_t *argv);
@@ -77,5 +81,5 @@
 static cmd_info_t exit_info = {
 	.name = "exit",
-	.description ="Exit kconsole",
+	.description = "Exit kconsole",
 	.argc = 0
 };
@@ -84,8 +88,35 @@
 static cmd_info_t continue_info = {
 	.name = "continue",
-	.description ="Return console back to userspace.",
+	.description = "Return console back to userspace.",
 	.func = cmd_continue,
 	.argc = 0
 };
+
+#ifdef CONFIG_TEST
+static int cmd_tests(cmd_arg_t *argv);
+static cmd_info_t tests_info = {
+	.name = "tests",
+	.description = "Print available kernel tests.",
+	.func = cmd_tests,
+	.argc = 0
+};
+
+static char test_buf[MAX_CMDLINE + 1];
+static int cmd_test(cmd_arg_t *argv);
+static cmd_arg_t test_argv[] = {
+	{
+		.type = ARG_TYPE_STRING,
+		.buffer = test_buf,
+		.len = sizeof(test_buf)
+	}
+};
+static cmd_info_t test_info = {
+	.name = "test",
+	.description = "Run kernel test.",
+	.func = cmd_test,
+	.argc = 1,
+	.argv = test_argv
+};
+#endif
 
 /* Data and methods for 'description' command. */
@@ -378,4 +409,8 @@
 	&zones_info,
 	&zone_info,
+#ifdef CONFIG_TEST
+	&tests_info,
+	&test_info,
+#endif
 	NULL
 };
@@ -806,4 +841,45 @@
 }
 
+/** Command for printing kernel tests list.
+ *
+ * @param argv Ignored.
+ *
+ * return Always 1.
+ */
+int cmd_tests(cmd_arg_t *argv)
+{
+	test_t *test;
+	
+	for (test = tests; test->name != NULL; test++)
+		printf("%s\t%s\n", test->name, test->desc);
+	
+	return 1;
+}
+
+/** Command for returning kernel tests
+ *
+ * @param argv Argument vector.
+ *
+ * return Always 1.
+ */
+int cmd_test(cmd_arg_t *argv)
+{
+	bool fnd = false;
+	test_t *test;
+	
+	for (test = tests; test->name != NULL; test++) {
+		if (strcmp(test->name, argv->buffer) == 0) {
+			fnd = true;
+			test->entry();
+			break;
+		}
+	}
+	
+	if (!fnd)
+		printf("Unknown test.\n");
+	
+	return 1;
+}
+
 /** @}
  */
Index: kernel/generic/src/main/kinit.c
===================================================================
--- kernel/generic/src/main/kinit.c	(revision 134877d64bac047ca117c283bd304140ea31a7b0)
+++ kernel/generic/src/main/kinit.c	(revision 319e60e55b0b59b46de5960c99fbbfe193c9017a)
@@ -70,8 +70,4 @@
 #include <synch/waitq.h>
 #include <synch/spinlock.h>
-
-#ifdef CONFIG_TEST
-#include <test.h>
-#endif /* CONFIG_TEST */
 
 /** Kernel initialization thread.
@@ -155,9 +151,4 @@
 	interrupts_enable();
 
-#ifdef CONFIG_TEST
-	test();
-	printf("\nTest finished, please reboot.\n");
-#else  /* CONFIG_TEST */
-
 	count_t i;
 	for (i = 0; i < init.cnt; i++) {
@@ -195,6 +186,4 @@
 		}
 	}
-#endif /* CONFIG_TEST */
-
 }
 
Index: kernel/kernel.config
===================================================================
--- kernel/kernel.config	(revision 134877d64bac047ca117c283bd304140ea31a7b0)
+++ kernel/kernel.config	(revision 319e60e55b0b59b46de5960c99fbbfe193c9017a)
@@ -119,31 +119,7 @@
 ## Run-time configuration directives
 
-# Kernel test type
-@ "" No test
-@ "atomic/atomic1" Test of atomic operations.
-@ "btree/btree1" B-tree test.
-@ "synch/rwlock1" Read write test 1
-@ "synch/rwlock2" Read write test 2
-@ "synch/rwlock3" Read write test 3
-@ "synch/rwlock4" Read write test 4
-@ "synch/rwlock5" Read write test 5
-@ "synch/semaphore1" Semaphore test 1
-@ "synch/semaphore2" Sempahore test 2
-@ [ARCH=ia32|ARCH=amd64|ARCH=ia64|ARCH=ia32xen] "fpu/fpu1" Intel FPU test 1
-@ [ARCH=ia32|ARCH=amd64|ARCH=ia32xen] "fpu/sse1" Intel SSE test 1
-@ [ARCH=mips32&MACHINE!=msim&MACHINE!=simics] "fpu/mips1" MIPS FPU test 1
-@ "print/print1" Printf test 1
-@ "thread/thread1" Thread test 1
-@ "mm/mapping1" Mapping test 1
-@ "mm/falloc1" Frame Allocation test 1
-@ "mm/falloc2" Frame Allocation test 2
-@ "mm/slab1" SLAB test1 - No CPU cache
-@ "mm/slab2" SLAB test2 - SMP CPU cache
-@ "fault/fault1" Write to NULL (maybe page fault)
-@ "sysinfo" Sysinfo fill and dump test
-@ [ARCH=ia64] "mm/purge1" Itanium TLB purge test
-@ [ARCH=mips32] "debug/mips1" MIPS breakpoint-debug test 
-! CONFIG_TEST (choice)
+# Compile kernel tests
+! CONFIG_TEST (y/n)
 
-# Benchmark test
-! [CONFIG_TEST!=] CONFIG_BENCH (n/y)
+# Benchmark tests
+! [CONFIG_TEST!=] CONFIG_BENCH (y/n)
Index: kernel/test/atomic/atomic1.c
===================================================================
--- kernel/test/atomic/atomic1.c	(revision 319e60e55b0b59b46de5960c99fbbfe193c9017a)
+++ kernel/test/atomic/atomic1.c	(revision 319e60e55b0b59b46de5960c99fbbfe193c9017a)
@@ -0,0 +1,67 @@
+/*
+ * 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>
+
+#ifdef CONFIG_BENCH
+#include <arch/cycle.h>
+#endif
+
+void test_atomic1(void)
+{
+#ifdef CONFIG_BENCH
+	uint64_t t0 = get_cycle();
+#endif
+	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");
+#ifdef CONFIG_BENCH
+	uint64_t dt = get_cycle() - t0;
+	printf("Time: %.*d cycles\n", sizeof(dt) * 2, dt);
+#endif
+	return;
+}
Index: rnel/test/atomic/atomic1/test.c
===================================================================
--- kernel/test/atomic/atomic1/test.c	(revision 134877d64bac047ca117c283bd304140ea31a7b0)
+++ 	(revision )
@@ -1,56 +1,0 @@
-/*
- * 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/mm/slab2/test.c
===================================================================
--- kernel/test/mm/slab2/test.c	(revision 134877d64bac047ca117c283bd304140ea31a7b0)
+++ kernel/test/mm/slab2/test.c	(revision 319e60e55b0b59b46de5960c99fbbfe193c9017a)
@@ -38,4 +38,8 @@
 #include <synch/mutex.h>
 
+#ifdef CONFIG_BENCH
+#include <arch/cycle.h>
+#endif
+
 #define ITEM_SIZE 256
 
@@ -209,4 +213,8 @@
 void test(void)
 {
+#ifdef CONFIG_BENCH
+	uint64_t t0 = get_cycle();
+#endif
+
 	printf("Running reclaim single-thread test .. pass1\n");
 	totalmemtest();
@@ -219,3 +227,8 @@
 	multitest(8192);
 	printf("All done.\n");
-}
+
+#ifdef CONFIG_BENCH
+	uint64_t dt = get_cycle() - t0;
+	printf("Time: %.*d cycles\n", sizeof(dt) * 2, dt);
+#endif
+}
Index: kernel/test/test.c
===================================================================
--- kernel/test/test.c	(revision 319e60e55b0b59b46de5960c99fbbfe193c9017a)
+++ kernel/test/test.c	(revision 319e60e55b0b59b46de5960c99fbbfe193c9017a)
@@ -0,0 +1,47 @@
+/*
+ * Copyright (C) 2006 Martin Decky
+ * 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.
+ */
+
+/** @addtogroup test
+ * @{
+ */
+/** @file
+ */
+
+#include <test.h>
+
+test_t tests[] = {
+	{
+		"atomic1",
+		"Test atomic operations",
+		&test_atomic1
+	},
+	{NULL, NULL, NULL}
+};
+
+/** @}
+ */
Index: kernel/test/test.h
===================================================================
--- kernel/test/test.h	(revision 319e60e55b0b59b46de5960c99fbbfe193c9017a)
+++ kernel/test/test.h	(revision 319e60e55b0b59b46de5960c99fbbfe193c9017a)
@@ -0,0 +1,54 @@
+/*
+ * Copyright (C) 2006 Martin Decky
+ * 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.
+ */
+
+/** @addtogroup test
+ * @{
+ */
+/** @file
+ */
+
+#ifndef KERN_TEST_H_
+#define KERN_TEST_H_
+
+#include <arch/types.h>
+#include <typedefs.h>
+
+typedef struct {
+	char * name;
+	char * desc;
+	function entry;
+} test_t;
+
+extern void test_atomic1(void);
+
+extern test_t tests[];
+
+#endif
+
+/** @}
+ */
