summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Makefrag.am7
-rw-r--r--configure.ac19
-rw-r--r--kern/kernel.c8
-rw-r--r--test/test.h23
-rw-r--r--test/test_pmap_update.c123
5 files changed, 180 insertions, 0 deletions
diff --git a/Makefrag.am b/Makefrag.am
index 5ae04208..fe5b942e 100644
--- a/Makefrag.am
+++ b/Makefrag.am
@@ -67,3 +67,10 @@ x15_SOURCES += \
vm/vm_prot.h \
vm/vm_setup.c \
vm/vm_setup.h
+
+x15_SOURCES += \
+ test/test.h
+
+if TEST_PMAP_UPDATE
+x15_SOURCES += test/test_pmap_update.c
+endif TEST_PMAP_UPDATE
diff --git a/configure.ac b/configure.ac
index 7982258c..5415aaf4 100644
--- a/configure.ac
+++ b/configure.ac
@@ -24,6 +24,12 @@ AC_ARG_ENABLE([debug],
[AS_HELP_STRING([--disable-debug],
[disable the debugging facilities])])
+AC_ARG_ENABLE([test-module],
+ [AS_HELP_STRING([--enable-test-module=TEST_MODULE],
+ [run the given test module instead of booting])],
+ [enable_test_module=$enableval],
+ [enable_test_module=no])
+
AC_ARG_WITH([max-cpus],
[AS_HELP_STRING([--with-max-cpus=MAX_CPUS],
[set the maximum number of supported processors])],
@@ -32,8 +38,21 @@ AC_ARG_WITH([max-cpus],
AC_DEFINE([__KERNEL__], [1], [kernel code])
AC_DEFINE_UNQUOTED([ARCH], [$arch], [arch])
+
AS_IF([test x"$enable_debug" = xno],
[AC_DEFINE([NDEBUG], [1], [disable debugging])])
+
+m4_define([ENABLE_TEST_MODULE],
+ [AS_CASE(["$enable_test_module"],
+ [pmap_update], [test_pmap_update=yes],
+ [AC_MSG_ERROR([invalid test module])])
+ AC_DEFINE([RUN_TEST_MODULE], [1],
+ [run test module instead of booting])
+ AC_MSG_NOTICE([test module enabled: $enable_test_module])])
+
+AS_IF([test x"$enable_test_module" != xno], [ENABLE_TEST_MODULE])
+AM_CONDITIONAL([TEST_PMAP_UPDATE], [test x"$test_pmap_update" = xyes])
+
AC_DEFINE_UNQUOTED([MAX_CPUS], [$opt_max_cpus],
[maximum number of supported processors])
diff --git a/kern/kernel.c b/kern/kernel.c
index 658c18d1..5d8b31ae 100644
--- a/kern/kernel.c
+++ b/kern/kernel.c
@@ -27,6 +27,10 @@
#include <machine/cpu.h>
#include <vm/vm_page.h>
+#ifdef RUN_TEST_MODULE
+#include <test/test.h>
+#endif /* RUN_TEST_MODULE */
+
void __init
kernel_main(void)
{
@@ -39,6 +43,10 @@ kernel_main(void)
work_setup();
llsync_setup();
+#ifdef RUN_TEST_MODULE
+ test_setup();
+#endif /* RUN_TEST_MODULE */
+
/*
* Enabling application processors is done late in the boot process for
* two reasons :
diff --git a/test/test.h b/test/test.h
new file mode 100644
index 00000000..4c2de926
--- /dev/null
+++ b/test/test.h
@@ -0,0 +1,23 @@
+/*
+ * Copyright (c) 2014 Richard Braun.
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef _TEST_TEST_H
+#define _TEST_TEST_H
+
+void test_setup(void);
+
+#endif /* _TEST_TEST_H */
diff --git a/test/test_pmap_update.c b/test/test_pmap_update.c
new file mode 100644
index 00000000..2386fda0
--- /dev/null
+++ b/test/test_pmap_update.c
@@ -0,0 +1,123 @@
+/*
+ * Copyright (c) 2014 Richard Braun.
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ *
+ * The purpose of this test module is to check that the pmap module properly
+ * synchronizes page tables across processors. Two threads are created and
+ * bound to processors 0 and 1 respectively. The first thread allocates a
+ * page and writes it, making sure physical mappings are up-to-date locally.
+ * It then transfers the page address to the second thread which validates
+ * the content of the page, an operation that can only be done if the page
+ * tables of the current processor have been updated.
+ */
+
+#include <kern/assert.h>
+#include <kern/condition.h>
+#include <kern/cpumap.h>
+#include <kern/mutex.h>
+#include <kern/panic.h>
+#include <kern/param.h>
+#include <kern/printk.h>
+#include <kern/stddef.h>
+#include <kern/string.h>
+#include <kern/thread.h>
+#include <test/test.h>
+#include <vm/vm_kmem.h>
+
+static struct condition test_condition;
+static struct mutex test_lock;
+static unsigned long test_va;
+
+static void
+test_run1(void *arg)
+{
+ void *ptr;
+
+ (void)arg;
+
+ printk("allocating page\n");
+ ptr = (void *)vm_kmem_alloc(PAGE_SIZE);
+ printk("writing page\n");
+ memset(ptr, 'a', PAGE_SIZE);
+
+ printk("passing page to second thread (%p)\n", ptr);
+
+ mutex_lock(&test_lock);
+ test_va = (unsigned long)ptr;
+ condition_signal(&test_condition);
+ mutex_unlock(&test_lock);
+}
+
+static void
+test_run2(void *arg)
+{
+ const char *ptr;
+ unsigned int i;
+
+ (void)arg;
+
+ printk("waiting for page\n");
+
+ mutex_lock(&test_lock);
+
+ while (test_va == 0)
+ condition_wait(&test_condition, &test_lock);
+
+ ptr = (const char *)test_va;
+
+ mutex_unlock(&test_lock);
+
+ printk("page received (%p), checking page\n", ptr);
+
+ for (i = 0; i < PAGE_SIZE; i++)
+ if (ptr[i] != 'a')
+ panic("invalid content");
+
+ vm_kmem_free((unsigned long)ptr, PAGE_SIZE);
+ printk("done\n");
+}
+
+void
+test_setup(void)
+{
+ struct thread_attr attr;
+ struct thread *thread;
+ struct cpumap *cpumap;
+ int error;
+
+ condition_init(&test_condition);
+ mutex_init(&test_lock);
+ test_va = 0;
+
+ error = cpumap_create(&cpumap);
+ assert(!error);
+
+ cpumap_zero(cpumap);
+ cpumap_set(cpumap, 0);
+ thread_attr_init(&attr, "x15_test_run1");
+ thread_attr_set_cpumap(&attr, cpumap);
+ error = thread_create(&thread, &attr, test_run1, NULL);
+ assert(!error);
+
+ cpumap_zero(cpumap);
+ cpumap_set(cpumap, 1);
+ thread_attr_init(&attr, "x15_test_run2");
+ thread_attr_set_cpumap(&attr, cpumap);
+ error = thread_create(&thread, &attr, test_run2, NULL);
+ assert(!error);
+
+ cpumap_destroy(cpumap);
+}